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()