Browse Source

bugfix type activity and improve update bobot

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
a05cfab65d
  1. 20
      app/Http/Controllers/ActivityController.php
  2. 38
      app/Models/Activity.php

20
app/Http/Controllers/ActivityController.php

@ -42,20 +42,22 @@ class ActivityController extends Controller
foreach($data as $objRow){
$type = "project";
$dataChildren = $this->getChildren($id, $objRow->id);
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_date);
if($objRow->type_activity=="milestone")
$type = $objRow->type_activity;
if(empty($dataChildren))
$type = "task";
$objRow->text = $objRow->name;
$objRow->parent = $objRow->parent_id ? $objRow->parent_id : null;
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_date);
$objRow->start_date = date_format($startDate,"Y-m-d H:i:s");
$objRow->end_date = date_format($endDate,"Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
$objRow->progress = (int) $objRow->persentase_progress / 100;
$dataChildren = $this->getChildren($id, $objRow->id);
$objRow->type = $type;
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
@ -183,7 +185,10 @@ class ActivityController extends Controller
$parent = $data['parent_id'] ?? null;
if($parent){
Activity::find($parent)->update(["type_activity"=>"project"]);
$parentData = Activity::find($parent);
if($parentData->parent_id) {
$parentData->update(["type_activity" => "project"]);
}
CommentActivity::where('activity_id', $parent)->delete();
UserToActivity::where('activity_id', $parent)->delete();
}
@ -209,16 +214,11 @@ class ActivityController extends Controller
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400);
$updateBobot = false;
$updateBobot = true;
if(!$data = Activity::find($id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404);
$dataUpdate = $request->all();
$oldRencanaBiaya = $data->rencana_biaya;
$newRencanaBiaya = str_replace(",",".",$request->rencana_biaya);
if($oldRencanaBiaya != $newRencanaBiaya)
$updateBobot = true;
$dataUpdate['name'] = $request->text;
$dataUpdate['persentase_progress'] = $request->progress*100;
$dataUpdate['updated_by'] = $this->currentName;

38
app/Models/Activity.php

@ -44,6 +44,7 @@ class Activity extends Model
if(Activity::where("parent_id", $data->parent_id)->count() == 0)
Activity::find($data->parent_id)->update(["type_activity"=>"task"]);
$data->updateBobot(true);
$data->updateCostPlanning();
$data->updatePersentaseProgress();
$data->updateCostActual();
@ -51,39 +52,26 @@ class Activity extends Model
}
private function updateBobot()
private function updateBobot($isDelete = false)
{
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
$root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->whereNull('parent_id')
->first();
if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) {
$totalCost = Activity::select(
DB::raw('sum(cast(rencana_biaya as double precision))')
)
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->whereNull("parent_id")
->first();
} else {
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->where("parent_id", $rootActivity->id)
->first();
}
if($totalCost->sum > 0){
if($root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
foreach ($activities as $activity) {
$activity->update([
"bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100,
"updated_by" => auth()->user() ? auth()->user()->name : "system",
]);
$activity->save();
if($isDelete && $activity->id == $this->id)
continue;
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100;
$activity->updated_by = auth()->user() ? auth()->user()->name : "system";
$activity->saveQuietly();
}
}
}
private function updateCostActual()

Loading…
Cancel
Save