From 71e0432f66ea61a49384440bfd97bb54629fa208 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Sat, 19 Nov 2022 23:55:18 +0700 Subject: [PATCH] fix volume actual calc --- app/Models/Activity.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 7b3468f..3ec0bac 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -130,20 +130,14 @@ class Activity extends Model public function getJobsDoneAttribute() { - $tmpPercentage = []; if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) return 0; if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) return 0; - foreach ($dataPlan as $value) { - $tmpPercentage[] = 100; - $getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty"); - $percentage = ($getDataVolActual * 100) / $value->qty_planning; - if($value->status_activity != 'done'){ - $tmpPercentage[] = $percentage >= 100 ? 90 : $percentage; - } - } - return array_sum($tmpPercentage) > 0 ? array_sum($tmpPercentage) / count($tmpPercentage) : 0; + $totalPlan = $dataPlan->sum('qty_planning'); + $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $this->id)->sum("qty"); + $percentage = ($totalVolumeActual * 100) / $totalPlan; + return $percentage > 95 ? 95 : $percentage; } public function getAssignHrAttribute()