From 0b08a7a5f4e9e06ab58cc53e12e31823a18d5cab Mon Sep 17 00:00:00 2001 From: yusuf Date: Wed, 20 Jul 2022 00:28:25 +0700 Subject: [PATCH 01/11] Delete 'activity_log.txt' --- activity_log.txt | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100755 activity_log.txt diff --git a/activity_log.txt b/activity_log.txt deleted file mode 100755 index 1c6c2d1..0000000 --- a/activity_log.txt +++ /dev/null @@ -1,20 +0,0 @@ -2022-07-12 00:13:26: 1379 Penentuan harga project -Added: (10000000 * 1), Cost plan old: 0 | +10000000 -Data type (double * double), double | double -Data type origin (double * NULL), string | double ------- -2022-07-12 00:13:32: 1378 Contract Management -Deleted: (10000000 * 1), Cost plan old: 20000000 | -10000000 -Data type (double * double), double | double -Data type origin (double * double), string | double ------- -2022-07-12 00:13:38: 1377 Brainstorming peningkatan layanan masyarakat -Deleted: (10000000 * 1), Cost plan old: 20000000 | -10000000 -Data type (double * double), double | double -Data type origin (double * double), string | double ------- -2022-07-12 00:13:47: 1379 Penentuan harga project -Deleted: (10000000 * 1), Cost plan old: 10000000 | -0 -Data type (double * double), double | double -Data type origin (double * double), string | double ------- From ffb296832e1c32bda43c11a0984bfad9c76f2f37 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Thu, 21 Jul 2022 20:42:54 +0700 Subject: [PATCH 02/11] refactor --- app/Http/Controllers/ActivityController.php | 1920 +++++++++---------- 1 file changed, 917 insertions(+), 1003 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 80b3624..5a133dd 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -2,1022 +2,936 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; use App\Models\Activity; -use App\Models\Link; -use App\Models\Project; -use App\Models\TemplateGantt; -use App\Models\UserToActivity; -use App\Models\CommentActivity; use App\Models\AssignMaterial; use App\Models\AssignTools; -use App\Models\VersionGantt; +use App\Models\CommentActivity; use App\Models\Holiday; +use App\Models\Link; +use App\Models\Project; use App\Models\ReportActivity; use App\Models\ReportActivityMaterial; -use DB; +use App\Models\TemplateGantt; +use App\Models\UserToActivity; +use App\Models\VersionGantt; +use Illuminate\Support\Facades\DB; +use Illuminate\Http\Request; +use Illuminate\Support\Arr; class ActivityController extends Controller { - public function getByGanttId($id, $proyek_id) - { - $cekData = Activity::where("version_gantt_id", $id)->count(); - - $dataGantt = []; - if($cekData > 0){ - $dataGantt = $this->getDataActivity($id); - }else{ - $this->templateToActivity($id, $proyek_id); - $dataGantt = $this->getDataActivity($id); - } - - return response()->json(['status'=>'success','data'=>$dataGantt,'code'=>200], 200); - } - - private function getDataActivity($id) - { - $checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); - $finalData = []; - if($checkHeader > 0){ - $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); - $startDate = date_create($dataHeader->start_date); - $endDate = date_create($dataHeader->end_date); - $dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s"); - $dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s"); - $dataHeader->type = "project"; - $dataHeader->text = $dataHeader->name; - $finalData[] = $dataHeader; - $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); - }else{ - $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); - } - - foreach($data as $objRow){ - $objRow->text = $objRow->name; - if($objRow->parent_id){ - $objRow->parent = $objRow->parent_id; - } - $startDate = date_create($objRow->start_date); - $endDate = date_create($objRow->end_date); - $objRow->jobs_done = $this->sumVolumeActualMaterial($objRow->id); - $objRow->assign_hr = $this->getUserActivity($objRow->id); - $objRow->assign_tools = $this->getToolsActivity($objRow->id); - $objRow->assign_material = $this->getMaterialActivity($objRow->id); - $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); - if($objRow->type_activity=="milestone"){ - $objRow->type = $objRow->type_activity; - }else if(empty($dataChildren)){ - $objRow->type = "task"; - }else{ - $objRow->type = "project"; - } - $finalData[] = $objRow; - $finalData = array_merge($finalData, $dataChildren); - } - - $dataLink = Link::where('version_gantt_id', $id)->get(); - $finalLink = []; - foreach($dataLink as $objRow) - { - $dataRow = array( - 'id'=>$objRow->id, - 'source'=>$objRow->s_activity_id, - 'target'=>$objRow->t_activity_id, - 'type'=>$objRow->type_link, - 'code'=>$objRow->code_link - ); - - if($objRow->lag) - { - $dataRow['lag'] = $objRow->lag; - } - - $finalLink[] = $dataRow; - - } - - $resultData = array( - "data"=>$finalData, - "links"=>$finalLink - ); - - return $resultData; - } - - 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(); - foreach($data as $objRow){ - $objRow->parent = $parent_id; - $objRow->text = $objRow->name; - $objRow->jobs_done = $this->sumVolumeActualMaterial($objRow->id); - $objRow->assign_hr = $this->getUserActivity($objRow->id); - $objRow->assign_tools = $this->getToolsActivity($objRow->id); - $objRow->assign_material = $this->getMaterialActivity($objRow->id); - $objRow->progress = (int)$objRow->persentase_progress/100; - $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; - $dataChildren = $this->getChildren($gantt_id, $objRow->id); - if($objRow->type_activity=="milestone"){ - $objRow->type = $objRow->type_activity; - }elseif(empty($dataChildren)){ - $objRow->type = "task"; - }else{ - $objRow->type = "project"; - } - $finalData[] = $objRow; - $finalData = array_merge($finalData, $dataChildren); - } - return $finalData; - } - - private function sumVolumeActuall($id) - { - $sumVa = ReportActivity::where("activity_id", $id)->sum("job_count_report"); - return $sumVa; - } - - private function sumVolumeActualMaterial($id) - { - $dataPlan = AssignMaterial::where('activity_id', $id)->get(); - $tmpPercentage1 = []; - if(!$dataPlan->isEmpty()){ - foreach ($dataPlan as $value) { - $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[] = 100; - } - else{ - $tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1; - } - } - - $totalPercentage = array_sum($tmpPercentage1) > 0 ? array_sum($tmpPercentage1) / count($tmpPercentage1) : 0; - }else{ - - - $totalPercentage = 0; - } - return $totalPercentage; - } - - private function getUserActivity($id) - { - $data = UserToActivity::select("u.name as name")->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")->where('assign_hr_to_activity.activity_id', $id)->get(); - $nameCollection = []; - foreach($data as $value){ - $nameCollection[] = $value->name; - } - return $nameCollection; - } - - private function getMaterialActivity($id) - { - $data = AssignMaterial::select("m.description as name")->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")->where('assign_material_to_activity.activity_id', $id)->get(); - $nameCollection = []; - foreach($data as $value){ - $nameCollection[] = $value->name; - } - return $nameCollection; - } - - private function getToolsActivity($id) - { - $data = AssignTools::select("m.name as name")->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")->where('assign_tools_to_activity.activity_id', $id)->get(); - $nameCollection = []; - foreach($data as $value){ - $nameCollection[] = $value->name; - } - return $nameCollection; - } - - private function templateToActivity($id, $proyek_id) - { - $resultProject = Project::find($proyek_id); - $newRencanaBiaya = str_replace(".","", $resultProject->rencana_biaya); - $dataHeader = array( - 'version_gantt_id'=>$id, - 'proyek_id'=>$proyek_id, - 'name'=> $resultProject->nama, - 'kode_sortname'=>$resultProject->kode_sortname, - 'start_date'=> $resultProject->mulai_proyek, - 'end_date'=> $resultProject->akhir_proyek, - 'rencana_biaya'=> $newRencanaBiaya, - 'type_activity'=> 'header', - 'created_by'=>$this->currentName - ); - $newHeader = Activity::create($dataHeader); - - $resultTypeProject = TemplateGantt::where('proyek_type_id',$resultProject->type_proyek_id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); - - $typeProjectId = $resultProject->type_proyek_id; - - foreach($resultTypeProject as $objRow){ - $newActivity = array( - 'version_gantt_id'=>$id, - 'parent_id'=>$newHeader->id, - 'proyek_id'=>$proyek_id, - 'name'=> $objRow->name_activity, - 'start_date'=>date("Y-m-d H:i:s"), - 'end_date'=>date("Y-m-d H:i:s"), - 'created_by'=>$this->currentName - ); - $checkChild = TemplateGantt::where("parent_id", $objRow->id)->count(); - if($checkChild > 0){ - $newActivity['type_activity'] = "project"; - }else{ - $newActivity['type_activity'] = "task"; - } - $resultNew = Activity::create($newActivity); - $this->getChildrenTemplate($id, $objRow->id, $typeProjectId, $proyek_id, $resultNew->id, $resultProject->mulai_proyek); - } - } - - private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay) - { - $data = TemplateGantt::where('proyek_type_id', $type_proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); - foreach($data as $objRow){ - $newActivity = array( - 'version_gantt_id'=>$id, - 'parent_id'=>$parent_new, - 'proyek_id'=>$proyek_id, - 'name'=> $objRow->name_activity, - 'start_date'=>$firstDay, - 'end_date'=>$firstDay, - 'created_by'=>$this->currentName - ); - $checkChild = TemplateGantt::where("parent_id", $objRow->id)->count(); - if($checkChild > 0){ - $newActivity['type_activity'] = "project"; - }else{ - $newActivity['type_activity'] = "task"; - } - $resultNew = Activity::create($newActivity); - $this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay); - } - } - - public function add(Request $request) - { - $this->validate($request, [ - 'version_gantt_id'=>'required' - ]); - - $data = $request->all(); - $data['name'] = $request->text; - $data['persentase_progress'] = $request->progress; - $data['created_by'] = $this->currentName; - $data['type_activity'] = "task"; - - $parent = isset($data['parent_id']) ? $data['parent_id'] : null; - if($parent && $parent > 0){ - $this->updateTypeProject($parent); - $comment = CommentActivity::where('activity_id', $parent)->delete(); - $hr = UserToActivity::where('activity_id', $parent)->delete(); - } - - $result = Activity::create($data); - - if($result){ - return response()->json(['status'=>'success','action'=>'inserted', 'tid'=>$result->id,'code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','action'=>'error','code'=>400], 400); - } - } - - private function updateTypeProject($id) - { - Activity::find($id)->update(["type_activity"=>"project"]); - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = Activity::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data activity, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400); - } - - $data = Activity::find($id); - $oldRencanaBiaya = $data->rencana_biaya; - $newRencanaBiaya = str_replace(",",".",$request->rencana_biaya); - if($oldRencanaBiaya==$newRencanaBiaya){ - $updateBobot = false; - }else{ - $updateBobot = true; - } - $parent = $data->parent_id; - $dataUpdate = $request->all(); - $dataUpdate['name'] = $request->text; - $dataUpdate['persentase_progress'] = $request->progress*100; - $dataUpdate['updated_by'] = $this->currentName; - if($data->type_activity!='header'){ - $dataUpdate['type_activity'] = $request->type; - } - if($data){ - $result = $data->update($dataUpdate); - if($result){ - if($parent && (int)$parent > 0){ - $this->updateCostPlanning($parent); - $this->updatePersentaseProgress($parent); - $this->updateCostActual($parent); - } - - $this->calculateAllBobot($data->proyek_id, $data->version_gantt_id); - - return response()->json(['status'=>'success','update_bobot'=>$updateBobot,'data'=>$dataUpdate, 'action'=>'updated','message'=>'data activity successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity not found!','code'=>400], 400); - die(); - } - } - - public function updateRegular(Request $request, $id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Activity::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data activity not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data activity successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data activity failed updated!','code'=>400], 400); - } - } - - private function calculateAllBobot($proyek, $gantt) - { - $checkHeader = Activity::where('version_gantt_id', $gantt)->where("proyek_id", $proyek)->where('type_activity', 'header')->count(); - if($checkHeader > 0){ - $dataHeader = Activity::where('version_gantt_id', $gantt)->where("proyek_id", $proyek)->where('type_activity', 'header')->first(); - $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("proyek_id", $proyek)->where("version_gantt_id", $gantt)->where("parent_id", $dataHeader->id)->first(); - }else{ - $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("proyek_id", $proyek)->where("version_gantt_id", $gantt)->whereNull("parent_id")->first(); - } - $totalCost = $totalCost->sum; - if($totalCost > 0){ - $activitys = Activity::where("proyek_id", $proyek)->where("version_gantt_id", $gantt)->get(); - foreach ($activitys as $activity) { - $bobot = ((int)$activity->rencana_biaya/$totalCost)*100; - $willUpdated = Activity::find($activity->id); - $dataUpdate = array( - "bobot_planning"=>$bobot, - "updated_by"=>$this->currentName - ); - $willUpdated->update($dataUpdate); - } - } - return true; - } - - public function delete($id) - { - $data = Activity::find($id); - - if($data){ - $parent = $data->parent_id; - if($parent && (int)$parent > 0){ - $this->checkForUpdateParent($parent); - $this->updateCostPlanning($parent); - $this->updatePersentaseProgress($parent); - $this->updateCostActual($parent); - } - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed deleted!','code'=>400], 400); - } - } - - private function checkForUpdateParent($id) - { - $count = Activity::where("parent_id", $id)->count(); - if(!$count || $count==0){ - Activity::find($id)->update(["type_activity"=>"task"]); - } - } - - public function getUpdate($id) - { - $data = Activity::find($id); - if($data){ - $data->progress = (int)$data->persentase_progress/100; - $data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya); - $data->jobs_done = $this->sumVolumeActualMaterial($data->id); - $data->assign_hr = $this->getUserActivity($data->id); - $data->assign_tools = $this->getToolsActivity($data->id); - $data->assign_material = $this->getMaterialActivity($data->id); - return response()->json(['status'=>'success', "data"=> $data,'code'=>200], 200); - }else{ - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity not found!','code'=>400], 400); - } - } - - private function updateCostPlanning($id) - { - $sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("parent_id", $id)->first(); - $dataActivity = Activity::find($id); - $dataUpdate = array( - "rencana_biaya" => $sumBiaya->sum, - "updated_by" => $this->currentName - ); - $dataActivity->update($dataUpdate); - if($dataActivity){ - $parent = $dataActivity->parent_id; - if($parent && (int)$parent > 0){ - $this->updateCostPlanning($parent); - } - } - } - - private function updatePersentaseProgress($id) - { - $sumProgress = Activity::where("parent_id", $id)->sum("persentase_progress"); - $totalChild = Activity::where("parent_id", $id)->count(); - $dataActivity = Activity::find($id); - $calculateProgressActual = $sumProgress/$totalChild; - $dataUpdate = array( - "persentase_progress" => $calculateProgressActual, - "updated_by" => $this->currentName - ); - $dataActivity->update($dataUpdate); - if($dataActivity){ - $parent = $dataActivity->parent_id; - if($parent && (int)$parent > 0){ - $this->updatePersentaseProgress($parent); - } - } - } - - private function updateCostActual($id) - { - $biayaActual = Activity::where("parent_id", $id)->sum("biaya_actual"); - $dataActivity = Activity::find($id); - - $dataUpdate = array( - "biaya_actual" => $biayaActual, - "updated_by" => $this->currentName - ); - $dataActivity->update($dataUpdate); - if($dataActivity){ - $parent = $dataActivity->parent_id; - if($parent && (int)$parent > 0){ - $this->updateCostActual($parent); - } - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_activity'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function calculateAllCost($activity_id, $proyek_id) - { - $materialCostPlanning = 0; - $toolsCostPlanning = 0; - - $allCost = $materialCostPlanning + $toolsCostPlanning; - return $allCost; - } - - public function getPercentagePerDay(Request $request) - { - $dataPayload = $request->all(); - $allGantt = []; - foreach ($dataPayload['project_id'] as $val) { - $allGantt[] = $this->getMaxVersionGantt($val); - } - - $dataFinal=[]; - foreach ($allGantt as $val) { - $dataProject = Project::find($val['proyek_id']); - $holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get(); - $dateHoliday = []; //$holiday->all(); - foreach ($holidays as $holiday) { - $startH = new \DateTime($holiday->date); - $endH = clone $startH; - $endH->modify('+'.$holiday->duration.' day'); - $intervalH = \DateInterval::createFromDateString('1 day'); - $periodH = new \DatePeriod($startH, $intervalH, $endH); - foreach ($periodH as $dt) { - $dateHoliday[] = $dt->format("Y-m-d"); - } - } - $verGantt = VersionGantt::find($val['last_gantt_id']); - $configOff = $verGantt->config_dayoff; - if($configOff && $configOff!= ""){ - $dayOff = explode(",", $verGantt->config_dayoff); - $dayOff = array_map( - function($value) { return (int)$value; }, - $dayOff - ); - }else{ - $dayOff = []; - } - $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); - if($checkHeader > 0){ - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - $minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - }else{ - $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - } - - $begin = new \DateTime($minDate); - $end = new \DateTime($maxDate); - $end = $end->modify( '+1 day' ); - $interval = \DateInterval::createFromDateString('1 day'); - $period = new \DatePeriod($begin, $interval, $end); - $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); - if($checkHeader > 0){ - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - }else{ - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - } - - $totalRencanaBudget = $totalRencanaBudget->sum; - $currentPercentage = 0; - $dataDate = []; - $dataPercen = []; - foreach ($period as $dt) { - $weekDay = $dt->format("w"); - $currentDate = $dt->format("Y-m-d"); - if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) - { - $totalPercentage = 0; - $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); - if($checkHeader > 0){ - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); - }else{ - $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); - } - - foreach ($dataActivity as $activity) { - $duration = $activity->duration; - if($totalRencanaBudget > 0 && $duration > 0){ - $totalPercentage = $totalPercentage + ((($activity->rencana_biaya/$totalRencanaBudget)*100)/$duration); - } - } - $currentPercentage = $currentPercentage + $totalPercentage; - $dataDate[] = $currentDate; - $dataPercen[] = $currentPercentage; - }else{ - $dataDate[] = $currentDate; - $dataPercen[] = "dateOff"; - } - } - $dataPercentage = array( - "date"=>$dataDate, - "percentage"=>$dataPercen - ); - $dataFinal[] = array( - "proyek_name"=> $dataProject->nama, - "data"=>$dataPercentage - ); - } - - if($dataFinal){ - return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400); - } - } - - - public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) - { - $dataPayload = $request->all(); - $allGantt = []; - if(isset($dataPayload['gannt_id'])){ - $allGantt = $dataPayload['gannt_id']; - }else{ - foreach ($dataPayload['project_id'] as $val) { - $allGantt[] = $this->getMaxVersionGantt($val); - } - } - $dataFinal=[]; - foreach ($allGantt as $keyGantt) { - $dataProject = Project::find($keyGantt['proyek_id']); - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first(); - - if($dataHeader){ - $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); - }else{ - $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); - - } - - $minDate = DB::table('assign_material_to_activity as ama') - ->where("ama.proyek_id", $keyGantt['proyek_id']) - ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->min("plan_date"); - - $maxDate = DB::table('assign_material_to_activity as ama') - ->where("ama.proyek_id", $keyGantt['proyek_id']) - ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->max("plan_date"); - - $begin = new \DateTime($minDate); - $end = new \DateTime($maxDate); - $end2 = new \DateTime($maxDate); - $interval = \DateInterval::createFromDateString('1 day'); - $period = new \DatePeriod($begin, $interval, $end); - $arr_ActualM = []; - $tempDate = []; - $tempPercentage = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; - - $currentACWP = 0; - $budgetControlACWP = 0; - $currentProgressActivity = 0; - $currentBCWP = 0; - $budgetControlBCWP = 0; - - foreach ($period as $dt) { - $dataPlanM = DB::table('assign_material_to_activity as ama') - ->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') - ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - ->where('ama.proyek_id', '=', $keyGantt['proyek_id']) - ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->whereDate('ama.plan_date', $dt->format("Y-m-d")) - ->get(); - $dataActualM = DB::table('report_activity_material as ram') - ->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') - ->join('m_activity as a', 'a.id', '=', 'ram.activity_id') - ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->where('a.proyek_id', '=', $keyGantt['proyek_id']) - ->whereDate('ram.report_date', $dt->format("Y-m-d")) - ->get(); - $dataTempPlan = []; - $x = 0; - $sumPercentagePlan=0; - $totalACWP = isset($totalACWP) ? $totalACWP : 0; - $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; - - foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table('assign_material_to_activity') - ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) - ->where('activity_id', '=', $keyPlanM->activity_id) - ->groupBy('activity_id') - ->first(); - $dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; - $dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning; - $dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date; - $dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity; - $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan; - $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan [$x]['duration'] = $keyPlanM->duration; - $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; - $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; - $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; - $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; - $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; - $x++; - } - - $w = 0; - $dataTempReport = []; - $sumPercentageActual=0; - foreach ($dataActualM as $keyActualM) { - $sumVolActual = DB::table('assign_material_to_activity') - ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) - ->where('activity_id', '=', $keyActualM->activity_id) - ->groupBy('activity_id') - ->first(); - $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; - $dataTempReport [$w]['qty'] = $keyActualM->qty; - $dataTempReport [$w]['report_date'] = $keyActualM->report_date; - $dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; - $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; - $dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; - $dataTempReport [$w]['duration'] = $keyActualM->duration; - $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; - $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; - $dataTempReport [$w]['totalacwp'] = $totalACWP; - $w++; - } - - $arr_ActualM[] = array( - 'date'=>$dt->format("Y-m-d"), - 'percentPlan'=>$sumPercentagePlan, - 'percentActual'=>$sumPercentageActual, - 'plan'=>$dataTempPlan, - 'actual'=>$dataTempReport, - ); - if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ - if($dt->format("w")==1){ - if($totalACWP > 0 ){ - $budgetControlACWP = $currentACWP + $totalACWP; - } - if($totalBCWP > 0 ){ - $budgetControlBCWP = $currentBCWP + $totalBCWP; - } - - $tempTtlPercentPlan+= $sumPercentagePlan; - $tempTtlPercentActual+= $sumPercentageActual; - $currentACWP += $totalACWP; - $currentBCWP += $totalBCWP; - - $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); - }else if($dt->format("Y-m-d") == $end2->format("Y-m-d")) { - $tempTtlPercentPlan+= $sumPercentagePlan; - $tempTtlPercentActual+= $sumPercentageActual; - $currentACWP += $totalACWP; - $currentBCWP += $totalBCWP; - - $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); - $tempTtlPercentPlan = 0; - $tempTtlPercentActual = 0; - } - }else{ - $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); - } - } - - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+0); - } - $costDeviation = $totalRencanaBudget - $estimatedCost; + public function getByGanttId($id, $proyek_id) + { + if(Activity::where("version_gantt_id", $id)->count() == 0) + $dataGantt = $this->getDataActivity($id); + + $this->templateToActivity($id, $proyek_id); + $dataGantt = $this->getDataActivity($id); + + return response()->json(['status'=>'success','data'=> $dataGantt,'code'=>200], 200); + } + + private function getDataActivity($id) + { + + $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); + $startDate = date_create($dataHeader->start_date); + $endDate = date_create($dataHeader->end_date); + $dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s"); + $dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s"); + $dataHeader->type = "project"; + $dataHeader->text = $dataHeader->name; + $finalData[] = $dataHeader; + $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); + + if(Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count() == 0) + $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); + + foreach($data as $objRow){ + $type = "project"; + 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->jobs_done = $this->sumVolumeActualMaterial($objRow->id); + $objRow->assign_hr = $this->getUserActivity($objRow->id); + $objRow->assign_tools = $this->getToolsActivity($objRow->id); + $objRow->assign_material = $this->getMaterialActivity($objRow->id); + $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); + } + + $dataLink = Link::where('version_gantt_id', $id)->get(); + $finalLink = []; + foreach($dataLink as $objRow) + { + $dataRow = array( + 'id'=>$objRow->id, + 'source'=>$objRow->s_activity_id, + 'target'=>$objRow->t_activity_id, + 'type'=>$objRow->type_link, + 'code'=>$objRow->code_link + ); + if($objRow->lag) + $dataRow['lag'] = $objRow->lag; + $finalLink[] = $dataRow; + } + + $resultData = array( + "data"=>$finalData, + "links"=>$finalLink + ); + + return $resultData; + } + + 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(); + foreach($data as $objRow){ + $objRow->parent = $parent_id; + $objRow->text = $objRow->name; + $objRow->jobs_done = $this->sumVolumeActualMaterial($objRow->id); + $objRow->assign_hr = $this->getUserActivity($objRow->id); + $objRow->assign_tools = $this->getToolsActivity($objRow->id); + $objRow->assign_material = $this->getMaterialActivity($objRow->id); + $objRow->progress = (int)$objRow->persentase_progress/100; + $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; + $dataChildren = $this->getChildren($gantt_id, $objRow->id); + if($objRow->type_activity=="milestone"){ + $objRow->type = $objRow->type_activity; + }elseif(empty($dataChildren)){ + $objRow->type = "task"; + }else{ + $objRow->type = "project"; + } + $finalData[] = $objRow; + $finalData = array_merge($finalData, $dataChildren); + } + return $finalData; + } + + private function sumVolumeActualMaterial($id) + { + $tmpPercentage = []; + + $dataPlan = AssignMaterial::where('activity_id', $id)->get(); + if($dataPlan->isEmpty()) + 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; + } + + private function getUserActivity($id) + { + return Arr::flatten(UserToActivity::select("u.name as name") + ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") + ->where('assign_hr_to_activity.activity_id', $id) + ->get() + ->toArray()); + } + + private function getMaterialActivity($id) + { + return Arr::flatten(AssignMaterial::select("m.description as name") + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('assign_material_to_activity.activity_id', $id) + ->get() + ->toArray()); + } + + private function getToolsActivity($id) + { + return Arr::flatten(AssignTools::select("m.name as name") + ->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id") + ->where('assign_tools_to_activity.activity_id', $id) + ->get() + ->toArray()); + } + + private function templateToActivity($id, $proyek_id) + { + $project = Project::findOrFail($proyek_id); + + $rootActivity = Activity::create([ + 'version_gantt_id'=>$id, + 'proyek_id'=>$proyek_id, + 'name'=> $project->nama, + 'kode_sortname'=>$project->kode_sortname, + 'start_date'=> $project->mulai_proyek, + 'end_date'=> $project->akhir_proyek, + 'rencana_biaya'=> str_replace(".","", $project->rencana_biaya), + 'type_activity'=> 'header', + 'created_by'=>$this->currentName, + ]); + + $resultTypeProject = TemplateGantt::where('proyek_type_id',$project + ->type_proyek_id) + ->whereNull('parent_id') + ->orderByRaw('id ASC') + ->get(); + + foreach($resultTypeProject as $objRow){ + $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); + $resultNew = Activity::create([ + 'type_activity'=> $childActivities > 0 ? "project" : "task", + 'version_gantt_id'=>$id, + 'parent_id'=>$rootActivity->id, + 'proyek_id'=>$proyek_id, + 'name'=> $objRow->name_activity, + 'start_date'=>date("Y-m-d H:i:s"), + 'end_date'=>date("Y-m-d H:i:s"), + 'created_by'=>$this->currentName + ]); + $this->getChildrenTemplate($id, $objRow->id, $project->type_project_id ,$proyek_id, $resultNew->id, $project->mulai_proyek); + } + } + + private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay) + { + $data = TemplateGantt::where('proyek_type_id', $type_proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); + foreach($data as $objRow){ + $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); + $resultNew = Activity::create([ + 'type_activity'=> $childActivities > 0 ? "project" : "task", + 'version_gantt_id'=>$id, + 'parent_id'=>$parent_new, + 'proyek_id'=>$proyek_id, + 'name'=> $objRow->name_activity, + 'start_date'=>$firstDay, + 'end_date'=>$firstDay, + 'created_by'=>$this->currentName + ]); + $this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay); + } + } + + public function add(Request $request) + { + $this->validate($request, [ + 'version_gantt_id'=>'required' + ]); + + $data = $request->all(); + $data['name'] = $request->text; + $data['persentase_progress'] = $request->progress; + $data['created_by'] = $this->currentName; + $data['type_activity'] = "task"; + + $parent = $data['parent_id'] ?? null; + if($parent){ + $this->updateTypeProject($parent); + CommentActivity::where('activity_id', $parent)->delete(); + UserToActivity::where('activity_id', $parent)->delete(); + } + + if(!$result = Activity::create($data)) + return response()->json(['status'=>'failed','action'=>'error','code'=> 500], 500); + + return response()->json(['status'=>'success','action'=>'inserted', 'tid'=>$result->id,'code'=>200], 200); + } + + private function updateTypeProject($id) + { + Activity::find($id)->update(["type_activity"=>"project"]); + } + + public function edit($id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + if(!$result = Activity::find($id)) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=> $result], 200); + } + + public function update(Request $request, $id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400); + + $updateBobot = false; + $data = Activity::findOrFail($id); + if(!$data = Activity::find($id)) + return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404); + $parent = $data->parent_id; + $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; + if($data->type_activity!='header') + $dataUpdate['type_activity'] = $request->type; + + if(!$data->update($dataUpdate)) + return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); + + if($parent){ + $this->updateCostPlanning($parent); + $this->updatePersentaseProgress($parent); + $this->updateCostActual($parent); + } + + $this->calculateAllBobot($data->proyek_id, $data->version_gantt_id); + + return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200); + } + + 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); + + $data = Activity::find($id); + + if(!$data = Activity::find($id)) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + if(!$data->update($request->all())) + return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Activity Updated!','code'=> 200], 200); + } + + private function calculateAllBobot($proyek, $gantt) + { + if(Activity::where('version_gantt_id', $gantt)->where("proyek_id", $proyek)->where('type_activity', 'header')->count() == 0) + $totalCost = Activity::select( + DB::raw('sum(cast(rencana_biaya as double precision))') + ) + ->where("proyek_id", $proyek) + ->where("version_gantt_id", $gantt) + ->whereNull("parent_id") + ->first(); + + $rootActivity = Activity::where('version_gantt_id', $gantt) + ->where("proyek_id", $proyek) + ->where('type_activity', 'header') + ->first(); + + $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) + ->where("proyek_id", $proyek) + ->where("version_gantt_id", $gantt) + ->where("parent_id", $rootActivity->id) + ->first(); + + if($totalCost->sum > 0){ + $activities = Activity::where("proyek_id", $proyek)->where("version_gantt_id", $gantt)->get(); + foreach ($activities as $activity) { + $activity->update([ + "bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100, + "updated_by" => $this->currentName + ]); + } + } + return true; + } + + public function delete($id) + { + $data = Activity::findOrFail($id); + + if(!$data = Activity::find($id)) + return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=> 404], 404); + + if($data->parent_id){ + $this->checkForUpdateParent($data->parent_id); + $this->updateCostPlanning($data->parent_id); + $this->updatePersentaseProgress($data->parent_id); + $this->updateCostActual($data->parent_id); + } + + if(!$data->delete()) + return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed deleted!','code'=> 500], 500); + + return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200); + } + + private function checkForUpdateParent($id) + { + if(Activity::where("parent_id", $id)->count() == 0) + Activity::find($id)->update(["type_activity"=>"task"]); + } + + public function getUpdate($id) + { + if(!$data = Activity::find($id)) + return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=>400], 400); + + $data->progress = (int) $data->persentase_progress / 100; + $data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya); + $data->jobs_done = $this->sumVolumeActualMaterial($data->id); + $data->assign_hr = $this->getUserActivity($data->id); + $data->assign_tools = $this->getToolsActivity($data->id); + $data->assign_material = $this->getMaterialActivity($data->id); + return response()->json(['status'=>'success', "data"=> $data,'code'=>200], 200); + } + + private function updateCostPlanning($id) + { + $sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) + ->where("parent_id", $id) + ->first(); + + $activity = Activity::find($id); + $data= array( + "rencana_biaya" => $sumBiaya->sum, + "updated_by" => $this->currentName + ); + + if($activity->update($data) && $activity->parent_id) + $this->updateCostPlanning($activity->parent_id); + } + + private function updatePersentaseProgress($id) + { + $siblings = Activity::where("parent_id", $id); + $sumProgress = $siblings->sum("persentase_progress"); + $totalChild = $siblings->count(); + $activity = Activity::find($id); + + $activity->update([ + "persentase_progress" => $sumProgress / $totalChild, + "updated_by" => $this->currentName + ]); + if($activity->parent_id) + $this->updatePersentaseProgress($activity->parent_id); + } + + private function updateCostActual($id) + { + $activity = Activity::find($id); + + $activity->update([ + "biaya_actual" => Activity::where("parent_id", $id)->sum("biaya_actual"), + "updated_by" => $this->currentName + ]); + if($activity->parent_id) + $this->updateCostActual($activity->parent_id); + } + + public function search(Request $request) + { + $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function getPercentagePerDay(Request $request) + { + $dataPayload = $request->all(); + $allGantt = []; + foreach ($dataPayload['project_id'] as $val) { + $allGantt[] = $this->getLatestGantt($val); + } + + $dataFinal=[]; + foreach ($allGantt as $val) { + $dataProject = Project::find($val['proyek_id']); + $holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get(); + $dateHoliday = []; //$holiday->all(); + foreach ($holidays as $holiday) { + $startH = new \DateTime($holiday->date); + $endH = clone $startH; + $endH->modify('+'.$holiday->duration.' day'); + $intervalH = \DateInterval::createFromDateString('1 day'); + $periodH = new \DatePeriod($startH, $intervalH, $endH); + foreach ($periodH as $dt) { + $dateHoliday[] = $dt->format("Y-m-d"); + } + } + $verGantt = VersionGantt::find($val['last_gantt_id']); + $configOff = $verGantt->config_dayoff; + if($configOff && $configOff!= ""){ + $dayOff = explode(",", $verGantt->config_dayoff); + $dayOff = array_map( + function($value) { return (int)$value; }, + $dayOff + ); + }else{ + $dayOff = []; + } + $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); + if($checkHeader > 0){ + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + $minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); + $maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); + }else{ + $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); + $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); + } + + $begin = new \DateTime($minDate); + $end = new \DateTime($maxDate); + $end = $end->modify( '+1 day' ); + $interval = \DateInterval::createFromDateString('1 day'); + $period = new \DatePeriod($begin, $interval, $end); + $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); + if($checkHeader > 0){ + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + }else{ + $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + } + + $totalRencanaBudget = $totalRencanaBudget->sum; + $currentPercentage = 0; + $dataDate = []; + $dataPercen = []; + foreach ($period as $dt) { + $weekDay = $dt->format("w"); + $currentDate = $dt->format("Y-m-d"); + if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) + { + $totalPercentage = 0; + $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); + if($checkHeader > 0){ + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); + }else{ + $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); + } + + foreach ($dataActivity as $activity) { + $duration = $activity->duration; + if($totalRencanaBudget > 0 && $duration > 0){ + $totalPercentage = $totalPercentage + ((($activity->rencana_biaya/$totalRencanaBudget)*100)/$duration); + } + } + $currentPercentage = $currentPercentage + $totalPercentage; + $dataDate[] = $currentDate; + $dataPercen[] = $currentPercentage; + }else{ + $dataDate[] = $currentDate; + $dataPercen[] = "dateOff"; + } + } + $dataPercentage = array( + "date"=>$dataDate, + "percentage"=>$dataPercen + ); + $dataFinal[] = array( + "proyek_name"=> $dataProject->nama, + "data"=>$dataPercentage + ); + } + + if($dataFinal){ + return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400); + } + } + + + public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) + { + $dataPayload = $request->all(); + $allGantt = []; + if(isset($dataPayload['gannt_id'])){ + $allGantt = $dataPayload['gannt_id']; + }else{ + foreach ($dataPayload['project_id'] as $val) { + $allGantt[] = $this->getLatestGantt($val); + } + } + $dataFinal=[]; + foreach ($allGantt as $keyGantt) { + $dataProject = Project::find($keyGantt['proyek_id']); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first(); + + if($dataHeader){ + $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); + }else{ + $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); + + } + + $minDate = DB::table('assign_material_to_activity as ama') + ->where("ama.proyek_id", $keyGantt['proyek_id']) + ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->min("plan_date"); + + $maxDate = DB::table('assign_material_to_activity as ama') + ->where("ama.proyek_id", $keyGantt['proyek_id']) + ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->max("plan_date"); + + $begin = new \DateTime($minDate); + $end = new \DateTime($maxDate); + $end2 = new \DateTime($maxDate); + $interval = \DateInterval::createFromDateString('1 day'); + $period = new \DatePeriod($begin, $interval, $end); + $arr_ActualM = []; + $tempDate = []; + $tempPercentage = []; + $tempTtlPercentPlan=0; + $tempTtlPercentActual=0; + + $currentACWP = 0; + $budgetControlACWP = 0; + $currentProgressActivity = 0; + $currentBCWP = 0; + $budgetControlBCWP = 0; + + foreach ($period as $dt) { + $dataPlanM = DB::table('assign_material_to_activity as ama') + ->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') + ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + ->where('ama.proyek_id', '=', $keyGantt['proyek_id']) + ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->whereDate('ama.plan_date', $dt->format("Y-m-d")) + ->get(); + $dataActualM = DB::table('report_activity_material as ram') + ->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') + ->join('m_activity as a', 'a.id', '=', 'ram.activity_id') + ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->where('a.proyek_id', '=', $keyGantt['proyek_id']) + ->whereDate('ram.report_date', $dt->format("Y-m-d")) + ->get(); + $dataTempPlan = []; + $x = 0; + $sumPercentagePlan=0; + $totalACWP = isset($totalACWP) ? $totalACWP : 0; + $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; + + foreach ($dataPlanM as $keyPlanM) { + $sumVolPlan = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyPlanM->activity_id) + ->groupBy('activity_id') + ->first(); + $dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; + $dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning; + $dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date; + $dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity; + $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan; + $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan [$x]['duration'] = $keyPlanM->duration; + $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; + $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; + $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; + $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; + $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + $x++; + } + + $w = 0; + $dataTempReport = []; + $sumPercentageActual=0; + foreach ($dataActualM as $keyActualM) { + $sumVolActual = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyActualM->activity_id) + ->groupBy('activity_id') + ->first(); + $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; + $dataTempReport [$w]['qty'] = $keyActualM->qty; + $dataTempReport [$w]['report_date'] = $keyActualM->report_date; + $dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; + $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; + $dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; + $dataTempReport [$w]['duration'] = $keyActualM->duration; + $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; + $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + $dataTempReport [$w]['totalacwp'] = $totalACWP; + $w++; + } + + $arr_ActualM[] = array( + 'date'=>$dt->format("Y-m-d"), + 'percentPlan'=>$sumPercentagePlan, + 'percentActual'=>$sumPercentageActual, + 'plan'=>$dataTempPlan, + 'actual'=>$dataTempReport, + ); + if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ + if($dt->format("w")==1){ + if($totalACWP > 0 ){ + $budgetControlACWP = $currentACWP + $totalACWP; + } + if($totalBCWP > 0 ){ + $budgetControlBCWP = $currentBCWP + $totalBCWP; + } + + $tempTtlPercentPlan+= $sumPercentagePlan; + $tempTtlPercentActual+= $sumPercentageActual; + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $tempDate[] = array($dt->format("Y-m-d"), 0, 0); + }else if($dt->format("Y-m-d") == $end2->format("Y-m-d")) { + $tempTtlPercentPlan+= $sumPercentagePlan; + $tempTtlPercentActual+= $sumPercentageActual; + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $tempDate[] = array($dt->format("Y-m-d"), 0, 0); + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; + } + }else{ + $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); + $tempDate[] = array($dt->format("Y-m-d"), 0, 0); + } + } + + if(round($totalACWP,0) > $totalRencanaBudget){ + $estimatedCost = round($totalACWP,0)+0; + }else{ + $estimatedCost = ($totalRencanaBudget+0); + } + $costDeviation = $totalRencanaBudget - $estimatedCost; if($costDeviation > 0){ $potential = "SAVING"; } else { $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; } - $dataResponse = array( - "date" =>$tempDate, - "percentage" =>$tempPercentage, - "data_details" =>$arr_ActualM, - "budget_control" =>array("current_budget"=> $totalRencanaBudget, - "acwp" => round($totalACWP,0), - "bcwp" => round($totalBCWP,0), - "rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), - "add_cost_to_complete" => 0, - "estimated_at_completion" => $estimatedCost, - "cost_deviation" => $costDeviation, - "potential" => $potential, - ) - ); - - $dataFinal[] = array( - "proyek_name"=> $dataProject->nama, - "data"=>$dataResponse, - "allGant"=>$allGantt - ); - } - - return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); - - } - - public function getCalculateCurvaSDays(Request $request) - { - $dataPayload = $request->all(); - $allGantt = []; - foreach ($dataPayload['project_id'] as $val) { - $allGantt[] = $this->getMaxVersionGantt($val); - } - - $dataFinal=[]; - foreach ($allGantt as $val) { - $dataProject = Project::find($val['proyek_id']); - $holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get(); - $dateHoliday = []; //$holiday->all(); - foreach ($holidays as $holiday) { - $startH = new \DateTime($holiday->date); - $endH = clone $startH; - $endH->modify('+'.$holiday->duration.' day'); - $intervalH = \DateInterval::createFromDateString('1 day'); - $periodH = new \DatePeriod($startH, $intervalH, $endH); - foreach ($periodH as $dt) { - $dateHoliday[] = $dt->format("Y-m-d"); - } - } - $verGantt = VersionGantt::find($val['last_gantt_id']); - $configOff = $verGantt->config_dayoff; - if($configOff && $configOff!= ""){ - $dayOff = explode(",", $verGantt->config_dayoff); - $dayOff = array_map( - function($value) { return (int)$value; }, - $dayOff - ); - }else{ - $dayOff = []; - } - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - if($dataHeader){ - $minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - }else{ - $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - } - - $begin = new \DateTime($minDate); - $end = new \DateTime($maxDate); - $interval = \DateInterval::createFromDateString('1 day'); - $period = new \DatePeriod($begin, $interval, $end); - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - if($dataHeader){ - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - }else{ - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - } - - $totalRencanaBudget = $totalRencanaBudget->sum; - $currentPercentage = 0; - $currentACWP = 0; - $currentProgressActivity = 0; - $currentBCWP = 0; - $dataDate = []; - $dataPercen = []; - $testdata = []; - foreach ($period as $dt) { - $weekDay = $dt->format("w"); - $currentDate = $dt->format("Y-m-d"); - $testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate); - if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) - { - $totalPercentage = 0; - $totalACWP = 0; - $totalProgressActivity = 0; - $totalBCWP = 0; - $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); - foreach ($dataActivity as $activity) { - - $duration = $activity->duration; - if($totalRencanaBudget > 0 && $duration > 0){ - $totalPercentage += $activity->bobot_planning/$duration; - if($activity->biaya_actual > 0 && $activity->persentase_progress){ - $totalACWP += $activity->biaya_actual/$duration; - $totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration; - $totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100; - } - } - } - - $currentPercentage = round(($currentPercentage + $totalPercentage), 0); - $currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP; - $currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0); - $currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP; - $currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage; - $currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity; - - - $dataDate[] = array($currentDate, $currentBCWP, $currentACWP); - $dataPercen[] = array($currentPercentage, $currentProgressActivity); - }else{ - $dataDate[] = $currentDate; - $dataPercen[] = array($currentPercentage,$currentProgressActivity); - } - } - $dataPercentage = array( - "date"=>$dataDate, - "percentage"=>$dataPercen - ); - $dataFinal[] = array( - "proyek_name"=> $dataProject->nama, - "data"=>$dataPercentage - ); - } - - if($dataFinal){ - return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'testdata' => $testdata, '$period' => $period, 'totalRecord'=>1], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400); - } - } - - private function getMaxVersionGantt($id){ - $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); - $data = array( - "last_gantt_id" => $maxGanttId, - "proyek_id" => $id - ); - return $data; - } - - public function setBaseline($gantt_id) - { - $activities = Activity::where("version_gantt_id", $gantt_id)->get(); - - foreach ($activities as $activity) { - $planned_start = $activity->start_date; - $planned_end = $activity->end_date; - $willUpdated = Activity::find($activity->id); - $dataUpdate = array( - "planned_start"=>$planned_start, - "planned_end"=>$planned_end - ); - $willUpdated->update($dataUpdate); - } - - return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=>200], 200); - } - - public function synchronizeReport($gantt_id) - { - $activities = Activity::where("version_gantt_id", $gantt_id)->get(); - $reports = []; - - foreach($activities as $activity) { - $activity_id = $activity->id; - $countReports = ReportActivity::where('activity_id', $activity_id)->count(); - if ($countReports === 1) { - $dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get(); - foreach($dataReports as $dr) { - $reports[] = array( - 'activity_id'=>$activity_id, - 'min_date'=>$dr->report_date, - 'max_date'=>date_modify(date_create($dr->report_date), "1 days") - ); - } - } - elseif ($countReports > 1) { - $firstReport = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->first(); - $lastReport = ReportActivity::where('activity_id', $activity_id)->orderByDesc('report_date')->first(); - $reports[] = array( - 'activity_id'=>$activity_id, - 'min_date'=>$firstReport->report_date, - 'max_date'=>date_modify(date_create($lastReport->report_date), "1 days") - ); - - } - } - - for ($i=0; $i < count($reports); $i++) { - $activity = Activity::find($reports[$i]['activity_id']); - $activity->start_date = $reports[$i]['min_date']; - $activity->end_date = $reports[$i]['max_date']; - $activity->save(); - } - - return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); - } + $dataResponse = array( + "date" =>$tempDate, + "percentage" =>$tempPercentage, + "data_details" =>$arr_ActualM, + "budget_control" =>array("current_budget"=> $totalRencanaBudget, + "acwp" => round($totalACWP,0), + "bcwp" => round($totalBCWP,0), + "rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), + "add_cost_to_complete" => 0, + "estimated_at_completion" => $estimatedCost, + "cost_deviation" => $costDeviation, + "potential" => $potential, + ) + ); + + $dataFinal[] = array( + "proyek_name"=> $dataProject->nama, + "data"=>$dataResponse, + "allGant"=>$allGantt + ); + } + + return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); + + } + + public function getCalculateCurvaSDays(Request $request) + { + $dataPayload = $request->all(); + $allGantt = []; + foreach ($dataPayload['project_id'] as $val) { + $allGantt[] = $this->getLatestGantt($val); + } + + $dataFinal=[]; + foreach ($allGantt as $val) { + $dataProject = Project::find($val['proyek_id']); + $holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get(); + $dateHoliday = []; //$holiday->all(); + foreach ($holidays as $holiday) { + $startH = new \DateTime($holiday->date); + $endH = clone $startH; + $endH->modify('+'.$holiday->duration.' day'); + $intervalH = \DateInterval::createFromDateString('1 day'); + $periodH = new \DatePeriod($startH, $intervalH, $endH); + foreach ($periodH as $dt) { + $dateHoliday[] = $dt->format("Y-m-d"); + } + } + $verGantt = VersionGantt::find($val['last_gantt_id']); + $configOff = $verGantt->config_dayoff; + if($configOff && $configOff!= ""){ + $dayOff = explode(",", $verGantt->config_dayoff); + $dayOff = array_map( + function($value) { return (int)$value; }, + $dayOff + ); + }else{ + $dayOff = []; + } + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + if($dataHeader){ + $minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); + $maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); + }else{ + $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); + $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); + } + + $begin = new \DateTime($minDate); + $end = new \DateTime($maxDate); + $interval = \DateInterval::createFromDateString('1 day'); + $period = new \DatePeriod($begin, $interval, $end); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + if($dataHeader){ + $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + }else{ + $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + } + + $totalRencanaBudget = $totalRencanaBudget->sum; + $currentPercentage = 0; + $currentACWP = 0; + $currentProgressActivity = 0; + $currentBCWP = 0; + $dataDate = []; + $dataPercen = []; + $testdata = []; + foreach ($period as $dt) { + $weekDay = $dt->format("w"); + $currentDate = $dt->format("Y-m-d"); + $testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate); + if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) + { + $totalPercentage = 0; + $totalACWP = 0; + $totalProgressActivity = 0; + $totalBCWP = 0; + $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); + foreach ($dataActivity as $activity) { + + $duration = $activity->duration; + if($totalRencanaBudget > 0 && $duration > 0){ + $totalPercentage += $activity->bobot_planning/$duration; + if($activity->biaya_actual > 0 && $activity->persentase_progress){ + $totalACWP += $activity->biaya_actual/$duration; + $totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration; + $totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100; + } + } + } + + $currentPercentage = round(($currentPercentage + $totalPercentage), 0); + $currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP; + $currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0); + $currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP; + $currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage; + $currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity; + + + $dataDate[] = array($currentDate, $currentBCWP, $currentACWP); + $dataPercen[] = array($currentPercentage, $currentProgressActivity); + }else{ + $dataDate[] = $currentDate; + $dataPercen[] = array($currentPercentage,$currentProgressActivity); + } + } + $dataPercentage = array( + "date"=>$dataDate, + "percentage"=>$dataPercen + ); + $dataFinal[] = array( + "proyek_name"=> $dataProject->nama, + "data"=>$dataPercentage + ); + } + + if($dataFinal){ + return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'testdata' => $testdata, '$period' => $period, 'totalRecord'=>1], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400); + } + } + + private function getLatestGantt($id){ + return array( + "last_gantt_id" => VersionGantt::where("proyek_id", $id)->latest(), + "proyek_id" => $id + ); + } + + public function setBaseline($gantt_id) + { + $activities = Activity::where("version_gantt_id", $gantt_id)->get(); + + foreach ($activities as $activity) { + $activity->update([ + "planned_start"=>$activity->start_date, + "planned_end"=>$activity->end_date, + ]); + } + + return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200); + } + + public function synchronizeReport($gantt_id) + { + $activities = Activity::where("version_gantt_id", $gantt_id)->get(); + $reports = []; + + foreach($activities as $activity) { + $activity_id = $activity->id; + $countReports = ReportActivity::where('activity_id', $activity_id)->count(); + if ($countReports === 1) { + $dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get(); + foreach($dataReports as $dr) { + $reports[] = array( + 'activity_id'=>$activity_id, + 'min_date'=>$dr->report_date, + 'max_date'=>date_modify(date_create($dr->report_date), "1 days") + ); + } + } + if ($countReports > 1) { + $firstReport = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->first(); + $lastReport = ReportActivity::where('activity_id', $activity_id)->orderByDesc('report_date')->first(); + $reports[] = array( + 'activity_id'=>$activity_id, + 'min_date'=>$firstReport->report_date, + 'max_date'=>date_modify(date_create($lastReport->report_date), "1 days") + ); + + } + } + + for ($i=0; $i < count($reports); $i++) { + $activity = Activity::find($reports[$i]['activity_id']); + $activity->start_date = $reports[$i]['min_date']; + $activity->end_date = $reports[$i]['max_date']; + $activity->save(); + } + + return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); + } } From 168eb9cae9a30db4f76f26e7a1e54218c6954baa Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Fri, 22 Jul 2022 15:47:36 +0700 Subject: [PATCH 03/11] refactor, move calculations to model --- app/Http/Controllers/ActivityController.php | 301 +------------------- app/Models/Activity.php | 150 +++++++++- 2 files changed, 155 insertions(+), 296 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 5a133dd..9c384c8 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -3,29 +3,25 @@ namespace App\Http\Controllers; use App\Models\Activity; -use App\Models\AssignMaterial; -use App\Models\AssignTools; use App\Models\CommentActivity; use App\Models\Holiday; use App\Models\Link; use App\Models\Project; use App\Models\ReportActivity; -use App\Models\ReportActivityMaterial; use App\Models\TemplateGantt; use App\Models\UserToActivity; use App\Models\VersionGantt; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; -use Illuminate\Support\Arr; class ActivityController extends Controller { public function getByGanttId($id, $proyek_id) { - if(Activity::where("version_gantt_id", $id)->count() == 0) - $dataGantt = $this->getDataActivity($id); + if(Activity::where("version_gantt_id", $id)->count() == 0) { + $this->cloneTemplate($id, $proyek_id); + } - $this->templateToActivity($id, $proyek_id); $dataGantt = $this->getDataActivity($id); return response()->json(['status'=>'success','data'=> $dataGantt,'code'=>200], 200); @@ -33,7 +29,6 @@ class ActivityController extends Controller private function getDataActivity($id) { - $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); $startDate = date_create($dataHeader->start_date); $endDate = date_create($dataHeader->end_date); @@ -53,20 +48,15 @@ class ActivityController extends Controller $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->jobs_done = $this->sumVolumeActualMaterial($objRow->id); - $objRow->assign_hr = $this->getUserActivity($objRow->id); - $objRow->assign_tools = $this->getToolsActivity($objRow->id); - $objRow->assign_material = $this->getMaterialActivity($objRow->id); $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; + $objRow->progress = (int) $objRow->persentase_progress / 100; $dataChildren = $this->getChildren($id, $objRow->id); $objRow->type = $type; $finalData[] = $objRow; @@ -104,10 +94,6 @@ class ActivityController extends Controller foreach($data as $objRow){ $objRow->parent = $parent_id; $objRow->text = $objRow->name; - $objRow->jobs_done = $this->sumVolumeActualMaterial($objRow->id); - $objRow->assign_hr = $this->getUserActivity($objRow->id); - $objRow->assign_tools = $this->getToolsActivity($objRow->id); - $objRow->assign_material = $this->getMaterialActivity($objRow->id); $objRow->progress = (int)$objRow->persentase_progress/100; $startDate = date_create($objRow->start_date); $endDate = date_create($objRow->end_date); @@ -129,54 +115,7 @@ class ActivityController extends Controller return $finalData; } - private function sumVolumeActualMaterial($id) - { - $tmpPercentage = []; - - $dataPlan = AssignMaterial::where('activity_id', $id)->get(); - if($dataPlan->isEmpty()) - 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; - } - - private function getUserActivity($id) - { - return Arr::flatten(UserToActivity::select("u.name as name") - ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") - ->where('assign_hr_to_activity.activity_id', $id) - ->get() - ->toArray()); - } - - private function getMaterialActivity($id) - { - return Arr::flatten(AssignMaterial::select("m.description as name") - ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->where('assign_material_to_activity.activity_id', $id) - ->get() - ->toArray()); - } - - private function getToolsActivity($id) - { - return Arr::flatten(AssignTools::select("m.name as name") - ->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id") - ->where('assign_tools_to_activity.activity_id', $id) - ->get() - ->toArray()); - } - - private function templateToActivity($id, $proyek_id) + private function cloneTemplate($id, $proyek_id) { $project = Project::findOrFail($proyek_id); @@ -248,6 +187,7 @@ class ActivityController extends Controller $parent = $data['parent_id'] ?? null; if($parent){ $this->updateTypeProject($parent); + Activity::find($parent)->update(["type_activity"=>"project"]); CommentActivity::where('activity_id', $parent)->delete(); UserToActivity::where('activity_id', $parent)->delete(); } @@ -258,11 +198,6 @@ class ActivityController extends Controller return response()->json(['status'=>'success','action'=>'inserted', 'tid'=>$result->id,'code'=>200], 200); } - private function updateTypeProject($id) - { - Activity::find($id)->update(["type_activity"=>"project"]); - } - public function edit($id){ if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); @@ -279,10 +214,8 @@ class ActivityController extends Controller return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400); $updateBobot = false; - $data = Activity::findOrFail($id); if(!$data = Activity::find($id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404); - $parent = $data->parent_id; $dataUpdate = $request->all(); $oldRencanaBiaya = $data->rencana_biaya; @@ -299,14 +232,6 @@ class ActivityController extends Controller if(!$data->update($dataUpdate)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); - if($parent){ - $this->updateCostPlanning($parent); - $this->updatePersentaseProgress($parent); - $this->updateCostActual($parent); - } - - $this->calculateAllBobot($data->proyek_id, $data->version_gantt_id); - return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200); } @@ -325,66 +250,17 @@ class ActivityController extends Controller return response()->json(['status'=>'success','message'=>'Activity Updated!','code'=> 200], 200); } - private function calculateAllBobot($proyek, $gantt) - { - if(Activity::where('version_gantt_id', $gantt)->where("proyek_id", $proyek)->where('type_activity', 'header')->count() == 0) - $totalCost = Activity::select( - DB::raw('sum(cast(rencana_biaya as double precision))') - ) - ->where("proyek_id", $proyek) - ->where("version_gantt_id", $gantt) - ->whereNull("parent_id") - ->first(); - - $rootActivity = Activity::where('version_gantt_id', $gantt) - ->where("proyek_id", $proyek) - ->where('type_activity', 'header') - ->first(); - - $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) - ->where("proyek_id", $proyek) - ->where("version_gantt_id", $gantt) - ->where("parent_id", $rootActivity->id) - ->first(); - - if($totalCost->sum > 0){ - $activities = Activity::where("proyek_id", $proyek)->where("version_gantt_id", $gantt)->get(); - foreach ($activities as $activity) { - $activity->update([ - "bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100, - "updated_by" => $this->currentName - ]); - } - } - return true; - } - public function delete($id) { - $data = Activity::findOrFail($id); - if(!$data = Activity::find($id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=> 404], 404); - if($data->parent_id){ - $this->checkForUpdateParent($data->parent_id); - $this->updateCostPlanning($data->parent_id); - $this->updatePersentaseProgress($data->parent_id); - $this->updateCostActual($data->parent_id); - } - if(!$data->delete()) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed deleted!','code'=> 500], 500); return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200); } - private function checkForUpdateParent($id) - { - if(Activity::where("parent_id", $id)->count() == 0) - Activity::find($id)->update(["type_activity"=>"task"]); - } - public function getUpdate($id) { if(!$data = Activity::find($id)) @@ -392,56 +268,9 @@ class ActivityController extends Controller $data->progress = (int) $data->persentase_progress / 100; $data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya); - $data->jobs_done = $this->sumVolumeActualMaterial($data->id); - $data->assign_hr = $this->getUserActivity($data->id); - $data->assign_tools = $this->getToolsActivity($data->id); - $data->assign_material = $this->getMaterialActivity($data->id); return response()->json(['status'=>'success', "data"=> $data,'code'=>200], 200); } - private function updateCostPlanning($id) - { - $sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) - ->where("parent_id", $id) - ->first(); - - $activity = Activity::find($id); - $data= array( - "rencana_biaya" => $sumBiaya->sum, - "updated_by" => $this->currentName - ); - - if($activity->update($data) && $activity->parent_id) - $this->updateCostPlanning($activity->parent_id); - } - - private function updatePersentaseProgress($id) - { - $siblings = Activity::where("parent_id", $id); - $sumProgress = $siblings->sum("persentase_progress"); - $totalChild = $siblings->count(); - $activity = Activity::find($id); - - $activity->update([ - "persentase_progress" => $sumProgress / $totalChild, - "updated_by" => $this->currentName - ]); - if($activity->parent_id) - $this->updatePersentaseProgress($activity->parent_id); - } - - private function updateCostActual($id) - { - $activity = Activity::find($id); - - $activity->update([ - "biaya_actual" => Activity::where("parent_id", $id)->sum("biaya_actual"), - "updated_by" => $this->currentName - ]); - if($activity->parent_id) - $this->updateCostActual($activity->parent_id); - } - public function search(Request $request) { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); @@ -756,124 +585,6 @@ class ActivityController extends Controller } - public function getCalculateCurvaSDays(Request $request) - { - $dataPayload = $request->all(); - $allGantt = []; - foreach ($dataPayload['project_id'] as $val) { - $allGantt[] = $this->getLatestGantt($val); - } - - $dataFinal=[]; - foreach ($allGantt as $val) { - $dataProject = Project::find($val['proyek_id']); - $holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get(); - $dateHoliday = []; //$holiday->all(); - foreach ($holidays as $holiday) { - $startH = new \DateTime($holiday->date); - $endH = clone $startH; - $endH->modify('+'.$holiday->duration.' day'); - $intervalH = \DateInterval::createFromDateString('1 day'); - $periodH = new \DatePeriod($startH, $intervalH, $endH); - foreach ($periodH as $dt) { - $dateHoliday[] = $dt->format("Y-m-d"); - } - } - $verGantt = VersionGantt::find($val['last_gantt_id']); - $configOff = $verGantt->config_dayoff; - if($configOff && $configOff!= ""){ - $dayOff = explode(",", $verGantt->config_dayoff); - $dayOff = array_map( - function($value) { return (int)$value; }, - $dayOff - ); - }else{ - $dayOff = []; - } - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - if($dataHeader){ - $minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - }else{ - $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - } - - $begin = new \DateTime($minDate); - $end = new \DateTime($maxDate); - $interval = \DateInterval::createFromDateString('1 day'); - $period = new \DatePeriod($begin, $interval, $end); - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - if($dataHeader){ - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - }else{ - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - } - - $totalRencanaBudget = $totalRencanaBudget->sum; - $currentPercentage = 0; - $currentACWP = 0; - $currentProgressActivity = 0; - $currentBCWP = 0; - $dataDate = []; - $dataPercen = []; - $testdata = []; - foreach ($period as $dt) { - $weekDay = $dt->format("w"); - $currentDate = $dt->format("Y-m-d"); - $testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate); - if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) - { - $totalPercentage = 0; - $totalACWP = 0; - $totalProgressActivity = 0; - $totalBCWP = 0; - $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); - foreach ($dataActivity as $activity) { - - $duration = $activity->duration; - if($totalRencanaBudget > 0 && $duration > 0){ - $totalPercentage += $activity->bobot_planning/$duration; - if($activity->biaya_actual > 0 && $activity->persentase_progress){ - $totalACWP += $activity->biaya_actual/$duration; - $totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration; - $totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100; - } - } - } - - $currentPercentage = round(($currentPercentage + $totalPercentage), 0); - $currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP; - $currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0); - $currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP; - $currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage; - $currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity; - - - $dataDate[] = array($currentDate, $currentBCWP, $currentACWP); - $dataPercen[] = array($currentPercentage, $currentProgressActivity); - }else{ - $dataDate[] = $currentDate; - $dataPercen[] = array($currentPercentage,$currentProgressActivity); - } - } - $dataPercentage = array( - "date"=>$dataDate, - "percentage"=>$dataPercen - ); - $dataFinal[] = array( - "proyek_name"=> $dataProject->nama, - "data"=>$dataPercentage - ); - } - - if($dataFinal){ - return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'testdata' => $testdata, '$period' => $period, 'totalRecord'=>1], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400); - } - } - private function getLatestGantt($id){ return array( "last_gantt_id" => VersionGantt::where("proyek_id", $id)->latest(), diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 94f2ae4..f7dc9a8 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -2,7 +2,12 @@ namespace App\Models; +use App\Models\AssignMaterial; +use App\Models\AssignTools; +use App\Models\ReportActivityMaterial; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Arr; +use Illuminate\Support\Facades\DB; class Activity extends Model { @@ -15,9 +20,152 @@ class Activity extends Model 'proyek_id', 'parent_id', 'kode_sortname', 'name', 'rencana_biaya', 'start_date', 'end_date', 'area_kerja', 'biaya_actual', 'persentase_bobot', 'persentase_progress', 'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan', - 'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom', + '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' ]; + + protected $attributes = [ + 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' + ]; + + protected $appends = [ + 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' + ]; + + public static function boot() { + parent::boot(); + + static::updated(function($data) { + + // update bobot + if(Activity::where('version_gantt_id', $data->version_gantt_id)->where("proyek_id", $data->proyek_id)->where('type_activity', 'header')->count() == 0) + $totalCost = Activity::select( + DB::raw('sum(cast(rencana_biaya as double precision))') + ) + ->where("proyek_id", $data->proyek_id) + ->where("version_gantt_id", $data->version_gantt_id) + ->whereNull("parent_id") + ->first(); + + $rootActivity = Activity::where('version_gantt_id', $data->version_gantt_id) + ->where("proyek_id", $data->proyek_id) + ->where('type_activity', 'header') + ->first(); + + $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) + ->where("proyek_id", $data->proyek_id) + ->where("version_gantt_id", $data->version_gantt_id) + ->where("parent_id", $rootActivity->id) + ->first(); + + if($totalCost->sum > 0){ + $activities = Activity::where("proyek_id", $data->proyek_id)->where("version_gantt_id", $data->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(); + } + } + + $data->updateCostPlanning(); + $data->updatePersentaseProgress(); + $data->updateCostActual(); + }); + + static::deleted(function($data) { + if(Activity::where("parent_id", $data->parent_id)->count() == 0) + Activity::find($data->parent_id)->update(["type_activity"=>"task"]); + + $data->updateCostPlanning(); + $data->updatePersentaseProgress(); + $data->updateCostActual(); + }); + + } + + private function updateCostActual() + { + $actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual"); + $this->biaya_actual = $actualCost; + if($parent = Activity::find($this->parent_id)){ + $parent->update([ + "biaya_actual" => $actualCost + ]); + } + } + + private function updatePersentaseProgress() + { + $siblings = Activity::where("parent_id", $this->parent_id); + $sumProgress = $siblings->sum("persentase_progress"); + $totalChild = $siblings->count(); + + $this->persentage_progress = $sumProgress / $totalChild; + if($parent = Activity::find($this->parent_id)){ + $parent->update([ + "persentase_progress" => $sumProgress / $totalChild, + ]); + } + } + + private function updateCostPlanning() { + $sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) + ->where("parent_id", $this->parent_id) + ->first(); + $this->rencana_biaya = $sumBiaya->sum; + if($parent = Activity::find($this->parent_id)){ + $parent->update([ + "rencana_biaya" => $sumBiaya->sum, + ]); + } + } + + public function getJobsDoneAttribute() + { + $tmpPercentage = []; + $dataPlan = AssignMaterial::where('activity_id', $this->id)->get(); + if($dataPlan->isEmpty()) + 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; + } + + public function getAssignHrAttribute() + { + return Arr::flatten(UserToActivity::select("u.name as name") + ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") + ->where('assign_hr_to_activity.activity_id', $this->id) + ->get() + ->toArray()); + } + + public function getAssignMaterialAttribute() + { + return Arr::flatten(AssignMaterial::select("m.description as name") + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('assign_material_to_activity.activity_id', $this->id) + ->get() + ->toArray()); + } + + public function getAssignToolsAttribute() + { + return Arr::flatten(AssignTools::select("m.name as name") + ->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id") + ->where('assign_tools_to_activity.activity_id', $this->id) + ->get() + ->toArray()); + } + } From 943c9738255e01a60cd5553eb991a717975c1315 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Fri, 22 Jul 2022 15:55:30 +0700 Subject: [PATCH 04/11] deleted --- activity_log.txt | 135 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/activity_log.txt b/activity_log.txt index 1c6c2d1..974774c 100755 --- a/activity_log.txt +++ b/activity_log.txt @@ -18,3 +18,138 @@ Deleted: (10000000 * 1), Cost plan old: 10000000 | -0 Data type (double * double), double | double Data type origin (double * double), string | double ------ +2022-07-21 15:17:44: 1670 New Activity +Added: (10000 * 1), Cost plan old: 10000.00 | +20000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-21 16:07:29: 1686 Planning +Added: (10000 * 1), Cost plan old: 0.00 | +10000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-21 17:47:31: 2013 P1 +Added: (100000 * 5), Cost plan old: | +500000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-21 17:47:49: 1674 Execution +Added: (250000 * 3), Cost plan old: | +750000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-21 17:47:57: 2013 P1 +Deleted: (100000 * 5), Cost plan old: 500000.00 | -0 +Data type (double * double), double | double +Data type origin (string * string), string | double +------ +2022-07-21 21:37:55: 2088 Phase 1 +Added: (500000 * 2), Cost plan old: 100000.00 | +1100000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-21 21:38:31: 2088 Phase 1 +Deleted: (500000 * 2), Cost plan old: 1100000.00 | -100000 +Data type (double * double), double | double +Data type origin (string * string), string | double +------ +2022-07-21 21:40:02: 2101 Phase 1 +Added: (10000 * 2), Cost plan old: | +20000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-21 21:42:04: 2101 Phase 1 +Added: (5000 * 1), Cost plan old: 25000.00 | +30000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-21 21:45:50: 2081 New Activity +Added: (10000 * 3), Cost plan old: | +30000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-21 21:46:04: 2081 New Activity +Added: (20000 * 1), Cost plan old: 30000.00 | +50000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-21 21:53:05: 2020 New Act +Added: (10000 * 2), Cost plan old: | +20000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-21 21:53:16: 1674 Execution +Deleted: (250000 * 3), Cost plan old: 750000.00 | -0 +Data type (double * double), double | double +Data type origin (string * string), string | double +------ +2022-07-21 23:16:21: 2325 B2 +Deleted: (50000 * 2), Cost plan old: 100000.00 | -0 +Data type (double * double), double | double +Data type origin (string * string), string | double +------ +2022-07-21 23:37:45: 2437 A +Added: (50000 * 2), Cost plan old: | +100000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-21 23:38:27: 2438 B +Added: (200000 * 5), Cost plan old: | +1000000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-21 23:43:22: 2438 B +Added: (20000 * 5), Cost plan old: 0.00 | +100000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-21 23:44:07: 2437 A +Added: (20000 * 5), Cost plan old: 0.00 | +100000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-21 23:54:51: 2438 D +Deleted: (20000 * 5), Cost plan old: 100000.00 | -0 +Data type (double * double), double | double +Data type origin (string * string), string | double +------ +2022-07-21 23:55:12: 2438 D +Added: (25000 * 2), Cost plan old: 0.00 | +50000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-22 00:23:54: 2437 cccc +Added: (10000 * 2), Cost plan old: 5000.00 | +25000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-22 00:36:26: 2433 Planning +Added: (100000 * 5), Cost plan old: | +500000 +Data type (double * double), double | double +Data type origin (string * NULL), NULL | double +------ +2022-07-22 00:36:43: 2433 Planning +Deleted: (100000 * 5), Cost plan old: 500000.00 | -0 +Data type (double * double), double | double +Data type origin (string * string), string | double +------ +2022-07-22 00:40:58: 2432 x +Added: (12 * 1), Cost plan old: 0.00 | +12 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-22 01:06:27: 2445 New Activity +Added: (100000 * 5), Cost plan old: 200000.00 | +700000 +Data type (double * double), double | double +Data type origin (string * NULL), string | double +------ +2022-07-22 14:44:14: 2445 e +Added: (100000 * 2), Cost plan old: 5000.00 | +205000 +Data type (double * double), double | double +Data type origin (string * NULL), string | string +------ +2022-07-22 14:45:52: 2445 e +Deleted: (100000 * 2), Cost plan old: 205000.00 | -5000 +Data type (double * double), double | double +Data type origin (string * string), string | string +------ From a746f821c3b238bb3b9afef940eeba9042e0ffe5 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Sun, 24 Jul 2022 05:22:23 +0700 Subject: [PATCH 05/11] WIP: implement decimal --- app/Http/Controllers/Controller.php | 17 -------- app/Models/Activity.php | 68 +++++++++++++++-------------- config/decimal.php | 5 +++ 3 files changed, 40 insertions(+), 50 deletions(-) create mode 100644 config/decimal.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index cefe1a4..742db50 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -250,21 +250,4 @@ class Controller extends BaseController $totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost"); return $totalCost; } - - protected function updatedCostPlanning($id) - { - $sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("parent_id", $id)->first(); - $dataActivity = Activity::find($id); - $dataUpdate = array( - "rencana_biaya" => $sumBiaya->sum, - "updated_by" => $this->currentName - ); - $dataActivity->update($dataUpdate); - if($dataActivity){ - $parent = $dataActivity->parent_id; - if($parent && (int)$parent > 0){ - $this->updateCostPlanning($parent); - } - } - } } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index f7dc9a8..01957ed 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -38,39 +38,7 @@ class Activity extends Model parent::boot(); static::updated(function($data) { - - // update bobot - if(Activity::where('version_gantt_id', $data->version_gantt_id)->where("proyek_id", $data->proyek_id)->where('type_activity', 'header')->count() == 0) - $totalCost = Activity::select( - DB::raw('sum(cast(rencana_biaya as double precision))') - ) - ->where("proyek_id", $data->proyek_id) - ->where("version_gantt_id", $data->version_gantt_id) - ->whereNull("parent_id") - ->first(); - - $rootActivity = Activity::where('version_gantt_id', $data->version_gantt_id) - ->where("proyek_id", $data->proyek_id) - ->where('type_activity', 'header') - ->first(); - - $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) - ->where("proyek_id", $data->proyek_id) - ->where("version_gantt_id", $data->version_gantt_id) - ->where("parent_id", $rootActivity->id) - ->first(); - - if($totalCost->sum > 0){ - $activities = Activity::where("proyek_id", $data->proyek_id)->where("version_gantt_id", $data->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(); - } - } - + $data->updateBobot(); $data->updateCostPlanning(); $data->updatePersentaseProgress(); $data->updateCostActual(); @@ -87,6 +55,40 @@ class Activity extends Model } + private function updateBobot() + { + 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(); + + $rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) + ->where("proyek_id", $this->proyek_id) + ->where('type_activity', 'header') + ->first(); + + $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){ + $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(); + } + } + } + private function updateCostActual() { $actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual"); diff --git a/config/decimal.php b/config/decimal.php new file mode 100644 index 0000000..9a4cb27 --- /dev/null +++ b/config/decimal.php @@ -0,0 +1,5 @@ + 5, + ]; +?> From 96ec1c8d4501f6cb40d9a23f4b15a32836071f3c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Jul 2022 16:35:58 +0700 Subject: [PATCH 06/11] add cors middleware --- bootstrap/app.php | 251 +++++++------- routes/web.php | 818 +++++++++++++++++++++++----------------------- 2 files changed, 535 insertions(+), 534 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index 4d429ac..ca0155b 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,125 +1,126 @@ -bootstrap(); - -date_default_timezone_set(env('APP_TIMEZONE', 'UTC')); - -/* -|-------------------------------------------------------------------------- -| Create The Application -|-------------------------------------------------------------------------- -| -| Here we will load the environment and create the application instance -| that serves as the central piece of this framework. We'll use this -| application as an "IoC" container and router for this framework. -| -*/ - -$app = new Laravel\Lumen\Application( - dirname(__DIR__) -); - -$app->withFacades(); - -$app->withEloquent(); - -/* -|-------------------------------------------------------------------------- -| Register Container Bindings -|-------------------------------------------------------------------------- -| -| Now we will register a few bindings in the service container. We will -| register the exception handler and the console kernel. You may add -| your own bindings here if you like or you can make another file. -| -*/ - -$app->singleton( - Illuminate\Contracts\Debug\ExceptionHandler::class, - App\Exceptions\Handler::class -); - -$app->singleton( - Illuminate\Contracts\Console\Kernel::class, - App\Console\Kernel::class -); - -/* -|-------------------------------------------------------------------------- -| Register Config Files -|-------------------------------------------------------------------------- -| -| Now we will register the "app" configuration file. If the file exists in -| your configuration directory it will be loaded; otherwise, we'll load -| the default version. You may register other files below as needed. -| -*/ - -$app->configure('auth'); -$app->configure('api'); -$app->configure('assets'); - - - - -/* -|-------------------------------------------------------------------------- -| Register Middleware -|-------------------------------------------------------------------------- -| -| Next, we will register the middleware with the application. These can -| be global middleware that run before and after each request into a -| route or middleware that'll be assigned to some specific routes. -| -*/ - - -$app->middleware([ - App\Http\Middleware\CorsMiddleware::class -]); - -$app->routeMiddleware([ - 'auth' => App\Http\Middleware\Authenticate::class, -]); - -/* -|-------------------------------------------------------------------------- -| Register Service Providers -|-------------------------------------------------------------------------- -| -| Here we will register all of the application's service providers which -| are used to bind services into the container. Service providers are -| totally optional, so you are not required to uncomment this line. -| -*/ - -$app->register(App\Providers\CatchAllOptionsRequestsProvider::class); - -$app->register(App\Providers\AuthServiceProvider::class); -$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class); -$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class); -class_alias('Yajra\DataTables\DataTables', 'Datatables'); -$app->configure('datatables'); -$app->register('Yajra\DataTables\DataTablesServiceProvider'); -/* -|-------------------------------------------------------------------------- -| Load The Application Routes -|-------------------------------------------------------------------------- -| -| Next we will include the routes file so that they can all be added to -| the application. This will provide all of the URLs the application -| can respond to, as well as the controllers that may handle them. -| -*/ - -$app->router->group([ - 'namespace' => 'App\Http\Controllers', -], function ($router) { - require __DIR__.'/../routes/web.php'; -}); - -return $app; +bootstrap(); + +date_default_timezone_set(env('APP_TIMEZONE', 'UTC')); + +/* +|-------------------------------------------------------------------------- +| Create The Application +|-------------------------------------------------------------------------- +| +| Here we will load the environment and create the application instance +| that serves as the central piece of this framework. We'll use this +| application as an "IoC" container and router for this framework. +| +*/ + +$app = new Laravel\Lumen\Application( + dirname(__DIR__) +); + +$app->withFacades(); + +$app->withEloquent(); + +/* +|-------------------------------------------------------------------------- +| Register Container Bindings +|-------------------------------------------------------------------------- +| +| Now we will register a few bindings in the service container. We will +| register the exception handler and the console kernel. You may add +| your own bindings here if you like or you can make another file. +| +*/ + +$app->singleton( + Illuminate\Contracts\Debug\ExceptionHandler::class, + App\Exceptions\Handler::class +); + +$app->singleton( + Illuminate\Contracts\Console\Kernel::class, + App\Console\Kernel::class +); + +/* +|-------------------------------------------------------------------------- +| Register Config Files +|-------------------------------------------------------------------------- +| +| Now we will register the "app" configuration file. If the file exists in +| your configuration directory it will be loaded; otherwise, we'll load +| the default version. You may register other files below as needed. +| +*/ + +$app->configure('auth'); +$app->configure('api'); +$app->configure('assets'); + + + + +/* +|-------------------------------------------------------------------------- +| Register Middleware +|-------------------------------------------------------------------------- +| +| Next, we will register the middleware with the application. These can +| be global middleware that run before and after each request into a +| route or middleware that'll be assigned to some specific routes. +| +*/ + + +$app->middleware([ + App\Http\Middleware\CorsMiddleware::class +]); + +$app->routeMiddleware([ + 'auth' => App\Http\Middleware\Authenticate::class, + 'cors' => App\Http\Middleware\CorsMiddleware::class +]); + +/* +|-------------------------------------------------------------------------- +| Register Service Providers +|-------------------------------------------------------------------------- +| +| Here we will register all of the application's service providers which +| are used to bind services into the container. Service providers are +| totally optional, so you are not required to uncomment this line. +| +*/ + +$app->register(App\Providers\CatchAllOptionsRequestsProvider::class); + +$app->register(App\Providers\AuthServiceProvider::class); +$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class); +$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class); +class_alias('Yajra\DataTables\DataTables', 'Datatables'); +$app->configure('datatables'); +$app->register('Yajra\DataTables\DataTablesServiceProvider'); +/* +|-------------------------------------------------------------------------- +| Load The Application Routes +|-------------------------------------------------------------------------- +| +| Next we will include the routes file so that they can all be added to +| the application. This will provide all of the URLs the application +| can respond to, as well as the controllers that may handle them. +| +*/ + +$app->router->group([ + 'namespace' => 'App\Http\Controllers', +], function ($router) { + require __DIR__.'/../routes/web.php'; +}); + +return $app; diff --git a/routes/web.php b/routes/web.php index abd459e..743fafe 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,409 +1,409 @@ -get('/', function () use ($router) { - return $router->app->version(); -}); - -$router->group(['prefix'=>'api'], function () use ($router) { - $router->post('/login', 'AuthController@login'); - - $router->post('/menu/add', 'MenuController@add'); - $router->get('/menu/edit/{id}', 'MenuController@edit'); - $router->put('/menu/update/{id}', 'MenuController@update'); - $router->delete('/menu/delete/{id}', 'MenuController@delete'); - $router->post('/menu/search', 'MenuController@search'); - $router->get('/menu/management/{id}', 'MenuController@listMenu'); - $router->get('/menu/list', 'MenuController@list'); - $router->post('/role-menu/add', 'RoleMenuController@add'); - $router->put('/role-menu/update/{id}', 'RoleMenuController@update'); - $router->delete('/role-menu/delete/{id}', 'RoleMenuController@delete'); - $router->delete('/role-menu/delete-byrole/{id}', 'RoleMenuController@deleteByRole'); - $router->post('/role-menu/search', 'RoleMenuController@search'); - $router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu'); - - $router->group(['middleware' => 'auth'], function () use ($router) { - - $router->post('/role/search', 'RoleController@search'); - $router->post('/role/add', 'RoleController@add'); - $router->get('/role/edit/{id}', 'RoleController@edit'); - $router->put('/role/update/{id}', 'RoleController@update'); - $router->delete('/role/delete/{id}', 'RoleController@delete'); - $router->get('/role/list', 'RoleController@list'); - - $router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen'); - $router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId'); - $router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete'); - $router->post('/document-project/search', 'ProjectDokumenController@searchDocProject'); - $router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen'); - - $router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen'); - $router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId'); - $router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete'); - $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); - $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); - - $router->post('/project/search', 'ProjectController@search'); - $router->post('/project/add', 'ProjectController@add'); - $router->put('/project/update/{id}', 'ProjectController@update'); - $router->get('/project/edit/{id}', 'ProjectController@edit'); - $router->delete('/project/delete/{id}', 'ProjectController@delete'); - $router->get('/project/list', 'ProjectController@list'); - $router->get('/project/list-user/{id}', 'ProjectController@getListProjectTask'); - $router->post('/project-charter/search', 'ProjectCharterController@search'); - $router->post('/project-charter/add', 'ProjectCharterController@add'); - $router->put('/project-charter/update/{id}', 'ProjectCharterController@update'); - - $router->post('/divisi/add', 'DivisiController@add'); - $router->get('/divisi/edit/{id}', 'DivisiController@edit'); - $router->put('/divisi/update/{id}', 'DivisiController@update'); - $router->post('/divisi/search', 'DivisiController@search'); - $router->delete('/divisi/delete/{id}', 'DivisiController@delete'); - $router->get('/divisi/list', 'DivisiController@list'); - - $router->post('/config-alert/search', 'ConfigAlertController@search'); - $router->post('/config-alert/add', 'ConfigAlertController@add'); - $router->get('/config-alert/edit/{id}', 'ConfigAlertController@edit'); - $router->put('/config-alert/update/{id}', 'ConfigAlertController@update'); - $router->delete('/config-alert/delete/{id}', 'ConfigAlertController@delete'); - $router->get('/config-alert/list', 'ConfigAlertController@list'); - - $router->post('/config-alert-to-user/search', 'ConfigAlertUserController@search'); - $router->post('/config-alert-to-user/add', 'ConfigAlertUserController@add'); - $router->put('/config-alert-to-user/update/{id}', 'ConfigAlertUserController@update'); - $router->delete('/config-alert-to-user/delete/{id}', 'ConfigAlertUserController@delete'); - $router->get('/config-alert/get-user/{id}', 'ConfigAlertUserController@getConfigUser'); - - $router->post('/human-resource/search', 'HumanResourceController@search'); - $router->post('/human-resource/add', 'HumanResourceController@add'); - $router->get('/human-resource/edit/{id}', 'HumanResourceController@edit'); - $router->put('/human-resource/update/{id}', 'HumanResourceController@update'); - $router->delete('/human-resource/delete/{id}', 'HumanResourceController@delete'); - $router->get('/human-resource/list', 'HumanResourceController@list'); - $router->get('/human-resource/select', 'HumanResourceController@select'); - $router->post('/human-resource/check-old-password/{id}', 'HumanResourceController@checkOldPassword'); - - $router->post('/project-role/search', 'ProjectRoleController@search'); - $router->post('/project-role/add', 'ProjectRoleController@add'); - $router->get('/project-role/edit/{id}', 'ProjectRoleController@edit'); - $router->put('/project-role/update/{id}', 'ProjectRoleController@update'); - $router->delete('/project-role/delete/{id}', 'ProjectRoleController@delete'); - $router->get('/project-role/list', 'ProjectRoleController@list'); - $router->get('/project-role/select', 'ProjectRoleController@select'); - - $router->post('/project-type/search', 'ProjectTypeController@search'); - $router->post('/project-type/add', 'ProjectTypeController@add'); - $router->get('/project-type/edit/{id}', 'ProjectTypeController@edit'); - $router->put('/project-type/update/{id}', 'ProjectTypeController@update'); - $router->delete('/project-type/delete/{id}', 'ProjectTypeController@delete'); - $router->get('/project-type/list', 'ProjectTypeController@list'); - - $router->post('/user-to-project/assign', 'UserProyekController@assignUserProyek'); - - $router->post('/request-material/add', 'RequestMaterialController@add'); - $router->post('/request-material/search', 'RequestMaterialController@search'); - $router->get('/request-material/edit/{id}', 'RequestMaterialController@edit'); - $router->put('/request-material/update/{id}', 'RequestMaterialController@update'); - $router->delete('/request-material/delete/{id}', 'RequestMaterialController@delete'); - $router->get('/request-material/list', 'RequestMaterialController@list'); - - $router->put('/request-material/update-warehouse-site/{id}', 'RequestMaterialController@updateWarehouseSite'); - - $router->post('/material-to-project/assign', 'MaterialProjectController@assignMaterial'); - - $router->post('/material-resource/add', 'MaterialResourceController@add'); - $router->post('/material-resource/search', 'MaterialResourceController@search'); - $router->get('/material-resource/update/{id}', 'MaterialResourceController@edit'); - $router->put('/material-resource/update/{id}', 'MaterialResourceController@update'); - $router->delete('/material-resource/delete/{id}', 'MaterialResourceController@delete'); - $router->get('/material-resource/list', 'MaterialResourceController@list'); - $router->get('/material-resource/select', 'MaterialResourceController@select'); - - $router->post('/tools-to-project/assign', 'ToolsProjectController@assignTools'); - $router->get('/tools-to-project/search', 'ToolsProjectController@searchTools'); - - $router->post('/tools-resource/add', 'ToolsResourceController@add'); - $router->post('/tools-resource/search', 'ToolsResourceController@search'); - $router->get('/tools-resource/edit/{id}', 'ToolsResourceController@edit'); - $router->put('/tools-resource/update/{id}', 'ToolsResourceController@update'); - $router->delete('/tools-resource/delete/{id}', 'ToolsResourceController@delete'); - $router->get('/tools-resource/list', 'ToolsResourceController@list'); - $router->get('/tools-resource/select', 'ToolsResourceController@select'); - - $router->post('/req-tools/add', 'ToolsRequestController@add'); - $router->get('/req-tools/edit/{id}', 'ToolsRequestController@edit'); - $router->put('/req-tools/update/{id}', 'ToolsRequestController@update'); - $router->post('/req-tools/search', 'ToolsRequestController@search'); - $router->delete('/req-tools/delete/{id}', 'ToolsRequestController@delete'); - $router->get('/req-tools/list', 'ToolsRequestController@list'); - - $router->post('/version-gantt/add', 'VersionGanttController@add'); - $router->get('/version-gantt/edit/{id}', 'VersionGanttController@edit'); - $router->put('/version-gantt/update/{id}', 'VersionGanttController@update'); - $router->post('/version-gantt/search', 'VersionGanttController@search'); - $router->delete('/version-gantt/delete/{id}', 'VersionGanttController@delete'); - $router->get('/version-gantt/list', 'VersionGanttController@list'); - - $router->post('/user-to-version-gantt/add', 'UserToVersionGanttController@add'); - $router->post('/user-to-version-gantt/add-multiple', 'UserToVersionGanttController@addMultiple'); - $router->get('/user-to-version-gantt/edit/{id}', 'UserToVersionGanttController@edit'); - $router->put('/user-to-version-gantt/update/{id}', 'UserToVersionGanttController@update'); - $router->post('/user-to-version-gantt/search', 'UserToVersionGanttController@search'); - $router->delete('/user-to-version-gantt/delete/{id}', 'UserToVersionGanttController@delete'); - $router->get('/user-to-version-gantt/list', 'UserToVersionGanttController@list'); - $router->get('/user-to-version-gantt/get-by-gantt/{gantt_id}', 'UserToVersionGanttController@getByUserGantt'); - - $router->post('/user-to-activity/add', 'UserToActivityController@add'); - $router->post('/user-to-activity/add-multiple', 'UserToActivityController@addMultiple'); - $router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit'); - $router->put('/user-to-activity/update/{id}', 'UserToActivityController@update'); - $router->post('/user-to-activity/search', 'UserToActivityController@search'); - $router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete'); - $router->get('/user-to-activity/list', 'UserToActivityController@list'); - $router->get('/user-to-activity/datatables', 'UserToActivityController@datatables'); - - $router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial'); - $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); - $router->get('/activity/search', 'ActivityController@search'); - $router->post('/task', 'ActivityController@add'); - $router->get('/task/edit/{id}', 'ActivityController@edit'); - $router->put('/task/{id}', 'ActivityController@update'); - $router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); - $router->delete('/task/{id}', 'ActivityController@delete'); - $router->get('/task/get-update/{id}', 'ActivityController@getUpdate'); - $router->post('/activity/get-percentage', 'ActivityController@getPercentagePerDay'); - $router->get('/activity/set-baseline/{gantt_id}', 'ActivityController@setBaseline'); - $router->post('/activity/get-curva-s', 'ActivityController@getCalculateCurvaS'); - $router->get('/activity/synchronize-report/{gantt_id}', 'ActivityController@synchronizeReport'); - - $router->post('/link', 'LinkController@add'); - $router->put('/link/{id}', 'LinkController@update'); - $router->delete('/link/{id}', 'LinkController@delete'); - - $router->post('/template-gantt/add', 'TemplateGanttController@add'); - $router->get('/template-gantt/edit/{id}', 'TemplateGanttController@edit'); - $router->put('/template-gantt/update/{id}', 'TemplateGanttController@update'); - $router->post('/template-gantt/search', 'TemplateGanttController@search'); - $router->delete('/template-gantt/delete/{id}', 'TemplateGanttController@delete'); - $router->get('/template-gantt/list', 'TemplateGanttController@list'); - $router->get('/template-gantt/get-tree/{id}', 'TemplateGanttController@getTreeByTypeProject'); - - $router->post('/comment-activity/add', 'CommentActivityController@add'); - $router->get('/comment-activity/edit/{id}', 'CommentActivityController@edit'); - $router->put('/comment-activity/update/{id}', 'CommentActivityController@update'); - $router->post('/comment-activity/search', 'CommentActivityController@search'); - $router->delete('/comment-activity/delete/{id}', 'CommentActivityController@delete'); - $router->get('/comment-activity/list', 'CommentActivityController@list'); - - $router->post('/presence/add', 'PresenceController@add'); - $router->get('/presence/edit/{id}', 'PresenceController@edit'); - $router->put('/presence/update/{id}', 'PresenceController@update'); - $router->post('/presence/search', 'PresenceController@search'); - $router->delete('/presence/delete/{id}', 'PresenceController@delete'); - $router->get('/presence/list', 'PresenceController@list'); - $router->get('/presence/clockinout/{id}', 'PresenceController@clockinout'); - $router->get('/presence/bulk-update-location', 'PresenceController@bulkUpdateLocation'); - - $router->post('/permit/add', 'AbsentController@add'); - $router->get('/permit/edit/{id}', 'AbsentController@edit'); - $router->put('/permit/update/{id}', 'AbsentController@update'); - $router->post('/permit/search', 'AbsentController@search'); - $router->delete('/permit/delete/{id}', 'AbsentController@delete'); - $router->get('/permit/list', 'AbsentController@list'); - - $router->post('/assign-tools/add', 'AssignToolsController@add'); - $router->get('/assign-tools/edit/{id}', 'AssignToolsController@edit'); - $router->put('/assign-tools/update/{id}', 'AssignToolsController@update'); - $router->post('/assign-tools/search', 'AssignToolsController@search'); - $router->delete('/assign-tools/delete/{id}', 'AssignToolsController@delete'); - $router->get('/assign-tools/list', 'AssignToolsController@list'); - $router->get('/assign-tools/datatables', 'AssignToolsController@datatables'); - - $router->post('/assign-material/add', 'AssignMaterialController@add'); - $router->get('/assign-material/edit/{id}', 'AssignMaterialController@edit'); - $router->put('/assign-material/update/{id}', 'AssignMaterialController@update'); - $router->post('/assign-material/search', 'AssignMaterialController@search'); - $router->delete('/assign-material/delete/{id}', 'AssignMaterialController@delete'); - $router->get('/assign-material/list', 'AssignMaterialController@list'); - $router->get('/assign-material/datatables', 'AssignMaterialController@datatables'); - $router->get('/assign-material/datatablesForReportActivity', 'AssignMaterialController@datatablesForReportActivity'); - $router->post('/assign-material/ForReportActivityByMaterial', 'AssignMaterialController@ForReportActivityByMaterial'); - - $router->post('/image/search', 'ImageController@search'); - $router->delete('/image/delete/{id}', 'ImageController@delete'); - $router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef'); - $router->post('/image/upload', 'ImageController@uploadImage'); - $router->get('/image/{id}/{category}', 'ImageController@getByRefId'); - - $router->post('/panic-button/add', 'PanicButtonController@add'); - $router->get('/panic-button/edit/{id}', 'PanicButtonController@edit'); - $router->put('/panic-button/update/{id}', 'PanicButtonController@update'); - $router->post('/panic-button/search', 'PanicButtonController@search'); - $router->delete('/panic-button/delete/{id}', 'PanicButtonController@delete'); - $router->get('/panic-button/list', 'PanicButtonController@list'); - - $router->post('/rate-sallary/add', 'RateSallaryController@add'); - $router->get('/rate-sallary/edit/{id}', 'RateSallaryController@edit'); - $router->put('/rate-sallary/update/{id}', 'RateSallaryController@update'); - $router->post('/rate-sallary/search', 'RateSallaryController@search'); - $router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete'); - $router->get('/rate-sallary/list', 'RateSallaryController@list'); - - $router->post('/project-participants/add', 'ProjectParticipantsController@add'); - $router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit'); - $router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update'); - $router->post('/project-participants/search', 'ProjectParticipantsController@search'); - $router->delete('/project-participants/delete/{id}', 'ProjectParticipantsController@delete'); - $router->delete('/project-participants/delete-by-proyek/{id}', 'ProjectParticipantsController@deleteByProyek'); - $router->get('/project-participants/list', 'ProjectParticipantsController@list'); - $router->get('/project-participants/{where}/{val}', 'ProjectParticipantsController@customWhere'); - - $router->post('/project-approval/add', 'ProjectApprovalController@add'); - $router->get('/project-approval/edit/{id}', 'ProjectApprovalController@edit'); - $router->put('/project-approval/update/{id}', 'ProjectApprovalController@update'); - $router->post('/project-approval/search', 'ProjectApprovalController@search'); - $router->delete('/project-approval/delete/{id}', 'ProjectApprovalController@delete'); - $router->delete('/project-approval/delete-by-proyek/{id}', 'ProjectApprovalController@deleteByProyek'); - $router->get('/project-approval/list', 'ProjectApprovalController@list'); - $router->get('/project-approval/{where}/{val}', 'ProjectApprovalController@customWhere'); - - $router->post('/project-milestone/add', 'ProjectMileStoneController@add'); - $router->get('/project-milestone/edit/{id}', 'ProjectMileStoneController@edit'); - $router->put('/project-milestone/update/{id}', 'ProjectMileStoneController@update'); - $router->post('/project-milestone/search', 'ProjectMileStoneController@search'); - $router->delete('/project-milestone/delete/{id}', 'ProjectMileStoneController@delete'); - $router->delete('/project-milestone/delete-by-proyek/{id}', 'ProjectMileStoneController@deleteByProyek'); - $router->get('/project-milestone/list', 'ProjectMileStoneController@list'); - $router->get('/project-milestone/select', 'ProjectMileStoneController@select'); - $router->get('/project-milestone/{where}/{val}', 'ProjectMileStoneController@customWhere'); - - $router->post('/dashboard/cost-planning-actual', 'DashboardController@costPlanningActual'); - $router->post('/dashboard/percentage-planning-actual', 'DashboardController@percentagePlanningActual'); - $router->post('/dashboard/search-user-presence', 'DashboardController@searchUserPresencePoints'); - $router->post('/dashboard/status-proyek', 'DashboardController@statusProyek'); - $router->post('/dashboard/curva-s', 'DashboardController@curvaS'); - - $router->post('/report-activity/add', 'ReportActivityController@add'); - $router->get('/report-activity/edit/{id}', 'ReportActivityController@edit'); - $router->put('/report-activity/update/{id}', 'ReportActivityController@update'); - $router->post('/report-activity/search', 'ReportActivityController@search'); - $router->delete('/report-activity/delete/{id}', 'ReportActivityController@delete'); - $router->get('/report-activity/list', 'ReportActivityController@list'); - $router->post('/report-activity/search-point', 'ReportActivityController@searchPoint'); - $router->get('/report-activity/datatables', 'ReportActivityController@datatables'); - - $router->post('/report-activity-material/add', 'ReportActivityMaterialController@add'); - $router->post('/report-activity-material/search', 'ReportActivityMaterialController@search'); - $router->delete('/report-activity-material/delete/{id}', 'ReportActivityMaterialController@delete'); - $router->get('/report-activity-material/list', 'ReportActivityMaterialController@list'); - $router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables'); - $router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish'); - $router->get('/report-activity-material/test', 'ReportActivityMaterialController@countForProgressTest'); - - - $router->post('/waypoint/add', 'WaypointController@add'); - $router->get('/waypoint/edit/{id}', 'WaypointController@edit'); - $router->put('/waypoint/update/{id}', 'WaypointController@update'); - $router->post('/waypoint/search', 'WaypointController@search'); - $router->delete('/waypoint/delete/{id}', 'WaypointController@delete'); - $router->get('/waypoint/list', 'WaypointController@list'); - - $router->post('/holiday/add', 'HolidayController@add'); - $router->get('/holiday/edit/{id}', 'HolidayController@edit'); - $router->put('/holiday/update/{id}', 'HolidayController@update'); - $router->post('/holiday/search', 'HolidayController@search'); - $router->delete('/holiday/delete/{id}', 'HolidayController@delete'); - $router->get('/holiday/list', 'HolidayController@list'); - $router->get('/holiday/datatables', 'HolidayController@datatables'); - - $router->post('/satuan/add', 'SatuanController@add'); - $router->get('/satuan/edit/{id}', 'SatuanController@edit'); - $router->put('/satuan/update/{id}', 'SatuanController@update'); - $router->post('/satuan/search', 'SatuanController@search'); - $router->delete('/satuan/delete/{id}', 'SatuanController@delete'); - $router->get('/satuan/list', 'SatuanController@list'); - - $router->post('/checklist-k3/add', 'ChecklistK3Controller@add'); - $router->get('/checklist-k3/edit/{id}', 'ChecklistK3Controller@edit'); - $router->put('/checklist-k3/update/{id}', 'ChecklistK3Controller@update'); - $router->post('/checklist-k3/search', 'ChecklistK3Controller@search'); - $router->delete('/checklist-k3/delete/{id}', 'ChecklistK3Controller@delete'); - $router->get('/checklist-k3/list', 'ChecklistK3Controller@list'); - - $router->post('/report-k3/add', 'ReportK3Controller@add'); - $router->get('/report-k3/edit/{id}', 'ReportK3Controller@edit'); - $router->put('/report-k3/update/{id}', 'ReportK3Controller@update'); - $router->post('/report-k3/search', 'ReportK3Controller@search'); - $router->delete('/report-k3/delete/{id}', 'ReportK3Controller@delete'); - $router->get('/report-k3/list', 'ReportK3Controller@list'); - - $router->post('/report-k3-detail/add', 'ReportK3DetailController@add'); - $router->get('/report-k3-detail/edit/{id}', 'ReportK3DetailController@edit'); - $router->put('/report-k3-detail/update/{id}', 'ReportK3DetailController@update'); - $router->post('/report-k3-detail/search', 'ReportK3DetailController@search'); - $router->delete('/report-k3-detail/delete/{id}', 'ReportK3DetailController@delete'); - $router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); - - $router->post('/user-to-proyek/add', 'UserToProyekController@add'); - $router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit'); - $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); - $router->post('/user-to-proyek/search', 'UserToProyekController@search'); - $router->delete('/user-to-proyek/delete/{id}', 'UserToProyekController@delete'); - $router->get('/user-to-proyek/list', 'UserToProyekController@list'); - $router->get('/user-to-proyek/select', 'UserToProyekController@select'); - - $router->post('/folder-document-proyek/add', 'FolderDocumentProyekController@add'); - $router->get('/folder-document-proyek/edit/{id}', 'FolderDocumentProyekController@edit'); - $router->put('/folder-document-proyek/update/{id}', 'FolderDocumentProyekController@update'); - $router->post('/folder-document-proyek/search', 'FolderDocumentProyekController@search'); - $router->delete('/folder-document-proyek/delete/{id}', 'FolderDocumentProyekController@delete'); - $router->get('/folder-document-proyek/list', 'FolderDocumentProyekController@list'); - $router->get('/folder-document-proyek/get-tree/{id}', 'FolderDocumentProyekController@getTree'); - - $router->post('/office-hours/add', 'OfficeHoursController@add'); - $router->get('/office-hours/edit/{id}', 'OfficeHoursController@edit'); - $router->put('/office-hours/update/{id}', 'OfficeHoursController@update'); - $router->post('/office-hours/search', 'OfficeHoursController@search'); - $router->delete('/office-hours/delete/{id}', 'OfficeHoursController@delete'); - $router->get('/office-hours/list', 'OfficeHoursController@list'); - - $router->get('/gantt-show-hide/get-by-gantt/{gantt_id}', 'ShowHideColumnController@getByUserGantt'); - $router->post('/gantt-show-hide/add', 'ShowHideColumnController@add'); - $router->post('/gantt-show-hide/update/{gantt_id}', 'ShowHideColumnController@update'); - - - $router->post('/shift/add', 'ShiftController@add'); - $router->get('/shift/edit/{id}', 'ShiftController@edit'); - $router->put('/shift/update/{id}', 'ShiftController@update'); - $router->post('/shift/search', 'ShiftController@search'); - $router->delete('/shift/delete/{id}', 'ShiftController@delete'); - $router->get('/shift/list', 'ShiftController@list'); - - $router->post('/user-monthly-shift/add', 'UserMonthlyShiftController@add'); - $router->put('/user-monthly-shift/update/{id}', 'UserMonthlyShiftController@update'); - $router->post('/user-monthly-shift/search', 'UserMonthlyShiftController@search'); - $router->delete('/user-monthly-shift/delete/{id}', 'UserMonthlyShiftController@delete'); - $router->delete('/user-monthly-shift/delete-at/{yyyymm}', 'UserMonthlyShiftController@deleteYYYYMM'); - $router->get('/user-monthly-shift/list', 'UserMonthlyShiftController@list'); - $router->post('/user-monthly-shift/import', 'UserMonthlyShiftController@import'); - $router->get('/user-monthly-shift/list/{yyyymm}', 'UserMonthlyShiftController@listYYYYMM'); - - $router->post('/user-to-shift/add', 'UserToShiftController@add'); - $router->get('/user-to-shift/edit/{id}', 'UserToShiftController@edit'); - $router->put('/user-to-shift/update/{id}', 'UserToShiftController@update'); - $router->post('/user-to-shift/search', 'UserToShiftController@search'); - $router->delete('/user-to-shift/delete/{id}', 'UserToShiftController@delete'); - $router->get('/user-to-shift/list', 'UserToShiftController@list'); - - $router->post('/control-monitoring/search', 'ControlMonitoringController@search'); - $router->get('/currency/list', 'CurrencyController@list'); - - $router->post('/project-to-checklist-k3/add', 'ProjectToChecklistK3Controller@add'); - $router->post('/project-to-checklist-k3/add-multiple', 'ProjectToChecklistK3Controller@addMultiple'); - $router->get('/project-to-checklist-k3/edit/{id}', 'ProjectToChecklistK3Controller@edit'); - $router->put('/project-to-checklist-k3/update/{id}', 'ProjectToChecklistK3Controller@update'); - $router->post('/project-to-checklist-k3/search', 'ProjectToChecklistK3Controller@search'); - $router->delete('/project-to-checklist-k3/delete/{id}', 'ProjectToChecklistK3Controller@delete'); - $router->get('/project-to-checklist-k3/list', 'ProjectToChecklistK3Controller@list'); - }); - -}); +get('/', function () use ($router) { + return $router->app->version(); +}); + +$router->group(['prefix'=>'api'], function () use ($router) { + $router->post('/login', 'AuthController@login'); + + $router->post('/menu/add', 'MenuController@add'); + $router->get('/menu/edit/{id}', 'MenuController@edit'); + $router->put('/menu/update/{id}', 'MenuController@update'); + $router->delete('/menu/delete/{id}', 'MenuController@delete'); + $router->post('/menu/search', 'MenuController@search'); + $router->get('/menu/management/{id}', 'MenuController@listMenu'); + $router->get('/menu/list', 'MenuController@list'); + $router->post('/role-menu/add', 'RoleMenuController@add'); + $router->put('/role-menu/update/{id}', 'RoleMenuController@update'); + $router->delete('/role-menu/delete/{id}', 'RoleMenuController@delete'); + $router->delete('/role-menu/delete-byrole/{id}', 'RoleMenuController@deleteByRole'); + $router->post('/role-menu/search', 'RoleMenuController@search'); + $router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu'); + + $router->group(['middleware' => ['auth', 'cors']], function () use ($router) { + + $router->post('/role/search', 'RoleController@search'); + $router->post('/role/add', 'RoleController@add'); + $router->get('/role/edit/{id}', 'RoleController@edit'); + $router->put('/role/update/{id}', 'RoleController@update'); + $router->delete('/role/delete/{id}', 'RoleController@delete'); + $router->get('/role/list', 'RoleController@list'); + + $router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen'); + $router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId'); + $router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete'); + $router->post('/document-project/search', 'ProjectDokumenController@searchDocProject'); + $router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen'); + + $router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen'); + $router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId'); + $router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete'); + $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); + $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); + + $router->post('/project/search', 'ProjectController@search'); + $router->post('/project/add', 'ProjectController@add'); + $router->put('/project/update/{id}', 'ProjectController@update'); + $router->get('/project/edit/{id}', 'ProjectController@edit'); + $router->delete('/project/delete/{id}', 'ProjectController@delete'); + $router->get('/project/list', 'ProjectController@list'); + $router->get('/project/list-user/{id}', 'ProjectController@getListProjectTask'); + $router->post('/project-charter/search', 'ProjectCharterController@search'); + $router->post('/project-charter/add', 'ProjectCharterController@add'); + $router->put('/project-charter/update/{id}', 'ProjectCharterController@update'); + + $router->post('/divisi/add', 'DivisiController@add'); + $router->get('/divisi/edit/{id}', 'DivisiController@edit'); + $router->put('/divisi/update/{id}', 'DivisiController@update'); + $router->post('/divisi/search', 'DivisiController@search'); + $router->delete('/divisi/delete/{id}', 'DivisiController@delete'); + $router->get('/divisi/list', 'DivisiController@list'); + + $router->post('/config-alert/search', 'ConfigAlertController@search'); + $router->post('/config-alert/add', 'ConfigAlertController@add'); + $router->get('/config-alert/edit/{id}', 'ConfigAlertController@edit'); + $router->put('/config-alert/update/{id}', 'ConfigAlertController@update'); + $router->delete('/config-alert/delete/{id}', 'ConfigAlertController@delete'); + $router->get('/config-alert/list', 'ConfigAlertController@list'); + + $router->post('/config-alert-to-user/search', 'ConfigAlertUserController@search'); + $router->post('/config-alert-to-user/add', 'ConfigAlertUserController@add'); + $router->put('/config-alert-to-user/update/{id}', 'ConfigAlertUserController@update'); + $router->delete('/config-alert-to-user/delete/{id}', 'ConfigAlertUserController@delete'); + $router->get('/config-alert/get-user/{id}', 'ConfigAlertUserController@getConfigUser'); + + $router->post('/human-resource/search', 'HumanResourceController@search'); + $router->post('/human-resource/add', 'HumanResourceController@add'); + $router->get('/human-resource/edit/{id}', 'HumanResourceController@edit'); + $router->put('/human-resource/update/{id}', 'HumanResourceController@update'); + $router->delete('/human-resource/delete/{id}', 'HumanResourceController@delete'); + $router->get('/human-resource/list', 'HumanResourceController@list'); + $router->get('/human-resource/select', 'HumanResourceController@select'); + $router->post('/human-resource/check-old-password/{id}', 'HumanResourceController@checkOldPassword'); + + $router->post('/project-role/search', 'ProjectRoleController@search'); + $router->post('/project-role/add', 'ProjectRoleController@add'); + $router->get('/project-role/edit/{id}', 'ProjectRoleController@edit'); + $router->put('/project-role/update/{id}', 'ProjectRoleController@update'); + $router->delete('/project-role/delete/{id}', 'ProjectRoleController@delete'); + $router->get('/project-role/list', 'ProjectRoleController@list'); + $router->get('/project-role/select', 'ProjectRoleController@select'); + + $router->post('/project-type/search', 'ProjectTypeController@search'); + $router->post('/project-type/add', 'ProjectTypeController@add'); + $router->get('/project-type/edit/{id}', 'ProjectTypeController@edit'); + $router->put('/project-type/update/{id}', 'ProjectTypeController@update'); + $router->delete('/project-type/delete/{id}', 'ProjectTypeController@delete'); + $router->get('/project-type/list', 'ProjectTypeController@list'); + + $router->post('/user-to-project/assign', 'UserProyekController@assignUserProyek'); + + $router->post('/request-material/add', 'RequestMaterialController@add'); + $router->post('/request-material/search', 'RequestMaterialController@search'); + $router->get('/request-material/edit/{id}', 'RequestMaterialController@edit'); + $router->put('/request-material/update/{id}', 'RequestMaterialController@update'); + $router->delete('/request-material/delete/{id}', 'RequestMaterialController@delete'); + $router->get('/request-material/list', 'RequestMaterialController@list'); + + $router->put('/request-material/update-warehouse-site/{id}', 'RequestMaterialController@updateWarehouseSite'); + + $router->post('/material-to-project/assign', 'MaterialProjectController@assignMaterial'); + + $router->post('/material-resource/add', 'MaterialResourceController@add'); + $router->post('/material-resource/search', 'MaterialResourceController@search'); + $router->get('/material-resource/update/{id}', 'MaterialResourceController@edit'); + $router->put('/material-resource/update/{id}', 'MaterialResourceController@update'); + $router->delete('/material-resource/delete/{id}', 'MaterialResourceController@delete'); + $router->get('/material-resource/list', 'MaterialResourceController@list'); + $router->get('/material-resource/select', 'MaterialResourceController@select'); + + $router->post('/tools-to-project/assign', 'ToolsProjectController@assignTools'); + $router->get('/tools-to-project/search', 'ToolsProjectController@searchTools'); + + $router->post('/tools-resource/add', 'ToolsResourceController@add'); + $router->post('/tools-resource/search', 'ToolsResourceController@search'); + $router->get('/tools-resource/edit/{id}', 'ToolsResourceController@edit'); + $router->put('/tools-resource/update/{id}', 'ToolsResourceController@update'); + $router->delete('/tools-resource/delete/{id}', 'ToolsResourceController@delete'); + $router->get('/tools-resource/list', 'ToolsResourceController@list'); + $router->get('/tools-resource/select', 'ToolsResourceController@select'); + + $router->post('/req-tools/add', 'ToolsRequestController@add'); + $router->get('/req-tools/edit/{id}', 'ToolsRequestController@edit'); + $router->put('/req-tools/update/{id}', 'ToolsRequestController@update'); + $router->post('/req-tools/search', 'ToolsRequestController@search'); + $router->delete('/req-tools/delete/{id}', 'ToolsRequestController@delete'); + $router->get('/req-tools/list', 'ToolsRequestController@list'); + + $router->post('/version-gantt/add', 'VersionGanttController@add'); + $router->get('/version-gantt/edit/{id}', 'VersionGanttController@edit'); + $router->put('/version-gantt/update/{id}', 'VersionGanttController@update'); + $router->post('/version-gantt/search', 'VersionGanttController@search'); + $router->delete('/version-gantt/delete/{id}', 'VersionGanttController@delete'); + $router->get('/version-gantt/list', 'VersionGanttController@list'); + + $router->post('/user-to-version-gantt/add', 'UserToVersionGanttController@add'); + $router->post('/user-to-version-gantt/add-multiple', 'UserToVersionGanttController@addMultiple'); + $router->get('/user-to-version-gantt/edit/{id}', 'UserToVersionGanttController@edit'); + $router->put('/user-to-version-gantt/update/{id}', 'UserToVersionGanttController@update'); + $router->post('/user-to-version-gantt/search', 'UserToVersionGanttController@search'); + $router->delete('/user-to-version-gantt/delete/{id}', 'UserToVersionGanttController@delete'); + $router->get('/user-to-version-gantt/list', 'UserToVersionGanttController@list'); + $router->get('/user-to-version-gantt/get-by-gantt/{gantt_id}', 'UserToVersionGanttController@getByUserGantt'); + + $router->post('/user-to-activity/add', 'UserToActivityController@add'); + $router->post('/user-to-activity/add-multiple', 'UserToActivityController@addMultiple'); + $router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit'); + $router->put('/user-to-activity/update/{id}', 'UserToActivityController@update'); + $router->post('/user-to-activity/search', 'UserToActivityController@search'); + $router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete'); + $router->get('/user-to-activity/list', 'UserToActivityController@list'); + $router->get('/user-to-activity/datatables', 'UserToActivityController@datatables'); + + $router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial'); + $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); + $router->get('/activity/search', 'ActivityController@search'); + $router->post('/task', 'ActivityController@add'); + $router->get('/task/edit/{id}', 'ActivityController@edit'); + $router->put('/task/{id}', 'ActivityController@update'); + $router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); + $router->delete('/task/{id}', 'ActivityController@delete'); + $router->get('/task/get-update/{id}', 'ActivityController@getUpdate'); + $router->post('/activity/get-percentage', 'ActivityController@getPercentagePerDay'); + $router->get('/activity/set-baseline/{gantt_id}', 'ActivityController@setBaseline'); + $router->post('/activity/get-curva-s', 'ActivityController@getCalculateCurvaS'); + $router->get('/activity/synchronize-report/{gantt_id}', 'ActivityController@synchronizeReport'); + + $router->post('/link', 'LinkController@add'); + $router->put('/link/{id}', 'LinkController@update'); + $router->delete('/link/{id}', 'LinkController@delete'); + + $router->post('/template-gantt/add', 'TemplateGanttController@add'); + $router->get('/template-gantt/edit/{id}', 'TemplateGanttController@edit'); + $router->put('/template-gantt/update/{id}', 'TemplateGanttController@update'); + $router->post('/template-gantt/search', 'TemplateGanttController@search'); + $router->delete('/template-gantt/delete/{id}', 'TemplateGanttController@delete'); + $router->get('/template-gantt/list', 'TemplateGanttController@list'); + $router->get('/template-gantt/get-tree/{id}', 'TemplateGanttController@getTreeByTypeProject'); + + $router->post('/comment-activity/add', 'CommentActivityController@add'); + $router->get('/comment-activity/edit/{id}', 'CommentActivityController@edit'); + $router->put('/comment-activity/update/{id}', 'CommentActivityController@update'); + $router->post('/comment-activity/search', 'CommentActivityController@search'); + $router->delete('/comment-activity/delete/{id}', 'CommentActivityController@delete'); + $router->get('/comment-activity/list', 'CommentActivityController@list'); + + $router->post('/presence/add', 'PresenceController@add'); + $router->get('/presence/edit/{id}', 'PresenceController@edit'); + $router->put('/presence/update/{id}', 'PresenceController@update'); + $router->post('/presence/search', 'PresenceController@search'); + $router->delete('/presence/delete/{id}', 'PresenceController@delete'); + $router->get('/presence/list', 'PresenceController@list'); + $router->get('/presence/clockinout/{id}', 'PresenceController@clockinout'); + $router->get('/presence/bulk-update-location', 'PresenceController@bulkUpdateLocation'); + + $router->post('/permit/add', 'AbsentController@add'); + $router->get('/permit/edit/{id}', 'AbsentController@edit'); + $router->put('/permit/update/{id}', 'AbsentController@update'); + $router->post('/permit/search', 'AbsentController@search'); + $router->delete('/permit/delete/{id}', 'AbsentController@delete'); + $router->get('/permit/list', 'AbsentController@list'); + + $router->post('/assign-tools/add', 'AssignToolsController@add'); + $router->get('/assign-tools/edit/{id}', 'AssignToolsController@edit'); + $router->put('/assign-tools/update/{id}', 'AssignToolsController@update'); + $router->post('/assign-tools/search', 'AssignToolsController@search'); + $router->delete('/assign-tools/delete/{id}', 'AssignToolsController@delete'); + $router->get('/assign-tools/list', 'AssignToolsController@list'); + $router->get('/assign-tools/datatables', 'AssignToolsController@datatables'); + + $router->post('/assign-material/add', 'AssignMaterialController@add'); + $router->get('/assign-material/edit/{id}', 'AssignMaterialController@edit'); + $router->put('/assign-material/update/{id}', 'AssignMaterialController@update'); + $router->post('/assign-material/search', 'AssignMaterialController@search'); + $router->delete('/assign-material/delete/{id}', 'AssignMaterialController@delete'); + $router->get('/assign-material/list', 'AssignMaterialController@list'); + $router->get('/assign-material/datatables', 'AssignMaterialController@datatables'); + $router->get('/assign-material/datatablesForReportActivity', 'AssignMaterialController@datatablesForReportActivity'); + $router->post('/assign-material/ForReportActivityByMaterial', 'AssignMaterialController@ForReportActivityByMaterial'); + + $router->post('/image/search', 'ImageController@search'); + $router->delete('/image/delete/{id}', 'ImageController@delete'); + $router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef'); + $router->post('/image/upload', 'ImageController@uploadImage'); + $router->get('/image/{id}/{category}', 'ImageController@getByRefId'); + + $router->post('/panic-button/add', 'PanicButtonController@add'); + $router->get('/panic-button/edit/{id}', 'PanicButtonController@edit'); + $router->put('/panic-button/update/{id}', 'PanicButtonController@update'); + $router->post('/panic-button/search', 'PanicButtonController@search'); + $router->delete('/panic-button/delete/{id}', 'PanicButtonController@delete'); + $router->get('/panic-button/list', 'PanicButtonController@list'); + + $router->post('/rate-sallary/add', 'RateSallaryController@add'); + $router->get('/rate-sallary/edit/{id}', 'RateSallaryController@edit'); + $router->put('/rate-sallary/update/{id}', 'RateSallaryController@update'); + $router->post('/rate-sallary/search', 'RateSallaryController@search'); + $router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete'); + $router->get('/rate-sallary/list', 'RateSallaryController@list'); + + $router->post('/project-participants/add', 'ProjectParticipantsController@add'); + $router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit'); + $router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update'); + $router->post('/project-participants/search', 'ProjectParticipantsController@search'); + $router->delete('/project-participants/delete/{id}', 'ProjectParticipantsController@delete'); + $router->delete('/project-participants/delete-by-proyek/{id}', 'ProjectParticipantsController@deleteByProyek'); + $router->get('/project-participants/list', 'ProjectParticipantsController@list'); + $router->get('/project-participants/{where}/{val}', 'ProjectParticipantsController@customWhere'); + + $router->post('/project-approval/add', 'ProjectApprovalController@add'); + $router->get('/project-approval/edit/{id}', 'ProjectApprovalController@edit'); + $router->put('/project-approval/update/{id}', 'ProjectApprovalController@update'); + $router->post('/project-approval/search', 'ProjectApprovalController@search'); + $router->delete('/project-approval/delete/{id}', 'ProjectApprovalController@delete'); + $router->delete('/project-approval/delete-by-proyek/{id}', 'ProjectApprovalController@deleteByProyek'); + $router->get('/project-approval/list', 'ProjectApprovalController@list'); + $router->get('/project-approval/{where}/{val}', 'ProjectApprovalController@customWhere'); + + $router->post('/project-milestone/add', 'ProjectMileStoneController@add'); + $router->get('/project-milestone/edit/{id}', 'ProjectMileStoneController@edit'); + $router->put('/project-milestone/update/{id}', 'ProjectMileStoneController@update'); + $router->post('/project-milestone/search', 'ProjectMileStoneController@search'); + $router->delete('/project-milestone/delete/{id}', 'ProjectMileStoneController@delete'); + $router->delete('/project-milestone/delete-by-proyek/{id}', 'ProjectMileStoneController@deleteByProyek'); + $router->get('/project-milestone/list', 'ProjectMileStoneController@list'); + $router->get('/project-milestone/select', 'ProjectMileStoneController@select'); + $router->get('/project-milestone/{where}/{val}', 'ProjectMileStoneController@customWhere'); + + $router->post('/dashboard/cost-planning-actual', 'DashboardController@costPlanningActual'); + $router->post('/dashboard/percentage-planning-actual', 'DashboardController@percentagePlanningActual'); + $router->post('/dashboard/search-user-presence', 'DashboardController@searchUserPresencePoints'); + $router->post('/dashboard/status-proyek', 'DashboardController@statusProyek'); + $router->post('/dashboard/curva-s', 'DashboardController@curvaS'); + + $router->post('/report-activity/add', 'ReportActivityController@add'); + $router->get('/report-activity/edit/{id}', 'ReportActivityController@edit'); + $router->put('/report-activity/update/{id}', 'ReportActivityController@update'); + $router->post('/report-activity/search', 'ReportActivityController@search'); + $router->delete('/report-activity/delete/{id}', 'ReportActivityController@delete'); + $router->get('/report-activity/list', 'ReportActivityController@list'); + $router->post('/report-activity/search-point', 'ReportActivityController@searchPoint'); + $router->get('/report-activity/datatables', 'ReportActivityController@datatables'); + + $router->post('/report-activity-material/add', 'ReportActivityMaterialController@add'); + $router->post('/report-activity-material/search', 'ReportActivityMaterialController@search'); + $router->delete('/report-activity-material/delete/{id}', 'ReportActivityMaterialController@delete'); + $router->get('/report-activity-material/list', 'ReportActivityMaterialController@list'); + $router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables'); + $router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish'); + $router->get('/report-activity-material/test', 'ReportActivityMaterialController@countForProgressTest'); + + + $router->post('/waypoint/add', 'WaypointController@add'); + $router->get('/waypoint/edit/{id}', 'WaypointController@edit'); + $router->put('/waypoint/update/{id}', 'WaypointController@update'); + $router->post('/waypoint/search', 'WaypointController@search'); + $router->delete('/waypoint/delete/{id}', 'WaypointController@delete'); + $router->get('/waypoint/list', 'WaypointController@list'); + + $router->post('/holiday/add', 'HolidayController@add'); + $router->get('/holiday/edit/{id}', 'HolidayController@edit'); + $router->put('/holiday/update/{id}', 'HolidayController@update'); + $router->post('/holiday/search', 'HolidayController@search'); + $router->delete('/holiday/delete/{id}', 'HolidayController@delete'); + $router->get('/holiday/list', 'HolidayController@list'); + $router->get('/holiday/datatables', 'HolidayController@datatables'); + + $router->post('/satuan/add', 'SatuanController@add'); + $router->get('/satuan/edit/{id}', 'SatuanController@edit'); + $router->put('/satuan/update/{id}', 'SatuanController@update'); + $router->post('/satuan/search', 'SatuanController@search'); + $router->delete('/satuan/delete/{id}', 'SatuanController@delete'); + $router->get('/satuan/list', 'SatuanController@list'); + + $router->post('/checklist-k3/add', 'ChecklistK3Controller@add'); + $router->get('/checklist-k3/edit/{id}', 'ChecklistK3Controller@edit'); + $router->put('/checklist-k3/update/{id}', 'ChecklistK3Controller@update'); + $router->post('/checklist-k3/search', 'ChecklistK3Controller@search'); + $router->delete('/checklist-k3/delete/{id}', 'ChecklistK3Controller@delete'); + $router->get('/checklist-k3/list', 'ChecklistK3Controller@list'); + + $router->post('/report-k3/add', 'ReportK3Controller@add'); + $router->get('/report-k3/edit/{id}', 'ReportK3Controller@edit'); + $router->put('/report-k3/update/{id}', 'ReportK3Controller@update'); + $router->post('/report-k3/search', 'ReportK3Controller@search'); + $router->delete('/report-k3/delete/{id}', 'ReportK3Controller@delete'); + $router->get('/report-k3/list', 'ReportK3Controller@list'); + + $router->post('/report-k3-detail/add', 'ReportK3DetailController@add'); + $router->get('/report-k3-detail/edit/{id}', 'ReportK3DetailController@edit'); + $router->put('/report-k3-detail/update/{id}', 'ReportK3DetailController@update'); + $router->post('/report-k3-detail/search', 'ReportK3DetailController@search'); + $router->delete('/report-k3-detail/delete/{id}', 'ReportK3DetailController@delete'); + $router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); + + $router->post('/user-to-proyek/add', 'UserToProyekController@add'); + $router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit'); + $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); + $router->post('/user-to-proyek/search', 'UserToProyekController@search'); + $router->delete('/user-to-proyek/delete/{id}', 'UserToProyekController@delete'); + $router->get('/user-to-proyek/list', 'UserToProyekController@list'); + $router->get('/user-to-proyek/select', 'UserToProyekController@select'); + + $router->post('/folder-document-proyek/add', 'FolderDocumentProyekController@add'); + $router->get('/folder-document-proyek/edit/{id}', 'FolderDocumentProyekController@edit'); + $router->put('/folder-document-proyek/update/{id}', 'FolderDocumentProyekController@update'); + $router->post('/folder-document-proyek/search', 'FolderDocumentProyekController@search'); + $router->delete('/folder-document-proyek/delete/{id}', 'FolderDocumentProyekController@delete'); + $router->get('/folder-document-proyek/list', 'FolderDocumentProyekController@list'); + $router->get('/folder-document-proyek/get-tree/{id}', 'FolderDocumentProyekController@getTree'); + + $router->post('/office-hours/add', 'OfficeHoursController@add'); + $router->get('/office-hours/edit/{id}', 'OfficeHoursController@edit'); + $router->put('/office-hours/update/{id}', 'OfficeHoursController@update'); + $router->post('/office-hours/search', 'OfficeHoursController@search'); + $router->delete('/office-hours/delete/{id}', 'OfficeHoursController@delete'); + $router->get('/office-hours/list', 'OfficeHoursController@list'); + + $router->get('/gantt-show-hide/get-by-gantt/{gantt_id}', 'ShowHideColumnController@getByUserGantt'); + $router->post('/gantt-show-hide/add', 'ShowHideColumnController@add'); + $router->post('/gantt-show-hide/update/{gantt_id}', 'ShowHideColumnController@update'); + + + $router->post('/shift/add', 'ShiftController@add'); + $router->get('/shift/edit/{id}', 'ShiftController@edit'); + $router->put('/shift/update/{id}', 'ShiftController@update'); + $router->post('/shift/search', 'ShiftController@search'); + $router->delete('/shift/delete/{id}', 'ShiftController@delete'); + $router->get('/shift/list', 'ShiftController@list'); + + $router->post('/user-monthly-shift/add', 'UserMonthlyShiftController@add'); + $router->put('/user-monthly-shift/update/{id}', 'UserMonthlyShiftController@update'); + $router->post('/user-monthly-shift/search', 'UserMonthlyShiftController@search'); + $router->delete('/user-monthly-shift/delete/{id}', 'UserMonthlyShiftController@delete'); + $router->delete('/user-monthly-shift/delete-at/{yyyymm}', 'UserMonthlyShiftController@deleteYYYYMM'); + $router->get('/user-monthly-shift/list', 'UserMonthlyShiftController@list'); + $router->post('/user-monthly-shift/import', 'UserMonthlyShiftController@import'); + $router->get('/user-monthly-shift/list/{yyyymm}', 'UserMonthlyShiftController@listYYYYMM'); + + $router->post('/user-to-shift/add', 'UserToShiftController@add'); + $router->get('/user-to-shift/edit/{id}', 'UserToShiftController@edit'); + $router->put('/user-to-shift/update/{id}', 'UserToShiftController@update'); + $router->post('/user-to-shift/search', 'UserToShiftController@search'); + $router->delete('/user-to-shift/delete/{id}', 'UserToShiftController@delete'); + $router->get('/user-to-shift/list', 'UserToShiftController@list'); + + $router->post('/control-monitoring/search', 'ControlMonitoringController@search'); + $router->get('/currency/list', 'CurrencyController@list'); + + $router->post('/project-to-checklist-k3/add', 'ProjectToChecklistK3Controller@add'); + $router->post('/project-to-checklist-k3/add-multiple', 'ProjectToChecklistK3Controller@addMultiple'); + $router->get('/project-to-checklist-k3/edit/{id}', 'ProjectToChecklistK3Controller@edit'); + $router->put('/project-to-checklist-k3/update/{id}', 'ProjectToChecklistK3Controller@update'); + $router->post('/project-to-checklist-k3/search', 'ProjectToChecklistK3Controller@search'); + $router->delete('/project-to-checklist-k3/delete/{id}', 'ProjectToChecklistK3Controller@delete'); + $router->get('/project-to-checklist-k3/list', 'ProjectToChecklistK3Controller@list'); + }); + +}); From 8608510f6e3758e87df9eb8a33e32804aa89398e Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 27 Jul 2022 02:47:14 +0700 Subject: [PATCH 07/11] bug fix --- app/Http/Controllers/ActivityController.php | 36 ++++++++++---------- app/Models/.Activity.php.swp | Bin 0 -> 20480 bytes app/Models/Activity.php | 23 +++++++------ 3 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 app/Models/.Activity.php.swp diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 9c384c8..4c7b9ba 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -1,5 +1,4 @@ -count() == 0) { + if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) { $this->cloneTemplate($id, $proyek_id); } @@ -29,18 +28,20 @@ class ActivityController extends Controller private function getDataActivity($id) { - $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); - $startDate = date_create($dataHeader->start_date); - $endDate = date_create($dataHeader->end_date); - $dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s"); - $dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s"); - $dataHeader->type = "project"; - $dataHeader->text = $dataHeader->name; - $finalData[] = $dataHeader; - $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); - - if(Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count() == 0) - $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); + $checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); $finalData = []; + if($checkHeader > 0){ + $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); + $startDate = date_create($dataHeader->start_date); + $endDate = date_create($dataHeader->end_date); + $dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s"); + $dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s"); + $dataHeader->type = "project"; + $dataHeader->text = $dataHeader->name; + $finalData[] = $dataHeader; + $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); + }else{ + $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); + } foreach($data as $objRow){ $type = "project"; @@ -117,7 +118,7 @@ class ActivityController extends Controller private function cloneTemplate($id, $proyek_id) { - $project = Project::findOrFail($proyek_id); + $project = Project::find($proyek_id); $rootActivity = Activity::create([ 'version_gantt_id'=>$id, @@ -126,7 +127,7 @@ class ActivityController extends Controller 'kode_sortname'=>$project->kode_sortname, 'start_date'=> $project->mulai_proyek, 'end_date'=> $project->akhir_proyek, - 'rencana_biaya'=> str_replace(".","", $project->rencana_biaya), + 'rencana_biaya'=> $project->rencana_biaya, 'type_activity'=> 'header', 'created_by'=>$this->currentName, ]); @@ -186,7 +187,6 @@ class ActivityController extends Controller $parent = $data['parent_id'] ?? null; if($parent){ - $this->updateTypeProject($parent); Activity::find($parent)->update(["type_activity"=>"project"]); CommentActivity::where('activity_id', $parent)->delete(); UserToActivity::where('activity_id', $parent)->delete(); diff --git a/app/Models/.Activity.php.swp b/app/Models/.Activity.php.swp new file mode 100644 index 0000000000000000000000000000000000000000..1f10603e10d65dac1b058a297422c9a500943daa GIT binary patch literal 20480 zcmeI2ZEPGz8ON8Dlw6>tFMMbvB&LUxyGvr9Q=pVf?dTG_G%0D_I7yM>aLnDUeQWRS zZgyvrI3biGM1znD;zepHl_*pKDN3aP6^IuJgoN5kln)@%B9&IH_)w4#&@U9e@PB4^ z_RZ(mPIxOCOTS!p=lwskGxIz%?a@Pf_OV+>wj21n#xOoL@lyN8x34ptlZGK&-=fzm z{Y^|x-+AEfsp0oEKR7*kx6El^l8;k{_2aI;5O};}2K6@YESOHW-ki91cvt*??s@fn zZr8Mfdb1;}W0qJP@p|6C4E0N`fL3623WQ>I_|~h9_uRaFloGtVd=tC=x`V4rt7B;e zv;tZIt$>3mHq$sw;RUm z;1%#P_!;;n_yqVcxDDJ0ZUFzd8gap|!LPs*;4|P1u)%fU$*TVS{1p0at+y;Dxss#^c}ta01xidhjYVIuAY#P5{!Z0oH*F(C}&S z6gUUAgA(`)94C*0L*Op(esD7w0b9WqupX=f=io#+0}g>Eco(<*rZJv)EH>Hv_TOIPaZ#sgFF?E%q(U`TIZgoiXtYCON3T|25TJ03n zP;X5?Kq@|GwmjdR^UWYY4nslMpHh!?HY8lZ?cF`g?(QHZGtV-z)wV5X4rO%Q&=J+z z4vLe_f^tkEA)s3J;&Owu+;W^Qj+kr6@t*0MNF|$yHk7xaQiW!rR5Z-ajQTj0 ztyGTW=(gI6QZ*imUbP050@JV7*iM#zF+A?@zR4P_94rRH?3cHZwj{sXc16pxx#M6+ z$*iiZYB{2osR71$hdaC_TgQ^|i3Z4Kvl`pNwvUcRd1lgOx~w$o`X=x6SXG5vX25tL z`#?6d#-J7YJ8n1yXFn}9B7Jw!T*!||^$N|8V;#fj!&q$1aYu+;r$7-{e~|;O1Sn)<t=J{sFqF%1mDm7A?oo2Y$ zW=6xP&|j*MPUdF2v-w+cADHFg~)~uT4t8UqCBSJDUN1R%BGZx6|LG)w#kZzhN$VQoNH`( zY`iRZuuzVdumQT~*UhCF=M+L^0>OpVX*6&#(-da6s@Bq~RDv}84~j!$Eh}-{N2IE% zXT0_du4klRqtV7>D3>h{pR3hjQQ~x;5QWRO9ihxC^KLt6bzR4#;lzW$nsZt`Kl9MX zzQVV-op~i(*A6PQ3vmUe53`H)#Pe|Nl@^b~kgZ;)%8nsKb;w zqpcD1EVE-Wca{Y`OVIR0^4*L$n#;Ah@P+%qB#yUIC%jaDy3@Ac3^zlhWWuOOKKiO?l=zQ3>d9US}3#LEMqe@4* zWHW_eEqn;ka75p=WNb>G-R049W^*kYQFw>3BRBfl%##H}##NgLdRV~y>{j6Vf_7~5 zLjC3zLJE*w99K~)oEfCEmThxdCgo>nsZ}9(JTo17 z9vVDzJMUl-31%jC?N}~K)AyHzO<=ib^T3>$wB4g2tg9JWOcbx_dC_Aqv)`mr)V#kh zo=uiSYs#tT0L?7Rgr!Lh>Ku9Do}~prrQ3GWwR*DuIc(cS*u7-`t8@K7!mj@|I19+` ze;j-RoCIa?H`w%l06ztv11G^W_z<`QOo9pUPH-bw2Yv+G|1t0-;DdX?pJ4x=1^0v9 zU>r2SZ(;9W0KWlGfV02`L*P}|_`d_c0MCG@!6V=yuphh*oBsRY9QZ0wzJNadKM%+c z@I2c42>3j>4}1)q0;IzUp#QW2S^=$qRzNGD75FzOa2l3R>;@7pwoH7nT8nJ!*xdzt zEAe_LTPxbI3pd%wjVSwGS_{enoVc~-UCXJK`>iM)JlSsO!vKPZ2JS^x?vF^fae0g$ zVsmb35z!mOBnOFaiqLl$DhyY;%?0+1)y!@zaS|bK>CQw^^h;?^!3K=%Ol3SXSTC8x zO=Yzu-c|^(dT|oNXYKm<=Fyf)eo=K)Bq*BpLGp4%jrPSG+N?|&bBl^zjan+3%M`5V z=bEv)p+w$m=@kxX(1Zgpq3M$bWnA8^%{KUF4N(*U}|Un)jCRyloKEpk>4 ziM|JSR3|#!sWG^Y$qm13cpVlQo!%7FHP|S*L*(Zhp9SP{K70h0+Yn67xFj|{M$UJX z^?^}1_%k7tjXWzk#_iCAs~&EqFi3_Ly9pMc^tZspOX2(gKb+1) zPW~GC|KkjgibZMQ)6sz}Y-yS?HrVQFG-4NJJTqj5IhnR&_(zq32`4^XL3z=k6}+KY zv85!?fa;K*GmsODyngbOLDo1vVu-s=Mkk-Yia0!O1(SVG&}506lK0R%nn={Akybu- zfEFjn%%MWQreuzjLkfZqn6CE112zE%*wWD^2SRdYmh%Kehh`XoyU0T$m68WB|I&lA zT!}RPa^=asU(Ja_@d%MrRymQ%v7E_wdWrsW^xiVZl6g4ENJP1AuZUNVV7h&5!1HJ_w1CN5QfQNw%EU*>4hWh*xJPW=EsD9I+3jU1x{v7nd zM?e#7058CeItb9josFc@lWt0w*&wH literal 0 HcmV?d00001 diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 01957ed..e3358b2 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -25,10 +25,10 @@ class Activity extends Model 'planned_start', 'planned_end', 'satuan_id', 'created_at', 'created_by', 'updated_at', 'updated_by' ]; - - protected $attributes = [ - 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' - ]; + // this piece of shit prepend column on create(), causing bugs + //protected $attributes = [ + // 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' + //]; protected $appends = [ 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' @@ -57,7 +57,7 @@ class Activity extends Model private function updateBobot() { - if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) + 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))') ) @@ -65,17 +65,18 @@ class Activity extends Model ->where("version_gantt_id", $this->version_gantt_id) ->whereNull("parent_id") ->first(); - - $rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) - ->where("proyek_id", $this->proyek_id) - ->where('type_activity', 'header') - ->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(); + } + $rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) + ->where("proyek_id", $this->proyek_id) + ->where('type_activity', 'header') + ->first(); + if($totalCost->sum > 0){ $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); From 53e13f4f5bab2d977a9079b48c6b539bcb9e7d18 Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 27 Jul 2022 02:47:39 +0700 Subject: [PATCH 08/11] add cors middleware to public --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 743fafe..192ef4d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,7 +4,7 @@ $router->get('/', function () use ($router) { return $router->app->version(); }); -$router->group(['prefix'=>'api'], function () use ($router) { +$router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) { $router->post('/login', 'AuthController@login'); $router->post('/menu/add', 'MenuController@add'); From e5e4f69d5d344718a8ec10ea28ca890587db27d5 Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 27 Jul 2022 04:20:40 +0700 Subject: [PATCH 09/11] implement decimal --- .../.ReportActivityMaterialController.php.swp | Bin 0 -> 20480 bytes .../Controllers/AssignMaterialController.php | 12 +++++++----- .../ReportActivityMaterialController.php | 9 ++++++++- .../Controllers/RequestMaterialController.php | 10 ++++++++-- 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 app/Http/Controllers/.ReportActivityMaterialController.php.swp diff --git a/app/Http/Controllers/.ReportActivityMaterialController.php.swp b/app/Http/Controllers/.ReportActivityMaterialController.php.swp new file mode 100644 index 0000000000000000000000000000000000000000..6c4666e885359659e4ceafb411f69fd965acc9c4 GIT binary patch literal 20480 zcmeI4Ym6jS6@Uv6q(P9CL=yyZw`u7f(mgZFL)L+AoY@C#VA*AtUBumGsOhemsomhk8|%m_ndq0?9BM?EnCI<(RCKD(=6-H*Zy(l*-gh<{>_#Z2cau3zus%( zrkz(_yKQ^vqRGp5ZrY|&8u-XZWP)RhL3ki)*i|PQo3X109KSX;x$(Nvl=*Hq8e><) zabs*l;KyO$c}^IO?Qj}F7*AGXcfpO9w%V~1y0+Jr7;Vfq24`^AE^dX4Wt@KHIQl`)j+C&R0F97QVpaU zNHvgZAl1PCKm&HovUa`0vYr9C|DVMFuf5Z#8o`i?s2%HHr|Gz;KVwi$ooNQT-!B63na0HsL5!S#T zPO_}u!Vw5z8ZLk{;FXMJ{Tv>JkHRf*2u^_v90OlC(Xu`Zcf(z<01-^UV{a#4sKb76 zVG=4(hIhl0Cs@|Qa4*~gharFu!fEjI@s{;_2w^>345!26ET-H8H^5F<11G}?@DK|r zUx&}Zr{Qk63+{wZ!Od_LoC|B=B^GX8gulb1@ME|g>fpgPD8kur798Cx!|NPT4QkHl z=qP&2%m$%jSLa0`SF>Y#yJ!2tjzn(3_L|O!IE08hTUgt=S*p0vrg|e@DvXRAl8Vp8 z^~QE5tU7*d&pGQvS?t+&iM-xQt}G^_$er_(Lmm?oi}OzC6!Nw?{W0y<@f@7M=tOwbkmPF2jTWGm8M#R^yqp- zjA^Cx-H>VO9L;-gGws<&);X%yYPU*RtQ#K}mx&LIi;1pVDzT0t_OO%JFObFSSYQ!Smtx!|Cq_Bu4ul6I!P2ctBjC><>t4<=RKil#hCD!6cWl*TYG8Uz; zrK#E~4N6X_FEJ?EASI@ORFkh06SJ;gD@bXn;6oUm&|RQWhFcyb+--O;NR7acoB}Pj zKMMT9p1f{}e7Ta3npF=I`8|ROY?<)%4O?w;5 zwrmEow(B_<(T?=~M4TG|%MR8{p$63K_n zftutj+srhV$}`jMTxPCQQ(P`|ZfY`Xl`3|7>Z8NxiKuUyN+v2MAuaJbQ`It)6-Ghj1QtPOO#4h?(B3+$TCLbXP&Ei8xK3VeZf zNjmjJ`Bi!uGqPHfMqbU{!%8o!ou~7<(fqI{dhRMs$xOm{*c071)zsfraVnb3{(XLo zR>w|dr+E+K&8l#P9lCRfr1ol3>hNur9Ww)a@D{((j72h+icp=o6^Two70(ab(`|Zm zlNnd2$K&egB1t05TBhT#)=s@nA@wNlEvxCsd-BX(dF9LK5=XZ0#_r9|MyKl5Z7h}S z?nX-2Okc43=U$o0N;+q&eR@Z6!)sO#6!MI8hV-l(O7B$8kERSp+jyIu1@7=RTe1`+ z=>z29c`_N&(Y7t4s@y#_t6y?Tkz>FOX;RhcJK8AU@j#cL>bhEYI1nz{!Cf{(sVMgJ zd*ODiHn^vD`{91GKI4R{O8P66isEpZKIm~$ypS#OZ!}xX>APA{gC&v5b_w>)&wZ_K z5+!^gLachU_7G>Rec)U;2V+jIN1}a+*fes4G;*;$<2lhK>i1-$v3Dy|wHNK}?k@ee zjgjxWF?fpAVp}|~S$BQfVXr(izt>m=dVo(vqK?@MSp;>nT~-QbU3!^3G%w@-$Jp#I z5lhPWKiR*3oS6Pz@SzUJ!B2?akH7&KfqxRWe;d9AE>vL#Y}gBH;6!+VSpF~Y99#)k zz~yijoB{tLmVW^502?;I8E_wQ{8!-1@Nu{UY?y*cxDXy8j(-@&p$H>TfLDp(e+Hk2 zMYs{3CuYABwwm}o!{@Wa=}*8{;biy+@%i)cL-;Q2f($%DY<>qEhJCOZ&V*ah+Z@~o z?}zhY45U7bkiOnR8en>rGpu&nN|n%F+z>GS{0RSDn$N(`@57qc?E_9B4p|YA77clP zUinH^9kl3FY=Xf|u5|&km%r2&^Pw|a&hEDt?5G;Ljd)@qaBGF}k*spaOKz>4&5!27 zU{MBrqxq~*Mys6FUbL8reMzZi`*TjHzD9NR5!&^V7RpvGb(6 zl`274bHb^m0+W;clb@DH)e3w^%?&yCNS_)N<&%_*_dN8`&MA(#*{!vbPg2+)xPBp9 zpT?AjkzCqpW{V=*9Cd5*vn=0+rY@hs!O5z$R1Im)9RvSzX<{NGlB>pr;i;XcGnQst zmSetIw|(ZrC}^?@qw;7k1EIIHFTR0&vDg2LgI33(XAJ3u%RRL6j)-&B>iV)D)MdA* zclO8S^66N6>F$=@zDT<}E|(ZRlALRfwn=i0RhEZgDE}63T6R=jwq{UQBPXb)q+@nn&E)WZms}#&}X)o^e~W8Y|J> z1!HNFwC6V1V{KXf)rKx6HercLS_Ns{TB}MeH5Ns~b67kUakwPxIotJxCpFx$2qV`m zih_5gqqY%PNwL~-Uwiqen3pwYDM^_uEUH>l-r-a+#qz3JNZ*J^Yn@34_3|kdbY|Kj zQseSE>*6vP?1*TVF@+{($sFnrA3V2z(SC)2?XU`7?!^6d?5J`_E%oZU)`YB?s?$`{ z^_ZgiYe>RUXePPeUP|nIF42%lW)EvZC@QZvLCmv#GUmFGk_tADOGy*TI`OW?cDT_xE>T{}f`4YX%NBWcF= zrivEo-V$lGXX3aG*fV(}cU5F8p16$ZzKWa-SPkpj#A&Y=vI5e%(R6g%Dyx5z(JF0R zd+TPn>z3?C_RUPv5qPt0$jJErW5lV)664DFKRMt3AL9Kd;ClEFoD1J1=6?_#fEXgU z9t!X>asH3sVTfQiY=HN`zlrgG2j77E!GRlL8eSyM|0_HLx56Pf2#fGxxDL*S2Z{9` zfNS7t*b481EUbmsi21(G`O(q?g^1X14EfQ}C@;xh0*Ragn~$0Dmn#@ zN&2`@dd7uwFXDaDG&$uu{uVkDh$I?2_;;rh8 WOS#fI(6-#UJbkXjY`~3J)_(!rbhiKi literal 0 HcmV?d00001 diff --git a/app/Http/Controllers/AssignMaterialController.php b/app/Http/Controllers/AssignMaterialController.php index a3a7991..0122c01 100644 --- a/app/Http/Controllers/AssignMaterialController.php +++ b/app/Http/Controllers/AssignMaterialController.php @@ -10,6 +10,11 @@ use Datatables; class AssignMaterialController extends Controller { + private function sanitizeDecimal($number) { + $number = str_replace(".","",$number); + $number = str_replace(",",".",$number); + return $number; + } public function add(Request $request){ $this->validate($request, [ @@ -20,14 +25,14 @@ class AssignMaterialController extends Controller $checkStock = RequestMaterial::where("id", $request->material_id)->first(); $currentStock = $checkStock->qty; - $price = $checkStock->price; if((int)$currentStock < (int)$request->qty_planning){ return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); } $data = $request->all(); $data['created_by'] = $this->currentName; - $data['budget'] = $price; + $data['budget'] = $checkStock->price; + $data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); $result = AssignMaterial::create($data); if(!$result) @@ -106,9 +111,6 @@ class AssignMaterialController extends Controller ->where('assign_material_to_activity.activity_id', $id_activity) ->orderBy('plan_date', 'desc') ->get(); - foreach($data as $d){ - $d->budget = str_replace(".", ",", $d->budget); - } return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){ diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index fe726a2..04ae220 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -9,7 +9,13 @@ use App\Models\AssignMaterial; use Datatables; class ReportActivityMaterialController extends Controller -{ +{ + private function sanitizeDecimal($number) { + $number = str_replace(".","",$number); + $number = str_replace(",",".",$number); + return $number; + } + public function add(Request $request){ $this->validate($request, [ @@ -20,6 +26,7 @@ class ReportActivityMaterialController extends Controller $data = $request->all(); $data['created_by'] = $this->currentName; $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); + $data['qty'] = $this->sanitizeDecimal($data['qty']); if(!ReportActivityMaterial::create($data)) return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]); diff --git a/app/Http/Controllers/RequestMaterialController.php b/app/Http/Controllers/RequestMaterialController.php index 2f4ee1a..3ef51db 100644 --- a/app/Http/Controllers/RequestMaterialController.php +++ b/app/Http/Controllers/RequestMaterialController.php @@ -8,6 +8,12 @@ use App\Models\MaterialResource; class RequestMaterialController extends Controller { + private function sanitizeDecimal($number) { + $number = str_replace(".","",$number); + $number = str_replace(",",".",$number); + return $number; + } + public function add(Request $request){ $this->validate($request, [ 'proyek_id' => 'required', @@ -19,8 +25,8 @@ class RequestMaterialController extends Controller ]); $data = $request->all(); - $data['price'] = str_replace(",", ".", $data['price']); - $data['qty'] = str_replace(",", ".", $data['qty']); + $data['price'] = $this->sanitizeDecimal($data['price']); + $data['qty'] = $this->sanitizeDecimal($data['qty']); $data['status'] = "fom"; $data['created_by'] = $this->currentName; From d6dcff417710f6f13b2c20098213dfbeac52ff2d Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 27 Jul 2022 06:31:06 +0700 Subject: [PATCH 10/11] endpoint for Dashboard PMO --- app/Http/Controllers/ProjectController.php | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 5402bc8..250ccf6 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -206,12 +206,58 @@ class ProjectController extends Controller public function list() { - $data = Project::all(); + $data = Project::orderBy('id', 'desc')->get(); $countData = $data->count(); if(!$data) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + $costWarningThreshold = 50000000; + $costDangerThreshold = 25000000; + $scheduleWarningThreshold = 10; + $scheduleDangerThreshold = 5; + foreach($data as $d){ + $progress = $costVariance = $actualCost = 0; + $lastActivity = null; + $scheduleHealth = "on-track"; + $costHealth = "on-budget"; + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); + if($rootActivity){ + $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; + $actualCost = $rootActivity->biaya_actual ?? 0; + $progress = $rootActivity->persentase_progress ?? 0; + /* + $timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); + $date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); + $date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); + $daysRemaining = $date2->diff($date1); + $daysRemaining = $daysRemaining->d; + + if($daysRemaining <= $scheduleDangerThreshold) { + $scheduleHealth = "danger"; + } elseif ($daysRemaining <= $scheduleWarningThreshold) { + $scheduleHealth = "warning"; + } + + $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); + */ + if($costVariance <= $costDangerThreshold) { + $costHealth = "danger"; + } elseif ($costVariance <= $costWarningThreshold) { + $costHealth = "warning"; + } + } + $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); + $d->plannedCost = $d->rencana_biaya; + $d->actualCost = $actualCost; + //$d->lastActivity = $lastActivity ?? "-"; + //$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; + $d->costVariance = $costVariance; + $d->costHealth = $costHealth; + //$d->scheduleHealth = $scheduleHealth; + $d->progress = $progress . "%"; + } + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); } From f29bb6a8b1e57b1ddbbc3fe0151ad8a6c99aec0b Mon Sep 17 00:00:00 2001 From: bnu Date: Wed, 27 Jul 2022 15:43:04 +0700 Subject: [PATCH 11/11] solved conflict --- app/Http/Controllers/ProjectController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index fcc8471..4435bbc 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -230,10 +230,9 @@ class ProjectController extends Controller } public function dashboard($id) - { - // $data = Project::WHERE("id", $id)->first(); + { $data = DB::table('m_proyek as mp') - ->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', 'mp.rencana_biaya', 'mp.company', 'mu.name as pm') + ->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', 'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm') ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') ->where('mp.id', $id) ->get();