From 3c35ce0b1864c51053f7374ee16cf0641ba59bbf Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 9 May 2023 00:38:13 +0700 Subject: [PATCH 001/185] update comment integrasi invoice --- app/Http/Controllers/ProjectController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 4689c04..75ab404 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -389,15 +389,16 @@ class ProjectController extends Controller } public function getInvoiceIntegration(Request $request) { - $search = urlencode($request->search); - if(empty($search)) - return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); - $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); + // $search = urlencode($request->search); + // if(empty($search)) + // return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); + // $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); - $response = MasterFunctionsHelper::curlReq($url); + // $response = MasterFunctionsHelper::curlReq($url); - return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); + // return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); + return response()->json(['status'=>'success', 'data'=> '', 'code'=>200], 200); } public function detail($id){ From abf4a5fda9e1c6d00e77df643add2d55a3845805 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 9 May 2023 00:44:23 +0700 Subject: [PATCH 002/185] update comment integrasi invoice --- app/Http/Controllers/ProjectController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 75ab404..4b5c5db 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -396,7 +396,6 @@ class ProjectController extends Controller // $response = MasterFunctionsHelper::curlReq($url); - // return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); return response()->json(['status'=>'success', 'data'=> '', 'code'=>200], 200); } From 0a506bdf48c9b6a4774a925a886a39ecad51ac8f Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 17 May 2023 09:36:03 +0700 Subject: [PATCH 003/185] Using current gantt instead of last gantt --- app/Helpers/MasterFunctionsHelper.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index ebd59b3..86197d7 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -54,7 +54,7 @@ class MasterFunctionsHelper { if(!is_int($request)){ $dataPayload = $request->all(); if(isset($dataPayload['gantt_id'])){ - $allGantt = $dataPayload['gantt_id']; + $allGantt[] = $dataPayload['gantt_id']; }else{ $allGantt[] = MasterFunctionsHelper::getLatestGantt($dataPayload['project_id']); } @@ -62,7 +62,15 @@ class MasterFunctionsHelper { $allGantt[] = MasterFunctionsHelper::getLatestGantt($request); } foreach($allGantt as $gantt){ - $gantt = VersionGantt::where('id', $gantt['last_gantt_id'])->first()->toArray(); + if (!isset($gantt['last_gantt_id'])) { + $ganttId = $gantt; + } else { + $ganttId = $gantt['last_gantt_id']; + } + $gantt = VersionGantt::find($ganttId)->toArray(); + // foreach ($gantt as $key => $value) { + // Log::info('gantt '.$value.' index '.$key); + // } if($gantt['calculation_type'] == 'simple') { // to do return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); From fd87c74fad55ceb49f21b0542779478f38fb6b5d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 17 May 2023 14:02:57 +0700 Subject: [PATCH 004/185] Fix overhead --- app/Http/Controllers/AssignMaterialController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/AssignMaterialController.php b/app/Http/Controllers/AssignMaterialController.php index 5a89147..b3f917a 100644 --- a/app/Http/Controllers/AssignMaterialController.php +++ b/app/Http/Controllers/AssignMaterialController.php @@ -42,7 +42,7 @@ class AssignMaterialController extends Controller $data['budget'] = $checkStock->price; $data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); - if ($planDate > $startDate) { + if ($planDate >= $startDate) { $result = AssignMaterial::create($data); return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200); }else{ From c052fbce16b6c2eec1e861bb0cb33f12122b0f53 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 17 May 2023 15:36:01 +0700 Subject: [PATCH 005/185] Calculation type hack --- app/Helpers/MasterFunctionsHelper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 86197d7..1224d23 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -71,12 +71,14 @@ class MasterFunctionsHelper { // foreach ($gantt as $key => $value) { // Log::info('gantt '.$value.' index '.$key); // } - if($gantt['calculation_type'] == 'simple') { - // to do - return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); - } else { - return MasterFunctionsHelper::calculateProgressBasedOnReportMaterial($gantt); - } + if (isset($gantt['calculation_type'])) { + if($gantt['calculation_type'] == 'simple') { + // to do + return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); + } else { + return MasterFunctionsHelper::calculateProgressBasedOnReportMaterial($gantt); + } + } } } From 34c3bba63031bce83f800e54f64ef78bdf9a2c30 Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 17 May 2023 17:27:39 +0700 Subject: [PATCH 006/185] fix status activity in report material --- app/Helpers/MasterFunctionsHelper.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 86197d7..de07da8 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -213,8 +213,26 @@ class MasterFunctionsHelper { $dataTempReport [$w]['duration'] = $keyActualM->duration; $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; try { + // assign_material_to_activity + $checkStatusActivity = DB::table('assign_material_to_activity') + ->select('activity_id', 'status_activity') + ->where('activity_id', '=', $keyActualM->activity_id) + ->orderBy('status_activity', 'ASC') + ->first(); $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ + if($checkStatusActivity->status_activity == 'done'){ + $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + }else{ + $sumPercentageActual+=(($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning)*(95/100); + } + // }else if($checkStatusActivity->status_activity == 'done'){ + // $sumPercentageActual+=0; + }else{ + $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + } + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); From c3d4d09a99eb7ac6d45ae36981f415f012da3f09 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 19 May 2023 11:32:09 +0700 Subject: [PATCH 007/185] Fix assigned hr dashboard project --- app/Http/Controllers/ProjectController.php | 5 ++--- app/Http/Controllers/UserToActivityController.php | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index fa2ee05..60e7a4d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -456,9 +456,8 @@ class ProjectController extends Controller } public function getManpower($proyek_id){ - $manPower = UserToProyek::where('proyek_id', $proyek_id)->get(); - $manCount = $manPower->count(); - return response()->json(['data'=>$manPower, 'totalRecord'=>$manCount]); + $manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); + return response()->json(['totalRecord'=>$manCount]); } public function getAssignedHR($gantt_id){ diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 048825c..14e67ed 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -41,7 +41,8 @@ class UserToActivityController extends Controller "activity_id" => $request->activity_id, "role_proyek_id" => $users_role[$index], "proyek_id" => $request->proyek_id, - "created_by" => $this->currentName + "created_by" => $this->currentName, + "version_gantt_id" => $request->version_gantt_id ); $result = UserToActivity::create($dataInsert); if($result){ From 69d2855e70b665a7e7e1cfdabdf14abb37536885 Mon Sep 17 00:00:00 2001 From: ibnu Date: Sat, 20 May 2023 10:24:19 +0700 Subject: [PATCH 008/185] update curva S same to progress gantt --- app/Helpers/MasterFunctionsHelper.php | 45 ++++++++++++++++++--------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index ebd5efa..96a61d2 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -223,17 +223,27 @@ class MasterFunctionsHelper { ->first(); $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ + // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ if($checkStatusActivity->status_activity == 'done'){ $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; }else{ - $sumPercentageActual+=(($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning)*(95/100); + if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ + $sumPercentageActual+=(($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning)*(95/100); + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + }else{ + $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } } - // }else if($checkStatusActivity->status_activity == 'done'){ - // $sumPercentageActual+=0; - }else{ - $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - } + // }else { + // if($checkStatusActivity->status_activity == 'done'){ + // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; + // }else{ + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // } + // } + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; } catch (\DivisionByZeroError $e) { @@ -246,7 +256,7 @@ class MasterFunctionsHelper { $arr_ActualM[] = array( 'date'=>$dt->format("Y-m-d"), 'percentPlan'=>$sumPercentagePlan, - 'percentActual'=>$sumPercentageActual, + 'percentActual'=> $sumPercentageActual, 'plan'=>$dataTempPlan, 'actual'=>$dataTempReport, ); @@ -254,12 +264,19 @@ class MasterFunctionsHelper { $tempTtlPercentPlan+= $sumPercentagePlan; $tempTtlPercentActual+= $sumPercentageActual; - if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100){ - if($tempTtlPercentActual >= 100) - $tempTtlPercentActual = 100; + // if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= $keyGantt['progress'];){ + // if($tempTtlPercentActual >= 100) + // $tempTtlPercentActual = 100; + // if($tempTtlPercentPlan >= 100) + // $tempTtlPercentPlan = 100; + + if($tempTtlPercentActual >= $keyGantt['progress']) + $tempTtlPercentActual = $keyGantt['progress']; if($tempTtlPercentPlan >= 100) $tempTtlPercentPlan = 100; - } + // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual + + // } $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; @@ -304,8 +321,8 @@ class MasterFunctionsHelper { $dataResponse = array( "date" =>$tempDate, "percentage" =>$tempPercentage, - "percentagePlan" => $tempPercentagePlan, - "percentageReal" => $tempPercentageReal, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, "data_details" =>$arr_ActualM, "budget_control" =>array("current_budget"=> $totalRencanaBudget, "acwp" => round($totalACWP,0), From 05e34cb66d49da293cdd722f4e2845bd1382267b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 22 May 2023 08:44:40 +0700 Subject: [PATCH 009/185] Gantt ftth parents --- .../Controllers/HierarchyFtthController.php | 24 +++++++++++++++++++ routes/web.php | 1 + 2 files changed, 25 insertions(+) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 388bb2a..6df56a9 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -149,6 +149,30 @@ class HierarchyFtthController extends Controller } } } + + public function getTreeByGantt($gantt_id) + { + $finalData = []; + $gantt = VersionGantt::find($gantt_id); + if ($gantt->hierarchy_ftth_id) { + $ftth = HierarchyFtth::find($gantt->hierarchy_ftth_id); + array_push($finalData, $ftth); + if($ftth->parent_id){ + $this->getParents($finalData, $ftth->parent_id); + } + } else { + return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200); + } + return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200); + } + + public function getParents(&$data, $id){ + $ftth = HierarchyFtth::find($id); + array_push($data, $ftth); + if ($ftth->parent_id) { + $this->getParents($data, $ftth->parent_id); + } + } public function getTreeByProject($project_id) { diff --git a/routes/web.php b/routes/web.php index eb8fe09..d2861e8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -448,6 +448,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update'); $router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy'); $router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject'); + $router->get('/hierarchy-ftths/tree-gantt/{gantt_id}', 'HierarchyFtthController@getTreeByGantt'); $router->post('/map-monitoring/search', 'MapMonitoringController@search'); }); From 02eff6fb8cc629c85a16c10e3e532335c224cde0 Mon Sep 17 00:00:00 2001 From: ibnu Date: Mon, 22 May 2023 14:17:13 +0700 Subject: [PATCH 010/185] fix curva S site --- app/Helpers/MasterFunctionsHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 96a61d2..96311e1 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -225,7 +225,7 @@ class MasterFunctionsHelper { // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ if($checkStatusActivity->status_activity == 'done'){ - $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + $sumPercentageActual+=$keyActualM->bobot_planning; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; }else{ if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ @@ -271,7 +271,7 @@ class MasterFunctionsHelper { // $tempTtlPercentPlan = 100; if($tempTtlPercentActual >= $keyGantt['progress']) - $tempTtlPercentActual = $keyGantt['progress']; + $tempTtlPercentActual = $keyGantt['progress']; if($tempTtlPercentPlan >= 100) $tempTtlPercentPlan = 100; // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual From 1d321b2b4878b20414d389610f970e07ad408b2f Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 23 May 2023 09:06:26 +0700 Subject: [PATCH 011/185] Import Nik --- app/Http/Controllers/ActivityController.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 361826d..a0282e2 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -9,6 +9,8 @@ use App\Models\TemplateGantt; use App\Models\TmpImport; use App\Models\VersionGantt; use App\Models\UserToActivity; +use App\Models\UserToProyek; +use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -462,7 +464,23 @@ class ActivityController extends Controller $activity->type_activity = "project"; $activity->save(); $activity->level = $activity_row['level']; - } + } + if (isset($data['activities'][$i]['nik'])) { + $user = User::where("ktp_number", $data['activities'][$i]['nik'])->first(); + $userProyek = UserToProyek::where("user_id", $user->id) + ->where("proyek_id", $projectId) + ->first(); + + $dataInsert = array( + "user_id" => $user->id, + "activity_id" => $activity->id, + "role_proyek_id" => $userProyek->project_role, + "proyek_id" => $projectId, + "created_by" => $this->currentName, + "version_gantt_id" => $data['ganttId'] + ); + UserToActivity::create($dataInsert); + } if (!empty($activity_row['predecessor'])) { $key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no')); From e7cf2e7ce360fbcd44374a3daca8abf1b264ab91 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 23 May 2023 11:35:42 +0700 Subject: [PATCH 012/185] Fix import nik --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index a0282e2..74da8c8 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -465,7 +465,7 @@ class ActivityController extends Controller $activity->save(); $activity->level = $activity_row['level']; } - if (isset($data['activities'][$i]['nik'])) { + if (isset($data['activities'][$i]['nik']) && $data['activities'][$i]['nik'] != '') { $user = User::where("ktp_number", $data['activities'][$i]['nik'])->first(); $userProyek = UserToProyek::where("user_id", $user->id) ->where("proyek_id", $projectId) From 4ccdb41f6a390dd0056dce0b389b1e62d309212c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 31 May 2023 13:53:21 +0700 Subject: [PATCH 013/185] update import --- app/Http/Controllers/ActivityController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 74da8c8..b23c12b 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -396,9 +396,12 @@ class ActivityController extends Controller } }; } + $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); foreach ($data['activities'] as $i => $activity_row) { - $startDate = \DateTime::createFromFormat('d-m-y', $activity_row['start_date']); - $endDate = \DateTime::createFromFormat('d-m-y H:i:sO', $activity_row['end_date']); + $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); + $endDate = clone $startDate; + $endDate->modify('+'.$activity_row['duration'].' days'); + $endDate->setTime(23, 59, 59); $input['name'] = $activity_row['name']; $input['proyek_id'] = $projectId; $input['version_gantt_id'] = $data['ganttId']; From c4baacd13cc77463765f8a3b6711becc988ca29e Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 2 Jun 2023 14:04:36 +0700 Subject: [PATCH 014/185] Display planning curve without report --- app/Helpers/MasterFunctionsHelper.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 96311e1..f8d1c9f 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -88,7 +88,10 @@ class MasterFunctionsHelper { $dataFinal=[]; $dataPayload = []; - $dataPayload['period'] = 'week'; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; $dataProject = Project::find($keyGantt['proyek_id']); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); @@ -110,9 +113,9 @@ class MasterFunctionsHelper { ->join('m_activity as b', 'b.id', '=', 'a.activity_id') ->where('b.version_gantt_id', '=', $keyGantt['id']) ->exists(); - - if(!$alreadyHasReport) - return $dataFinal; + // note : delete this + // if(!$alreadyHasReport) + // return $dataFinal; $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); From b86511c08b265fa63263f32cabd5d0a2a9dbdc2d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 2 Jun 2023 14:13:11 +0700 Subject: [PATCH 015/185] Fix planning until today not entire project --- app/Helpers/MasterFunctionsHelper.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index f8d1c9f..d7b3536 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -120,22 +120,11 @@ class MasterFunctionsHelper { $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); $begin = new \DateTime($minDate.' Monday'); - if(isset($dataPayload['end_date'])){ - $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate. ' Friday'); - $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged - $interval = new \DateInterval('P7D'); - } else { - $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['id']) - ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's - $end = new \DateTime($maxDate. ' Friday'); - $end->modify('next Friday'); - $interval = new \DateInterval('P7D'); - } + $maxDate = date('Y-m-d'); + $end = new \DateTime($maxDate. ' Friday'); + // $end->modify('next Friday'); + /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged + $interval = new \DateInterval('P7D'); $period = new \DatePeriod($begin, $interval, $end); $arr_ActualM = []; From 293971554c88f4b2002004da369a774a173bd3a8 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 6 Jun 2023 15:58:47 +0700 Subject: [PATCH 016/185] Reversing the s curve --- app/Helpers/MasterFunctionsHelper.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index d7b3536..f8d1c9f 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -120,11 +120,22 @@ class MasterFunctionsHelper { $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); $begin = new \DateTime($minDate.' Monday'); - $maxDate = date('Y-m-d'); - $end = new \DateTime($maxDate. ' Friday'); - // $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged - $interval = new \DateInterval('P7D'); + if(isset($dataPayload['end_date'])){ + $maxDate = $dataPayload['end_date']; + $end = new \DateTime($maxDate. ' Friday'); + $end->modify('next Friday'); + /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged + $interval = new \DateInterval('P7D'); + } else { + $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['id']) + ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $end = new \DateTime($maxDate. ' Friday'); + $end->modify('next Friday'); + $interval = new \DateInterval('P7D'); + } $period = new \DatePeriod($begin, $interval, $end); $arr_ActualM = []; From aaabf0d21087438021b9f51bdea0c62bdd7b18ab Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 7 Jun 2023 11:38:18 +0700 Subject: [PATCH 017/185] Remove gantt progress checker --- app/Helpers/MasterFunctionsHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index f8d1c9f..5a1f77e 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -273,8 +273,8 @@ class MasterFunctionsHelper { // if($tempTtlPercentPlan >= 100) // $tempTtlPercentPlan = 100; - if($tempTtlPercentActual >= $keyGantt['progress']) - $tempTtlPercentActual = $keyGantt['progress']; + // if($tempTtlPercentActual >= $keyGantt['progress']) + // $tempTtlPercentActual = $keyGantt['progress']; if($tempTtlPercentPlan >= 100) $tempTtlPercentPlan = 100; // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual From d2d3d6bad871bb4e44a4494bcc60ac292f1d2e98 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 7 Jun 2023 13:57:46 +0700 Subject: [PATCH 018/185] Fix dashboard error --- app/Helpers/MasterFunctionsHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 5a1f77e..04f3076 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -192,7 +192,10 @@ class MasterFunctionsHelper { try { $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; + if(isset($keyPlanM->duration) && $keyPlanM->duration > 0) + $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; + else + $totalBCWP = 0; $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); From e2d1bb425e19432183c28ec432a412dd206e5aa7 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 7 Jun 2023 14:54:12 +0700 Subject: [PATCH 019/185] Fix lag --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index b23c12b..8635b25 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -502,7 +502,7 @@ class ActivityController extends Controller 'type_link' => 0, 'code_link' => 'FS', 'version_gantt_id' => $data['ganttId'], - 'lag' => $diff > 1 ? $diff : null, + 'lag' => null, ]); } } From f6a05748573fd37780a36bb9c56290113889b5cd Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 8 Jun 2023 08:52:45 +0700 Subject: [PATCH 020/185] Fix link creation --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 8635b25..23ef012 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -488,7 +488,7 @@ class ActivityController extends Controller if (!empty($activity_row['predecessor'])) { $key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no')); - if (!$predecessorActivity = Activity::find($data['activities'][$key]['activity_id'])) + if (!isset($data['activities'][$key]['activity_id']) || !$predecessorActivity = Activity::find($data['activities'][$key]['activity_id'])) continue; $predecessorFinishDate = new \DateTime($predecessorActivity->end_date); From 9f85cda9a1d25342099d6ff7b522f3f99c2d109c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 8 Jun 2023 09:03:05 +0700 Subject: [PATCH 021/185] Fix report activity material validation --- app/Http/Controllers/ReportActivityMaterialController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index fd61e5f..54be3e0 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -35,7 +35,7 @@ class ReportActivityMaterialController extends Controller /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ $data['assign_material_id'] = $request->assign_material_id; $data['qty'] = $this->sanitizeDecimal($data['qty']); - if($reportDate > $startDate){ + if($reportDate >= $startDate){ $created = ReportActivityMaterial::create($data); return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); } else { From 9ae2f37029b1a3557b1732d7b646c2277910677f Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 8 Jun 2023 09:11:37 +0700 Subject: [PATCH 022/185] Remove weight pro rate --- app/Http/Controllers/ActivityController.php | 90 ++++++++++----------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 23ef012..3c60307 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -351,51 +351,51 @@ class ActivityController extends Controller $activityStack = []; - $hasWeight = false; - - foreach ($data['activities'] as $key => $value) { - if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){ - $hasWeight = true; - break; - } - } - - if(!$hasWeight){ - foreach ($data['activities'] as $key => $value) { - if($key == 0){ - $data['activities'][$key]['weight'] = 100; - } else { - $parentWeight = 0; - $siblingsCount = 1; - - $i = $key; - while($i > 0){ - if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){ - $parentWeight = $data['activities'][$i - 1]['weight']; - break; - } - if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ - $siblingsCount++; - } - $i--; - } - - $i = $key+1; - while($i < count($data['activities'])){ - if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){ - break; - } - // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); - if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ - $siblingsCount++; - } - $i++; - } - - $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; - } - }; - } + // $hasWeight = false; + // + // foreach ($data['activities'] as $key => $value) { + // if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){ + // $hasWeight = true; + // break; + // } + // } + // + // if(!$hasWeight){ + // foreach ($data['activities'] as $key => $value) { + // if($key == 0){ + // $data['activities'][$key]['weight'] = 100; + // } else { + // $parentWeight = 0; + // $siblingsCount = 1; + // + // $i = $key; + // while($i > 0){ + // if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){ + // $parentWeight = $data['activities'][$i - 1]['weight']; + // break; + // } + // if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ + // $siblingsCount++; + // } + // $i--; + // } + // + // $i = $key+1; + // while($i < count($data['activities'])){ + // if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){ + // break; + // } + // // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); + // if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ + // $siblingsCount++; + // } + // $i++; + // } + // + // $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; + // } + // }; + // } $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); foreach ($data['activities'] as $i => $activity_row) { $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); From cfe27e2a226f11a010703a4617d820c5431a9389 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 8 Jun 2023 11:18:09 +0700 Subject: [PATCH 023/185] Fix actual progress calculation --- app/Helpers/MasterFunctionsHelper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 04f3076..8fb7284 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -212,6 +212,7 @@ class MasterFunctionsHelper { ->where('activity_id', '=', $keyActualM->activity_id) ->groupBy('activity_id') ->first(); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; $dataTempReport [$w]['qty'] = $keyActualM->qty; $dataTempReport [$w]['report_date'] = $keyActualM->report_date; @@ -231,7 +232,7 @@ class MasterFunctionsHelper { // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ if($checkStatusActivity->status_activity == 'done'){ - $sumPercentageActual+=$keyActualM->bobot_planning; + $sumPercentageActual+=$keyActualM->bobot_planning/$reportCount; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; }else{ if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ From beed9508325d7a8fdedce506e187634fcb3e9c62 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 8 Jun 2023 12:31:59 +0700 Subject: [PATCH 024/185] Revert pro rate --- app/Http/Controllers/ActivityController.php | 90 ++++++++++----------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 3c60307..23ef012 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -351,51 +351,51 @@ class ActivityController extends Controller $activityStack = []; - // $hasWeight = false; - // - // foreach ($data['activities'] as $key => $value) { - // if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){ - // $hasWeight = true; - // break; - // } - // } - // - // if(!$hasWeight){ - // foreach ($data['activities'] as $key => $value) { - // if($key == 0){ - // $data['activities'][$key]['weight'] = 100; - // } else { - // $parentWeight = 0; - // $siblingsCount = 1; - // - // $i = $key; - // while($i > 0){ - // if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){ - // $parentWeight = $data['activities'][$i - 1]['weight']; - // break; - // } - // if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ - // $siblingsCount++; - // } - // $i--; - // } - // - // $i = $key+1; - // while($i < count($data['activities'])){ - // if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){ - // break; - // } - // // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); - // if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ - // $siblingsCount++; - // } - // $i++; - // } - // - // $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; - // } - // }; - // } + $hasWeight = false; + + foreach ($data['activities'] as $key => $value) { + if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){ + $hasWeight = true; + break; + } + } + + if(!$hasWeight){ + foreach ($data['activities'] as $key => $value) { + if($key == 0){ + $data['activities'][$key]['weight'] = 100; + } else { + $parentWeight = 0; + $siblingsCount = 1; + + $i = $key; + while($i > 0){ + if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){ + $parentWeight = $data['activities'][$i - 1]['weight']; + break; + } + if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ + $siblingsCount++; + } + $i--; + } + + $i = $key+1; + while($i < count($data['activities'])){ + if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){ + break; + } + // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); + if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ + $siblingsCount++; + } + $i++; + } + + $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; + } + }; + } $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); foreach ($data['activities'] as $i => $activity_row) { $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); From bee51f8ce50ef94cad8523c9640f08bd0a07c4a3 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 9 Jun 2023 15:00:42 +0700 Subject: [PATCH 025/185] Remove progress status checker --- app/Models/ReportActivityMaterial.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/Models/ReportActivityMaterial.php b/app/Models/ReportActivityMaterial.php index 75b0817..44db31c 100644 --- a/app/Models/ReportActivityMaterial.php +++ b/app/Models/ReportActivityMaterial.php @@ -61,15 +61,10 @@ class ReportActivityMaterial extends Model $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); - if($dataPlan[0]->status_activity == 'done'){ - $activity->persentase_progress = 100; - } else { $totalPlan = $dataPlan->sum('qty_planning'); $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); $percentage = ($totalVolumeActual * 100) / $totalPlan; $activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; - } - $activity->save(); }); From af770faae999a15779131db169d10ed816836b72 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 9 Jun 2023 16:04:21 +0700 Subject: [PATCH 026/185] Fix refresh --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 23ef012..c9a2081 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -247,7 +247,7 @@ class ActivityController extends Controller if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400); - $updateBobot = true; + $updateBobot = false; if(!$data = Activity::find($id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404); $dataUpdate = $request->all(); From 23268a3d515061cb610f62319cccf4be0bcd398e Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 12 Jun 2023 08:36:39 +0700 Subject: [PATCH 027/185] Fix update bobot --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index c9a2081..23ef012 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -247,7 +247,7 @@ class ActivityController extends Controller if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400); - $updateBobot = false; + $updateBobot = true; if(!$data = Activity::find($id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404); $dataUpdate = $request->all(); From e5ce9156b4d2eb66a921e5302c13234ec2ac020b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 12 Jun 2023 13:33:32 +0700 Subject: [PATCH 028/185] Fix jobs done --- app/Models/Activity.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index ce49289..29ab815 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -188,6 +188,8 @@ class Activity extends Model return 0; if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) return 0; + if($dataPlan->isEmpty()) + return 0; if($dataPlan[0]->status_activity == 'done') return 100; return $this->persentase_progress; From 5a7a2690690bf283765d3146073ddbb514d07ac3 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 13 Jun 2023 15:11:47 +0700 Subject: [PATCH 029/185] Fix import WIP --- app/Http/Controllers/ActivityController.php | 40 ++++++++++++++++++++- app/Models/Activity.php | 10 ++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 23ef012..35615b2 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -348,6 +348,7 @@ class ActivityController extends Controller Activity::where('version_gantt_id', $data['ganttId'])->delete(); $projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id; + $dayOffs = VersionGantt::find($data['ganttId'])->first()->config_dayoff; $activityStack = []; @@ -400,7 +401,23 @@ class ActivityController extends Controller foreach ($data['activities'] as $i => $activity_row) { $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); $endDate = clone $startDate; - $endDate->modify('+'.$activity_row['duration'].' days'); + // $endDate->modify('+'.$activity_row['duration'].' days'); + + $daysRemaining = $activity_row['duration']; + + // Loop until the remaining days become zero + while ($daysRemaining > 0) { + $endDate->modify('+1 day'); + + // Check if the current day is a day off (Sunday or Saturday) + $currentDayOfWeek = (int)$endDate->format('w'); + if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) { + continue; // Skip the day off and continue to the next day + } + + $daysRemaining--; // Decrease the remaining days by one + } + Log::info('create ', [$activity_row['duration'], $startDate, $endDate]); $endDate->setTime(23, 59, 59); $input['name'] = $activity_row['name']; $input['proyek_id'] = $projectId; @@ -494,6 +511,27 @@ class ActivityController extends Controller $predecessorFinishDate = new \DateTime($predecessorActivity->end_date); $interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date)); $diff = $interval->days; + unset($activity->level); + $successorStartDate = $predecessorFinishDate; + $successorEndDate = clone $successorStartDate; + $daysRemaining = $activity->duration; + + // Loop until the remaining days become zero + while ($daysRemaining > 1) { + $successorEndDate->modify('+1 day'); + + // Check if the current day is a day off (Sunday or Saturday) + $currentDayOfWeek = (int)$successorEndDate->format('w'); + if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) { + continue; // Skip the day off and continue to the next day + } + + $daysRemaining--; // Decrease the remaining days by one + } + Log::info('update ', [$activity->id, $activity->duration, $successorStartDate, $successorEndDate]); + $activity->start_date = $successorStartDate; + $activity->end_date = $successorEndDate; + $activity->save(); Link::create([ 'created_by' => $this->currentName, diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 29ab815..1b98d03 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -36,6 +36,11 @@ class Activity extends Model public function getStartDateAttribute($value) { + if ($value instanceof \DateTime) { + return Carbon::instance($value) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } return Carbon::createFromTimestamp(strtotime($value)) ->timezone(env('APP_TIMEZONE')) ->toDateTimeString(); @@ -43,6 +48,11 @@ class Activity extends Model public function getEndDateAttribute($value) { + if ($value instanceof \DateTime) { + return Carbon::instance($value) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } return Carbon::createFromTimestamp(strtotime($value)) ->timezone(env('APP_TIMEZONE')) ->toDateTimeString(); From 8ee23fdcf5a57b77bf284c62fc9d4ece77699597 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 14 Jun 2023 17:06:21 +0700 Subject: [PATCH 030/185] Import update date --- app/Http/Controllers/ActivityController.php | 11 +++++++++++ routes/web.php | 1 + 2 files changed, 12 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 35615b2..c879a1c 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -776,4 +776,15 @@ class ActivityController extends Controller } return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400); } + + public function importUpdate(Request $request) { + $data = $request->all(); + foreach ($data as $value) { + $activity = Activity::find($value['id']); + $activity->start_date = $value['start_date']; + $activity->end_date = $value['end_date']; + $activity->save(); + } + return response()->json(['status'=>'success','data'=>$request,'message'=>'Update successful!','code'=>200], 200); + } } diff --git a/routes/web.php b/routes/web.php index d2861e8..7eacf60 100644 --- a/routes/web.php +++ b/routes/web.php @@ -202,6 +202,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->get('/activity/search', 'ActivityController@search'); $router->post('/activity/import', 'ActivityController@import'); + $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/task', 'ActivityController@add'); $router->get('/task/edit/{id}', 'ActivityController@edit'); From e39192b54d69a4134a31557c3d5d8b6442eddbf8 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 15 Jun 2023 09:31:21 +0700 Subject: [PATCH 031/185] Remove duration modifiers --- app/Http/Controllers/ActivityController.php | 39 +-------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index c879a1c..13dca16 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -401,23 +401,7 @@ class ActivityController extends Controller foreach ($data['activities'] as $i => $activity_row) { $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); $endDate = clone $startDate; - // $endDate->modify('+'.$activity_row['duration'].' days'); - - $daysRemaining = $activity_row['duration']; - - // Loop until the remaining days become zero - while ($daysRemaining > 0) { - $endDate->modify('+1 day'); - - // Check if the current day is a day off (Sunday or Saturday) - $currentDayOfWeek = (int)$endDate->format('w'); - if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) { - continue; // Skip the day off and continue to the next day - } - - $daysRemaining--; // Decrease the remaining days by one - } - Log::info('create ', [$activity_row['duration'], $startDate, $endDate]); + $endDate->modify('+'.$activity_row['duration'].' days'); $endDate->setTime(23, 59, 59); $input['name'] = $activity_row['name']; $input['proyek_id'] = $projectId; @@ -511,27 +495,6 @@ class ActivityController extends Controller $predecessorFinishDate = new \DateTime($predecessorActivity->end_date); $interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date)); $diff = $interval->days; - unset($activity->level); - $successorStartDate = $predecessorFinishDate; - $successorEndDate = clone $successorStartDate; - $daysRemaining = $activity->duration; - - // Loop until the remaining days become zero - while ($daysRemaining > 1) { - $successorEndDate->modify('+1 day'); - - // Check if the current day is a day off (Sunday or Saturday) - $currentDayOfWeek = (int)$successorEndDate->format('w'); - if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) { - continue; // Skip the day off and continue to the next day - } - - $daysRemaining--; // Decrease the remaining days by one - } - Log::info('update ', [$activity->id, $activity->duration, $successorStartDate, $successorEndDate]); - $activity->start_date = $successorStartDate; - $activity->end_date = $successorEndDate; - $activity->save(); Link::create([ 'created_by' => $this->currentName, From 24234e3f8617b98ba2bf4212fe5410543a914b42 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 19 Jun 2023 10:46:01 +0700 Subject: [PATCH 032/185] Fix backend duration --- app/Http/Controllers/ActivityController.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 13dca16..fc3e04e 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -401,7 +401,21 @@ class ActivityController extends Controller foreach ($data['activities'] as $i => $activity_row) { $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); $endDate = clone $startDate; - $endDate->modify('+'.$activity_row['duration'].' days'); + $endDate->modify('-1 day'); + $daysRemaining = $activity_row['duration']; + + // Loop until the remaining days become zero + while ($daysRemaining > 0) { + $endDate->modify('+1 day'); + + // Check if the current day is a day off (Sunday or Saturday) + $currentDayOfWeek = (int)$endDate->format('w'); + if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) { + continue; // Skip the day off and continue to the next day + } + + $daysRemaining--; // Decrease the remaining days by one + } $endDate->setTime(23, 59, 59); $input['name'] = $activity_row['name']; $input['proyek_id'] = $projectId; @@ -744,6 +758,7 @@ class ActivityController extends Controller $data = $request->all(); foreach ($data as $value) { $activity = Activity::find($value['id']); + $activity->duration = $value['duration']; $activity->start_date = $value['start_date']; $activity->end_date = $value['end_date']; $activity->save(); From 43468b06540927c08a3f3e426ef00692a0b48eb7 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 19 Jun 2023 16:16:00 +0700 Subject: [PATCH 033/185] Fix progress s curve --- app/Helpers/MasterFunctionsHelper.php | 74 +++++++++++++++++++-------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 8fb7284..406020d 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -120,9 +120,11 @@ class MasterFunctionsHelper { $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); $begin = new \DateTime($minDate.' Monday'); + $begin->modify('last Monday'); if(isset($dataPayload['end_date'])){ $maxDate = $dataPayload['end_date']; $end = new \DateTime($maxDate. ' Friday'); + $end->modify('next Friday'); $end->modify('next Friday'); /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged $interval = new \DateInterval('P7D'); @@ -133,6 +135,7 @@ class MasterFunctionsHelper { ->where('a.version_gantt_id', '=', $keyGantt['id']) ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's $end = new \DateTime($maxDate. ' Friday'); + $end->modify('next Friday'); $end->modify('next Friday'); $interval = new \DateInterval('P7D'); } @@ -152,14 +155,35 @@ class MasterFunctionsHelper { foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); - $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['id']) - ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) - ->whereDate('ama.plan_date', '>', $minSevenDays) - ->get(); + // $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['id']) + // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) + // ->whereDate('ama.plan_date', '>', $minSevenDays) + // ->get(); + + $activities = DB::table('m_activity AS a') + ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->whereDate('amta.plan_date', '<=',$dt->format("Y-m-d")) + ->whereDate('amta.plan_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); + + $dataPlanM = DB::table('m_activity AS a') + ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->whereDate('a.start_date', '<=',$dt->format("Y-m-d")) + ->whereDate('a.start_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') + ->union($activities) + ->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') @@ -175,23 +199,33 @@ class MasterFunctionsHelper { $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; + $sumVolPlan = DB::table(function ($query) use ($keyGantt) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->unionAll(function ($query) use ($keyGantt){ + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']); + }) + ->orderBy('id', 'asc'); + }, 'subquery') + ->sum('bobot_planning'); + $dataTempPlan [$x]['activity_id'] = $keyPlanM->id; $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan; + $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan; $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; $dataTempPlan [$x]['duration'] = $keyPlanM->duration; $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; try { - $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; - $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; + $dataTempPlan [$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan+= $keyPlanM->bobot_planning; if(isset($keyPlanM->duration) && $keyPlanM->duration > 0) $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; else From 51b879ca5047020bdeaae83395cd53fc923ba344 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 20 Jun 2023 13:30:31 +0700 Subject: [PATCH 034/185] Fix s curve calculation --- app/Helpers/MasterFunctionsHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 406020d..24cd2a1 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -246,6 +246,9 @@ class MasterFunctionsHelper { ->where('activity_id', '=', $keyActualM->activity_id) ->groupBy('activity_id') ->first(); + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; $dataTempReport [$w]['qty'] = $keyActualM->qty; @@ -269,7 +272,7 @@ class MasterFunctionsHelper { $sumPercentageActual+=$keyActualM->bobot_planning/$reportCount; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; }else{ - if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ + if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1 || (int)$sumVolActual->ttl_qty_plan == (int)$sumReportActual){ $sumPercentageActual+=(($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning)*(95/100); // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; }else{ From 7d7824c98e89cac9c08dda5beec12c366df18d3d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 21 Jun 2023 09:03:47 +0700 Subject: [PATCH 035/185] Fix import activity stack --- app/Http/Controllers/ActivityController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index fc3e04e..144b92c 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -467,6 +467,7 @@ class ActivityController extends Controller } $activity->parent_id = $activityStack[count($activityStack) - 1]->id ?? null; + array_push($activityStack, $activity); // there should be better way to except / filter attribute level before save because it's cause error // cant use except() / filter() on $activity collection somehow unset($activity->level); From b3b178d8ec053e27ec2f644971271d89ffa80edf Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 22 Jun 2023 16:26:47 +0700 Subject: [PATCH 036/185] Fix progress data type and daysoff duration --- app/Http/Controllers/ActivityController.php | 4 +-- app/Models/VersionGantt.php | 36 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 144b92c..c31e50b 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -107,7 +107,7 @@ class ActivityController extends Controller foreach($data as $objRow){ $objRow->parent = $parent_id; $objRow->text = $objRow->name; - $objRow->progress = (int)$objRow->persentase_progress/100; + $objRow->progress = (float)$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"); @@ -323,7 +323,7 @@ class ActivityController extends Controller 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->progress = (float) $data->persentase_progress / 100; $data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya); return response()->json(['status'=>'success', "data"=> $data,'code'=>200], 200); } diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 72c6185..236bff2 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -3,6 +3,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use App\Models\Activity; +use DateTime; class VersionGantt extends Model { @@ -28,4 +30,38 @@ class VersionGantt extends Model 'updated_at', 'updated_by' ]; + + public static function boot() { + parent::boot(); + + static::updated(function($data) { + $data->updateActDuration(); + }); + } + + public function updateActDuration(){ + $daysOff = explode(',', $this->config_dayoff); + $activities = Activity::where('version_gantt_id', $this->id)->get(); + foreach ($activities as $value) { + $startDate = new DateTime($value->start_date); + $endDate = new DateTime($value->end_date); + $duration = $endDate->diff($startDate)->days + 1; + + // Iterate through each day and subtract the days off + for ($i = 0; $i < $duration; $i++) { + $currentDate = clone $startDate; + $currentDate->modify("+$i day"); + + $currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) + + if (in_array($currentDayOfWeek, $daysOff)) { + $duration--; // Subtract one day from the duration for each day off + } + } + + // Update the activity duration + $value->duration = $duration; + $value->save(); + } + } } From a8ea220e2486ae1f20bf7fe58204d7d5294f5520 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 23 Jun 2023 10:03:06 +0700 Subject: [PATCH 037/185] Adjusting daysof into php format --- app/Models/VersionGantt.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 236bff2..0784bbe 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -41,6 +41,10 @@ class VersionGantt extends Model public function updateActDuration(){ $daysOff = explode(',', $this->config_dayoff); + if (in_array('0', $daysOff)) { + $key = array_search('0', $daysOff, false); + $daysOff[$key] = '7'; + } $activities = Activity::where('version_gantt_id', $this->id)->get(); foreach ($activities as $value) { $startDate = new DateTime($value->start_date); From b79f558b40dac10e028dd5c1684d0b1609e120a8 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 23 Jun 2023 14:58:24 +0700 Subject: [PATCH 038/185] Fix successor duration --- app/Models/VersionGantt.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 0784bbe..05abbf6 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use App\Models\Activity; +use App\Models\Link; use DateTime; class VersionGantt extends Model @@ -47,9 +48,13 @@ class VersionGantt extends Model } $activities = Activity::where('version_gantt_id', $this->id)->get(); foreach ($activities as $value) { + $exist = Link::where('t_activity_id', $value->id)->exists(); $startDate = new DateTime($value->start_date); $endDate = new DateTime($value->end_date); $duration = $endDate->diff($startDate)->days + 1; + if ($exist) { + $duration--; + } // Iterate through each day and subtract the days off for ($i = 0; $i < $duration; $i++) { From 7ed4861ebbc7c7720482c3d35f5097daa1bbf89c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 26 Jun 2023 11:24:00 +0700 Subject: [PATCH 039/185] Change danger into overrun --- app/Http/Controllers/ProjectController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 60e7a4d..41d1b51 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -274,7 +274,7 @@ class ProjectController extends Controller $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); $totalActualCost = $data->sum('actualCost'); $manpowers = User::count(); - $projectsOnDanger = Project::where('budget_health', 'danger')->count(); + $projectsOnDanger = Project::where('budget_health', 'overrun')->count(); $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); $projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); try { From 18780a09c31e5210cba80e647e0da678757c5b8e Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 27 Jun 2023 08:41:55 +0700 Subject: [PATCH 040/185] Fix project by schedule health --- app/Http/Controllers/DashboardBoDController.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 273d568..8e851cb 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -127,13 +127,19 @@ class DashboardBoDController extends Controller $projects = Project::where('mulai_proyek', 'like', $year)->get(); foreach($projects as $project) { - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + $selisihProgress = 0; + if($project->scurve && $project->scurve[0]){ + $planningProgress = $project->scurve[0]['data']['percentagePlan'][count($project->scurve[0]['data']['percentagePlan'])-1]; + $actualProgress = $project->scurve[0]['data']['percentageReal'][count($project->scurve[0]['data']['percentageReal'])-1]; + } + $selisihProgress = $planningProgress - $actualProgress; try { - if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) + if($selisihProgress > 0 && $selisihProgress <= 5) $return['warning'] += 1; - elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) + elseif($selisihProgress > 5 && $selisihProgress <= 100) $return['behind-schedule'] += 1; - elseif(@$project->scurve['difference'] == 0) + elseif($selisihProgress == 0) $return['on-schedule'] += 1; } catch (\Error $e) { return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); From 60b45418a6b1f6199799262ee0653d124ad4606c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Sun, 2 Jul 2023 13:48:36 +0700 Subject: [PATCH 041/185] Initial linear curve --- app/Helpers/MasterFunctionsHelper.php | 54 +++++++++++++++++++ .../Controllers/HierarchyFtthController.php | 7 ++- app/Http/Controllers/ProjectController.php | 7 ++- .../Controllers/VersionGanttController.php | 3 +- app/Models/HierarchyFtth.php | 2 +- app/Models/VersionGantt.php | 1 + routes/web.php | 1 + 7 files changed, 71 insertions(+), 4 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 24cd2a1..49877be 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -5,6 +5,7 @@ namespace App\Helpers; use App\Models\Activity; use App\Models\Project; use App\Models\VersionGantt; +use App\Models\HierarchyFtth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -82,6 +83,59 @@ class MasterFunctionsHelper { } } + public function getLinearSCurve($request){ + $ftths = HierarchyFtth::where('project_id', $request->project_id)->get(); + $ttlProgress = 0; + $ttlPlanning = 0; + + foreach ($ftths as $ftth) { + $progress = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('progress'); + $planning = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('bobot'); + $ttlProgress += $progress; + $ttlPlanning += $planning; + } + + $minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first(); + $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); + + $begin = new \DateTime($minDate->mulai_proyek. ' Monday'); + $begin->modify('last Monday'); + + $end = new \DateTime($maxDate->akhir_proyek. ' Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); + + $interval = new \DateInterval('P7D'); + + $period = new \DatePeriod($begin, $interval, $end); + $dates = iterator_to_array($period); + $count = count($dates); + + $avgProgress = $ttlProgress/$count; + $avgPlanning = $ttlPlanning/$count; + $progressData = []; + $planningData = []; + $tempProgress = 0; + $tempPlanning = 0; + + foreach($period as $p){ + array_push($progressData, $tempProgress); + array_push($planningData, $tempPlanning); + $tempProgress += $avgProgress; + $tempPlanning += $avgPlanning; + } + + $dataResponse = array( + "percentagePlan" => $progressData, + "percentageReal" => $planningData, + ); + + $dataFinal[] = array( + "data"=>$dataResponse, + ); + return $dataFinal; + } + public function calculateProgressBasedOnReportMaterial($keyGantt) { DB::enableQueryLog(); diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 6df56a9..3b3f64f 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -110,12 +110,15 @@ class HierarchyFtthController extends Controller if($ftthIds){ foreach ($ftthIds as $ftthId) { $gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress'); + $bobot_planning = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('bobot'); $ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); $ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); if($ftth){ $round = $gantts/$ganttCount; + $round_bobot = $bobot_planning/$ganttCount; $ftth->progress = round($round, 2); + $ftth->bobot_planning = round($round_bobot, 2); try { $ftth->save(); } catch (\Exception $e) { @@ -189,6 +192,7 @@ class HierarchyFtthController extends Controller foreach ($progress as $p) { if ($p->id == $gantt->id) { $gantt->progress = $p->persentase_progress; + $gantt->bobot_planning = $p->bobot_planning ? $p->bobot_planning : 0; } } } @@ -216,6 +220,7 @@ class HierarchyFtthController extends Controller foreach ($progress as $p) { if ($p->id == $gantt->id) { $gantt->progress = $p->persentase_progress; + $gantt->bobot_planning = $p->bobot_planning ? $p->bobot_planning : 0; } } } @@ -228,7 +233,7 @@ class HierarchyFtthController extends Controller } public function ganttProgress($column, $value){ - $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress') + $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning') ->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id') ->where("m_version_gantt.".$column, $value) ->where('m_activity.type_activity', "project") diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 41d1b51..ba90377 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -330,6 +330,11 @@ class ProjectController extends Controller public function getSCurve(Request $request){ $data = MasterFunctionsHelper::getSCurve($request); return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); + } + + public function getLinearSCurve(Request $request){ + $data = MasterFunctionsHelper::getLinearSCurve($request); + return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); } public function synchronizeReport($gantt_id) @@ -412,7 +417,7 @@ class ProjectController extends Controller $gantt = MasterFunctionsHelper::getLatestGantt($id); $result->projectManager = User::where('id', $result->pm_id)->value('name'); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first(); - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); } public function getOverdueActivities(Request $request){ diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index b66dc3f..97b5857 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -91,7 +91,7 @@ class VersionGanttController extends Controller } public function ganttProgress($column, $value){ - $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress') + $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning') ->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id') ->where("m_version_gantt.".$column, $value) // ->where('m_activity.type_activity', "project") @@ -100,6 +100,7 @@ class VersionGanttController extends Controller foreach($progress as $item) { if($item->persentase_progress){ $item->progress = $item->persentase_progress; + $item->bobot = $item->bobot_planning; $item->save(); } } diff --git a/app/Models/HierarchyFtth.php b/app/Models/HierarchyFtth.php index 9a94bfc..34fd7d3 100644 --- a/app/Models/HierarchyFtth.php +++ b/app/Models/HierarchyFtth.php @@ -12,6 +12,6 @@ class HierarchyFtth extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress' + 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning' ]; } diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 05abbf6..4409af8 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -25,6 +25,7 @@ class VersionGantt extends Model 'committed_cost', 'cost_to_complete', 'progress', + 'bobot', 'hierarchy_ftth_id', 'created_at', 'created_by', diff --git a/routes/web.php b/routes/web.php index 7eacf60..c65786d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -66,6 +66,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR'); $router->post('/project/get-s-curve', 'ProjectController@getSCurve'); + $router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve'); $router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities'); $router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration'); $router->post('/project/get-report-distribution', 'ProjectController@getReportDistribution'); From e644cb4782ad3815bd25cc42d84d3929895307d7 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 3 Jul 2023 12:42:01 +0700 Subject: [PATCH 042/185] Adjusting s curve --- app/Helpers/MasterFunctionsHelper.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 49877be..1a07007 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -111,23 +111,26 @@ class MasterFunctionsHelper { $dates = iterator_to_array($period); $count = count($dates); - $avgProgress = $ttlProgress/$count; - $avgPlanning = $ttlPlanning/$count; + $avgProgress = $ttlProgress/$ttlPlanning/$count*100; + $avgPlanning = $ttlPlanning/$ttlPlanning/$count*100; $progressData = []; $planningData = []; + $dates = []; $tempProgress = 0; $tempPlanning = 0; foreach($period as $p){ array_push($progressData, $tempProgress); array_push($planningData, $tempPlanning); + array_push($dates, $p->format("Y-m-d")); $tempProgress += $avgProgress; $tempPlanning += $avgPlanning; } $dataResponse = array( - "percentagePlan" => $progressData, - "percentageReal" => $planningData, + "percentagePlan" => $planningData, + "percentageReal" => $progressData, + "date" => $dates, ); $dataFinal[] = array( From 39a8fd6b40ea8bc01c3f9710d09f341c71551cb8 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 3 Jul 2023 16:55:30 +0700 Subject: [PATCH 043/185] Fix progress --- app/Helpers/MasterFunctionsHelper.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 1a07007..54af18a 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -99,11 +99,8 @@ class MasterFunctionsHelper { $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); $begin = new \DateTime($minDate->mulai_proyek. ' Monday'); - $begin->modify('last Monday'); $end = new \DateTime($maxDate->akhir_proyek. ' Friday'); - $end->modify('next Friday'); - $end->modify('next Friday'); $interval = new \DateInterval('P7D'); @@ -118,13 +115,14 @@ class MasterFunctionsHelper { $dates = []; $tempProgress = 0; $tempPlanning = 0; - + array_push($progressData, round($tempProgress, 2)); + array_push($planningData, round($tempPlanning, 2)); foreach($period as $p){ - array_push($progressData, $tempProgress); - array_push($planningData, $tempPlanning); - array_push($dates, $p->format("Y-m-d")); $tempProgress += $avgProgress; $tempPlanning += $avgPlanning; + array_push($progressData, round($tempProgress, 2)); + array_push($planningData, round($tempPlanning, 2)); + array_push($dates, $p->format("Y-m-d")); } $dataResponse = array( From 8784a28a145ff6325ccb6e939e264e68f3969f9b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 4 Jul 2023 16:46:57 +0700 Subject: [PATCH 044/185] Fix s curve --- app/Console/Commands/CalculateSCurve.php | 31 +++ app/Console/Kernel.php | 3 +- app/Helpers/MasterFunctionsHelper.php | 274 +++++++++++++++++++++ app/Http/Controllers/ProjectController.php | 12 + app/Models/Project.php | 2 + routes/web.php | 2 + 6 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/CalculateSCurve.php diff --git a/app/Console/Commands/CalculateSCurve.php b/app/Console/Commands/CalculateSCurve.php new file mode 100644 index 0000000..72a2e37 --- /dev/null +++ b/app/Console/Commands/CalculateSCurve.php @@ -0,0 +1,31 @@ +argument('project_id'); + $project = Project::find($project_id); + + $project->calculation_status = true; + $project->save(); + + $data = MasterFunctionsHelper::CalculateSCurve($project_id); + + $project->scurve = json_encode($data); + $project->calculation_status = true; + $project->save(); + + return $data; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index a379d80..a7fceee 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,7 +13,8 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ - Commands\syncHumanResourceIntegration::class + Commands\syncHumanResourceIntegration::class, + Commands\CalculateSCurve::class ]; /** diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 54af18a..b93588d 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -442,6 +442,280 @@ class MasterFunctionsHelper { return $dataFinal; } + + public function calculateSCurve($projectId) + { + DB::enableQueryLog(); + + $dataFinal=[]; + $dataPayload = []; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; + + $dataProject = Project::find($projectId); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first(); + if(isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek){ + $dataPayload['end_date'] = $dataProject->akhir_proyek; + } + + if($dataHeader){ + $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya"); + }else{ + $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya"); + } + + $alreadyHasReport = DB::table('report_activity_material as a') + ->select('a.id') + ->join('m_activity as b', 'b.id', '=', 'a.activity_id') + ->exists(); + + $minDate = $dataProject->mulai_proyek; + + $begin = new \DateTime($minDate.' Monday'); + $begin->modify('last Monday'); + if(isset($dataPayload['end_date'])){ + $maxDate = $dataPayload['end_date']; + $end = new \DateTime($maxDate. ' Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); + /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged + $interval = new \DateInterval('P7D'); + } else { + // $maxDate = DB::table('assign_material_to_activity as ama') + // ->where("ama.proyek_id", $projectId) + // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $maxDate = $dataProject->akhir_proyek; + $end = new \DateTime($maxDate. ' Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); + $interval = new \DateInterval('P7D'); + } + $period = new \DatePeriod($begin, $interval, $end); + + $arr_ActualM = []; + $tempDate = []; + $tempPercentagePlan = []; + $tempPercentagePlanWhr = []; + $tempPercentageReal = []; + $tempTtlPercentPlan=0; + $tempTtlPercentActual=0; + + $currentACWP = 0; + $currentBCWP = 0; + + foreach ($period as $dt) { + $minSevenDays = new \Datetime($dt->format("Y-m-d")); + $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); + // $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['id']) + // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) + // ->whereDate('ama.plan_date', '>', $minSevenDays) + // ->get(); + + $activities = DB::table('m_activity AS a') + ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->whereDate('amta.plan_date', '<=',$dt->format("Y-m-d")) + ->whereDate('amta.plan_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); + + $dataPlanM = DB::table('m_activity AS a') + ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->whereDate('a.start_date', '<=',$dt->format("Y-m-d")) + ->whereDate('a.start_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') + ->union($activities) + ->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.proyek_id', '=', $projectId) + ->whereDate('ram.report_date', '<=',$dt->format("Y-m-d")) + ->whereDate('ram.report_date', '>',$minSevenDays) + ->get(); + $dataTempPlan = []; + $x = 0; + $sumPercentagePlan=0; + $totalACWP = isset($totalACWP) ? $totalACWP : 0; + $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; + + foreach ($dataPlanM as $keyPlanM) { + $sumVolPlan = DB::table(function ($query){ + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->unionAll(function ($query){ + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0); + })->orderBy('id', 'asc'); + }, 'subquery') + ->sum('bobot_planning'); + $dataTempPlan [$x]['activity_id'] = $keyPlanM->id; + $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan; + $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan [$x]['duration'] = $keyPlanM->duration; + $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; + try { + $dataTempPlan [$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan+= $keyPlanM->bobot_planning; + if(isset($keyPlanM->duration) && $keyPlanM->duration > 0) + $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; + else + $totalBCWP = 0; + $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $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(); + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $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; + try { + // assign_material_to_activity + $checkStatusActivity = DB::table('assign_material_to_activity') + ->select('activity_id', 'status_activity') + ->where('activity_id', '=', $keyActualM->activity_id) + ->orderBy('status_activity', 'ASC') + ->first(); + $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ + if($checkStatusActivity->status_activity == 'done'){ + $sumPercentageActual+=$keyActualM->bobot_planning/$reportCount; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + }else{ + if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1 || (int)$sumVolActual->ttl_qty_plan == (int)$sumReportActual){ + $sumPercentageActual+=(($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning)*(95/100); + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + }else{ + $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } + } + // }else { + // if($checkStatusActivity->status_activity == 'done'){ + // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; + // }else{ + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // } + // } + + + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $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'){ + $tempTtlPercentPlan+= $sumPercentagePlan; + $tempTtlPercentActual+= $sumPercentageActual; + + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); + $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; + $tempPercentageReal[] = round($tempTtlPercentActual, 2); + }else{ + $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); + $tempPercentagePlan[] = round($sumPercentagePlan, 2); + $tempPercentageReal[] = round($sumPercentageActual, 2); + } + $tempDate[] = array($dt->format("Y-m-d")); + } + + try { + if(round($totalACWP,0) > $totalRencanaBudget){ + $estimatedCost = round($totalACWP,0)+0; + }else{ + $estimatedCost = ($totalRencanaBudget+0); + } + } catch (\DivisionByZeroError $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + ]); + } + $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + + $costDeviation = $totalRencanaBudget - $estimatedCost; + if($costDeviation > 0){ + $potential = "SAVING"; + } else { + $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; + } + + $dataResponse = array( + "date" =>$tempDate, + "percentage" =>$tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "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, + ); + + return $dataFinal; + } public function calculateProgressBasedOnSimple($keyGantt){ DB::enableQueryLog(); diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index ba90377..6e8ca66 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -29,6 +29,7 @@ use App\Models\OfficeHours; use Illuminate\Support\Facades\DB; use App\Helpers\MasterFunctionsHelper; use App\Models\ReportActivityMaterial; +use Illuminate\Support\Facades\Artisan; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; @@ -332,6 +333,17 @@ class ProjectController extends Controller return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); } + public function calculateSCurve(Request $request){ + $sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); + return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200); + } + + public function sCurveCommand(Request $request){ + Artisan::call('calculate:scurve', [ + 'project_id' => $request->project_id + ]); + } + public function getLinearSCurve(Request $request){ $data = MasterFunctionsHelper::getLinearSCurve($request); return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); diff --git a/app/Models/Project.php b/app/Models/Project.php index 452dd62..880efec 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -42,6 +42,8 @@ class Project extends Model 'currency_name', 'budget_health', 'phase_id', + 'calculation_status', + 'scurve', 'created_at', 'created_by', 'updated_at', diff --git a/routes/web.php b/routes/web.php index c65786d..03f769c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -66,6 +66,8 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR'); $router->post('/project/get-s-curve', 'ProjectController@getSCurve'); + $router->post('/project/calculate-s-curve', 'ProjectController@calculateSCurve'); + $router->post('/project/s-curve-command', 'ProjectController@sCurveCommand'); $router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve'); $router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities'); $router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration'); From ce46b3b61c88f54b707ec3b30e5635f95e15dd5d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 6 Jul 2023 11:40:16 +0700 Subject: [PATCH 045/185] Fix ftth & fix scurve duration span --- app/Console/Commands/CalculateSCurve.php | 2 -- app/Helpers/MasterFunctionsHelper.php | 6 +++--- app/Models/HierarchyFtth.php | 11 +++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/CalculateSCurve.php b/app/Console/Commands/CalculateSCurve.php index 72a2e37..2d005d7 100644 --- a/app/Console/Commands/CalculateSCurve.php +++ b/app/Console/Commands/CalculateSCurve.php @@ -25,7 +25,5 @@ class CalculateSCurve extends Command $project->scurve = json_encode($data); $project->calculation_status = true; $project->save(); - - return $data; } } diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index b93588d..9108ceb 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -473,11 +473,11 @@ class MasterFunctionsHelper { $minDate = $dataProject->mulai_proyek; - $begin = new \DateTime($minDate.' Monday'); + $begin = new \DateTime($minDate); $begin->modify('last Monday'); if(isset($dataPayload['end_date'])){ $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate. ' Friday'); + $end = new \DateTime($maxDate); $end->modify('next Friday'); $end->modify('next Friday'); /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged @@ -488,7 +488,7 @@ class MasterFunctionsHelper { // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's $maxDate = $dataProject->akhir_proyek; - $end = new \DateTime($maxDate. ' Friday'); + $end = new \DateTime($maxDate); $end->modify('next Friday'); $end->modify('next Friday'); $interval = new \DateInterval('P7D'); diff --git a/app/Models/HierarchyFtth.php b/app/Models/HierarchyFtth.php index 34fd7d3..fae503c 100644 --- a/app/Models/HierarchyFtth.php +++ b/app/Models/HierarchyFtth.php @@ -14,4 +14,15 @@ class HierarchyFtth extends Model protected $fillable = [ 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning' ]; + + public static function boot() { + parent::boot(); + + static::deleted(function($data) { + $ftths = HierarchyFtth::where('parent_id', $data->id)->get(); + foreach ($ftths as $ftth) { + $ftth->delete(); + } + }); + } } From 4b667994bbfb7fb2e0507165f13dd3ac6018467c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 7 Jul 2023 09:24:44 +0700 Subject: [PATCH 046/185] Fix date instance --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index c31e50b..f5cf99d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -399,7 +399,7 @@ class ActivityController extends Controller } $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); foreach ($data['activities'] as $i => $activity_row) { - $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); + $startDate = new \DateTime($projectStart->mulai_proyek); $endDate = clone $startDate; $endDate->modify('-1 day'); $daysRemaining = $activity_row['duration']; From 391507dedbf4fecf9c9c7ab62f3181455e243ca1 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 7 Jul 2023 15:13:17 +0700 Subject: [PATCH 047/185] fix dashboard --- app/Http/Controllers/DashboardBoDController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 8e851cb..9c48541 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -10,6 +10,7 @@ use App\Models\User; use App\Models\UserToVersionGantt; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class DashboardBoDController extends Controller { @@ -130,8 +131,10 @@ class DashboardBoDController extends Controller $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $selisihProgress = 0; if($project->scurve && $project->scurve[0]){ - $planningProgress = $project->scurve[0]['data']['percentagePlan'][count($project->scurve[0]['data']['percentagePlan'])-1]; - $actualProgress = $project->scurve[0]['data']['percentageReal'][count($project->scurve[0]['data']['percentageReal'])-1]; + $planningArray = $project->scurve[0]['data']['percentagePlan']; + $actualArray = $project->scurve[0]['data']['percentageReal']; + $planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0; + $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; } $selisihProgress = $planningProgress - $actualProgress; try { From c5fda7e5e3611eca6f6c8b415166ff86b1916f17 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 10 Jul 2023 11:36:00 +0700 Subject: [PATCH 048/185] Fix project count --- app/Http/Controllers/DashboardBoDController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 9c48541..56ba219 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -140,10 +140,10 @@ class DashboardBoDController extends Controller try { if($selisihProgress > 0 && $selisihProgress <= 5) $return['warning'] += 1; - elseif($selisihProgress > 5 && $selisihProgress <= 100) - $return['behind-schedule'] += 1; elseif($selisihProgress == 0) $return['on-schedule'] += 1; + else + $return['behind-schedule'] += 1; } catch (\Error $e) { return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); } From 1fda5ce91f4aaf47251344fb9d4dfa2f28e7f22d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 12 Jul 2023 16:44:17 +0700 Subject: [PATCH 049/185] Fix check location --- app/Http/Controllers/PresenceController.php | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 3dba574..1dcbcd2 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -263,20 +263,22 @@ class PresenceController extends Controller foreach($geom as $dataGeom){ $valGeom = json_decode($dataGeom->geom); if($params->clock_in_out['type']=="out"){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); } - foreach ($check as $key) { - // assign and in boundary - if($key->boundary){ - $temp[]=array( - "activity_id" => $dataGeom->id, - "boundary" => $key->boundary, - "status_assign" => true - ); - } + if(count($check)>0){ + if($check[0]->boundary){ + $temp[]=array( + "activity_id" => $dataGeom->id, + "boundary" => $check[0]->boundary, + "status_assign" => true + ); + } } + } // assign and not in boundary if(count($temp) < 1){ $temp[]=array( @@ -288,7 +290,7 @@ class PresenceController extends Controller ); } } - }else{ + else{ // not assign $temp[]=array( "activity_id" => null, From cabc171a2fe58df4c912302e3b83e8cd0d6c1dbf Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 18 Jul 2023 15:22:57 +0700 Subject: [PATCH 050/185] Fix lag --- app/Http/Controllers/ActivityController.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index f5cf99d..f3c172d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -14,6 +14,7 @@ use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; +use DateTime; class ActivityController extends Controller { @@ -250,18 +251,29 @@ class ActivityController extends Controller $updateBobot = true; if(!$data = Activity::find($id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404); + $link = Link::where('t_activity_id', $data->id)->get(); + if ($link) { + foreach ($link as $linkData) { + $predecessor = Activity::find($linkData->s_activity_id); + $start = new DateTime($data->start_date); + $end = new DateTime($predecessor->end_date); + $lag = $start->diff($end)->format('%a'); + $linkData->lag = $lag; + $linkData->save(); + } + } $dataUpdate = $request->all(); $dataUpdate['name'] = $request->text; $dataUpdate['persentase_progress'] = $request->progress*100; $dataUpdate['updated_by'] = $this->currentName; - unset($dataUpdate['sortorder']); + unset($dataUpdate['sortorder']); if($data->type_activity!='header') $dataUpdate['type_activity'] = $request->type; - if($request->has("target")){ - $this->updateOrder($id, $request->target); - } + if($request->has("target")){ + $this->updateOrder($id, $request->target); + } if(!$data->update($dataUpdate)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); From 7bd8b727aecc2e01f3ef3fc051b1554c4bf2b2e8 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 20 Jul 2023 08:53:04 +0700 Subject: [PATCH 051/185] Fix lag --- app/Http/Controllers/ActivityController.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index f3c172d..126fc02 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -251,17 +251,6 @@ class ActivityController extends Controller $updateBobot = true; if(!$data = Activity::find($id)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404); - $link = Link::where('t_activity_id', $data->id)->get(); - if ($link) { - foreach ($link as $linkData) { - $predecessor = Activity::find($linkData->s_activity_id); - $start = new DateTime($data->start_date); - $end = new DateTime($predecessor->end_date); - $lag = $start->diff($end)->format('%a'); - $linkData->lag = $lag; - $linkData->save(); - } - } $dataUpdate = $request->all(); $dataUpdate['name'] = $request->text; From 8d4f404f3ffe83850d8bad415d2a250ef03ad553 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 20 Jul 2023 10:50:10 +0700 Subject: [PATCH 052/185] Fix date range --- app/Helpers/MasterFunctionsHelper.php | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 9108ceb..9e0551b 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -143,10 +143,10 @@ class MasterFunctionsHelper { $dataFinal=[]; $dataPayload = []; - $dataPayload['period'] = 'week'; - $totalACWP = 0; - $totalBCWP = 0; - $tempPercentage = []; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; $dataProject = Project::find($keyGantt['proyek_id']); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); @@ -168,19 +168,19 @@ class MasterFunctionsHelper { ->join('m_activity as b', 'b.id', '=', 'a.activity_id') ->where('b.version_gantt_id', '=', $keyGantt['id']) ->exists(); - // note : delete this + // note : delete this // if(!$alreadyHasReport) // return $dataFinal; $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); $begin = new \DateTime($minDate.' Monday'); - $begin->modify('last Monday'); + $begin->modify('last Monday'); if(isset($dataPayload['end_date'])){ $maxDate = $dataPayload['end_date']; $end = new \DateTime($maxDate. ' Friday'); - $end->modify('next Friday'); - $end->modify('next Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged $interval = new \DateInterval('P7D'); } else { @@ -190,8 +190,8 @@ class MasterFunctionsHelper { ->where('a.version_gantt_id', '=', $keyGantt['id']) ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's $end = new \DateTime($maxDate. ' Friday'); - $end->modify('next Friday'); - $end->modify('next Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); @@ -210,6 +210,7 @@ class MasterFunctionsHelper { foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); + $tempDate[] = array($dt->format("Y-m-d")); // $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') @@ -254,7 +255,7 @@ class MasterFunctionsHelper { $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table(function ($query) use ($keyGantt) { + $sumVolPlan = DB::table(function ($query) use ($keyGantt) { $query->select('a.*') ->from('m_activity AS a') ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') @@ -301,10 +302,10 @@ class MasterFunctionsHelper { ->where('activity_id', '=', $keyActualM->activity_id) ->groupBy('activity_id') ->first(); - $sumReportActual = DB::table('report_activity_material') - ->where('activity_id', $keyActualM->activity_id) - ->sum('qty'); - $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; $dataTempReport [$w]['qty'] = $keyActualM->qty; $dataTempReport [$w]['report_date'] = $keyActualM->report_date; @@ -392,7 +393,6 @@ class MasterFunctionsHelper { $tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentageReal[] = round($sumPercentageActual, 2); } - $tempDate[] = array($dt->format("Y-m-d")); } try { From 7cf1cca8ecc6167cf1e6370f06e92d9d26cdd9e3 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 20 Jul 2023 14:55:52 +0700 Subject: [PATCH 053/185] Add formatting --- app/Helpers/MasterFunctionsHelper.php | 885 +++++++++++++------------- 1 file changed, 447 insertions(+), 438 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 9e0551b..a537ed8 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -9,17 +9,19 @@ use App\Models\HierarchyFtth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; -class MasterFunctionsHelper { +class MasterFunctionsHelper +{ - public static function curlReq($url, $token = ""){ - if(!$token) + public static function curlReq($url, $token = "") + { + if (!$token) $token = config('api.adw_token'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $headers = [ - 'Authorization: '.$token + 'Authorization: ' . $token ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); @@ -34,114 +36,117 @@ class MasterFunctionsHelper { return json_decode($output); } - public function getLatestGantt($id){ + public function getLatestGantt($id) + { $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); - if(!$maxGanttId){ - $data = array( - "proyek_id" => $id - ); - } else { - $data = array( - "last_gantt_id" => $maxGanttId, - "proyek_id" => $id - ); - } - return $data; + if (!$maxGanttId) { + $data = array( + "proyek_id" => $id + ); + } else { + $data = array( + "last_gantt_id" => $maxGanttId, + "proyek_id" => $id + ); + } + return $data; } // dipake di dashboard project & bod - public function getSCurve($request){ - $allGantt = []; - if(!is_int($request)){ + public function getSCurve($request) + { + $allGantt = []; + if (!is_int($request)) { $dataPayload = $request->all(); - if(isset($dataPayload['gantt_id'])){ + if (isset($dataPayload['gantt_id'])) { $allGantt[] = $dataPayload['gantt_id']; - }else{ + } else { $allGantt[] = MasterFunctionsHelper::getLatestGantt($dataPayload['project_id']); } } else { $allGantt[] = MasterFunctionsHelper::getLatestGantt($request); } - foreach($allGantt as $gantt){ - if (!isset($gantt['last_gantt_id'])) { - $ganttId = $gantt; - } else { - $ganttId = $gantt['last_gantt_id']; - } + foreach ($allGantt as $gantt) { + if (!isset($gantt['last_gantt_id'])) { + $ganttId = $gantt; + } else { + $ganttId = $gantt['last_gantt_id']; + } $gantt = VersionGantt::find($ganttId)->toArray(); - // foreach ($gantt as $key => $value) { - // Log::info('gantt '.$value.' index '.$key); - // } - if (isset($gantt['calculation_type'])) { - if($gantt['calculation_type'] == 'simple') { - // to do - return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); - } else { - return MasterFunctionsHelper::calculateProgressBasedOnReportMaterial($gantt); - } - } + // foreach ($gantt as $key => $value) { + // Log::info('gantt '.$value.' index '.$key); + // } + if (isset($gantt['calculation_type'])) { + if ($gantt['calculation_type'] == 'simple') { + // to do + return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); + } else { + return MasterFunctionsHelper::calculateProgressBasedOnReportMaterial($gantt); + } + } } } - public function getLinearSCurve($request){ - $ftths = HierarchyFtth::where('project_id', $request->project_id)->get(); - $ttlProgress = 0; - $ttlPlanning = 0; + public function getLinearSCurve($request) + { + $ftths = HierarchyFtth::where('project_id', $request->project_id)->get(); + $ttlProgress = 0; + $ttlPlanning = 0; + + foreach ($ftths as $ftth) { + $progress = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('progress'); + $planning = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('bobot'); + $ttlProgress += $progress; + $ttlPlanning += $planning; + } - foreach ($ftths as $ftth) { - $progress = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('progress'); - $planning = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('bobot'); - $ttlProgress += $progress; - $ttlPlanning += $planning; - } + $minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first(); + $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); - $minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first(); - $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); + $begin = new \DateTime($minDate->mulai_proyek . ' Monday'); - $begin = new \DateTime($minDate->mulai_proyek. ' Monday'); - - $end = new \DateTime($maxDate->akhir_proyek. ' Friday'); + $end = new \DateTime($maxDate->akhir_proyek . ' Friday'); - $interval = new \DateInterval('P7D'); + $interval = new \DateInterval('P7D'); $period = new \DatePeriod($begin, $interval, $end); - $dates = iterator_to_array($period); - $count = count($dates); - - $avgProgress = $ttlProgress/$ttlPlanning/$count*100; - $avgPlanning = $ttlPlanning/$ttlPlanning/$count*100; - $progressData = []; - $planningData = []; - $dates = []; - $tempProgress = 0; - $tempPlanning = 0; - array_push($progressData, round($tempProgress, 2)); - array_push($planningData, round($tempPlanning, 2)); - foreach($period as $p){ - $tempProgress += $avgProgress; - $tempPlanning += $avgPlanning; - array_push($progressData, round($tempProgress, 2)); - array_push($planningData, round($tempPlanning, 2)); - array_push($dates, $p->format("Y-m-d")); - } - - $dataResponse = array( - "percentagePlan" => $planningData, - "percentageReal" => $progressData, - "date" => $dates, - ); - - $dataFinal[] = array( - "data"=>$dataResponse, + $dates = iterator_to_array($period); + $count = count($dates); + + $avgProgress = $ttlProgress / $ttlPlanning / $count * 100; + $avgPlanning = $ttlPlanning / $ttlPlanning / $count * 100; + $progressData = []; + $planningData = []; + $dates = []; + $tempProgress = 0; + $tempPlanning = 0; + array_push($progressData, round($tempProgress, 2)); + array_push($planningData, round($tempPlanning, 2)); + foreach ($period as $p) { + $tempProgress += $avgProgress; + $tempPlanning += $avgPlanning; + array_push($progressData, round($tempProgress, 2)); + array_push($planningData, round($tempPlanning, 2)); + array_push($dates, $p->format("Y-m-d")); + } + + $dataResponse = array( + "percentagePlan" => $planningData, + "percentageReal" => $progressData, + "date" => $dates, ); - return $dataFinal; - } + + $dataFinal[] = array( + "data" => $dataResponse, + ); + return $dataFinal; + } public function calculateProgressBasedOnReportMaterial($keyGantt) { DB::enableQueryLog(); - $dataFinal=[]; + $dataFinal = []; $dataPayload = []; $dataPayload['period'] = 'week'; $totalACWP = 0; @@ -150,17 +155,17 @@ class MasterFunctionsHelper { $dataProject = Project::find($keyGantt['proyek_id']); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); - if(isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek){ + if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { $dataPayload['end_date'] = $dataProject->akhir_proyek; } - if($dataHeader){ + if ($dataHeader) { $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); - }else{ + } else { $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); } - if(!Activity::where("version_gantt_id", $keyGantt['id'])->first()) + if (!Activity::where("version_gantt_id", $keyGantt['id'])->first()) return $dataFinal; $alreadyHasReport = DB::table('report_activity_material as a') @@ -174,22 +179,22 @@ class MasterFunctionsHelper { $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); - $begin = new \DateTime($minDate.' Monday'); + $begin = new \DateTime($minDate . ' Monday'); $begin->modify('last Monday'); - if(isset($dataPayload['end_date'])){ + if (isset($dataPayload['end_date'])) { $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate. ' Friday'); + $end = new \DateTime($maxDate . ' Friday'); $end->modify('next Friday'); $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged - $interval = new \DateInterval('P7D'); + /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + $interval = new \DateInterval('P7D'); } else { $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['id']) ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's - $end = new \DateTime($maxDate. ' Friday'); + $end = new \DateTime($maxDate . ' Friday'); $end->modify('next Friday'); $end->modify('next Friday'); $interval = new \DateInterval('P7D'); @@ -201,8 +206,8 @@ class MasterFunctionsHelper { $tempPercentagePlan = []; $tempPercentagePlanWhr = []; $tempPercentageReal = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; $currentACWP = 0; $currentBCWP = 0; @@ -220,73 +225,73 @@ class MasterFunctionsHelper { // ->whereDate('ama.plan_date', '>', $minSevenDays) // ->get(); - $activities = DB::table('m_activity AS a') - ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']) - ->whereDate('amta.plan_date', '<=',$dt->format("Y-m-d")) - ->whereDate('amta.plan_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); - - $dataPlanM = DB::table('m_activity AS a') - ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']) - ->whereDate('a.start_date', '<=',$dt->format("Y-m-d")) - ->whereDate('a.start_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') - ->union($activities) - ->get(); + $activities = DB::table('m_activity AS a') + ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) + ->whereDate('amta.plan_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); + + $dataPlanM = DB::table('m_activity AS a') + ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->whereDate('a.start_date', '<=', $dt->format("Y-m-d")) + ->whereDate('a.start_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') + ->union($activities) + ->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['id']) ->where('a.proyek_id', '=', $keyGantt['proyek_id']) - ->whereDate('ram.report_date', '<=',$dt->format("Y-m-d")) - ->whereDate('ram.report_date', '>',$minSevenDays) + ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) + ->whereDate('ram.report_date', '>', $minSevenDays) ->get(); $dataTempPlan = []; $x = 0; - $sumPercentagePlan=0; + $sumPercentagePlan = 0; $totalACWP = isset($totalACWP) ? $totalACWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table(function ($query) use ($keyGantt) { - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']) - ->unionAll(function ($query) use ($keyGantt){ - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']); - }) - ->orderBy('id', 'asc'); - }, 'subquery') - ->sum('bobot_planning'); - $dataTempPlan [$x]['activity_id'] = $keyPlanM->id; - $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan; - $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan [$x]['duration'] = $keyPlanM->duration; - $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; + $sumVolPlan = DB::table(function ($query) use ($keyGantt) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->unionAll(function ($query) use ($keyGantt) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']); + }) + ->orderBy('id', 'asc'); + }, 'subquery') + ->sum('bobot_planning'); + $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; + $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; + $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan[$x]['duration'] = $keyPlanM->duration; + $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; try { - $dataTempPlan [$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan+= $keyPlanM->bobot_planning; - if(isset($keyPlanM->duration) && $keyPlanM->duration > 0) - $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; - else - $totalBCWP = 0; - $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan += $keyPlanM->bobot_planning; + if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) + $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; + else + $totalBCWP = 0; + $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } @@ -295,7 +300,7 @@ class MasterFunctionsHelper { $w = 0; $dataTempReport = []; - $sumPercentageActual=0; + $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')) @@ -305,37 +310,37 @@ class MasterFunctionsHelper { $sumReportActual = DB::table('report_activity_material') ->where('activity_id', $keyActualM->activity_id) ->sum('qty'); - $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); - $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; + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $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; try { // assign_material_to_activity $checkStatusActivity = DB::table('assign_material_to_activity') - ->select('activity_id', 'status_activity') - ->where('activity_id', '=', $keyActualM->activity_id) - ->orderBy('status_activity', 'ASC') - ->first(); - $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + ->select('activity_id', 'status_activity') + ->where('activity_id', '=', $keyActualM->activity_id) + ->orderBy('status_activity', 'ASC') + ->first(); + $dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ - if($checkStatusActivity->status_activity == 'done'){ - $sumPercentageActual+=$keyActualM->bobot_planning/$reportCount; + if ($checkStatusActivity->status_activity == 'done') { + $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } else { + if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { + $sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100); // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - }else{ - if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1 || (int)$sumVolActual->ttl_qty_plan == (int)$sumReportActual){ - $sumPercentageActual+=(($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning)*(95/100); - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - }else{ - $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } - } + } else { + $sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } + } // }else { // if($checkStatusActivity->status_activity == 'done'){ // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; @@ -343,63 +348,63 @@ class MasterFunctionsHelper { // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // } // } - - - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + + + $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } - $dataTempReport [$w]['totalacwp'] = $totalACWP; + $dataTempReport[$w]['totalacwp'] = $totalACWP; $w++; } $arr_ActualM[] = array( - 'date'=>$dt->format("Y-m-d"), - 'percentPlan'=>$sumPercentagePlan, - 'percentActual'=> $sumPercentageActual, - 'plan'=>$dataTempPlan, - 'actual'=>$dataTempReport, + 'date' => $dt->format("Y-m-d"), + 'percentPlan' => $sumPercentagePlan, + 'percentActual' => $sumPercentageActual, + 'plan' => $dataTempPlan, + 'actual' => $dataTempReport, ); - if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ - $tempTtlPercentPlan+= $sumPercentagePlan; - $tempTtlPercentActual+= $sumPercentageActual; + if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; // if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= $keyGantt['progress'];){ - // if($tempTtlPercentActual >= 100) - // $tempTtlPercentActual = 100; - // if($tempTtlPercentPlan >= 100) - // $tempTtlPercentPlan = 100; - - // if($tempTtlPercentActual >= $keyGantt['progress']) - // $tempTtlPercentActual = $keyGantt['progress']; - if($tempTtlPercentPlan >= 100) - $tempTtlPercentPlan = 100; - // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual - + // if($tempTtlPercentActual >= 100) + // $tempTtlPercentActual = 100; + // if($tempTtlPercentPlan >= 100) + // $tempTtlPercentPlan = 100; + + // if($tempTtlPercentActual >= $keyGantt['progress']) + // $tempTtlPercentActual = $keyGantt['progress']; + if ($tempTtlPercentPlan >= 100) + $tempTtlPercentPlan = 100; + // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual + // } $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; - $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentageReal[] = round($tempTtlPercentActual, 2); - if($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100){ + if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { break; } - }else{ - $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); + } else { + $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); $tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentageReal[] = round($sumPercentageActual, 2); } } try { - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+0); + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); } } catch (\DivisionByZeroError $e) { return response()->json([ @@ -411,58 +416,59 @@ class MasterFunctionsHelper { $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; $costDeviation = $totalRencanaBudget - $estimatedCost; - if($costDeviation > 0){ + if ($costDeviation > 0) { $potential = "SAVING"; } else { $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; } $dataResponse = array( - "date" =>$tempDate, - "percentage" =>$tempPercentage, - "percentagePlan" => $tempPercentagePlan, - "percentageReal" => $tempPercentageReal, - "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, + "date" => $tempDate, + "percentage" => $tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "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, - "gantt"=>$keyGantt + "proyek_name" => $dataProject->nama, + "data" => $dataResponse, + "gantt" => $keyGantt ); return $dataFinal; } - - public function calculateSCurve($projectId) + + public function calculateSCurve($projectId) { DB::enableQueryLog(); - $dataFinal=[]; + $dataFinal = []; $dataPayload = []; - $dataPayload['period'] = 'week'; - $totalACWP = 0; - $totalBCWP = 0; - $tempPercentage = []; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; $dataProject = Project::find($projectId); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first(); - if(isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek){ + if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { $dataPayload['end_date'] = $dataProject->akhir_proyek; } - if($dataHeader){ + if ($dataHeader) { $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya"); - }else{ + } else { $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya"); } @@ -474,23 +480,23 @@ class MasterFunctionsHelper { $minDate = $dataProject->mulai_proyek; $begin = new \DateTime($minDate); - $begin->modify('last Monday'); - if(isset($dataPayload['end_date'])){ + $begin->modify('last Monday'); + if (isset($dataPayload['end_date'])) { $maxDate = $dataPayload['end_date']; $end = new \DateTime($maxDate); - $end->modify('next Friday'); - $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged - $interval = new \DateInterval('P7D'); + $end->modify('next Friday'); + $end->modify('next Friday'); + /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + $interval = new \DateInterval('P7D'); } else { // $maxDate = DB::table('assign_material_to_activity as ama') // ->where("ama.proyek_id", $projectId) // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's - $maxDate = $dataProject->akhir_proyek; + $maxDate = $dataProject->akhir_proyek; $end = new \DateTime($maxDate); - $end->modify('next Friday'); - $end->modify('next Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); @@ -500,8 +506,8 @@ class MasterFunctionsHelper { $tempPercentagePlan = []; $tempPercentagePlanWhr = []; $tempPercentageReal = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; $currentACWP = 0; $currentBCWP = 0; @@ -518,67 +524,67 @@ class MasterFunctionsHelper { // ->whereDate('ama.plan_date', '>', $minSevenDays) // ->get(); - $activities = DB::table('m_activity AS a') - ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->whereDate('amta.plan_date', '<=',$dt->format("Y-m-d")) - ->whereDate('amta.plan_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); - - $dataPlanM = DB::table('m_activity AS a') - ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->whereDate('a.start_date', '<=',$dt->format("Y-m-d")) - ->whereDate('a.start_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') - ->union($activities) - ->get(); + $activities = DB::table('m_activity AS a') + ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) + ->whereDate('amta.plan_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); + + $dataPlanM = DB::table('m_activity AS a') + ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->whereDate('a.start_date', '<=', $dt->format("Y-m-d")) + ->whereDate('a.start_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') + ->union($activities) + ->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.proyek_id', '=', $projectId) - ->whereDate('ram.report_date', '<=',$dt->format("Y-m-d")) - ->whereDate('ram.report_date', '>',$minSevenDays) + ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) + ->whereDate('ram.report_date', '>', $minSevenDays) ->get(); $dataTempPlan = []; $x = 0; - $sumPercentagePlan=0; + $sumPercentagePlan = 0; $totalACWP = isset($totalACWP) ? $totalACWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table(function ($query){ - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->unionAll(function ($query){ - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0); - })->orderBy('id', 'asc'); - }, 'subquery') - ->sum('bobot_planning'); - $dataTempPlan [$x]['activity_id'] = $keyPlanM->id; - $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan; - $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan [$x]['duration'] = $keyPlanM->duration; - $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; + $sumVolPlan = DB::table(function ($query) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->unionAll(function ($query) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0); + })->orderBy('id', 'asc'); + }, 'subquery') + ->sum('bobot_planning'); + $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; + $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; + $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan[$x]['duration'] = $keyPlanM->duration; + $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; try { - $dataTempPlan [$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan+= $keyPlanM->bobot_planning; - if(isset($keyPlanM->duration) && $keyPlanM->duration > 0) - $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; - else - $totalBCWP = 0; - $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan += $keyPlanM->bobot_planning; + if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) + $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; + else + $totalBCWP = 0; + $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } @@ -587,47 +593,47 @@ class MasterFunctionsHelper { $w = 0; $dataTempReport = []; - $sumPercentageActual=0; + $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(); - $sumReportActual = DB::table('report_activity_material') - ->where('activity_id', $keyActualM->activity_id) - ->sum('qty'); - $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); - $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; + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $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; try { // assign_material_to_activity $checkStatusActivity = DB::table('assign_material_to_activity') - ->select('activity_id', 'status_activity') - ->where('activity_id', '=', $keyActualM->activity_id) - ->orderBy('status_activity', 'ASC') - ->first(); - $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + ->select('activity_id', 'status_activity') + ->where('activity_id', '=', $keyActualM->activity_id) + ->orderBy('status_activity', 'ASC') + ->first(); + $dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ - if($checkStatusActivity->status_activity == 'done'){ - $sumPercentageActual+=$keyActualM->bobot_planning/$reportCount; + if ($checkStatusActivity->status_activity == 'done') { + $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } else { + if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { + $sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100); // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - }else{ - if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1 || (int)$sumVolActual->ttl_qty_plan == (int)$sumReportActual){ - $sumPercentageActual+=(($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning)*(95/100); - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - }else{ - $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } - } + } else { + $sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } + } // }else { // if($checkStatusActivity->status_activity == 'done'){ // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; @@ -635,36 +641,36 @@ class MasterFunctionsHelper { // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // } // } - - - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + + + $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } - $dataTempReport [$w]['totalacwp'] = $totalACWP; + $dataTempReport[$w]['totalacwp'] = $totalACWP; $w++; } $arr_ActualM[] = array( - 'date'=>$dt->format("Y-m-d"), - 'percentPlan'=>$sumPercentagePlan, - 'percentActual'=> $sumPercentageActual, - 'plan'=>$dataTempPlan, - 'actual'=>$dataTempReport, + 'date' => $dt->format("Y-m-d"), + 'percentPlan' => $sumPercentagePlan, + 'percentActual' => $sumPercentageActual, + 'plan' => $dataTempPlan, + 'actual' => $dataTempReport, ); - if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ - $tempTtlPercentPlan+= $sumPercentagePlan; - $tempTtlPercentActual+= $sumPercentageActual; + if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; - $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentageReal[] = round($tempTtlPercentActual, 2); - }else{ - $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); + } else { + $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); $tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentageReal[] = round($sumPercentageActual, 2); } @@ -672,10 +678,10 @@ class MasterFunctionsHelper { } try { - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+0); + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); } } catch (\DivisionByZeroError $e) { return response()->json([ @@ -686,57 +692,59 @@ class MasterFunctionsHelper { $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; $costDeviation = $totalRencanaBudget - $estimatedCost; - if($costDeviation > 0){ + if ($costDeviation > 0) { $potential = "SAVING"; } else { $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; } $dataResponse = array( - "date" =>$tempDate, - "percentage" =>$tempPercentage, - "percentagePlan" => $tempPercentagePlan, - "percentageReal" => $tempPercentageReal, - "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, + "date" => $tempDate, + "percentage" => $tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "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, + "proyek_name" => $dataProject->nama, + "data" => $dataResponse, ); return $dataFinal; - } + } - public function calculateProgressBasedOnSimple($keyGantt){ + public function calculateProgressBasedOnSimple($keyGantt) + { DB::enableQueryLog(); - $dataFinal=[]; + $dataFinal = []; $dataPayload = []; $dataPayload['period'] = 'week'; $dataProject = Project::find($keyGantt['proyek_id']); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); - if(isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek){ + if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { $dataPayload['end_date'] = $dataProject->akhir_proyek; } - if($dataHeader){ + if ($dataHeader) { $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); - }else{ + } else { $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); } - if(!Activity::where("version_gantt_id", $keyGantt['id'])->first()) + if (!Activity::where("version_gantt_id", $keyGantt['id'])->first()) return $dataFinal; // $alreadyHasReport = DB::table('report_activity_material as a') @@ -750,12 +758,12 @@ class MasterFunctionsHelper { $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); - $begin = new \DateTime($minDate.' Monday'); - if(isset($dataPayload['end_date'])){ + $begin = new \DateTime($minDate . ' Monday'); + if (isset($dataPayload['end_date'])) { $maxDate = $dataPayload['end_date']; $end = new \DateTime($maxDate); - /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged - $interval = new \DateInterval('P7D'); + /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + $interval = new \DateInterval('P7D'); } else { // $maxDate = DB::table('assign_material_to_activity as ama') // ->where("ama.proyek_id", $keyGantt['proyek_id']) @@ -763,7 +771,7 @@ class MasterFunctionsHelper { // ->where('a.version_gantt_id', '=', $keyGantt['id']) // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's $maxDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('end_date')->first(); - $end = new \DateTime($maxDate. ' Friday'); + $end = new \DateTime($maxDate . ' Friday'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); @@ -773,8 +781,8 @@ class MasterFunctionsHelper { $tempPercentagePlan = []; $tempPercentagePlanWhr = []; $tempPercentageReal = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; $currentACWP = 0; $currentBCWP = 0; @@ -782,17 +790,17 @@ class MasterFunctionsHelper { foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); - + $dataPlanM = DB::table('m_activity') ->select('id as activity_id', 'bobot_planning', 'start_date', 'biaya_actual', 'duration', 'persentase_progress') // ->join('m_activity as a', 'a.id', '=', 'activity_id') ->where('proyek_id', '=', $keyGantt['proyek_id']) ->where('type_activity', '=', 'task') ->where('version_gantt_id', '=', $keyGantt['id']) - ->whereDate('start_date', '<=',$dt->format("Y-m-d")) + ->whereDate('start_date', '<=', $dt->format("Y-m-d")) ->whereDate('start_date', '>', $minSevenDays) ->get(); - + $dataActualM = DB::table('m_activity as a') ->select('mapl.id as id_progress_log', 'mapl.activity_id', 'mapl.variance', 'mapl.created_at', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') ->join('m_activity_progress_log as mapl', 'a.id', '=', 'mapl.activity_id') @@ -800,31 +808,31 @@ class MasterFunctionsHelper { ->where('a.type_activity', '=', 'task') ->where('mapl.variance', '>', 0) ->where('a.proyek_id', '=', $keyGantt['proyek_id']) - ->whereDate('mapl.created_at', '<=',$dt->format("Y-m-d")) - ->whereDate('mapl.created_at', '>',$minSevenDays) + ->whereDate('mapl.created_at', '<=', $dt->format("Y-m-d")) + ->whereDate('mapl.created_at', '>', $minSevenDays) ->get(); $dataTempPlan = []; $x = 0; - $sumPercentagePlan=0; + $sumPercentagePlan = 0; $totalACWP = isset($totalACWP) ? $totalACWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; foreach ($dataPlanM as $keyPlanM) { - - $dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; - $dataTempPlan [$x]['qty_plan'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['plan_date'] = $keyPlanM->start_date; - $dataTempPlan [$x]['start_activity'] = $keyPlanM->start_date; - $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['ttl_plan'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan [$x]['duration'] = $keyPlanM->duration; - $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; + + $dataTempPlan[$x]['activity_id'] = $keyPlanM->activity_id; + $dataTempPlan[$x]['qty_plan'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['plan_date'] = $keyPlanM->start_date; + $dataTempPlan[$x]['start_activity'] = $keyPlanM->start_date; + $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['ttl_plan'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan[$x]['duration'] = $keyPlanM->duration; + $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; try { - $dataTempPlan [$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan+=$keyPlanM->bobot_planning; + $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan += $keyPlanM->bobot_planning; $totalBCWP += 0; - $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } @@ -833,62 +841,62 @@ class MasterFunctionsHelper { $w = 0; $dataTempReport = []; - $sumPercentageActual=0; + $sumPercentageActual = 0; foreach ($dataActualM as $keyActualM) { $sumVolActual = DB::table('m_activity_progress_log') ->select('id', DB::raw('SUM(variance) as ttl_percen_act')) ->where('id', '=', $keyActualM->id_progress_log) ->groupBy('id') ->first(); - $dataTempReport [$w]['id_progress_log'] = $keyActualM->id_progress_log; + $dataTempReport[$w]['id_progress_log'] = $keyActualM->id_progress_log; // $dataTempReport [$w]['qty'] = $keyActualM->qty; - $dataTempReport [$w]['report_date'] = $keyActualM->created_at; - $dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; + $dataTempReport[$w]['report_date'] = $keyActualM->created_at; + $dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning; // $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_percen_act ? $sumVolActual->ttl_percen_act : 0; - $dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; - $dataTempReport [$w]['duration'] = $keyActualM->duration; - $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; + $dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual; + $dataTempReport[$w]['duration'] = $keyActualM->duration; + $dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress; try { - $dataTempReport [$w]['percentage'] = $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act/100)*$keyActualM->bobot_planning : 0; - $sumPercentageActual+=$sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act/100)*$keyActualM->bobot_planning : 0; - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + $dataTempReport[$w]['percentage'] = $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0; + $sumPercentageActual += $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0; + $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } - $dataTempReport [$w]['totalacwp'] = $totalACWP; + $dataTempReport[$w]['totalacwp'] = $totalACWP; $w++; } $arr_ActualM[] = array( - 'date'=>$dt->format("Y-m-d"), - 'percentPlan'=>$sumPercentagePlan, - 'percentActual'=>$sumPercentageActual, - 'plan'=>$dataTempPlan, - 'actual'=>$dataTempReport, + 'date' => $dt->format("Y-m-d"), + 'percentPlan' => $sumPercentagePlan, + 'percentActual' => $sumPercentageActual, + 'plan' => $dataTempPlan, + 'actual' => $dataTempReport, ); - if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ - $tempTtlPercentPlan+= $sumPercentagePlan; - $tempTtlPercentActual+= $sumPercentageActual; + if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; - if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100){ - if($tempTtlPercentActual >= 100) + if ($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100) { + if ($tempTtlPercentActual >= 100) $tempTtlPercentActual = 100; - if($tempTtlPercentPlan >= 100) + if ($tempTtlPercentPlan >= 100) $tempTtlPercentPlan = 100; } $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; - $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentageReal[] = round($tempTtlPercentActual, 2); - if($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100){ + if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { break; } - }else{ - $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); + } else { + $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); $tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentageReal[] = round($sumPercentageActual, 2); } @@ -896,10 +904,10 @@ class MasterFunctionsHelper { } try { - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+0); + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); } } catch (\DivisionByZeroError $e) { return response()->json([ @@ -911,36 +919,37 @@ class MasterFunctionsHelper { $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; $costDeviation = $totalRencanaBudget - $estimatedCost; - if($costDeviation > 0){ + if ($costDeviation > 0) { $potential = "SAVING"; } else { $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; } $dataResponse = array( - "date" =>$tempDate, - "percentage" =>$tempPercentage, - "percentagePlan" => $tempPercentagePlan, - "percentageReal" => $tempPercentageReal, - "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, + "date" => $tempDate, + "percentage" => $tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "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, - "gantt"=>$keyGantt, + "proyek_name" => $dataProject->nama, + "data" => $dataResponse, + "gantt" => $keyGantt, ); return $dataFinal; } -} +} \ No newline at end of file From 96222016f0a33802f0c2834043d9c0e0105292fb Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 26 Jul 2023 16:53:19 +0700 Subject: [PATCH 054/185] Format ActivityController --- app/Http/Controllers/ActivityController.php | 740 ++++++++++---------- app/Http/Controllers/ProjectController.php | 7 +- 2 files changed, 380 insertions(+), 367 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 126fc02..15e6cb4 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -20,58 +20,59 @@ class ActivityController extends Controller { public function getByGanttId($id, $proyek_id) { - $gantt = VersionGantt::find($id); - if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) { - if(!$gantt->hierarchy_ftth_id) { - $this->cloneTemplate($id, $proyek_id); - } else { - $this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_id); - } + $gantt = VersionGantt::find($id); + if (Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) { + if (!$gantt->hierarchy_ftth_id) { + $this->cloneTemplate($id, $proyek_id); + } else { + $this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_id); + } } $dataGantt = $this->getDataActivity($id); - return response()->json(['status'=>'success','data'=> $dataGantt,'code'=>200], 200); + 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->progress = $dataHeader->persentase_progress / 100; - $dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start),"Y-m-d H:i:s") : NULL; - $dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end),"Y-m-d H:i:s") : NULL; - $dataHeader->type = "header"; - $dataHeader->text = $dataHeader->name; - $finalData[] = $dataHeader; - $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get(); - }else{ - $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', '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->progress = $dataHeader->persentase_progress / 100; + $dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start), "Y-m-d H:i:s") : NULL; + $dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL; + $dataHeader->type = "header"; + $dataHeader->text = $dataHeader->name; + $finalData[] = $dataHeader; + $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get(); + } else { + $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get(); } - foreach($data as $objRow){ + foreach ($data as $objRow) { $type = "project"; $dataChildren = $this->getChildren($id, $objRow->id); $startDate = date_create($objRow->start_date); $endDate = date_create($objRow->end_date); - if($objRow->type_activity=="milestone") + if ($objRow->type_activity == "milestone") $type = $objRow->type_activity; - if(empty($dataChildren)) + if (empty($dataChildren)) $type = "task"; $objRow->text = $objRow->name; $objRow->parent = $objRow->parent_id ? $objRow->parent_id : null; - $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 = $objRow->persentase_progress / 100; + $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 = $objRow->persentase_progress / 100; $objRow->type = $type; $finalData[] = $objRow; $finalData = array_merge($finalData, $dataChildren); @@ -79,23 +80,22 @@ class ActivityController extends Controller $dataLink = Link::where('version_gantt_id', $id)->get(); $finalLink = []; - foreach($dataLink as $objRow) - { + 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 + 'id' => $objRow->id, + 'source' => $objRow->s_activity_id, + 'target' => $objRow->t_activity_id, + 'type' => $objRow->type_link, + 'code' => $objRow->code_link ); - if($objRow->lag) + if ($objRow->lag) $dataRow['lag'] = $objRow->lag; $finalLink[] = $dataRow; } $resultData = array( - "data"=>$finalData, - "links"=>$finalLink + "data" => $finalData, + "links" => $finalLink ); return $resultData; @@ -105,22 +105,22 @@ class ActivityController extends Controller { $finalData = []; $data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get(); - foreach($data as $objRow){ + foreach ($data as $objRow) { $objRow->parent = $parent_id; $objRow->text = $objRow->name; - $objRow->progress = (float)$objRow->persentase_progress/100; + $objRow->progress = (float) $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; + $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"){ + if ($objRow->type_activity == "milestone") { $objRow->type = $objRow->type_activity; - }elseif(empty($dataChildren)){ + } elseif (empty($dataChildren)) { $objRow->type = "task"; - }else{ + } else { $objRow->type = "project"; } $finalData[] = $objRow; @@ -129,54 +129,55 @@ class ActivityController extends Controller return $finalData; } - private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) { - $project = Project::find($proyek_id); - if($hierarchy_ftth_id){ - $gantt = VersionGantt::find($id); - $rootActivity = Activity::create([ - 'version_gantt_id'=>$id, - 'proyek_id'=>$proyek_id, - 'name'=> $gantt->name_version, - 'start_date'=> $project->mulai_proyek, - 'end_date'=> $project->akhir_proyek, - 'rencana_biaya'=> $project->rencana_biaya, - 'type_activity'=> 'project', - 'created_by'=>$this->currentName, - 'sortorder'=>1 - ]); - } else { - $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'=> $project->rencana_biaya, - 'type_activity'=> 'project', - 'created_by'=>$this->currentName, - 'sortorder'=>1 - ]); - } + private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) + { + $project = Project::find($proyek_id); + if ($hierarchy_ftth_id) { + $gantt = VersionGantt::find($id); + $rootActivity = Activity::create([ + 'version_gantt_id' => $id, + 'proyek_id' => $proyek_id, + 'name' => $gantt->name_version, + 'start_date' => $project->mulai_proyek, + 'end_date' => $project->akhir_proyek, + 'rencana_biaya' => $project->rencana_biaya, + 'type_activity' => 'project', + 'created_by' => $this->currentName, + 'sortorder' => 1 + ]); + } else { + $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' => $project->rencana_biaya, + 'type_activity' => 'project', + 'created_by' => $this->currentName, + 'sortorder' => 1 + ]); + } $resultTypeProject = TemplateGantt::where('proyek_type_id', $project->type_proyek_id) ->whereNull('parent_id') ->orderByRaw('id ASC') ->get(); - foreach($resultTypeProject as $objRow){ + foreach ($resultTypeProject as $objRow) { $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); - $max = Activity::where('version_gantt_id', $id)->max('sortorder'); + $max = Activity::where('version_gantt_id', $id)->max('sortorder'); $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, - 'sortorder'=>$max+1 + '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, + 'sortorder' => $max + 1 ]); $this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek); } @@ -185,19 +186,19 @@ class ActivityController extends Controller private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay) { $data = TemplateGantt::where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); - foreach($data as $objRow){ + foreach ($data as $objRow) { $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); - $max = Activity::where('version_gantt_id', $id)->max('sortorder'); + $max = Activity::where('version_gantt_id', $id)->max('sortorder'); $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, - 'sortorder'=>$max+1 + '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, + 'sortorder' => $max + 1 ]); $this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay); } @@ -206,127 +207,130 @@ class ActivityController extends Controller public function add(Request $request) { $this->validate($request, [ - 'version_gantt_id'=>'required' + 'version_gantt_id' => 'required' ]); $data = $request->all(); $data['name'] = $request->text; $data['persentase_progress'] = $request->progress; $data['created_by'] = $this->currentName; - $max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder'); - $data['sortorder'] = $max + 1; + $max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder'); + $data['sortorder'] = $max + 1; $data['type_activity'] = "task"; $parent = $data['parent_id'] ?? null; - if($parent){ + if ($parent) { $parentData = Activity::find($parent); - if($parentData->parent_id) { + if ($parentData->parent_id) { $parentData->update(["type_activity" => "project"]); } 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); + 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); + return response()->json(['status' => 'success', 'action' => 'inserted', 'tid' => $result->id, 'code' => 200], 200); } - public function edit($id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + 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); + 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); + 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); + if (empty($id) || !is_int((int) $id)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'id is required!', 'code' => 400], 400); $updateBobot = true; - if(!$data = Activity::find($id)) - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404); + if (!$data = Activity::find($id)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); $dataUpdate = $request->all(); $dataUpdate['name'] = $request->text; - $dataUpdate['persentase_progress'] = $request->progress*100; + $dataUpdate['persentase_progress'] = $request->progress * 100; $dataUpdate['updated_by'] = $this->currentName; - unset($dataUpdate['sortorder']); - if($data->type_activity!='header') + unset($dataUpdate['sortorder']); + if ($data->type_activity != 'header') $dataUpdate['type_activity'] = $request->type; - - if($request->has("target")){ - $this->updateOrder($id, $request->target); + + if ($request->has("target")) { + $this->updateOrder($id, $request->target); } - if(!$data->update($dataUpdate)) - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); + if (!$data->update($dataUpdate)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed updated!', 'code' => 400], 400); - return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200); + return response()->json(['status' => 'success', 'update_bobot' => $updateBobot, 'data' => $dataUpdate, 'action' => 'updated', 'message' => 'Activity updated!', 'code' => 200], 200); } - private function updateOrder($taskId, $target){ - $nextTask = false; - $targetId = $target; - - if(strpos($target, "next:") === 0){ - $targetId = substr($target, strlen("next:")); - $nextTask = true; - } - - if($targetId == "null") - return; - - $targetOrder = Activity::find($targetId)->sortorder; - if($nextTask) - $targetOrder++; - - Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder"); - - $updatedTask = Activity::find($taskId); - $updatedTask->sortorder = $targetOrder; - $updatedTask->save(); - } - - public function updateRegular(Request $request, $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + private function updateOrder($taskId, $target) + { + $nextTask = false; + $targetId = $target; + + if (strpos($target, "next:") === 0) { + $targetId = substr($target, strlen("next:")); + $nextTask = true; + } + + if ($targetId == "null") + return; + + $targetOrder = Activity::find($targetId)->sortorder; + if ($nextTask) + $targetOrder++; + + Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder"); + + $updatedTask = Activity::find($taskId); + $updatedTask->sortorder = $targetOrder; + $updatedTask->save(); + } + + public function updateRegular(Request $request, $id) + { + if (empty($id) || !is_int((int) $id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $data = Activity::find($id); - if(!$data = Activity::find($id)) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + 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); + 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); + return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); } public function delete($id) { - if(!$data = Activity::find($id)) - return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=> 404], 404); + if (!$data = Activity::find($id)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); - if(!$data->delete()) - return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed deleted!','code'=> 500], 500); + 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); + return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); } public function getUpdate($id) { - if(!$data = Activity::find($id)) - return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=>400], 400); + if (!$data = Activity::find($id)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 400], 400); $data->progress = (float) $data->persentase_progress / 100; $data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya); - return response()->json(['status'=>'success', "data"=> $data,'code'=>200], 200); + return response()->json(['status' => 'success', "data" => $data, 'code' => 200], 200); } public function search(Request $request) @@ -336,88 +340,89 @@ class ActivityController extends Controller $countBuilder = $dataBuilder['count']; $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } - // before upload file - public function importOld(Request $request) + // before upload file + public function importOld(Request $request) { - $data = $request->all(); + $data = $request->all(); $data['created_by'] = $this->currentName; Activity::where('version_gantt_id', $data['ganttId'])->delete(); $projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id; - $dayOffs = VersionGantt::find($data['ganttId'])->first()->config_dayoff; + $dayOffs = VersionGantt::find($data['ganttId'])->first()->config_dayoff; $activityStack = []; - $hasWeight = false; - - foreach ($data['activities'] as $key => $value) { - if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){ - $hasWeight = true; - break; - } - } - - if(!$hasWeight){ - foreach ($data['activities'] as $key => $value) { - if($key == 0){ - $data['activities'][$key]['weight'] = 100; - } else { - $parentWeight = 0; - $siblingsCount = 1; - - $i = $key; - while($i > 0){ - if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){ - $parentWeight = $data['activities'][$i - 1]['weight']; - break; - } - if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ - $siblingsCount++; - } - $i--; - } - - $i = $key+1; - while($i < count($data['activities'])){ - if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){ - break; - } - // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); - if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ - $siblingsCount++; - } - $i++; - } - - $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; - } - }; - } - $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); + $hasWeight = false; + + foreach ($data['activities'] as $key => $value) { + if (isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0) { + $hasWeight = true; + break; + } + } + + if (!$hasWeight) { + foreach ($data['activities'] as $key => $value) { + if ($key == 0) { + $data['activities'][$key]['weight'] = 100; + } else { + $parentWeight = 0; + $siblingsCount = 1; + + $i = $key; + while ($i > 0) { + if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level'] - 1) { + $parentWeight = $data['activities'][$i - 1]['weight']; + break; + } + if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) { + $siblingsCount++; + } + $i--; + } + + $i = $key + 1; + while ($i < count($data['activities'])) { + if ($data['activities'][$i]['level'] == $data['activities'][$key]['level'] - 1) { + break; + } + // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); + if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) { + $siblingsCount++; + } + $i++; + } + + $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; + } + } + ; + } + $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); foreach ($data['activities'] as $i => $activity_row) { $startDate = new \DateTime($projectStart->mulai_proyek); - $endDate = clone $startDate; - $endDate->modify('-1 day'); - $daysRemaining = $activity_row['duration']; - - // Loop until the remaining days become zero - while ($daysRemaining > 0) { - $endDate->modify('+1 day'); - - // Check if the current day is a day off (Sunday or Saturday) - $currentDayOfWeek = (int)$endDate->format('w'); - if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) { - continue; // Skip the day off and continue to the next day - } - - $daysRemaining--; // Decrease the remaining days by one - } - $endDate->setTime(23, 59, 59); + $endDate = clone $startDate; + $endDate->modify('-1 day'); + $daysRemaining = $activity_row['duration']; + + // Loop until the remaining days become zero + while ($daysRemaining > 0) { + $endDate->modify('+1 day'); + + // Check if the current day is a day off (Sunday or Saturday) + $currentDayOfWeek = (int) $endDate->format('w'); + if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) { + continue; // Skip the day off and continue to the next day + } + + $daysRemaining--; // Decrease the remaining days by one + } + $endDate->setTime(23, 59, 59); $input['name'] = $activity_row['name']; $input['proyek_id'] = $projectId; $input['version_gantt_id'] = $data['ganttId']; @@ -428,8 +433,8 @@ class ActivityController extends Controller $input['bobot_planning'] = $activity_row['weight']; $input['persentase_progress'] = 0; $input['type_activity'] = $i == 0 ? "header" : "task"; - $input['created_by'] = $this->currentName; - $input['sortorder'] = $activity_row['no']; + $input['created_by'] = $this->currentName; + $input['sortorder'] = $activity_row['no']; if (!$activity = Activity::create($input)) { Activity::where('version_gantt_id', $data['ganttId'])->delete(); @@ -439,7 +444,7 @@ class ActivityController extends Controller $data['activities'][$i]['activity_id'] = $activity->id; if ($i == 0) { - $activity->type_activity = "project"; + $activity->type_activity = "project"; $activity->save(); $activity->level = $activity_row['level']; array_push($activityStack, $activity); @@ -468,7 +473,7 @@ class ActivityController extends Controller } $activity->parent_id = $activityStack[count($activityStack) - 1]->id ?? null; - array_push($activityStack, $activity); + array_push($activityStack, $activity); // there should be better way to except / filter attribute level before save because it's cause error // cant use except() / filter() on $activity collection somehow unset($activity->level); @@ -484,23 +489,23 @@ class ActivityController extends Controller $activity->type_activity = "project"; $activity->save(); $activity->level = $activity_row['level']; - } - if (isset($data['activities'][$i]['nik']) && $data['activities'][$i]['nik'] != '') { - $user = User::where("ktp_number", $data['activities'][$i]['nik'])->first(); - $userProyek = UserToProyek::where("user_id", $user->id) - ->where("proyek_id", $projectId) - ->first(); - - $dataInsert = array( - "user_id" => $user->id, - "activity_id" => $activity->id, - "role_proyek_id" => $userProyek->project_role, - "proyek_id" => $projectId, - "created_by" => $this->currentName, - "version_gantt_id" => $data['ganttId'] - ); - UserToActivity::create($dataInsert); - } + } + if (isset($data['activities'][$i]['nik']) && $data['activities'][$i]['nik'] != '') { + $user = User::where("ktp_number", $data['activities'][$i]['nik'])->first(); + $userProyek = UserToProyek::where("user_id", $user->id) + ->where("proyek_id", $projectId) + ->first(); + + $dataInsert = array( + "user_id" => $user->id, + "activity_id" => $activity->id, + "role_proyek_id" => $userProyek->project_role, + "proyek_id" => $projectId, + "created_by" => $this->currentName, + "version_gantt_id" => $data['ganttId'] + ); + UserToActivity::create($dataInsert); + } if (!empty($activity_row['predecessor'])) { $key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no')); @@ -525,35 +530,36 @@ class ActivityController extends Controller } return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200); - } + } - private function getLatestGantt($id){ + private function getLatestGantt($id) + { $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); - $data = array( - "last_gantt_id" => $maxGanttId, - "proyek_id" => $id - ); - return $data; + $data = array( + "last_gantt_id" => $maxGanttId, + "proyek_id" => $id + ); + return $data; } public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) { $dataPayload = $request->all(); - $allGantt = []; - if(isset($dataPayload['gannt_id'])){ - $allGantt = $dataPayload['gannt_id']; - }else{ + $allGantt = []; + if (isset($dataPayload['gannt_id'])) { + $allGantt = $dataPayload['gannt_id']; + } else { foreach ($dataPayload['project_id'] as $val) { $allGantt[] = $this->getLatestGantt($val); } } - $dataFinal=[]; + $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){ + 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{ + } 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') @@ -574,8 +580,8 @@ class ActivityController extends Controller $arr_ActualM = []; $tempDate = []; $tempPercentage = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; $currentACWP = 0; $budgetControlACWP = 0; $currentProgressActivity = 0; @@ -598,7 +604,7 @@ class ActivityController extends Controller ->get(); $dataTempPlan = []; $x = 0; - $sumPercentagePlan=0; + $sumPercentagePlan = 0; $totalACWP = isset($totalACWP) ? $totalACWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; foreach ($dataPlanM as $keyPlanM) { @@ -607,117 +613,118 @@ class ActivityController extends Controller ->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; + $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; + $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; + $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, + '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 ){ + if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { + if ($dt->format("w") == 1) { + if ($totalACWP > 0) { $budgetControlACWP = $currentACWP + $totalACWP; } - if($totalBCWP > 0 ){ + if ($totalBCWP > 0) { $budgetControlBCWP = $currentBCWP + $totalBCWP; } - $tempTtlPercentPlan+= $sumPercentagePlan; - $tempTtlPercentActual+= $sumPercentageActual; + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; - $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $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; + } 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)); + $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)); + } 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); + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); } $costDeviation = $totalRencanaBudget - $estimatedCost; - if($costDeviation > 0){ + 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, + "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 + "proyek_name" => $dataProject->nama, + "data" => $dataResponse, + "allGant" => $allGantt ); } - return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataFinal], 200); } - + public function import(Request $request) { - $data = $request->all(); + $data = $request->all(); $data['created_by'] = $this->currentName; Activity::where('version_gantt_id', $data['gantt_id'])->delete(); $projectId = VersionGantt::where('id', $data['gantt_id'])->first()->proyek_id; @@ -725,46 +732,47 @@ class ActivityController extends Controller $excel = TmpImport::latest('id')->first(); return response()->json(['stack' => $excel, 'status' => 'success', 'message' => 'Data imported!', 'data' => $data, 'code' => 200], 200); - } + } public function uploadTmpImport(Request $request) { - if($request->hasFile('dokumen')){ - $document = $request->file('dokumen'); - $gantt_id = $request->gantt_id; - $name = $document->getClientOriginalName(); + if ($request->hasFile('dokumen')) { + $document = $request->file('dokumen'); + $gantt_id = $request->gantt_id; + $name = $document->getClientOriginalName(); $result = $document->move($this->pathTmpImport, $name); - if($result){ + if ($result) { $data = [ - 'gantt_id' => (int)$gantt_id, + 'gantt_id' => (int) $gantt_id, 'file' => $name, 'type_dokumen' => $request->type_dokumen ]; $result = TmpImport::create($data); - if(!$result){ - unlink($this->pathTmpImport.$name); - return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + if (!$result) { + unlink($this->pathTmpImport . $name); + return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); } - return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200); + return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200); } - return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); } - return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400); + return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400); } - public function importUpdate(Request $request) { - $data = $request->all(); - foreach ($data as $value) { - $activity = Activity::find($value['id']); - $activity->duration = $value['duration']; - $activity->start_date = $value['start_date']; - $activity->end_date = $value['end_date']; - $activity->save(); - } - return response()->json(['status'=>'success','data'=>$request,'message'=>'Update successful!','code'=>200], 200); - } -} + public function importUpdate(Request $request) + { + $data = $request->all(); + foreach ($data as $value) { + $activity = Activity::find($value['id']); + $activity->duration = $value['duration']; + $activity->start_date = $value['start_date']; + $activity->end_date = $value['end_date']; + $activity->save(); + } + return response()->json(['status' => 'success', 'data' => $request, 'message' => 'Update successful!', 'code' => 200], 200); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 6e8ca66..d1d58b2 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -393,9 +393,14 @@ class ProjectController extends Controller public function setBaseline($gantt_id) { - $activities = Activity::where("version_gantt_id", $gantt_id)->get(); + $activities = Activity::where("version_gantt_id", $gantt_id)->orderBy('id')->get(); foreach ($activities as $activity) { + $successor = Link::where('t_activity_id', $activity->id)->first(); + if ($successor) { + $predecessor = Activity::find($successor->s_activity_id); + $activity->start_date = $predecessor->end_date; + } $activity->update([ "planned_start"=>$activity->start_date, "planned_end"=>$activity->end_date, From 4293e375b7c1e2f1a1d4e547e058d7f822821af4 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 27 Jul 2023 10:36:26 +0700 Subject: [PATCH 055/185] Fix set baseline --- app/Http/Controllers/ProjectController.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index d1d58b2..6e8ca66 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -393,14 +393,9 @@ class ProjectController extends Controller public function setBaseline($gantt_id) { - $activities = Activity::where("version_gantt_id", $gantt_id)->orderBy('id')->get(); + $activities = Activity::where("version_gantt_id", $gantt_id)->get(); foreach ($activities as $activity) { - $successor = Link::where('t_activity_id', $activity->id)->first(); - if ($successor) { - $predecessor = Activity::find($successor->s_activity_id); - $activity->start_date = $predecessor->end_date; - } $activity->update([ "planned_start"=>$activity->start_date, "planned_end"=>$activity->end_date, From 039bca44ba42b1faa815f434b562ee10cdb1cddb Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 27 Jul 2023 14:50:10 +0700 Subject: [PATCH 056/185] Fix sync report --- app/Http/Controllers/ProjectController.php | 42 +++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 6e8ca66..43dadf9 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -349,6 +349,25 @@ class ProjectController extends Controller return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); } + public static function setSyncDate($activity_id, $activity, $report) { + $status = ReportActivityMaterial::select('description')->where('activity_id', $activity_id)->first(); + if (isset($status) && $status != 'done') { + $minDate = date_create($report->report_date); + $maxDate = date_create($report->report_date); + date_add($maxDate, date_interval_create_from_date_string($activity->duration . " days")); + } else { + $material = AssignMaterial::where('activity_id', $activity_id)->first(); + $minDate = $material->start_activity; + $maxDate = $material->finish_activity; + } + $reports = array( + 'activity_id' => $activity_id, + 'min_date' => $minDate, + 'max_date' => $maxDate + ); + return $reports; + } + public function synchronizeReport($gantt_id) { $activities = Activity::where("version_gantt_id", $gantt_id)->get(); @@ -360,21 +379,12 @@ class ProjectController extends Controller if ($countReports === 1) { $dataReports = ReportActivityMaterial::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") - ); + $reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr); } } if ($countReports > 1) { $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); - $lastReport = ReportActivityMaterial::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") - ); + $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); } $activity->reports = $reports; } @@ -383,8 +393,16 @@ class ProjectController extends Controller for ($i=0; $i < count($reports); $i++) { $activity = Activity::find($reports[$i]['activity_id']); + $successor = Link::where('t_activity_id', $activity->id)->first(); + if ($successor) { + $predecessor = Activity::find($successor->s_activity_id); + $activity->start_date = $predecessor->end_date; + $reports[$i]['max_date']->modify('1 day'); + } else { + $reports[$i]['max_date']->modify('-1 day'); + } $activity->start_date = $reports[$i]['min_date']; - $activity->end_date = $reports[$i]['max_date']; + $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); $activity->save(); } From b25723c9367db426234d94fc7e33ede690c7657d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 28 Jul 2023 08:54:46 +0700 Subject: [PATCH 057/185] Fix dayoff --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 15e6cb4..708b3a5 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -353,7 +353,7 @@ class ActivityController extends Controller Activity::where('version_gantt_id', $data['ganttId'])->delete(); $projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id; - $dayOffs = VersionGantt::find($data['ganttId'])->first()->config_dayoff; + $dayOffs = VersionGantt::where('id', $data['ganttId'])->first()->config_dayoff; $activityStack = []; From b0b2c7b89f722bf98ec6e96692566e79559b5695 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 28 Jul 2023 10:35:12 +0700 Subject: [PATCH 058/185] Fix Sync Report --- app/Http/Controllers/ProjectController.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 43dadf9..158b77e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -350,20 +350,21 @@ class ProjectController extends Controller } public static function setSyncDate($activity_id, $activity, $report) { - $status = ReportActivityMaterial::select('description')->where('activity_id', $activity_id)->first(); - if (isset($status) && $status != 'done') { + $status = AssignMaterial::select('status_activity')->where('activity_id', $activity_id)->first(); + if (isset($status->status_activity) && $status->status_activity != 'done') { $minDate = date_create($report->report_date); $maxDate = date_create($report->report_date); date_add($maxDate, date_interval_create_from_date_string($activity->duration . " days")); } else { $material = AssignMaterial::where('activity_id', $activity_id)->first(); - $minDate = $material->start_activity; - $maxDate = $material->finish_activity; + $minDate = date_create($material->start_activity); + $maxDate = date_create($material->finish_activity); } $reports = array( 'activity_id' => $activity_id, 'min_date' => $minDate, - 'max_date' => $maxDate + 'max_date' => $maxDate, + 'status' => $status->status_activity ); return $reports; } @@ -397,8 +398,8 @@ class ProjectController extends Controller if ($successor) { $predecessor = Activity::find($successor->s_activity_id); $activity->start_date = $predecessor->end_date; - $reports[$i]['max_date']->modify('1 day'); - } else { + } + if($reports[$i]['status'] != 'done'){ $reports[$i]['max_date']->modify('-1 day'); } $activity->start_date = $reports[$i]['min_date']; From 8c817ac2f3b51cf83542e6ac0439ee852bb32e4f Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 1 Aug 2023 15:28:20 +0700 Subject: [PATCH 059/185] Fix handling default value --- app/Http/Controllers/ActivityController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 708b3a5..978276d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -462,8 +462,12 @@ class ActivityController extends Controller do { array_pop($activityStack); $lastStack = end($activityStack); - if ($activity->level > $lastStack->level) + if ($lastStack) { + if ($activity->level > $lastStack->level) + $lastStackIsNotRight = false; + } else { $lastStackIsNotRight = false; + } } while ($lastStackIsNotRight); } From af788c2d49b9e4599bbf04b5c17df1bc805c7c3b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 2 Aug 2023 10:49:41 +0700 Subject: [PATCH 060/185] Fix default column showed --- app/Http/Controllers/ShowHideColumnController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ShowHideColumnController.php b/app/Http/Controllers/ShowHideColumnController.php index a2db693..be5292f 100644 --- a/app/Http/Controllers/ShowHideColumnController.php +++ b/app/Http/Controllers/ShowHideColumnController.php @@ -45,12 +45,12 @@ class ShowHideColumnController extends Controller $success = 0; - foreach ($columns as $column) { + foreach ($columns as $key => $column) { $dataAdd = array( 'version_gantt_id'=>$request->version_gantt_id, 'user_id'=>$this->currentId, - 'column_name'=>$column, - 'show'=>true, + 'column_name'=>$key, + 'show'=>$column, 'created_by'=>$this->currentName ); From 5afcf08a59272084c09903485ad9440f87588027 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 4 Aug 2023 13:31:23 +0700 Subject: [PATCH 061/185] Update gantt update local storage --- app/Http/Controllers/ActivityController.php | 26 +++++++++++++++++++++ routes/web.php | 1 + 2 files changed, 27 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 978276d..57d665f 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -312,6 +312,32 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); } + public function batchUpdate(Request $request, $ganttId) + { + $entities = $request->all(); + if (empty($ganttId) || !is_int((int) $ganttId)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + $activity = Activity::where('version_gantt_id',$ganttId)->get(); + $link = Link::where('version_gantt_id', $ganttId)->get(); + if (!$activity) + return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404); + if (!$link) + return response()->json(['status' => 'failed', 'message' => 'Link not found!', 'code' => 404], 404); + foreach ($entities as $entity) { + if ($entity['entity'] == "task") { + $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); + $entity['data']['name'] = $entity['data']['text']; + if(!$activityToUpdate->update($entity['data'])) + return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); + } else if ($entity['entity'] == "link"){ + $linkToUpdate = $link->firstWhere('id', $entity['data']['id']); + if(!$linkToUpdate->update($entity['data'])) + return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500); + } + } + return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); + } + public function delete($id) { if (!$data = Activity::find($id)) diff --git a/routes/web.php b/routes/web.php index 03f769c..a9bcb99 100644 --- a/routes/web.php +++ b/routes/web.php @@ -207,6 +207,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld'); + $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); $router->post('/task', 'ActivityController@add'); $router->get('/task/edit/{id}', 'ActivityController@edit'); $router->put('/task/{id}', 'ActivityController@update'); From eee1bdcfc1292cee5204ac9ed33d94529b57c0fa Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 7 Aug 2023 09:33:26 +0700 Subject: [PATCH 062/185] Optimize map monitoring --- .../Controllers/MapMonitoringController.php | 14 +++--- app/Http/Controllers/ProjectController.php | 48 ------------------- 2 files changed, 7 insertions(+), 55 deletions(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index 26b36cb..637983a 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -22,24 +22,24 @@ class MapMonitoringController extends Controller ->select('user_id') ->whereIn('proyek_id', $request->project_id) ->distinct() - ->get(); - // get position hr in presensi - $tmp = []; - foreach($hr_assign_project as $key){ - $presensi = DB::table('t_clock_in_out as tcio') + ->pluck('user_id'); + // get position hr in presensi + $presences = DB::table('t_clock_in_out as tcio') ->select('tcio.id as clock_in_out_id','mu.id as user_id', 'mu.name as fullname', 'tcio.clock_in', 'tcio.clock_out', 'tcio.clock_in_lat', 'tcio.clock_in_lng', 'tcio.clock_out_lat', 'tcio.clock_out_lng', 'tcio.clock_in_loc', 'tcio.clock_out_loc', 'tcio.clock_in_boundary', 'tcio.clock_out_boundary', 'mu.username', 'tcio.date_presence', 'tcio.created_at') ->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') - ->where('mu.id', $key->user_id) + ->whereIn('mu.id', $hr_assign_project) ->orderBy('tcio.id', 'DESC') ->first(); $project = DB::table('assign_hr_to_proyek as ahtp') ->select('ahtp.proyek_id as id', 'mp.nama as project_name') ->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id') ->whereIn('ahtp.proyek_id', $request->project_id) - ->where('ahtp.user_id', $key->user_id) + ->whereIn('ahtp.user_id', $hr_assign_project) ->get(); + $tmp = []; + foreach($presences as $presensi){ if($presensi && isset($presensi->user_id)){ $image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first(); $tmp[] = array( diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 158b77e..104fcf2 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -224,54 +224,6 @@ class ProjectController extends Controller if(!$data) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - $scheduleWarningThreshold = 10; - $scheduleDangerThreshold = 5; - foreach($data as $d){ - $progress = $costVariance = $actualCost = 0; - $lastActivity = null; - $scheduleHealth = "on-track"; - $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); - if($rootActivity){ - $costVariance = (int)$d->rencana_biaya - (int)$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)); - } - $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->costVariance = $costVariance; - $d->costHealth = $d->budget_health; - $d->scheduleHealth = $scheduleHealth; - $d->progress = $progress; - $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; - $d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; - $d->projectManager = DB::table('m_proyek') - ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') - ->where('m_proyek.id', $d->id) - ->pluck('m_users.name') - ->first(); - if($d->area_kerja != ''){ - $d->geolocation = $this->httpReq($d->area_kerja); - $d->geolocation = []; - } else { - $d->geolocation = []; - } - } - $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); $totalActualCost = $data->sum('actualCost'); $manpowers = User::count(); From 89992a4bcbb016e3637c45b9dd253a79c6d4aaa1 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 7 Aug 2023 10:14:52 +0700 Subject: [PATCH 063/185] Fix map monitoring --- app/Http/Controllers/MapMonitoringController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index 637983a..93b29fe 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -22,24 +22,24 @@ class MapMonitoringController extends Controller ->select('user_id') ->whereIn('proyek_id', $request->project_id) ->distinct() - ->pluck('user_id'); - // get position hr in presensi - $presences = DB::table('t_clock_in_out as tcio') + ->get(); + // get position hr in presensi + $tmp = []; + foreach($hr_assign_project as $key){ + $presensi = DB::table('t_clock_in_out as tcio') ->select('tcio.id as clock_in_out_id','mu.id as user_id', 'mu.name as fullname', 'tcio.clock_in', 'tcio.clock_out', 'tcio.clock_in_lat', 'tcio.clock_in_lng', 'tcio.clock_out_lat', 'tcio.clock_out_lng', 'tcio.clock_in_loc', 'tcio.clock_out_loc', 'tcio.clock_in_boundary', 'tcio.clock_out_boundary', 'mu.username', 'tcio.date_presence', 'tcio.created_at') ->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') - ->whereIn('mu.id', $hr_assign_project) + ->where('mu.id', $key->user_id) ->orderBy('tcio.id', 'DESC') ->first(); $project = DB::table('assign_hr_to_proyek as ahtp') ->select('ahtp.proyek_id as id', 'mp.nama as project_name') ->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id') ->whereIn('ahtp.proyek_id', $request->project_id) - ->whereIn('ahtp.user_id', $hr_assign_project) + ->where('ahtp.user_id', $key->user_id) ->get(); - $tmp = []; - foreach($presences as $presensi){ if($presensi && isset($presensi->user_id)){ $image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first(); $tmp[] = array( @@ -60,7 +60,7 @@ class MapMonitoringController extends Controller 'image_selfie' => isset($image->image) ? $image->image : '-', 'created_at' => $presensi->created_at, 'presence_status' => $presensi->date_presence == $dateNow ? true : false,//true, //status date_presence, - 'projects' => $project + 'projects' => $project ); } } From a01f1ca25eacb56c4f172f4ef3733025634eaf78 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 7 Aug 2023 10:16:29 +0700 Subject: [PATCH 064/185] Add formatting --- .../Controllers/MapMonitoringController.php | 105 ++++++++++-------- 1 file changed, 60 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index 93b29fe..efec73f 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -15,56 +15,71 @@ class MapMonitoringController extends Controller // default map monitoring shows today's presence lat lon in the map public function search(Request $request) - { + { $dateNow = Carbon::today()->addHour(7)->format('Y-m-d'); // get distinct human assign project $hr_assign_project = DB::table('assign_hr_to_proyek') - ->select('user_id') - ->whereIn('proyek_id', $request->project_id) - ->distinct() - ->get(); + ->select('user_id') + ->whereIn('proyek_id', $request->project_id) + ->distinct() + ->get(); // get position hr in presensi $tmp = []; - foreach($hr_assign_project as $key){ + foreach ($hr_assign_project as $key) { $presensi = DB::table('t_clock_in_out as tcio') - ->select('tcio.id as clock_in_out_id','mu.id as user_id', 'mu.name as fullname', 'tcio.clock_in', 'tcio.clock_out', 'tcio.clock_in_lat', 'tcio.clock_in_lng', - 'tcio.clock_out_lat', 'tcio.clock_out_lng', 'tcio.clock_in_loc', 'tcio.clock_out_loc', 'tcio.clock_in_boundary', - 'tcio.clock_out_boundary', 'mu.username', 'tcio.date_presence', 'tcio.created_at') - ->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') - ->where('mu.id', $key->user_id) - ->orderBy('tcio.id', 'DESC') - ->first(); - $project = DB::table('assign_hr_to_proyek as ahtp') - ->select('ahtp.proyek_id as id', 'mp.nama as project_name') - ->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id') - ->whereIn('ahtp.proyek_id', $request->project_id) - ->where('ahtp.user_id', $key->user_id) - ->get(); - if($presensi && isset($presensi->user_id)){ + ->select( + 'tcio.id as clock_in_out_id', + 'mu.id as user_id', + 'mu.name as fullname', + 'tcio.clock_in', + 'tcio.clock_out', + 'tcio.clock_in_lat', + 'tcio.clock_in_lng', + 'tcio.clock_out_lat', + 'tcio.clock_out_lng', + 'tcio.clock_in_loc', + 'tcio.clock_out_loc', + 'tcio.clock_in_boundary', + 'tcio.clock_out_boundary', + 'mu.username', + 'tcio.date_presence', + 'tcio.created_at' + ) + ->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') + ->where('mu.id', $key->user_id) + ->orderBy('tcio.id', 'DESC') + ->first(); + $project = DB::table('assign_hr_to_proyek as ahtp') + ->select('ahtp.proyek_id as id', 'mp.nama as project_name') + ->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id') + ->whereIn('ahtp.proyek_id', $request->project_id) + ->where('ahtp.user_id', $key->user_id) + ->get(); + if ($presensi && isset($presensi->user_id)) { $image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first(); $tmp[] = array( - 'user_id' => $presensi->user_id, - 'clock_in' => $presensi->clock_in, - 'clock_out' => $presensi->clock_out, - 'date_presence' => $presensi->date_presence, - 'clock_in_lat' => $presensi->clock_in_lat, - 'clock_in_lng' => $presensi->clock_in_lng, - 'clock_out_lat' => $presensi->clock_out_lat, - 'clock_out_lng' => $presensi->clock_out_lng, - 'clock_in_loc' => $presensi->clock_in_loc, - 'clock_out_loc' => $presensi->clock_out_loc, - 'clock_in_boundary' => $presensi->clock_in_boundary, - 'clock_out_boundary' => $presensi->clock_out_boundary, - 'username' => $presensi->username, - 'name' => $presensi->fullname, - 'image_selfie' => isset($image->image) ? $image->image : '-', - 'created_at' => $presensi->created_at, - 'presence_status' => $presensi->date_presence == $dateNow ? true : false,//true, //status date_presence, - 'projects' => $project + 'user_id' => $presensi->user_id, + 'clock_in' => $presensi->clock_in, + 'clock_out' => $presensi->clock_out, + 'date_presence' => $presensi->date_presence, + 'clock_in_lat' => $presensi->clock_in_lat, + 'clock_in_lng' => $presensi->clock_in_lng, + 'clock_out_lat' => $presensi->clock_out_lat, + 'clock_out_lng' => $presensi->clock_out_lng, + 'clock_in_loc' => $presensi->clock_in_loc, + 'clock_out_loc' => $presensi->clock_out_loc, + 'clock_in_boundary' => $presensi->clock_in_boundary, + 'clock_out_boundary' => $presensi->clock_out_boundary, + 'username' => $presensi->username, + 'name' => $presensi->fullname, + 'image_selfie' => isset($image->image) ? $image->image : '-', + 'created_at' => $presensi->created_at, + 'presence_status' => $presensi->date_presence == $dateNow ? true : false, //true, //status date_presence, + 'projects' => $project ); } } - return response()->json(['status'=>'success','code'=>200, 'data' => $tmp, 'totalRecord'=>count($tmp)], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $tmp, 'totalRecord' => count($tmp)], 200); } public function list() @@ -72,12 +87,12 @@ class MapMonitoringController extends Controller $data = Presence::all(); $countData = $data->count(); - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list presence, please try again later!','code'=>400], 400); + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list presence, please try again later!', 'code' => 400], 400); } } - -} + +} \ No newline at end of file From 5cd80e434864e27d62148809cc0c11d4fa7fe1ce Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 7 Aug 2023 10:57:10 +0700 Subject: [PATCH 065/185] Remove unnecessary column --- app/Http/Controllers/MapMonitoringController.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index efec73f..0dda48a 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -35,15 +35,9 @@ class MapMonitoringController extends Controller 'tcio.clock_out', 'tcio.clock_in_lat', 'tcio.clock_in_lng', - 'tcio.clock_out_lat', - 'tcio.clock_out_lng', 'tcio.clock_in_loc', 'tcio.clock_out_loc', - 'tcio.clock_in_boundary', - 'tcio.clock_out_boundary', - 'mu.username', 'tcio.date_presence', - 'tcio.created_at' ) ->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') ->where('mu.id', $key->user_id) @@ -61,19 +55,12 @@ class MapMonitoringController extends Controller 'user_id' => $presensi->user_id, 'clock_in' => $presensi->clock_in, 'clock_out' => $presensi->clock_out, - 'date_presence' => $presensi->date_presence, 'clock_in_lat' => $presensi->clock_in_lat, 'clock_in_lng' => $presensi->clock_in_lng, - 'clock_out_lat' => $presensi->clock_out_lat, - 'clock_out_lng' => $presensi->clock_out_lng, 'clock_in_loc' => $presensi->clock_in_loc, 'clock_out_loc' => $presensi->clock_out_loc, - 'clock_in_boundary' => $presensi->clock_in_boundary, - 'clock_out_boundary' => $presensi->clock_out_boundary, - 'username' => $presensi->username, 'name' => $presensi->fullname, 'image_selfie' => isset($image->image) ? $image->image : '-', - 'created_at' => $presensi->created_at, 'presence_status' => $presensi->date_presence == $dateNow ? true : false, //true, //status date_presence, 'projects' => $project ); From d782797bef6db1e75f9ed4b1685c3fdf9f6ae0c7 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 10 Aug 2023 12:07:20 +0700 Subject: [PATCH 066/185] Fix date range --- app/Helpers/MasterFunctionsHelper.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index a537ed8..0a817d5 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -189,14 +189,19 @@ class MasterFunctionsHelper /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged $interval = new \DateInterval('P7D'); } else { - $maxDate = DB::table('assign_material_to_activity as ama') + $actualMaxDate = 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['id']) - ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's - $end = new \DateTime($maxDate . ' Friday'); - $end->modify('next Friday'); - $end->modify('next Friday'); + ->max("a.end_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $plannedMaxDate = 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['id']) + ->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity' + $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); + $end = $maxDate; + $end->modify('last month'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); From 15e18b79017c6b736fd6954545d8239bb8c0426b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 11 Aug 2023 11:43:08 +0700 Subject: [PATCH 067/185] Fix report activity after update --- app/Http/Controllers/ActivityController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 57d665f..5158b05 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -327,8 +327,10 @@ class ActivityController extends Controller if ($entity['entity'] == "task") { $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $entity['data']['name'] = $entity['data']['text']; + $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; if(!$activityToUpdate->update($entity['data'])) return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); + $updatedJobsDone = $activityToUpdate->jobs_done; } else if ($entity['entity'] == "link"){ $linkToUpdate = $link->firstWhere('id', $entity['data']['id']); if(!$linkToUpdate->update($entity['data'])) From 70740213add4cf8397e146f6c0bff5d3008d3919 Mon Sep 17 00:00:00 2001 From: ibnu Date: Sat, 12 Aug 2023 18:58:35 +0700 Subject: [PATCH 068/185] update test optimalisasi API project search --- app/Http/Controllers/Controller.php | 73 ++++++++++++++++++++++ app/Http/Controllers/ProjectController.php | 13 ++++ rest-client.http | 72 ++++++++++++++++++++- routes/web.php | 2 +- 4 files changed, 156 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index c431f28..bd2fd2d 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -97,6 +97,79 @@ class Controller extends BaseController return $data; } + // new version for custom select in selfTable + protected function setUpPayloadSelect($condition, $tableSelf) + { + $alias = "selfTable"; + $builder = DB::table($tableSelf." AS ".$alias); + // $builder = $builder->select($alias.".*"); + if($condition){ + if(isset($condition['select'])){ + foreach($condition['select'] as $select){ + $builder = $builder->select($alias.".".$select); + } + } + if(isset($condition['joins'])){ + $no = 0; + foreach($condition['joins'] as $join){ + $tableJoin = isset($join['name1']) ? $join['name1'] : $alias; + $tableName = $join['name']; + $columnJoin = $join['column_join']; // foreign key table sini + $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan + $columnResult = $join['column_results']; + + foreach($columnResult as $sColumn){ + $builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn); + } + $builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); + $no++; + } + } + + if(isset($condition['columns'])){ + $listWhere = $condition['columns']; + + $builder = $builder->where(function ($query) use($listWhere, $alias){ + foreach($listWhere as $where){ + $value = $where['value']; + if($value && $value!="" && $value!=" "){ + $column = $where['name']; + $operator = strtolower($where['logic_operator']); // like, =, <>, range + $value2 = isset($where['value1']) ? $where['value1'] : ""; + $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; + $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } + } + }); + } + + if(isset($condition['group_column'])){ + $builder = $this->groupWhere($builder, $condition['group_column'], $alias); + } + + $data['count'] = clone $builder; + + if(isset($condition['paging'])){ + $builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']); + } + + if(isset($condition['orders'])){ + $orders = $condition['orders']; + $sortBy = $orders['ascending'] ? "ASC" : "DESC"; + $columnOrder = $orders['columns']; + foreach($columnOrder as $column){ + $builder = $builder->orderBy($alias.".".$column, $sortBy); + } + } + }else{ + $builder = $builder->select($alias.".*"); + } + $data['builder'] = $builder; + return $data; + } + + + private function groupWhere($oldBuilder, $groupWhere, $alias) { $builder = $oldBuilder; diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 104fcf2..9d50370 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -216,6 +216,19 @@ class ProjectController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); } + public function searchCustom(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayloadSelect($payload, 'm_proyek'); + $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 list() { $data = Project::orderBy('id', 'desc')->get(); diff --git a/rest-client.http b/rest-client.http index 03878db..772aee0 100644 --- a/rest-client.http +++ b/rest-client.http @@ -1,10 +1,12 @@ -@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODQ0NFwvYXBpXC9sb2dpbiIsImlhdCI6MTY3NzQ3NzIzMSwiZXhwIjoxNjc4MDgyMDMxLCJuYmYiOjE2Nzc0NzcyMzEsImp0aSI6ImR5WWhRY3ZIbUJEcmFKMG0iLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.9zT6CBbQholzIdQ9ZBDoxMvrR-PKvIYkGzdNB6bim0Y +@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODQ0NFwvYXBpXC9sb2dpbiIsImlhdCI6MTY5MTc2MDYyNCwiZXhwIjoxNjkyMzY1NDI0LCJuYmYiOjE2OTE3NjA2MjQsImp0aSI6Ikd2bEFPTE4yZ2FuRFdVbjEiLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.XNGbsmcgQ-CkV8vLlvnItGKM0R1am5X5b6qUFOR1DRo +@tokenS = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hZHctYXBpLm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjkxNTcyMTIwLCJleHAiOjE2OTIxNzY5MjAsIm5iZiI6MTY5MTU3MjEyMCwianRpIjoiVUdqbnhLRVdlZzYyTTBnayIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.5QqK0dLW5jzbVOkSCSW0mFo0K7ycGOBW9NCG_2Zldm4 -@hostname = https://adw-api.ospro.id/api + +# @hostname = https://adw-api.ospro.id/api # @hostname = https://ospro-api.ospro.id/api # @hostname = https://api-iu.ospro.id/api # @hostname = https://api-staging-adw.ospro.id/api -# @hostname = http://localhost:8444/api +@hostname = http://localhost:8444/api # @hostname = http://103.73.125.81:8444/api # @hostname = http://localhost:8444/adw-backend/api @@ -402,6 +404,59 @@ GET {{hostname}}/project/list Authorization: Bearer {{token}} content-type: application/json +### +POST {{hostname}}/project/search +Authorization: Bearer {{token}} +content-type: application/json + +{ + "columns": [ + { + "name": "nama", + "logic_operator": "ilike", + "value": "", + "operator": "AND" + } + ], + "select": ["kode_sortname", "nama", "mulai_proyek"], + "joins": [ + { + "name": "m_users", + "column_join": "pm_id", + "column_results": [ + "name", + "username" + ] + }, + { + "name": "m_type_proyek", + "column_join": "type_proyek_id", + "column_results": [ + "name", + "description" + ] + } + ], + "orders": { + "columns": [ + "id" + ], + "ascending": false + }, + "paging": { + "start": 0, + "length": 10 + } +} + +### +POST https://adw-api.ospro.id/api/project/search +Authorization: Bearer {{tokenS}} +content-type: application/json + +{ + "columns":[{"name":"nama","logic_operator":"ilike","value":"","operator":"AND"}],"joins":[{"name":"m_users","column_join":"pm_id","column_results":["name","username"]},{"name":"m_type_proyek","column_join":"type_proyek_id","column_results":["name","description"]}],"orders":{"columns":["id"],"ascending":false},"paging":{"start":0,"length":10} +} ### add POST {{hostname}}/project/add @@ -1103,3 +1158,14 @@ content-type: application/json } } + +####### +POST {{hostname}}/project/get-s-curve +Authorization: Bearer {{token}} +content-type: application/json + +{ + "period":"week", + "project_id":"118", + "gantt_id":"287" +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index a9bcb99..f7f8f93 100644 --- a/routes/web.php +++ b/routes/web.php @@ -53,7 +53,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); - $router->post('/project/search', 'ProjectController@search'); + $router->post('/project/search', 'ProjectController@searchCustom'); $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); $router->get('/project/edit/{id}', 'ProjectController@edit'); From 71e21226d265760b05ae52f9e2543eee9bf57d88 Mon Sep 17 00:00:00 2001 From: ibnu Date: Mon, 14 Aug 2023 07:28:43 +0700 Subject: [PATCH 069/185] update logic setUpPayload custom select --- app/Http/Controllers/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index bd2fd2d..abad8b3 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -106,7 +106,7 @@ class Controller extends BaseController if($condition){ if(isset($condition['select'])){ foreach($condition['select'] as $select){ - $builder = $builder->select($alias.".".$select); + $builder = $builder->addSelect($alias.".".$select); } } if(isset($condition['joins'])){ From 2eeb504119c54d91c03194209fa7f75b27ac666b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 14 Aug 2023 10:32:46 +0700 Subject: [PATCH 070/185] Fix update actual cost --- app/Models/Activity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 1b98d03..eefcea4 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -71,8 +71,8 @@ class Activity extends Model $data->updateCostPlanning(); if($data->bobot_planning){ $data->updatePersentaseProgress(); - $data->updateCostActual(); } + $data->updateCostActual(); // if($data->start_date != request()->start_date || $data->end_date != request()->end_date) { // $data->updateStartEndDateHeader(); // } @@ -86,8 +86,8 @@ class Activity extends Model $data->updateCostPlanning(); if($data->bobot_planning){ $data->updatePersentaseProgress(); - $data->updateCostActual(); } + $data->updateCostActual(); $data->updateStartEndDateHeader(); }); From 9e60faf622801258c52ab5ec6c7dff624153a9b1 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 15 Aug 2023 09:02:24 +0700 Subject: [PATCH 071/185] Removing s curve from select --- app/Http/Controllers/ProjectController.php | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 9d50370..7b186c5 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -231,7 +231,44 @@ class ProjectController extends Controller public function list() { - $data = Project::orderBy('id', 'desc')->get(); + $data = Project::select( + 'id', + 'kode_sortname', + 'jumlah_stakeholder', + 'nama', + 'mulai_proyek', + 'akhir_proyek', + 'area_kerja', + 'lokasi_kantor', + 'rencana_biaya', + 'biaya_actual', + 'company', + 'pm_id', + 'type_proyek_id', + 'divisi_id', + 'persentase_progress', + 'keterangan', + 'durasi_proyek', + 'progress_by_worklog', + 'status', + 'currency_symbol', + 'currency_code', + 'currency_name', + 'project_objectives', + 'considered_success_when', + 'potential_risk', + 'testing_environment', + 'currency_code', + 'currency_symbol', + 'currency_name', + 'budget_health', + 'phase_id', + 'calculation_status', + 'created_at', + 'created_by', + 'updated_at', + 'updated_by' + )->orderBy('id', 'desc')->get(); $countData = $data->count(); if(!$data) From 1e6fe6f1232edcd920c7baf2500452a3d14bca14 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 15 Aug 2023 10:05:57 +0700 Subject: [PATCH 072/185] Use only required column hr list --- app/Http/Controllers/HumanResourceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 8e23f87..9e47627 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -112,7 +112,7 @@ class HumanResourceController extends Controller public function list() { - $data = HumanResource::all(); + $data = HumanResource::select('id', 'name')->get(); $countData = $data->count(); if($data){ From 4cd909c8ed4938389cc827d45f0d3d5809f6af17 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 15 Aug 2023 10:41:00 +0700 Subject: [PATCH 073/185] update search --- app/Http/Controllers/ProjectController.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 9d50370..5149d0d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -214,24 +214,11 @@ class ProjectController extends Controller $totalRecord = $countBuilder->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function searchCustom(Request $request) - { - $payload = $request->all(); - - $dataBuilder = $this->setUpPayloadSelect($payload, 'm_proyek'); - $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 list() { - $data = Project::orderBy('id', 'desc')->get(); + $data = Project::select("id", "nama", "kode_sortname")->orderBy('id', 'desc')->get(); $countData = $data->count(); if(!$data) @@ -254,7 +241,7 @@ class ProjectController extends Controller } try { $projectsByType = DB::table('m_proyek') - ->select('m_type_proyek.name', DB::raw('count(*) as total')) + ->select('m_type_proyek.name', DB::raw('count(id) as total')) ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') ->groupBy('m_type_proyek.name') ->get(); From 6050cd6a1e24b2d555fba97c411c1baa7d720f55 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 15 Aug 2023 10:48:01 +0700 Subject: [PATCH 074/185] update logic cek location --- app/Http/Controllers/PresenceController.php | 28 +++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 36ee625..00980cc 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -263,11 +263,35 @@ class PresenceController extends Controller foreach($geom as $dataGeom){ $valGeom = json_decode($dataGeom->geom); if($params->clock_in_out['type']=="out"){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + if($valGeom->type == "FeatureCollection"){ + // return count($valGeom->features); + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + } }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + if($valGeom->type == "FeatureCollection"){ + // return count($valGeom->features); + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + } } if(count($check)>0){ if($check[0]->boundary){ From 8fee272740a6dd9dfa4831b1ea84e7f48f333ca5 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 15 Aug 2023 14:58:55 +0700 Subject: [PATCH 075/185] update logic multi area clockinout --- app/Http/Controllers/PresenceController.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 00980cc..7490ab8 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -263,13 +263,12 @@ class PresenceController extends Controller foreach($geom as $dataGeom){ $valGeom = json_decode($dataGeom->geom); if($params->clock_in_out['type']=="out"){ - if($valGeom->type == "FeatureCollection"){ - // return count($valGeom->features); + if($valGeom->type == "FeatureCollection"){ $multiArea = $valGeom->features; foreach($multiArea as $area){ $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ + if($check[0]->boundary == true){ break; } } @@ -278,13 +277,12 @@ class PresenceController extends Controller ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); } }else{ - if($valGeom->type == "FeatureCollection"){ - // return count($valGeom->features); + if($valGeom->type == "FeatureCollection"){ $multiArea = $valGeom->features; foreach($multiArea as $area){ $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ + if($check[0]->boundary == true){ break; } } @@ -338,6 +336,7 @@ class PresenceController extends Controller ->whereDate("ma.end_date", ">=", $params->time) ->get(); $temp = []; + // return json_encode($geom); if (count($geom) > 0) { foreach($geom as $dataGeom){ $valGeom = json_decode($dataGeom->geom); @@ -348,7 +347,7 @@ class PresenceController extends Controller foreach($multiArea as $area){ $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ + if($check[0]->boundary == true){ break; } } @@ -363,7 +362,7 @@ class PresenceController extends Controller foreach($multiArea as $area){ $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ + if($check[0]->boundary == true){ break; } } From 9ec799d787d5db77e55c210cc4da12693e723413 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 15 Aug 2023 15:04:36 +0700 Subject: [PATCH 076/185] update logic multi area clockinout --- app/Http/Controllers/PresenceController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 7490ab8..722607c 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -266,9 +266,9 @@ class PresenceController extends Controller if($valGeom->type == "FeatureCollection"){ $multiArea = $valGeom->features; foreach($multiArea as $area){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - if($check[0]->boundary == true){ + if($check[0]->boundary){ break; } } @@ -282,7 +282,7 @@ class PresenceController extends Controller foreach($multiArea as $area){ $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - if($check[0]->boundary == true){ + if($check[0]->boundary){ break; } } @@ -345,9 +345,9 @@ class PresenceController extends Controller // return count($valGeom->features); $multiArea = $valGeom->features; foreach($multiArea as $area){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - if($check[0]->boundary == true){ + if($check[0]->boundary){ break; } } @@ -362,7 +362,7 @@ class PresenceController extends Controller foreach($multiArea as $area){ $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - if($check[0]->boundary == true){ + if($check[0]->boundary){ break; } } From 2ac211ffafef1cc97ede96a36891b091b4c61ca4 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 15 Aug 2023 15:05:44 +0700 Subject: [PATCH 077/185] Fix multiarea geom --- app/Http/Controllers/PresenceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 00980cc..018052e 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -267,7 +267,7 @@ class PresenceController extends Controller // return count($valGeom->features); $multiArea = $valGeom->features; foreach($multiArea as $area){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); if($check[0]->boundary){ break; From a0cff6bf7083e40e86e65635b587b73497bd43d4 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 15 Aug 2023 16:00:12 +0700 Subject: [PATCH 078/185] Fix project list map monitoring --- app/Http/Controllers/ProjectController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 1787d88..e2d25ce 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -278,7 +278,7 @@ class ProjectController extends Controller } try { $projectsByType = DB::table('m_proyek') - ->select('m_type_proyek.name', DB::raw('count(id) as total')) + ->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total')) ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') ->groupBy('m_type_proyek.name') ->get(); From b8784cf6ffbf0e8da4fd64c820d0561916b3e999 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 16 Aug 2023 13:27:46 +0700 Subject: [PATCH 079/185] Fix type milestone --- app/Http/Controllers/ActivityController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 5158b05..6124751 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -216,7 +216,9 @@ class ActivityController extends Controller $data['created_by'] = $this->currentName; $max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder'); $data['sortorder'] = $max + 1; - $data['type_activity'] = "task"; + if (!isset($data['type_activity'])) { + $data['type_activity'] = "task"; + } $parent = $data['parent_id'] ?? null; if ($parent) { From e56c4597d275da9f3d1b8c67536b20a655de0dda Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 16 Aug 2023 13:53:39 +0700 Subject: [PATCH 080/185] Fix sync report --- app/Http/Controllers/ProjectController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index e2d25ce..32eaeec 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -340,7 +340,10 @@ class ProjectController extends Controller public static function setSyncDate($activity_id, $activity, $report) { $status = AssignMaterial::select('status_activity')->where('activity_id', $activity_id)->first(); - if (isset($status->status_activity) && $status->status_activity != 'done') { + if (!isset($status->status_activity)) { + $status->status_activity = 'open'; + } + if ($status->status_activity != 'done') { $minDate = date_create($report->report_date); $maxDate = date_create($report->report_date); date_add($maxDate, date_interval_create_from_date_string($activity->duration . " days")); From c7ef95542519a74a080e3e91e3889c44af4627f5 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 16 Aug 2023 14:38:04 +0700 Subject: [PATCH 081/185] Fix period range --- app/Helpers/MasterFunctionsHelper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 0a817d5..07e2c74 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -201,7 +201,6 @@ class MasterFunctionsHelper ->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity' $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); $end = $maxDate; - $end->modify('last month'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); From fc35b7869e1e7507a573070701469f7389dc0f5c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 16 Aug 2023 16:18:15 +0700 Subject: [PATCH 082/185] Formatting --- .../Controllers/DashboardBoDController.php | 163 ++++++++++-------- 1 file changed, 89 insertions(+), 74 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 56ba219..8d437b1 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -14,16 +14,18 @@ use Illuminate\Support\Facades\Log; class DashboardBoDController extends Controller { - private function interpolateYear($year){ - if($year) - $year = '%'.$year.'%'; + private function interpolateYear($year) + { + if ($year) + $year = '%' . $year . '%'; return $year; } - private function curlReq($url, $token){ + private function curlReq($url, $token) + { $ch = curl_init(); $headers = [ - 'Authorization: '.$token + 'Authorization: ' . $token ]; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); @@ -37,7 +39,8 @@ class DashboardBoDController extends Controller return json_decode($response); } - private function getInvoiceIntegration($search) { + private function getInvoiceIntegration($search) + { // if(empty($search)) // return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); // @@ -52,30 +55,31 @@ class DashboardBoDController extends Controller } // to do - public function getCompanyCashFlow($year = '%') { + public function getCompanyCashFlow($year = '%') + { $year = $this->interpolateYear($year); $totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; // we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field $totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) ->where('mulai_proyek', 'like', $year) - /* ->orWhere('akhir_proyek', 'like', $year) */ + /* ->orWhere('akhir_proyek', 'like', $year) */ ->pluck('sum') ->first(); $projects = Project::where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->get(); - foreach($projects as $project){ + foreach ($projects as $project) { $project->expenses = 0; $resp = null; - if($project->kode_sortname != ""){ + if ($project->kode_sortname != "") { $resp = $this->getInvoiceIntegration($project->kode_sortname); /* $resp = $project->kode_sortname; */ $cost = $resp->data->total_cost ?? 0; $cost = substr($cost, 0, strpos($cost, ".")); - $totalExpenditure+= (int) $cost; + $totalExpenditure += (int) $cost; $totalInvoice += $resp->data->total_invoice_amount ?? 0; $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; } @@ -87,20 +91,21 @@ class DashboardBoDController extends Controller 'total_budget' => (int) $totalBudgets ?? 0, 'total_expenditure' => $totalExpenditure, 'total_invoice' => $totalInvoice, - 'total_paid_invoice' => $totalPaidInvoice , + 'total_paid_invoice' => $totalPaidInvoice, ] ], 200); } - public function getInvoiceOutstanding($year = '%'){ + public function getInvoiceOutstanding($year = '%') + { $year = $this->interpolateYear($year); $projects = Project::where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->get(); $return = []; - foreach($projects as $project){ + foreach ($projects as $project) { $resp = null; - if($project->kode_sortname != ""){ + if ($project->kode_sortname != "") { $resp = $this->getInvoiceIntegration($project->kode_sortname); array_push($return, [ 'project' => $project->nama, @@ -117,7 +122,8 @@ class DashboardBoDController extends Controller ], 200); } - public function getTotalProjectPerScheduleHealth($year = '%'){ + public function getTotalProjectPerScheduleHealth($year = '%') + { $year = $this->interpolateYear($year); $return = [ @@ -127,48 +133,49 @@ class DashboardBoDController extends Controller ]; $projects = Project::where('mulai_proyek', 'like', $year)->get(); - foreach($projects as $project) { - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); - $selisihProgress = 0; - if($project->scurve && $project->scurve[0]){ - $planningArray = $project->scurve[0]['data']['percentagePlan']; - $actualArray = $project->scurve[0]['data']['percentageReal']; - $planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0; - $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; - } - $selisihProgress = $planningProgress - $actualProgress; + foreach ($projects as $project) { + $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + $selisihProgress = 0; + if ($project->scurve && $project->scurve[0]) { + $planningArray = $project->scurve[0]['data']['percentagePlan']; + $actualArray = $project->scurve[0]['data']['percentageReal']; + $planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0; + $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; + } + $selisihProgress = $planningProgress - $actualProgress; try { - if($selisihProgress > 0 && $selisihProgress <= 5) - $return['warning'] += 1; - elseif($selisihProgress == 0) - $return['on-schedule'] += 1; - else - $return['behind-schedule'] += 1; + if ($selisihProgress > 0 && $selisihProgress <= 5) + $return['warning'] += 1; + elseif ($selisihProgress == 0) + $return['on-schedule'] += 1; + else + $return['behind-schedule'] += 1; } catch (\Error $e) { - return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); + return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); } } return response()->json(['data' => $return, 'q' => $projects], 200); } - public function getTotalProjectScheduleHealthPerDivision($year = '%'){ + public function getTotalProjectScheduleHealthPerDivision($year = '%') + { $year = $this->interpolateYear($year); $divisions = Divisi::whereNull('parent')->get(); - foreach($divisions as $division){ + foreach ($divisions as $division) { $scheduleData = new Collection(); $behindSchedule = $warning = $onSchedule = 0; $projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get(); - foreach($projects as $project) { + foreach ($projects as $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); - if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) + if (@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) $warning++; - elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) + elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) $behindSchedule++; - elseif(@$project->scurve['difference'] == 0) + elseif (@$project->scurve['difference'] == 0) $onSchedule++; } @@ -184,7 +191,8 @@ class DashboardBoDController extends Controller ], 200); } - public function getTotalProjectPerBudgetHealth($year = '%'){ + public function getTotalProjectPerBudgetHealth($year = '%') + { $year = $this->interpolateYear($year); return response()->json([ 'data' => [ @@ -195,28 +203,30 @@ class DashboardBoDController extends Controller ], 200); } - private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){ + private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health) + { return Project::where('divisi_id', $divisi) ->where('mulai_proyek', 'like', $year) - /* ->orWhere('akhir_proyek', 'like', $year) */ + /* ->orWhere('akhir_proyek', 'like', $year) */ ->where('budget_health', $health) ->count(); } - public function getTotalProjectBudgetHealthPerDivision($year = '%'){ + public function getTotalProjectBudgetHealthPerDivision($year = '%') + { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id','name') + $divisions = Divisi::select('id', 'name') ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child - foreach($divisions as $division){ + foreach ($divisions as $division) { $budgetData = new Collection(); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget'); - foreach($division->children as $d){ + foreach ($division->children as $d) { $budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun'); $budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning'); $budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget'); @@ -224,7 +234,7 @@ class DashboardBoDController extends Controller unset($division->children); $division->budgetData = $budgetData; } - foreach($divisions as $division){ + foreach ($divisions as $division) { } return response()->json([ 'data' => [ @@ -233,14 +243,15 @@ class DashboardBoDController extends Controller ], 200); } - public function getTotalProjectPerPhase($year = '%'){ + public function getTotalProjectPerPhase($year = '%') + { $year = $this->interpolateYear($year); $projectPhases = ProjectPhase::orderBy('order')->get(); - foreach($projectPhases as $phase){ + foreach ($projectPhases as $phase) { $phase->totalProject = Project::where('phase_id', $phase->id) - ->where('mulai_proyek', 'like', $year) - /* ->orWhere('akhir_proyek', 'like', $year) */ - ->count(); + ->where('mulai_proyek', 'like', $year) + /* ->orWhere('akhir_proyek', 'like', $year) */ + ->count(); } return response()->json([ 'data' => [ @@ -249,24 +260,26 @@ class DashboardBoDController extends Controller ], 200); } - private function countTotalProjectInDivision($id, $year){ + private function countTotalProjectInDivision($id, $year) + { return Project::where('divisi_id', $id) ->where('mulai_proyek', 'like', $year) ->count(); } - public function getTotalProjectPerDivision($year = '%') { + public function getTotalProjectPerDivision($year = '%') + { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id','name') + $divisions = Divisi::select('id', 'name') ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child - foreach($divisions as $v){ + foreach ($divisions as $v) { $v->total = $this->countTotalProjectInDivision($v->id, $year); - foreach($v->children as $d){ + foreach ($v->children as $d) { $v->total += $this->countTotalProjectInDivision($d->id, $year); } unset($v->children); @@ -277,27 +290,29 @@ class DashboardBoDController extends Controller ], 200); } - private function countTotalProjectValueInDivision($id, $year){ + private function countTotalProjectValueInDivision($id, $year) + { return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) ->where('mulai_proyek', 'like', $year) - /* ->orWhere('akhir_proyek', 'like', $year) */ + /* ->orWhere('akhir_proyek', 'like', $year) */ ->where('divisi_id', $id) ->pluck('sum') ->first(); } - public function getTotalProjectValuePerDivision($year = '%') { + public function getTotalProjectValuePerDivision($year = '%') + { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id','name') + $divisions = Divisi::select('id', 'name') ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child - foreach($divisions as $v){ + foreach ($divisions as $v) { $v->total = $this->countTotalProjectValueInDivision($v->id, $year); - foreach($v->children as $d){ + foreach ($v->children as $d) { $v->total += $this->countTotalProjectValueInDivision($d->id, $year); } unset($v->children); @@ -309,16 +324,17 @@ class DashboardBoDController extends Controller } - public function getDetailExpenditure($year = '%'){ + public function getDetailExpenditure($year = '%') + { $year = $this->interpolateYear($year); $projects = Project::where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->orderBy('id', 'desc') ->get(); - foreach($projects as $project){ + foreach ($projects as $project) { $lastGantt = MasterFunctionsHelper::getLatestGantt($project->id); - if($project->kode_sortname != ""){ + if ($project->kode_sortname != "") { $resp = $this->getInvoiceIntegration($project->kode_sortname); $project->invoice = [ 'invoiced' => $resp->data->total_invoice_amount ?? 0, @@ -328,12 +344,12 @@ class DashboardBoDController extends Controller $project->pm = User::find($project->pm_id); /* $project->header = Activity::where('proyek_id', $project->id)->where('version_gantt_id', $lastGantt['last_gantt_id'])->whereNull('parent_id')->first(); */ - if(!isset($lastGantt['last_gantt_id'])){ - $project->manPowers = 0; - } else { - $project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); - } + if (!isset($lastGantt['last_gantt_id'])) { + $project->manPowers = 0; + } else { + $project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); + $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + } $project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id); } @@ -342,5 +358,4 @@ class DashboardBoDController extends Controller 'total_manpowers' => User::count() ], 200); } -} - +} \ No newline at end of file From d850aef744bc27f572687875eb31b59a4ebb27c5 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 18 Aug 2023 09:04:54 +0700 Subject: [PATCH 083/185] Fix batch update sortorder --- app/Http/Controllers/ActivityController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 6124751..4ba8865 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -330,6 +330,9 @@ class ActivityController extends Controller $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $entity['data']['name'] = $entity['data']['text']; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; + if (isset($entity['data']['target'])) { + $this->updateOrder($entity['data']['id'], $entity['data']['target']); + } if(!$activityToUpdate->update($entity['data'])) return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); $updatedJobsDone = $activityToUpdate->jobs_done; From 7bf4b74ee397d3ee44491e7b7cb4a486b043277d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 18 Aug 2023 11:38:21 +0700 Subject: [PATCH 084/185] fix calculate scurve --- app/Helpers/MasterFunctionsHelper.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 07e2c74..681e39b 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -604,6 +604,12 @@ class MasterFunctionsHelper ->where('activity_id', '=', $keyActualM->activity_id) ->groupBy('activity_id') ->first(); + if (!isset($sumVolActual)) { + $sumVolActual = (object) [ + 'activity_id' => $keyActualM->activity_id, + 'ttl_qty_plan' => "0" + ]; + } $sumReportActual = DB::table('report_activity_material') ->where('activity_id', $keyActualM->activity_id) ->sum('qty'); @@ -623,18 +629,29 @@ class MasterFunctionsHelper ->where('activity_id', '=', $keyActualM->activity_id) ->orderBy('status_activity', 'ASC') ->first(); - $dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; + if (!isset($checkStatusActivity)) { + $checkStatusActivity = (object) [ + 'activity_id' => $keyActualM->activity_id, + 'status_activity' => 'open' + ]; + } + if ($sumVolActual->ttl_qty_plan == "0") { + $actual = 0; + } else { + $actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan; + } + $dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning; // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ if ($checkStatusActivity->status_activity == 'done') { $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; } else { - if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { - $sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100); + if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { + $sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100); // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; } else { - $sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; + $sumPercentageActual += $actual * $keyActualM->bobot_planning; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; } } From 7f9fe052e53ddcd849c9e99f907296407b3b1591 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 18 Aug 2023 16:10:39 +0700 Subject: [PATCH 085/185] Adding more range for scurve --- app/Helpers/MasterFunctionsHelper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 681e39b..eb70448 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -200,7 +200,8 @@ class MasterFunctionsHelper ->where('a.version_gantt_id', '=', $keyGantt['id']) ->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity' $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); - $end = $maxDate; + $end = new \DateTime($maxDate->format('Y-m-d') . ' Friday'); + $end->modify('next Friday'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); From 65833f14556412ea6b8a8966fe8896ddd27490d9 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 18 Aug 2023 17:12:37 +0700 Subject: [PATCH 086/185] delete report when delete overhead --- app/Models/AssignMaterial.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Models/AssignMaterial.php b/app/Models/AssignMaterial.php index 5cb8bc5..0c282a6 100644 --- a/app/Models/AssignMaterial.php +++ b/app/Models/AssignMaterial.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use App\Models\RequestMaterial; use App\Models\Activity; +use App\Models\ReportActivityMaterial; class AssignMaterial extends Model { @@ -35,6 +36,7 @@ class AssignMaterial extends Model }); static::deleted(function($data) { + $reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); $activity = Activity::where('id', $data->activity_id)->first(); $activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); $activity->save(); From 37b3eed4fb2a00cecd1a63e58fe88d8296686ba9 Mon Sep 17 00:00:00 2001 From: ibnu Date: Sun, 20 Aug 2023 14:21:49 +0700 Subject: [PATCH 087/185] update test --- app/Http/Controllers/ProjectController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 1787d88..25ca5a6 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -407,6 +407,8 @@ class ProjectController extends Controller $activity->update([ "planned_start"=>$activity->start_date, "planned_end"=>$activity->end_date, + "early_start"=>$activity->start_date, + "early_end"=>$activity->end_date, ]); } From 584e7ef8594760fa9c4991f1ab78510e4b6c3251 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 21 Aug 2023 10:41:56 +0700 Subject: [PATCH 088/185] Add column --- app/Models/UserToProyek.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/UserToProyek.php b/app/Models/UserToProyek.php index eb80c9b..bffc876 100644 --- a/app/Models/UserToProyek.php +++ b/app/Models/UserToProyek.php @@ -14,6 +14,6 @@ class UserToProyek extends Model protected $fillable = [ 'user_id', 'proyek_id', 'rbs', 'project_role', 'group_r', 'max_used', 'standart_rate', 'uom_standart_rate', 'overtime_rate', 'uom_overtime_rate', 'cost_per_used', 'accrue_at', - 'base_calender', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'base_calender', 'is_customer', 'created_at', 'created_by', 'updated_at', 'updated_by' ]; } From c75350c46681f6592ce8de7178c8df146b002ae7 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 21 Aug 2023 16:10:58 +0700 Subject: [PATCH 089/185] Fix check location for radius --- app/Http/Controllers/PresenceController.php | 36 ++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 722607c..6c40779 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -266,6 +266,20 @@ class PresenceController extends Controller if($valGeom->type == "FeatureCollection"){ $multiArea = $valGeom->features; foreach($multiArea as $area){ + if ($area->geometry->type === "Point") { + $pointCoordinates = $area->geometry->coordinates; + $pointLng = $pointCoordinates[0]; + $pointLat = $pointCoordinates[1]; + + $check = DB::select(DB::raw("SELECT ST_Distance( + ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'), + ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326) + ) <= " . $area->properties->radius . " as within_radius")); + + if ($check[0]->within_radius) { + break; + } + } $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); if($check[0]->boundary){ @@ -280,6 +294,20 @@ class PresenceController extends Controller if($valGeom->type == "FeatureCollection"){ $multiArea = $valGeom->features; foreach($multiArea as $area){ + if ($area->geometry->type === "Point") { + $pointCoordinates = $area->geometry->coordinates; + $pointLng = $pointCoordinates[0]; + $pointLat = $pointCoordinates[1]; + + $check = DB::select(DB::raw("SELECT ST_Distance( + ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'), + ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326) + ) <= " . $area->properties->radius . " as within_radius")); + + if ($check[0]->within_radius) { + break; + } + } $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); if($check[0]->boundary){ @@ -292,12 +320,18 @@ class PresenceController extends Controller } } if(count($check)>0){ - if($check[0]->boundary){ + if(isset($check[0]->boundary) && $check[0]->boundary){ $temp[]=array( "activity_id" => $dataGeom->id, "boundary" => $check[0]->boundary, "status_assign" => true ); + } else if (isset($check[0]->within_radius) && $check[0]->within_radius) { + $temp[]=array( + "activity_id" => $dataGeom->id, + "boundary" => $check[0]->within_radius, + "status_assign" => true + ); } } } From 73cf600790017bd75ac726cb57f29f271d993957 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 22 Aug 2023 09:46:08 +0700 Subject: [PATCH 090/185] Add wptime on map monitoring --- app/Http/Controllers/MapMonitoringController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index 0dda48a..3fdcef4 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -38,10 +38,14 @@ class MapMonitoringController extends Controller 'tcio.clock_in_loc', 'tcio.clock_out_loc', 'tcio.date_presence', + 'mw.lat', + 'mw.lon', + 'mw.wptime' ) ->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') + ->join('m_waypoint as mw', 'mu.id', '=', 'mw.user_id') ->where('mu.id', $key->user_id) - ->orderBy('tcio.id', 'DESC') + ->orderBy('mw.wptime', 'DESC') ->first(); $project = DB::table('assign_hr_to_proyek as ahtp') ->select('ahtp.proyek_id as id', 'mp.nama as project_name') @@ -53,6 +57,9 @@ class MapMonitoringController extends Controller $image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first(); $tmp[] = array( 'user_id' => $presensi->user_id, + 'wp_lat' => $presensi->lat, + 'wp_lon' => $presensi->lon, + 'wp_time' => $presensi->wptime, 'clock_in' => $presensi->clock_in, 'clock_out' => $presensi->clock_out, 'clock_in_lat' => $presensi->clock_in_lat, From fd0fe14ef02cf2fd0bfd4d3d53b65bf5cbfc5630 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 22 Aug 2023 10:26:58 +0700 Subject: [PATCH 091/185] Excluding customer for user assignment --- .../Controllers/HumanResourceController.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 9e47627..f71cf28 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -138,11 +138,26 @@ class HumanResourceController extends Controller } } - if($search && !empty($search)){ - $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') - ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereNotIn("m_users.id", $forbidden)->get(); - }else{ - $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereNotIn("m_users.id", $forbidden)->get(); + if ($search && !empty($search)) { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") + ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->where("assign_hr_to_proyek.proyek_id", $idProyek) + ->where(function ($query) { + $query->where("assign_hr_to_proyek.is_customer", "!=", true) + ->orWhereNull("assign_hr_to_proyek.is_customer"); + }) + ->where("m_users.name", 'like', '%' . $search . '%') + ->whereNotIn("m_users.id", $forbidden)->get(); + } else { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") + ->where("assign_hr_to_proyek.proyek_id", $idProyek) + ->where(function ($query) { + $query->where("assign_hr_to_proyek.is_customer", "!=", true) + ->orWhereNull("assign_hr_to_proyek.is_customer"); + }) + ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->whereNotIn("m_users.id", $forbidden) + ->get(); } return response()->json($data); From 80b186e2243555ecfe5a812ca3af7db97ce79d6d Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 22 Aug 2023 20:45:08 +0700 Subject: [PATCH 092/185] update early and actual --- app/Http/Controllers/ActivityController.php | 32 +++++++++++++++++++++ app/Http/Controllers/ProjectController.php | 7 +++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 5158b05..12293ed 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -47,6 +47,10 @@ class ActivityController extends Controller $dataHeader->progress = $dataHeader->persentase_progress / 100; $dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start), "Y-m-d H:i:s") : NULL; $dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL; + + $dataHeader->actual_start = isset($dataHeader->actual_start) ? date_format(date_create($dataHeader->actual_start), "Y-m-d") : NULL; + $dataHeader->actual_end = isset($dataHeader->actual_end) ? date_format(date_create($dataHeader->actual_end), "Y-m-d") : NULL; + $dataHeader->type = "header"; $dataHeader->text = $dataHeader->name; $finalData[] = $dataHeader; @@ -72,6 +76,10 @@ class ActivityController extends Controller $objRow->end_date = date_format($endDate, "Y-m-d H:i:s"); $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL; + + $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; + $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; + $objRow->progress = $objRow->persentase_progress / 100; $objRow->type = $type; $finalData[] = $objRow; @@ -115,6 +123,30 @@ class ActivityController extends Controller $objRow->end_date = date_format($endDate, "Y-m-d H:i:s"); $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL; + + // $linking = Link::where('t_activity_id', $objRow->id)->first(); + // if(isset($linking->s_activity_id)){ + // $activityLink = Activity::where('id', $linking->s_activity_id)->first(); + // $earlyStart=date_create($activityLink->end_date); + // date_add($earlyStart,date_interval_create_from_date_string("1 days")); + // $objRow->early_start = date_format($earlyStart, "Y-m-d"); + // }else{ + // $objRow->early_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d") : NULL; + // } + + // if(isset($objRow->planned_end)){ + // $baseStart = strtotime($objRow->planned_start); + // $baseFinish = strtotime($objRow->planned_end); + // $durationStrtotime = $baseFinish - $baseStart; + + // $durasiBaseline = round($durationStrtotime / (60 * 60 * 24)); + // $earlyEnd = date_create($objRow->start_date); + // date_add($earlyEnd,date_interval_create_from_date_string("".$durasiBaseline." days")); + // $objRow->early_end = date_format($earlyEnd, "Y-m-d"); + // } + $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; + $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; + $dataChildren = $this->getChildren($gantt_id, $objRow->id); if ($objRow->type_activity == "milestone") { $objRow->type = $objRow->type_activity; diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 25ca5a6..b8fc761 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -390,9 +390,12 @@ class ProjectController extends Controller } if($reports[$i]['status'] != 'done'){ $reports[$i]['max_date']->modify('-1 day'); + }else if($reports[$i]['status'] == 'done'){ + $activity->actual_end = $reports[$i]['max_date']->setTime(23,59,59); } - $activity->start_date = $reports[$i]['min_date']; - $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); + $activity->start_date = $reports[$i]['min_date']; //same early + $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early + $activity->actual_start = $reports[$i]['min_date']; $activity->save(); } From e0785ced109cf49afd1ae23b97f61a6782ebf793 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 22 Aug 2023 20:47:59 +0700 Subject: [PATCH 093/185] update early and actual update logic 22 Aug --- app/Http/Controllers/ActivityController.php | 20 -------------------- app/Models/Activity.php | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index ad931e9..c95c3f2 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -124,26 +124,6 @@ class ActivityController extends Controller $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL; - // $linking = Link::where('t_activity_id', $objRow->id)->first(); - // if(isset($linking->s_activity_id)){ - // $activityLink = Activity::where('id', $linking->s_activity_id)->first(); - // $earlyStart=date_create($activityLink->end_date); - // date_add($earlyStart,date_interval_create_from_date_string("1 days")); - // $objRow->early_start = date_format($earlyStart, "Y-m-d"); - // }else{ - // $objRow->early_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d") : NULL; - // } - - // if(isset($objRow->planned_end)){ - // $baseStart = strtotime($objRow->planned_start); - // $baseFinish = strtotime($objRow->planned_end); - // $durationStrtotime = $baseFinish - $baseStart; - - // $durasiBaseline = round($durationStrtotime / (60 * 60 * 24)); - // $earlyEnd = date_create($objRow->start_date); - // date_add($earlyEnd,date_interval_create_from_date_string("".$durasiBaseline." days")); - // $objRow->early_end = date_format($earlyEnd, "Y-m-d"); - // } $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; diff --git a/app/Models/Activity.php b/app/Models/Activity.php index eefcea4..3d09785 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -25,7 +25,7 @@ class Activity extends Model 'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan', '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', + 'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end', 'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder' ]; From 98174773f2569df998581aa48a9ffd931a435431 Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 23 Aug 2023 10:41:42 +0700 Subject: [PATCH 094/185] update logic early recursive activity from start and end --- app/Http/Controllers/ActivityController.php | 51 +++++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index c95c3f2..401837e 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -48,9 +48,11 @@ class ActivityController extends Controller $dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start), "Y-m-d H:i:s") : NULL; $dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL; - $dataHeader->actual_start = isset($dataHeader->actual_start) ? date_format(date_create($dataHeader->actual_start), "Y-m-d") : NULL; - $dataHeader->actual_end = isset($dataHeader->actual_end) ? date_format(date_create($dataHeader->actual_end), "Y-m-d") : NULL; - + $actualStart = $this->getActivityFirst($dataHeader->id); + $dataHeader->actual_start = date_format(date_create($actualStart), "Y-m-d"); + $actualEnd = $this->getActivityLast($dataHeader->id); + $dataHeader->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; + $dataHeader->type = "header"; $dataHeader->text = $dataHeader->name; $finalData[] = $dataHeader; @@ -76,9 +78,11 @@ class ActivityController extends Controller $objRow->end_date = date_format($endDate, "Y-m-d H:i:s"); $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL; - - $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; - $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; + + $actualStart = $this->getActivityFirst($objRow->id); + $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; + $actualEnd = $this->getActivityLast($objRow->id); + $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; $objRow->progress = $objRow->persentase_progress / 100; $objRow->type = $type; @@ -123,17 +127,22 @@ class ActivityController extends Controller $objRow->end_date = date_format($endDate, "Y-m-d H:i:s"); $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL; - - $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; - $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; - + $dataChildren = $this->getChildren($gantt_id, $objRow->id); if ($objRow->type_activity == "milestone") { $objRow->type = $objRow->type_activity; + $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; } elseif (empty($dataChildren)) { $objRow->type = "task"; + $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; + $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; } else { $objRow->type = "project"; + $actualStart = $this->getActivityFirst($objRow->id); + $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; + + $actualEnd = $this->getActivityLast($objRow->id); + $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; } $finalData[] = $objRow; $finalData = array_merge($finalData, $dataChildren); @@ -141,6 +150,28 @@ class ActivityController extends Controller return $finalData; } + public function getActivityFirst($parentId){ + $activity = Activity::where('parent_id', $parentId)->orderByRaw('start_date ASC')->first(); + if($activity->type_activity == "task"){ + // Log::info("activity ", [$activity]); + return $activity->actual_start; + }else{ + return $this->getActivityFirst($activity->id); + } + + } + + public function getActivityLast($parentId){ + $activity = Activity::where('parent_id', $parentId)->orderByRaw('start_date DESC')->first(); + if($activity->type_activity == "task"){ + // Log::info("activity ", [$activity]); + return $activity->actual_end; + }else{ + return $this->getActivityLast($activity->id); + } + + } + private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) { $project = Project::find($proyek_id); From 199d34fdd4a31386f10e7f598e862e3302a34f74 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 23 Aug 2023 14:50:26 +0700 Subject: [PATCH 095/185] Fix work area restriction --- app/Http/Controllers/PresenceController.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 6c40779..ad0501c 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\HumanResource; use Log; use Illuminate\Http\Request; use App\Models\Presence; @@ -24,7 +25,10 @@ class PresenceController extends Controller if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ $statusBoundary = true; } - + $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); + if ($statusRestriction->status_boundary) { + $statusBoundary = true; + } // not assign if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ $data=array( @@ -134,7 +138,10 @@ class PresenceController extends Controller if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ $statusBoundary = true; } - + $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); + if ($statusRestriction->status_boundary) { + $statusBoundary = true; + } // not assign if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ $data=array( From e8c8961bd5d2e2c5675c532f75600f339c2e3299 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 23 Aug 2023 18:11:45 +0700 Subject: [PATCH 096/185] add endpoint project-by-customer/{id} --- app/Http/Controllers/ProjectController.php | 991 +++++++++++---------- app/Models/UserToProyek.php | 38 +- routes/web.php | 908 +++++++++---------- 3 files changed, 994 insertions(+), 943 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 6e8ca66..e558e78 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -36,237 +36,252 @@ const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json& class ProjectController extends Controller { - public function add(Request $request) - { - $this->validate($request, [ - 'nama' => 'required', - 'mulai_proyek' => 'required', - 'akhir_proyek' => 'required', - 'rencana_biaya' => 'required', - 'type_proyek_id' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - if(empty($data['phase_id'])) - $data['phase_id'] = 1; - - $result = Project::create($data); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); - - $this->createOfficeHours($result->id); - $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); - - return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); - } - - public function edit($id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $result = Project::find($id); - - if(!$result) - 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','message'=>'id is required!','code'=>400], 400); - - $data = Project::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $result = $data->update($request->all()); - - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); - } - - private function createOfficeHours($proyek_id) - { - $dataCreate = array( - "proyek_id"=>$proyek_id, - "monday_start"=> "08:00:00", - "monday_end"=> "16:00:00", - "tuesday_start"=> "08:00:00", - "tuesday_end"=> "16:00:00", - "wednesday_start"=> "08:00:00", - "wednesday_end"=> "16:00:00", - "thursday_start"=> "08:00:00", - "thursday_end"=> "16:00:00", - "friday_start"=> "08:00:00", - "friday_end"=> "16:00:00", - "saturday_start"=> "08:00:00", - "saturday_end"=> "16:00:00", - "sunday_start"=> "08:00:00", - "sunday_end"=> "16:00:00", - "created_by"=> $this->currentName - ); - - OfficeHours::create($dataCreate); - - return true; - } - - public function delete($id) - { - $data = Project::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - $this->deleteRelative($id); - - if(!$data->delete()) - return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); - } - - private function deleteRelative($project_id) - { - UserToProyek::where('proyek_id', $project_id)->delete(); - UserToActivity::where('proyek_id', $project_id)->delete(); - AssignMaterial::where('proyek_id', $project_id)->delete(); - ProjectCharter::where('proyek_id', $project_id)->delete(); - ProjectApproval::where('proyek_id', $project_id)->delete(); - ProjectMileStone::where('proyek_id', $project_id)->delete(); - ProjectParticipants::where('proyek_id', $project_id)->delete(); - $this->deleteVersionGantt($project_id); - $this->deleteDokumenProject($project_id); - } - - private function deleteVersionGantt($project_id) - { - $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); - $vhIds = $dataVg->all(); - $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); - $activityIds = $activity->all(); - $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); - foreach ($dataRa as $ra) { - $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); - foreach ($images as $image) { - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); - } - } - Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); - } - $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); - foreach ($dataAd as $ad) { - if(file_exists($this->pathActivityDocument.$ad->file)){ - unlink($this->pathActivityDocument.$ad->file); - } - } - ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); - CommentActivity::whereIn("activity_id", $activityIds)->delete(); - Holiday::where("proyek_id", $project_id)->delete(); - VersionGantt::where("proyek_id", $project_id)->delete(); - Link::whereIn("version_gantt_id", $vhIds)->delete(); - ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); - Activity::whereIn("version_gantt_id", $vhIds)->delete(); - ReportActivity::whereIn("activity_id", $activityIds)->delete(); - } - - private function deleteDokumenProject($project_id) - { - $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); - - foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); - } - } - DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); - - $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); - $ref_ids = $dataFolder->all(); - $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); - foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); - } - } - - DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); - } - - public function search(Request $request) - { - $payload = $request->all(); - - $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); - $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 list() - { - $data = Project::orderBy('id', 'desc')->get(); - $countData = $data->count(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - $scheduleWarningThreshold = 10; - $scheduleDangerThreshold = 5; - foreach($data as $d){ - $progress = $costVariance = $actualCost = 0; - $lastActivity = null; - $scheduleHealth = "on-track"; - $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); - if($rootActivity){ - $costVariance = (int)$d->rencana_biaya - (int)$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)); - } - $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->costVariance = $costVariance; - $d->costHealth = $d->budget_health; - $d->scheduleHealth = $scheduleHealth; - $d->progress = $progress; - $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; - $d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; + public function add(Request $request) + { + $this->validate($request, [ + 'nama' => 'required', + 'mulai_proyek' => 'required', + 'akhir_proyek' => 'required', + 'rencana_biaya' => 'required', + 'type_proyek_id' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + if (empty($data['phase_id'])) + $data['phase_id'] = 1; + + $result = Project::create($data); + + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500); + + $this->createOfficeHours($result->id); + $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); + + return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200); + } + + public function edit($id) + { + if (empty($id) || !is_int((int)$id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $result = Project::find($id); + + if (!$result) + 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', 'message' => 'id is required!', 'code' => 400], 400); + + $data = Project::find($id); + + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + + $result = $data->update($request->all()); + + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500); + + return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200); + } + + private function createOfficeHours($proyek_id) + { + $dataCreate = array( + "proyek_id" => $proyek_id, + "monday_start" => "08:00:00", + "monday_end" => "16:00:00", + "tuesday_start" => "08:00:00", + "tuesday_end" => "16:00:00", + "wednesday_start" => "08:00:00", + "wednesday_end" => "16:00:00", + "thursday_start" => "08:00:00", + "thursday_end" => "16:00:00", + "friday_start" => "08:00:00", + "friday_end" => "16:00:00", + "saturday_start" => "08:00:00", + "saturday_end" => "16:00:00", + "sunday_start" => "08:00:00", + "sunday_end" => "16:00:00", + "created_by" => $this->currentName + ); + + OfficeHours::create($dataCreate); + + return true; + } + + public function delete($id) + { + $data = Project::find($id); + + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + + $this->deleteRelative($id); + + if (!$data->delete()) + return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500); + + return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); + } + + private function deleteRelative($project_id) + { + UserToProyek::where('proyek_id', $project_id)->delete(); + UserToActivity::where('proyek_id', $project_id)->delete(); + AssignMaterial::where('proyek_id', $project_id)->delete(); + ProjectCharter::where('proyek_id', $project_id)->delete(); + ProjectApproval::where('proyek_id', $project_id)->delete(); + ProjectMileStone::where('proyek_id', $project_id)->delete(); + ProjectParticipants::where('proyek_id', $project_id)->delete(); + $this->deleteVersionGantt($project_id); + $this->deleteDokumenProject($project_id); + } + + private function deleteVersionGantt($project_id) + { + $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); + $vhIds = $dataVg->all(); + $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); + $activityIds = $activity->all(); + $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); + foreach ($dataRa as $ra) { + $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); + foreach ($images as $image) { + if (file_exists($this->pathImage . $image->image)) { + unlink($this->pathImage . $image->image); + } + } + Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); + } + $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); + foreach ($dataAd as $ad) { + if (file_exists($this->pathActivityDocument . $ad->file)) { + unlink($this->pathActivityDocument . $ad->file); + } + } + ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); + CommentActivity::whereIn("activity_id", $activityIds)->delete(); + Holiday::where("proyek_id", $project_id)->delete(); + VersionGantt::where("proyek_id", $project_id)->delete(); + Link::whereIn("version_gantt_id", $vhIds)->delete(); + ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); + Activity::whereIn("version_gantt_id", $vhIds)->delete(); + ReportActivity::whereIn("activity_id", $activityIds)->delete(); + } + + private function deleteDokumenProject($project_id) + { + $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); + + foreach ($dataDokumen as $dokumen) { + if (file_exists($this->pathDocument . $dokumen->file)) { + unlink($this->pathDocument . $dokumen->file); + } + } + DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); + + $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); + $ref_ids = $dataFolder->all(); + $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); + foreach ($dataDokumen as $dokumen) { + if (file_exists($this->pathDocument . $dokumen->file)) { + unlink($this->pathDocument . $dokumen->file); + } + } + + DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); + } + + public function getByUser($id) + { + $result = UserToProyek::query() + ->where([ + ['user_id', $id], + ['is_customer', true] + ])->get(); + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Get User Project Not Found!', 'code' => 404], 404); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); + $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 list() + { + $data = Project::orderBy('id', 'desc')->get(); + $countData = $data->count(); + + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + + $scheduleWarningThreshold = 10; + $scheduleDangerThreshold = 5; + foreach ($data as $d) { + $progress = $costVariance = $actualCost = 0; + $lastActivity = null; + $scheduleHealth = "on-track"; + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); + if ($rootActivity) { + $costVariance = (int)$d->rencana_biaya - (int)$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)); + } + $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->costVariance = $costVariance; + $d->costHealth = $d->budget_health; + $d->scheduleHealth = $scheduleHealth; + $d->progress = $progress; + $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; + $d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; $d->projectManager = DB::table('m_proyek') - ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') - ->where('m_proyek.id', $d->id) - ->pluck('m_users.name') - ->first(); - if($d->area_kerja != ''){ + ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') + ->where('m_proyek.id', $d->id) + ->pluck('m_users.name') + ->first(); + if ($d->area_kerja != '') { $d->geolocation = $this->httpReq($d->area_kerja); - $d->geolocation = []; + $d->geolocation = []; } else { $d->geolocation = []; } @@ -274,268 +289,304 @@ class ProjectController extends Controller $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); $totalActualCost = $data->sum('actualCost'); - $manpowers = User::count(); - $projectsOnDanger = Project::where('budget_health', 'overrun')->count(); + $manpowers = User::count(); + $projectsOnDanger = Project::where('budget_health', 'overrun')->count(); $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); $projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); try { $projectsByPhase = DB::table('m_proyek') - ->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) - ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') - ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') - ->get(); + ->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) + ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') + ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') + ->get(); } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()]); } try { $projectsByType = DB::table('m_proyek') - ->select('m_type_proyek.name', DB::raw('count(*) as total')) - ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') - ->groupBy('m_type_proyek.name') - ->get(); + ->select('m_type_proyek.name', DB::raw('count(*) as total')) + ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') + ->groupBy('m_type_proyek.name') + ->get(); } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()]); } - return response()->json( - [ - 'status'=>'success', - 'code'=>200, - 'data'=>$data, - 'totalRecord'=>$countData, - 'totalPlannedCost' => $totalPlannedCost, - 'totalActualCost' => $totalActualCost, - 'totalRevenue' => $totalPlannedCost - $totalActualCost, - 'manpowers' => $manpowers, - 'projectsOnDanger'=> $projectsOnDanger, - 'projectPhases' => $projectPhases, - 'projectsByPhase' => $projectsByPhase, - 'projectTypes' => $projectTypes, - 'projectsByType' => $projectsByType, - ], 200); - } - - public function getListProjectTask($id){ - $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") - ->where("assign_hr_to_activity.user_id", $id) - ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') - ->groupBy("m_proyek.proyek_id") - ->get(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); - } - - public function getSCurve(Request $request){ - $data = MasterFunctionsHelper::getSCurve($request); - return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); - } - - public function calculateSCurve(Request $request){ - $sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); - return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200); - } - - public function sCurveCommand(Request $request){ - Artisan::call('calculate:scurve', [ - 'project_id' => $request->project_id - ]); - } - - public function getLinearSCurve(Request $request){ - $data = MasterFunctionsHelper::getLinearSCurve($request); - return response()->json(['status'=>'success','code'=>200, 'data' => $data], 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 = ReportActivityMaterial::where('activity_id', $activity_id)->count(); - if ($countReports === 1) { - $dataReports = ReportActivityMaterial::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 = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); - $lastReport = ReportActivityMaterial::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") - ); - } - $activity->reports = $reports; - } - /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ - /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ - - 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); - } - - 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 getInvoiceIntegration(Request $request) { - // $search = urlencode($request->search); - // if(empty($search)) - // return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); - // $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); - - $response = null; - - // return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); - return response()->json(['status'=>'success', 'data'=> '', 'code'=>200], 200); - } - - public function detail($id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $result = Project::find($id); - - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $gantt = MasterFunctionsHelper::getLatestGantt($id); - $result->projectManager = User::where('id', $result->pm_id)->value('name'); - $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first(); - return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); - } - - public function getOverdueActivities(Request $request){ - $payload = $request->all(); - if(empty($payload['id']) || !is_int((int)$payload['id'])) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $result = Project::find($payload['id']); - - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); - //TODO possible overdue bug - if(isset($payload['till_date'])) - $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); - else - $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); - - $result->overdueActivities = $overdueActivities; - - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); - } - - public function getReportDistribution(Request $request){ - $payload = $request->all(); - - if(empty($payload['project_id']) || !is_int((int)$payload['project_id'])) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $reports = DB::table('assign_material_to_activity as ama') - ->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit', - 'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date') - ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id') - ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id') - ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - ->join('m_users as u', 'u.id', '=', 'ram.user_id') - ->where('ama.proyek_id', '=', $payload['project_id']) - ->whereNotNull('ram.lat') - ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); - - return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200); - } - - public function getManpower($proyek_id){ - $manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); - return response()->json(['totalRecord'=>$manCount]); - } - - public function getAssignedHR($gantt_id){ - $results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date') - ->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id') - ->where('assign_hr_to_activity.version_gantt_id', $gantt_id) - ->get(); - return response()->json(['data'=>$results]); - } - - public function dashboard($id) - { - $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', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') - ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') - ->where('mp.id', $id) - ->first(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404); - - $manpowers = UserToProyek::where('proyek_id', $id)->count(); - $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); - - $actualCost = @$rootActivity->biaya_actual ?? 0; - $progress = @$rootActivity->persentase_progress ?? 0; - - $commentActivity = DB::table('m_comment_activity as mca') - ->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created', - 'ma.name as activity') - ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') - ->where('ma.proyek_id', $id) - ->orderBy('comment_by') - ->take(2) - ->get(); - - $data->actual_cost = $actualCost; - $data->progress = $progress; - $data->comment = $commentActivity; - $data->man_power = $manpowers; - - return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200); - } - - private function httpReq($search){ - $ch = curl_init(); + return response()->json( + [ + 'status' => 'success', + 'code' => 200, + 'data' => $data, + 'totalRecord' => $countData, + 'totalPlannedCost' => $totalPlannedCost, + 'totalActualCost' => $totalActualCost, + 'totalRevenue' => $totalPlannedCost - $totalActualCost, + 'manpowers' => $manpowers, + 'projectsOnDanger' => $projectsOnDanger, + 'projectPhases' => $projectPhases, + 'projectsByPhase' => $projectsByPhase, + 'projectTypes' => $projectTypes, + 'projectsByType' => $projectsByType, + ], + 200 + ); + } + + public function getListProjectTask($id) + { + $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*") + ->where("assign_hr_to_activity.user_id", $id) + ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') + ->groupBy("m_proyek.proyek_id") + ->get(); + + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } + + public function getSCurve(Request $request) + { + $data = MasterFunctionsHelper::getSCurve($request); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } + + public function calculateSCurve(Request $request) + { + $sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200); + } + + public function sCurveCommand(Request $request) + { + Artisan::call('calculate:scurve', [ + 'project_id' => $request->project_id + ]); + } + + public function getLinearSCurve(Request $request) + { + $data = MasterFunctionsHelper::getLinearSCurve($request); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 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 = ReportActivityMaterial::where('activity_id', $activity_id)->count(); + if ($countReports === 1) { + $dataReports = ReportActivityMaterial::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 = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); + $lastReport = ReportActivityMaterial::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") + ); + } + $activity->reports = $reports; + } + /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ + /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ + + 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); + } + + 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 getInvoiceIntegration(Request $request) + { + // $search = urlencode($request->search); + // if(empty($search)) + // return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); + // $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); + + $response = null; + + // return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); + return response()->json(['status' => 'success', 'data' => '', 'code' => 200], 200); + } + + public function detail($id) + { + if (empty($id) || !is_int((int)$id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $result = Project::find($id); + + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + + $gantt = MasterFunctionsHelper::getLatestGantt($id); + $result->projectManager = User::where('id', $result->pm_id)->value('name'); + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $gantt], 200); + } + + public function getOverdueActivities(Request $request) + { + $payload = $request->all(); + if (empty($payload['id']) || !is_int((int)$payload['id'])) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $result = Project::find($payload['id']); + + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Project not found!', 'code' => 404], 404); + //TODO possible overdue bug + if (isset($payload['till_date'])) + $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $payload['till_date'])->orderBy('end_date', 'asc')->get(); + else + $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); + + $result->overdueActivities = $overdueActivities; + + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } + + public function getReportDistribution(Request $request) + { + $payload = $request->all(); + + if (empty($payload['project_id']) || !is_int((int)$payload['project_id'])) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $reports = DB::table('assign_material_to_activity as ama') + ->select( + 'u.name', + 'a.name as activity_name', + 'ama.qty_planning', + 'ram.qty as qty_real', + 'rm.description as material_name', + 'rm.uom as material_unit', + 'ram.lat', + 'ram.lon', + 'ram.description as report_notes', + 'ram.report_date' + ) + ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id') + ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id') + ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + ->join('m_users as u', 'u.id', '=', 'ram.user_id') + ->where('ama.proyek_id', '=', $payload['project_id']) + ->whereNotNull('ram.lat') + ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); + + return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200); + } + + public function getManpower($proyek_id) + { + $manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); + return response()->json(['totalRecord' => $manCount]); + } + + public function getAssignedHR($gantt_id) + { + $results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date') + ->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id') + ->where('assign_hr_to_activity.version_gantt_id', $gantt_id) + ->get(); + return response()->json(['data' => $results]); + } + + public function dashboard($id) + { + $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', + 'mp.currency_symbol', + 'mu.name as pm', + 'mp.budget_health' + ) + ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') + ->where('mp.id', $id) + ->first(); + + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data tidak ditemukan!', 'code' => 404], 404); + + $manpowers = UserToProyek::where('proyek_id', $id)->count(); + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); + + $actualCost = @$rootActivity->biaya_actual ?? 0; + $progress = @$rootActivity->persentase_progress ?? 0; + + $commentActivity = DB::table('m_comment_activity as mca') + ->select( + 'mca.activity_id', + 'mca.comment as comment', + 'mca.created_by as comment_by', + 'mca.created_at as comment_created', + 'ma.name as activity' + ) + ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') + ->where('ma.proyek_id', $id) + ->orderBy('comment_by') + ->take(2) + ->get(); + + $data->actual_cost = $actualCost; + $data->progress = $progress; + $data->comment = $commentActivity; + $data->man_power = $manpowers; + + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } + + private function httpReq($search) + { + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_VERBOSE, true); - curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); + curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); - $info = curl_getinfo($ch); + $info = curl_getinfo($ch); $output = curl_exec($ch); curl_close($ch); return json_decode($output); - } - + } } - diff --git a/app/Models/UserToProyek.php b/app/Models/UserToProyek.php index eb80c9b..ef83af1 100644 --- a/app/Models/UserToProyek.php +++ b/app/Models/UserToProyek.php @@ -1,19 +1,19 @@ -get('/', function () use ($router) { - return $router->app->version(); + return $router->app->version(); }); -$router->group(['prefix'=>'api', 'middleware' => 'cors'], 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->get('/dashboard/get-company-cashflow[/{year}]', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure - $router->get('/dashboard/get-invoice-outstanding[/{year}]', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in - $router->get('/dashboard/get-total-project-per-schedule-health[/{year}]', 'DashboardBoDController@getTotalProjectPerScheduleHealth'); - $router->get('/dashboard/get-total-project-per-budget-health[/{year}]', 'DashboardBoDController@getTotalProjectPerBudgetHealth'); - $router->get('/dashboard/get-total-project-schedule-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision'); - $router->get('/dashboard/get-total-project-budget-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision'); - $router->get('/dashboard/get-total-project-per-phase[/{year}]', 'DashboardBoDController@getTotalProjectPerPhase'); - $router->get('/dashboard/get-total-project-per-division[/{year}]', 'DashboardBoDController@getTotalProjectPerDivision'); - $router->get('/dashboard/get-total-project-value-per-division[/{year}]', 'DashboardBoDController@getTotalProjectValuePerDivision'); - $router->get('/dashboard/get-detail-expenditure[/{year}]', 'DashboardBoDController@getDetailExpenditure'); - - $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->get('/project/detail/{id}', 'ProjectController@detail'); - $router->delete('/project/delete/{id}', 'ProjectController@delete'); - $router->get('/project/list', 'ProjectController@list'); - $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline'); - $router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport'); - $router->get('/project/manpower/{proyek_id}', 'ProjectController@getManpower'); - $router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR'); - - $router->post('/project/get-s-curve', 'ProjectController@getSCurve'); - $router->post('/project/calculate-s-curve', 'ProjectController@calculateSCurve'); - $router->post('/project/s-curve-command', 'ProjectController@sCurveCommand'); - $router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve'); - $router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities'); - $router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration'); - $router->post('/project/get-report-distribution', 'ProjectController@getReportDistribution'); - - /* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */ - /* $router->get('/project/get-total-expenditure/{id}', 'ProjectController@getTotalExpenditure'); */ - /* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */ - /* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */ - - - $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->get('/human-resource/sync', 'HumanResourceController@sync'); - - $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('/project-phase/search', 'ProjectPhaseController@search'); - $router->post('/project-phase/add', 'ProjectPhaseController@add'); - $router->get('/project-phase/edit/{id}', 'ProjectPhaseController@edit'); - $router->put('/project-phase/update/{id}', 'ProjectPhaseController@update'); - $router->delete('/project-phase/delete/{id}', 'ProjectPhaseController@delete'); - $router->get('/project-phase/list', 'ProjectPhaseController@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->get('/request-material/get-material-integration', 'RequestMaterialController@getMaterialIntegration'); - - $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->post('/user-to-activity/list-filtered', 'UserToActivityController@listFiltered'); - $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('/activity/import', 'ActivityController@import'); - $router->post('/activity/import-update', 'ActivityController@importUpdate'); - $router->post('/activity/import-old', 'ActivityController@importOld'); - $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('/tmp-import/upload', 'ActivityController@uploadTmpImport'); - - $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->post('/presence/reportk3', 'PresenceController@reportK3'); - $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('/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->post('/waypoint/add', 'WaypointController@add'); - $router->post('/waypoint/add-bulk', 'WaypointController@addBulk'); - $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->get('/user-to-proyek/get-employee-integration', 'UserToProyekController@getEmployeeIntegration'); - - $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->get('/gantt-show-hide/get-column-by-type/{type}', 'ShowHideColumnController@getColumnByType'); - - - $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'); - - $router->post('/project-comment/add', 'ProjectCommentController@add'); - $router->put('/project-comment/update/{id}', 'ProjectCommentController@update'); - $router->post('/project-comment/search', 'ProjectCommentController@search'); - - $router->get('/hierarchy-ftths', 'HierarchyFtthController@index'); - $router->post('/hierarchy-ftths', 'HierarchyFtthController@store'); - $router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search'); - $router->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show'); - $router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update'); - $router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy'); - $router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject'); - $router->get('/hierarchy-ftths/tree-gantt/{gantt_id}', 'HierarchyFtthController@getTreeByGantt'); - - $router->post('/map-monitoring/search', 'MapMonitoringController@search'); - }); - +$router->group(['prefix' => 'api', 'middleware' => 'cors'], 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->get('/dashboard/get-company-cashflow[/{year}]', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure + $router->get('/dashboard/get-invoice-outstanding[/{year}]', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in + $router->get('/dashboard/get-total-project-per-schedule-health[/{year}]', 'DashboardBoDController@getTotalProjectPerScheduleHealth'); + $router->get('/dashboard/get-total-project-per-budget-health[/{year}]', 'DashboardBoDController@getTotalProjectPerBudgetHealth'); + $router->get('/dashboard/get-total-project-schedule-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision'); + $router->get('/dashboard/get-total-project-budget-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision'); + $router->get('/dashboard/get-total-project-per-phase[/{year}]', 'DashboardBoDController@getTotalProjectPerPhase'); + $router->get('/dashboard/get-total-project-per-division[/{year}]', 'DashboardBoDController@getTotalProjectPerDivision'); + $router->get('/dashboard/get-total-project-value-per-division[/{year}]', 'DashboardBoDController@getTotalProjectValuePerDivision'); + $router->get('/dashboard/get-detail-expenditure[/{year}]', 'DashboardBoDController@getDetailExpenditure'); + + $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->get('/project-by-customer/{id}', 'ProjectController@getByUser'); + $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->get('/project/detail/{id}', 'ProjectController@detail'); + $router->delete('/project/delete/{id}', 'ProjectController@delete'); + $router->get('/project/list', 'ProjectController@list'); + $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline'); + $router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport'); + $router->get('/project/manpower/{proyek_id}', 'ProjectController@getManpower'); + $router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR'); + + $router->post('/project/get-s-curve', 'ProjectController@getSCurve'); + $router->post('/project/calculate-s-curve', 'ProjectController@calculateSCurve'); + $router->post('/project/s-curve-command', 'ProjectController@sCurveCommand'); + $router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve'); + $router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities'); + $router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration'); + $router->post('/project/get-report-distribution', 'ProjectController@getReportDistribution'); + + /* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */ + /* $router->get('/project/get-total-expenditure/{id}', 'ProjectController@getTotalExpenditure'); */ + /* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */ + /* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */ + + + $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->get('/human-resource/sync', 'HumanResourceController@sync'); + + $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('/project-phase/search', 'ProjectPhaseController@search'); + $router->post('/project-phase/add', 'ProjectPhaseController@add'); + $router->get('/project-phase/edit/{id}', 'ProjectPhaseController@edit'); + $router->put('/project-phase/update/{id}', 'ProjectPhaseController@update'); + $router->delete('/project-phase/delete/{id}', 'ProjectPhaseController@delete'); + $router->get('/project-phase/list', 'ProjectPhaseController@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->get('/request-material/get-material-integration', 'RequestMaterialController@getMaterialIntegration'); + + $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->post('/user-to-activity/list-filtered', 'UserToActivityController@listFiltered'); + $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('/activity/import', 'ActivityController@import'); + $router->post('/activity/import-update', 'ActivityController@importUpdate'); + $router->post('/activity/import-old', 'ActivityController@importOld'); + $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('/tmp-import/upload', 'ActivityController@uploadTmpImport'); + + $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->post('/presence/reportk3', 'PresenceController@reportK3'); + $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('/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->post('/waypoint/add', 'WaypointController@add'); + $router->post('/waypoint/add-bulk', 'WaypointController@addBulk'); + $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->get('/user-to-proyek/get-employee-integration', 'UserToProyekController@getEmployeeIntegration'); + + $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->get('/gantt-show-hide/get-column-by-type/{type}', 'ShowHideColumnController@getColumnByType'); + + + $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'); + + $router->post('/project-comment/add', 'ProjectCommentController@add'); + $router->put('/project-comment/update/{id}', 'ProjectCommentController@update'); + $router->post('/project-comment/search', 'ProjectCommentController@search'); + + $router->get('/hierarchy-ftths', 'HierarchyFtthController@index'); + $router->post('/hierarchy-ftths', 'HierarchyFtthController@store'); + $router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search'); + $router->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show'); + $router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update'); + $router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy'); + $router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject'); + $router->get('/hierarchy-ftths/tree-gantt/{gantt_id}', 'HierarchyFtthController@getTreeByGantt'); + + $router->post('/map-monitoring/search', 'MapMonitoringController@search'); + }); }); From b1a6ee123116e23ccedefcc2c663ea42e790c61b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 24 Aug 2023 12:19:16 +0700 Subject: [PATCH 097/185] Enable integration --- .../Commands/syncHumanResourceIntegration.php | 6 ++--- .../Controllers/DashboardBoDController.php | 22 +++++++++---------- app/Http/Controllers/ProjectController.php | 10 ++++----- .../Controllers/RequestMaterialController.php | 2 +- .../Controllers/UserToProyekController.php | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/Console/Commands/syncHumanResourceIntegration.php b/app/Console/Commands/syncHumanResourceIntegration.php index 6120999..7b4ef5f 100644 --- a/app/Console/Commands/syncHumanResourceIntegration.php +++ b/app/Console/Commands/syncHumanResourceIntegration.php @@ -39,9 +39,9 @@ class syncHumanResourceIntegration extends Command */ public function handle() { - // $url = config('api.adw').'/employees?page=1'; - // echo "Requesting to " . $url; - $response = null; + $url = config('api.adw').'/employees?page=1'; + echo "Requesting to " . $url; + $response = MasterFunctionsHelper::curlReq($url); if(!$response) return; diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 8d437b1..22a53c7 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -41,17 +41,17 @@ class DashboardBoDController extends Controller private function getInvoiceIntegration($search) { - // if(empty($search)) - // return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); - // - // $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); - // $token = config('api.adw_token'); - // $response = $this->curlReq($url, $token); - // - // if(@$response->data->project_no == "") - // return null; - // - return null; + if(empty($search)) + return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); + + $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); + $token = config('api.adw_token'); + $response = $this->curlReq($url, $token); + + if(@$response->data->project_no == "") + return null; + + return $response; } // to do diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 68f8165..3d22495 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -422,12 +422,12 @@ class ProjectController extends Controller } public function getInvoiceIntegration(Request $request) { - // $search = urlencode($request->search); - // if(empty($search)) - // return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); - // $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); + $search = urlencode($request->search); + if(empty($search)) + return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); + $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); - $response = null; + $response = MasterFunctionsHelper::curlReq($url); // return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); return response()->json(['status'=>'success', 'data'=> '', 'code'=>200], 200); diff --git a/app/Http/Controllers/RequestMaterialController.php b/app/Http/Controllers/RequestMaterialController.php index 35cb76d..605cf5f 100644 --- a/app/Http/Controllers/RequestMaterialController.php +++ b/app/Http/Controllers/RequestMaterialController.php @@ -170,7 +170,7 @@ class RequestMaterialController extends Controller } public function getMaterialIntegration(Request $request) { - $search = null; + $search = urlencode($request->name); if(empty($search)) return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); $url = str_replace("SEARCH", $search, config('api.adw').'/stock_master?name=SEARCH'); diff --git a/app/Http/Controllers/UserToProyekController.php b/app/Http/Controllers/UserToProyekController.php index dc944ea..fecdfec 100644 --- a/app/Http/Controllers/UserToProyekController.php +++ b/app/Http/Controllers/UserToProyekController.php @@ -185,7 +185,7 @@ class UserToProyekController extends Controller } public function getEmployeeIntegration(Request $request) { - $search = null; + $search = urlencode($request->name); if(empty($search)) return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); $url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH'); From 3051a9c4c30c9a86d27a17e42ee9a34e4144cebe Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 24 Aug 2023 14:11:58 +0700 Subject: [PATCH 098/185] update token integrasi --- config/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/api.php b/config/api.php index 4a6fad5..bb3c62a 100644 --- a/config/api.php +++ b/config/api.php @@ -2,6 +2,6 @@ return [ 'nominatim' => env('API_NOMINATIM', 'https://nominatim.oslogdev.com'), 'adw' => env('API_ADW', 'http://ospro-api.adyawinsa.com:9083/api'), - 'adw_token' => env('API_ADW_TOKEN', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxMjAyIiwiZXhwIjoxNjkxODMwNDkzfQ.DvBQIOZsdFndWsliPCZT65Y6G5Xx4vWBKz8Rhe7rvRA') + 'adw_token' => env('API_ADW_TOKEN', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxMjAyIiwiZXhwIjoxNzI0Mzk1NTExfQ.z9_Q7vjZbcbr8Mook4EmlOuOByNP12_DEDSabf0zanU') ]; ?> From 5e96eabedc6ef000453f826118af83ba41bd9044 Mon Sep 17 00:00:00 2001 From: ardhi Date: Fri, 25 Aug 2023 02:12:12 +0700 Subject: [PATCH 099/185] add broadcast API functionality (firebase) --- app/Http/Controllers/BroadcastController.php | 153 +++++++++++++++++++ app/Models/Broadcast.php | 2 +- app/Services/FCMService.php | 49 ++++++ bootstrap/app.php | 1 + routes/web.php | 23 ++- 5 files changed, 219 insertions(+), 9 deletions(-) create mode 100644 app/Services/FCMService.php diff --git a/app/Http/Controllers/BroadcastController.php b/app/Http/Controllers/BroadcastController.php index 7e0a8ca..5bb223e 100644 --- a/app/Http/Controllers/BroadcastController.php +++ b/app/Http/Controllers/BroadcastController.php @@ -3,7 +3,160 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Models\Broadcast; +use App\Models\User; +use App\Services\FCMService; class BroadcastController extends Controller { + public function add(Request $request) + { + + $data = $request->all(); + $data['status_send'] = true; + $data['created_by'] = $this->currentName; + // dd($data); + $result = Broadcast::create($data); + if($result){ + $this->sendNotification($data); + return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400); + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = Broadcast::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = Broadcast::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = Broadcast::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); + $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 list() + { + $data = Broadcast::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list broadcast, please try again later!','code'=>400], 400); + } + } + + public function sendNotification($data) + { + // send_to_type (all, roles, user) + if (isset($data['send_to_type'])) { + switch ($data['send_to_type']) { + case 'all': + $users = User::whereNotNull('fcm_token')->get(); + if (isset($users)) { + foreach ($users as $user) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + case 'roles': + $users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); + if (isset($users)) { + foreach ($users as $user) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + case 'user': + $user = User::where("id", $data['send_to_id'])->whereNotNull('fcm_token')->first(); + if (isset($user)) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + break; + + default: + # code... + break; + } + } + } } diff --git a/app/Models/Broadcast.php b/app/Models/Broadcast.php index c2767c9..bacbdcd 100644 --- a/app/Models/Broadcast.php +++ b/app/Models/Broadcast.php @@ -12,6 +12,6 @@ class Broadcast extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'title_notif', 'message_notif', 'description', 'send_to_type', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'title_notif', 'message_notif', 'description', 'send_to_type', 'send_to_id', 'status_send', 'created_at', 'created_by', 'updated_at', 'updated_by' ]; } diff --git a/app/Services/FCMService.php b/app/Services/FCMService.php new file mode 100644 index 0000000..3fdf971 --- /dev/null +++ b/app/Services/FCMService.php @@ -0,0 +1,49 @@ + [$fcm_token], + "notification" => [ + "title" => $notification['title'], + "body" => $notification['body'], + ] + ]; + $encodedData = json_encode($data); + + $headers = [ + 'Authorization:key=' . $serverKey, + 'Content-Type: application/json', + ]; + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + // Disabling SSL Certificate support temporarly + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_POSTFIELDS, $encodedData); + + $result = curl_exec($ch); + if ($result === FALSE) { + return array("success"=> false, "message"=> curl_error($ch)); + } + // Close connection + curl_close($ch); + return array("success"=> true, "message"=> $result); + } +} \ No newline at end of file diff --git a/bootstrap/app.php b/bootstrap/app.php index af68fb8..13cdeb8 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -63,6 +63,7 @@ $app->configure('auth'); $app->configure('api'); $app->configure('assets'); $app->configure('app'); +$app->configure('fcm'); /* |-------------------------------------------------------------------------- diff --git a/routes/web.php b/routes/web.php index 26b1365..2b97a41 100644 --- a/routes/web.php +++ b/routes/web.php @@ -447,16 +447,23 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->put('/project-comment/update/{id}', 'ProjectCommentController@update'); $router->post('/project-comment/search', 'ProjectCommentController@search'); - $router->get('/hierarchy-ftths', 'HierarchyFtthController@index'); - $router->post('/hierarchy-ftths', 'HierarchyFtthController@store'); - $router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search'); - $router->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show'); - $router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update'); - $router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy'); - $router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject'); - $router->get('/hierarchy-ftths/tree-gantt/{gantt_id}', 'HierarchyFtthController@getTreeByGantt'); + $router->get('/hierarchy-ftths', 'HierarchyFtthController@index'); + $router->post('/hierarchy-ftths', 'HierarchyFtthController@store'); + $router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search'); + $router->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show'); + $router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update'); + $router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy'); + $router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject'); + $router->get('/hierarchy-ftths/tree-gantt/{gantt_id}', 'HierarchyFtthController@getTreeByGantt'); $router->post('/map-monitoring/search', 'MapMonitoringController@search'); + + $router->post('/broadcast/add', 'BroadcastController@add'); + $router->get('/broadcast/edit/{id}', 'BroadcastController@edit'); + $router->put('/broadcast/update/{id}', 'BroadcastController@update'); + $router->post('/broadcast/search', 'BroadcastController@search'); + $router->delete('/broadcast/delete/{id}', 'BroadcastController@delete'); + $router->get('/broadcast/list', 'BroadcastController@list'); }); }); From 3188eba18dbc017f700a4db1aa7ae0512b049e9f Mon Sep 17 00:00:00 2001 From: ardhi Date: Fri, 25 Aug 2023 02:12:26 +0700 Subject: [PATCH 100/185] add broadcast API functionality (firebase) --- config/fcm.php | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 config/fcm.php diff --git a/config/fcm.php b/config/fcm.php new file mode 100644 index 0000000..5c60ec9 --- /dev/null +++ b/config/fcm.php @@ -0,0 +1,5 @@ + "AAAAin2zZmc:APA91bHFIYDzZGyVyXvt2C8I09wC2k8siWPQIo4b1Db0QjxCzQR5SRQU9KY1iNRIUhTL6OoLUs2x6UAiP1BNv-mwOlSR7C_405msoNL2p33JVBxrtqc7hdMc5TEdTBB4ZGRVH7ltQzSe", +]; \ No newline at end of file From 2aed8364ab732760e4ca13c96b82e6d0ea4b1a12 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 25 Aug 2023 11:19:36 +0700 Subject: [PATCH 101/185] Fix getactivity first and last --- app/Http/Controllers/ActivityController.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 401837e..3b8ff84 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -151,7 +151,10 @@ class ActivityController extends Controller } public function getActivityFirst($parentId){ - $activity = Activity::where('parent_id', $parentId)->orderByRaw('start_date ASC')->first(); + $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first(); + if (!isset($activity)) { + return null; + } if($activity->type_activity == "task"){ // Log::info("activity ", [$activity]); return $activity->actual_start; @@ -162,7 +165,10 @@ class ActivityController extends Controller } public function getActivityLast($parentId){ - $activity = Activity::where('parent_id', $parentId)->orderByRaw('start_date DESC')->first(); + $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); + if (!isset($activity)) { + return null; + } if($activity->type_activity == "task"){ // Log::info("activity ", [$activity]); return $activity->actual_end; From ff08801cad71e71924b6d1acb51773bd03a75a04 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 25 Aug 2023 11:23:13 +0700 Subject: [PATCH 102/185] quick fix --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 3b8ff84..99f3614 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -165,7 +165,7 @@ class ActivityController extends Controller } public function getActivityLast($parentId){ - $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); + $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start DESC')->first(); if (!isset($activity)) { return null; } From fda161cc4c7c698f85b578d619c69db96de5528b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 25 Aug 2023 15:13:40 +0700 Subject: [PATCH 103/185] quick fix --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 99f3614..3b8ff84 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -165,7 +165,7 @@ class ActivityController extends Controller } public function getActivityLast($parentId){ - $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start DESC')->first(); + $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); if (!isset($activity)) { return null; } From 02d10a4a8bdf2d568527db2999de17e6704cc07a Mon Sep 17 00:00:00 2001 From: ibnu Date: Sun, 27 Aug 2023 15:50:08 +0700 Subject: [PATCH 104/185] update auto_scheduling is false every actual_start is not null --- app/Http/Controllers/ActivityController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 3b8ff84..0cc4563 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -136,6 +136,9 @@ class ActivityController extends Controller $objRow->type = "task"; $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; + if(isset($objRow->actual_start)){ + $objRow->auto_scheduling = false; + } } else { $objRow->type = "project"; $actualStart = $this->getActivityFirst($objRow->id); From 866d7478922073d67a52c7834f7c2c344eb35f7d Mon Sep 17 00:00:00 2001 From: wahyuun Date: Sun, 27 Aug 2023 19:57:50 +0700 Subject: [PATCH 105/185] add endpoint project-by-customer --- app/Http/Controllers/Controller.php | 689 ++++++++++++--------- app/Http/Controllers/ProjectController.php | 20 +- routes/web.php | 2 +- 3 files changed, 393 insertions(+), 318 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index c431f28..90e141a 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -1,306 +1,383 @@ -currentDate = date("Y-m-d H:i:s"); - $this->currentName = auth()->user() ? auth()->user()->name : "system"; - $this->currentId = auth()->user() ? auth()->user()->id : 0; - - $this->pathImage = config('assets.image'); - $this->pathDocument = config('assets.project'); - $this->pathActivityDocument = config('assets.activity'); - } - - protected function setUpPayload($condition, $tableSelf) - { - $alias = "selfTable"; - $builder = DB::table($tableSelf." AS ".$alias); - $builder = $builder->select($alias.".*"); - if($condition){ - if(isset($condition['joins'])){ - $selectColumn = []; - $no = 0; - foreach($condition['joins'] as $join){ - $tableJoin = isset($join['name1']) ? $join['name1'] : $alias; - $tableName = $join['name']; - $columnJoin = $join['column_join']; // foreign key table sini - $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan - $columnResult = $join['column_results']; - - foreach($columnResult as $sColumn){ - $builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn); - } - $builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); - $no++; - } - } - - if(isset($condition['columns'])){ - $listWhere = $condition['columns']; - - $builder = $builder->where(function ($query) use($listWhere, $alias){ - foreach($listWhere as $where){ - $value = $where['value']; - if($value && $value!="" && $value!=" "){ - $column = $where['name']; - $operator = strtolower($where['logic_operator']); // like, =, <>, range - $value2 = isset($where['value1']) ? $where['value1'] : ""; - $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; - $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - } - } - }); - } - - if(isset($condition['group_column'])){ - $builder = $this->groupWhere($builder, $condition['group_column'], $alias); - } - - $data['count'] = clone $builder; - - if(isset($condition['paging'])){ - $builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']); - } - - if(isset($condition['orders'])){ - $orders = $condition['orders']; - $sortBy = $orders['ascending'] ? "ASC" : "DESC"; - $columnOrder = $orders['columns']; - foreach($columnOrder as $column){ - $builder = $builder->orderBy($alias.".".$column, $sortBy); - } - } - } - $data['builder'] = $builder; - return $data; - } - - private function groupWhere($oldBuilder, $groupWhere, $alias) - { - $builder = $oldBuilder; - $listGroupWhere = $groupWhere; - $operator = $listGroupWhere['operator']; - $operatorGroup = $listGroupWhere['group_operator']; - $listWhere = $listGroupWhere['where']; - if(strtolower($operator)=="and"){ - $builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){ - $no = 1; - foreach ($listWhere as $where) { - $value = $where['value']; - $column = $where['name']; - $operator = strtolower($where['logic_operator']); - $value2 = isset($where['value1']) ? $where['value1'] : ""; - $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; - if($value && $value!="" && $value!=" "){ - if($operatorGroup=="and"){ - $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ - if($no==1){ - $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ - $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); - } - } - } - $no = $no+1; - } - }); - }else if(strtolower($operator)=="or"){ - $builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){ - $no = 1; - foreach ($listWhere as $where) { - $value = $where['value']; - $column = $where['name']; - $operator = strtolower($where['logic_operator']); - $value2 = isset($where['value1']) ? $where['value1'] : ""; - $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; - if($value && $value!="" && $value!=" "){ - if($operatorGroup=="and"){ - $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ - if($no==1){ - $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ - $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); - } - } - } - $no++; - } - }); - } - return $builder; - } - - private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) - { - $query = $oldQuery; - if($operator=="range"){ - $query = $query->whereBetween($tableColumn.".".$column, [$value, $value2]); - }else if($operator=="like"){ - $query = $query->where($tableColumn.".".$column, 'like', '%'.$value.'%'); - }else if($operator=="ilike"){ - $query = $query->where($tableColumn.".".$column, '~*', $value); - }else if($operator=="="){ - $query = $query->where($tableColumn.".".$column, $value); - }else if($operator=="in"){ - $query = $query->whereIn($tableColumn.".".$column, $value); - }else if($operator=="notin"){ - $query = $query->whereNotIn($tableColumn.".".$column, $value); - }else{ - $query = $query->where($tableColumn.".".$column, $operator, $value); - } - return $query; - } - - private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){ - $query = $oldQuery; - if($operator=="range"){ - $query = $query->whereBetween($column, [$value, $value2]); - }else if($operator=="like"){ - $query = $query->where($column, 'like', '%'.$value.'%'); - }else if($operator=="ilike"){ - $query = $query->where($column, '~*', $value); - }else if($operator=="="){ - $query = $query->where($column, $value); - }else if($operator=="in"){ - $query = $query->whereIn($column, $value); - }else if($operator=="notin"){ - $query = $query->whereNotIn($column, $value); - }else{ - $query = $query->where($column, $operator, $value); - } - return $query; - } - - private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) - { - $query = $oldQuery; - if($operator=="range"){ - $query = $query->orWhereBetween($tableColumn.".".$column, [$value, $value2]); - }else if($operator=="like"){ - $query = $query->orWhere($tableColumn.".".$column, 'like', '%'.$value.'%'); - }else if($operator=="ilike"){ - $query = $query->where($tableColumn.".".$column, '~*', $value); - }else if($operator=="="){ - $query = $query->orWhere($tableColumn.".".$column, $value); - }else if($operator=="in"){ - $query = $query->orWhereIn($tableColumn.".".$column, $value); - }else if($operator=="notin"){ - $query = $query->orWhereNotIn($tableColumn.".".$column, $value); - }else{ - $query = $query->orWhere($tableColumn.".".$column, $operator, $value); - } - return $query; - } - - protected function calculateAllCost($activity_id, $proyek_id){ - $humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id); - $materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id); - $toolsCostPlanning = 0; - - $allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning; - return $allCost; - } - - private function calculateAllHumanCost($activity_id, $proyek_id) - { - $dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate") - ->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id") - ->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id) - ->where("ahp.proyek_id", $proyek_id) - ->get(); - - $totalCost = 0; - foreach ($dataHuman as $human) { - $totalCost += $this->calculateHumanCost($human, $activity_id); - } - - return $totalCost; - } - - private function calculateHumanCost($human, $activity_id) - { - $activity = Activity::find($activity_id); - $duration = $activity->duration; - $standarRate = $human->standart_rate; - $maxUsed = $human->max_used/100; - if ($human->uom_standart_rate == "Hour") { - $totalCost = ($standarRate*8*$duration)*$maxUsed; - return $totalCost; - } - $totalCost = ($standarRate*$duration)*$maxUsed; - return $totalCost; - } - - private function calculateMaterialCost($activity_id, $proyek_id) - { - $totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost") - ->where("proyek_id", $proyek_id) - ->where("activity_id", $activity_id) - ->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)")); - return $totalCost; - } - - protected function getLoc($lat, $lng){ - // $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); - // return $response->json; - - $url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"; - // $token = config('api.adw_token'); - $response = $this->curlRequest($url); - return $response; - } - - private function curlRequest($url){ - $ch = curl_init(); - // $headers = [ - // 'Authorization: '.$token - // ]; - curl_setopt($ch, CURLOPT_URL, $url); - // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $response = curl_exec($ch); - if ($response === false) - $response = curl_error($ch); - curl_close($ch); - - return json_decode($response); - } - - protected function addDetailK3($dataDetail, $report_id){ - foreach ($dataDetail as $value) { - $dataNew = array( - "report_k3_id"=>$report_id, - "checklist_k3_id"=>$value['checklist_id'], - "name_checklist_k3"=>$value['checklist_name'], - "created_by"=>$this->currentName - ); - - ReportK3Detail::create($dataNew); - } - } -} +currentDate = date("Y-m-d H:i:s"); + $this->currentName = auth()->user() ? auth()->user()->name : "system"; + $this->currentId = auth()->user() ? auth()->user()->id : 0; + + $this->pathImage = config('assets.image'); + $this->pathDocument = config('assets.project'); + $this->pathActivityDocument = config('assets.activity'); + } + + protected function setUpPayloadByUser($condition) + { + $alias = "utp"; + + $userProyek = UserToProyek::from('assign_hr_to_proyek AS ' . $alias); + $userProyek = $userProyek->where([ + ['is_customer', true], + // $condition['user_id']['user_id'] + ['user_id', 1561] + ])->select('m_proyek.*', 'm_type_proyek.name AS nama_type_proyek'); + + if (isset($condition['joins'])) { + $no = 0; + foreach ($condition['joins'] as $join) { + $tableJoin = isset($join['name1']) ? $join['name1'] : $alias; + $tableName = $join['name']; + $columnJoin = $join['column_join']; // foreign key table sini + $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan + $columnResult = $join['column_results']; + + foreach ($columnResult as $sColumn) { + $userProyek = $userProyek->addSelect($tableName . "." . $sColumn . " as join_" . $this->listJoinAll[$no] . "_" . $sColumn); + } + $userProyek = $userProyek->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf); + $no++; + } + $userProyek->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id'); + } + + if (isset($condition['columns'])) { + $listWhere = $condition['columns']; + + $userProyek = $userProyek->where(function ($query) use ($listWhere, $alias) { + foreach ($listWhere as $where) { + $value = $where['value']; + if ($value && $value != "" && $value != " ") { + $column = $where['name']; + $operator = strtolower($where['logic_operator']); // like, =, <>, range + $value2 = isset($where['value1']) ? $where['value1'] : ""; + $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; + $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } + } + }); + } + + if (isset($condition['group_column'])) { + $userProyek = $this->groupWhere($userProyek, $condition['group_column'], $alias); + } + + $data['count'] = clone $userProyek; + + if (isset($condition['paging'])) { + $userProyek = $userProyek->offset($condition['paging']['start'])->limit($condition['paging']['length']); + } + + if (isset($condition['orders'])) { + $orders = $condition['orders']; + $sortBy = $orders['ascending'] ? "ASC" : "DESC"; + $columnOrder = $orders['columns']; + foreach ($columnOrder as $column) { + $userProyek = $userProyek->orderBy($alias . "." . $column, $sortBy); + } + } + $data['userProyek'] = $userProyek; + return $data; + } + + protected function setUpPayload($condition, $tableSelf) + { + $alias = "selfTable"; + $builder = DB::table($tableSelf . " AS " . $alias); + $builder = $builder->select($alias . ".*"); + if ($condition) { + if (isset($condition['joins'])) { + $selectColumn = []; + $no = 0; + foreach ($condition['joins'] as $join) { + $tableJoin = isset($join['name1']) ? $join['name1'] : $alias; + $tableName = $join['name']; + $columnJoin = $join['column_join']; // foreign key table sini + $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan + $columnResult = $join['column_results']; + + foreach ($columnResult as $sColumn) { + $builder = $builder->addSelect($tableName . "." . $sColumn . " as join_" . $this->listJoinAll[$no] . "_" . $sColumn); + } + $builder = $builder->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf); + $no++; + } + } + + if (isset($condition['columns'])) { + $listWhere = $condition['columns']; + + $builder = $builder->where(function ($query) use ($listWhere, $alias) { + foreach ($listWhere as $where) { + $value = $where['value']; + if ($value && $value != "" && $value != " ") { + $column = $where['name']; + $operator = strtolower($where['logic_operator']); // like, =, <>, range + $value2 = isset($where['value1']) ? $where['value1'] : ""; + $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; + $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } + } + }); + } + + if (isset($condition['group_column'])) { + $builder = $this->groupWhere($builder, $condition['group_column'], $alias); + } + + $data['count'] = clone $builder; + + if (isset($condition['paging'])) { + $builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']); + } + + if (isset($condition['orders'])) { + $orders = $condition['orders']; + $sortBy = $orders['ascending'] ? "ASC" : "DESC"; + $columnOrder = $orders['columns']; + foreach ($columnOrder as $column) { + $builder = $builder->orderBy($alias . "." . $column, $sortBy); + } + } + } + $data['builder'] = $builder; + return $data; + } + + private function groupWhere($oldBuilder, $groupWhere, $alias) + { + $builder = $oldBuilder; + $listGroupWhere = $groupWhere; + $operator = $listGroupWhere['operator']; + $operatorGroup = $listGroupWhere['group_operator']; + $listWhere = $listGroupWhere['where']; + if (strtolower($operator) == "and") { + $builder = $builder->where(function ($query) use ($operatorGroup, $listWhere, $alias) { + $no = 1; + foreach ($listWhere as $where) { + $value = $where['value']; + $column = $where['name']; + $operator = strtolower($where['logic_operator']); + $value2 = isset($where['value1']) ? $where['value1'] : ""; + $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; + if ($value && $value != "" && $value != " ") { + if ($operatorGroup == "and") { + $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } else { + if ($no == 1) { + $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } else { + $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } + } + } + $no = $no + 1; + } + }); + } else if (strtolower($operator) == "or") { + $builder = $builder->orWhere(function ($query) use ($operatorGroup, $listWhere, $alias) { + $no = 1; + foreach ($listWhere as $where) { + $value = $where['value']; + $column = $where['name']; + $operator = strtolower($where['logic_operator']); + $value2 = isset($where['value1']) ? $where['value1'] : ""; + $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; + if ($value && $value != "" && $value != " ") { + if ($operatorGroup == "and") { + $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } else { + if ($no == 1) { + $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } else { + $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); + } + } + } + $no++; + } + }); + } + return $builder; + } + + private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) + { + $query = $oldQuery; + if ($operator == "range") { + $query = $query->whereBetween($tableColumn . "." . $column, [$value, $value2]); + } else if ($operator == "like") { + $query = $query->where($tableColumn . "." . $column, 'like', '%' . $value . '%'); + } else if ($operator == "ilike") { + $query = $query->where($tableColumn . "." . $column, '~*', $value); + } else if ($operator == "=") { + $query = $query->where($tableColumn . "." . $column, $value); + } else if ($operator == "in") { + $query = $query->whereIn($tableColumn . "." . $column, $value); + } else if ($operator == "notin") { + $query = $query->whereNotIn($tableColumn . "." . $column, $value); + } else { + $query = $query->where($tableColumn . "." . $column, $operator, $value); + } + return $query; + } + + private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2) + { + $query = $oldQuery; + if ($operator == "range") { + $query = $query->whereBetween($column, [$value, $value2]); + } else if ($operator == "like") { + $query = $query->where($column, 'like', '%' . $value . '%'); + } else if ($operator == "ilike") { + $query = $query->where($column, '~*', $value); + } else if ($operator == "=") { + $query = $query->where($column, $value); + } else if ($operator == "in") { + $query = $query->whereIn($column, $value); + } else if ($operator == "notin") { + $query = $query->whereNotIn($column, $value); + } else { + $query = $query->where($column, $operator, $value); + } + return $query; + } + + private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) + { + $query = $oldQuery; + if ($operator == "range") { + $query = $query->orWhereBetween($tableColumn . "." . $column, [$value, $value2]); + } else if ($operator == "like") { + $query = $query->orWhere($tableColumn . "." . $column, 'like', '%' . $value . '%'); + } else if ($operator == "ilike") { + $query = $query->where($tableColumn . "." . $column, '~*', $value); + } else if ($operator == "=") { + $query = $query->orWhere($tableColumn . "." . $column, $value); + } else if ($operator == "in") { + $query = $query->orWhereIn($tableColumn . "." . $column, $value); + } else if ($operator == "notin") { + $query = $query->orWhereNotIn($tableColumn . "." . $column, $value); + } else { + $query = $query->orWhere($tableColumn . "." . $column, $operator, $value); + } + return $query; + } + + protected function calculateAllCost($activity_id, $proyek_id) + { + $humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id); + $materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id); + $toolsCostPlanning = 0; + + $allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning; + return $allCost; + } + + private function calculateAllHumanCost($activity_id, $proyek_id) + { + $dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate", "ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate") + ->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id") + ->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id) + ->where("ahp.proyek_id", $proyek_id) + ->get(); + + $totalCost = 0; + foreach ($dataHuman as $human) { + $totalCost += $this->calculateHumanCost($human, $activity_id); + } + + return $totalCost; + } + + private function calculateHumanCost($human, $activity_id) + { + $activity = Activity::find($activity_id); + $duration = $activity->duration; + $standarRate = $human->standart_rate; + $maxUsed = $human->max_used / 100; + if ($human->uom_standart_rate == "Hour") { + $totalCost = ($standarRate * 8 * $duration) * $maxUsed; + return $totalCost; + } + $totalCost = ($standarRate * $duration) * $maxUsed; + return $totalCost; + } + + private function calculateMaterialCost($activity_id, $proyek_id) + { + $totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost") + ->where("proyek_id", $proyek_id) + ->where("activity_id", $activity_id) + ->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)")); + return $totalCost; + } + + protected function getLoc($lat, $lng) + { + // $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); + // return $response->json; + + $url = config('api.nominatim') . "/reverse?lat=" . $lat . "&lon=" . $lng . "&format=json"; + // $token = config('api.adw_token'); + $response = $this->curlRequest($url); + return $response; + } + + private function curlRequest($url) + { + $ch = curl_init(); + // $headers = [ + // 'Authorization: '.$token + // ]; + curl_setopt($ch, CURLOPT_URL, $url); + // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + $response = curl_exec($ch); + if ($response === false) + $response = curl_error($ch); + curl_close($ch); + + return json_decode($response); + } + + protected function addDetailK3($dataDetail, $report_id) + { + foreach ($dataDetail as $value) { + $dataNew = array( + "report_k3_id" => $report_id, + "checklist_k3_id" => $value['checklist_id'], + "name_checklist_k3" => $value['checklist_name'], + "created_by" => $this->currentName + ); + + ReportK3Detail::create($dataNew); + } + } +} diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index e558e78..7117d65 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -204,18 +204,16 @@ class ProjectController extends Controller DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); } - public function getByUser($id) + public function getByUser(Request $request) { - $result = UserToProyek::query() - ->where([ - ['user_id', $id], - ['is_customer', true] - ])->get(); - if ($result) { - return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); - } else { - return response()->json(['status' => 'failed', 'message' => 'Get User Project Not Found!', 'code' => 404], 404); - } + $payload = $request->all(); + $dataBuilder = $this->setUpPayloadByUser($payload); + $builder = $dataBuilder['userProyek']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } public function search(Request $request) diff --git a/routes/web.php b/routes/web.php index a35676c..47ed601 100644 --- a/routes/web.php +++ b/routes/web.php @@ -53,7 +53,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); - $router->get('/project-by-customer/{id}', 'ProjectController@getByUser'); + $router->post('/project-by-customer', 'ProjectController@getByUser'); $router->post('/project/search', 'ProjectController@search'); $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); From c60fc81b1005848db31411d06d18fd29087e1b0d Mon Sep 17 00:00:00 2001 From: ardhi Date: Mon, 28 Aug 2023 11:16:18 +0700 Subject: [PATCH 106/185] fix clock_in time in map monitoring --- app/Http/Controllers/MapMonitoringController.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index 3fdcef4..cd68d20 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -37,15 +37,11 @@ class MapMonitoringController extends Controller 'tcio.clock_in_lng', 'tcio.clock_in_loc', 'tcio.clock_out_loc', - 'tcio.date_presence', - 'mw.lat', - 'mw.lon', - 'mw.wptime' + 'tcio.date_presence' ) ->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') - ->join('m_waypoint as mw', 'mu.id', '=', 'mw.user_id') ->where('mu.id', $key->user_id) - ->orderBy('mw.wptime', 'DESC') + ->orderBy('tcio.clock_in', 'DESC') ->first(); $project = DB::table('assign_hr_to_proyek as ahtp') ->select('ahtp.proyek_id as id', 'mp.nama as project_name') @@ -55,11 +51,12 @@ class MapMonitoringController extends Controller ->get(); if ($presensi && isset($presensi->user_id)) { $image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first(); + $waypoint = DB::table('m_waypoint')->select('lat', 'lon', 'wptime')->where('user_id', $presensi->user_id)->orderBy('wptime', 'DESC')->first(); $tmp[] = array( 'user_id' => $presensi->user_id, - 'wp_lat' => $presensi->lat, - 'wp_lon' => $presensi->lon, - 'wp_time' => $presensi->wptime, + 'wp_lat' => isset($waypoint) ? $waypoint->lat : '-', + 'wp_lon' => isset($waypoint) ? $waypoint->lon : '-', + 'wp_time' => isset($waypoint) ? $waypoint->wptime : '-', 'clock_in' => $presensi->clock_in, 'clock_out' => $presensi->clock_out, 'clock_in_lat' => $presensi->clock_in_lat, From 472d63240f0ed054fdfd74e114fef409265c932e Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 28 Aug 2023 11:46:40 +0700 Subject: [PATCH 107/185] display schedule & bcwp fix --- app/Helpers/MasterFunctionsHelper.php | 4 ++++ app/Http/Controllers/ProjectController.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index eb70448..6d75174 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -427,6 +427,8 @@ class MasterFunctionsHelper $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; } + $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; + $totalBCWP = $lastReal * $totalBCWP; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, @@ -720,6 +722,8 @@ class MasterFunctionsHelper $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; } + $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; + $totalBCWP = $lastReal * $totalBCWP; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 3d22495..ffbe3fa 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -445,6 +445,18 @@ class ProjectController extends Controller $gantt = MasterFunctionsHelper::getLatestGantt($id); $result->projectManager = User::where('id', $result->pm_id)->value('name'); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first(); + // dd($result->header->start_date); + $ganttId = $gantt['last_gantt_id']; + + $startDate = Activity::where('version_gantt_id', $ganttId) + ->orderBy('start_date') + ->value('start_date'); + + $endDate = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('end_date') + ->value('end_date'); + $result->header->start_date = $startDate; + $result->header->end_date = $endDate; return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); } From 6ce61143e711f672226cb4650aef0847220a18ba Mon Sep 17 00:00:00 2001 From: ibnu Date: Mon, 28 Aug 2023 11:56:34 +0700 Subject: [PATCH 108/185] update set timeout 5 minutes --- Dockerfile | 3 + docker/nginx/conf.d/default.conf | 9 + docker/php/php.ini | 1947 ++++++++++++++++++++++++++++++ 3 files changed, 1959 insertions(+) create mode 100644 docker/php/php.ini diff --git a/Dockerfile b/Dockerfile index 4edd5c1..f9925d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,9 @@ RUN docker-php-ext-install \ pgsql \ tokenizer +# Copy php.ini to the container +COPY /docker/php/php.ini /usr/local/etc/php/ + #Install Extensions RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/default.conf index e3e292a..f311b54 100644 --- a/docker/nginx/conf.d/default.conf +++ b/docker/nginx/conf.d/default.conf @@ -15,6 +15,15 @@ server { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; + + client_max_body_size 100M; + client_body_buffer_size 5M; + fastcgi_read_timeout 900; + keepalive_timeout 900; + send_timeout 300; + proxy_read_timeout 900; + proxy_connect_timeout 900; + proxy_send_timeout 900; } location / { diff --git a/docker/php/php.ini b/docker/php/php.ini new file mode 100644 index 0000000..efc483f --- /dev/null +++ b/docker/php/php.ini @@ -0,0 +1,1947 @@ +[PHP] + +;;;;;;;;;;;;;;;;;;; +; About php.ini ; +;;;;;;;;;;;;;;;;;;; +; PHP's initialization file, generally called php.ini, is responsible for +; configuring many of the aspects of PHP's behavior. + +; PHP attempts to find and load this configuration from a number of locations. +; The following is a summary of its search order: +; 1. SAPI module specific location. +; 2. The PHPRC environment variable. (As of PHP 5.2.0) +; 3. A number of predefined registry keys on Windows (As of PHP 5.2.0) +; 4. Current working directory (except CLI) +; 5. The web server's directory (for SAPI modules), or directory of PHP +; (otherwise in Windows) +; 6. The directory from the --with-config-file-path compile time option, or the +; Windows directory (usually C:\windows) +; See the PHP docs for more specific information. +; http://php.net/configuration.file + +; The syntax of the file is extremely simple. Whitespace and lines +; beginning with a semicolon are silently ignored (as you probably guessed). +; Section headers (e.g. [Foo]) are also silently ignored, even though +; they might mean something in the future. + +; Directives following the section heading [PATH=/www/mysite] only +; apply to PHP files in the /www/mysite directory. Directives +; following the section heading [HOST=www.example.com] only apply to +; PHP files served from www.example.com. Directives set in these +; special sections cannot be overridden by user-defined INI files or +; at runtime. Currently, [PATH=] and [HOST=] sections only work under +; CGI/FastCGI. +; http://php.net/ini.sections + +; Directives are specified using the following syntax: +; directive = value +; Directive names are *case sensitive* - foo=bar is different from FOO=bar. +; Directives are variables used to configure PHP or PHP extensions. +; There is no name validation. If PHP can't find an expected +; directive because it is not set or is mistyped, a default value will be used. + +; The value can be a string, a number, a PHP constant (e.g. E_ALL or M_PI), one +; of the INI constants (On, Off, True, False, Yes, No and None) or an expression +; (e.g. E_ALL & ~E_NOTICE), a quoted string ("bar"), or a reference to a +; previously set variable or directive (e.g. ${foo}) + +; Expressions in the INI file are limited to bitwise operators and parentheses: +; | bitwise OR +; ^ bitwise XOR +; & bitwise AND +; ~ bitwise NOT +; ! boolean NOT + +; Boolean flags can be turned on using the values 1, On, True or Yes. +; They can be turned off using the values 0, Off, False or No. + +; An empty string can be denoted by simply not writing anything after the equal +; sign, or by using the None keyword: + +; foo = ; sets foo to an empty string +; foo = None ; sets foo to an empty string +; foo = "None" ; sets foo to the string 'None' + +; If you use constants in your value, and these constants belong to a +; dynamically loaded extension (either a PHP extension or a Zend extension), +; you may only use these constants *after* the line that loads the extension. + +;;;;;;;;;;;;;;;;;;; +; About this file ; +;;;;;;;;;;;;;;;;;;; +; PHP comes packaged with two INI files. One that is recommended to be used +; in production environments and one that is recommended to be used in +; development environments. + +; php.ini-production contains settings which hold security, performance and +; best practices at its core. But please be aware, these settings may break +; compatibility with older or less security conscience applications. We +; recommending using the production ini in production and testing environments. + +; php.ini-development is very similar to its production variant, except it is +; much more verbose when it comes to errors. We recommend using the +; development version only in development environments, as errors shown to +; application users can inadvertently leak otherwise secure information. + +; This is the php.ini-production INI file. + +;;;;;;;;;;;;;;;;;;; +; Quick Reference ; +;;;;;;;;;;;;;;;;;;; +; The following are all the settings which are different in either the production +; or development versions of the INIs with respect to PHP's default behavior. +; Please see the actual settings later in the document for more details as to why +; we recommend these changes in PHP's behavior. + +; display_errors +; Default Value: On +; Development Value: On +; Production Value: Off + +; display_startup_errors +; Default Value: Off +; Development Value: On +; Production Value: Off + +; error_reporting +; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED +; Development Value: E_ALL +; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT + +; log_errors +; Default Value: Off +; Development Value: On +; Production Value: On + +; max_input_time +; Default Value: -1 (Unlimited) +; Development Value: 60 (60 seconds) +; Production Value: 60 (60 seconds) + +; output_buffering +; Default Value: Off +; Development Value: 4096 +; Production Value: 4096 + +; register_argc_argv +; Default Value: On +; Development Value: Off +; Production Value: Off + +; request_order +; Default Value: None +; Development Value: "GP" +; Production Value: "GP" + +; session.gc_divisor +; Default Value: 100 +; Development Value: 1000 +; Production Value: 1000 + +; session.sid_bits_per_character +; Default Value: 4 +; Development Value: 5 +; Production Value: 5 + +; short_open_tag +; Default Value: On +; Development Value: Off +; Production Value: Off + +; variables_order +; Default Value: "EGPCS" +; Development Value: "GPCS" +; Production Value: "GPCS" + +;;;;;;;;;;;;;;;;;;;; +; php.ini Options ; +;;;;;;;;;;;;;;;;;;;; +; Name for user-defined php.ini (.htaccess) files. Default is ".user.ini" +;user_ini.filename = ".user.ini" + +; To disable this feature set this option to an empty value +;user_ini.filename = + +; TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes) +;user_ini.cache_ttl = 300 + +;;;;;;;;;;;;;;;;;;;; +; Language Options ; +;;;;;;;;;;;;;;;;;;;; + +; Enable the PHP scripting language engine under Apache. +; http://php.net/engine +engine = On + +; This directive determines whether or not PHP will recognize code between +; tags as PHP source which should be processed as such. It is +; generally recommended that should be used and that this feature +; should be disabled, as enabling it may result in issues when generating XML +; documents, however this remains supported for backward compatibility reasons. +; Note that this directive does not control the would work. +; http://php.net/syntax-highlighting +;highlight.string = #DD0000 +;highlight.comment = #FF9900 +;highlight.keyword = #007700 +;highlight.default = #0000BB +;highlight.html = #000000 + +; If enabled, the request will be allowed to complete even if the user aborts +; the request. Consider enabling it if executing long requests, which may end up +; being interrupted by the user or a browser timing out. PHP's default behavior +; is to disable this feature. +; http://php.net/ignore-user-abort +;ignore_user_abort = On + +; Determines the size of the realpath cache to be used by PHP. This value should +; be increased on systems where PHP opens many files to reflect the quantity of +; the file operations performed. +; Note: if open_basedir is set, the cache is disabled +; http://php.net/realpath-cache-size +;realpath_cache_size = 4096k + +; Duration of time, in seconds for which to cache realpath information for a given +; file or directory. For systems with rarely changing files, consider increasing this +; value. +; http://php.net/realpath-cache-ttl +;realpath_cache_ttl = 120 + +; Enables or disables the circular reference collector. +; http://php.net/zend.enable-gc +zend.enable_gc = On + +; If enabled, scripts may be written in encodings that are incompatible with +; the scanner. CP936, Big5, CP949 and Shift_JIS are the examples of such +; encodings. To use this feature, mbstring extension must be enabled. +; Default: Off +;zend.multibyte = Off + +; Allows to set the default encoding for the scripts. This value will be used +; unless "declare(encoding=...)" directive appears at the top of the script. +; Only affects if zend.multibyte is set. +; Default: "" +;zend.script_encoding = + +; Allows to include or exclude arguments from stack traces generated for exceptions. +; In production, it is recommended to turn this setting on to prohibit the output +; of sensitive information in stack traces +; Default: Off +zend.exception_ignore_args = On + +;;;;;;;;;;;;;;;;; +; Miscellaneous ; +;;;;;;;;;;;;;;;;; + +; Decides whether PHP may expose the fact that it is installed on the server +; (e.g. by adding its signature to the Web server header). It is no security +; threat in any way, but it makes it possible to determine whether you use PHP +; on your server or not. +; http://php.net/expose-php +expose_php = On + +;;;;;;;;;;;;;;;;;;; +; Resource Limits ; +;;;;;;;;;;;;;;;;;;; + +; Maximum execution time of each script, in seconds +; http://php.net/max-execution-time +; Note: This directive is hardcoded to 0 for the CLI SAPI +max_execution_time = 300 + +; Maximum amount of time each script may spend parsing request data. It's a good +; idea to limit this time on productions servers in order to eliminate unexpectedly +; long running scripts. +; Note: This directive is hardcoded to -1 for the CLI SAPI +; Default Value: -1 (Unlimited) +; Development Value: 60 (60 seconds) +; Production Value: 60 (60 seconds) +; http://php.net/max-input-time +max_input_time = 300 + +; Maximum input variable nesting level +; http://php.net/max-input-nesting-level +;max_input_nesting_level = 64 + +; How many GET/POST/COOKIE input variables may be accepted +;max_input_vars = 1000 + +; Maximum amount of memory a script may consume +; http://php.net/memory-limit +memory_limit = 128M + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Error handling and logging ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; This directive informs PHP of which errors, warnings and notices you would like +; it to take action for. The recommended way of setting values for this +; directive is through the use of the error level constants and bitwise +; operators. The error level constants are below here for convenience as well as +; some common settings and their meanings. +; By default, PHP is set to take action on all errors, notices and warnings EXCEPT +; those related to E_NOTICE and E_STRICT, which together cover best practices and +; recommended coding standards in PHP. For performance reasons, this is the +; recommend error reporting setting. Your production server shouldn't be wasting +; resources complaining about best practices and coding standards. That's what +; development servers and development settings are for. +; Note: The php.ini-development file has this setting as E_ALL. This +; means it pretty much reports everything which is exactly what you want during +; development and early testing. +; +; Error Level Constants: +; E_ALL - All errors and warnings (includes E_STRICT as of PHP 5.4.0) +; E_ERROR - fatal run-time errors +; E_RECOVERABLE_ERROR - almost fatal run-time errors +; E_WARNING - run-time warnings (non-fatal errors) +; E_PARSE - compile-time parse errors +; E_NOTICE - run-time notices (these are warnings which often result +; from a bug in your code, but it's possible that it was +; intentional (e.g., using an uninitialized variable and +; relying on the fact it is automatically initialized to an +; empty string) +; E_STRICT - run-time notices, enable to have PHP suggest changes +; to your code which will ensure the best interoperability +; and forward compatibility of your code +; E_CORE_ERROR - fatal errors that occur during PHP's initial startup +; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's +; initial startup +; E_COMPILE_ERROR - fatal compile-time errors +; E_COMPILE_WARNING - compile-time warnings (non-fatal errors) +; E_USER_ERROR - user-generated error message +; E_USER_WARNING - user-generated warning message +; E_USER_NOTICE - user-generated notice message +; E_DEPRECATED - warn about code that will not work in future versions +; of PHP +; E_USER_DEPRECATED - user-generated deprecation warnings +; +; Common Values: +; E_ALL (Show all errors, warnings and notices including coding standards.) +; E_ALL & ~E_NOTICE (Show all errors, except for notices) +; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.) +; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors) +; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED +; Development Value: E_ALL +; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT +; http://php.net/error-reporting +error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT + +; This directive controls whether or not and where PHP will output errors, +; notices and warnings too. Error output is very useful during development, but +; it could be very dangerous in production environments. Depending on the code +; which is triggering the error, sensitive information could potentially leak +; out of your application such as database usernames and passwords or worse. +; For production environments, we recommend logging errors rather than +; sending them to STDOUT. +; Possible Values: +; Off = Do not display any errors +; stderr = Display errors to STDERR (affects only CGI/CLI binaries!) +; On or stdout = Display errors to STDOUT +; Default Value: On +; Development Value: On +; Production Value: Off +; http://php.net/display-errors +display_errors = Off + +; The display of errors which occur during PHP's startup sequence are handled +; separately from display_errors. PHP's default behavior is to suppress those +; errors from clients. Turning the display of startup errors on can be useful in +; debugging configuration problems. We strongly recommend you +; set this to 'off' for production servers. +; Default Value: Off +; Development Value: On +; Production Value: Off +; http://php.net/display-startup-errors +display_startup_errors = Off + +; Besides displaying errors, PHP can also log errors to locations such as a +; server-specific log, STDERR, or a location specified by the error_log +; directive found below. While errors should not be displayed on productions +; servers they should still be monitored and logging is a great way to do that. +; Default Value: Off +; Development Value: On +; Production Value: On +; http://php.net/log-errors +log_errors = On + +; Set maximum length of log_errors. In error_log information about the source is +; added. The default is 1024 and 0 allows to not apply any maximum length at all. +; http://php.net/log-errors-max-len +log_errors_max_len = 1024 + +; Do not log repeated messages. Repeated errors must occur in same file on same +; line unless ignore_repeated_source is set true. +; http://php.net/ignore-repeated-errors +ignore_repeated_errors = Off + +; Ignore source of message when ignoring repeated messages. When this setting +; is On you will not log errors with repeated messages from different files or +; source lines. +; http://php.net/ignore-repeated-source +ignore_repeated_source = Off + +; If this parameter is set to Off, then memory leaks will not be shown (on +; stdout or in the log). This is only effective in a debug compile, and if +; error reporting includes E_WARNING in the allowed list +; http://php.net/report-memleaks +report_memleaks = On + +; This setting is on by default. +;report_zend_debug = 0 + +; Store the last error/warning message in $php_errormsg (boolean). Setting this value +; to On can assist in debugging and is appropriate for development servers. It should +; however be disabled on production servers. +; This directive is DEPRECATED. +; Default Value: Off +; Development Value: Off +; Production Value: Off +; http://php.net/track-errors +;track_errors = Off + +; Turn off normal error reporting and emit XML-RPC error XML +; http://php.net/xmlrpc-errors +;xmlrpc_errors = 0 + +; An XML-RPC faultCode +;xmlrpc_error_number = 0 + +; When PHP displays or logs an error, it has the capability of formatting the +; error message as HTML for easier reading. This directive controls whether +; the error message is formatted as HTML or not. +; Note: This directive is hardcoded to Off for the CLI SAPI +; http://php.net/html-errors +;html_errors = On + +; If html_errors is set to On *and* docref_root is not empty, then PHP +; produces clickable error messages that direct to a page describing the error +; or function causing the error in detail. +; You can download a copy of the PHP manual from http://php.net/docs +; and change docref_root to the base URL of your local copy including the +; leading '/'. You must also specify the file extension being used including +; the dot. PHP's default behavior is to leave these settings empty, in which +; case no links to documentation are generated. +; Note: Never use this feature for production boxes. +; http://php.net/docref-root +; Examples +;docref_root = "/phpmanual/" + +; http://php.net/docref-ext +;docref_ext = .html + +; String to output before an error message. PHP's default behavior is to leave +; this setting blank. +; http://php.net/error-prepend-string +; Example: +;error_prepend_string = "" + +; String to output after an error message. PHP's default behavior is to leave +; this setting blank. +; http://php.net/error-append-string +; Example: +;error_append_string = "" + +; Log errors to specified file. PHP's default behavior is to leave this value +; empty. +; http://php.net/error-log +; Example: +;error_log = php_errors.log +; Log errors to syslog (Event Log on Windows). +;error_log = syslog + +; The syslog ident is a string which is prepended to every message logged +; to syslog. Only used when error_log is set to syslog. +;syslog.ident = php + +; The syslog facility is used to specify what type of program is logging +; the message. Only used when error_log is set to syslog. +;syslog.facility = user + +; Set this to disable filtering control characters (the default). +; Some loggers only accept NVT-ASCII, others accept anything that's not +; control characters. If your logger accepts everything, then no filtering +; is needed at all. +; Allowed values are: +; ascii (all printable ASCII characters and NL) +; no-ctrl (all characters except control characters) +; all (all characters) +; raw (like "all", but messages are not split at newlines) +; http://php.net/syslog.filter +;syslog.filter = ascii + +;windows.show_crt_warning +; Default value: 0 +; Development value: 0 +; Production value: 0 + +;;;;;;;;;;;;;;;;; +; Data Handling ; +;;;;;;;;;;;;;;;;; + +; The separator used in PHP generated URLs to separate arguments. +; PHP's default setting is "&". +; http://php.net/arg-separator.output +; Example: +;arg_separator.output = "&" + +; List of separator(s) used by PHP to parse input URLs into variables. +; PHP's default setting is "&". +; NOTE: Every character in this directive is considered as separator! +; http://php.net/arg-separator.input +; Example: +;arg_separator.input = ";&" + +; This directive determines which super global arrays are registered when PHP +; starts up. G,P,C,E & S are abbreviations for the following respective super +; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty +; paid for the registration of these arrays and because ENV is not as commonly +; used as the others, ENV is not recommended on productions servers. You +; can still get access to the environment variables through getenv() should you +; need to. +; Default Value: "EGPCS" +; Development Value: "GPCS" +; Production Value: "GPCS"; +; http://php.net/variables-order +variables_order = "GPCS" + +; This directive determines which super global data (G,P & C) should be +; registered into the super global array REQUEST. If so, it also determines +; the order in which that data is registered. The values for this directive +; are specified in the same manner as the variables_order directive, +; EXCEPT one. Leaving this value empty will cause PHP to use the value set +; in the variables_order directive. It does not mean it will leave the super +; globals array REQUEST empty. +; Default Value: None +; Development Value: "GP" +; Production Value: "GP" +; http://php.net/request-order +request_order = "GP" + +; This directive determines whether PHP registers $argv & $argc each time it +; runs. $argv contains an array of all the arguments passed to PHP when a script +; is invoked. $argc contains an integer representing the number of arguments +; that were passed when the script was invoked. These arrays are extremely +; useful when running scripts from the command line. When this directive is +; enabled, registering these variables consumes CPU cycles and memory each time +; a script is executed. For performance reasons, this feature should be disabled +; on production servers. +; Note: This directive is hardcoded to On for the CLI SAPI +; Default Value: On +; Development Value: Off +; Production Value: Off +; http://php.net/register-argc-argv +register_argc_argv = Off + +; When enabled, the ENV, REQUEST and SERVER variables are created when they're +; first used (Just In Time) instead of when the script starts. If these +; variables are not used within a script, having this directive on will result +; in a performance gain. The PHP directive register_argc_argv must be disabled +; for this directive to have any effect. +; http://php.net/auto-globals-jit +auto_globals_jit = On + +; Whether PHP will read the POST data. +; This option is enabled by default. +; Most likely, you won't want to disable this option globally. It causes $_POST +; and $_FILES to always be empty; the only way you will be able to read the +; POST data will be through the php://input stream wrapper. This can be useful +; to proxy requests or to process the POST data in a memory efficient fashion. +; http://php.net/enable-post-data-reading +;enable_post_data_reading = Off + +; Maximum size of POST data that PHP will accept. +; Its value may be 0 to disable the limit. It is ignored if POST data reading +; is disabled through enable_post_data_reading. +; http://php.net/post-max-size +post_max_size = 80M + +; Automatically add files before PHP document. +; http://php.net/auto-prepend-file +auto_prepend_file = + +; Automatically add files after PHP document. +; http://php.net/auto-append-file +auto_append_file = + +; By default, PHP will output a media type using the Content-Type header. To +; disable this, simply set it to be empty. +; +; PHP's built-in default media type is set to text/html. +; http://php.net/default-mimetype +default_mimetype = "text/html" + +; PHP's default character set is set to UTF-8. +; http://php.net/default-charset +default_charset = "UTF-8" + +; PHP internal character encoding is set to empty. +; If empty, default_charset is used. +; http://php.net/internal-encoding +;internal_encoding = + +; PHP input character encoding is set to empty. +; If empty, default_charset is used. +; http://php.net/input-encoding +;input_encoding = + +; PHP output character encoding is set to empty. +; If empty, default_charset is used. +; See also output_buffer. +; http://php.net/output-encoding +;output_encoding = + +;;;;;;;;;;;;;;;;;;;;;;;;; +; Paths and Directories ; +;;;;;;;;;;;;;;;;;;;;;;;;; + +; UNIX: "/path1:/path2" +;include_path = ".:/php/includes" +; +; Windows: "\path1;\path2" +;include_path = ".;c:\php\includes" +; +; PHP's default setting for include_path is ".;/path/to/php/pear" +; http://php.net/include-path + +; The root of the PHP pages, used only if nonempty. +; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root +; if you are running php as a CGI under any web server (other than IIS) +; see documentation for security issues. The alternate is to use the +; cgi.force_redirect configuration below +; http://php.net/doc-root +doc_root = + +; The directory under which PHP opens the script using /~username used only +; if nonempty. +; http://php.net/user-dir +user_dir = + +; Directory in which the loadable extensions (modules) reside. +; http://php.net/extension-dir +;extension_dir = "./" +; On windows: +;extension_dir = "ext" + +; Directory where the temporary files should be placed. +; Defaults to the system default (see sys_get_temp_dir) +;sys_temp_dir = "/tmp" + +; Whether or not to enable the dl() function. The dl() function does NOT work +; properly in multithreaded servers, such as IIS or Zeus, and is automatically +; disabled on them. +; http://php.net/enable-dl +enable_dl = Off + +; cgi.force_redirect is necessary to provide security running PHP as a CGI under +; most web servers. Left undefined, PHP turns this on by default. You can +; turn it off here AT YOUR OWN RISK +; **You CAN safely turn this off for IIS, in fact, you MUST.** +; http://php.net/cgi.force-redirect +;cgi.force_redirect = 1 + +; if cgi.nph is enabled it will force cgi to always sent Status: 200 with +; every request. PHP's default behavior is to disable this feature. +;cgi.nph = 1 + +; if cgi.force_redirect is turned on, and you are not running under Apache or Netscape +; (iPlanet) web servers, you MAY need to set an environment variable name that PHP +; will look for to know it is OK to continue execution. Setting this variable MAY +; cause security issues, KNOW WHAT YOU ARE DOING FIRST. +; http://php.net/cgi.redirect-status-env +;cgi.redirect_status_env = + +; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's +; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok +; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting +; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting +; of zero causes PHP to behave as before. Default is 1. You should fix your scripts +; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. +; http://php.net/cgi.fix-pathinfo +;cgi.fix_pathinfo=1 + +; if cgi.discard_path is enabled, the PHP CGI binary can safely be placed outside +; of the web tree and people will not be able to circumvent .htaccess security. +;cgi.discard_path=1 + +; FastCGI under IIS supports the ability to impersonate +; security tokens of the calling client. This allows IIS to define the +; security context that the request runs under. mod_fastcgi under Apache +; does not currently support this feature (03/17/2002) +; Set to 1 if running under IIS. Default is zero. +; http://php.net/fastcgi.impersonate +;fastcgi.impersonate = 1 + +; Disable logging through FastCGI connection. PHP's default behavior is to enable +; this feature. +;fastcgi.logging = 0 + +; cgi.rfc2616_headers configuration option tells PHP what type of headers to +; use when sending HTTP response code. If set to 0, PHP sends Status: header that +; is supported by Apache. When this option is set to 1, PHP will send +; RFC2616 compliant header. +; Default is zero. +; http://php.net/cgi.rfc2616-headers +;cgi.rfc2616_headers = 0 + +; cgi.check_shebang_line controls whether CGI PHP checks for line starting with #! +; (shebang) at the top of the running script. This line might be needed if the +; script support running both as stand-alone script and via PHP CGI<. PHP in CGI +; mode skips this line and ignores its content if this directive is turned on. +; http://php.net/cgi.check-shebang-line +;cgi.check_shebang_line=1 + +;;;;;;;;;;;;;;;; +; File Uploads ; +;;;;;;;;;;;;;;;; + +; Whether to allow HTTP file uploads. +; http://php.net/file-uploads +file_uploads = On + +; Temporary directory for HTTP uploaded files (will use system default if not +; specified). +; http://php.net/upload-tmp-dir +;upload_tmp_dir = + +; Maximum allowed size for uploaded files. +; http://php.net/upload-max-filesize +upload_max_filesize = 20M + +; Maximum number of files that can be uploaded via a single request +max_file_uploads = 20 + +;;;;;;;;;;;;;;;;;; +; Fopen wrappers ; +;;;;;;;;;;;;;;;;;; + +; Whether to allow the treatment of URLs (like http:// or ftp://) as files. +; http://php.net/allow-url-fopen +allow_url_fopen = On + +; Whether to allow include/require to open URLs (like http:// or ftp://) as files. +; http://php.net/allow-url-include +allow_url_include = Off + +; Define the anonymous ftp password (your email address). PHP's default setting +; for this is empty. +; http://php.net/from +;from="john@doe.com" + +; Define the User-Agent string. PHP's default setting for this is empty. +; http://php.net/user-agent +;user_agent="PHP" + +; Default timeout for socket based streams (seconds) +; http://php.net/default-socket-timeout +default_socket_timeout = 600 + +; If your scripts have to deal with files from Macintosh systems, +; or you are running on a Mac and need to deal with files from +; unix or win32 systems, setting this flag will cause PHP to +; automatically detect the EOL character in those files so that +; fgets() and file() will work regardless of the source of the file. +; http://php.net/auto-detect-line-endings +;auto_detect_line_endings = Off + +;;;;;;;;;;;;;;;;;;;;;; +; Dynamic Extensions ; +;;;;;;;;;;;;;;;;;;;;;; + +; If you wish to have an extension loaded automatically, use the following +; syntax: +; +; extension=modulename +; +; For example: +; +; extension=mysqli +; +; When the extension library to load is not located in the default extension +; directory, You may specify an absolute path to the library file: +; +; extension=/path/to/extension/mysqli.so +; +; Note : The syntax used in previous PHP versions ('extension=.so' and +; 'extension='php_.dll') is supported for legacy reasons and may be +; deprecated in a future PHP major version. So, when it is possible, please +; move to the new ('extension=) syntax. +; +; Notes for Windows environments : +; +; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+) +; extension folders as well as the separate PECL DLL download (PHP 5+). +; Be sure to appropriately set the extension_dir directive. +; +;extension=bz2 +;extension=curl +;extension=ffi +;extension=ftp +;extension=fileinfo +;extension=gd2 +;extension=gettext +;extension=gmp +;extension=intl +;extension=imap +;extension=ldap +;extension=mbstring +;extension=exif ; Must be after mbstring as it depends on it +;extension=mysqli +;extension=oci8_12c ; Use with Oracle Database 12c Instant Client +;extension=odbc +;extension=openssl +;extension=pdo_firebird +;extension=pdo_mysql +;extension=pdo_oci +;extension=pdo_odbc +;extension=pdo_pgsql +;extension=pdo_sqlite +;extension=pgsql +;extension=shmop + +; The MIBS data available in the PHP distribution must be installed. +; See http://www.php.net/manual/en/snmp.installation.php +;extension=snmp + +;extension=soap +;extension=sockets +;extension=sodium +;extension=sqlite3 +;extension=tidy +;extension=xmlrpc +;extension=xsl + +;;;;;;;;;;;;;;;;;;; +; Module Settings ; +;;;;;;;;;;;;;;;;;;; + +[CLI Server] +; Whether the CLI web server uses ANSI color coding in its terminal output. +cli_server.color = On + +[Date] +; Defines the default timezone used by the date functions +; http://php.net/date.timezone +;date.timezone = + +; http://php.net/date.default-latitude +;date.default_latitude = 31.7667 + +; http://php.net/date.default-longitude +;date.default_longitude = 35.2333 + +; http://php.net/date.sunrise-zenith +;date.sunrise_zenith = 90.583333 + +; http://php.net/date.sunset-zenith +;date.sunset_zenith = 90.583333 + +[filter] +; http://php.net/filter.default +;filter.default = unsafe_raw + +; http://php.net/filter.default-flags +;filter.default_flags = + +[iconv] +; Use of this INI entry is deprecated, use global input_encoding instead. +; If empty, default_charset or input_encoding or iconv.input_encoding is used. +; The precedence is: default_charset < input_encoding < iconv.input_encoding +;iconv.input_encoding = + +; Use of this INI entry is deprecated, use global internal_encoding instead. +; If empty, default_charset or internal_encoding or iconv.internal_encoding is used. +; The precedence is: default_charset < internal_encoding < iconv.internal_encoding +;iconv.internal_encoding = + +; Use of this INI entry is deprecated, use global output_encoding instead. +; If empty, default_charset or output_encoding or iconv.output_encoding is used. +; The precedence is: default_charset < output_encoding < iconv.output_encoding +; To use an output encoding conversion, iconv's output handler must be set +; otherwise output encoding conversion cannot be performed. +;iconv.output_encoding = + +[imap] +; rsh/ssh logins are disabled by default. Use this INI entry if you want to +; enable them. Note that the IMAP library does not filter mailbox names before +; passing them to rsh/ssh command, thus passing untrusted data to this function +; with rsh/ssh enabled is insecure. +;imap.enable_insecure_rsh=0 + +[intl] +;intl.default_locale = +; This directive allows you to produce PHP errors when some error +; happens within intl functions. The value is the level of the error produced. +; Default is 0, which does not produce any errors. +;intl.error_level = E_WARNING +;intl.use_exceptions = 0 + +[sqlite3] +; Directory pointing to SQLite3 extensions +; http://php.net/sqlite3.extension-dir +;sqlite3.extension_dir = + +; SQLite defensive mode flag (only available from SQLite 3.26+) +; When the defensive flag is enabled, language features that allow ordinary +; SQL to deliberately corrupt the database file are disabled. This forbids +; writing directly to the schema, shadow tables (eg. FTS data tables), or +; the sqlite_dbpage virtual table. +; https://www.sqlite.org/c3ref/c_dbconfig_defensive.html +; (for older SQLite versions, this flag has no use) +;sqlite3.defensive = 1 + +[Pcre] +; PCRE library backtracking limit. +; http://php.net/pcre.backtrack-limit +;pcre.backtrack_limit=100000 + +; PCRE library recursion limit. +; Please note that if you set this value to a high number you may consume all +; the available process stack and eventually crash PHP (due to reaching the +; stack size limit imposed by the Operating System). +; http://php.net/pcre.recursion-limit +;pcre.recursion_limit=100000 + +; Enables or disables JIT compilation of patterns. This requires the PCRE +; library to be compiled with JIT support. +;pcre.jit=1 + +[Pdo] +; Whether to pool ODBC connections. Can be one of "strict", "relaxed" or "off" +; http://php.net/pdo-odbc.connection-pooling +;pdo_odbc.connection_pooling=strict + +;pdo_odbc.db2_instance_name + +[Pdo_mysql] +; Default socket name for local MySQL connects. If empty, uses the built-in +; MySQL defaults. +pdo_mysql.default_socket= + +[Phar] +; http://php.net/phar.readonly +;phar.readonly = On + +; http://php.net/phar.require-hash +;phar.require_hash = On + +;phar.cache_list = + +[mail function] +; For Win32 only. +; http://php.net/smtp +SMTP = localhost +; http://php.net/smtp-port +smtp_port = 25 + +; For Win32 only. +; http://php.net/sendmail-from +;sendmail_from = me@example.com + +; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). +; http://php.net/sendmail-path +;sendmail_path = + +; Force the addition of the specified parameters to be passed as extra parameters +; to the sendmail binary. These parameters will always replace the value of +; the 5th parameter to mail(). +;mail.force_extra_parameters = + +; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename +mail.add_x_header = Off + +; The path to a log file that will log all mail() calls. Log entries include +; the full path of the script, line number, To address and headers. +;mail.log = +; Log mail to syslog (Event Log on Windows). +;mail.log = syslog + +[ODBC] +; http://php.net/odbc.default-db +;odbc.default_db = Not yet implemented + +; http://php.net/odbc.default-user +;odbc.default_user = Not yet implemented + +; http://php.net/odbc.default-pw +;odbc.default_pw = Not yet implemented + +; Controls the ODBC cursor model. +; Default: SQL_CURSOR_STATIC (default). +;odbc.default_cursortype + +; Allow or prevent persistent links. +; http://php.net/odbc.allow-persistent +odbc.allow_persistent = On + +; Check that a connection is still valid before reuse. +; http://php.net/odbc.check-persistent +odbc.check_persistent = On + +; Maximum number of persistent links. -1 means no limit. +; http://php.net/odbc.max-persistent +odbc.max_persistent = -1 + +; Maximum number of links (persistent + non-persistent). -1 means no limit. +; http://php.net/odbc.max-links +odbc.max_links = -1 + +; Handling of LONG fields. Returns number of bytes to variables. 0 means +; passthru. +; http://php.net/odbc.defaultlrl +odbc.defaultlrl = 4096 + +; Handling of binary data. 0 means passthru, 1 return as is, 2 convert to char. +; See the documentation on odbc_binmode and odbc_longreadlen for an explanation +; of odbc.defaultlrl and odbc.defaultbinmode +; http://php.net/odbc.defaultbinmode +odbc.defaultbinmode = 1 + +[MySQLi] + +; Maximum number of persistent links. -1 means no limit. +; http://php.net/mysqli.max-persistent +mysqli.max_persistent = -1 + +; Allow accessing, from PHP's perspective, local files with LOAD DATA statements +; http://php.net/mysqli.allow_local_infile +;mysqli.allow_local_infile = On + +; Allow or prevent persistent links. +; http://php.net/mysqli.allow-persistent +mysqli.allow_persistent = On + +; Maximum number of links. -1 means no limit. +; http://php.net/mysqli.max-links +mysqli.max_links = -1 + +; Default port number for mysqli_connect(). If unset, mysqli_connect() will use +; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the +; compile-time value defined MYSQL_PORT (in that order). Win32 will only look +; at MYSQL_PORT. +; http://php.net/mysqli.default-port +mysqli.default_port = 3306 + +; Default socket name for local MySQL connects. If empty, uses the built-in +; MySQL defaults. +; http://php.net/mysqli.default-socket +mysqli.default_socket = + +; Default host for mysqli_connect() (doesn't apply in safe mode). +; http://php.net/mysqli.default-host +mysqli.default_host = + +; Default user for mysqli_connect() (doesn't apply in safe mode). +; http://php.net/mysqli.default-user +mysqli.default_user = + +; Default password for mysqli_connect() (doesn't apply in safe mode). +; Note that this is generally a *bad* idea to store passwords in this file. +; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw") +; and reveal this password! And of course, any users with read access to this +; file will be able to reveal the password as well. +; http://php.net/mysqli.default-pw +mysqli.default_pw = + +; Allow or prevent reconnect +mysqli.reconnect = Off + +[mysqlnd] +; Enable / Disable collection of general statistics by mysqlnd which can be +; used to tune and monitor MySQL operations. +mysqlnd.collect_statistics = On + +; Enable / Disable collection of memory usage statistics by mysqlnd which can be +; used to tune and monitor MySQL operations. +mysqlnd.collect_memory_statistics = Off + +; Records communication from all extensions using mysqlnd to the specified log +; file. +; http://php.net/mysqlnd.debug +;mysqlnd.debug = + +; Defines which queries will be logged. +;mysqlnd.log_mask = 0 + +; Default size of the mysqlnd memory pool, which is used by result sets. +;mysqlnd.mempool_default_size = 16000 + +; Size of a pre-allocated buffer used when sending commands to MySQL in bytes. +;mysqlnd.net_cmd_buffer_size = 2048 + +; Size of a pre-allocated buffer used for reading data sent by the server in +; bytes. +;mysqlnd.net_read_buffer_size = 32768 + +; Timeout for network requests in seconds. +;mysqlnd.net_read_timeout = 31536000 + +; SHA-256 Authentication Plugin related. File with the MySQL server public RSA +; key. +;mysqlnd.sha256_server_public_key = + +[OCI8] + +; Connection: Enables privileged connections using external +; credentials (OCI_SYSOPER, OCI_SYSDBA) +; http://php.net/oci8.privileged-connect +;oci8.privileged_connect = Off + +; Connection: The maximum number of persistent OCI8 connections per +; process. Using -1 means no limit. +; http://php.net/oci8.max-persistent +;oci8.max_persistent = -1 + +; Connection: The maximum number of seconds a process is allowed to +; maintain an idle persistent connection. Using -1 means idle +; persistent connections will be maintained forever. +; http://php.net/oci8.persistent-timeout +;oci8.persistent_timeout = -1 + +; Connection: The number of seconds that must pass before issuing a +; ping during oci_pconnect() to check the connection validity. When +; set to 0, each oci_pconnect() will cause a ping. Using -1 disables +; pings completely. +; http://php.net/oci8.ping-interval +;oci8.ping_interval = 60 + +; Connection: Set this to a user chosen connection class to be used +; for all pooled server requests with Oracle 11g Database Resident +; Connection Pooling (DRCP). To use DRCP, this value should be set to +; the same string for all web servers running the same application, +; the database pool must be configured, and the connection string must +; specify to use a pooled server. +;oci8.connection_class = + +; High Availability: Using On lets PHP receive Fast Application +; Notification (FAN) events generated when a database node fails. The +; database must also be configured to post FAN events. +;oci8.events = Off + +; Tuning: This option enables statement caching, and specifies how +; many statements to cache. Using 0 disables statement caching. +; http://php.net/oci8.statement-cache-size +;oci8.statement_cache_size = 20 + +; Tuning: Enables statement prefetching and sets the default number of +; rows that will be fetched automatically after statement execution. +; http://php.net/oci8.default-prefetch +;oci8.default_prefetch = 100 + +; Compatibility. Using On means oci_close() will not close +; oci_connect() and oci_new_connect() connections. +; http://php.net/oci8.old-oci-close-semantics +;oci8.old_oci_close_semantics = Off + +[PostgreSQL] +; Allow or prevent persistent links. +; http://php.net/pgsql.allow-persistent +pgsql.allow_persistent = On + +; Detect broken persistent links always with pg_pconnect(). +; Auto reset feature requires a little overheads. +; http://php.net/pgsql.auto-reset-persistent +pgsql.auto_reset_persistent = Off + +; Maximum number of persistent links. -1 means no limit. +; http://php.net/pgsql.max-persistent +pgsql.max_persistent = -1 + +; Maximum number of links (persistent+non persistent). -1 means no limit. +; http://php.net/pgsql.max-links +pgsql.max_links = -1 + +; Ignore PostgreSQL backends Notice message or not. +; Notice message logging require a little overheads. +; http://php.net/pgsql.ignore-notice +pgsql.ignore_notice = 0 + +; Log PostgreSQL backends Notice message or not. +; Unless pgsql.ignore_notice=0, module cannot log notice message. +; http://php.net/pgsql.log-notice +pgsql.log_notice = 0 + +[bcmath] +; Number of decimal digits for all bcmath functions. +; http://php.net/bcmath.scale +bcmath.scale = 0 + +[browscap] +; http://php.net/browscap +;browscap = extra/browscap.ini + +[Session] +; Handler used to store/retrieve data. +; http://php.net/session.save-handler +session.save_handler = files + +; Argument passed to save_handler. In the case of files, this is the path +; where data files are stored. Note: Windows users have to change this +; variable in order to use PHP's session functions. +; +; The path can be defined as: +; +; session.save_path = "N;/path" +; +; where N is an integer. Instead of storing all the session files in +; /path, what this will do is use subdirectories N-levels deep, and +; store the session data in those directories. This is useful if +; your OS has problems with many files in one directory, and is +; a more efficient layout for servers that handle many sessions. +; +; NOTE 1: PHP will not create this directory structure automatically. +; You can use the script in the ext/session dir for that purpose. +; NOTE 2: See the section on garbage collection below if you choose to +; use subdirectories for session storage +; +; The file storage module creates files using mode 600 by default. +; You can change that by using +; +; session.save_path = "N;MODE;/path" +; +; where MODE is the octal representation of the mode. Note that this +; does not overwrite the process's umask. +; http://php.net/session.save-path +;session.save_path = "/tmp" + +; Whether to use strict session mode. +; Strict session mode does not accept an uninitialized session ID, and +; regenerates the session ID if the browser sends an uninitialized session ID. +; Strict mode protects applications from session fixation via a session adoption +; vulnerability. It is disabled by default for maximum compatibility, but +; enabling it is encouraged. +; https://wiki.php.net/rfc/strict_sessions +session.use_strict_mode = 0 + +; Whether to use cookies. +; http://php.net/session.use-cookies +session.use_cookies = 1 + +; http://php.net/session.cookie-secure +;session.cookie_secure = + +; This option forces PHP to fetch and use a cookie for storing and maintaining +; the session id. We encourage this operation as it's very helpful in combating +; session hijacking when not specifying and managing your own session id. It is +; not the be-all and end-all of session hijacking defense, but it's a good start. +; http://php.net/session.use-only-cookies +session.use_only_cookies = 1 + +; Name of the session (used as cookie name). +; http://php.net/session.name +session.name = PHPSESSID + +; Initialize session on request startup. +; http://php.net/session.auto-start +session.auto_start = 0 + +; Lifetime in seconds of cookie or, if 0, until browser is restarted. +; http://php.net/session.cookie-lifetime +session.cookie_lifetime = 0 + +; The path for which the cookie is valid. +; http://php.net/session.cookie-path +session.cookie_path = / + +; The domain for which the cookie is valid. +; http://php.net/session.cookie-domain +session.cookie_domain = + +; Whether or not to add the httpOnly flag to the cookie, which makes it +; inaccessible to browser scripting languages such as JavaScript. +; http://php.net/session.cookie-httponly +session.cookie_httponly = + +; Add SameSite attribute to cookie to help mitigate Cross-Site Request Forgery (CSRF/XSRF) +; Current valid values are "Strict", "Lax" or "None". When using "None", +; make sure to include the quotes, as `none` is interpreted like `false` in ini files. +; https://tools.ietf.org/html/draft-west-first-party-cookies-07 +session.cookie_samesite = + +; Handler used to serialize data. php is the standard serializer of PHP. +; http://php.net/session.serialize-handler +session.serialize_handler = php + +; Defines the probability that the 'garbage collection' process is started on every +; session initialization. The probability is calculated by using gc_probability/gc_divisor, +; e.g. 1/100 means there is a 1% chance that the GC process starts on each request. +; Default Value: 1 +; Development Value: 1 +; Production Value: 1 +; http://php.net/session.gc-probability +session.gc_probability = 1 + +; Defines the probability that the 'garbage collection' process is started on every +; session initialization. The probability is calculated by using gc_probability/gc_divisor, +; e.g. 1/100 means there is a 1% chance that the GC process starts on each request. +; For high volume production servers, using a value of 1000 is a more efficient approach. +; Default Value: 100 +; Development Value: 1000 +; Production Value: 1000 +; http://php.net/session.gc-divisor +session.gc_divisor = 1000 + +; After this number of seconds, stored data will be seen as 'garbage' and +; cleaned up by the garbage collection process. +; http://php.net/session.gc-maxlifetime +session.gc_maxlifetime = 1440 + +; NOTE: If you are using the subdirectory option for storing session files +; (see session.save_path above), then garbage collection does *not* +; happen automatically. You will need to do your own garbage +; collection through a shell script, cron entry, or some other method. +; For example, the following script is the equivalent of setting +; session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes): +; find /path/to/sessions -cmin +24 -type f | xargs rm + +; Check HTTP Referer to invalidate externally stored URLs containing ids. +; HTTP_REFERER has to contain this substring for the session to be +; considered as valid. +; http://php.net/session.referer-check +session.referer_check = + +; Set to {nocache,private,public,} to determine HTTP caching aspects +; or leave this empty to avoid sending anti-caching headers. +; http://php.net/session.cache-limiter +session.cache_limiter = nocache + +; Document expires after n minutes. +; http://php.net/session.cache-expire +session.cache_expire = 180 + +; trans sid support is disabled by default. +; Use of trans sid may risk your users' security. +; Use this option with caution. +; - User may send URL contains active session ID +; to other person via. email/irc/etc. +; - URL that contains active session ID may be stored +; in publicly accessible computer. +; - User may access your site with the same session ID +; always using URL stored in browser's history or bookmarks. +; http://php.net/session.use-trans-sid +session.use_trans_sid = 0 + +; Set session ID character length. This value could be between 22 to 256. +; Shorter length than default is supported only for compatibility reason. +; Users should use 32 or more chars. +; http://php.net/session.sid-length +; Default Value: 32 +; Development Value: 26 +; Production Value: 26 +session.sid_length = 26 + +; The URL rewriter will look for URLs in a defined set of HTML tags. +;
is special; if you include them here, the rewriter will +; add a hidden field with the info which is otherwise appended +; to URLs. tag's action attribute URL will not be modified +; unless it is specified. +; Note that all valid entries require a "=", even if no value follows. +; Default Value: "a=href,area=href,frame=src,form=" +; Development Value: "a=href,area=href,frame=src,form=" +; Production Value: "a=href,area=href,frame=src,form=" +; http://php.net/url-rewriter.tags +session.trans_sid_tags = "a=href,area=href,frame=src,form=" + +; URL rewriter does not rewrite absolute URLs by default. +; To enable rewrites for absolute paths, target hosts must be specified +; at RUNTIME. i.e. use ini_set() +; tags is special. PHP will check action attribute's URL regardless +; of session.trans_sid_tags setting. +; If no host is defined, HTTP_HOST will be used for allowed host. +; Example value: php.net,www.php.net,wiki.php.net +; Use "," for multiple hosts. No spaces are allowed. +; Default Value: "" +; Development Value: "" +; Production Value: "" +;session.trans_sid_hosts="" + +; Define how many bits are stored in each character when converting +; the binary hash data to something readable. +; Possible values: +; 4 (4 bits: 0-9, a-f) +; 5 (5 bits: 0-9, a-v) +; 6 (6 bits: 0-9, a-z, A-Z, "-", ",") +; Default Value: 4 +; Development Value: 5 +; Production Value: 5 +; http://php.net/session.hash-bits-per-character +session.sid_bits_per_character = 5 + +; Enable upload progress tracking in $_SESSION +; Default Value: On +; Development Value: On +; Production Value: On +; http://php.net/session.upload-progress.enabled +;session.upload_progress.enabled = On + +; Cleanup the progress information as soon as all POST data has been read +; (i.e. upload completed). +; Default Value: On +; Development Value: On +; Production Value: On +; http://php.net/session.upload-progress.cleanup +;session.upload_progress.cleanup = On + +; A prefix used for the upload progress key in $_SESSION +; Default Value: "upload_progress_" +; Development Value: "upload_progress_" +; Production Value: "upload_progress_" +; http://php.net/session.upload-progress.prefix +;session.upload_progress.prefix = "upload_progress_" + +; The index name (concatenated with the prefix) in $_SESSION +; containing the upload progress information +; Default Value: "PHP_SESSION_UPLOAD_PROGRESS" +; Development Value: "PHP_SESSION_UPLOAD_PROGRESS" +; Production Value: "PHP_SESSION_UPLOAD_PROGRESS" +; http://php.net/session.upload-progress.name +;session.upload_progress.name = "PHP_SESSION_UPLOAD_PROGRESS" + +; How frequently the upload progress should be updated. +; Given either in percentages (per-file), or in bytes +; Default Value: "1%" +; Development Value: "1%" +; Production Value: "1%" +; http://php.net/session.upload-progress.freq +;session.upload_progress.freq = "1%" + +; The minimum delay between updates, in seconds +; Default Value: 1 +; Development Value: 1 +; Production Value: 1 +; http://php.net/session.upload-progress.min-freq +;session.upload_progress.min_freq = "1" + +; Only write session data when session data is changed. Enabled by default. +; http://php.net/session.lazy-write +;session.lazy_write = On + +[Assertion] +; Switch whether to compile assertions at all (to have no overhead at run-time) +; -1: Do not compile at all +; 0: Jump over assertion at run-time +; 1: Execute assertions +; Changing from or to a negative value is only possible in php.ini! (For turning assertions on and off at run-time, see assert.active, when zend.assertions = 1) +; Default Value: 1 +; Development Value: 1 +; Production Value: -1 +; http://php.net/zend.assertions +zend.assertions = -1 + +; Assert(expr); active by default. +; http://php.net/assert.active +;assert.active = On + +; Throw an AssertionError on failed assertions +; http://php.net/assert.exception +;assert.exception = On + +; Issue a PHP warning for each failed assertion. (Overridden by assert.exception if active) +; http://php.net/assert.warning +;assert.warning = On + +; Don't bail out by default. +; http://php.net/assert.bail +;assert.bail = Off + +; User-function to be called if an assertion fails. +; http://php.net/assert.callback +;assert.callback = 0 + +; Eval the expression with current error_reporting(). Set to true if you want +; error_reporting(0) around the eval(). +; http://php.net/assert.quiet-eval +;assert.quiet_eval = 0 + +[COM] +; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs +; http://php.net/com.typelib-file +;com.typelib_file = + +; allow Distributed-COM calls +; http://php.net/com.allow-dcom +;com.allow_dcom = true + +; autoregister constants of a component's typlib on com_load() +; http://php.net/com.autoregister-typelib +;com.autoregister_typelib = true + +; register constants casesensitive +; http://php.net/com.autoregister-casesensitive +;com.autoregister_casesensitive = false + +; show warnings on duplicate constant registrations +; http://php.net/com.autoregister-verbose +;com.autoregister_verbose = true + +; The default character set code-page to use when passing strings to and from COM objects. +; Default: system ANSI code page +;com.code_page= + +[mbstring] +; language for internal character representation. +; This affects mb_send_mail() and mbstring.detect_order. +; http://php.net/mbstring.language +;mbstring.language = Japanese + +; Use of this INI entry is deprecated, use global internal_encoding instead. +; internal/script encoding. +; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*) +; If empty, default_charset or internal_encoding or iconv.internal_encoding is used. +; The precedence is: default_charset < internal_encoding < iconv.internal_encoding +;mbstring.internal_encoding = + +; Use of this INI entry is deprecated, use global input_encoding instead. +; http input encoding. +; mbstring.encoding_translation = On is needed to use this setting. +; If empty, default_charset or input_encoding or mbstring.input is used. +; The precedence is: default_charset < input_encoding < mbstring.http_input +; http://php.net/mbstring.http-input +;mbstring.http_input = + +; Use of this INI entry is deprecated, use global output_encoding instead. +; http output encoding. +; mb_output_handler must be registered as output buffer to function. +; If empty, default_charset or output_encoding or mbstring.http_output is used. +; The precedence is: default_charset < output_encoding < mbstring.http_output +; To use an output encoding conversion, mbstring's output handler must be set +; otherwise output encoding conversion cannot be performed. +; http://php.net/mbstring.http-output +;mbstring.http_output = + +; enable automatic encoding translation according to +; mbstring.internal_encoding setting. Input chars are +; converted to internal encoding by setting this to On. +; Note: Do _not_ use automatic encoding translation for +; portable libs/applications. +; http://php.net/mbstring.encoding-translation +;mbstring.encoding_translation = Off + +; automatic encoding detection order. +; "auto" detect order is changed according to mbstring.language +; http://php.net/mbstring.detect-order +;mbstring.detect_order = auto + +; substitute_character used when character cannot be converted +; one from another +; http://php.net/mbstring.substitute-character +;mbstring.substitute_character = none + +; overload(replace) single byte functions by mbstring functions. +; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(), +; etc. Possible values are 0,1,2,4 or combination of them. +; For example, 7 for overload everything. +; 0: No overload +; 1: Overload mail() function +; 2: Overload str*() functions +; 4: Overload ereg*() functions +; http://php.net/mbstring.func-overload +;mbstring.func_overload = 0 + +; enable strict encoding detection. +; Default: Off +;mbstring.strict_detection = On + +; This directive specifies the regex pattern of content types for which mb_output_handler() +; is activated. +; Default: mbstring.http_output_conv_mimetype=^(text/|application/xhtml\+xml) +;mbstring.http_output_conv_mimetype= + +; This directive specifies maximum stack depth for mbstring regular expressions. It is similar +; to the pcre.recursion_limit for PCRE. +; Default: 100000 +;mbstring.regex_stack_limit=100000 + +; This directive specifies maximum retry count for mbstring regular expressions. It is similar +; to the pcre.backtrack_limit for PCRE. +; Default: 1000000 +;mbstring.regex_retry_limit=1000000 + +[gd] +; Tell the jpeg decode to ignore warnings and try to create +; a gd image. The warning will then be displayed as notices +; disabled by default +; http://php.net/gd.jpeg-ignore-warning +;gd.jpeg_ignore_warning = 1 + +[exif] +; Exif UNICODE user comments are handled as UCS-2BE/UCS-2LE and JIS as JIS. +; With mbstring support this will automatically be converted into the encoding +; given by corresponding encode setting. When empty mbstring.internal_encoding +; is used. For the decode settings you can distinguish between motorola and +; intel byte order. A decode setting cannot be empty. +; http://php.net/exif.encode-unicode +;exif.encode_unicode = ISO-8859-15 + +; http://php.net/exif.decode-unicode-motorola +;exif.decode_unicode_motorola = UCS-2BE + +; http://php.net/exif.decode-unicode-intel +;exif.decode_unicode_intel = UCS-2LE + +; http://php.net/exif.encode-jis +;exif.encode_jis = + +; http://php.net/exif.decode-jis-motorola +;exif.decode_jis_motorola = JIS + +; http://php.net/exif.decode-jis-intel +;exif.decode_jis_intel = JIS + +[Tidy] +; The path to a default tidy configuration file to use when using tidy +; http://php.net/tidy.default-config +;tidy.default_config = /usr/local/lib/php/default.tcfg + +; Should tidy clean and repair output automatically? +; WARNING: Do not use this option if you are generating non-html content +; such as dynamic images +; http://php.net/tidy.clean-output +tidy.clean_output = Off + +[soap] +; Enables or disables WSDL caching feature. +; http://php.net/soap.wsdl-cache-enabled +soap.wsdl_cache_enabled=1 + +; Sets the directory name where SOAP extension will put cache files. +; http://php.net/soap.wsdl-cache-dir +soap.wsdl_cache_dir="/tmp" + +; (time to live) Sets the number of second while cached file will be used +; instead of original one. +; http://php.net/soap.wsdl-cache-ttl +soap.wsdl_cache_ttl=86400 + +; Sets the size of the cache limit. (Max. number of WSDL files to cache) +soap.wsdl_cache_limit = 5 + +[sysvshm] +; A default size of the shared memory segment +;sysvshm.init_mem = 10000 + +[ldap] +; Sets the maximum number of open links or -1 for unlimited. +ldap.max_links = -1 + +[dba] +;dba.default_handler= + +[opcache] +; Determines if Zend OPCache is enabled +;opcache.enable=1 + +; Determines if Zend OPCache is enabled for the CLI version of PHP +;opcache.enable_cli=0 + +; The OPcache shared memory storage size. +;opcache.memory_consumption=128 + +; The amount of memory for interned strings in Mbytes. +;opcache.interned_strings_buffer=8 + +; The maximum number of keys (scripts) in the OPcache hash table. +; Only numbers between 200 and 1000000 are allowed. +;opcache.max_accelerated_files=10000 + +; The maximum percentage of "wasted" memory until a restart is scheduled. +;opcache.max_wasted_percentage=5 + +; When this directive is enabled, the OPcache appends the current working +; directory to the script key, thus eliminating possible collisions between +; files with the same name (basename). Disabling the directive improves +; performance, but may break existing applications. +;opcache.use_cwd=1 + +; When disabled, you must reset the OPcache manually or restart the +; webserver for changes to the filesystem to take effect. +;opcache.validate_timestamps=1 + +; How often (in seconds) to check file timestamps for changes to the shared +; memory storage allocation. ("1" means validate once per second, but only +; once per request. "0" means always validate) +;opcache.revalidate_freq=2 + +; Enables or disables file search in include_path optimization +;opcache.revalidate_path=0 + +; If disabled, all PHPDoc comments are dropped from the code to reduce the +; size of the optimized code. +;opcache.save_comments=1 + +; Allow file existence override (file_exists, etc.) performance feature. +;opcache.enable_file_override=0 + +; A bitmask, where each bit enables or disables the appropriate OPcache +; passes +;opcache.optimization_level=0x7FFFBFFF + +;opcache.dups_fix=0 + +; The location of the OPcache blacklist file (wildcards allowed). +; Each OPcache blacklist file is a text file that holds the names of files +; that should not be accelerated. The file format is to add each filename +; to a new line. The filename may be a full path or just a file prefix +; (i.e., /var/www/x blacklists all the files and directories in /var/www +; that start with 'x'). Line starting with a ; are ignored (comments). +;opcache.blacklist_filename= + +; Allows exclusion of large files from being cached. By default all files +; are cached. +;opcache.max_file_size=0 + +; Check the cache checksum each N requests. +; The default value of "0" means that the checks are disabled. +;opcache.consistency_checks=0 + +; How long to wait (in seconds) for a scheduled restart to begin if the cache +; is not being accessed. +;opcache.force_restart_timeout=180 + +; OPcache error_log file name. Empty string assumes "stderr". +;opcache.error_log= + +; All OPcache errors go to the Web server log. +; By default, only fatal errors (level 0) or errors (level 1) are logged. +; You can also enable warnings (level 2), info messages (level 3) or +; debug messages (level 4). +;opcache.log_verbosity_level=1 + +; Preferred Shared Memory back-end. Leave empty and let the system decide. +;opcache.preferred_memory_model= + +; Protect the shared memory from unexpected writing during script execution. +; Useful for internal debugging only. +;opcache.protect_memory=0 + +; Allows calling OPcache API functions only from PHP scripts which path is +; started from specified string. The default "" means no restriction +;opcache.restrict_api= + +; Mapping base of shared memory segments (for Windows only). All the PHP +; processes have to map shared memory into the same address space. This +; directive allows to manually fix the "Unable to reattach to base address" +; errors. +;opcache.mmap_base= + +; Facilitates multiple OPcache instances per user (for Windows only). All PHP +; processes with the same cache ID and user share an OPcache instance. +;opcache.cache_id= + +; Enables and sets the second level cache directory. +; It should improve performance when SHM memory is full, at server restart or +; SHM reset. The default "" disables file based caching. +;opcache.file_cache= + +; Enables or disables opcode caching in shared memory. +;opcache.file_cache_only=0 + +; Enables or disables checksum validation when script loaded from file cache. +;opcache.file_cache_consistency_checks=1 + +; Implies opcache.file_cache_only=1 for a certain process that failed to +; reattach to the shared memory (for Windows only). Explicitly enabled file +; cache is required. +;opcache.file_cache_fallback=1 + +; Enables or disables copying of PHP code (text segment) into HUGE PAGES. +; This should improve performance, but requires appropriate OS configuration. +;opcache.huge_code_pages=1 + +; Validate cached file permissions. +;opcache.validate_permission=0 + +; Prevent name collisions in chroot'ed environment. +;opcache.validate_root=0 + +; If specified, it produces opcode dumps for debugging different stages of +; optimizations. +;opcache.opt_debug_level=0 + +; Specifies a PHP script that is going to be compiled and executed at server +; start-up. +; http://php.net/opcache.preload +;opcache.preload= + +; Preloading code as root is not allowed for security reasons. This directive +; facilitates to let the preloading to be run as another user. +; http://php.net/opcache.preload_user +;opcache.preload_user= + +; Prevents caching files that are less than this number of seconds old. It +; protects from caching of incompletely updated files. In case all file updates +; on your site are atomic, you may increase performance by setting it to "0". +;opcache.file_update_protection=2 + +; Absolute path used to store shared lockfiles (for *nix only). +;opcache.lockfile_path=/tmp + +[curl] +; A default value for the CURLOPT_CAINFO option. This is required to be an +; absolute path. +;curl.cainfo = + +[openssl] +; The location of a Certificate Authority (CA) file on the local filesystem +; to use when verifying the identity of SSL/TLS peers. Most users should +; not specify a value for this directive as PHP will attempt to use the +; OS-managed cert stores in its absence. If specified, this value may still +; be overridden on a per-stream basis via the "cafile" SSL stream context +; option. +;openssl.cafile= + +; If openssl.cafile is not specified or if the CA file is not found, the +; directory pointed to by openssl.capath is searched for a suitable +; certificate. This value must be a correctly hashed certificate directory. +; Most users should not specify a value for this directive as PHP will +; attempt to use the OS-managed cert stores in its absence. If specified, +; this value may still be overridden on a per-stream basis via the "capath" +; SSL stream context option. +;openssl.capath= + +[ffi] +; FFI API restriction. Possible values: +; "preload" - enabled in CLI scripts and preloaded files (default) +; "false" - always disabled +; "true" - always enabled +;ffi.enable=preload + +; List of headers files to preload, wildcard patterns allowed. +;ffi.preload= \ No newline at end of file From cbb10e171c1fd91c6c85594ad362139398043357 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 28 Aug 2023 13:21:12 +0700 Subject: [PATCH 109/185] getoverdue by gantt and project --- app/Http/Controllers/ProjectController.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index ffbe3fa..944b7ad 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -470,11 +470,20 @@ class ProjectController extends Controller if(!$result) return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); //TODO possible overdue bug - if(isset($payload['till_date'])) - $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); - else - $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); - + if(isset($payload['till_date'])) { + if (isset($payload['scurve'])) { + $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); + } else { + $overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); + } + } + else { + if (isset($payload['scurve'])) { + $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); + } else { + $overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); + } + } $result->overdueActivities = $overdueActivities; return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); From cb3cd6cb1f0c24b7578fe447ea74cde8d1b60489 Mon Sep 17 00:00:00 2001 From: ardhi Date: Mon, 28 Aug 2023 13:55:01 +0700 Subject: [PATCH 110/185] bug fix isset waypoint on map monitoring --- app/Http/Controllers/MapMonitoringController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index cd68d20..486e3be 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -54,8 +54,8 @@ class MapMonitoringController extends Controller $waypoint = DB::table('m_waypoint')->select('lat', 'lon', 'wptime')->where('user_id', $presensi->user_id)->orderBy('wptime', 'DESC')->first(); $tmp[] = array( 'user_id' => $presensi->user_id, - 'wp_lat' => isset($waypoint) ? $waypoint->lat : '-', - 'wp_lon' => isset($waypoint) ? $waypoint->lon : '-', + 'wp_lat' => isset($waypoint) ? $waypoint->lat : null, + 'wp_lon' => isset($waypoint) ? $waypoint->lon : null, 'wp_time' => isset($waypoint) ? $waypoint->wptime : '-', 'clock_in' => $presensi->clock_in, 'clock_out' => $presensi->clock_out, From 39573779091939714c0036530ea1cc9a096af040 Mon Sep 17 00:00:00 2001 From: ardhi Date: Mon, 28 Aug 2023 13:56:00 +0700 Subject: [PATCH 111/185] bug fix isset waypoint on map monitoring --- app/Http/Controllers/MapMonitoringController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index 486e3be..c98f5c2 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -56,7 +56,7 @@ class MapMonitoringController extends Controller 'user_id' => $presensi->user_id, 'wp_lat' => isset($waypoint) ? $waypoint->lat : null, 'wp_lon' => isset($waypoint) ? $waypoint->lon : null, - 'wp_time' => isset($waypoint) ? $waypoint->wptime : '-', + 'wp_time' => isset($waypoint) ? $waypoint->wptime : null, 'clock_in' => $presensi->clock_in, 'clock_out' => $presensi->clock_out, 'clock_in_lat' => $presensi->clock_in_lat, From a9838aa5fc4b9bb58c58882ae9d402fc3e7423cf Mon Sep 17 00:00:00 2001 From: ardhi Date: Mon, 28 Aug 2023 14:08:18 +0700 Subject: [PATCH 112/185] bug fix isset waypoint on map monitoring --- app/Http/Controllers/MapMonitoringController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/MapMonitoringController.php b/app/Http/Controllers/MapMonitoringController.php index c98f5c2..5c17475 100644 --- a/app/Http/Controllers/MapMonitoringController.php +++ b/app/Http/Controllers/MapMonitoringController.php @@ -54,9 +54,9 @@ class MapMonitoringController extends Controller $waypoint = DB::table('m_waypoint')->select('lat', 'lon', 'wptime')->where('user_id', $presensi->user_id)->orderBy('wptime', 'DESC')->first(); $tmp[] = array( 'user_id' => $presensi->user_id, - 'wp_lat' => isset($waypoint) ? $waypoint->lat : null, - 'wp_lon' => isset($waypoint) ? $waypoint->lon : null, - 'wp_time' => isset($waypoint) ? $waypoint->wptime : null, + 'wp_lat' => isset($waypoint) ? $waypoint->lat : $presensi->clock_in_lat, + 'wp_lon' => isset($waypoint) ? $waypoint->lon : $presensi->clock_in_lng, + 'wp_time' => isset($waypoint) ? $waypoint->wptime : $presensi->clock_in, 'clock_in' => $presensi->clock_in, 'clock_out' => $presensi->clock_out, 'clock_in_lat' => $presensi->clock_in_lat, From 0b13e01b4928233bbdaf87609356de3af1bf5374 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 28 Aug 2023 14:59:51 +0700 Subject: [PATCH 113/185] fix schedule dashboard project --- app/Http/Controllers/ProjectController.php | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 944b7ad..0a37a92 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -448,13 +448,27 @@ class ProjectController extends Controller // dd($result->header->start_date); $ganttId = $gantt['last_gantt_id']; - $startDate = Activity::where('version_gantt_id', $ganttId) - ->orderBy('start_date') - ->value('start_date'); + $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); - $endDate = Activity::where('version_gantt_id', $ganttId) - ->orderByDesc('end_date') - ->value('end_date'); + if ($actualStartExist) { + $startDate = Activity::where('version_gantt_id', $ganttId) + ->orderBy('actual_start') + ->value('start_date'); + } else { + $startDate = Activity::where('version_gantt_id', $ganttId) + ->orderBy('start_date') + ->value('start_date'); + } + if ($actualEndExist) { + $endDate = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('actual_end') + ->value('end_date'); + } else { + $endDate = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('end_date') + ->value('end_date'); + } $result->header->start_date = $startDate; $result->header->end_date = $endDate; return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); From f32f16d03851d266eebea74296b26c0850916ab1 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 28 Aug 2023 16:32:48 +0700 Subject: [PATCH 114/185] fix till date --- app/Http/Controllers/ProjectController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 0a37a92..3a204d7 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -484,11 +484,14 @@ class ProjectController extends Controller if(!$result) return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); //TODO possible overdue bug + $endDate = Activity::where('proyek_id', $payload['id']) + ->orderByDesc('end_date') + ->value('end_date'); if(isset($payload['till_date'])) { if (isset($payload['scurve'])) { - $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); + $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); } else { - $overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); + $overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); } } else { From d383f5c1d847a5738e27b0f65fd0824b4121e350 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 28 Aug 2023 18:13:41 +0700 Subject: [PATCH 115/185] update method endpoint --- app/Http/Controllers/Controller.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 90e141a..c131d43 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -44,9 +44,8 @@ class Controller extends BaseController $userProyek = UserToProyek::from('assign_hr_to_proyek AS ' . $alias); $userProyek = $userProyek->where([ ['is_customer', true], - // $condition['user_id']['user_id'] - ['user_id', 1561] - ])->select('m_proyek.*', 'm_type_proyek.name AS nama_type_proyek'); + ['user_id', $condition['user_id']['user_id']] + ])->select('m_proyek.*', 'm_type_proyek.name AS join_second_name'); if (isset($condition['joins'])) { $no = 0; From 9fb9744dd5cf564af7c69f3458953995ec5d3e63 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 29 Aug 2023 10:34:43 +0700 Subject: [PATCH 116/185] update bcwp --- app/Helpers/MasterFunctionsHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 6d75174..5c9764f 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -428,7 +428,7 @@ class MasterFunctionsHelper } $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $totalBCWP; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, @@ -723,7 +723,7 @@ class MasterFunctionsHelper } $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $totalBCWP; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, From ff353fbf53707f58dffd1a6f642849c9dcbcd416 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 29 Aug 2023 14:08:50 +0700 Subject: [PATCH 117/185] scurve queue --- app/Http/Controllers/ProjectController.php | 13 +++++-- app/Jobs/ProcessSCurve.php | 36 +++++++++++++++++++ .../2023_08_29_130624_create_jobs_table.php | 36 +++++++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 app/Jobs/ProcessSCurve.php create mode 100644 database/migrations/2023_08_29_130624_create_jobs_table.php diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 3a204d7..7478494 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -30,6 +30,7 @@ use Illuminate\Support\Facades\DB; use App\Helpers\MasterFunctionsHelper; use App\Models\ReportActivityMaterial; use Illuminate\Support\Facades\Artisan; +use App\Jobs\ProcessSCurve; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; @@ -328,9 +329,15 @@ class ProjectController extends Controller } public function sCurveCommand(Request $request){ - Artisan::call('calculate:scurve', [ - 'project_id' => $request->project_id - ]); + $project = Project::find($request->project_id); + + if ($project) { + dispatch(new ProcessSCurve($project)); + + return response()->json(['message' => 'S Curve calculation queued']); + } + + return response()->json(['message' => 'Project not found'], 404); } public function getLinearSCurve(Request $request){ diff --git a/app/Jobs/ProcessSCurve.php b/app/Jobs/ProcessSCurve.php new file mode 100644 index 0000000..fe07ab9 --- /dev/null +++ b/app/Jobs/ProcessSCurve.php @@ -0,0 +1,36 @@ +project = $project; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $data = MasterFunctionsHelper::CalculateSCurve($this->project->id); + + $this->project->scurve = json_encode($data); + $this->project->calculation_status = true; + $this->project->save(); + } +} diff --git a/database/migrations/2023_08_29_130624_create_jobs_table.php b/database/migrations/2023_08_29_130624_create_jobs_table.php new file mode 100644 index 0000000..1be9e8a --- /dev/null +++ b/database/migrations/2023_08_29_130624_create_jobs_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs'); + } +} From 427449bb26f4d468c8e119be35b8c7f722f5171c Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 29 Aug 2023 14:55:32 +0700 Subject: [PATCH 118/185] disable queue --- app/Http/Controllers/ProjectController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 7478494..48cb86e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -329,15 +329,18 @@ class ProjectController extends Controller } public function sCurveCommand(Request $request){ - $project = Project::find($request->project_id); + Artisan::call('calculate:scurve', [ + 'project_id' => $request->project_id + ]); + // $project = Project::find($request->project_id); - if ($project) { - dispatch(new ProcessSCurve($project)); + // if ($project) { + // dispatch(new ProcessSCurve($project)); - return response()->json(['message' => 'S Curve calculation queued']); - } + // return response()->json(['message' => 'S Curve calculation queued']); + // } - return response()->json(['message' => 'Project not found'], 404); + // return response()->json(['message' => 'Project not found'], 404); } public function getLinearSCurve(Request $request){ From bf63d4ac3b0e746b9e1d08533f596f6f1ed49d6c Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 30 Aug 2023 10:19:04 +0700 Subject: [PATCH 119/185] fix broadcast --- app/Http/Controllers/BroadcastController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/BroadcastController.php b/app/Http/Controllers/BroadcastController.php index 5bb223e..87eb02d 100644 --- a/app/Http/Controllers/BroadcastController.php +++ b/app/Http/Controllers/BroadcastController.php @@ -15,6 +15,12 @@ class BroadcastController extends Controller $data = $request->all(); $data['status_send'] = true; $data['created_by'] = $this->currentName; + if (isset($data['send_to_id'])) { + $idArray = $data['send_to_id']; + if (is_array($data['send_to_id'])) { + $data['send_to_id'] = implode(", ", $idArray); + } + } // dd($data); $result = Broadcast::create($data); if($result){ @@ -140,8 +146,10 @@ class BroadcastController extends Controller } break; - case 'user': - $user = User::where("id", $data['send_to_id'])->whereNotNull('fcm_token')->first(); + case 'users': + $idArray = explode(", ", $data['send_to_id']); + foreach ($idArray as $key => $value) { + $user = User::where("id", $value)->whereNotNull('fcm_token')->first(); if (isset($user)) { FCMService::send( $user->fcm_token, @@ -151,6 +159,7 @@ class BroadcastController extends Controller ] ); } + } break; default: From ab5fd49d37698ee06c16efc51a128866482b3a3e Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 30 Aug 2023 10:22:41 +0700 Subject: [PATCH 120/185] update post to get method --- app/Http/Controllers/Controller.php | 67 ---------------------- app/Http/Controllers/ProjectController.php | 25 +++++--- routes/web.php | 2 +- 3 files changed, 17 insertions(+), 77 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index c131d43..a77975b 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -37,73 +37,6 @@ class Controller extends BaseController $this->pathActivityDocument = config('assets.activity'); } - protected function setUpPayloadByUser($condition) - { - $alias = "utp"; - - $userProyek = UserToProyek::from('assign_hr_to_proyek AS ' . $alias); - $userProyek = $userProyek->where([ - ['is_customer', true], - ['user_id', $condition['user_id']['user_id']] - ])->select('m_proyek.*', 'm_type_proyek.name AS join_second_name'); - - if (isset($condition['joins'])) { - $no = 0; - foreach ($condition['joins'] as $join) { - $tableJoin = isset($join['name1']) ? $join['name1'] : $alias; - $tableName = $join['name']; - $columnJoin = $join['column_join']; // foreign key table sini - $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan - $columnResult = $join['column_results']; - - foreach ($columnResult as $sColumn) { - $userProyek = $userProyek->addSelect($tableName . "." . $sColumn . " as join_" . $this->listJoinAll[$no] . "_" . $sColumn); - } - $userProyek = $userProyek->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf); - $no++; - } - $userProyek->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id'); - } - - if (isset($condition['columns'])) { - $listWhere = $condition['columns']; - - $userProyek = $userProyek->where(function ($query) use ($listWhere, $alias) { - foreach ($listWhere as $where) { - $value = $where['value']; - if ($value && $value != "" && $value != " ") { - $column = $where['name']; - $operator = strtolower($where['logic_operator']); // like, =, <>, range - $value2 = isset($where['value1']) ? $where['value1'] : ""; - $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; - $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - } - } - }); - } - - if (isset($condition['group_column'])) { - $userProyek = $this->groupWhere($userProyek, $condition['group_column'], $alias); - } - - $data['count'] = clone $userProyek; - - if (isset($condition['paging'])) { - $userProyek = $userProyek->offset($condition['paging']['start'])->limit($condition['paging']['length']); - } - - if (isset($condition['orders'])) { - $orders = $condition['orders']; - $sortBy = $orders['ascending'] ? "ASC" : "DESC"; - $columnOrder = $orders['columns']; - foreach ($columnOrder as $column) { - $userProyek = $userProyek->orderBy($alias . "." . $column, $sortBy); - } - } - $data['userProyek'] = $userProyek; - return $data; - } - protected function setUpPayload($condition, $tableSelf) { $alias = "selfTable"; diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 7117d65..553a5dd 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -204,16 +204,23 @@ class ProjectController extends Controller DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); } - public function getByUser(Request $request) + public function getByUser($id) { - $payload = $request->all(); - $dataBuilder = $this->setUpPayloadByUser($payload); - $builder = $dataBuilder['userProyek']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - - return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + $alias = "utp"; + $userProyek = UserToProyek::query() + ->from('assign_hr_to_proyek AS ' . $alias) + ->where([ + ['is_customer', true], + ['user_id', $id] + ]) + ->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id') + ->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id') + ->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') + ->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name') + ->get(); + $totalRecord = $userProyek->count(); + + return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); } public function search(Request $request) diff --git a/routes/web.php b/routes/web.php index 47ed601..254d963 100644 --- a/routes/web.php +++ b/routes/web.php @@ -53,7 +53,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); - $router->post('/project-by-customer', 'ProjectController@getByUser'); + $router->get('/project-by-customer/{id}','ProjectController@getByUser'); $router->post('/project/search', 'ProjectController@search'); $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); From 222aaf42a052e13dc1a3aef9ff2bd14335382d09 Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 30 Aug 2023 15:12:28 +0700 Subject: [PATCH 121/185] update uncomment response API invoice --- app/Http/Controllers/ProjectController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index fe082c2..5e0fbde 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -439,8 +439,7 @@ class ProjectController extends Controller $response = MasterFunctionsHelper::curlReq($url); - // return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); - return response()->json(['status'=>'success', 'data'=> '', 'code'=>200], 200); + return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); } public function getByUser($id) { From 464407d9ee74888df746c9c9139db8ff2f3535c0 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Thu, 31 Aug 2023 16:26:48 +0700 Subject: [PATCH 122/185] add select role_id in HumanResourceController@list --- .../Controllers/HumanResourceController.php | 389 +++++++++--------- 1 file changed, 196 insertions(+), 193 deletions(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index f71cf28..86f886a 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -1,193 +1,196 @@ -validate($request, [ - 'role_id' => 'required', - 'name' => 'required', - 'ktp_number' => 'required', - 'employee_type' => 'required' - ]); - - $data = $request->all(); - - if(isset($request->password) && $request->password!=""){ - $data['password'] = md5($request->password); - } - - $result = HumanResource::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'Human Resource Pool successfull created','code'=>200]); - }else{ - return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed created','code'=>400]); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = HumanResource::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data human resource, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id){ - - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $humanresource = HumanResource::find($id); - - $data = $request->all(); - - if(isset($request->password) && $request->password!="" ){ - $data['password'] = md5($request->password); - } - - if(isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()){ - return response()->json(['status'=>'failed','message'=>'Username already exists!','code'=>400], 400); - } - - if($humanresource){ - $result = $humanresource->update($data); - }else{ - return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); - die(); - } - - if($result){ - return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = HumanResource::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_users'); - $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 list() - { - $data = HumanResource::select('id', 'name')->get(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list human resource, please try again later!','code'=>400], 400); - } - } - - public function select(Request $request){ - - $search = $request->query('search'); - - $idActivity = (int)$request->query('idact'); - $idProyek = (int)$request->query('idProyek'); - - $forbidden = []; - - if($idActivity && $idActivity > 0){ - $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); - foreach($dataF as $val){ - $forbidden[] = $val->user_id; - } - } - - if ($search && !empty($search)) { - $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") - ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') - ->where("assign_hr_to_proyek.proyek_id", $idProyek) - ->where(function ($query) { - $query->where("assign_hr_to_proyek.is_customer", "!=", true) - ->orWhereNull("assign_hr_to_proyek.is_customer"); - }) - ->where("m_users.name", 'like', '%' . $search . '%') - ->whereNotIn("m_users.id", $forbidden)->get(); - } else { - $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") - ->where("assign_hr_to_proyek.proyek_id", $idProyek) - ->where(function ($query) { - $query->where("assign_hr_to_proyek.is_customer", "!=", true) - ->orWhereNull("assign_hr_to_proyek.is_customer"); - }) - ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') - ->whereNotIn("m_users.id", $forbidden) - ->get(); - } - - return response()->json($data); - } - - public function checkOldPassword(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $data = $request->all(); - - if(isset($request->old_password) && $request->old_password!="" ){ - $result = HumanResource::find($id); - $data['old_password'] = md5($request->old_password); - if($data['old_password'] !== $result->password) { - return response()->json(['status'=>'failed','message'=>"old password seems doesn't match in records. please try again.",'code'=>400], 400); - } - elseif($data['old_password'] === $result->password) { - return response()->json(['status'=>'success','message'=>"old password match",'data'=>$result,'code'=>200], 200); - } - } - else { - return response()->json(['status'=>'failed','message'=>'old_password is required!','code'=>400], 400); - } - } - - public function sync(){ - Artisan::call('sync:integration-human-resources'); - } -} +validate($request, [ + 'role_id' => 'required', + 'name' => 'required', + 'ktp_number' => 'required', + 'employee_type' => 'required' + ]); + + $data = $request->all(); + + if (isset($request->password) && $request->password != "") { + $data['password'] = md5($request->password); + } + + $result = HumanResource::create($data); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]); + } else { + return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]); + } + } + + public function edit($id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $result = HumanResource::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data human resource, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $humanresource = HumanResource::find($id); + + $data = $request->all(); + + if (isset($request->password) && $request->password != "") { + $data['password'] = md5($request->password); + } + + if (isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()) { + return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400); + } + + if ($humanresource) { + $result = $humanresource->update($data); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); + die(); + } + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed updated!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = HumanResource::find($id); + + if ($data) { + $delete = $data->delete(); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); + die(); + } + + + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed deleted!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_users'); + $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 list() + { + $data = HumanResource::select('id', 'name', 'role_id')->get(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list human resource, please try again later!', 'code' => 400], 400); + } + } + + public function select(Request $request) + { + + $search = $request->query('search'); + + $idActivity = (int)$request->query('idact'); + $idProyek = (int)$request->query('idProyek'); + + $forbidden = []; + + if ($idActivity && $idActivity > 0) { + $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); + foreach ($dataF as $val) { + $forbidden[] = $val->user_id; + } + } + + if ($search && !empty($search)) { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") + ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->where("assign_hr_to_proyek.proyek_id", $idProyek) + ->where(function ($query) { + $query->where("assign_hr_to_proyek.is_customer", "!=", true) + ->orWhereNull("assign_hr_to_proyek.is_customer"); + }) + ->where("m_users.name", 'like', '%' . $search . '%') + ->whereNotIn("m_users.id", $forbidden)->get(); + } else { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") + ->where("assign_hr_to_proyek.proyek_id", $idProyek) + ->where(function ($query) { + $query->where("assign_hr_to_proyek.is_customer", "!=", true) + ->orWhereNull("assign_hr_to_proyek.is_customer"); + }) + ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->whereNotIn("m_users.id", $forbidden) + ->get(); + } + + return response()->json($data); + } + + public function checkOldPassword(Request $request, $id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $data = $request->all(); + + if (isset($request->old_password) && $request->old_password != "") { + $result = HumanResource::find($id); + $data['old_password'] = md5($request->old_password); + if ($data['old_password'] !== $result->password) { + return response()->json(['status' => 'failed', 'message' => "old password seems doesn't match in records. please try again.", 'code' => 400], 400); + } elseif ($data['old_password'] === $result->password) { + return response()->json(['status' => 'success', 'message' => "old password match", 'data' => $result, 'code' => 200], 200); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'old_password is required!', 'code' => 400], 400); + } + } + + public function sync() + { + Artisan::call('sync:integration-human-resources'); + } +} From 1762422e293cbd73b4b41c466e9a706c71fe6fb0 Mon Sep 17 00:00:00 2001 From: ibnu Date: Fri, 1 Sep 2023 01:09:51 +0700 Subject: [PATCH 123/185] update logic get actual date from header activity --- app/Http/Controllers/ActivityController.php | 58 ++++++++++++++++++--- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 0cc4563..03990d9 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -48,9 +48,9 @@ class ActivityController extends Controller $dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start), "Y-m-d H:i:s") : NULL; $dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL; - $actualStart = $this->getActivityFirst($dataHeader->id); + $actualStart = $this->getFirstLastDateActivity($dataHeader->id, "start"); $dataHeader->actual_start = date_format(date_create($actualStart), "Y-m-d"); - $actualEnd = $this->getActivityLast($dataHeader->id); + $actualEnd = $this->getFirstLastDateActivity($dataHeader->id, "end"); $dataHeader->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; $dataHeader->type = "header"; @@ -79,9 +79,9 @@ class ActivityController extends Controller $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL; - $actualStart = $this->getActivityFirst($objRow->id); + $actualStart = $this->getFirstLastDateActivity($objRow->id, "start"); $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; - $actualEnd = $this->getActivityLast($objRow->id); + $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end"); $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; $objRow->progress = $objRow->persentase_progress / 100; @@ -141,10 +141,10 @@ class ActivityController extends Controller } } else { $objRow->type = "project"; - $actualStart = $this->getActivityFirst($objRow->id); + $actualStart = $this->getFirstLastDateActivity($objRow->id, "start"); $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; - $actualEnd = $this->getActivityLast($objRow->id); + $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end"); $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; } $finalData[] = $objRow; @@ -167,6 +167,52 @@ class ActivityController extends Controller } + public function getFirstLastDateActivity($id, $params){ + if($params == "start"){ + $data = Activity::select('id', 'parent_id', 'name', 'actual_start')->where('parent_id', $id)->get(); + }else{ + $data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get(); + } + $dataFinal=[]; + foreach ($data as $val) { + $activity = $this->getchildActivityForActual($val->id, $params); + $dataFinal[] = $val; + $dataFinal = array_merge($dataFinal, $activity); + + } + if($params == "start"){ + $actualStartValues = array_column(array_filter($dataFinal, function($item) { + return isset($item['actual_start']); + }), 'actual_start'); + + $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; + }else{ + $actualEndValues = array_column(array_filter($dataFinal, function($item) { + return isset($item['actual_end']); + }), 'actual_end'); + + $returnActualStartOrEnd = count($actualEndValues) > 0 ? max($actualEndValues) : null; + } + + // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); + return $returnActualStartOrEnd; + } + + public function getchildActivityForActual($parent, $params){ + if($params == "start"){ + $activity = Activity::select('id', 'actual_start')->where('parent_id', $parent)->get(); + }else{ + $activity = Activity::select('id', 'actual_end')->where('parent_id', $parent)->get(); + } + $temp = []; + foreach($activity as $val1){ + $getChild = $this->getchildActivityForActual($val1->id, $params); + $temp[] = $val1; + $temp = array_merge($temp, $getChild); + } + return $temp; + } + public function getActivityLast($parentId){ $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); if (!isset($activity)) { From 964af57b62690681d064c9e400986a840bfa15f6 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 1 Sep 2023 09:47:13 +0700 Subject: [PATCH 124/185] check status boundary --- app/Http/Controllers/PresenceController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index ad0501c..6aef1a8 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -258,6 +258,7 @@ class PresenceController extends Controller // cek user tersebut apakah punya assign task yang ada bondary nya // geom ada di table activity // $clock_time = + $user = HumanResource::find($params->user_id); $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") ->where("ahta.user_id", $params->user_id) @@ -326,14 +327,14 @@ class PresenceController extends Controller ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); } } - if(count($check)>0){ - if(isset($check[0]->boundary) && $check[0]->boundary){ + if(!$user->status_boundary || count($check)>0){ + if(!$user->status_boundary || (isset($check[0]->boundary) && $check[0]->boundary)){ $temp[]=array( "activity_id" => $dataGeom->id, "boundary" => $check[0]->boundary, "status_assign" => true ); - } else if (isset($check[0]->within_radius) && $check[0]->within_radius) { + } else if (!$user->status_boundary || (isset($check[0]->within_radius) && $check[0]->within_radius)) { $temp[]=array( "activity_id" => $dataGeom->id, "boundary" => $check[0]->within_radius, From dcede1f72a7f57f62a662ab7eb2443db9f495d2a Mon Sep 17 00:00:00 2001 From: wahyuun Date: Tue, 5 Sep 2023 17:01:28 +0700 Subject: [PATCH 125/185] query ProjectController@edit --- app/Http/Controllers/ProjectController.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 5e0fbde..a6fac6a 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -65,11 +65,16 @@ class ProjectController extends Controller return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); } - public function edit($id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + public function edit($id) + { + if (empty($id) || !is_int((int)$id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $result = Project::query() + ->select(array_diff(DB::getSchemaBuilder()->getColumnListing('m_proyek'), ['created_by', 'created_at', 'updated_at', 'updated_by', 'scurve'])) + ->whereId($id) + ->first(); - $result = Project::find($id); if(!$result) return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); From a4b2c9c21ed571a4b40b4b8b963e839795a2d5a6 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Sat, 9 Sep 2023 08:53:16 +0700 Subject: [PATCH 126/185] update ProjectController@edit and add fillable in Project Model --- app/Http/Controllers/ProjectController.php | 12 ++- app/Models/Project.php | 108 ++++++++++----------- 2 files changed, 63 insertions(+), 57 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index a6fac6a..27a3a94 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -71,10 +71,16 @@ class ProjectController extends Controller return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $result = Project::query() - ->select(array_diff(DB::getSchemaBuilder()->getColumnListing('m_proyek'), ['created_by', 'created_at', 'updated_at', 'updated_by', 'scurve'])) - ->whereId($id) - ->first(); + ->from('m_proyek AS mp') + ->where('mp.id', $id) + ->selectRaw('kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,lokasi_kantor,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status'); + if (!is_null($result->first()['divisi_id'])) { + $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') + ->addSelect(DB::raw('m_divisi.name AS nama_divisi')); + } + + $result = $result->first(); if(!$result) return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); diff --git a/app/Models/Project.php b/app/Models/Project.php index 6d3d5f4..cf2d0ad 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -1,54 +1,54 @@ - Date: Wed, 13 Sep 2023 13:47:10 +0700 Subject: [PATCH 127/185] fix endline --- app/Http/Controllers/DivisiController.php | 198 +++++++++++----------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index ea7c3d4..1bff005 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -1,99 +1,99 @@ -depth = $depth; - array_push($array, $divisi); - foreach($divisi->children as $child){ - $array = $this->getAllChildren($child, $depth + 1, $array); - } - return $array; - } - - public function add(Request $request){ - $this->validate($request, [ - 'name' => 'required', - 'description' => 'string', - 'parent' => 'integer' - ]); - - $data = $request->all(); - $data['created_by'] = $this->currentName; - - $result = Divisi::create($data); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); - - return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); - } - - public function update(Request $request, $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Divisi::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $result = $data->update($request->all()); - - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); - } - - public function delete($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Divisi::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $delete = $data->delete(); - - if(!$delete) - return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); - } - - public function search() - { - return $this->list(); - // cant use builder for this case - } - - public function list() - { - $parentMenus = Divisi::whereNull('parent')->with('children')->get(); - $divisions = []; - foreach($parentMenus as $menu){ - $childs = $this->getAllChildren($menu); - foreach($childs as $d){ - $d->displayName = ' ' . $d->name; - for($i=0; $i < $d->depth; $i++){ - $d->displayName = '--' . $d->displayName ; - } - array_push($divisions, $d); - } - } - $countData = count($divisions); - if($countData == 0) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); - } -} +depth = $depth; + array_push($array, $divisi); + foreach($divisi->children as $child){ + $array = $this->getAllChildren($child, $depth + 1, $array); + } + return $array; + } + + public function add(Request $request){ + $this->validate($request, [ + 'name' => 'required', + 'description' => 'string', + 'parent' => 'integer' + ]); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + + $result = Divisi::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); + + return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); + } + + public function update(Request $request, $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Divisi::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Divisi::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $delete = $data->delete(); + + if(!$delete) + return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); + } + + public function search() + { + return $this->list(); + // cant use builder for this case + } + + public function list() + { + $parentMenus = Divisi::whereNull('parent')->with('children')->get(); + $divisions = []; + foreach($parentMenus as $menu){ + $childs = $this->getAllChildren($menu); + foreach($childs as $d){ + $d->displayName = ' ' . $d->name; + for($i=0; $i < $d->depth; $i++){ + $d->displayName = '--' . $d->displayName ; + } + array_push($divisions, $d); + } + } + $countData = count($divisions); + if($countData == 0) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); + } +} From 4859cba81e826171e30c1422ea532d438b8710e8 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 13 Sep 2023 14:00:04 +0700 Subject: [PATCH 128/185] fix divisi search --- app/Http/Controllers/DivisiController.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index 1bff005..7368f1e 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -70,9 +70,16 @@ class DivisiController extends Controller return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); } - public function search() - { - return $this->list(); + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_divisi'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + //return $this->list(); // cant use builder for this case } From 2204ea5ef81ec0e27cc41b73462a5f25a38ddb16 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 13 Sep 2023 15:21:16 +0700 Subject: [PATCH 129/185] sync report quick fix --- app/Http/Controllers/ProjectController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 5e0fbde..6fe1c12 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use DateTime; use Illuminate\Http\Request; use App\Models\Project; use App\Models\UserToProyek; @@ -349,7 +350,16 @@ class ProjectController extends Controller } public static function setSyncDate($activity_id, $activity, $report) { - $status = AssignMaterial::select('status_activity')->where('activity_id', $activity_id)->first(); + $status = AssignMaterial::where('activity_id', $activity_id)->first(); + if (!isset($status)) { + $reports = array( + 'activity_id' => $activity_id, + 'min_date' => new DateTime($activity->start_date), + 'max_date' => new DateTime($activity->end_date), + 'status' => 'open' + ); + return $reports; + } if (!isset($status->status_activity)) { $status->status_activity = 'open'; } From a9582aab73bf644fe19f3c8c1081cd69de8430e5 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 14 Sep 2023 14:11:17 +0700 Subject: [PATCH 130/185] fix endline --- app/Models/AssignMaterial.php | 92 +++++++++++++++++------------------ 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/app/Models/AssignMaterial.php b/app/Models/AssignMaterial.php index 0c282a6..09620ee 100644 --- a/app/Models/AssignMaterial.php +++ b/app/Models/AssignMaterial.php @@ -1,46 +1,46 @@ - 'integer', - 'budget' => 'string', - ]; - - public static function boot() { - parent::boot(); - - static::created(function($data) { - $activity = Activity::find($data->activity_id); - $material = RequestMaterial::where("id", $data->material_id)->first(); - $activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); - $activity->save(); - }); - - static::deleted(function($data) { - $reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); - $activity = Activity::where('id', $data->activity_id)->first(); - $activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); - $activity->save(); - }); - - } -} + 'integer', + 'budget' => 'string', + ]; + + public static function boot() { + parent::boot(); + + static::created(function($data) { + $activity = Activity::find($data->activity_id); + $material = RequestMaterial::where("id", $data->material_id)->first(); + $activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); + $activity->save(); + }); + + static::deleted(function($data) { + $reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); + $activity = Activity::where('id', $data->activity_id)->first(); + $activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); + $activity->save(); + }); + + } +} From 4b8df65f4426d3d90c22d8938c434dcb38b7b0aa Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 14 Sep 2023 17:09:07 +0700 Subject: [PATCH 131/185] cascade delete, delete report, update status --- .../Controllers/AssignMaterialController.php | 436 +++++++++--------- .../ReportActivityMaterialController.php | 18 +- app/Models/ReportActivityMaterial.php | 146 +++--- 3 files changed, 309 insertions(+), 291 deletions(-) diff --git a/app/Http/Controllers/AssignMaterialController.php b/app/Http/Controllers/AssignMaterialController.php index b3f917a..3d78384 100644 --- a/app/Http/Controllers/AssignMaterialController.php +++ b/app/Http/Controllers/AssignMaterialController.php @@ -1,215 +1,221 @@ -validate($request, [ - 'activity_id' => 'required', - 'material_id' => 'required', - 'qty_planning' => 'required' - ]); - - $activity = Activity::where('id', $request->activity_id)->first(); - - $checkStock = RequestMaterial::where("id", $request->material_id)->first(); - $currentStock = $checkStock->qty; - if((int)$currentStock < (int)$request->qty_planning){ - return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); - } - - $start_date = $activity->start_date; - $start_date = substr($start_date, 0, 19); // remove the timezone offset - $startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); - $planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date))); - - $data = $request->all(); - $data['created_by'] = $this->currentName; - $data['budget'] = $checkStock->price; - $data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); - - if ($planDate >= $startDate) { - $result = AssignMaterial::create($data); - return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400); - } - } - - public function update(Request $request, $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = AssignMaterial::find($id); - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - $result = $data->update($request->all()); - - if($result) - return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200); - - return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); - } - - public function delete($id) - { - $data = AssignMaterial::where('id', $id)->first(); - - if($data->delete()) - return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200); - - return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); - } - - public function edit($id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $result = AssignMaterial::find($id); - - if($result) - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'assign_material_to_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 list() - { - $data = AssignMaterial::all(); - $countData = $data->count(); - - if($data) - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - - return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500); - } - - public function datatables(Request $request){ - $id_activity = $request->query('idact'); - $type = $request->query('type') ?? "material"; - $data = AssignMaterial::select( - "assign_material_to_activity.*","m.description as material_name", "m.uom as uom" - ) - ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->where('assign_material_to_activity.activity_id', $id_activity) - ->where('assign_material_to_activity.type', $type) - ->orderBy('plan_date', 'desc') - ->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('action', function($row){ - $actionBtn = ''; - return $actionBtn; - }) - ->rawColumns(['action'])->make(true); - } - - public function datatablesForReportActivity(Request $request){ - $id_activity = $request->query('idact'); - $data = - AssignMaterial::select( - AssignMaterial::raw('SUM(qty_planning) as qty_planning'), - "m.description as material_name", - "assign_material_to_activity.activity_id", - "assign_material_to_activity.type" - // "assign_material_to_activity.material_id", - ) - ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->groupBy("m.description") - ->groupBy("assign_material_to_activity.activity_id") - ->groupBy("assign_material_to_activity.type") - ->where("assign_material_to_activity.activity_id", $id_activity)->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('qty_sum', function($row){ - $val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1") - ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id") - ->groupBy("m.description") - ->where("m.description", strval($row->material_name)) - ->where("ram.activity_id", $row->activity_id)->first(); - return $val_qty_act ? $val_qty_act->qty_sum : '-'; - }) - ->addColumn('status_activity', function($row){ - $val_status = AssignMaterial::select("status_activity") - ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') - ->where('m.description', '=', $row->material_name) - ->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); - return $val_status ? $val_status->status_activity : null; - }) - ->addColumn('start_activity', function($row){ - $val_start = AssignMaterial::select("start_activity") - ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') - ->where('m.description', '=', $row->material_name) - ->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); - return $val_start ? $val_start->start_activity : null; - }) - ->addColumn('finish_activity', function($row){ - $val_finish = AssignMaterial::select("finish_activity") - ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') - ->where('m.description', '=', $row->material_name) - ->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); - return $val_finish ? $val_finish->finish_activity : null; - }) - ->addColumn('uom', function($row){ - $val_uom = RequestMaterial::select("uom") - ->where('description', '=', $row->material_name)->first(); - return $val_uom ? $val_uom->uom : null; - }) - ->addColumn('assign_material_id', function($row){ - $assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); - return $assignMaterial ? $assignMaterial->id : null; - }) - ->addColumn('action', function($row){ - $dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); - $actionBtn = ''; - $actionBtn .= ''; - return $actionBtn; - }) - ->rawColumns(['action'])->make(true); - } - - public function ForReportActivityByMaterial(Request $request){ - $id_activity = $request->idact; - $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") - ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->where('assign_material_to_activity.activity_id', $id_activity)->get(); - foreach ($data as $key) { - $val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty"); - } - $countData = $data->count(); - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400); - } - } -} +validate($request, [ + 'activity_id' => 'required', + 'material_id' => 'required', + 'qty_planning' => 'required' + ]); + + $activity = Activity::where('id', $request->activity_id)->first(); + + $checkStock = RequestMaterial::where("id", $request->material_id)->first(); + $currentStock = $checkStock->qty; + if((int)$currentStock < (int)$request->qty_planning){ + return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); + } + + $start_date = $activity->start_date; + $start_date = substr($start_date, 0, 19); // remove the timezone offset + $startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); + $planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date))); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + $data['budget'] = $checkStock->price; + $data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); + + if ($planDate >= $startDate) { + $result = AssignMaterial::create($data); + return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400); + } + } + + public function update(Request $request, $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = AssignMaterial::find($id); + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + $result = $data->update($request->all()); + + if($result) + return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200); + + return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); + } + + public function delete($id) + { + $data = AssignMaterial::where('id', $id)->first(); + $reports = ReportActivityMaterial::where('assign_material_id', $data->id)->get(); + if (isset($reports)) { + foreach ($reports as $report) { + $report->delete(); + } + } + + if($data->delete()) + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200); + + return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); + } + + public function edit($id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $result = AssignMaterial::find($id); + + if($result) + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'assign_material_to_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 list() + { + $data = AssignMaterial::all(); + $countData = $data->count(); + + if($data) + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + + return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500); + } + + public function datatables(Request $request){ + $id_activity = $request->query('idact'); + $type = $request->query('type') ?? "material"; + $data = AssignMaterial::select( + "assign_material_to_activity.*","m.description as material_name", "m.uom as uom" + ) + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('assign_material_to_activity.activity_id', $id_activity) + ->where('assign_material_to_activity.type', $type) + ->orderBy('plan_date', 'desc') + ->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('action', function($row){ + $actionBtn = ''; + return $actionBtn; + }) + ->rawColumns(['action'])->make(true); + } + + public function datatablesForReportActivity(Request $request){ + $id_activity = $request->query('idact'); + $data = + AssignMaterial::select( + AssignMaterial::raw('SUM(qty_planning) as qty_planning'), + "m.description as material_name", + "assign_material_to_activity.activity_id", + "assign_material_to_activity.type" + // "assign_material_to_activity.material_id", + ) + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->groupBy("m.description") + ->groupBy("assign_material_to_activity.activity_id") + ->groupBy("assign_material_to_activity.type") + ->where("assign_material_to_activity.activity_id", $id_activity)->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('qty_sum', function($row){ + $val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1") + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id") + ->groupBy("m.description") + ->where("m.description", strval($row->material_name)) + ->where("ram.activity_id", $row->activity_id)->first(); + return $val_qty_act ? $val_qty_act->qty_sum : '-'; + }) + ->addColumn('status_activity', function($row){ + $val_status = AssignMaterial::select("status_activity") + ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') + ->where('m.description', '=', $row->material_name) + ->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); + return $val_status ? $val_status->status_activity : null; + }) + ->addColumn('start_activity', function($row){ + $val_start = AssignMaterial::select("start_activity") + ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') + ->where('m.description', '=', $row->material_name) + ->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); + return $val_start ? $val_start->start_activity : null; + }) + ->addColumn('finish_activity', function($row){ + $val_finish = AssignMaterial::select("finish_activity") + ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') + ->where('m.description', '=', $row->material_name) + ->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); + return $val_finish ? $val_finish->finish_activity : null; + }) + ->addColumn('uom', function($row){ + $val_uom = RequestMaterial::select("uom") + ->where('description', '=', $row->material_name)->first(); + return $val_uom ? $val_uom->uom : null; + }) + ->addColumn('assign_material_id', function($row){ + $assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); + return $assignMaterial ? $assignMaterial->id : null; + }) + ->addColumn('action', function($row){ + $dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); + $actionBtn = ''; + $actionBtn .= ''; + return $actionBtn; + }) + ->rawColumns(['action'])->make(true); + } + + public function ForReportActivityByMaterial(Request $request){ + $id_activity = $request->idact; + $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('assign_material_to_activity.activity_id', $id_activity)->get(); + foreach ($data as $key) { + $val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty"); + } + $countData = $data->count(); + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400); + } + } +} diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 54be3e0..86cb638 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -59,6 +59,14 @@ class ReportActivityMaterialController extends Controller "updated_by" => $this->currentName ); Activity::where('id', $request->activity_id)->update($dataUpdate); + } else { + $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); + $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); + $dataUpdate = array( + "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, + "updated_by" => $this->currentName + ); + Activity::where('id', $request->activity_id)->update($dataUpdate); } return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]); @@ -114,12 +122,14 @@ class ReportActivityMaterialController extends Controller ->addIndexColumn() ->addColumn('action', function($row){ $actionBtn = ''; - $actionBtn .= ''; + if ($row->status_activity != 'done') { + $actionBtn .= ''; + } return $actionBtn; }) ->rawColumns(['action'])->make(true); }else{ - $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource") + $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") ->join("m_req_material as m", "m.id", "=", "amta.material_id") ->join("m_users as u", "u.id", "=", "report_activity_material.user_id") @@ -131,7 +141,9 @@ class ReportActivityMaterialController extends Controller ->addIndexColumn() ->addColumn('action', function($row){ $actionBtn = ''; - $actionBtn .= ''; + if ($row->status_activity != 'done') { + $actionBtn .= ''; + } return $actionBtn; }) ->rawColumns(['action'])->make(true); diff --git a/app/Models/ReportActivityMaterial.php b/app/Models/ReportActivityMaterial.php index 44db31c..39849d5 100644 --- a/app/Models/ReportActivityMaterial.php +++ b/app/Models/ReportActivityMaterial.php @@ -1,73 +1,73 @@ -timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - - public static function boot() { - parent::boot(); - - static::created(function($data) { - $activity = Activity::find($data->activity_id); - $assignedMaterial = AssignMaterial::find($data->assign_material_id); - - $biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); - - $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); - if($dataPlan[0]->status_activity == 'done'){ - $percentage = 100; - } else { - $totalPlan = $dataPlan->sum('qty_planning'); - $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); - $percentage = ($totalVolumeActual * 100) / $totalPlan; - $percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; - } - - $activity->update([ - "persentase_progress" => $percentage, - "biaya_actual" => $biayaActual, - ]); - - $activity->save(); - }); - - static::deleted(function($data) { - - $activity = Activity::find($data->activity_id); - $assignedMaterial = AssignMaterial::find($data->assign_material_id); - - $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); - - $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); - $totalPlan = $dataPlan->sum('qty_planning'); - $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); - $percentage = ($totalVolumeActual * 100) / $totalPlan; - $activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; - $activity->save(); - - }); - - } -} +timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + + public static function boot() { + parent::boot(); + + static::created(function($data) { + $activity = Activity::find($data->activity_id); + $assignedMaterial = AssignMaterial::find($data->assign_material_id); + + $biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); + + $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); + if($dataPlan[0]->status_activity == 'done'){ + $percentage = 100; + } else { + $totalPlan = $dataPlan->sum('qty_planning'); + $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); + $percentage = ($totalVolumeActual * 100) / $totalPlan; + $percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; + } + + $activity->update([ + "persentase_progress" => $percentage, + "biaya_actual" => $biayaActual, + ]); + + $activity->save(); + }); + + static::deleted(function($data) { + + $activity = Activity::find($data->activity_id); + $assignedMaterial = AssignMaterial::find($data->assign_material_id); + + $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); + + $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); + $totalPlan = $dataPlan->sum('qty_planning'); + $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); + $percentage = ($totalVolumeActual * 100) / $totalPlan; + $activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; + $activity->save(); + + }); + + } +} From abcb01fafe8159cc3db718b179f513cf85b48bc8 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 15 Sep 2023 14:30:41 +0700 Subject: [PATCH 132/185] endline fix --- app/Http/Controllers/RoleMenuController.php | 204 ++++++++++---------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/app/Http/Controllers/RoleMenuController.php b/app/Http/Controllers/RoleMenuController.php index 05942f5..ebd5d0a 100644 --- a/app/Http/Controllers/RoleMenuController.php +++ b/app/Http/Controllers/RoleMenuController.php @@ -1,102 +1,102 @@ -validate($request, [ - 'role_id' => 'required', - 'menu_id' => 'required', - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = RoleMenu::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = RoleMenu::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = RoleMenu::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); - } - } - - public function deleteByRole($id) - { - $data = RoleMenu::where("role_id", $id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 't_roles_menu'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } -} +validate($request, [ + 'role_id' => 'required', + 'menu_id' => 'required', + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = RoleMenu::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = RoleMenu::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = RoleMenu::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); + } + } + + public function deleteByRole($id) + { + $data = RoleMenu::where("role_id", $id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 't_roles_menu'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } +} From 9ec406a94240cc63273b579a17c6efee81bee04b Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:42:00 +0700 Subject: [PATCH 133/185] fix search and add broadcast --- app/Http/Controllers/BroadcastController.php | 348 ++++++++++--------- 1 file changed, 177 insertions(+), 171 deletions(-) diff --git a/app/Http/Controllers/BroadcastController.php b/app/Http/Controllers/BroadcastController.php index 87eb02d..66ca433 100644 --- a/app/Http/Controllers/BroadcastController.php +++ b/app/Http/Controllers/BroadcastController.php @@ -1,171 +1,177 @@ -all(); - $data['status_send'] = true; - $data['created_by'] = $this->currentName; - if (isset($data['send_to_id'])) { - $idArray = $data['send_to_id']; - if (is_array($data['send_to_id'])) { - $data['send_to_id'] = implode(", ", $idArray); - } - } - // dd($data); - $result = Broadcast::create($data); - if($result){ - $this->sendNotification($data); - return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = Broadcast::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Broadcast::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = Broadcast::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); - $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 list() - { - $data = Broadcast::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list broadcast, please try again later!','code'=>400], 400); - } - } - - public function sendNotification($data) - { - // send_to_type (all, roles, user) - if (isset($data['send_to_type'])) { - switch ($data['send_to_type']) { - case 'all': - $users = User::whereNotNull('fcm_token')->get(); - if (isset($users)) { - foreach ($users as $user) { - FCMService::send( - $user->fcm_token, - [ - 'title' => $data['title_notif'], - 'body' => $data['message_notif'], - ] - ); - } - } - break; - - case 'roles': - $users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); - if (isset($users)) { - foreach ($users as $user) { - FCMService::send( - $user->fcm_token, - [ - 'title' => $data['title_notif'], - 'body' => $data['message_notif'], - ] - ); - } - } - break; - - case 'users': - $idArray = explode(", ", $data['send_to_id']); - foreach ($idArray as $key => $value) { - $user = User::where("id", $value)->whereNotNull('fcm_token')->first(); - if (isset($user)) { - FCMService::send( - $user->fcm_token, - [ - 'title' => $data['title_notif'], - 'body' => $data['message_notif'], - ] - ); - } - } - break; - - default: - # code... - break; - } - } - } -} +all(); + $data['created_by'] = $this->currentName; + if (isset($data['send_to_id'])) { + $idArray = $data['send_to_id']; + if (is_array($data['send_to_id'])) { + $data['send_to_id'] = implode(", ", $idArray); + } + } + $result = Broadcast::create($data); + if($result){ + $data['status_send'] !== "registered" ? $this->sendNotification($data) : ''; + return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400); + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = Broadcast::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = Broadcast::find($id); + + $status_send = $request->status_send; + + if($status_send === 'resend' || $status_send === 'send' && !empty($data)) + { + $data['status_send'] = $status_send; + $this->sendNotification($data); + } + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = Broadcast::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); + $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 list() + { + $data = Broadcast::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list broadcast, please try again later!','code'=>400], 400); + } + } + + public function sendNotification($data) + { + // send_to_type (all, roles, user) + if (isset($data['send_to_type'])) { + switch ($data['send_to_type']) { + case 'all': + $users = User::whereNotNull('fcm_token')->get(); + if (isset($users)) { + foreach ($users as $user) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + case 'roles': + $users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); + if (isset($users)) { + foreach ($users as $user) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + case 'users': + $idArray = explode(", ", $data['send_to_id']); + foreach ($idArray as $key => $value) { + $user = User::where("id", $value)->whereNotNull('fcm_token')->first(); + if (isset($user)) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + default: + # code... + break; + } + } + } +} From afd447cdd38ecb393f64fcbdfd6de763ef38a005 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:43:43 +0700 Subject: [PATCH 134/185] fix search table,add divisi,edit divisi --- app/Http/Controllers/DivisiController.php | 211 ++++++++++++---------- 1 file changed, 112 insertions(+), 99 deletions(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index ea7c3d4..a7d3617 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -1,99 +1,112 @@ -depth = $depth; - array_push($array, $divisi); - foreach($divisi->children as $child){ - $array = $this->getAllChildren($child, $depth + 1, $array); - } - return $array; - } - - public function add(Request $request){ - $this->validate($request, [ - 'name' => 'required', - 'description' => 'string', - 'parent' => 'integer' - ]); - - $data = $request->all(); - $data['created_by'] = $this->currentName; - - $result = Divisi::create($data); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); - - return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); - } - - public function update(Request $request, $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Divisi::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $result = $data->update($request->all()); - - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); - } - - public function delete($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Divisi::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $delete = $data->delete(); - - if(!$delete) - return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); - } - - public function search() - { - return $this->list(); - // cant use builder for this case - } - - public function list() - { - $parentMenus = Divisi::whereNull('parent')->with('children')->get(); - $divisions = []; - foreach($parentMenus as $menu){ - $childs = $this->getAllChildren($menu); - foreach($childs as $d){ - $d->displayName = ' ' . $d->name; - for($i=0; $i < $d->depth; $i++){ - $d->displayName = '--' . $d->displayName ; - } - array_push($divisions, $d); - } - } - $countData = count($divisions); - if($countData == 0) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); - } -} +depth = $depth; + array_push($array, $divisi); + foreach($divisi->children as $child){ + $array = $this->getAllChildren($child, $depth + 1, $array); + } + return $array; + } + + public function add(Request $request){ + $this->validate($request, [ + 'name' => 'string|required|unique:m_divisi,name', + 'description' => 'nullable|string', + 'parent' => 'nullable|integer' + ]); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + + $result = Divisi::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); + + return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); + } + + public function update(Request $request, $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $this->validate($request, [ + 'name' => 'string|required', + 'description' => 'nullable|string', + 'parent' => 'nullable|integer' + ]); + $data = Divisi::find($id); + + $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : ''; + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Divisi::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $delete = $data->delete(); + + if(!$delete) + return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_divisi'); + $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 list() + { + $parentMenus = Divisi::whereNull('parent')->with('children')->get(); + $divisions = []; + foreach($parentMenus as $menu){ + $childs = $this->getAllChildren($menu); + foreach($childs as $d){ + $d->displayName = ' ' . $d->name; + for($i=0; $i < $d->depth; $i++){ + $d->displayName = '--' . $d->displayName ; + } + array_push($divisions, $d); + } + } + $countData = count($divisions); + if($countData == 0) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); + } +} From abc80b780783902999ec986c256af4aefcead784 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:44:23 +0700 Subject: [PATCH 135/185] assign customer --- app/Http/Controllers/HumanResourceController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 86f886a..be26a1c 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -15,7 +15,7 @@ class HumanResourceController extends Controller $this->validate($request, [ 'role_id' => 'required', 'name' => 'required', - 'ktp_number' => 'required', + 'ktp_number' => 'required|numeric|unique:m_users,ktp_number', 'employee_type' => 'required' ]); @@ -56,9 +56,12 @@ class HumanResourceController extends Controller if (!$id || (int) $id < 0 || $id == "") { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } - $humanresource = HumanResource::find($id); + $request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|numeric']) : ''; + $request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : ''; + $request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; + $data = $request->all(); if (isset($request->password) && $request->password != "") { From c965d8bb153eaca468a4fa9bf8eb3c75c6c57305 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:45:14 +0700 Subject: [PATCH 136/185] fix add & edit set unik field name --- app/Http/Controllers/MenuController.php | 310 ++++++++++++------------ 1 file changed, 159 insertions(+), 151 deletions(-) diff --git a/app/Http/Controllers/MenuController.php b/app/Http/Controllers/MenuController.php index 679c533..6ff9324 100644 --- a/app/Http/Controllers/MenuController.php +++ b/app/Http/Controllers/MenuController.php @@ -1,151 +1,159 @@ -validate($request, [ - 'icon' => 'required', - 'name' => 'required', - 'url' => 'required', - 'sequence' => 'required', - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = Menu::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add data menu failed!','code'=>400], 400); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = Menu::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Menu::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = Menu::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_menu'); - $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 listMenu($id) - { - $dataParent = RoleMenu::select("m_menu.*") - ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') - ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') - ->whereNull('m_menu.parent_id') - ->where('m_roles.id', $id) - ->orderBy('m_menu.sequence', 'ASC') - ->get(); - - $finalData = []; - foreach($dataParent as $data){ - $data->children = $this->getChildrenMenu($data->id, $id); - $finalData[] = $data; - } - - return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); - } - - protected function getChildrenMenu($id, $role_id) - { - $dataChildren = RoleMenu::select("m_menu.*") - ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') - ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') - ->where('m_roles.id', $role_id) - ->where('m_menu.parent_id', $id) - ->orderBy('m_menu.sequence', 'ASC') - ->get(); - $children = []; - if($dataChildren){ - foreach($dataChildren as $data) - { - $data->children = $this->getChildrenMenu($data->id, $role_id); - $children[] = $data; - } - } - return $children; - } - - public function list() - { - $data = Menu::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list menu, please try again later!','code'=>400], 400); - } - } -} +validate($request, [ + 'icon' => 'required', + 'name' => 'string|required|unique:m_menu,name', + 'url' => 'required|unique:m_menu,url', + 'sequence' => 'required|integer', + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Menu::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data menu failed!','code'=>400], 400); + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = Menu::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + $this->validate($request, [ + 'icon' => 'required', + 'name' => 'string|required', + 'url' => 'required', + 'sequence' => 'required|integer', + ]); + $data = Menu::find($id); + + $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_menu,name']) : ''; + $request->url !== $data['url'] ? $this->validate($request,['url'=>'unique:m_menu,url']) : ''; + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = Menu::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_menu'); + $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 listMenu($id) + { + $dataParent = RoleMenu::select("m_menu.*") + ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') + ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') + ->whereNull('m_menu.parent_id') + ->where('m_roles.id', $id) + ->orderBy('m_menu.sequence', 'ASC') + ->get(); + + $finalData = []; + foreach($dataParent as $data){ + $data->children = $this->getChildrenMenu($data->id, $id); + $finalData[] = $data; + } + + return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); + } + + protected function getChildrenMenu($id, $role_id) + { + $dataChildren = RoleMenu::select("m_menu.*") + ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') + ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') + ->where('m_roles.id', $role_id) + ->where('m_menu.parent_id', $id) + ->orderBy('m_menu.sequence', 'ASC') + ->get(); + $children = []; + if($dataChildren){ + foreach($dataChildren as $data) + { + $data->children = $this->getChildrenMenu($data->id, $role_id); + $children[] = $data; + } + } + return $children; + } + + public function list() + { + $data = Menu::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list menu, please try again later!','code'=>400], 400); + } + } +} From 4f4682c48fac9adf3cf9b33ea935e9235e9ddf05 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:46:18 +0700 Subject: [PATCH 137/185] add unique field name --- app/Http/Controllers/RoleController.php | 207 ++++++++++++------------ 1 file changed, 106 insertions(+), 101 deletions(-) diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index b420107..4a29066 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -1,101 +1,106 @@ -validate($request, [ - 'name' => 'required', - 'description' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = Role::create($data); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); - - return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); - } - - public function edit( $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $result = Role::find($id); - - if(!$result) - 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','message'=>'id is required!','code'=>400], 400); - - $data = Role::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); - - $result = $data->update($request->all()); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); - - return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); - } - - public function delete($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Role::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); - - $delete = $data->delete(); - - if(!$delete) - return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); - - return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); - } - - public function search(Request $request) - { - $payload = $request->all(); - - $dataBuilder = $this->setUpPayload($payload, 'm_roles'); - $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 list() - { - $data = Role::all(); - $countData = $data->count(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); - - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - } -} +validate($request, [ + 'name' => 'string|required|unique:m_roles,name', + 'description' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Role::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); + } + + public function edit( $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $result = Role::find($id); + + if(!$result) + 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','message'=>'id is required!','code'=>400], 400); + + $this->validate($request, [ + 'name' => 'string|required', + 'description' => 'required' + ]); + $data = Role::find($id); + $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_roles,name']) : ''; + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Role::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + $delete = $data->delete(); + + if(!$delete) + return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_roles'); + $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 list() + { + $data = Role::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + } +} From 26a0884ccf0075e1410628975e2ea126ac4be19e Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:47:29 +0700 Subject: [PATCH 138/185] add addMultiple method for AssignCustomer add --- .../Controllers/UserToProyekController.php | 467 ++++++++++-------- 1 file changed, 253 insertions(+), 214 deletions(-) diff --git a/app/Http/Controllers/UserToProyekController.php b/app/Http/Controllers/UserToProyekController.php index fecdfec..a7a1cac 100644 --- a/app/Http/Controllers/UserToProyekController.php +++ b/app/Http/Controllers/UserToProyekController.php @@ -1,214 +1,253 @@ -validate($request, [ - 'user_id' => 'required', - 'proyek_id' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = UserToProyek::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = UserToProyek::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = UserToProyek::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = UserToProyek::find($id); - if($data){ - $userId = $data->user_id; - $proyekId = $data->proyek_id; - $delete = $data->delete(); - if($delete){ - $this->deleteRelative($proyekId, $userId); - } - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); - } - } - - private function deleteRelative($proyekId, $userId) - { - $uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get(); - foreach ($uta as $value) { - $dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); - foreach ($dataRa as $ra) { - $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); - foreach ($images as $image) { - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); - } - } - Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); - } - ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete(); - } - UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete(); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek'); - $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 list() - { - $data = UserToProyek::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400); - } - } - - public function select(Request $request){ - - $search = $request->query('search'); - - $idProyek = (int)$request->query('idProyek'); - $idActivity = (int)$request->query('idact'); - - $include = []; - - if($idActivity && $idActivity > 0){ - $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); - foreach($dataF as $val){ - $include[] = $val->user_id; - } - } - - if($search && !empty($search)){ - $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') - ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); - }else{ - $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get(); - } - - if($data instanceof \Illuminate\Database\Eloquent\Collection){ - $pm = array( - "id"=>$this->currentId, - "name"=> "Project Manager" - ); - $data->push($pm); - } - - return response()->json($data); - } - - private function curlReq($url, $token){ - $ch = curl_init(); - $headers = [ - 'Authorization: '.$token - ]; - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $response = curl_exec($ch); - if ($response === false) - $response = curl_error($ch); - curl_close($ch); - - return json_decode($response); - } - - public function getEmployeeIntegration(Request $request) { - $search = urlencode($request->name); - if(empty($search)) - return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); - $url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH'); - $token = config('api.adw_token'); - $firstResponse = $this->curlReq($url, $token); - - if($firstResponse->total == 0) - return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404); - - $data = $firstResponse->data; - return response()->json([$data]); - $currentPage = 1; - - if($firstResponse->last_page > 0) { - do { - $currentPage++; - $response = $this->curlReq($url.'&page='.$currentPage, $token); - foreach($response->data as $d){ - array_push($data, $d); - } - } while ($currentPage < $firstResponse->last_page); - } - - return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200); - } -} +validate($request, [ + 'user_id' => 'required', + 'proyek_id' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = UserToProyek::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400); + } + } + + public function addMultiple(Request $request){ + $user_IDs = $request->user_id; + + $data = UserToProyek::where("proyek_id", $request->proyek_id); + + if($data){ + $data->delete(); + } + + if(is_array($user_IDs) && count($user_IDs) > 0){ + $countRes = 0; + foreach($user_IDs as $item){ + + $dataInsert = array( + "user_id" => $item, + "proyek_id" => $request->proyek_id, + "created_by" => $this->currentName, + 'is_customer'=>true + ); + + $result = UserToProyek::create($dataInsert); + + if($result){ + $countRes++; + }else{ + $countRes--; + } + } + if($countRes > 0){ + return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); + }else{ + return response()->json(['status'=>'success' ,'message'=>'Project customer failed created','code'=>400]); + } + }else{ + return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); + } + + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = UserToProyek::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = UserToProyek::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = UserToProyek::find($id); + if($data){ + $userId = $data->user_id; + $proyekId = $data->proyek_id; + $delete = $data->delete(); + if($delete){ + $this->deleteRelative($proyekId, $userId); + } + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); + } + } + + private function deleteRelative($proyekId, $userId) + { + $uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get(); + foreach ($uta as $value) { + $dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); + foreach ($dataRa as $ra) { + $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); + foreach ($images as $image) { + if(file_exists($this->pathImage.$image->image)){ + unlink($this->pathImage.$image->image); + } + } + Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); + } + ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete(); + } + UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete(); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek'); + $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 list() + { + $data = UserToProyek::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400); + } + } + + public function select(Request $request){ + + $search = $request->query('search'); + + $idProyek = (int)$request->query('idProyek'); + $idActivity = (int)$request->query('idact'); + + $include = []; + + if($idActivity && $idActivity > 0){ + $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); + foreach($dataF as $val){ + $include[] = $val->user_id; + } + } + + if($search && !empty($search)){ + $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); + }else{ + $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get(); + } + + if($data instanceof \Illuminate\Database\Eloquent\Collection){ + $pm = array( + "id"=>$this->currentId, + "name"=> "Project Manager" + ); + $data->push($pm); + } + + return response()->json($data); + } + + private function curlReq($url, $token){ + $ch = curl_init(); + $headers = [ + 'Authorization: '.$token + ]; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + $response = curl_exec($ch); + if ($response === false) + $response = curl_error($ch); + curl_close($ch); + + return json_decode($response); + } + + public function getEmployeeIntegration(Request $request) { + $search = urlencode($request->name); + if(empty($search)) + return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); + $url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH'); + $token = config('api.adw_token'); + $firstResponse = $this->curlReq($url, $token); + + if($firstResponse->total == 0) + return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404); + + $data = $firstResponse->data; + return response()->json([$data]); + $currentPage = 1; + + if($firstResponse->last_page > 0) { + do { + $currentPage++; + $response = $this->curlReq($url.'&page='.$currentPage, $token); + foreach($response->data as $d){ + array_push($data, $d); + } + } while ($currentPage < $firstResponse->last_page); + } + + return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200); + } +} From 2a89a8667df85c0e77febab5bf076ea306515b63 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:48:24 +0700 Subject: [PATCH 139/185] add endpoint user-to-proyek/add-multiple --- routes/web.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/web.php b/routes/web.php index a207fe8..adae2bc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -381,6 +381,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); $router->post('/user-to-proyek/add', 'UserToProyekController@add'); + $router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple'); $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'); From 9e093bba04d94b307b8a181fcea126ba20623960 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 12:58:48 +0700 Subject: [PATCH 140/185] created delete method in deleteRelative method --- app/Http/Controllers/ProjectController.php | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 27a3a94..b4cc196 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -2,35 +2,38 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Models\Link; +use App\Models\User; +use App\Models\Image; +use App\Models\Holiday; use App\Models\Project; -use App\Models\UserToProyek; use App\Models\Activity; -use App\Models\UserToActivity; -use App\Models\User; +use App\Jobs\ProcessSCurve; +use App\Models\OfficeHours; +use App\Models\ProjectType; +use App\Models\ProjectPhase; +use App\Models\UserToProyek; +use App\Models\VersionGantt; +use Illuminate\Http\Request; +use App\Models\ProjectIssues; use App\Models\AssignMaterial; use App\Models\DokumenProject; -use App\Models\FolderDocumentProyek; use App\Models\ProjectCharter; -use App\Models\ProjectApproval; -use App\Models\ProjectPhase; -use App\Models\ProjectType; -use App\Models\ProjectMileStone; -use App\Models\ProjectParticipants; +use App\Models\ReportActivity; use App\Models\ShowHideColumn; -use App\Models\VersionGantt; -use App\Models\Image; -use App\Models\CommentActivity; -use App\Models\Link; +use App\Models\UserToActivity; use App\Models\ActivityDokumen; -use App\Models\Holiday; -use App\Models\ReportActivity; -use App\Models\OfficeHours; +use App\Models\CommentActivity; +use App\Models\ProjectApproval; +use App\Models\ProjectMileStone; +use App\Models\ProjectChecklists; use Illuminate\Support\Facades\DB; +use App\Models\ProjectParticipants; +use App\Models\FolderDocumentProyek; use App\Helpers\MasterFunctionsHelper; +use App\Models\ProjectRisks; use App\Models\ReportActivityMaterial; use Illuminate\Support\Facades\Artisan; -use App\Jobs\ProcessSCurve; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; @@ -156,6 +159,9 @@ class ProjectController extends Controller ProjectApproval::where('proyek_id', $project_id)->delete(); ProjectMileStone::where('proyek_id', $project_id)->delete(); ProjectParticipants::where('proyek_id', $project_id)->delete(); + ProjectChecklists::where('proyek_id', $project_id)->delete(); + ProjectIssues::where('proyek_id', $project_id)->delete(); + ProjectRisks::where('proyek_id', $project_id)->delete(); $this->deleteVersionGantt($project_id); $this->deleteDokumenProject($project_id); } From 047fba126bc13909df0eb5c337fbdcc2bdb13ad1 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 12:59:07 +0700 Subject: [PATCH 141/185] add endpoint api --- routes/web.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/routes/web.php b/routes/web.php index adae2bc..376bb43 100644 --- a/routes/web.php +++ b/routes/web.php @@ -292,6 +292,33 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete'); $router->get('/rate-sallary/list', 'RateSallaryController@list'); + $router->post('/project-checklists/add', 'ProjectChecklistsController@add'); + $router->get('/project-checklists/edit/{id}', 'ProjectChecklistsController@edit'); + $router->put('/project-checklists/update/{id}', 'ProjectChecklistsController@update'); + $router->post('/project-checklists/search', 'ProjectChecklistsController@search'); + $router->delete('/project-checklists/delete/{id}', 'ProjectChecklistsController@delete'); + $router->delete('/project-checklists/delete-by-proyek/{id}', 'ProjectChecklistsController@deleteByProyek'); + $router->get('/project-checklists/list', 'ProjectChecklistsController@list'); + $router->get('/project-checklists/{where}/{val}', 'ProjectChecklistsController@customWhere'); + + $router->post('/project-issues/add', 'ProjectIssuesController@add'); + $router->get('/project-issues/edit/{id}', 'ProjectIssuesController@edit'); + $router->put('/project-issues/update/{id}', 'ProjectIssuesController@update'); + $router->post('/project-issues/search', 'ProjectIssuesController@search'); + $router->delete('/project-issues/delete/{id}', 'ProjectIssuesController@delete'); + $router->delete('/project-issues/delete-by-proyek/{id}', 'ProjectIssuesController@deleteByProyek'); + $router->get('/project-issues/list', 'ProjectIssuesController@list'); + $router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere'); + + $router->post('/project-risks/add', 'ProjectRisksController@add'); + $router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit'); + $router->put('/project-issues/update/{id}', 'ProjectRisksController@update'); + $router->post('/project-risks/search', 'ProjectRisksController@search'); + $router->delete('/project-risks/delete/{id}', 'ProjectRisksController@delete'); + $router->delete('/project-risks/delete-by-proyek/{id}', 'ProjectRisksController@deleteByProyek'); + $router->get('/project-risks/list', 'ProjectRisksController@list'); + $router->get('/project-risks/{where}/{val}', 'ProjectRisksController@customWhere'); + $router->post('/project-participants/add', 'ProjectParticipantsController@add'); $router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit'); $router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update'); From 45d6ae61596f8fc526e1d988bc9afa3172750496 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 12:59:49 +0700 Subject: [PATCH 142/185] create controller --- .../ProjectChecklistsController.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 app/Http/Controllers/ProjectChecklistsController.php diff --git a/app/Http/Controllers/ProjectChecklistsController.php b/app/Http/Controllers/ProjectChecklistsController.php new file mode 100644 index 0000000..c7e0590 --- /dev/null +++ b/app/Http/Controllers/ProjectChecklistsController.php @@ -0,0 +1,136 @@ +status_exist==="") { + $request->merge(['status_exist' => true]); + } + + $this->validate($request, [ + 'proyek_id' => 'required', + 'item' => 'required|string', + 'status_exist' => 'boolean' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = ProjectChecklists::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data project participants failed!','code'=>400], 400); + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = ProjectChecklists::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data project participants, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = ProjectChecklists::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = ProjectChecklists::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); + } + } + + public function deleteByProyek($id) + { + $data = ProjectChecklists::where('proyek_id', $id)->delete(); + + if($data){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); + } + } + + public function customWhere($where, $val) + { + $data = ProjectChecklists::where($where, $val)->orderBy('id', 'asc')->get(); + + if($data){ + return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'project_charter_checklist'); + $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 list() + { + $data = ProjectChecklists::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list project participants, please try again later!','code'=>400], 400); + } + } +} From cbac76e19c8946da2e1bdd84e742ecec22945bf4 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 13:00:01 +0700 Subject: [PATCH 143/185] create controller --- .../Controllers/ProjectIssuesController.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 app/Http/Controllers/ProjectIssuesController.php diff --git a/app/Http/Controllers/ProjectIssuesController.php b/app/Http/Controllers/ProjectIssuesController.php new file mode 100644 index 0000000..fc54850 --- /dev/null +++ b/app/Http/Controllers/ProjectIssuesController.php @@ -0,0 +1,136 @@ +level_issue === "") { + $request->merge(['level_issue' => 0]); + } + + $this->validate($request, [ + 'proyek_id' => 'required', + 'description' => 'required|string', + 'level_issue' => 'required|integer' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = ProjectIssues::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data project participants failed!','code'=>400], 400); + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = ProjectIssues::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data project participants, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = ProjectIssues::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = ProjectIssues::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); + } + } + + public function deleteByProyek($id) + { + $data = ProjectIssues::where('proyek_id', $id)->delete(); + + if($data){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); + } + } + + public function customWhere($where, $val) + { + $data = ProjectIssues::where($where, $val)->orderBy('id', 'asc')->get(); + + if($data){ + return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'project_charter_issue'); + $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 list() + { + $data = ProjectIssues::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list project participants, please try again later!','code'=>400], 400); + } + } +} From 2e1567d9f1de5abcb2c1d5f8559fb26ceac21bba Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 13:00:13 +0700 Subject: [PATCH 144/185] create controller --- .../Controllers/ProjectRisksController.php | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 app/Http/Controllers/ProjectRisksController.php diff --git a/app/Http/Controllers/ProjectRisksController.php b/app/Http/Controllers/ProjectRisksController.php new file mode 100644 index 0000000..d5c53df --- /dev/null +++ b/app/Http/Controllers/ProjectRisksController.php @@ -0,0 +1,137 @@ +level_risk === "") { + $request->merge(['level_risk' => 0]); + } + + $this->validate($request, [ + 'proyek_id' => 'required', + 'level_risk' => 'required|integer', + 'description' => 'required|string', + 'preventive_risk' => 'required|string' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = ProjectRisks::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data project participants failed!','code'=>400], 400); + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = ProjectRisks::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data project participants, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = ProjectRisks::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = ProjectRisks::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); + } + } + + public function deleteByProyek($id) + { + $data = ProjectRisks::where('proyek_id', $id)->delete(); + + if($data){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); + } + } + + public function customWhere($where, $val) + { + $data = ProjectRisks::where($where, $val)->orderBy('id', 'asc')->get(); + + if($data){ + return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'project_charter_risk'); + $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 list() + { + $data = ProjectRisks::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list project participants, please try again later!','code'=>400], 400); + } + } +} From 065ca6291c4fced4127eaadbbacdd2008b9a7c2d Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 13:00:30 +0700 Subject: [PATCH 145/185] create model --- app/Models/ProjectChecklists.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/Models/ProjectChecklists.php diff --git a/app/Models/ProjectChecklists.php b/app/Models/ProjectChecklists.php new file mode 100644 index 0000000..fb37975 --- /dev/null +++ b/app/Models/ProjectChecklists.php @@ -0,0 +1,23 @@ + Date: Wed, 20 Sep 2023 13:00:44 +0700 Subject: [PATCH 146/185] create model --- app/Models/ProjectIssues.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/Models/ProjectIssues.php diff --git a/app/Models/ProjectIssues.php b/app/Models/ProjectIssues.php new file mode 100644 index 0000000..c3560b4 --- /dev/null +++ b/app/Models/ProjectIssues.php @@ -0,0 +1,23 @@ + Date: Wed, 20 Sep 2023 13:01:06 +0700 Subject: [PATCH 147/185] create model --- app/Models/ProjectRisks.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/Models/ProjectRisks.php diff --git a/app/Models/ProjectRisks.php b/app/Models/ProjectRisks.php new file mode 100644 index 0000000..dba2ecd --- /dev/null +++ b/app/Models/ProjectRisks.php @@ -0,0 +1,24 @@ + Date: Wed, 20 Sep 2023 14:01:19 +0700 Subject: [PATCH 148/185] project detail use gantt id --- app/Http/Controllers/ProjectController.php | 15 +++++++++------ routes/web.php | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 6fe1c12..b275a66 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -469,7 +469,7 @@ class ProjectController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); } - public function detail($id){ + public function detail(Request $request, $id, $gantt_id = null){ if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); @@ -477,12 +477,15 @@ class ProjectController extends Controller if(!$result) return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $gantt = MasterFunctionsHelper::getLatestGantt($id); + if (!isset($gantt_id)) { + $gantt = MasterFunctionsHelper::getLatestGantt($id); + $ganttId = $gantt['last_gantt_id']; + } else { + $ganttId = $gantt_id; + } $result->projectManager = User::where('id', $result->pm_id)->value('name'); - $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first(); + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); // dd($result->header->start_date); - $ganttId = $gantt['last_gantt_id']; $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); @@ -507,7 +510,7 @@ class ProjectController extends Controller } $result->header->start_date = $startDate; $result->header->end_date = $endDate; - return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); + return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); } public function getOverdueActivities(Request $request){ diff --git a/routes/web.php b/routes/web.php index a207fe8..8e669a2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,7 +58,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); $router->get('/project/edit/{id}', 'ProjectController@edit'); - $router->get('/project/detail/{id}', 'ProjectController@detail'); + $router->get('/project/detail/{id}[/{gantt_id}]', 'ProjectController@detail'); $router->delete('/project/delete/{id}', 'ProjectController@delete'); $router->get('/project/list', 'ProjectController@list'); $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline'); From 0d74de7e7488bf659c8e6380a1eec99d8309097e Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 21 Sep 2023 08:51:37 +0700 Subject: [PATCH 149/185] fix endline, fix sync report --- app/Http/Controllers/ActivityController.php | 1826 +++++++++---------- app/Http/Controllers/ProjectController.php | 8 +- app/Models/Activity.php | 492 ++--- 3 files changed, 1166 insertions(+), 1160 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 03990d9..b8af8d4 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -1,913 +1,913 @@ -where("version_gantt_id", $id)->count() == 0) { - if (!$gantt->hierarchy_ftth_id) { - $this->cloneTemplate($id, $proyek_id); - } else { - $this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_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->progress = $dataHeader->persentase_progress / 100; - $dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start), "Y-m-d H:i:s") : NULL; - $dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL; - - $actualStart = $this->getFirstLastDateActivity($dataHeader->id, "start"); - $dataHeader->actual_start = date_format(date_create($actualStart), "Y-m-d"); - $actualEnd = $this->getFirstLastDateActivity($dataHeader->id, "end"); - $dataHeader->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; - - $dataHeader->type = "header"; - $dataHeader->text = $dataHeader->name; - $finalData[] = $dataHeader; - $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get(); - } else { - $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get(); - } - - foreach ($data as $objRow) { - $type = "project"; - $dataChildren = $this->getChildren($id, $objRow->id); - $startDate = date_create($objRow->start_date); - $endDate = date_create($objRow->end_date); - - if ($objRow->type_activity == "milestone") - $type = $objRow->type_activity; - if (empty($dataChildren)) - $type = "task"; - - $objRow->text = $objRow->name; - $objRow->parent = $objRow->parent_id ? $objRow->parent_id : null; - $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; - - $actualStart = $this->getFirstLastDateActivity($objRow->id, "start"); - $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; - $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end"); - $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; - - $objRow->progress = $objRow->persentase_progress / 100; - $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('sortorder', 'asc')->get(); - foreach ($data as $objRow) { - $objRow->parent = $parent_id; - $objRow->text = $objRow->name; - $objRow->progress = (float) $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; - $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; - } elseif (empty($dataChildren)) { - $objRow->type = "task"; - $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; - $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; - if(isset($objRow->actual_start)){ - $objRow->auto_scheduling = false; - } - } else { - $objRow->type = "project"; - $actualStart = $this->getFirstLastDateActivity($objRow->id, "start"); - $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; - - $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end"); - $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; - } - $finalData[] = $objRow; - $finalData = array_merge($finalData, $dataChildren); - } - return $finalData; - } - - public function getActivityFirst($parentId){ - $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first(); - if (!isset($activity)) { - return null; - } - if($activity->type_activity == "task"){ - // Log::info("activity ", [$activity]); - return $activity->actual_start; - }else{ - return $this->getActivityFirst($activity->id); - } - - } - - public function getFirstLastDateActivity($id, $params){ - if($params == "start"){ - $data = Activity::select('id', 'parent_id', 'name', 'actual_start')->where('parent_id', $id)->get(); - }else{ - $data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get(); - } - $dataFinal=[]; - foreach ($data as $val) { - $activity = $this->getchildActivityForActual($val->id, $params); - $dataFinal[] = $val; - $dataFinal = array_merge($dataFinal, $activity); - - } - if($params == "start"){ - $actualStartValues = array_column(array_filter($dataFinal, function($item) { - return isset($item['actual_start']); - }), 'actual_start'); - - $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; - }else{ - $actualEndValues = array_column(array_filter($dataFinal, function($item) { - return isset($item['actual_end']); - }), 'actual_end'); - - $returnActualStartOrEnd = count($actualEndValues) > 0 ? max($actualEndValues) : null; - } - - // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); - return $returnActualStartOrEnd; - } - - public function getchildActivityForActual($parent, $params){ - if($params == "start"){ - $activity = Activity::select('id', 'actual_start')->where('parent_id', $parent)->get(); - }else{ - $activity = Activity::select('id', 'actual_end')->where('parent_id', $parent)->get(); - } - $temp = []; - foreach($activity as $val1){ - $getChild = $this->getchildActivityForActual($val1->id, $params); - $temp[] = $val1; - $temp = array_merge($temp, $getChild); - } - return $temp; - } - - public function getActivityLast($parentId){ - $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); - if (!isset($activity)) { - return null; - } - if($activity->type_activity == "task"){ - // Log::info("activity ", [$activity]); - return $activity->actual_end; - }else{ - return $this->getActivityLast($activity->id); - } - - } - - private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) - { - $project = Project::find($proyek_id); - if ($hierarchy_ftth_id) { - $gantt = VersionGantt::find($id); - $rootActivity = Activity::create([ - 'version_gantt_id' => $id, - 'proyek_id' => $proyek_id, - 'name' => $gantt->name_version, - 'start_date' => $project->mulai_proyek, - 'end_date' => $project->akhir_proyek, - 'rencana_biaya' => $project->rencana_biaya, - 'type_activity' => 'project', - 'created_by' => $this->currentName, - 'sortorder' => 1 - ]); - } else { - $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' => $project->rencana_biaya, - 'type_activity' => 'project', - 'created_by' => $this->currentName, - 'sortorder' => 1 - ]); - } - - $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(); - $max = Activity::where('version_gantt_id', $id)->max('sortorder'); - $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, - 'sortorder' => $max + 1 - ]); - $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('parent_id', $parent_id)->orderByRaw('id ASC')->get(); - foreach ($data as $objRow) { - $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); - $max = Activity::where('version_gantt_id', $id)->max('sortorder'); - $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, - 'sortorder' => $max + 1 - ]); - $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; - $max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder'); - $data['sortorder'] = $max + 1; - if (!isset($data['type_activity'])) { - $data['type_activity'] = "task"; - } - - $parent = $data['parent_id'] ?? null; - if ($parent) { - $parentData = Activity::find($parent); - if ($parentData->parent_id) { - $parentData->update(["type_activity" => "project"]); - } - CommentActivity::where('activity_id', $parent)->delete(); - UserToActivity::where('activity_id', $parent)->delete(); - } - - 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); - } - - 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 = true; - if (!$data = Activity::find($id)) - return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); - $dataUpdate = $request->all(); - - $dataUpdate['name'] = $request->text; - $dataUpdate['persentase_progress'] = $request->progress * 100; - $dataUpdate['updated_by'] = $this->currentName; - unset($dataUpdate['sortorder']); - if ($data->type_activity != 'header') - $dataUpdate['type_activity'] = $request->type; - - if ($request->has("target")) { - $this->updateOrder($id, $request->target); - } - - if (!$data->update($dataUpdate)) - return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed updated!', 'code' => 400], 400); - - return response()->json(['status' => 'success', 'update_bobot' => $updateBobot, 'data' => $dataUpdate, 'action' => 'updated', 'message' => 'Activity updated!', 'code' => 200], 200); - } - - private function updateOrder($taskId, $target) - { - $nextTask = false; - $targetId = $target; - - if (strpos($target, "next:") === 0) { - $targetId = substr($target, strlen("next:")); - $nextTask = true; - } - - if ($targetId == "null") - return; - - $targetOrder = Activity::find($targetId)->sortorder; - if ($nextTask) - $targetOrder++; - - Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder"); - - $updatedTask = Activity::find($taskId); - $updatedTask->sortorder = $targetOrder; - $updatedTask->save(); - } - - public function updateRegular(Request $request, $id) - { - if (empty($id) || !is_int((int) $id)) - return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); - - $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); - } - - public function batchUpdate(Request $request, $ganttId) - { - $entities = $request->all(); - if (empty($ganttId) || !is_int((int) $ganttId)) - return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); - $activity = Activity::where('version_gantt_id',$ganttId)->get(); - $link = Link::where('version_gantt_id', $ganttId)->get(); - if (!$activity) - return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404); - if (!$link) - return response()->json(['status' => 'failed', 'message' => 'Link not found!', 'code' => 404], 404); - foreach ($entities as $entity) { - if ($entity['entity'] == "task") { - $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); - $entity['data']['name'] = $entity['data']['text']; - $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; - if (isset($entity['data']['target'])) { - $this->updateOrder($entity['data']['id'], $entity['data']['target']); - } - if(!$activityToUpdate->update($entity['data'])) - return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); - $updatedJobsDone = $activityToUpdate->jobs_done; - } else if ($entity['entity'] == "link"){ - $linkToUpdate = $link->firstWhere('id', $entity['data']['id']); - if(!$linkToUpdate->update($entity['data'])) - return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500); - } - } - return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); - } - - public function delete($id) - { - if (!$data = Activity::find($id)) - return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); - - 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); - } - - 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 = (float) $data->persentase_progress / 100; - $data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya); - return response()->json(['status' => 'success', "data" => $data, 'code' => 200], 200); - } - - 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); - } - - // before upload file - public function importOld(Request $request) - { - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - Activity::where('version_gantt_id', $data['ganttId'])->delete(); - - $projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id; - $dayOffs = VersionGantt::where('id', $data['ganttId'])->first()->config_dayoff; - - $activityStack = []; - - $hasWeight = false; - - foreach ($data['activities'] as $key => $value) { - if (isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0) { - $hasWeight = true; - break; - } - } - - if (!$hasWeight) { - foreach ($data['activities'] as $key => $value) { - if ($key == 0) { - $data['activities'][$key]['weight'] = 100; - } else { - $parentWeight = 0; - $siblingsCount = 1; - - $i = $key; - while ($i > 0) { - if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level'] - 1) { - $parentWeight = $data['activities'][$i - 1]['weight']; - break; - } - if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) { - $siblingsCount++; - } - $i--; - } - - $i = $key + 1; - while ($i < count($data['activities'])) { - if ($data['activities'][$i]['level'] == $data['activities'][$key]['level'] - 1) { - break; - } - // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); - if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) { - $siblingsCount++; - } - $i++; - } - - $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; - } - } - ; - } - $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); - foreach ($data['activities'] as $i => $activity_row) { - $startDate = new \DateTime($projectStart->mulai_proyek); - $endDate = clone $startDate; - $endDate->modify('-1 day'); - $daysRemaining = $activity_row['duration']; - - // Loop until the remaining days become zero - while ($daysRemaining > 0) { - $endDate->modify('+1 day'); - - // Check if the current day is a day off (Sunday or Saturday) - $currentDayOfWeek = (int) $endDate->format('w'); - if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) { - continue; // Skip the day off and continue to the next day - } - - $daysRemaining--; // Decrease the remaining days by one - } - $endDate->setTime(23, 59, 59); - $input['name'] = $activity_row['name']; - $input['proyek_id'] = $projectId; - $input['version_gantt_id'] = $data['ganttId']; - $input['parent_id'] = null; - $input['start_date'] = $startDate->format('Y-m-d'); - $input['end_date'] = $endDate->format('Y-m-d H:i:sO'); - $input['duration'] = $activity_row['duration']; - $input['bobot_planning'] = $activity_row['weight']; - $input['persentase_progress'] = 0; - $input['type_activity'] = $i == 0 ? "header" : "task"; - $input['created_by'] = $this->currentName; - $input['sortorder'] = $activity_row['no']; - - if (!$activity = Activity::create($input)) { - Activity::where('version_gantt_id', $data['ganttId'])->delete(); - return response()->json(['status' => 'error', 'message' => 'Input failed on ' . $activity['name'], 'code' => 500], 500); - } - - $data['activities'][$i]['activity_id'] = $activity->id; - - if ($i == 0) { - $activity->type_activity = "project"; - $activity->save(); - $activity->level = $activity_row['level']; - array_push($activityStack, $activity); - continue; - } - - $activity->level = $activity_row['level']; - - if ($lastStack = end($activityStack)) { - $levelLowerThanLastStack = $activity->level < $lastStack->level; - $levelEqualWithLastStack = $activity->level == $lastStack->level; - - if ($levelLowerThanLastStack) { - $lastStackIsNotRight = $levelLowerThanLastStack; - do { - array_pop($activityStack); - $lastStack = end($activityStack); - if ($lastStack) { - if ($activity->level > $lastStack->level) - $lastStackIsNotRight = false; - } else { - $lastStackIsNotRight = false; - } - } while ($lastStackIsNotRight); - } - - if ($levelEqualWithLastStack) { - array_pop($activityStack); - } - } - - $activity->parent_id = $activityStack[count($activityStack) - 1]->id ?? null; - array_push($activityStack, $activity); - // there should be better way to except / filter attribute level before save because it's cause error - // cant use except() / filter() on $activity collection somehow - unset($activity->level); - $activity->save(); - $activity->level = $activity_row['level']; - - if (@$activityStack[count($activityStack) - 1]->level != $activity->level && $activity->level != $data['activities'][$i - 1]['level']) { - array_push($activityStack, $activity); - } - - if ($activity->level < @$data['activities'][$i + 1]['level']) { - unset($activity->level); - $activity->type_activity = "project"; - $activity->save(); - $activity->level = $activity_row['level']; - } - if (isset($data['activities'][$i]['nik']) && $data['activities'][$i]['nik'] != '') { - $user = User::where("ktp_number", $data['activities'][$i]['nik'])->first(); - $userProyek = UserToProyek::where("user_id", $user->id) - ->where("proyek_id", $projectId) - ->first(); - - $dataInsert = array( - "user_id" => $user->id, - "activity_id" => $activity->id, - "role_proyek_id" => $userProyek->project_role, - "proyek_id" => $projectId, - "created_by" => $this->currentName, - "version_gantt_id" => $data['ganttId'] - ); - UserToActivity::create($dataInsert); - } - - if (!empty($activity_row['predecessor'])) { - $key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no')); - - if (!isset($data['activities'][$key]['activity_id']) || !$predecessorActivity = Activity::find($data['activities'][$key]['activity_id'])) - continue; - - $predecessorFinishDate = new \DateTime($predecessorActivity->end_date); - $interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date)); - $diff = $interval->days; - - Link::create([ - 'created_by' => $this->currentName, - 's_activity_id' => $predecessorActivity->id, - 't_activity_id' => $activity->id, - 'type_link' => 0, - 'code_link' => 'FS', - 'version_gantt_id' => $data['ganttId'], - 'lag' => null, - ]); - } - } - - return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200); - } - - private function getLatestGantt($id) - { - $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); - $data = array( - "last_gantt_id" => $maxGanttId, - "proyek_id" => $id - ); - return $data; - } - - 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 import(Request $request) - { - $data = $request->all(); - $data['created_by'] = $this->currentName; - Activity::where('version_gantt_id', $data['gantt_id'])->delete(); - $projectId = VersionGantt::where('id', $data['gantt_id'])->first()->proyek_id; - // get data excel - $excel = TmpImport::latest('id')->first(); - - return response()->json(['stack' => $excel, 'status' => 'success', 'message' => 'Data imported!', 'data' => $data, 'code' => 200], 200); - } - - public function uploadTmpImport(Request $request) - { - if ($request->hasFile('dokumen')) { - $document = $request->file('dokumen'); - $gantt_id = $request->gantt_id; - $name = $document->getClientOriginalName(); - - $result = $document->move($this->pathTmpImport, $name); - if ($result) { - $data = [ - 'gantt_id' => (int) $gantt_id, - 'file' => $name, - 'type_dokumen' => $request->type_dokumen - ]; - - $result = TmpImport::create($data); - - if (!$result) { - unlink($this->pathTmpImport . $name); - return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); - } - return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200); - - } - return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); - } - return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400); - } - - public function importUpdate(Request $request) - { - $data = $request->all(); - foreach ($data as $value) { - $activity = Activity::find($value['id']); - $activity->duration = $value['duration']; - $activity->start_date = $value['start_date']; - $activity->end_date = $value['end_date']; - $activity->save(); - } - return response()->json(['status' => 'success', 'data' => $request, 'message' => 'Update successful!', 'code' => 200], 200); - } -} \ No newline at end of file +where("version_gantt_id", $id)->count() == 0) { + if (!$gantt->hierarchy_ftth_id) { + $this->cloneTemplate($id, $proyek_id); + } else { + $this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_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->progress = $dataHeader->persentase_progress / 100; + $dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start), "Y-m-d H:i:s") : NULL; + $dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL; + + $actualStart = $this->getFirstLastDateActivity($dataHeader->id, "start"); + $dataHeader->actual_start = date_format(date_create($actualStart), "Y-m-d"); + $actualEnd = $this->getFirstLastDateActivity($dataHeader->id, "end"); + $dataHeader->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; + + $dataHeader->type = "header"; + $dataHeader->text = $dataHeader->name; + $finalData[] = $dataHeader; + $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get(); + } else { + $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get(); + } + + foreach ($data as $objRow) { + $type = "project"; + $dataChildren = $this->getChildren($id, $objRow->id); + $startDate = date_create($objRow->start_date); + $endDate = date_create($objRow->end_date); + + if ($objRow->type_activity == "milestone") + $type = $objRow->type_activity; + if (empty($dataChildren)) + $type = "task"; + + $objRow->text = $objRow->name; + $objRow->parent = $objRow->parent_id ? $objRow->parent_id : null; + $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; + + $actualStart = $this->getFirstLastDateActivity($objRow->id, "start"); + $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; + $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end"); + $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; + + $objRow->progress = $objRow->persentase_progress / 100; + $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('sortorder', 'asc')->get(); + foreach ($data as $objRow) { + $objRow->parent = $parent_id; + $objRow->text = $objRow->name; + $objRow->progress = (float) $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; + $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; + } elseif (empty($dataChildren)) { + $objRow->type = "task"; + $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; + $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; + if(isset($objRow->actual_start)){ + $objRow->auto_scheduling = false; + } + } else { + $objRow->type = "project"; + $actualStart = $this->getFirstLastDateActivity($objRow->id, "start"); + $objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL; + + $actualEnd = $this->getFirstLastDateActivity($objRow->id, "end"); + $objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL; + } + $finalData[] = $objRow; + $finalData = array_merge($finalData, $dataChildren); + } + return $finalData; + } + + public function getActivityFirst($parentId){ + $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first(); + if (!isset($activity)) { + return null; + } + if($activity->type_activity == "task"){ + // Log::info("activity ", [$activity]); + return $activity->actual_start; + }else{ + return $this->getActivityFirst($activity->id); + } + + } + + public function getFirstLastDateActivity($id, $params){ + if($params == "start"){ + $data = Activity::select('id', 'parent_id', 'name', 'actual_start')->where('parent_id', $id)->get(); + }else{ + $data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get(); + } + $dataFinal=[]; + foreach ($data as $val) { + $activity = $this->getchildActivityForActual($val->id, $params); + $dataFinal[] = $val; + $dataFinal = array_merge($dataFinal, $activity); + + } + if($params == "start"){ + $actualStartValues = array_column(array_filter($dataFinal, function($item) { + return isset($item['actual_start']); + }), 'actual_start'); + + $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; + }else{ + $actualEndValues = array_column(array_filter($dataFinal, function($item) { + return isset($item['actual_end']); + }), 'actual_end'); + + $returnActualStartOrEnd = count($actualEndValues) > 0 ? max($actualEndValues) : null; + } + + // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); + return $returnActualStartOrEnd; + } + + public function getchildActivityForActual($parent, $params){ + if($params == "start"){ + $activity = Activity::select('id', 'actual_start')->where('parent_id', $parent)->get(); + }else{ + $activity = Activity::select('id', 'actual_end')->where('parent_id', $parent)->get(); + } + $temp = []; + foreach($activity as $val1){ + $getChild = $this->getchildActivityForActual($val1->id, $params); + $temp[] = $val1; + $temp = array_merge($temp, $getChild); + } + return $temp; + } + + public function getActivityLast($parentId){ + $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); + if (!isset($activity)) { + return null; + } + if($activity->type_activity == "task"){ + // Log::info("activity ", [$activity]); + return $activity->actual_end; + }else{ + return $this->getActivityLast($activity->id); + } + + } + + private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) + { + $project = Project::find($proyek_id); + if ($hierarchy_ftth_id) { + $gantt = VersionGantt::find($id); + $rootActivity = Activity::create([ + 'version_gantt_id' => $id, + 'proyek_id' => $proyek_id, + 'name' => $gantt->name_version, + 'start_date' => $project->mulai_proyek, + 'end_date' => $project->akhir_proyek, + 'rencana_biaya' => $project->rencana_biaya, + 'type_activity' => 'project', + 'created_by' => $this->currentName, + 'sortorder' => 1 + ]); + } else { + $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' => $project->rencana_biaya, + 'type_activity' => 'project', + 'created_by' => $this->currentName, + 'sortorder' => 1 + ]); + } + + $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(); + $max = Activity::where('version_gantt_id', $id)->max('sortorder'); + $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, + 'sortorder' => $max + 1 + ]); + $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('parent_id', $parent_id)->orderByRaw('id ASC')->get(); + foreach ($data as $objRow) { + $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); + $max = Activity::where('version_gantt_id', $id)->max('sortorder'); + $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, + 'sortorder' => $max + 1 + ]); + $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; + $max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder'); + $data['sortorder'] = $max + 1; + if (!isset($data['type_activity'])) { + $data['type_activity'] = "task"; + } + + $parent = $data['parent_id'] ?? null; + if ($parent) { + $parentData = Activity::find($parent); + if ($parentData->parent_id) { + $parentData->update(["type_activity" => "project"]); + } + CommentActivity::where('activity_id', $parent)->delete(); + UserToActivity::where('activity_id', $parent)->delete(); + } + + 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); + } + + 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 = true; + if (!$data = Activity::find($id)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); + $dataUpdate = $request->all(); + + $dataUpdate['name'] = $request->text; + $dataUpdate['persentase_progress'] = $request->progress * 100; + $dataUpdate['updated_by'] = $this->currentName; + unset($dataUpdate['sortorder']); + if ($data->type_activity != 'header') + $dataUpdate['type_activity'] = $request->type; + + if ($request->has("target")) { + $this->updateOrder($id, $request->target); + } + + if (!$data->update($dataUpdate)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed updated!', 'code' => 400], 400); + + return response()->json(['status' => 'success', 'update_bobot' => $updateBobot, 'data' => $dataUpdate, 'action' => 'updated', 'message' => 'Activity updated!', 'code' => 200], 200); + } + + private function updateOrder($taskId, $target) + { + $nextTask = false; + $targetId = $target; + + if (strpos($target, "next:") === 0) { + $targetId = substr($target, strlen("next:")); + $nextTask = true; + } + + if ($targetId == "null") + return; + + $targetOrder = Activity::find($targetId)->sortorder; + if ($nextTask) + $targetOrder++; + + Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder"); + + $updatedTask = Activity::find($taskId); + $updatedTask->sortorder = $targetOrder; + $updatedTask->save(); + } + + public function updateRegular(Request $request, $id) + { + if (empty($id) || !is_int((int) $id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $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); + } + + public function batchUpdate(Request $request, $ganttId) + { + $entities = $request->all(); + if (empty($ganttId) || !is_int((int) $ganttId)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + $activity = Activity::where('version_gantt_id',$ganttId)->get(); + $link = Link::where('version_gantt_id', $ganttId)->get(); + if (!$activity) + return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404); + if (!$link) + return response()->json(['status' => 'failed', 'message' => 'Link not found!', 'code' => 404], 404); + foreach ($entities as $entity) { + if ($entity['entity'] == "task") { + $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); + $entity['data']['name'] = $entity['data']['text']; + $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; + if (isset($entity['data']['target'])) { + $this->updateOrder($entity['data']['id'], $entity['data']['target']); + } + if(!$activityToUpdate->update($entity['data'])) + return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); + $updatedJobsDone = $activityToUpdate->jobs_done; + } else if ($entity['entity'] == "link"){ + $linkToUpdate = $link->firstWhere('id', $entity['data']['id']); + if(!$linkToUpdate->update($entity['data'])) + return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500); + } + } + return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); + } + + public function delete($id) + { + if (!$data = Activity::find($id)) + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); + + 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); + } + + 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 = (float) $data->persentase_progress / 100; + $data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya); + return response()->json(['status' => 'success', "data" => $data, 'code' => 200], 200); + } + + 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); + } + + // before upload file + public function importOld(Request $request) + { + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + Activity::where('version_gantt_id', $data['ganttId'])->delete(); + + $projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id; + $dayOffs = VersionGantt::where('id', $data['ganttId'])->first()->config_dayoff; + + $activityStack = []; + + $hasWeight = false; + + foreach ($data['activities'] as $key => $value) { + if (isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0) { + $hasWeight = true; + break; + } + } + + if (!$hasWeight) { + foreach ($data['activities'] as $key => $value) { + if ($key == 0) { + $data['activities'][$key]['weight'] = 100; + } else { + $parentWeight = 0; + $siblingsCount = 1; + + $i = $key; + while ($i > 0) { + if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level'] - 1) { + $parentWeight = $data['activities'][$i - 1]['weight']; + break; + } + if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) { + $siblingsCount++; + } + $i--; + } + + $i = $key + 1; + while ($i < count($data['activities'])) { + if ($data['activities'][$i]['level'] == $data['activities'][$key]['level'] - 1) { + break; + } + // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); + if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) { + $siblingsCount++; + } + $i++; + } + + $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; + } + } + ; + } + $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); + foreach ($data['activities'] as $i => $activity_row) { + $startDate = new \DateTime($projectStart->mulai_proyek); + $endDate = clone $startDate; + $endDate->modify('-1 day'); + $daysRemaining = $activity_row['duration']; + + // Loop until the remaining days become zero + while ($daysRemaining > 0) { + $endDate->modify('+1 day'); + + // Check if the current day is a day off (Sunday or Saturday) + $currentDayOfWeek = (int) $endDate->format('w'); + if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) { + continue; // Skip the day off and continue to the next day + } + + $daysRemaining--; // Decrease the remaining days by one + } + $endDate->setTime(23, 59, 59); + $input['name'] = $activity_row['name']; + $input['proyek_id'] = $projectId; + $input['version_gantt_id'] = $data['ganttId']; + $input['parent_id'] = null; + $input['start_date'] = $startDate->format('Y-m-d'); + $input['end_date'] = $endDate->format('Y-m-d H:i:sO'); + $input['duration'] = $activity_row['duration']; + $input['bobot_planning'] = $activity_row['weight']; + $input['persentase_progress'] = 0; + $input['type_activity'] = $i == 0 ? "header" : "task"; + $input['created_by'] = $this->currentName; + $input['sortorder'] = $activity_row['no']; + + if (!$activity = Activity::create($input)) { + Activity::where('version_gantt_id', $data['ganttId'])->delete(); + return response()->json(['status' => 'error', 'message' => 'Input failed on ' . $activity['name'], 'code' => 500], 500); + } + + $data['activities'][$i]['activity_id'] = $activity->id; + + if ($i == 0) { + $activity->type_activity = "project"; + $activity->save(); + $activity->level = $activity_row['level']; + array_push($activityStack, $activity); + continue; + } + + $activity->level = $activity_row['level']; + + if ($lastStack = end($activityStack)) { + $levelLowerThanLastStack = $activity->level < $lastStack->level; + $levelEqualWithLastStack = $activity->level == $lastStack->level; + + if ($levelLowerThanLastStack) { + $lastStackIsNotRight = $levelLowerThanLastStack; + do { + array_pop($activityStack); + $lastStack = end($activityStack); + if ($lastStack) { + if ($activity->level > $lastStack->level) + $lastStackIsNotRight = false; + } else { + $lastStackIsNotRight = false; + } + } while ($lastStackIsNotRight); + } + + if ($levelEqualWithLastStack) { + array_pop($activityStack); + } + } + + $activity->parent_id = $activityStack[count($activityStack) - 1]->id ?? null; + array_push($activityStack, $activity); + // there should be better way to except / filter attribute level before save because it's cause error + // cant use except() / filter() on $activity collection somehow + unset($activity->level); + $activity->save(); + $activity->level = $activity_row['level']; + + if (@$activityStack[count($activityStack) - 1]->level != $activity->level && $activity->level != $data['activities'][$i - 1]['level']) { + array_push($activityStack, $activity); + } + + if ($activity->level < @$data['activities'][$i + 1]['level']) { + unset($activity->level); + $activity->type_activity = "project"; + $activity->save(); + $activity->level = $activity_row['level']; + } + if (isset($data['activities'][$i]['nik']) && $data['activities'][$i]['nik'] != '') { + $user = User::where("ktp_number", $data['activities'][$i]['nik'])->first(); + $userProyek = UserToProyek::where("user_id", $user->id) + ->where("proyek_id", $projectId) + ->first(); + + $dataInsert = array( + "user_id" => $user->id, + "activity_id" => $activity->id, + "role_proyek_id" => $userProyek->project_role, + "proyek_id" => $projectId, + "created_by" => $this->currentName, + "version_gantt_id" => $data['ganttId'] + ); + UserToActivity::create($dataInsert); + } + + if (!empty($activity_row['predecessor'])) { + $key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no')); + + if (!isset($data['activities'][$key]['activity_id']) || !$predecessorActivity = Activity::find($data['activities'][$key]['activity_id'])) + continue; + + $predecessorFinishDate = new \DateTime($predecessorActivity->end_date); + $interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date)); + $diff = $interval->days; + + Link::create([ + 'created_by' => $this->currentName, + 's_activity_id' => $predecessorActivity->id, + 't_activity_id' => $activity->id, + 'type_link' => 0, + 'code_link' => 'FS', + 'version_gantt_id' => $data['ganttId'], + 'lag' => null, + ]); + } + } + + return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200); + } + + private function getLatestGantt($id) + { + $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); + $data = array( + "last_gantt_id" => $maxGanttId, + "proyek_id" => $id + ); + return $data; + } + + 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 import(Request $request) + { + $data = $request->all(); + $data['created_by'] = $this->currentName; + Activity::where('version_gantt_id', $data['gantt_id'])->delete(); + $projectId = VersionGantt::where('id', $data['gantt_id'])->first()->proyek_id; + // get data excel + $excel = TmpImport::latest('id')->first(); + + return response()->json(['stack' => $excel, 'status' => 'success', 'message' => 'Data imported!', 'data' => $data, 'code' => 200], 200); + } + + public function uploadTmpImport(Request $request) + { + if ($request->hasFile('dokumen')) { + $document = $request->file('dokumen'); + $gantt_id = $request->gantt_id; + $name = $document->getClientOriginalName(); + + $result = $document->move($this->pathTmpImport, $name); + if ($result) { + $data = [ + 'gantt_id' => (int) $gantt_id, + 'file' => $name, + 'type_dokumen' => $request->type_dokumen + ]; + + $result = TmpImport::create($data); + + if (!$result) { + unlink($this->pathTmpImport . $name); + return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); + } + return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200); + + } + return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); + } + return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400); + } + + public function importUpdate(Request $request) + { + $data = $request->all(); + foreach ($data as $value) { + $activity = Activity::find($value['id']); + $activity->duration = $value['duration']; + $activity->start_date = $value['start_date']; + $activity->end_date = $value['end_date']; + $activity->save(); + } + return response()->json(['status' => 'success', 'data' => $request, 'message' => 'Update successful!', 'code' => 200], 200); + } +} diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index b275a66..3dc7fcc 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -399,7 +399,13 @@ class ProjectController extends Controller $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); } - $activity->reports = $reports; + $activity->reports = $reports; + $successor = Link::where('t_activity_id', $activity->id)->first(); + if ($successor) { + $predecessor = Activity::find($successor->s_activity_id); + $activity->start_date = $predecessor->end_date; + } + $activity->save(); } /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 3d09785..3a8e54c 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -1,246 +1,246 @@ -timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - return Carbon::createFromTimestamp(strtotime($value)) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - - public function getEndDateAttribute($value) - { - if ($value instanceof \DateTime) { - return Carbon::instance($value) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - return Carbon::createFromTimestamp(strtotime($value)) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - - - public static function boot() { - parent::boot(); - - static::updating(function($data) { - $data->logPersentaseProgress(); - }); - - static::updated(function($data) { - $data->updateBobot(); - $data->updateCostPlanning(); - if($data->bobot_planning){ - $data->updatePersentaseProgress(); - } - $data->updateCostActual(); - // if($data->start_date != request()->start_date || $data->end_date != request()->end_date) { - // $data->updateStartEndDateHeader(); - // } - }); - - static::deleted(function($data) { - if(Activity::where("parent_id", $data->parent_id)->count() == 0) - Activity::find($data->parent_id)->update(["type_activity"=>"task"]); - - $data->updateBobot(true); - $data->updateCostPlanning(); - if($data->bobot_planning){ - $data->updatePersentaseProgress(); - } - $data->updateCostActual(); - $data->updateStartEndDateHeader(); - }); - - } - - private function updateBobot($isDelete = false) - { - $root = Activity::where('version_gantt_id', $this->version_gantt_id) - ->where("proyek_id", $this->proyek_id) - ->whereNull('parent_id') - ->first(); - - if($root->rencana_biaya > 0){ - $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); - foreach ($activities as $activity) { - if($isDelete && $activity->id == $this->id) - continue; - - $activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100; - $activity->updated_by = auth()->user() ? auth()->user()->name : "system"; - $activity->saveQuietly(); - - } - } else { - if($parent = Activity::find($this->parent_id)){ - $totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning'); - $parent->update([ - "bobot_planning" => $totalChildWeight - ]); - } - } - } - - 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() - { - if($parent = Activity::find($this->parent_id)){ - $parentActWeight = $parent->bobot_planning; - - if ($parentActWeight == 0) { - $parent->update([ - "persentase_progress" => 0 - ]); - return; - } - - $totalChildProportionalProgress = 0; - $childs = Activity::where("parent_id", $parent->id)->get(); - foreach($childs as $child){ - $currentActWeight = $child->bobot_planning; - $currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress; - $totalChildProportionalProgress += $currentActProportionalProgress; - } - $parent->update([ - "persentase_progress" => $totalChildProportionalProgress - ]); - } - } - - 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, - ]); - } - } - - private function logPersentaseProgress() - { - ActivityProgressLog::create([ - 'version_gantt_id' => $this->version_gantt_id, - 'activity_id' => request()->id, - 'old_percentage' => $this->persentase_progress, - 'new_percentage' => request()->persentase_progress, - 'variance' => $this->persentase_progress - request()->persentase_progress, - 'created_by'=> "system" - ]); - } - - private function updateStartEndDateHeader() - { - $earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first(); - $latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first(); - if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) { - $header->start_date = $earliestStartDate; - $header->end_date = $latestEndDate; - $header->saveQuietly(); - } - } - - public function getJobsDoneAttribute() - { - if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) - return 0; - if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) - return 0; - if($dataPlan->isEmpty()) - return 0; - if($dataPlan[0]->status_activity == 'done') - return 100; - return $this->persentase_progress; - } - - 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) - ->where('assign_material_to_activity.type', "material") - ->get() - ->toArray()); - } - - public function getAssignExpenseAttribute() - { - 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) - ->where('assign_material_to_activity.type', "expense") - ->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()); - } - -} +timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + return Carbon::createFromTimestamp(strtotime($value)) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + + public function getEndDateAttribute($value) + { + if ($value instanceof \DateTime) { + return Carbon::instance($value) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + return Carbon::createFromTimestamp(strtotime($value)) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + + + public static function boot() { + parent::boot(); + + static::updating(function($data) { + $data->logPersentaseProgress(); + }); + + static::updated(function($data) { + $data->updateBobot(); + $data->updateCostPlanning(); + if($data->bobot_planning){ + $data->updatePersentaseProgress(); + } + $data->updateCostActual(); + // if($data->start_date != request()->start_date || $data->end_date != request()->end_date) { + // $data->updateStartEndDateHeader(); + // } + }); + + static::deleted(function($data) { + if(Activity::where("parent_id", $data->parent_id)->count() == 0) + Activity::find($data->parent_id)->update(["type_activity"=>"task"]); + + $data->updateBobot(true); + $data->updateCostPlanning(); + if($data->bobot_planning){ + $data->updatePersentaseProgress(); + } + $data->updateCostActual(); + $data->updateStartEndDateHeader(); + }); + + } + + private function updateBobot($isDelete = false) + { + $root = Activity::where('version_gantt_id', $this->version_gantt_id) + ->where("proyek_id", $this->proyek_id) + ->whereNull('parent_id') + ->first(); + + if($root->rencana_biaya > 0){ + $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); + foreach ($activities as $activity) { + if($isDelete && $activity->id == $this->id) + continue; + + $activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100; + $activity->updated_by = auth()->user() ? auth()->user()->name : "system"; + $activity->saveQuietly(); + + } + } else { + if($parent = Activity::find($this->parent_id)){ + $totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning'); + $parent->update([ + "bobot_planning" => $totalChildWeight + ]); + } + } + } + + 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() + { + if($parent = Activity::find($this->parent_id)){ + $parentActWeight = $parent->bobot_planning; + + if ($parentActWeight == 0) { + $parent->update([ + "persentase_progress" => 0 + ]); + return; + } + + $totalChildProportionalProgress = 0; + $childs = Activity::where("parent_id", $parent->id)->get(); + foreach($childs as $child){ + $currentActWeight = $child->bobot_planning; + $currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress; + $totalChildProportionalProgress += $currentActProportionalProgress; + } + $parent->update([ + "persentase_progress" => $totalChildProportionalProgress + ]); + } + } + + 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, + ]); + } + } + + private function logPersentaseProgress() + { + ActivityProgressLog::create([ + 'version_gantt_id' => $this->version_gantt_id, + 'activity_id' => request()->id, + 'old_percentage' => $this->persentase_progress, + 'new_percentage' => request()->persentase_progress, + 'variance' => $this->persentase_progress - request()->persentase_progress, + 'created_by'=> "system" + ]); + } + + private function updateStartEndDateHeader() + { + $earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first(); + $latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first(); + if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) { + $header->start_date = $earliestStartDate; + $header->end_date = $latestEndDate; + $header->saveQuietly(); + } + } + + public function getJobsDoneAttribute() + { + if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) + return 0; + if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) + return 0; + if($dataPlan->isEmpty()) + return 0; + if($dataPlan[0]->status_activity == 'done') + return 100; + return $this->persentase_progress; + } + + 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) + ->where('assign_material_to_activity.type', "material") + ->get() + ->toArray()); + } + + public function getAssignExpenseAttribute() + { + 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) + ->where('assign_material_to_activity.type', "expense") + ->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 e795185d5699eaedcf4e67218c7ca610d538e12a Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 21 Sep 2023 10:03:07 +0700 Subject: [PATCH 150/185] fix sync report --- app/Http/Controllers/ProjectController.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 3dc7fcc..e9c7099 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -399,13 +399,6 @@ class ProjectController extends Controller $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); } - $activity->reports = $reports; - $successor = Link::where('t_activity_id', $activity->id)->first(); - if ($successor) { - $predecessor = Activity::find($successor->s_activity_id); - $activity->start_date = $predecessor->end_date; - } - $activity->save(); } /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ @@ -428,6 +421,18 @@ class ProjectController extends Controller $activity->save(); } + foreach($activities as $activity) { + $successor = Link::where('t_activity_id', $activity->id)->first(); + if ($successor) { + $predecessor = Activity::find($successor->s_activity_id); + $activity->start_date = $predecessor->end_date; + $end_date = new DateTime($activity->start_date); + $end_date->modify("+" . $activity->duration . " days"); + $activity->end_date = $end_date->format("Y-m-d H:i:sO"); + } + $activity->save(); + } + return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); } From 6dd3992cdf3c607bbb6b969a4659179b22b5fdb6 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 21 Sep 2023 14:22:29 +0700 Subject: [PATCH 151/185] fix schedule dashboard project --- app/Helpers/MasterFunctionsHelper.php | 1962 ++++++++++++------------- 1 file changed, 981 insertions(+), 981 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 5c9764f..706d734 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -1,981 +1,981 @@ -max("id"); - if (!$maxGanttId) { - $data = array( - "proyek_id" => $id - ); - } else { - $data = array( - "last_gantt_id" => $maxGanttId, - "proyek_id" => $id - ); - } - return $data; - } - - // dipake di dashboard project & bod - public function getSCurve($request) - { - $allGantt = []; - if (!is_int($request)) { - $dataPayload = $request->all(); - if (isset($dataPayload['gantt_id'])) { - $allGantt[] = $dataPayload['gantt_id']; - } else { - $allGantt[] = MasterFunctionsHelper::getLatestGantt($dataPayload['project_id']); - } - } else { - $allGantt[] = MasterFunctionsHelper::getLatestGantt($request); - } - foreach ($allGantt as $gantt) { - if (!isset($gantt['last_gantt_id'])) { - $ganttId = $gantt; - } else { - $ganttId = $gantt['last_gantt_id']; - } - $gantt = VersionGantt::find($ganttId)->toArray(); - // foreach ($gantt as $key => $value) { - // Log::info('gantt '.$value.' index '.$key); - // } - if (isset($gantt['calculation_type'])) { - if ($gantt['calculation_type'] == 'simple') { - // to do - return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); - } else { - return MasterFunctionsHelper::calculateProgressBasedOnReportMaterial($gantt); - } - } - } - } - - public function getLinearSCurve($request) - { - $ftths = HierarchyFtth::where('project_id', $request->project_id)->get(); - $ttlProgress = 0; - $ttlPlanning = 0; - - foreach ($ftths as $ftth) { - $progress = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('progress'); - $planning = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('bobot'); - $ttlProgress += $progress; - $ttlPlanning += $planning; - } - - $minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first(); - $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); - - $begin = new \DateTime($minDate->mulai_proyek . ' Monday'); - - $end = new \DateTime($maxDate->akhir_proyek . ' Friday'); - - $interval = new \DateInterval('P7D'); - - $period = new \DatePeriod($begin, $interval, $end); - $dates = iterator_to_array($period); - $count = count($dates); - - $avgProgress = $ttlProgress / $ttlPlanning / $count * 100; - $avgPlanning = $ttlPlanning / $ttlPlanning / $count * 100; - $progressData = []; - $planningData = []; - $dates = []; - $tempProgress = 0; - $tempPlanning = 0; - array_push($progressData, round($tempProgress, 2)); - array_push($planningData, round($tempPlanning, 2)); - foreach ($period as $p) { - $tempProgress += $avgProgress; - $tempPlanning += $avgPlanning; - array_push($progressData, round($tempProgress, 2)); - array_push($planningData, round($tempPlanning, 2)); - array_push($dates, $p->format("Y-m-d")); - } - - $dataResponse = array( - "percentagePlan" => $planningData, - "percentageReal" => $progressData, - "date" => $dates, - ); - - $dataFinal[] = array( - "data" => $dataResponse, - ); - return $dataFinal; - } - - public function calculateProgressBasedOnReportMaterial($keyGantt) - { - DB::enableQueryLog(); - - $dataFinal = []; - $dataPayload = []; - $dataPayload['period'] = 'week'; - $totalACWP = 0; - $totalBCWP = 0; - $tempPercentage = []; - - $dataProject = Project::find($keyGantt['proyek_id']); - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); - if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { - $dataPayload['end_date'] = $dataProject->akhir_proyek; - } - - if ($dataHeader) { - $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); - } else { - $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); - } - - if (!Activity::where("version_gantt_id", $keyGantt['id'])->first()) - return $dataFinal; - - $alreadyHasReport = DB::table('report_activity_material as a') - ->select('a.id') - ->join('m_activity as b', 'b.id', '=', 'a.activity_id') - ->where('b.version_gantt_id', '=', $keyGantt['id']) - ->exists(); - // note : delete this - // if(!$alreadyHasReport) - // return $dataFinal; - - $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); - - $begin = new \DateTime($minDate . ' Monday'); - $begin->modify('last Monday'); - if (isset($dataPayload['end_date'])) { - $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate . ' Friday'); - $end->modify('next Friday'); - $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged - $interval = new \DateInterval('P7D'); - } else { - $actualMaxDate = 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['id']) - ->max("a.end_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's - $plannedMaxDate = 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['id']) - ->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity' - $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); - $end = new \DateTime($maxDate->format('Y-m-d') . ' Friday'); - $end->modify('next Friday'); - $interval = new \DateInterval('P7D'); - } - $period = new \DatePeriod($begin, $interval, $end); - - $arr_ActualM = []; - $tempDate = []; - $tempPercentagePlan = []; - $tempPercentagePlanWhr = []; - $tempPercentageReal = []; - $tempTtlPercentPlan = 0; - $tempTtlPercentActual = 0; - - $currentACWP = 0; - $currentBCWP = 0; - - foreach ($period as $dt) { - $minSevenDays = new \Datetime($dt->format("Y-m-d")); - $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); - $tempDate[] = array($dt->format("Y-m-d")); - // $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['id']) - // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) - // ->whereDate('ama.plan_date', '>', $minSevenDays) - // ->get(); - - $activities = DB::table('m_activity AS a') - ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']) - ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) - ->whereDate('amta.plan_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); - - $dataPlanM = DB::table('m_activity AS a') - ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']) - ->whereDate('a.start_date', '<=', $dt->format("Y-m-d")) - ->whereDate('a.start_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') - ->union($activities) - ->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['id']) - ->where('a.proyek_id', '=', $keyGantt['proyek_id']) - ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) - ->whereDate('ram.report_date', '>', $minSevenDays) - ->get(); - $dataTempPlan = []; - $x = 0; - $sumPercentagePlan = 0; - $totalACWP = isset($totalACWP) ? $totalACWP : 0; - $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; - - foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table(function ($query) use ($keyGantt) { - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']) - ->unionAll(function ($query) use ($keyGantt) { - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->where('a.version_gantt_id', $keyGantt['id']); - }) - ->orderBy('id', 'asc'); - }, 'subquery') - ->sum('bobot_planning'); - $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; - $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; - $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan[$x]['duration'] = $keyPlanM->duration; - $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; - try { - $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan += $keyPlanM->bobot_planning; - if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) - $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; - else - $totalBCWP = 0; - $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; - } catch (\DivisionByZeroError $e) { - return response()->json(['message' => $e->getMessage()]); - } - $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(); - $sumReportActual = DB::table('report_activity_material') - ->where('activity_id', $keyActualM->activity_id) - ->sum('qty'); - $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); - $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; - try { - // assign_material_to_activity - $checkStatusActivity = DB::table('assign_material_to_activity') - ->select('activity_id', 'status_activity') - ->where('activity_id', '=', $keyActualM->activity_id) - ->orderBy('status_activity', 'ASC') - ->first(); - $dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; - // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ - if ($checkStatusActivity->status_activity == 'done') { - $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } else { - if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { - $sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100); - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } else { - $sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } - } - // }else { - // if($checkStatusActivity->status_activity == 'done'){ - // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; - // }else{ - // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - // } - // } - - - $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; - } catch (\DivisionByZeroError $e) { - return response()->json(['message' => $e->getMessage()]); - } - $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') { - $tempTtlPercentPlan += $sumPercentagePlan; - $tempTtlPercentActual += $sumPercentageActual; - - // if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= $keyGantt['progress'];){ - // if($tempTtlPercentActual >= 100) - // $tempTtlPercentActual = 100; - // if($tempTtlPercentPlan >= 100) - // $tempTtlPercentPlan = 100; - - // if($tempTtlPercentActual >= $keyGantt['progress']) - // $tempTtlPercentActual = $keyGantt['progress']; - if ($tempTtlPercentPlan >= 100) - $tempTtlPercentPlan = 100; - // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual - - // } - - $currentACWP += $totalACWP; - $currentBCWP += $totalBCWP; - - $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); - $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); - $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; - $tempPercentageReal[] = round($tempTtlPercentActual, 2); - if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { - break; - } - } else { - $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); - $tempPercentagePlan[] = round($sumPercentagePlan, 2); - $tempPercentageReal[] = round($sumPercentageActual, 2); - } - } - - try { - if (round($totalACWP, 0) > $totalRencanaBudget) { - $estimatedCost = round($totalACWP, 0) + 0; - } else { - $estimatedCost = ($totalRencanaBudget + 0); - } - } catch (\DivisionByZeroError $e) { - return response()->json([ - 'message' => $e->getMessage(), - "line" => 566, - 'gantt' => $keyGantt, - ]); - } - $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; - - $costDeviation = $totalRencanaBudget - $estimatedCost; - if ($costDeviation > 0) { - $potential = "SAVING"; - } else { - $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; - } - - $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; - $dataResponse = array( - "date" => $tempDate, - "percentage" => $tempPercentage, - "percentagePlan" => $tempPercentagePlan, - "percentageReal" => $tempPercentageReal, - "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, - "gantt" => $keyGantt - ); - - return $dataFinal; - } - - public function calculateSCurve($projectId) - { - DB::enableQueryLog(); - - $dataFinal = []; - $dataPayload = []; - $dataPayload['period'] = 'week'; - $totalACWP = 0; - $totalBCWP = 0; - $tempPercentage = []; - - $dataProject = Project::find($projectId); - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first(); - if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { - $dataPayload['end_date'] = $dataProject->akhir_proyek; - } - - if ($dataHeader) { - $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya"); - } else { - $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya"); - } - - $alreadyHasReport = DB::table('report_activity_material as a') - ->select('a.id') - ->join('m_activity as b', 'b.id', '=', 'a.activity_id') - ->exists(); - - $minDate = $dataProject->mulai_proyek; - - $begin = new \DateTime($minDate); - $begin->modify('last Monday'); - if (isset($dataPayload['end_date'])) { - $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate); - $end->modify('next Friday'); - $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged - $interval = new \DateInterval('P7D'); - } else { - // $maxDate = DB::table('assign_material_to_activity as ama') - // ->where("ama.proyek_id", $projectId) - // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's - $maxDate = $dataProject->akhir_proyek; - $end = new \DateTime($maxDate); - $end->modify('next Friday'); - $end->modify('next Friday'); - $interval = new \DateInterval('P7D'); - } - $period = new \DatePeriod($begin, $interval, $end); - - $arr_ActualM = []; - $tempDate = []; - $tempPercentagePlan = []; - $tempPercentagePlanWhr = []; - $tempPercentageReal = []; - $tempTtlPercentPlan = 0; - $tempTtlPercentActual = 0; - - $currentACWP = 0; - $currentBCWP = 0; - - foreach ($period as $dt) { - $minSevenDays = new \Datetime($dt->format("Y-m-d")); - $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); - // $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['id']) - // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) - // ->whereDate('ama.plan_date', '>', $minSevenDays) - // ->get(); - - $activities = DB::table('m_activity AS a') - ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) - ->whereDate('amta.plan_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); - - $dataPlanM = DB::table('m_activity AS a') - ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->whereDate('a.start_date', '<=', $dt->format("Y-m-d")) - ->whereDate('a.start_date', '>', $minSevenDays) - ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') - ->union($activities) - ->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.proyek_id', '=', $projectId) - ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) - ->whereDate('ram.report_date', '>', $minSevenDays) - ->get(); - $dataTempPlan = []; - $x = 0; - $sumPercentagePlan = 0; - $totalACWP = isset($totalACWP) ? $totalACWP : 0; - $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; - - foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table(function ($query) { - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0) - ->unionAll(function ($query) { - $query->select('a.*') - ->from('m_activity AS a') - ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') - ->where('a.type_activity', 'task') - ->where('a.bobot_planning', '>', 0); - })->orderBy('id', 'asc'); - }, 'subquery') - ->sum('bobot_planning'); - $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; - $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; - $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan[$x]['duration'] = $keyPlanM->duration; - $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; - try { - $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan += $keyPlanM->bobot_planning; - if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) - $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; - else - $totalBCWP = 0; - $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; - } catch (\DivisionByZeroError $e) { - return response()->json(['message' => $e->getMessage()]); - } - $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(); - if (!isset($sumVolActual)) { - $sumVolActual = (object) [ - 'activity_id' => $keyActualM->activity_id, - 'ttl_qty_plan' => "0" - ]; - } - $sumReportActual = DB::table('report_activity_material') - ->where('activity_id', $keyActualM->activity_id) - ->sum('qty'); - $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); - $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; - try { - // assign_material_to_activity - $checkStatusActivity = DB::table('assign_material_to_activity') - ->select('activity_id', 'status_activity') - ->where('activity_id', '=', $keyActualM->activity_id) - ->orderBy('status_activity', 'ASC') - ->first(); - if (!isset($checkStatusActivity)) { - $checkStatusActivity = (object) [ - 'activity_id' => $keyActualM->activity_id, - 'status_activity' => 'open' - ]; - } - if ($sumVolActual->ttl_qty_plan == "0") { - $actual = 0; - } else { - $actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan; - } - $dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning; - // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ - if ($checkStatusActivity->status_activity == 'done') { - $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } else { - if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { - $sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100); - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } else { - $sumPercentageActual += $actual * $keyActualM->bobot_planning; - // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; - } - } - // }else { - // if($checkStatusActivity->status_activity == 'done'){ - // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; - // }else{ - // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - // } - // } - - - $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; - } catch (\DivisionByZeroError $e) { - return response()->json(['message' => $e->getMessage()]); - } - $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') { - $tempTtlPercentPlan += $sumPercentagePlan; - $tempTtlPercentActual += $sumPercentageActual; - - $currentACWP += $totalACWP; - $currentBCWP += $totalBCWP; - - $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); - $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); - $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; - $tempPercentageReal[] = round($tempTtlPercentActual, 2); - } else { - $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); - $tempPercentagePlan[] = round($sumPercentagePlan, 2); - $tempPercentageReal[] = round($sumPercentageActual, 2); - } - $tempDate[] = array($dt->format("Y-m-d")); - } - - try { - if (round($totalACWP, 0) > $totalRencanaBudget) { - $estimatedCost = round($totalACWP, 0) + 0; - } else { - $estimatedCost = ($totalRencanaBudget + 0); - } - } catch (\DivisionByZeroError $e) { - return response()->json([ - 'message' => $e->getMessage(), - "line" => 566, - ]); - } - $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; - - $costDeviation = $totalRencanaBudget - $estimatedCost; - if ($costDeviation > 0) { - $potential = "SAVING"; - } else { - $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; - } - - $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; - $dataResponse = array( - "date" => $tempDate, - "percentage" => $tempPercentage, - "percentagePlan" => $tempPercentagePlan, - "percentageReal" => $tempPercentageReal, - "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, - ); - - return $dataFinal; - } - - public function calculateProgressBasedOnSimple($keyGantt) - { - DB::enableQueryLog(); - - $dataFinal = []; - $dataPayload = []; - $dataPayload['period'] = 'week'; - - $dataProject = Project::find($keyGantt['proyek_id']); - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); - if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { - $dataPayload['end_date'] = $dataProject->akhir_proyek; - } - - if ($dataHeader) { - $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); - } else { - $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); - } - - if (!Activity::where("version_gantt_id", $keyGantt['id'])->first()) - return $dataFinal; - - // $alreadyHasReport = DB::table('report_activity_material as a') - // ->select('a.id') - // ->join('m_activity as b', 'b.id', '=', 'a.activity_id') - // ->where('b.version_gantt_id', '=', $keyGantt['id']) - // ->exists(); - - // if(!$alreadyHasReport) - // return $dataFinal; - - $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); - - $begin = new \DateTime($minDate . ' Monday'); - if (isset($dataPayload['end_date'])) { - $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate); - /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged - $interval = new \DateInterval('P7D'); - } else { - // $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['id']) - // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's - $maxDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('end_date')->first(); - $end = new \DateTime($maxDate . ' Friday'); - $interval = new \DateInterval('P7D'); - } - $period = new \DatePeriod($begin, $interval, $end); - - $arr_ActualM = []; - $tempDate = []; - $tempPercentagePlan = []; - $tempPercentagePlanWhr = []; - $tempPercentageReal = []; - $tempTtlPercentPlan = 0; - $tempTtlPercentActual = 0; - - $currentACWP = 0; - $currentBCWP = 0; - - foreach ($period as $dt) { - $minSevenDays = new \Datetime($dt->format("Y-m-d")); - $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); - - $dataPlanM = DB::table('m_activity') - ->select('id as activity_id', 'bobot_planning', 'start_date', 'biaya_actual', 'duration', 'persentase_progress') - // ->join('m_activity as a', 'a.id', '=', 'activity_id') - ->where('proyek_id', '=', $keyGantt['proyek_id']) - ->where('type_activity', '=', 'task') - ->where('version_gantt_id', '=', $keyGantt['id']) - ->whereDate('start_date', '<=', $dt->format("Y-m-d")) - ->whereDate('start_date', '>', $minSevenDays) - ->get(); - - $dataActualM = DB::table('m_activity as a') - ->select('mapl.id as id_progress_log', 'mapl.activity_id', 'mapl.variance', 'mapl.created_at', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') - ->join('m_activity_progress_log as mapl', 'a.id', '=', 'mapl.activity_id') - ->where('a.version_gantt_id', '=', $keyGantt['id']) - ->where('a.type_activity', '=', 'task') - ->where('mapl.variance', '>', 0) - ->where('a.proyek_id', '=', $keyGantt['proyek_id']) - ->whereDate('mapl.created_at', '<=', $dt->format("Y-m-d")) - ->whereDate('mapl.created_at', '>', $minSevenDays) - ->get(); - $dataTempPlan = []; - $x = 0; - $sumPercentagePlan = 0; - $totalACWP = isset($totalACWP) ? $totalACWP : 0; - $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; - - foreach ($dataPlanM as $keyPlanM) { - - $dataTempPlan[$x]['activity_id'] = $keyPlanM->activity_id; - $dataTempPlan[$x]['qty_plan'] = $keyPlanM->bobot_planning; - $dataTempPlan[$x]['plan_date'] = $keyPlanM->start_date; - $dataTempPlan[$x]['start_activity'] = $keyPlanM->start_date; - $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan[$x]['ttl_plan'] = $keyPlanM->bobot_planning; - $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan[$x]['duration'] = $keyPlanM->duration; - $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; - try { - $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan += $keyPlanM->bobot_planning; - $totalBCWP += 0; - $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; - } catch (\DivisionByZeroError $e) { - return response()->json(['message' => $e->getMessage()]); - } - $x++; - } - - $w = 0; - $dataTempReport = []; - $sumPercentageActual = 0; - foreach ($dataActualM as $keyActualM) { - $sumVolActual = DB::table('m_activity_progress_log') - ->select('id', DB::raw('SUM(variance) as ttl_percen_act')) - ->where('id', '=', $keyActualM->id_progress_log) - ->groupBy('id') - ->first(); - $dataTempReport[$w]['id_progress_log'] = $keyActualM->id_progress_log; - // $dataTempReport [$w]['qty'] = $keyActualM->qty; - $dataTempReport[$w]['report_date'] = $keyActualM->created_at; - $dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning; - // $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_percen_act ? $sumVolActual->ttl_percen_act : 0; - $dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual; - $dataTempReport[$w]['duration'] = $keyActualM->duration; - $dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress; - try { - $dataTempReport[$w]['percentage'] = $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0; - $sumPercentageActual += $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0; - $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; - } catch (\DivisionByZeroError $e) { - return response()->json(['message' => $e->getMessage()]); - } - $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') { - $tempTtlPercentPlan += $sumPercentagePlan; - $tempTtlPercentActual += $sumPercentageActual; - - if ($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100) { - if ($tempTtlPercentActual >= 100) - $tempTtlPercentActual = 100; - if ($tempTtlPercentPlan >= 100) - $tempTtlPercentPlan = 100; - } - - $currentACWP += $totalACWP; - $currentBCWP += $totalBCWP; - - $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); - $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); - $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; - $tempPercentageReal[] = round($tempTtlPercentActual, 2); - if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { - break; - } - } else { - $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); - $tempPercentagePlan[] = round($sumPercentagePlan, 2); - $tempPercentageReal[] = round($sumPercentageActual, 2); - } - $tempDate[] = array($dt->format("Y-m-d")); - } - - try { - if (round($totalACWP, 0) > $totalRencanaBudget) { - $estimatedCost = round($totalACWP, 0) + 0; - } else { - $estimatedCost = ($totalRencanaBudget + 0); - } - } catch (\DivisionByZeroError $e) { - return response()->json([ - 'message' => $e->getMessage(), - "line" => 566, - 'gantt' => $keyGantt, - ]); - } - $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; - - $costDeviation = $totalRencanaBudget - $estimatedCost; - if ($costDeviation > 0) { - $potential = "SAVING"; - } else { - $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; - } - - $dataResponse = array( - "date" => $tempDate, - "percentage" => $tempPercentage, - "percentagePlan" => $tempPercentagePlan, - "percentageReal" => $tempPercentageReal, - "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, - "gantt" => $keyGantt, - ); - - return $dataFinal; - } - -} \ No newline at end of file +max("id"); + if (!$maxGanttId) { + $data = array( + "proyek_id" => $id + ); + } else { + $data = array( + "last_gantt_id" => $maxGanttId, + "proyek_id" => $id + ); + } + return $data; + } + + // dipake di dashboard project & bod + public function getSCurve($request) + { + $allGantt = []; + if (!is_int($request)) { + $dataPayload = $request->all(); + if (isset($dataPayload['gantt_id'])) { + $allGantt[] = $dataPayload['gantt_id']; + } else { + $allGantt[] = MasterFunctionsHelper::getLatestGantt($dataPayload['project_id']); + } + } else { + $allGantt[] = MasterFunctionsHelper::getLatestGantt($request); + } + foreach ($allGantt as $gantt) { + if (!isset($gantt['last_gantt_id'])) { + $ganttId = $gantt; + } else { + $ganttId = $gantt['last_gantt_id']; + } + $gantt = VersionGantt::find($ganttId)->toArray(); + // foreach ($gantt as $key => $value) { + // Log::info('gantt '.$value.' index '.$key); + // } + if (isset($gantt['calculation_type'])) { + if ($gantt['calculation_type'] == 'simple') { + // to do + return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); + } else { + return MasterFunctionsHelper::calculateProgressBasedOnReportMaterial($gantt); + } + } + } + } + + public function getLinearSCurve($request) + { + $ftths = HierarchyFtth::where('project_id', $request->project_id)->get(); + $ttlProgress = 0; + $ttlPlanning = 0; + + foreach ($ftths as $ftth) { + $progress = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('progress'); + $planning = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('bobot'); + $ttlProgress += $progress; + $ttlPlanning += $planning; + } + + $minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first(); + $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); + + $begin = new \DateTime($minDate->mulai_proyek . ' Monday'); + + $end = new \DateTime($maxDate->akhir_proyek . ' Friday'); + + $interval = new \DateInterval('P7D'); + + $period = new \DatePeriod($begin, $interval, $end); + $dates = iterator_to_array($period); + $count = count($dates); + + $avgProgress = $ttlProgress / $ttlPlanning / $count * 100; + $avgPlanning = $ttlPlanning / $ttlPlanning / $count * 100; + $progressData = []; + $planningData = []; + $dates = []; + $tempProgress = 0; + $tempPlanning = 0; + array_push($progressData, round($tempProgress, 2)); + array_push($planningData, round($tempPlanning, 2)); + foreach ($period as $p) { + $tempProgress += $avgProgress; + $tempPlanning += $avgPlanning; + array_push($progressData, round($tempProgress, 2)); + array_push($planningData, round($tempPlanning, 2)); + array_push($dates, $p->format("Y-m-d")); + } + + $dataResponse = array( + "percentagePlan" => $planningData, + "percentageReal" => $progressData, + "date" => $dates, + ); + + $dataFinal[] = array( + "data" => $dataResponse, + ); + return $dataFinal; + } + + public function calculateProgressBasedOnReportMaterial($keyGantt) + { + DB::enableQueryLog(); + + $dataFinal = []; + $dataPayload = []; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; + + $dataProject = Project::find($keyGantt['proyek_id']); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); + if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { + $dataPayload['end_date'] = $dataProject->akhir_proyek; + } + + if ($dataHeader) { + $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); + } else { + $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); + } + + if (!Activity::where("version_gantt_id", $keyGantt['id'])->first()) + return $dataFinal; + + $alreadyHasReport = DB::table('report_activity_material as a') + ->select('a.id') + ->join('m_activity as b', 'b.id', '=', 'a.activity_id') + ->where('b.version_gantt_id', '=', $keyGantt['id']) + ->exists(); + // note : delete this + // if(!$alreadyHasReport) + // return $dataFinal; + + $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); + + $begin = new \DateTime($minDate . ' Monday'); + $begin->modify('last Monday'); + if (isset($dataPayload['end_date'])) { + $maxDate = $dataPayload['end_date']; + $end = new \DateTime($maxDate . ' Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); + /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + $interval = new \DateInterval('P7D'); + } else { + $actualMaxDate = 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['id']) + ->max("a.end_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $plannedMaxDate = 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['id']) + ->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity' + $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); + $end = new \DateTime($maxDate->format('Y-m-d') . ' Friday'); + $end->modify('next Friday'); + $interval = new \DateInterval('P7D'); + } + $period = new \DatePeriod($begin, $interval, $end); + + $arr_ActualM = []; + $tempDate = []; + $tempPercentagePlan = []; + $tempPercentagePlanWhr = []; + $tempPercentageReal = []; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; + + $currentACWP = 0; + $currentBCWP = 0; + + foreach ($period as $dt) { + $minSevenDays = new \Datetime($dt->format("Y-m-d")); + $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); + $tempDate[] = array($dt->format("Y-m-d")); + // $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['id']) + // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) + // ->whereDate('ama.plan_date', '>', $minSevenDays) + // ->get(); + + $activities = DB::table('m_activity AS a') + ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) + ->whereDate('amta.plan_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); + + $dataPlanM = DB::table('m_activity AS a') + ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->whereDate('a.start_date', '<=', $dt->format("Y-m-d")) + ->whereDate('a.start_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') + ->union($activities) + ->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['id']) + ->where('a.proyek_id', '=', $keyGantt['proyek_id']) + ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) + ->whereDate('ram.report_date', '>', $minSevenDays) + ->get(); + $dataTempPlan = []; + $x = 0; + $sumPercentagePlan = 0; + $totalACWP = isset($totalACWP) ? $totalACWP : 0; + $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; + + foreach ($dataPlanM as $keyPlanM) { + $sumVolPlan = DB::table(function ($query) use ($keyGantt) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']) + ->unionAll(function ($query) use ($keyGantt) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.version_gantt_id', $keyGantt['id']); + }) + ->orderBy('id', 'asc'); + }, 'subquery') + ->sum('bobot_planning'); + $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; + $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; + $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan[$x]['duration'] = $keyPlanM->duration; + $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; + try { + $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan += $keyPlanM->bobot_planning; + if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) + $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; + else + $totalBCWP = 0; + $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $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(); + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $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; + try { + // assign_material_to_activity + $checkStatusActivity = DB::table('assign_material_to_activity') + ->select('activity_id', 'status_activity') + ->where('activity_id', '=', $keyActualM->activity_id) + ->orderBy('status_activity', 'ASC') + ->first(); + $dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ + if ($checkStatusActivity->status_activity == 'done') { + $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } else { + if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { + $sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100); + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } else { + $sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } + } + // }else { + // if($checkStatusActivity->status_activity == 'done'){ + // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; + // }else{ + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // } + // } + + + $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $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') { + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; + + // if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= $keyGantt['progress'];){ + // if($tempTtlPercentActual >= 100) + // $tempTtlPercentActual = 100; + // if($tempTtlPercentPlan >= 100) + // $tempTtlPercentPlan = 100; + + // if($tempTtlPercentActual >= $keyGantt['progress']) + // $tempTtlPercentActual = $keyGantt['progress']; + if ($tempTtlPercentPlan >= 100) + $tempTtlPercentPlan = 100; + // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual + + // } + + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); + $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); + $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; + $tempPercentageReal[] = round($tempTtlPercentActual, 2); + if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { + break; + } + } else { + $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); + $tempPercentagePlan[] = round($sumPercentagePlan, 2); + $tempPercentageReal[] = round($sumPercentageActual, 2); + } + } + + try { + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); + } + } catch (\DivisionByZeroError $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + 'gantt' => $keyGantt, + ]); + } + $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + + $costDeviation = $totalRencanaBudget - $estimatedCost; + if ($costDeviation > 0) { + $potential = "SAVING"; + } else { + $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; + } + + $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; + $dataResponse = array( + "date" => $tempDate, + "percentage" => $tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "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, + "gantt" => $keyGantt + ); + + return $dataFinal; + } + + public function calculateSCurve($projectId) + { + DB::enableQueryLog(); + + $dataFinal = []; + $dataPayload = []; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; + + $dataProject = Project::find($projectId); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first(); + if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { + $dataPayload['end_date'] = $dataProject->akhir_proyek; + } + + if ($dataHeader) { + $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya"); + } else { + $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya"); + } + + $alreadyHasReport = DB::table('report_activity_material as a') + ->select('a.id') + ->join('m_activity as b', 'b.id', '=', 'a.activity_id') + ->exists(); + + $minDate = $dataProject->mulai_proyek; + + $begin = new \DateTime($minDate); + $begin->modify('last Monday'); + if (isset($dataPayload['end_date'])) { + $maxDate = $dataPayload['end_date']; + $end = new \DateTime($maxDate); + $end->modify('next Friday'); + $end->modify('next Friday'); + /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + $interval = new \DateInterval('P7D'); + } else { + // $maxDate = DB::table('assign_material_to_activity as ama') + // ->where("ama.proyek_id", $projectId) + // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $maxDate = $dataProject->akhir_proyek; + $end = new \DateTime($maxDate); + $end->modify('next Friday'); + $end->modify('next Friday'); + $interval = new \DateInterval('P7D'); + } + $period = new \DatePeriod($begin, $interval, $end); + + $arr_ActualM = []; + $tempDate = []; + $tempPercentagePlan = []; + $tempPercentagePlanWhr = []; + $tempPercentageReal = []; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; + + $currentACWP = 0; + $currentBCWP = 0; + + foreach ($period as $dt) { + $minSevenDays = new \Datetime($dt->format("Y-m-d")); + $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); + // $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['id']) + // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) + // ->whereDate('ama.plan_date', '>', $minSevenDays) + // ->get(); + + $activities = DB::table('m_activity AS a') + ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) + ->whereDate('amta.plan_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); + + $dataPlanM = DB::table('m_activity AS a') + ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->whereDate('a.start_date', '<=', $dt->format("Y-m-d")) + ->whereDate('a.start_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') + ->union($activities) + ->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.proyek_id', '=', $projectId) + ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) + ->whereDate('ram.report_date', '>', $minSevenDays) + ->get(); + $dataTempPlan = []; + $x = 0; + $sumPercentagePlan = 0; + $totalACWP = isset($totalACWP) ? $totalACWP : 0; + $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; + + foreach ($dataPlanM as $keyPlanM) { + $sumVolPlan = DB::table(function ($query) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->unionAll(function ($query) { + $query->select('a.*') + ->from('m_activity AS a') + ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0); + })->orderBy('id', 'asc'); + }, 'subquery') + ->sum('bobot_planning'); + $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; + $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; + $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan[$x]['duration'] = $keyPlanM->duration; + $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; + try { + $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan += $keyPlanM->bobot_planning; + if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) + $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; + else + $totalBCWP = 0; + $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $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(); + if (!isset($sumVolActual)) { + $sumVolActual = (object) [ + 'activity_id' => $keyActualM->activity_id, + 'ttl_qty_plan' => "0" + ]; + } + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $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; + try { + // assign_material_to_activity + $checkStatusActivity = DB::table('assign_material_to_activity') + ->select('activity_id', 'status_activity') + ->where('activity_id', '=', $keyActualM->activity_id) + ->orderBy('status_activity', 'ASC') + ->first(); + if (!isset($checkStatusActivity)) { + $checkStatusActivity = (object) [ + 'activity_id' => $keyActualM->activity_id, + 'status_activity' => 'open' + ]; + } + if ($sumVolActual->ttl_qty_plan == "0") { + $actual = 0; + } else { + $actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan; + } + $dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning; + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ + if ($checkStatusActivity->status_activity == 'done') { + $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } else { + if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { + $sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100); + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } else { + $sumPercentageActual += $actual * $keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } + } + // }else { + // if($checkStatusActivity->status_activity == 'done'){ + // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; + // }else{ + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // } + // } + + + $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $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') { + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; + + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); + $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); + $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; + $tempPercentageReal[] = round($tempTtlPercentActual, 2); + } else { + $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); + $tempPercentagePlan[] = round($sumPercentagePlan, 2); + $tempPercentageReal[] = round($sumPercentageActual, 2); + } + $tempDate[] = array($dt->format("Y-m-d")); + } + + try { + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); + } + } catch (\DivisionByZeroError $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + ]); + } + $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + + $costDeviation = $totalRencanaBudget - $estimatedCost; + if ($costDeviation > 0) { + $potential = "SAVING"; + } else { + $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; + } + + $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; + $dataResponse = array( + "date" => $tempDate, + "percentage" => $tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "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, + ); + + return $dataFinal; + } + + public function calculateProgressBasedOnSimple($keyGantt) + { + DB::enableQueryLog(); + + $dataFinal = []; + $dataPayload = []; + $dataPayload['period'] = 'week'; + + $dataProject = Project::find($keyGantt['proyek_id']); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); + if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { + $dataPayload['end_date'] = $dataProject->akhir_proyek; + } + + if ($dataHeader) { + $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); + } else { + $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); + } + + if (!Activity::where("version_gantt_id", $keyGantt['id'])->first()) + return $dataFinal; + + // $alreadyHasReport = DB::table('report_activity_material as a') + // ->select('a.id') + // ->join('m_activity as b', 'b.id', '=', 'a.activity_id') + // ->where('b.version_gantt_id', '=', $keyGantt['id']) + // ->exists(); + + // if(!$alreadyHasReport) + // return $dataFinal; + + $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); + + $begin = new \DateTime($minDate . ' Monday'); + if (isset($dataPayload['end_date'])) { + $maxDate = $dataPayload['end_date']; + $end = new \DateTime($maxDate); + /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + $interval = new \DateInterval('P7D'); + } else { + // $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['id']) + // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $maxDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('end_date')->first(); + $end = new \DateTime($maxDate . ' Friday'); + $interval = new \DateInterval('P7D'); + } + $period = new \DatePeriod($begin, $interval, $end); + + $arr_ActualM = []; + $tempDate = []; + $tempPercentagePlan = []; + $tempPercentagePlanWhr = []; + $tempPercentageReal = []; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; + + $currentACWP = 0; + $currentBCWP = 0; + + foreach ($period as $dt) { + $minSevenDays = new \Datetime($dt->format("Y-m-d")); + $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); + + $dataPlanM = DB::table('m_activity') + ->select('id as activity_id', 'bobot_planning', 'start_date', 'biaya_actual', 'duration', 'persentase_progress') + // ->join('m_activity as a', 'a.id', '=', 'activity_id') + ->where('proyek_id', '=', $keyGantt['proyek_id']) + ->where('type_activity', '=', 'task') + ->where('version_gantt_id', '=', $keyGantt['id']) + ->whereDate('start_date', '<=', $dt->format("Y-m-d")) + ->whereDate('start_date', '>', $minSevenDays) + ->get(); + + $dataActualM = DB::table('m_activity as a') + ->select('mapl.id as id_progress_log', 'mapl.activity_id', 'mapl.variance', 'mapl.created_at', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') + ->join('m_activity_progress_log as mapl', 'a.id', '=', 'mapl.activity_id') + ->where('a.version_gantt_id', '=', $keyGantt['id']) + ->where('a.type_activity', '=', 'task') + ->where('mapl.variance', '>', 0) + ->where('a.proyek_id', '=', $keyGantt['proyek_id']) + ->whereDate('mapl.created_at', '<=', $dt->format("Y-m-d")) + ->whereDate('mapl.created_at', '>', $minSevenDays) + ->get(); + $dataTempPlan = []; + $x = 0; + $sumPercentagePlan = 0; + $totalACWP = isset($totalACWP) ? $totalACWP : 0; + $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; + + foreach ($dataPlanM as $keyPlanM) { + + $dataTempPlan[$x]['activity_id'] = $keyPlanM->activity_id; + $dataTempPlan[$x]['qty_plan'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['plan_date'] = $keyPlanM->start_date; + $dataTempPlan[$x]['start_activity'] = $keyPlanM->start_date; + $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['ttl_plan'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan[$x]['duration'] = $keyPlanM->duration; + $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; + try { + $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan += $keyPlanM->bobot_planning; + $totalBCWP += 0; + $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $x++; + } + + $w = 0; + $dataTempReport = []; + $sumPercentageActual = 0; + foreach ($dataActualM as $keyActualM) { + $sumVolActual = DB::table('m_activity_progress_log') + ->select('id', DB::raw('SUM(variance) as ttl_percen_act')) + ->where('id', '=', $keyActualM->id_progress_log) + ->groupBy('id') + ->first(); + $dataTempReport[$w]['id_progress_log'] = $keyActualM->id_progress_log; + // $dataTempReport [$w]['qty'] = $keyActualM->qty; + $dataTempReport[$w]['report_date'] = $keyActualM->created_at; + $dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning; + // $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_percen_act ? $sumVolActual->ttl_percen_act : 0; + $dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual; + $dataTempReport[$w]['duration'] = $keyActualM->duration; + $dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress; + try { + $dataTempReport[$w]['percentage'] = $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0; + $sumPercentageActual += $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0; + $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $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') { + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; + + if ($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100) { + if ($tempTtlPercentActual >= 100) + $tempTtlPercentActual = 100; + if ($tempTtlPercentPlan >= 100) + $tempTtlPercentPlan = 100; + } + + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); + $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); + $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; + $tempPercentageReal[] = round($tempTtlPercentActual, 2); + if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { + break; + } + } else { + $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); + $tempPercentagePlan[] = round($sumPercentagePlan, 2); + $tempPercentageReal[] = round($sumPercentageActual, 2); + } + $tempDate[] = array($dt->format("Y-m-d")); + } + + try { + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); + } + } catch (\DivisionByZeroError $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + 'gantt' => $keyGantt, + ]); + } + $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + + $costDeviation = $totalRencanaBudget - $estimatedCost; + if ($costDeviation > 0) { + $potential = "SAVING"; + } else { + $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; + } + + $dataResponse = array( + "date" => $tempDate, + "percentage" => $tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "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, + "gantt" => $keyGantt, + ); + + return $dataFinal; + } + +} From 6a5c24adcb632b7b4549413e7d0802368bdd71b8 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 21 Sep 2023 14:22:51 +0700 Subject: [PATCH 152/185] fix schedule dashboard project --- app/Http/Controllers/ProjectController.php | 57 +++++++++++++--------- routes/web.php | 2 +- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index e9c7099..fb73310 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -480,7 +480,7 @@ class ProjectController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); } - public function detail(Request $request, $id, $gantt_id = null){ + public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){ if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); @@ -495,33 +495,42 @@ class ProjectController extends Controller $ganttId = $gantt_id; } $result->projectManager = User::where('id', $result->pm_id)->value('name'); - $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); - // dd($result->header->start_date); - $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); - $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); + if (isset($s_curve)) { + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); + $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); + $actualEndExist = Activity::where('proyek_id', $id)->whereNotNull('actual_end')->exists(); + $query = Activity::where('proyek_id', $id); + } else { + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); + $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); + $query = Activity::where('version_gantt_id', $ganttId); + } - if ($actualStartExist) { - $startDate = Activity::where('version_gantt_id', $ganttId) - ->orderBy('actual_start') - ->value('start_date'); - } else { - $startDate = Activity::where('version_gantt_id', $ganttId) - ->orderBy('start_date') - ->value('start_date'); - } - if ($actualEndExist) { - $endDate = Activity::where('version_gantt_id', $ganttId) - ->orderByDesc('actual_end') - ->value('end_date'); - } else { - $endDate = Activity::where('version_gantt_id', $ganttId) - ->orderByDesc('end_date') - ->value('end_date'); - } + if ($actualStartExist) { + $startDate = $query->orderBy('actual_start')->value('start_date'); + } else { + $startDate = $query->orderBy('start_date')->value('start_date'); + } + + if ($actualEndExist) { + $endDate = $query->orderByDesc('actual_end')->value('end_date'); + } else { + $endDate = $query->orderByDesc('end_date')->value('end_date'); + } + + $plannedStart = Activity::where('version_gantt_id', $ganttId) + ->orderBy('planned_start') + ->value('planned_start'); + $plannedEnd = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('planned_end') + ->value('planned_end'); $result->header->start_date = $startDate; $result->header->end_date = $endDate; - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + $result->header->planned_start = $plannedStart; + $result->header->planned_end = $plannedEnd; + return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200); } public function getOverdueActivities(Request $request){ diff --git a/routes/web.php b/routes/web.php index 8e669a2..448986d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,7 +58,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); $router->get('/project/edit/{id}', 'ProjectController@edit'); - $router->get('/project/detail/{id}[/{gantt_id}]', 'ProjectController@detail'); + $router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail'); $router->delete('/project/delete/{id}', 'ProjectController@delete'); $router->get('/project/list', 'ProjectController@list'); $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline'); From c1526d3eee71dc5c02e19113111d8a57760ec5b2 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 25 Sep 2023 14:15:34 +0700 Subject: [PATCH 153/185] add parent select in Divisi Models --- app/Http/Controllers/DashboardBoDController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 22a53c7..fe2456b 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -271,7 +271,7 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name') + $divisions = Divisi::select('id', 'name','parent') ->with('children') ->whereNull('parent') ->get(); @@ -358,4 +358,4 @@ class DashboardBoDController extends Controller 'total_manpowers' => User::count() ], 200); } -} \ No newline at end of file +} From 18c5102722f8e34796efbe330dc593469f6e8cc3 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 25 Sep 2023 14:16:17 +0700 Subject: [PATCH 154/185] change position eloquent in list method --- app/Http/Controllers/DivisiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index a7d3617..17ad122 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -91,7 +91,7 @@ class DivisiController extends Controller public function list() { - $parentMenus = Divisi::whereNull('parent')->with('children')->get(); + $parentMenus = Divisi::with('children')->whereNull('parent')->get(); $divisions = []; foreach($parentMenus as $menu){ $childs = $this->getAllChildren($menu); From 22748a5b5a46dca4a3ec762fd7c4611deb450b72 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 25 Sep 2023 16:32:27 +0700 Subject: [PATCH 155/185] fix search task mobile --- app/Http/Controllers/PresenceController.php | 1238 ++++++++--------- .../Controllers/UserToActivityController.php | 419 +++--- 2 files changed, 839 insertions(+), 818 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 6aef1a8..0d79917 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -1,619 +1,619 @@ -validate($request, [ - 'user_id' => 'required' - ]); - - $checkLocation = $this->checkLocation($request); - $statusBoundary = false; - $date = date_create($request->clock_time); - // assign and in boundary - if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ - $statusBoundary = true; - } - $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); - if ($statusRestriction->status_boundary) { - $statusBoundary = true; - } - // not assign - if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ - $data=array( - 'id' => null, - 'boundary' => $statusBoundary - ); - return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200); - } - // assign and not in boundary - if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ - $data=array( - 'id' => null, - 'boundary' => true - ); - return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda berada di luar area kerja.','code'=>200], 200); - } - - if($request->type=="out"){ - $clock_out_loc = $this->getLoc($request->clock_out_lat, $request->clock_out_lng)->display_name; - $dataUpdate = array( - "clock_out"=>$request->clock_time, - "clock_out_lat" => $request->clock_out_lat, - "clock_out_lng" => $request->clock_out_lng, - "updated_by"=>$this->currentName, - "clock_out_loc" => $clock_out_loc, - "clock_out_boundary" => $statusBoundary - ); - - $resultUpdate = $this->updateFormAdd($dataUpdate, $request->user_id); - if($resultUpdate && $resultUpdate > 0){ - if($statusBoundary){ - for ($i=0; $i < count($checkLocation); $i++) { - # code... - DB::table('clock_in_out_boundary')->insert([ - "clock_in_out_id" => $resultUpdate, - "user_id" => $request->user_id, - "activity_id" => $checkLocation[$i]['activity_id'], - "type" => $request->type, - "created_at" => $date, - "created_by" => $this->currentName - ]); - }; - }; - $data=array( - 'id' => $resultUpdate, - 'boundary' => $statusBoundary - ); - - return response()->json(['status'=>'success', 'data'=>$data,'message'=>'clock out success!','code'=>200], 200); - } - else{ - return response()->json(['status'=>'failed','message'=>'clock out failed please try again!','code'=>400], 400); - } - die(); - } - - $onlyDate = date_format($date,"Y-m-d"); - $clock_in_loc = $this->getLoc($request->clock_in_lat, $request->clock_in_lng)->display_name; - - $dataAdd = array( - 'user_id'=> $request->user_id, - 'clock_in'=> $request->clock_time, - 'date_presence'=> $onlyDate, - 'created_by' => $this->currentName, - 'clock_in_lat' => $request->clock_in_lat, - 'clock_in_lng' => $request->clock_in_lng, - 'clock_in_loc' => $clock_in_loc, - 'clock_in_boundary' => $statusBoundary - ); - - $result = Presence::create($dataAdd); - $data=array( - 'id' => $result->id, - 'boundary' => $statusBoundary - ); - if($result){ - if($statusBoundary){ - for ($i=0; $i < count($checkLocation); $i++) { - # code... - DB::table('clock_in_out_boundary')->insert([ - "clock_in_out_id" => $result->id, - "user_id" => $request->user_id, - "activity_id" => $checkLocation[$i]['activity_id'], - "type" => $request->type, - "created_at" => $date, - "created_by" => $this->currentName - ]); - }; - }; - return response()->json(['status'=>'success', 'data' => $data,'message'=>'clock in successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'clock in failed!','code'=>400], 400); - } - } - - public function reportK3(Request $request){ - // return response()->json(['status'=>'success', 'message'=>$request->report_k3['detail'],'code'=>200], 200); - - $this->validate($request, [ - 'user_id' => 'required' - ]); - - $checkLocation = $this->checkLocation($request); - $statusBoundary = false; - $date = date_create($request->time); - // assign and in boundary - if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ - $statusBoundary = true; - } - $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); - if ($statusRestriction->status_boundary) { - $statusBoundary = true; - } - // not assign - if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ - $data=array( - 'id' => null, - 'boundary' => $statusBoundary - ); - return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200); - } - // assign and not in boundary - if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ - $data=array( - 'id' => null, - 'boundary' => true - ); - return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda berada di luar area kerja.','code'=>200], 200); - } - - if($request->clock_in_out['type']=="out"){ - $clock_out_loc = $this->getLoc($request->clock_in_out['clock_out_lat'], $request->clock_in_out['clock_out_lng'])->display_name; - $dataUpdate = array( - "clock_out"=>$request->time, - "clock_out_lat" => $request->clock_in_out['clock_out_lat'], - "clock_out_lng" => $request->clock_in_out['clock_out_lng'], - "updated_by"=>$this->currentName, - "clock_out_loc" => $clock_out_loc, - "clock_out_boundary" => $statusBoundary - ); - - $resultUpdate = $this->updateFormAdd($dataUpdate, $request->user_id); - if($resultUpdate && $resultUpdate > 0){ - if($statusBoundary){ - for ($i=0; $i < count($checkLocation); $i++) { - # code... - DB::table('clock_in_out_boundary')->insert([ - "clock_in_out_id" => $resultUpdate, - "user_id" => $request->user_id, - "activity_id" => $checkLocation[$i]['activity_id'], - "type" => $request->clock_in_out['type'], - "created_at" => $date, - "created_by" => $this->currentName - ]); - }; - }; - $data=array( - 'presence_id' => $resultUpdate, - 'boundary' => $statusBoundary - ); - - return response()->json(['status'=>'success', 'data'=>$data,'message'=>'clock out success!','code'=>200], 200); - } - else{ - return response()->json(['status'=>'failed','message'=>'clock out failed please try again!','code'=>400], 400); - } - die(); - } - - $onlyDate = date_format($date,"Y-m-d"); - $clock_in_loc = $this->getLoc($request->clock_in_out['clock_in_lat'], $request->clock_in_out['clock_in_lng'])->display_name; - - $dataFormK3 = array( - "user_id" => $request->user_id, - "proyek_id" => $request->report_k3['proyek_id'], - "report_date" => $request->time, - "description" => $request->report_k3['description'] - ); - - $dataFormPresence = array( - 'user_id' => $request->user_id, - 'clock_in' => $request->time, - 'date_presence' => $onlyDate, - 'created_by' => $this->currentName, - 'clock_in_lat' => $request->clock_in_out['clock_in_lat'], - 'clock_in_lng' => $request->clock_in_out['clock_in_lng'], - 'clock_in_loc' => $clock_in_loc, - 'clock_in_boundary' => $statusBoundary - ); - - $result = Presence::create($dataFormPresence); - $data=array( - 'presence_id' => $result->id, - 'boundary' => $statusBoundary - ); - if($result){ - if($statusBoundary){ - $insertk3 = $this->insertK3($dataFormK3, $request->report_k3['detail']) ; - for ($i=0; $i < count($checkLocation); $i++) { - # code... - DB::table('clock_in_out_boundary')->insert([ - "clock_in_out_id" => $result->id, - "user_id" => $request->user_id, - "activity_id" => $checkLocation[$i]['activity_id'], - "type" => $request->type, - "created_at" => $date, - "created_by" => $this->currentName - ]); - }; - $data['report_id'] = $insertk3->id; - }; - return response()->json(['status'=>'success', 'data'=> $data, 'message'=>'clock in successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'clock in failed!','code'=>400], 400); - } - } - - private function insertK3($params, $details){ - $insert = ReportK3::create($params); - if($insert && $details){ - $this->addDetailK3($details, $insert->id); - } - return $insert; - } - - private function checkLocation($params){ - // cek user tersebut apakah punya assign task yang ada bondary nya - // geom ada di table activity - // $clock_time = - $user = HumanResource::find($params->user_id); - $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") - ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") - ->where("ahta.user_id", $params->user_id) - ->whereNotNull("ma.geom") - ->whereDate("ma.start_date", "<=", $params->time) - ->whereDate("ma.end_date", ">=", $params->time) - ->get(); - $temp = []; - if (count($geom) > 0) { - foreach($geom as $dataGeom){ - $valGeom = json_decode($dataGeom->geom); - if($params->clock_in_out['type']=="out"){ - if($valGeom->type == "FeatureCollection"){ - $multiArea = $valGeom->features; - foreach($multiArea as $area){ - if ($area->geometry->type === "Point") { - $pointCoordinates = $area->geometry->coordinates; - $pointLng = $pointCoordinates[0]; - $pointLat = $pointCoordinates[1]; - - $check = DB::select(DB::raw("SELECT ST_Distance( - ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'), - ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326) - ) <= " . $area->properties->radius . " as within_radius")); - - if ($check[0]->within_radius) { - break; - } - } - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ - break; - } - } - }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - } - }else{ - if($valGeom->type == "FeatureCollection"){ - $multiArea = $valGeom->features; - foreach($multiArea as $area){ - if ($area->geometry->type === "Point") { - $pointCoordinates = $area->geometry->coordinates; - $pointLng = $pointCoordinates[0]; - $pointLat = $pointCoordinates[1]; - - $check = DB::select(DB::raw("SELECT ST_Distance( - ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'), - ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326) - ) <= " . $area->properties->radius . " as within_radius")); - - if ($check[0]->within_radius) { - break; - } - } - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ - break; - } - } - }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - } - } - if(!$user->status_boundary || count($check)>0){ - if(!$user->status_boundary || (isset($check[0]->boundary) && $check[0]->boundary)){ - $temp[]=array( - "activity_id" => $dataGeom->id, - "boundary" => $check[0]->boundary, - "status_assign" => true - ); - } else if (!$user->status_boundary || (isset($check[0]->within_radius) && $check[0]->within_radius)) { - $temp[]=array( - "activity_id" => $dataGeom->id, - "boundary" => $check[0]->within_radius, - "status_assign" => true - ); - } - } - } - // assign and not in boundary - if(count($temp) < 1){ - $temp[]=array( - "activity_id" => null, - "boundary" => false, - "status_assign" => true - // "geom" => $geom, - // "cek" => $check[0]->boundary - ); - } - } - else{ - // not assign - $temp[]=array( - "activity_id" => null, - "boundary" => false, - "status_assign" => false - ); - } - return $temp; - } - - public function checkLocationTest(Request $request){ - // cek user tersebut apakah punya assign task yang ada bondary nya - // geom ada di table activity - // $clock_time = - $params = $request; - $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") - ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") - ->where("ahta.user_id", $params->user_id) - ->whereNotNull("ma.geom") - ->whereDate("ma.start_date", "<=", $params->time) - ->whereDate("ma.end_date", ">=", $params->time) - ->get(); - $temp = []; - // return json_encode($geom); - if (count($geom) > 0) { - foreach($geom as $dataGeom){ - $valGeom = json_decode($dataGeom->geom); - if($params->clock_in_out['type']=="out"){ - if($valGeom->type == "FeatureCollection"){ - // return count($valGeom->features); - $multiArea = $valGeom->features; - foreach($multiArea as $area){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ - break; - } - } - }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); - } - }else{ - if($valGeom->type == "FeatureCollection"){ - // return count($valGeom->features); - $multiArea = $valGeom->features; - foreach($multiArea as $area){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - if($check[0]->boundary){ - break; - } - } - }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), - ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); - } - } - if(count($check)>0){ - if($check[0]->boundary){ - $temp[]=array( - "activity_id" => $dataGeom->id, - "boundary" => $check[0]->boundary, - "status_assign" => true - ); - } - } - } - // assign and not in boundary - if(count($temp) < 1){ - $temp[]=array( - "activity_id" => null, - "boundary" => false, - "status_assign" => true - // "geom" => $geom, - // "cek" => $check[0]->boundary - ); - } - } - else{ - // not assign - $temp[]=array( - "activity_id" => null, - "boundary" => false, - "status_assign" => false - ); - } - return $temp; - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = Presence::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data project, please try again later!','code'=>400], 400); - } - } - - public function clockinout($id) { - $dateTimeNow = Carbon::now()->addHour(7); - $dataPresence = Presence::where('user_id', $id)->orderBy('id', 'DESC')->first(); - - if($dataPresence){ - - $dateNow = date("Y-m-d"); - $dateA = strtotime($dataPresence->clock_in); - $dayClockin = date("Y-m-d", $dateA); - if($dayClockin == $dateNow){ - $clock_in = $dataPresence->clock_in; - $clock_out = $dataPresence->clock_out; - }else{ - $clock_in = null; - $clock_out = null; - } - $res_data = array( - "id" => $dataPresence->id, - "at" => $dateTimeNow, - "user_id"=> $id, - "clock_in"=> $clock_in, - "clock_out"=> $clock_out, - "last_clock_in"=> $dataPresence->clock_in, - "last_clock_out"=> $dataPresence->clock_out, - "in_working_time"=> true - ); - return response()->json(['status'=>'success','data'=>$res_data,'code'=>200], 200); - } - $res_data = array( - "id" => null, - "at" => $dateTimeNow, - "user_id"=> $id, - "clock_in"=> null, - "clock_out"=> null, - "last_clock_in"=> null, - "last_clock_out"=> null, - "in_working_time"=> true - ); - return response()->json(['status'=>'success','data'=>$res_data,'code'=>200], 200); - } - - private function updateFormAdd($data, $id){ - $date = date_create($data['clock_out']); - $onlyDate = date_format($date,"Y-m-d"); - - $dataPresence = Presence::where('user_id',$id) - ->where("clock_in", "<=", $data["clock_out"]) - ->orderByDesc("id") - ->first(); - - if($dataPresence){ - $queryUpdate = $dataPresence->update($data); - if($queryUpdate){ - $getDataUpdate = Presence::where('user_id', $id)->where("date_presence", $onlyDate)->first(); - return $getDataUpdate->id; - }else{ - return false; - } - }else{ - return false; - } - die(); - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Presence::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data presence not found!','code'=>400], 400); - die(); - } - - if($result){ - return response()->json(['status'=>'success','message'=>'data presence successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data presence failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = Presence::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data presence not found!','code'=>400], 400); - die(); - } - - if($delete){ - return response()->json(['status'=>'success','message'=>'data presence successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data presence failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 't_clock_in_out'); - $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 list() - { - $data = Presence::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list presence, please try again later!','code'=>400], 400); - } - } - - public function bulkUpdateLocation() - { - $data = Presence::all(); - $finalData = []; - foreach($data as $objRow) { - $presence = Presence::find($objRow->id); - - $clock_in_lat = $objRow->clock_in_lat; - $clock_in_lng = $objRow->clock_in_lng; - $objRow->clock_in_loc = ""; - if (isset($clock_in_lat) && isset($clock_in_lng)) { - $objRow->clock_in_loc = $this->getLoc($clock_in_lat, $clock_in_lng)->display_name; - } - - $clock_out_lat = $objRow->clock_out_lat; - $clock_out_lng = $objRow->clock_out_lng; - $objRow->clock_out_loc = ""; - if (isset($clock_out_lat) && isset($clock_out_lng) && $clock_out_lng != null) { - $locAddress = $this->getLoc($clock_out_lat, $clock_out_lng); - $objRow->clock_out_loc = isset($locAddress->display_name) ? $locAddress->display_name : "-"; - } - - - $presence->clock_in_loc = $objRow->clock_in_loc; - $presence->clock_out_loc = $objRow->clock_out_loc; - $presence->save(); - } - return response()->json(['status'=>'success','message'=>'success update!','code'=>200], 200); - } -} +validate($request, [ + 'user_id' => 'required' + ]); + + $checkLocation = $this->checkLocation($request); + $statusBoundary = false; + $date = date_create($request->clock_time); + // assign and in boundary + if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ + $statusBoundary = true; + } + $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); + if ($statusRestriction->status_boundary) { + $statusBoundary = true; + } + // not assign + if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + $data=array( + 'id' => null, + 'boundary' => $statusBoundary + ); + return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200); + } + // assign and not in boundary + if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + $data=array( + 'id' => null, + 'boundary' => true + ); + return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda berada di luar area kerja.','code'=>200], 200); + } + + if($request->type=="out"){ + $clock_out_loc = $this->getLoc($request->clock_out_lat, $request->clock_out_lng)->display_name; + $dataUpdate = array( + "clock_out"=>$request->clock_time, + "clock_out_lat" => $request->clock_out_lat, + "clock_out_lng" => $request->clock_out_lng, + "updated_by"=>$this->currentName, + "clock_out_loc" => $clock_out_loc, + "clock_out_boundary" => $statusBoundary + ); + + $resultUpdate = $this->updateFormAdd($dataUpdate, $request->user_id); + if($resultUpdate && $resultUpdate > 0){ + if($statusBoundary){ + for ($i=0; $i < count($checkLocation); $i++) { + # code... + DB::table('clock_in_out_boundary')->insert([ + "clock_in_out_id" => $resultUpdate, + "user_id" => $request->user_id, + "activity_id" => $checkLocation[$i]['activity_id'], + "type" => $request->type, + "created_at" => $date, + "created_by" => $this->currentName + ]); + }; + }; + $data=array( + 'id' => $resultUpdate, + 'boundary' => $statusBoundary + ); + + return response()->json(['status'=>'success', 'data'=>$data,'message'=>'clock out success!','code'=>200], 200); + } + else{ + return response()->json(['status'=>'failed','message'=>'clock out failed please try again!','code'=>400], 400); + } + die(); + } + + $onlyDate = date_format($date,"Y-m-d"); + $clock_in_loc = $this->getLoc($request->clock_in_lat, $request->clock_in_lng)->display_name; + + $dataAdd = array( + 'user_id'=> $request->user_id, + 'clock_in'=> $request->clock_time, + 'date_presence'=> $onlyDate, + 'created_by' => $this->currentName, + 'clock_in_lat' => $request->clock_in_lat, + 'clock_in_lng' => $request->clock_in_lng, + 'clock_in_loc' => $clock_in_loc, + 'clock_in_boundary' => $statusBoundary + ); + + $result = Presence::create($dataAdd); + $data=array( + 'id' => $result->id, + 'boundary' => $statusBoundary + ); + if($result){ + if($statusBoundary){ + for ($i=0; $i < count($checkLocation); $i++) { + # code... + DB::table('clock_in_out_boundary')->insert([ + "clock_in_out_id" => $result->id, + "user_id" => $request->user_id, + "activity_id" => $checkLocation[$i]['activity_id'], + "type" => $request->type, + "created_at" => $date, + "created_by" => $this->currentName + ]); + }; + }; + return response()->json(['status'=>'success', 'data' => $data,'message'=>'clock in successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'clock in failed!','code'=>400], 400); + } + } + + public function reportK3(Request $request){ + // return response()->json(['status'=>'success', 'message'=>$request->report_k3['detail'],'code'=>200], 200); + + $this->validate($request, [ + 'user_id' => 'required' + ]); + + $checkLocation = $this->checkLocation($request); + $statusBoundary = false; + $date = date_create($request->time); + // assign and in boundary + if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ + $statusBoundary = true; + } + $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); + if ($statusRestriction->status_boundary) { + $statusBoundary = true; + } + // not assign + if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + $data=array( + 'id' => null, + 'boundary' => $statusBoundary + ); + return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200); + } + // assign and not in boundary + if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + $data=array( + 'id' => null, + 'boundary' => true + ); + return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda berada di luar area kerja.','code'=>200], 200); + } + + if($request->clock_in_out['type']=="out"){ + $clock_out_loc = $this->getLoc($request->clock_in_out['clock_out_lat'], $request->clock_in_out['clock_out_lng'])->display_name; + $dataUpdate = array( + "clock_out"=>$request->time, + "clock_out_lat" => $request->clock_in_out['clock_out_lat'], + "clock_out_lng" => $request->clock_in_out['clock_out_lng'], + "updated_by"=>$this->currentName, + "clock_out_loc" => $clock_out_loc, + "clock_out_boundary" => $statusBoundary + ); + + $resultUpdate = $this->updateFormAdd($dataUpdate, $request->user_id); + if($resultUpdate && $resultUpdate > 0){ + if($statusBoundary){ + for ($i=0; $i < count($checkLocation); $i++) { + # code... + DB::table('clock_in_out_boundary')->insert([ + "clock_in_out_id" => $resultUpdate, + "user_id" => $request->user_id, + "activity_id" => $checkLocation[$i]['activity_id'], + "type" => $request->clock_in_out['type'], + "created_at" => $date, + "created_by" => $this->currentName + ]); + }; + }; + $data=array( + 'presence_id' => $resultUpdate, + 'boundary' => $statusBoundary + ); + + return response()->json(['status'=>'success', 'data'=>$data,'message'=>'clock out success!','code'=>200], 200); + } + else{ + return response()->json(['status'=>'failed','message'=>'clock out failed please try again!','code'=>400], 400); + } + die(); + } + + $onlyDate = date_format($date,"Y-m-d"); + $clock_in_loc = $this->getLoc($request->clock_in_out['clock_in_lat'], $request->clock_in_out['clock_in_lng'])->display_name; + + $dataFormK3 = array( + "user_id" => $request->user_id, + "proyek_id" => $request->report_k3['proyek_id'], + "report_date" => $request->time, + "description" => $request->report_k3['description'] + ); + + $dataFormPresence = array( + 'user_id' => $request->user_id, + 'clock_in' => $request->time, + 'date_presence' => $onlyDate, + 'created_by' => $this->currentName, + 'clock_in_lat' => $request->clock_in_out['clock_in_lat'], + 'clock_in_lng' => $request->clock_in_out['clock_in_lng'], + 'clock_in_loc' => $clock_in_loc, + 'clock_in_boundary' => $statusBoundary + ); + + $result = Presence::create($dataFormPresence); + $data=array( + 'presence_id' => $result->id, + 'boundary' => $statusBoundary + ); + if($result){ + if($statusBoundary){ + $insertk3 = $this->insertK3($dataFormK3, $request->report_k3['detail']) ; + for ($i=0; $i < count($checkLocation); $i++) { + # code... + DB::table('clock_in_out_boundary')->insert([ + "clock_in_out_id" => $result->id, + "user_id" => $request->user_id, + "activity_id" => $checkLocation[$i]['activity_id'], + "type" => $request->type, + "created_at" => $date, + "created_by" => $this->currentName + ]); + }; + $data['report_id'] = $insertk3->id; + }; + return response()->json(['status'=>'success', 'data'=> $data, 'message'=>'clock in successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'clock in failed!','code'=>400], 400); + } + } + + private function insertK3($params, $details){ + $insert = ReportK3::create($params); + if($insert && $details){ + $this->addDetailK3($details, $insert->id); + } + return $insert; + } + + private function checkLocation($params){ + // cek user tersebut apakah punya assign task yang ada bondary nya + // geom ada di table activity + // $clock_time = + $user = HumanResource::find($params->user_id); + $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") + ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") + ->where("ahta.user_id", $params->user_id) + ->whereNotNull("ma.geom") + ->whereDate("ma.start_date", "<=", $params->time) + ->whereDate("ma.end_date", ">=", $params->time) + ->get(); + $temp = []; + if (count($geom) > 0) { + foreach($geom as $dataGeom){ + $valGeom = json_decode($dataGeom->geom); + if($params->clock_in_out['type']=="out"){ + if($valGeom->type == "FeatureCollection"){ + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + if ($area->geometry->type === "Point") { + $pointCoordinates = $area->geometry->coordinates; + $pointLng = $pointCoordinates[0]; + $pointLat = $pointCoordinates[1]; + + $check = DB::select(DB::raw("SELECT ST_Distance( + ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'), + ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326) + ) <= " . $area->properties->radius . " as within_radius")); + + if ($check[0]->within_radius) { + break; + } + } + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + } + }else{ + if($valGeom->type == "FeatureCollection"){ + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + if ($area->geometry->type === "Point") { + $pointCoordinates = $area->geometry->coordinates; + $pointLng = $pointCoordinates[0]; + $pointLat = $pointCoordinates[1]; + + $check = DB::select(DB::raw("SELECT ST_Distance( + ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'), + ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326) + ) <= " . $area->properties->radius . " as within_radius")); + + if ($check[0]->within_radius) { + break; + } + } + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + } + } + if(!$user->status_boundary || count($check)>0){ + if(!$user->status_boundary || (isset($check[0]->boundary) && $check[0]->boundary)){ + $temp[]=array( + "activity_id" => $dataGeom->id, + "boundary" => $check[0]->boundary, + "status_assign" => true + ); + } else if (!$user->status_boundary || (isset($check[0]->within_radius) && $check[0]->within_radius)) { + $temp[]=array( + "activity_id" => $dataGeom->id, + "boundary" => $check[0]->within_radius, + "status_assign" => true + ); + } + } + } + // assign and not in boundary + if(count($temp) < 1){ + $temp[]=array( + "activity_id" => null, + "boundary" => false, + "status_assign" => true + // "geom" => $geom, + // "cek" => $check[0]->boundary + ); + } + } + else{ + // not assign + $temp[]=array( + "activity_id" => null, + "boundary" => false, + "status_assign" => false + ); + } + return $temp; + } + + public function checkLocationTest(Request $request){ + // cek user tersebut apakah punya assign task yang ada bondary nya + // geom ada di table activity + // $clock_time = + $params = $request; + $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") + ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") + ->where("ahta.user_id", $params->user_id) + ->whereNotNull("ma.geom") + ->whereDate("ma.start_date", "<=", $params->time) + ->whereDate("ma.end_date", ">=", $params->time) + ->get(); + $temp = []; + // return json_encode($geom); + if (count($geom) > 0) { + foreach($geom as $dataGeom){ + $valGeom = json_decode($dataGeom->geom); + if($params->clock_in_out['type']=="out"){ + if($valGeom->type == "FeatureCollection"){ + // return count($valGeom->features); + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + } + }else{ + if($valGeom->type == "FeatureCollection"){ + // return count($valGeom->features); + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + } + } + if(count($check)>0){ + if($check[0]->boundary){ + $temp[]=array( + "activity_id" => $dataGeom->id, + "boundary" => $check[0]->boundary, + "status_assign" => true + ); + } + } + } + // assign and not in boundary + if(count($temp) < 1){ + $temp[]=array( + "activity_id" => null, + "boundary" => false, + "status_assign" => true + // "geom" => $geom, + // "cek" => $check[0]->boundary + ); + } + } + else{ + // not assign + $temp[]=array( + "activity_id" => null, + "boundary" => false, + "status_assign" => false + ); + } + return $temp; + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = Presence::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data project, please try again later!','code'=>400], 400); + } + } + + public function clockinout($id) { + $dateTimeNow = Carbon::now()->addHour(7); + $dataPresence = Presence::where('user_id', $id)->orderBy('id', 'DESC')->first(); + + if($dataPresence){ + + $dateNow = date("Y-m-d"); + $dateA = strtotime($dataPresence->clock_in); + $dayClockin = date("Y-m-d", $dateA); + if($dayClockin == $dateNow){ + $clock_in = $dataPresence->clock_in; + $clock_out = $dataPresence->clock_out; + }else{ + $clock_in = null; + $clock_out = null; + } + $res_data = array( + "id" => $dataPresence->id, + "at" => $dateTimeNow, + "user_id"=> $id, + "clock_in"=> $clock_in, + "clock_out"=> $clock_out, + "last_clock_in"=> $dataPresence->clock_in, + "last_clock_out"=> $dataPresence->clock_out, + "in_working_time"=> true + ); + return response()->json(['status'=>'success','data'=>$res_data,'code'=>200], 200); + } + $res_data = array( + "id" => null, + "at" => $dateTimeNow, + "user_id"=> $id, + "clock_in"=> null, + "clock_out"=> null, + "last_clock_in"=> null, + "last_clock_out"=> null, + "in_working_time"=> true + ); + return response()->json(['status'=>'success','data'=>$res_data,'code'=>200], 200); + } + + private function updateFormAdd($data, $id){ + $date = date_create($data['clock_out']); + $onlyDate = date_format($date,"Y-m-d"); + + $dataPresence = Presence::where('user_id',$id) + ->where("clock_in", "<=", $data["clock_out"]) + ->orderByDesc("id") + ->first(); + + if($dataPresence){ + $queryUpdate = $dataPresence->update($data); + if($queryUpdate){ + $getDataUpdate = Presence::where('user_id', $id)->where("date_presence", $onlyDate)->first(); + return $getDataUpdate->id; + }else{ + return false; + } + }else{ + return false; + } + die(); + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = Presence::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data presence not found!','code'=>400], 400); + die(); + } + + if($result){ + return response()->json(['status'=>'success','message'=>'data presence successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data presence failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = Presence::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data presence not found!','code'=>400], 400); + die(); + } + + if($delete){ + return response()->json(['status'=>'success','message'=>'data presence successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data presence failed deleted!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 't_clock_in_out'); + $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 list() + { + $data = Presence::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list presence, please try again later!','code'=>400], 400); + } + } + + public function bulkUpdateLocation() + { + $data = Presence::all(); + $finalData = []; + foreach($data as $objRow) { + $presence = Presence::find($objRow->id); + + $clock_in_lat = $objRow->clock_in_lat; + $clock_in_lng = $objRow->clock_in_lng; + $objRow->clock_in_loc = ""; + if (isset($clock_in_lat) && isset($clock_in_lng)) { + $objRow->clock_in_loc = $this->getLoc($clock_in_lat, $clock_in_lng)->display_name; + } + + $clock_out_lat = $objRow->clock_out_lat; + $clock_out_lng = $objRow->clock_out_lng; + $objRow->clock_out_loc = ""; + if (isset($clock_out_lat) && isset($clock_out_lng) && $clock_out_lng != null) { + $locAddress = $this->getLoc($clock_out_lat, $clock_out_lng); + $objRow->clock_out_loc = isset($locAddress->display_name) ? $locAddress->display_name : "-"; + } + + + $presence->clock_in_loc = $objRow->clock_in_loc; + $presence->clock_out_loc = $objRow->clock_out_loc; + $presence->save(); + } + return response()->json(['status'=>'success','message'=>'success update!','code'=>200], 200); + } +} diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 14e67ed..f9b9ef3 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -1,199 +1,220 @@ -validate($request, [ - 'activity_id' => 'required', - 'user_id' => 'required' - ]); - - $data = $request->all(); - $data['created_by'] = $this->currentName; - - if(!UserToActivity::create($data)) - return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]); - - return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]); - } - - public function addMultiple(Request $request){ - $users_id = $request->user_id; - $users_role = $request->role_proyek_id; - - // $data = UserToActivity::where("activity_id", $request->activity_id); - // if($data){ - // $data->delete(); - // } - - if(is_array($users_id) && count($users_id) > 0){ - $countRes = 0; - foreach($users_id as $index => $item){ - $dataInsert = array( - "user_id" => $item, - "activity_id" => $request->activity_id, - "role_proyek_id" => $users_role[$index], - "proyek_id" => $request->proyek_id, - "created_by" => $this->currentName, - "version_gantt_id" => $request->version_gantt_id - ); - $result = UserToActivity::create($dataInsert); - if($result){ - $countRes++; - }else{ - $countRes--; - } - } - - if($countRes == 0) - return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]); - - $allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id); - $dataUpdateCost = array( - "rencana_biaya"=>$allCost, - "updated_by"=> $this->currentName - ); - $actUpdate = Activity::find($request->activity_id); - if($actUpdate){ - $actUpdate->update($dataUpdateCost); - if($actUpdate->parent_id){ - $this->updatedCostPlanning($actUpdate->parent_id); - } - } - return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); - }else{ - return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); - } - - } - - private function updatedCostPlanning($parent_id) { - $sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') - ->where("parent_id", $parent_id) - ->first(); - if($parent = Activity::find($parent_id)){ - $parent->update([ - "rencana_biaya" => $sumBiaya->sum, - ]); - } - } - - public function update(Request $request, $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = UserToActivity::find($id); - if(!$data) - 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'=>'Data updated!','code'=>200], 200); - } - - public function delete($id) - { - $data = UserToActivity::find($id); - if(!$data) - return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); - - if($data->delete()){ - return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); - } - - return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = UserToActivity::find($id); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400); - - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_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 list() - { - $data = UserToActivity::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); - } - } - - public function listFiltered(Request $request) - { - $startDate = $request->start_date; - $endDate = $request->end_date; - $userId = $request->user_id; - $proyekId = $request->proyek_id; - - if (isset($proyekId)) { - $data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') - ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') - ->where('m_activity.start_date', '=', $startDate) - ->where('m_activity.end_date', '=', $endDate) - ->where('assign_hr_to_activity.user_id', '=', $userId) - ->where('assign_hr_to_activity.proyek_id', '=', $proyekId) - ->get(); - }else { - $data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') - ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') - ->where('m_activity.start_date', '=', $startDate) - ->where('m_activity.end_date', '=', $endDate) - ->where('assign_hr_to_activity.user_id', '=', $userId) - ->get(); - } - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); - } - } - - public function datatables(Request $request){ - $id_activity = $request->query('idact'); - $data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name") - ->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") - ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") - ->where('assign_hr_to_activity.activity_id', $id_activity) - ->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('action', function($row){ - $actionBtn = ''; - return $actionBtn; - }) - ->rawColumns(['action'])->make(true); - } -} +validate($request, [ + 'activity_id' => 'required', + 'user_id' => 'required' + ]); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + + if(!UserToActivity::create($data)) + return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]); + + return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]); + } + + public function addMultiple(Request $request){ + $users_id = $request->user_id; + $users_role = $request->role_proyek_id; + + // $data = UserToActivity::where("activity_id", $request->activity_id); + // if($data){ + // $data->delete(); + // } + + if(is_array($users_id) && count($users_id) > 0){ + $countRes = 0; + foreach($users_id as $index => $item){ + $dataInsert = array( + "user_id" => $item, + "activity_id" => $request->activity_id, + "role_proyek_id" => $users_role[$index], + "proyek_id" => $request->proyek_id, + "created_by" => $this->currentName, + "version_gantt_id" => $request->version_gantt_id + ); + $result = UserToActivity::create($dataInsert); + if($result){ + $countRes++; + }else{ + $countRes--; + } + } + + if($countRes == 0) + return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]); + + $allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id); + $dataUpdateCost = array( + "rencana_biaya"=>$allCost, + "updated_by"=> $this->currentName + ); + $actUpdate = Activity::find($request->activity_id); + if($actUpdate){ + $actUpdate->update($dataUpdateCost); + if($actUpdate->parent_id){ + $this->updatedCostPlanning($actUpdate->parent_id); + } + } + return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); + }else{ + return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); + } + + } + + private function updatedCostPlanning($parent_id) { + $sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') + ->where("parent_id", $parent_id) + ->first(); + if($parent = Activity::find($parent_id)){ + $parent->update([ + "rencana_biaya" => $sumBiaya->sum, + ]); + } + } + + public function update(Request $request, $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = UserToActivity::find($id); + if(!$data) + 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'=>'Data updated!','code'=>200], 200); + } + + public function delete($id) + { + $data = UserToActivity::find($id); + if(!$data) + return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); + + if($data->delete()){ + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + } + + return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = UserToActivity::find($id); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + if (isset($payload['join_column'])) { + $join_column = $payload['join_column']; + $startDate = $join_column['start_date']; + $endDate = $join_column['end_date']; + $startDate = date("Y-m-d H:i:sO", strtotime($startDate)); + $endDate = date("Y-m-d H:i:sO", strtotime($endDate)); + unset($payload['join_column']); + } + + $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + if (isset($join_column)) { + $builder->where(function ($query) use ($startDate, $endDate) { + $query + ->where('m_proyek.mulai_proyek', '<=', $startDate) + ->where('m_proyek.akhir_proyek', '>=', $endDate) + ->where(function ($query) use ($endDate, $startDate) { + $query + ->where('m_activity.start_date', '<=', $startDate) + ->where('m_activity.end_date', '>=', $endDate); + }); + }); + } + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = UserToActivity::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); + } + } + + public function listFiltered(Request $request) + { + $startDate = $request->start_date; + $endDate = $request->end_date; + $userId = $request->user_id; + $proyekId = $request->proyek_id; + + if (isset($proyekId)) { + $data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') + ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') + ->where('m_activity.start_date', '=', $startDate) + ->where('m_activity.end_date', '=', $endDate) + ->where('assign_hr_to_activity.user_id', '=', $userId) + ->where('assign_hr_to_activity.proyek_id', '=', $proyekId) + ->get(); + }else { + $data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') + ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') + ->where('m_activity.start_date', '=', $startDate) + ->where('m_activity.end_date', '=', $endDate) + ->where('assign_hr_to_activity.user_id', '=', $userId) + ->get(); + } + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); + } + } + + public function datatables(Request $request){ + $id_activity = $request->query('idact'); + $data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name") + ->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") + ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") + ->where('assign_hr_to_activity.activity_id', $id_activity) + ->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('action', function($row){ + $actionBtn = ''; + return $actionBtn; + }) + ->rawColumns(['action'])->make(true); + } +} From 366ac1477762d209c6bcb70c96ef7d6dd73f3b15 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 26 Sep 2023 10:24:01 +0700 Subject: [PATCH 156/185] fix date filter --- .../Controllers/UserToActivityController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index f9b9ef3..5951aa6 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -131,10 +131,6 @@ class UserToActivityController extends Controller $payload = $request->all(); if (isset($payload['join_column'])) { $join_column = $payload['join_column']; - $startDate = $join_column['start_date']; - $endDate = $join_column['end_date']; - $startDate = date("Y-m-d H:i:sO", strtotime($startDate)); - $endDate = date("Y-m-d H:i:sO", strtotime($endDate)); unset($payload['join_column']); } @@ -142,14 +138,18 @@ class UserToActivityController extends Controller $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; if (isset($join_column)) { + $startDate = $join_column['start_date']; + $endDate = $join_column['end_date']; + $startDate = date("Y-m-d H:i:sO", strtotime($startDate)); + $endDate = date("Y-m-d H:i:sO", strtotime($endDate)); $builder->where(function ($query) use ($startDate, $endDate) { $query - ->where('m_proyek.mulai_proyek', '<=', $startDate) - ->where('m_proyek.akhir_proyek', '>=', $endDate) + ->where('m_proyek.mulai_proyek', '>=', $startDate) + ->where('m_proyek.akhir_proyek', '<=', $endDate) ->where(function ($query) use ($endDate, $startDate) { $query - ->where('m_activity.start_date', '<=', $startDate) - ->where('m_activity.end_date', '>=', $endDate); + ->where('m_activity.start_date', '>=', $startDate) + ->where('m_activity.end_date', '<=', $endDate); }); }); } From 1a02dd2d03dea20092536068fc0dded0f14ab505 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 26 Sep 2023 13:54:21 +0700 Subject: [PATCH 157/185] add status filter --- app/Http/Controllers/UserToActivityController.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 5951aa6..c422cf6 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\UserToActivity; use App\Models\Activity; +use App\Models\AssignMaterial; use Datatables; class UserToActivityController extends Controller @@ -140,6 +141,7 @@ class UserToActivityController extends Controller if (isset($join_column)) { $startDate = $join_column['start_date']; $endDate = $join_column['end_date']; + $status = $join_column['status']; $startDate = date("Y-m-d H:i:sO", strtotime($startDate)); $endDate = date("Y-m-d H:i:sO", strtotime($endDate)); $builder->where(function ($query) use ($startDate, $endDate) { @@ -154,6 +156,16 @@ class UserToActivityController extends Controller }); } $dataGet = $builder->get(); + if (isset($status) && $status != "") { + $filteredData = []; + foreach ($dataGet as $value) { + $assignMaterial = AssignMaterial::where('activity_id', $value->activity_id)->first(); + if ($assignMaterial->status_activity == $status) { + $filteredData[] = $value; + } + } + $dataGet = $filteredData; + } $totalRecord = $countBuilder->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); } From ab1842f5c632f2b524138ab63fa08f1f5c44b125 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 27 Sep 2023 09:31:18 +0700 Subject: [PATCH 158/185] add filter project id --- app/Http/Controllers/PresenceController.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 0d79917..f5309ac 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -259,13 +259,17 @@ class PresenceController extends Controller // geom ada di table activity // $clock_time = $user = HumanResource::find($params->user_id); - $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") - ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") - ->where("ahta.user_id", $params->user_id) - ->whereNotNull("ma.geom") - ->whereDate("ma.start_date", "<=", $params->time) - ->whereDate("ma.end_date", ">=", $params->time) - ->get(); + $geomQuery = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") + ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") + ->where("ahta.user_id", $params->user_id) + ->whereNotNull("ma.geom") + ->whereDate("ma.start_date", "<=", $params->time) + ->whereDate("ma.end_date", ">=", $params->time); + if (isset($params->report_k3['proyek_id'])) { + $geom = $geomQuery->where("ma.proyek_id", $params->report_k3['proyek_id'])->get(); + } else { + $geom = $geomQuery->get(); + } $temp = []; if (count($geom) > 0) { foreach($geom as $dataGeom){ From c422bade05f132ae292668d9858a3f17407cbc76 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 27 Sep 2023 14:15:42 +0700 Subject: [PATCH 159/185] fix work area restriction --- app/Http/Controllers/PresenceController.php | 28 ++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index f5309ac..49b9da1 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -345,6 +345,13 @@ class PresenceController extends Controller "status_assign" => true ); } + } else { + // bypass work area restriction + $temp[]=array( + "activity_id" => null, + "boundary" => true, + "status_assign" => true + ); } } // assign and not in boundary @@ -359,12 +366,21 @@ class PresenceController extends Controller } } else{ - // not assign - $temp[]=array( - "activity_id" => null, - "boundary" => false, - "status_assign" => false - ); + if ($user->status_boundary) { + // bypass work area restriction + $temp[]=array( + "activity_id" => null, + "boundary" => true, + "status_assign" => true + ); + } else { + // not assign + $temp[]=array( + "activity_id" => null, + "boundary" => false, + "status_assign" => false + ); + } } return $temp; } From 785e8677fff88eb62ae34d97c9517b66643defd8 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 27 Sep 2023 14:57:47 +0700 Subject: [PATCH 160/185] change condition Models --- app/Http/Controllers/DivisiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index 7ef14d3..e398682 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -92,7 +92,7 @@ class DivisiController extends Controller public function list() { - $parentMenus = Divisi::with('children')->whereNull('parent')->get(); + $parentMenus = Divisi::whereNull('parent')->with('children')->get(); $divisions = []; foreach($parentMenus as $menu){ $childs = $this->getAllChildren($menu); From f4cd27cdc6cbe65991bdbf2b561d62561b4bfdd5 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 27 Sep 2023 14:58:08 +0700 Subject: [PATCH 161/185] add select option in models --- app/Http/Controllers/ProjectController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index aee3fe3..c872505 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -77,7 +77,7 @@ class ProjectController extends Controller $result = Project::query() ->from('m_proyek AS mp') ->where('mp.id', $id) - ->selectRaw('kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,lokasi_kantor,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status'); + ->selectRaw('value_proyek,scoupe_of_work,kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status'); if (!is_null($result->first()['divisi_id'])) { $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') From b7ffe700b26afe5dd8efc14c8d176c40faac5701 Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 27 Sep 2023 18:01:07 +0700 Subject: [PATCH 162/185] update sementara untuk clockin-out work restricted --- app/Http/Controllers/PresenceController.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 0d79917..cff437f 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -26,11 +26,11 @@ class PresenceController extends Controller $statusBoundary = true; } $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); - if ($statusRestriction->status_boundary) { + if (!$statusRestriction->status_boundary) { $statusBoundary = true; } // not assign - if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false && $statusBoundary == false){ $data=array( 'id' => null, 'boundary' => $statusBoundary @@ -38,7 +38,7 @@ class PresenceController extends Controller return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200); } // assign and not in boundary - if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false && $statusBoundary == false){ $data=array( 'id' => null, 'boundary' => true @@ -65,7 +65,7 @@ class PresenceController extends Controller DB::table('clock_in_out_boundary')->insert([ "clock_in_out_id" => $resultUpdate, "user_id" => $request->user_id, - "activity_id" => $checkLocation[$i]['activity_id'], + "activity_id" => $checkLocation[$i]['activity_id'] ? $checkLocation[$i]['activity_id'] : 0, "type" => $request->type, "created_at" => $date, "created_by" => $this->currentName @@ -86,7 +86,8 @@ class PresenceController extends Controller } $onlyDate = date_format($date,"Y-m-d"); - $clock_in_loc = $this->getLoc($request->clock_in_lat, $request->clock_in_lng)->display_name; + // $clock_in_loc = $this->getLoc($request->clock_in_lat, $request->clock_in_lng)->display_name; + $clock_in_loc = "test"; $dataAdd = array( 'user_id'=> $request->user_id, @@ -139,11 +140,11 @@ class PresenceController extends Controller $statusBoundary = true; } $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); - if ($statusRestriction->status_boundary) { + if (!$statusRestriction->status_boundary) { $statusBoundary = true; } // not assign - if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false && $statusBoundary == false){ $data=array( 'id' => null, 'boundary' => $statusBoundary @@ -151,7 +152,7 @@ class PresenceController extends Controller return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200); } // assign and not in boundary - if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){ + if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false && $statusBoundary == false){ $data=array( 'id' => null, 'boundary' => true @@ -178,7 +179,7 @@ class PresenceController extends Controller DB::table('clock_in_out_boundary')->insert([ "clock_in_out_id" => $resultUpdate, "user_id" => $request->user_id, - "activity_id" => $checkLocation[$i]['activity_id'], + "activity_id" => $checkLocation[$i]['activity_id'] ? $checkLocation[$i]['activity_id'] : 0, "type" => $request->clock_in_out['type'], "created_at" => $date, "created_by" => $this->currentName @@ -232,7 +233,7 @@ class PresenceController extends Controller DB::table('clock_in_out_boundary')->insert([ "clock_in_out_id" => $result->id, "user_id" => $request->user_id, - "activity_id" => $checkLocation[$i]['activity_id'], + "activity_id" => $checkLocation[$i]['activity_id'] ? $checkLocation[$i]['activity_id'] : 0, "type" => $request->type, "created_at" => $date, "created_by" => $this->currentName From 53cb5d59f97b2e61ec64ee59c7e72ff6efcd251d Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 2 Oct 2023 08:34:23 +0700 Subject: [PATCH 163/185] handling string --- app/Http/Controllers/ActivityController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index b8af8d4..b04972d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -428,6 +428,7 @@ class ActivityController extends Controller $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $entity['data']['name'] = $entity['data']['text']; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; + $entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']); if (isset($entity['data']['target'])) { $this->updateOrder($entity['data']['id'], $entity['data']['target']); } From 4f3f4aa71db897e7d6018c14fa2a30a100526058 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 6 Oct 2023 09:33:37 +0700 Subject: [PATCH 164/185] fix sync report --- app/Http/Controllers/ProjectController.php | 44 +++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index aee3fe3..7f5c8f9 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -416,17 +416,21 @@ class ProjectController extends Controller $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); } + $successor = Link::where('t_activity_id', $activity->id)->first(); + if ($successor) { + $predecessor = Activity::find($successor->s_activity_id); + $activity->start_date = $predecessor->end_date; + $end_date = new DateTime($activity->start_date); + $end_date->modify("+" . $activity->duration . " days"); + $activity->end_date = $end_date->format("Y-m-d H:i:sO"); + } + $activity->save(); } /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ for ($i=0; $i < count($reports); $i++) { $activity = Activity::find($reports[$i]['activity_id']); - $successor = Link::where('t_activity_id', $activity->id)->first(); - if ($successor) { - $predecessor = Activity::find($successor->s_activity_id); - $activity->start_date = $predecessor->end_date; - } if($reports[$i]['status'] != 'done'){ $reports[$i]['max_date']->modify('-1 day'); }else if($reports[$i]['status'] == 'done'){ @@ -434,19 +438,25 @@ class ProjectController extends Controller } $activity->start_date = $reports[$i]['min_date']; //same early $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early - $activity->actual_start = $reports[$i]['min_date']; - $activity->save(); - } - - foreach($activities as $activity) { - $successor = Link::where('t_activity_id', $activity->id)->first(); - if ($successor) { - $predecessor = Activity::find($successor->s_activity_id); - $activity->start_date = $predecessor->end_date; - $end_date = new DateTime($activity->start_date); - $end_date->modify("+" . $activity->duration . " days"); - $activity->end_date = $end_date->format("Y-m-d H:i:sO"); + $dayOffs = VersionGantt::where('id', $activity->version_gantt_id)->first()->config_dayoff; + $startDate = new DateTime($activity->start_date); + $endDate = new DateTime($activity->end_date); + $diff = date_diff($startDate, $endDate); + $duration = $diff->days + 1; + $daysRemaining = $duration; + // Loop until the remaining days become zero + while ($daysRemaining > 0) { + $endDate->modify('-1 day'); + // Check if the current day is a day off (Sunday or Saturday) + $currentDayOfWeek = (int) $endDate->format('w'); + if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) { + // continue; // Skip the day off and continue to the next day + $duration--; + } + $daysRemaining--; // Decrease the remaining days by one } + $activity->duration = $duration; + $activity->actual_start = $reports[$i]['min_date']; $activity->save(); } From 3252a98090820c01b7b72d7a9aef669dfdb73b78 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 6 Oct 2023 14:06:25 +0700 Subject: [PATCH 165/185] cek rencana biaya --- app/Http/Controllers/ActivityController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index b04972d..1b43a3e 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -428,7 +428,9 @@ class ActivityController extends Controller $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $entity['data']['name'] = $entity['data']['text']; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; - $entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']); + if (isset($entity['data']['rencana_biaya'])) { + $entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']); + } if (isset($entity['data']['target'])) { $this->updateOrder($entity['data']['id'], $entity['data']['target']); } From 6b74bf5852107092504dddd87b3c67ee6c2cc7fd Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 9 Oct 2023 09:02:52 +0700 Subject: [PATCH 166/185] fix endline --- app/Models/UserToActivity.php | 122 +++++++++++++++++----------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/app/Models/UserToActivity.php b/app/Models/UserToActivity.php index a33667c..76f948a 100644 --- a/app/Models/UserToActivity.php +++ b/app/Models/UserToActivity.php @@ -1,61 +1,61 @@ -activity_id); - $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); - - $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); - - if($getWorkingHours->uom_standart_rate == "Hour") - $salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); - - $activity->rencana_biaya += $salary; - $activity->save(); - }); - - static::deleted(function($data) { - $activity = Activity::find($data->activity_id); - - $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); - $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); - if($getWorkingHours->uom_standart_rate == "Hour"){ - $salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); - } - - $activity->rencana_biaya -= $salary; - if ($activity->rencana_biaya < 0) { - $activity->rencana_biaya = 0; - } - $activity->save(); - }); - - } - -} +activity_id); + $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); + + $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); + + if($getWorkingHours->uom_standart_rate == "Hour") + $salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); + + $activity->rencana_biaya += $salary; + $activity->save(); + }); + + static::deleted(function($data) { + $activity = Activity::find($data->activity_id); + + $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); + $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); + if($getWorkingHours->uom_standart_rate == "Hour"){ + $salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); + } + + $activity->rencana_biaya -= $salary; + if ($activity->rencana_biaya < 0) { + $activity->rencana_biaya = 0; + } + $activity->save(); + }); + + } + +} From 1bb91826ae8976eafb790058690ff5fa418850e3 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 9 Oct 2023 14:30:41 +0700 Subject: [PATCH 167/185] countDays, schedule, hr date --- app/Helpers/MasterFunctionsHelper.php | 20 ++++++++++ app/Http/Controllers/ActivityController.php | 40 +++++++++++++++++-- app/Http/Controllers/ProjectController.php | 16 +------- .../Controllers/UserToActivityController.php | 10 +++-- app/Models/UserToActivity.php | 2 + routes/web.php | 1 + 6 files changed, 67 insertions(+), 22 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 706d734..d681c40 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -36,6 +36,26 @@ class MasterFunctionsHelper return json_decode($output); } + public static function countDays($ganttId, $start, $end){ + $dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff; + $diff = date_diff($start, $end); + $endCount = clone $end; + $duration = $diff->days + 1; + $daysRemaining = $duration; + // Loop until the remaining days become zero + while ($daysRemaining > 0) { + $endCount->modify('-1 day'); + // Check if the current day is a day off (Sunday or Saturday) + $currentDayOfWeek = (int) $endCount->format('w'); + if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) { + // continue; // Skip the day off and continue to the next day + $duration--; + } + $daysRemaining--; // Decrease the remaining days by one + } + return $duration; + } + public function getLatestGantt($id) { $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 1b43a3e..a516e9e 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -1,6 +1,7 @@ json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); } + public function updateSchedule($ganttId){ + if (empty($ganttId) || !is_int((int) $ganttId)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $activities = Activity::where('version_gantt_id', $ganttId)->get(); + if (!$activities) + return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404); + $duration = 0; + foreach ($activities as $key => $activity) { + if (isset($activity->planned_start) && isset($activity->planned_end)) { + $today = new DateTime(); + $endDate = new DateTime($activity->end_date); + $startDate = new DateTime($activity->start_date); + $plannedStart = new DateTime($activity->planned_start); + $plannedEnd = new DateTime($activity->planned_end); + $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); + if ($today >= $endDate) { + $endDate = $today; + $rerataBobot = $activity->bobot_planning / $duration; + $bobotActual = $activity->progress * $activity->bobot_planning; + $sisaBobot = $activity->bobot_planning - $bobotActual; + $sisaHari = $sisaBobot / $rerataBobot; + $endDate->modify("+".$sisaHari." Days"); + $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); + $activity->duration = $actualDuration; + $activity->end_date = $endDate; + $activity->save(); + } + } + } + return response()->json(['status' => 'success', 'message' => 'Activities Updated!', 'code' => 200], 200); + } + public function batchUpdate(Request $request, $ganttId) { $entities = $request->all(); @@ -434,12 +468,12 @@ class ActivityController extends Controller if (isset($entity['data']['target'])) { $this->updateOrder($entity['data']['id'], $entity['data']['target']); } - if(!$activityToUpdate->update($entity['data'])) + if (!$activityToUpdate->update($entity['data'])) return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); $updatedJobsDone = $activityToUpdate->jobs_done; - } else if ($entity['entity'] == "link"){ + } else if ($entity['entity'] == "link") { $linkToUpdate = $link->firstWhere('id', $entity['data']['id']); - if(!$linkToUpdate->update($entity['data'])) + if (!$linkToUpdate->update($entity['data'])) return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500); } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 7f5c8f9..75ecec4 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -438,23 +438,9 @@ class ProjectController extends Controller } $activity->start_date = $reports[$i]['min_date']; //same early $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early - $dayOffs = VersionGantt::where('id', $activity->version_gantt_id)->first()->config_dayoff; $startDate = new DateTime($activity->start_date); $endDate = new DateTime($activity->end_date); - $diff = date_diff($startDate, $endDate); - $duration = $diff->days + 1; - $daysRemaining = $duration; - // Loop until the remaining days become zero - while ($daysRemaining > 0) { - $endDate->modify('-1 day'); - // Check if the current day is a day off (Sunday or Saturday) - $currentDayOfWeek = (int) $endDate->format('w'); - if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) { - // continue; // Skip the day off and continue to the next day - $duration--; - } - $daysRemaining--; // Decrease the remaining days by one - } + $duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate); $activity->duration = $duration; $activity->actual_start = $reports[$i]['min_date']; $activity->save(); diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index c422cf6..2c3a658 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -27,7 +27,7 @@ class UserToActivityController extends Controller public function addMultiple(Request $request){ $users_id = $request->user_id; - $users_role = $request->role_proyek_id; + $users_role = $request->role_proyek_id; // $data = UserToActivity::where("activity_id", $request->activity_id); // if($data){ @@ -42,8 +42,10 @@ class UserToActivityController extends Controller "activity_id" => $request->activity_id, "role_proyek_id" => $users_role[$index], "proyek_id" => $request->proyek_id, - "created_by" => $this->currentName, - "version_gantt_id" => $request->version_gantt_id + "start_date" => $request->start_date, + "end_date" => $request->end_date, + "created_by" => $this->currentName, + "version_gantt_id" => $request->version_gantt_id ); $result = UserToActivity::create($dataInsert); if($result){ @@ -216,7 +218,7 @@ class UserToActivityController extends Controller public function datatables(Request $request){ $id_activity = $request->query('idact'); - $data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name") + $data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name") ->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") ->where('assign_hr_to_activity.activity_id', $id_activity) diff --git a/app/Models/UserToActivity.php b/app/Models/UserToActivity.php index 76f948a..1b795b1 100644 --- a/app/Models/UserToActivity.php +++ b/app/Models/UserToActivity.php @@ -18,6 +18,8 @@ class UserToActivity extends Model 'version_gantt_id', 'role_proyek_id', 'activity_id', + 'start_date', + 'end_date', 'created_at', 'created_by', 'updated_at', diff --git a/routes/web.php b/routes/web.php index bcc0e2b..7f62207 100644 --- a/routes/web.php +++ b/routes/web.php @@ -209,6 +209,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); + $router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule'); $router->post('/task', 'ActivityController@add'); $router->get('/task/edit/{id}', 'ActivityController@edit'); $router->put('/task/{id}', 'ActivityController@update'); From d69de496bdea39a0093529fd5dc4291dce504d9c Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 10 Oct 2023 09:25:24 +0700 Subject: [PATCH 168/185] fix endline --- .../ReportActivityMaterialController.php | 304 +++++++++--------- 1 file changed, 152 insertions(+), 152 deletions(-) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 86cb638..94edcb4 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -1,152 +1,152 @@ -validate($request, [ - 'activity_id' => 'required', - 'qty' => 'required' - ]); - - $activity = Activity::where('id', $request->activity_id)->first(); - - $start_date = $activity->start_date; - $start_date = substr($start_date, 0, 19); // remove the timezone offset - $startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); - $reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date))); - - $data = $request->all(); - $data['created_by'] = $this->currentName; - /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ - $data['assign_material_id'] = $request->assign_material_id; - $data['qty'] = $this->sanitizeDecimal($data['qty']); - if($reportDate >= $startDate){ - $created = ReportActivityMaterial::create($data); - return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); - } else { - return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); - } - } - - public function updateStatusStartFinish(Request $request){ - - $payloadUpdate = array( - 'start_activity' => $request->start_activity, - 'finish_activity' => $request->finish_activity, - 'status_activity' => $request->status_activity - ); - $updateData = AssignMaterial::where('activity_id',$request->activity_id) - ->update($payloadUpdate); - if($updateData){ - if($request->status_activity == 'done'){ - $dataUpdate = array( - "persentase_progress" => 100, - "updated_by" => $this->currentName - ); - Activity::where('id', $request->activity_id)->update($dataUpdate); - } else { - $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); - $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); - $dataUpdate = array( - "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, - "updated_by" => $this->currentName - ); - Activity::where('id', $request->activity_id)->update($dataUpdate); - } - - return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]); - } - else{ - return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]); - } - } - - public function delete($id) - { - if(!ReportActivityMaterial::findOrFail($id)->delete()) - return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'report_activity_material'); - $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 list() - { - $data = ReportActivityMaterial::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400); - } - } - - public function datatables(Request $request){ - $id_activity = $request->query('idAct'); - $type = $request->query('type'); - $materialName = $request->query('materialName'); - if($type == 'plan'){ - $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") - ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->where('assign_material_to_activity.activity_id', $id_activity) - ->where('m.description', $materialName) - ->orderBy('assign_material_to_activity.id', 'asc') - ->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('action', function($row){ - $actionBtn = ''; - if ($row->status_activity != 'done') { - $actionBtn .= ''; - } - return $actionBtn; - }) - ->rawColumns(['action'])->make(true); - }else{ - $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") - ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") - ->join("m_req_material as m", "m.id", "=", "amta.material_id") - ->join("m_users as u", "u.id", "=", "report_activity_material.user_id") - ->where('report_activity_material.activity_id', $id_activity) - ->where('m.description', $materialName) - ->orderBy('report_activity_material.report_date', 'asc') - ->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('action', function($row){ - $actionBtn = ''; - if ($row->status_activity != 'done') { - $actionBtn .= ''; - } - return $actionBtn; - }) - ->rawColumns(['action'])->make(true); - } - } -} +validate($request, [ + 'activity_id' => 'required', + 'qty' => 'required' + ]); + + $activity = Activity::where('id', $request->activity_id)->first(); + + $start_date = $activity->start_date; + $start_date = substr($start_date, 0, 19); // remove the timezone offset + $startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); + $reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date))); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ + $data['assign_material_id'] = $request->assign_material_id; + $data['qty'] = $this->sanitizeDecimal($data['qty']); + if($reportDate >= $startDate){ + $created = ReportActivityMaterial::create($data); + return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); + } else { + return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); + } + } + + public function updateStatusStartFinish(Request $request){ + + $payloadUpdate = array( + 'start_activity' => $request->start_activity, + 'finish_activity' => $request->finish_activity, + 'status_activity' => $request->status_activity + ); + $updateData = AssignMaterial::where('activity_id',$request->activity_id) + ->update($payloadUpdate); + if($updateData){ + if($request->status_activity == 'done'){ + $dataUpdate = array( + "persentase_progress" => 100, + "updated_by" => $this->currentName + ); + Activity::where('id', $request->activity_id)->update($dataUpdate); + } else { + $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); + $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); + $dataUpdate = array( + "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, + "updated_by" => $this->currentName + ); + Activity::where('id', $request->activity_id)->update($dataUpdate); + } + + return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]); + } + else{ + return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]); + } + } + + public function delete($id) + { + if(!ReportActivityMaterial::findOrFail($id)->delete()) + return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'report_activity_material'); + $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 list() + { + $data = ReportActivityMaterial::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400); + } + } + + public function datatables(Request $request){ + $id_activity = $request->query('idAct'); + $type = $request->query('type'); + $materialName = $request->query('materialName'); + if($type == 'plan'){ + $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('assign_material_to_activity.activity_id', $id_activity) + ->where('m.description', $materialName) + ->orderBy('assign_material_to_activity.id', 'asc') + ->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('action', function($row){ + $actionBtn = ''; + if ($row->status_activity != 'done') { + $actionBtn .= ''; + } + return $actionBtn; + }) + ->rawColumns(['action'])->make(true); + }else{ + $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") + ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") + ->join("m_req_material as m", "m.id", "=", "amta.material_id") + ->join("m_users as u", "u.id", "=", "report_activity_material.user_id") + ->where('report_activity_material.activity_id', $id_activity) + ->where('m.description', $materialName) + ->orderBy('report_activity_material.report_date', 'asc') + ->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('action', function($row){ + $actionBtn = ''; + if ($row->status_activity != 'done') { + $actionBtn .= ''; + } + return $actionBtn; + }) + ->rawColumns(['action'])->make(true); + } + } +} From c49cbe48c8a0ead73044fa811b40af5ef206684f Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 10 Oct 2023 11:08:31 +0700 Subject: [PATCH 169/185] forcing report date --- app/Http/Controllers/ReportActivityMaterialController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 94edcb4..eae0d86 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -35,11 +35,11 @@ class ReportActivityMaterialController extends Controller /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ $data['assign_material_id'] = $request->assign_material_id; $data['qty'] = $this->sanitizeDecimal($data['qty']); - if($reportDate >= $startDate){ + if($reportDate >= $startDate || isset($data['force']) && $data['force'] == "true"){ $created = ReportActivityMaterial::create($data); return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); } else { - return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); + return response()->json(['status'=>'failed','message'=>'Report date is before early start, still wanna add data ?','code'=>400,'data'=>$data], 400); } } From e4b46f6d701a6ee141c0e8c2ed401afc63fa4193 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 10 Oct 2023 13:13:42 +0700 Subject: [PATCH 170/185] handle zero division --- app/Http/Controllers/ActivityController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index a516e9e..50ba368 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -431,10 +431,10 @@ class ActivityController extends Controller $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); if ($today >= $endDate) { $endDate = $today; - $rerataBobot = $activity->bobot_planning / $duration; + $rerataBobot = $duration > 0 ? $activity->bobot_planning / $duration : 0; $bobotActual = $activity->progress * $activity->bobot_planning; $sisaBobot = $activity->bobot_planning - $bobotActual; - $sisaHari = $sisaBobot / $rerataBobot; + $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0; $endDate->modify("+".$sisaHari." Days"); $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); $activity->duration = $actualDuration; From 387c9149fd9c902fa9b90b35d3e6e9ed173d879e Mon Sep 17 00:00:00 2001 From: wahyuun Date: Tue, 10 Oct 2023 13:30:17 +0700 Subject: [PATCH 171/185] fix bug addMultiple Customer --- app/Http/Controllers/UserToProyekController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserToProyekController.php b/app/Http/Controllers/UserToProyekController.php index a7a1cac..f6fca59 100644 --- a/app/Http/Controllers/UserToProyekController.php +++ b/app/Http/Controllers/UserToProyekController.php @@ -33,7 +33,10 @@ class UserToProyekController extends Controller public function addMultiple(Request $request){ $user_IDs = $request->user_id; - $data = UserToProyek::where("proyek_id", $request->proyek_id); + $data = UserToProyek::where([ + ["proyek_id" , $request->proyek_id], + ['is_customer',true] + ]); if($data){ $data->delete(); From 1fbb8ea2b014fef2565f2755246f9466c9e9290c Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 10 Oct 2023 15:41:39 +0700 Subject: [PATCH 172/185] fix update schedule --- app/Http/Controllers/ActivityController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 50ba368..e36ec6c 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -431,11 +431,12 @@ class ActivityController extends Controller $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); if ($today >= $endDate) { $endDate = $today; - $rerataBobot = $duration > 0 ? $activity->bobot_planning / $duration : 0; - $bobotActual = $activity->progress * $activity->bobot_planning; - $sisaBobot = $activity->bobot_planning - $bobotActual; + $bobotPlanning = (int) $activity->bobot_planning; + $rerataBobot = $duration > 0 ? $bobotPlanning / $duration : 0; + $bobotActual = (int) $activity->persentase_progress/100 * $bobotPlanning; + $sisaBobot = $bobotPlanning - $bobotActual; $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0; - $endDate->modify("+".$sisaHari." Days"); + $endDate->modify("+".ceil($sisaHari)." Days"); $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); $activity->duration = $actualDuration; $activity->end_date = $endDate; From d98dec9c49171f0b2332386552b9d5f09292a5c4 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 11 Oct 2023 13:43:39 +0700 Subject: [PATCH 173/185] fix actual date, check status update schedule --- app/Http/Controllers/ActivityController.php | 10 +++++++++- .../Controllers/ReportActivityMaterialController.php | 2 ++ app/Models/ReportActivityMaterial.php | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index e36ec6c..dce8f9e 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Helpers\MasterFunctionsHelper; use App\Models\Activity; +use App\Models\AssignMaterial; use App\Models\CommentActivity; use App\Models\Link; use App\Models\Project; @@ -422,7 +423,14 @@ class ActivityController extends Controller return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404); $duration = 0; foreach ($activities as $key => $activity) { - if (isset($activity->planned_start) && isset($activity->planned_end)) { + $assignMaterial = AssignMaterial::where('activity_id', $activity->id)->first(); + if (isset($assignMaterial)) { + $statusActivity = $assignMaterial->status_activity; + } else { + $statusActivity = ''; + } + if (isset($activity->planned_start) && isset($activity->planned_end) && $statusActivity != "done") { + // todo check report for no report / progress == 0 $today = new DateTime(); $endDate = new DateTime($activity->end_date); $startDate = new DateTime($activity->start_date); diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index eae0d86..0ec323c 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -63,6 +63,8 @@ class ReportActivityMaterialController extends Controller $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); $dataUpdate = array( + "actual_start" => null, + "actual_end" => null, "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, "updated_by" => $this->currentName ); diff --git a/app/Models/ReportActivityMaterial.php b/app/Models/ReportActivityMaterial.php index 39849d5..df0bb0b 100644 --- a/app/Models/ReportActivityMaterial.php +++ b/app/Models/ReportActivityMaterial.php @@ -59,6 +59,8 @@ class ReportActivityMaterial extends Model $assignedMaterial = AssignMaterial::find($data->assign_material_id); $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); + $activity->actual_start = null; + $activity->actual_end = null; $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); $totalPlan = $dataPlan->sum('qty_planning'); From 02200c0ada57eda3d0d96fbfaa35669a9c8728c6 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 12 Oct 2023 08:05:08 +0700 Subject: [PATCH 174/185] fix endline --- .../Controllers/VersionGanttController.php | 240 +++++++++--------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index 97b5857..c3fe398 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -1,120 +1,120 @@ -validate($request, [ - 'name_version' => 'required', - 'proyek_id' => 'required' - ]); - $data = $request->all(); - $data['created_by'] = $this->currentName; - - $result = VersionGantt::create($data); - if($result){ - return response()->json(['status'=>'success','message'=>'version gantt Project successfull created','code'=>200]); - }else{ - return response()->json(['status'=>'failed','message'=>'version gantt Project failed created','code'=>400]); - } - } - - public function update(Request $request, $id){ - - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - $data = VersionGantt::find($id); - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400); - die(); - } - - if($result){ - return response()->json(['status'=>'success','message'=>'version gantt Project successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'version gantt Project failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = VersionGantt::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'version gantt Project successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'version gantt Project failed deleted!','code'=>400], 400); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = VersionGantt::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data version gantt, please try again later!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_version_gantt'); - $builder = $dataBuilder['builder']; - // $countBuilder = $dataBuilder['count']; - $this->ganttProgress($request->columns[0]["name"], $request->columns[0]["value"]); - $dataGet = $builder->get(); - - // $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet], 200); - } - - public function ganttProgress($column, $value){ - $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning') - ->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id') - ->where("m_version_gantt.".$column, $value) - // ->where('m_activity.type_activity', "project") - ->where('m_activity.parent_id', null) - ->get(); - foreach($progress as $item) { - if($item->persentase_progress){ - $item->progress = $item->persentase_progress; - $item->bobot = $item->bobot_planning; - $item->save(); - } - } - } - - public function list() - { - $data = VersionGantt::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list version gantt, please try again later!','code'=>400], 400); - } - } -} +validate($request, [ + 'name_version' => 'required', + 'proyek_id' => 'required' + ]); + $data = $request->all(); + $data['created_by'] = $this->currentName; + + $result = VersionGantt::create($data); + if($result){ + return response()->json(['status'=>'success','message'=>'version gantt Project successfull created','code'=>200]); + }else{ + return response()->json(['status'=>'failed','message'=>'version gantt Project failed created','code'=>400]); + } + } + + public function update(Request $request, $id){ + + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + $data = VersionGantt::find($id); + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400); + die(); + } + + if($result){ + return response()->json(['status'=>'success','message'=>'version gantt Project successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'version gantt Project failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = VersionGantt::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'version gantt Project successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'version gantt Project failed deleted!','code'=>400], 400); + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = VersionGantt::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data version gantt, please try again later!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_version_gantt'); + $builder = $dataBuilder['builder']; + // $countBuilder = $dataBuilder['count']; + $this->ganttProgress($request->columns[0]["name"], $request->columns[0]["value"]); + $dataGet = $builder->get(); + + // $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet], 200); + } + + public function ganttProgress($column, $value){ + $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning') + ->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id') + ->where("m_version_gantt.".$column, $value) + // ->where('m_activity.type_activity', "project") + ->where('m_activity.parent_id', null) + ->get(); + foreach($progress as $item) { + if($item->persentase_progress){ + $item->progress = $item->persentase_progress; + $item->bobot = $item->bobot_planning; + $item->save(); + } + } + } + + public function list() + { + $data = VersionGantt::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list version gantt, please try again later!','code'=>400], 400); + } + } +} From 88151c2f49f8be05c37825d4399f75579de9aa37 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 12 Oct 2023 09:27:10 +0700 Subject: [PATCH 175/185] prorate total cost for gantt --- app/Http/Controllers/ProjectController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 75ecec4..f5b921b 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -466,12 +466,16 @@ class ProjectController extends Controller } public function getInvoiceIntegration(Request $request) { + $ganttCount = VersionGantt::where('proyek_id', $request->id)->count(); $search = urlencode($request->search); if(empty($search)) return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); $response = MasterFunctionsHelper::curlReq($url); + if (isset($request->gantt_id)) { + $response->data->total_cost = $response->data->total_cost / $ganttCount; + } return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); } From 4c5af70ca4cdf1b233ad8bebeca8a29af5082213 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 12 Oct 2023 14:33:49 +0700 Subject: [PATCH 176/185] divide qty planning --- .../ReportActivityMaterialController.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 0ec323c..d84c4fa 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -2,11 +2,13 @@ namespace App\Http\Controllers; +use App\Helpers\MasterFunctionsHelper; use Illuminate\Http\Request; use App\Models\ReportActivityMaterial; use App\Models\Activity; use App\Models\AssignMaterial; use Datatables; +use DateTime; class ReportActivityMaterialController extends Controller { @@ -114,12 +116,22 @@ class ReportActivityMaterialController extends Controller $type = $request->query('type'); $materialName = $request->query('materialName'); if($type == 'plan'){ + $activity = Activity::findOrFail($id_activity); + $baselineDuration = 0; + if (isset($activity->planned_start) && isset($activity->planned_end)) { + $baselineDuration = MasterFunctionsHelper::countDays($activity->version_gantt_id, new DateTime($activity->planned_start), new DateTime($activity->planned_end)); + } $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->where('assign_material_to_activity.activity_id', $id_activity) ->where('m.description', $materialName) ->orderBy('assign_material_to_activity.id', 'asc') ->get(); + if ($baselineDuration > 0) { + foreach ($data as $key => $value) { + $data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1); + } + } return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){ @@ -131,7 +143,12 @@ class ReportActivityMaterialController extends Controller }) ->rawColumns(['action'])->make(true); }else{ - $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") + $activity = Activity::findOrFail($id_activity); + $baselineDuration = 0; + if (isset($activity->planned_start) && isset($activity->planned_end)) { + $baselineDuration = MasterFunctionsHelper::countDays($activity->version_gantt_id, new DateTime($activity->planned_start), new DateTime($activity->planned_end)); + } + $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity", "amta.qty_planning") ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") ->join("m_req_material as m", "m.id", "=", "amta.material_id") ->join("m_users as u", "u.id", "=", "report_activity_material.user_id") @@ -139,6 +156,11 @@ class ReportActivityMaterialController extends Controller ->where('m.description', $materialName) ->orderBy('report_activity_material.report_date', 'asc') ->get(); + if ($baselineDuration > 0) { + foreach ($data as $key => $value) { + $data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1); + } + } return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){ From e6d244bd4cc40681a4483db4432da8dc73af8cce Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 13 Oct 2023 10:10:32 +0700 Subject: [PATCH 177/185] parent actual date only if all children have it --- app/Http/Controllers/ActivityController.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index dce8f9e..5655cdb 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -186,14 +186,12 @@ class ActivityController extends Controller $actualStartValues = array_column(array_filter($dataFinal, function($item) { return isset($item['actual_start']); }), 'actual_start'); - - $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; + $returnActualStartOrEnd = count($actualStartValues) == count($dataFinal) ? min($actualStartValues) : null; }else{ $actualEndValues = array_column(array_filter($dataFinal, function($item) { return isset($item['actual_end']); }), 'actual_end'); - - $returnActualStartOrEnd = count($actualEndValues) > 0 ? max($actualEndValues) : null; + $returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null; } // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); From 0ae702ebe5baa2285b68a0f48753d3b5a15cee96 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 13 Oct 2023 14:44:28 +0700 Subject: [PATCH 178/185] fix update status --- .../Controllers/ReportActivityMaterialController.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index d84c4fa..e451129 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -70,6 +70,17 @@ class ReportActivityMaterialController extends Controller "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, "updated_by" => $this->currentName ); + if ($sumReportActivityMaterial > 0) { + $data = []; + $reportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->get(); + foreach ($reportActivityMaterial as $value) { + $data[] = $value; + } + $actualStartValues = array_column(array_filter($data, function($item) { + return isset($item['report_date']); + }), 'report_date'); + $dataUpdate["actual_start"] = min($actualStartValues); + } Activity::where('id', $request->activity_id)->update($dataUpdate); } From 6996f1fff378e55d760022e46b7dbab39719670f Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 16 Oct 2023 10:58:26 +0700 Subject: [PATCH 179/185] add color column in select query --- app/Http/Controllers/DivisiController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index e398682..2d056aa 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -21,7 +21,8 @@ class DivisiController extends Controller $this->validate($request, [ 'name' => 'string|required|unique:m_divisi,name', 'description' => 'nullable|string', - 'parent' => 'nullable|integer' + 'parent' => 'nullable|integer', + 'color'=>'nullable|string|max:10' ]); $data = $request->all(); From 1a5de7253c62540033d54c8fd01185a2ddeb602a Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 16 Oct 2023 10:58:42 +0700 Subject: [PATCH 180/185] add color column --- app/Models/Divisi.php | 83 ++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/app/Models/Divisi.php b/app/Models/Divisi.php index 5a37c85..ac255f4 100644 --- a/app/Models/Divisi.php +++ b/app/Models/Divisi.php @@ -1,41 +1,42 @@ -children()->delete(); - }); - } - - public function parent() - { - return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); - } - - public function children() - { - return $this->hasMany('App\Models\Divisi','parent')->with('children'); - } -} +children()->delete(); + }); + } + + public function parent() + { + return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); + } + + public function children() + { + return $this->hasMany('App\Models\Divisi','parent')->with('children'); + } +} From b2581a980b46273d3a012bf0d4d9dd206bf9a25f Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 16 Oct 2023 12:14:07 +0700 Subject: [PATCH 181/185] update dashboard --- app/Http/Controllers/DashboardBoDController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index fe2456b..143af38 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -271,7 +271,7 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name','parent') + $divisions = Divisi::select('id', 'name','parent','color') ->with('children') ->whereNull('parent') ->get(); From 7233afaa697c62346e4db2b453f1e6830d844a28 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 16 Oct 2023 13:31:52 +0700 Subject: [PATCH 182/185] fix endline --- app/Models/Role.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/Models/Role.php b/app/Models/Role.php index 3c0f409..0363567 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -1,17 +1,17 @@ - Date: Mon, 16 Oct 2023 13:56:22 +0700 Subject: [PATCH 183/185] update recursive --- app/Http/Controllers/ActivityController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 5655cdb..acd94b0 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -175,6 +175,7 @@ class ActivityController extends Controller }else{ $data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get(); } + $parent = Activity::findOrFail($id); $dataFinal=[]; foreach ($data as $val) { $activity = $this->getchildActivityForActual($val->id, $params); @@ -187,11 +188,19 @@ class ActivityController extends Controller return isset($item['actual_start']); }), 'actual_start'); $returnActualStartOrEnd = count($actualStartValues) == count($dataFinal) ? min($actualStartValues) : null; + if (isset($parent)) { + $parent->actual_start = $returnActualStartOrEnd; + $parent->save(); + } }else{ $actualEndValues = array_column(array_filter($dataFinal, function($item) { return isset($item['actual_end']); }), 'actual_end'); $returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null; + if (isset($parent)) { + $parent->actual_end = $returnActualStartOrEnd; + $parent->save(); + } } // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); From 3270b42a7778cca697aebd2c1b2307c93298835d Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 16 Oct 2023 16:27:21 +0700 Subject: [PATCH 184/185] default page --- app/Http/Controllers/RoleController.php | 3 +++ app/Models/Role.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index 4a29066..57b8c58 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -18,6 +18,9 @@ class RoleController extends Controller $data = $request->all(); $data['created_by'] = $this->currentName; + if (!isset($data['default_page'])) { + $data['default_page'] = 29; // dashboard + } $result = Role::create($data); diff --git a/app/Models/Role.php b/app/Models/Role.php index 0363567..73de4a2 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -12,6 +12,6 @@ class Role extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by' ]; } From 0c2eea2395f632b543a27599fac1e1d5bd8c709d Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 17 Oct 2023 11:11:08 +0700 Subject: [PATCH 185/185] division zero handle --- app/Helpers/MasterFunctionsHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index d681c40..ae74952 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -687,7 +687,7 @@ class MasterFunctionsHelper // } - $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; + $totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); }