diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 61902e9..2c7025f 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -45,9 +45,9 @@ class ActivityController extends Controller $dataHeader->type = "header"; $dataHeader->text = $dataHeader->name; $finalData[] = $dataHeader; - $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); + $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get(); }else{ - $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); + $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get(); } foreach($data as $objRow){ @@ -68,6 +68,9 @@ class ActivityController extends Controller $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 = $objRow->persentase_progress / 100; + if ($objRow->sortorder == 0 || $objRow->sortorder == null) { + $objRow->sortorder = $objRow->id; + } $objRow->type = $type; $finalData[] = $objRow; $finalData = array_merge($finalData, $dataChildren); @@ -100,7 +103,7 @@ class ActivityController extends Controller private function getChildren($gantt_id, $parent_id) { $finalData = []; - $data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('id', 'asc')->get(); + $data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get(); foreach($data as $objRow){ $objRow->parent = $parent_id; $objRow->text = $objRow->name; @@ -111,6 +114,9 @@ class ActivityController extends Controller $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; + if ($objRow->sortorder == 0 || $objRow->sortorder == null) { + $objRow->sortorder = $objRow->id; + } $dataChildren = $this->getChildren($gantt_id, $objRow->id); if($objRow->type_activity=="milestone"){ $objRow->type = $objRow->type_activity; @@ -203,6 +209,7 @@ class ActivityController extends Controller $data['name'] = $request->text; $data['persentase_progress'] = $request->progress; $data['created_by'] = $this->currentName; + $data['sortorder'] = Activity::max("sortorder") + 1; $data['type_activity'] = "task"; $parent = $data['parent_id'] ?? null; @@ -246,6 +253,10 @@ class ActivityController extends Controller $dataUpdate['updated_by'] = $this->currentName; if($data->type_activity!='header') $dataUpdate['type_activity'] = $request->type; + + if($request->has("target")){ + $this->updateOrder($id, $request->target); + } if(!$data->update($dataUpdate)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); @@ -253,6 +264,29 @@ class ActivityController extends Controller return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200); } + private function updateOrder($taskId, $target){ + $nextTask = false; + $targetId = $target; + + if(strpos($target, "next:") === 0){ + $targetId = substr($target, strlen("next:")); + $nextTask = true; + } + + if($targetId == "null") + return; + + $targetOrder = Activity::find($targetId)->sortorder; + if($nextTask) + $targetOrder++; + + Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder"); + + $updatedTask = Activity::find($taskId); + $updatedTask->sortorder = $targetOrder; + $updatedTask->save(); + } + public function updateRegular(Request $request, $id){ if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); @@ -326,7 +360,8 @@ class ActivityController extends Controller $input['bobot_planning'] = $activity_row['weight']; $input['persentase_progress'] = 0; $input['type_activity'] = $i == 0 ? "header" : "task"; - $input['created_by'] = $this->currentName; + $input['created_by'] = $this->currentName; + $input['sortorder'] = $activity_row['no']; if (!$activity = Activity::create($input)) { Activity::where('version_gantt_id', $data['ganttId'])->delete(); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a02d0d1..c431f28 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -227,14 +227,14 @@ class Controller extends BaseController private function calculateAllHumanCost($activity_id, $proyek_id) { - $dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id") + $dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate") + ->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id") ->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id) ->where("ahp.proyek_id", $proyek_id) ->get(); $totalCost = 0; foreach ($dataHuman as $human) { - $uom = $human->uom_standart_rate; $totalCost += $this->calculateHumanCost($human, $activity_id); } @@ -247,6 +247,10 @@ class Controller extends BaseController $duration = $activity->duration; $standarRate = $human->standart_rate; $maxUsed = $human->max_used/100; + if ($human->uom_standart_rate == "Hour") { + $totalCost = ($standarRate*8*$duration)*$maxUsed; + return $totalCost; + } $totalCost = ($standarRate*$duration)*$maxUsed; return $totalCost; } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 4c436d8..ce49289 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -26,7 +26,7 @@ class Activity extends Model 'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom', 'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan', 'planned_start', 'planned_end', 'satuan_id', - 'created_at', 'created_by', 'updated_at', 'updated_by' + 'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder' ]; protected $appends = [