Browse Source

overhaul progress calc

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
07dc607386
  1. 41
      app/Http/Controllers/ReportActivityMaterialController.php
  2. 7
      app/Models/Activity.php
  3. 4
      app/Models/AssignMaterial.php
  4. 24
      app/Models/ReportActivityMaterial.php

41
app/Http/Controllers/ReportActivityMaterialController.php

@ -31,7 +31,6 @@ class ReportActivityMaterialController extends Controller
if(!ReportActivityMaterial::create($data)) if(!ReportActivityMaterial::create($data))
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]); return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]);
$this->countForProgress($request->activity_id);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200]); return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200]);
} }
@ -68,46 +67,6 @@ class ReportActivityMaterialController extends Controller
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200); return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
} }
private function countForProgress($id)
{
$dataActivity = Activity::find($id);
$dataPlan = AssignMaterial::where('activity_id', $id)->get();
$tmpPercentage1 = [];
if(!$dataPlan->isEmpty()){
foreach ($dataPlan as $value) {
# code...
$price = $value->material_id;
$qty_plan = $value->qty_planning;
$status_activity = $value->status_activity;
$getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty");
$percentage1 = ($getDataVolActual * 100) / $qty_plan;
if($status_activity == 'done'){
$tmpPercentage1[] = $percentage1 > 100 ? 100 : $percentage1;
}else if($status_activity == 'on-progress'){
$tmpPercentage1[] = $percentage1 >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage1;
}else{
$tmpPercentage1[] = $percentage1 >= config('max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage1;
}
}
$totalPercentage = array_sum($tmpPercentage1) / count($tmpPercentage1);
}else{
$totalPercentage = 0;
}
$dataUpdate = array(
"persentase_progress" => $totalPercentage,
"updated_by" => $this->currentName
);
return $dataActivity->update($dataUpdate);
}
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();

7
app/Models/Activity.php

@ -134,10 +134,9 @@ class Activity extends Model
return 0; return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
return 0; return 0;
$totalPlan = $dataPlan->sum('qty_planning'); if($dataPlan[0]->status_activity == 'done')
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $this->id)->sum("qty"); return 100;
$percentage = ($totalVolumeActual * 100) / $totalPlan; return $this->persentase_progress;
return $percentage > config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
} }
public function getAssignHrAttribute() public function getAssignHrAttribute()

4
app/Models/AssignMaterial.php

@ -14,7 +14,9 @@ class AssignMaterial extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'proyek_id', 'activity_id', 'material_id', 'qty_planning', 'budget', 'plan_date','created_at', 'created_by', 'updated_at', 'updated_by' 'proyek_id', 'activity_id', 'material_id', 'qty_planning',
'budget', 'plan_date', 'status_activity',
'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
protected $casts = [ protected $casts = [

24
app/Models/ReportActivityMaterial.php

@ -30,13 +30,22 @@ class ReportActivityMaterial extends Model
parent::boot(); parent::boot();
static::created(function($data) { static::created(function($data) {
$activity = Activity::find($data->activity_id); $activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id); $assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual += floatval($assignedMaterial->budget) * floatval($data->qty); $activity->biaya_actual += floatval($assignedMaterial->budget) * floatval($data->qty);
$activity->save();
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
if($dataPlan[0]->status_activity == 'done'){
$activity->persentase_progress = 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;
}
$activity->save();
}); });
static::deleted(function($data) { static::deleted(function($data) {
@ -45,6 +54,17 @@ class ReportActivityMaterial extends Model
$assignedMaterial = AssignMaterial::find($data->assign_material_id); $assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); $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;
} 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;
}
$activity->save(); $activity->save();
}); });

Loading…
Cancel
Save