|
|
|
@ -33,18 +33,23 @@ class ReportActivityMaterial extends Model
|
|
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
|
$assignedMaterial = AssignMaterial::find($data->assign_material_id); |
|
|
|
|
|
|
|
|
|
$activity->biaya_actual += floatval($assignedMaterial->budget) * floatval($data->qty); |
|
|
|
|
$biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); |
|
|
|
|
|
|
|
|
|
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); |
|
|
|
|
if($dataPlan[0]->status_activity == 'done'){ |
|
|
|
|
$activity->persentase_progress = 100; |
|
|
|
|
$percentage = 100; |
|
|
|
|
} else { |
|
|
|
|
$totalPlan = $dataPlan->sum('qty_planning'); |
|
|
|
|
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); |
|
|
|
|
$percentage = ($totalVolumeActual * 100) / $totalPlan; |
|
|
|
|
$activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; |
|
|
|
|
$percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$activity->update([ |
|
|
|
|
"persentase_progress" => $percentage, |
|
|
|
|
"biaya_actual" => $biayaActual, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|