From b284e235d4bf063a6f1e87793d69969bed5c82cb Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 3 Apr 2023 13:06:49 +0700 Subject: [PATCH 001/252] Task #860q7btm6 cek username --- app/Http/Controllers/HumanResourceController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 2d372ff..0defd38 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -60,6 +60,10 @@ class HumanResourceController extends Controller 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); From a505b92e1eac9dbf222cd304bef799543fcc9857 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 3 Apr 2023 14:51:28 +0700 Subject: [PATCH 002/252] Task #860q2d6rx fix bug --- app/Http/Controllers/ProjectController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 37a2da7..4689c04 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -231,7 +231,7 @@ class ProjectController extends Controller $scheduleHealth = "on-track"; $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); if($rootActivity){ - $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; + $costVariance = (int)$d->rencana_biaya - (int)$rootActivity->biaya_actual; $actualCost = $rootActivity->biaya_actual ?? 0; $progress = $rootActivity->persentase_progress ?? 0; @@ -271,7 +271,7 @@ class ProjectController extends Controller } } - $totalPlannedCost = $data->sum('plannedCost'); + $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(); From 2727c52a42d9d6abf0c5c65302b8954efae1e08c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 4 Apr 2023 11:01:37 +0700 Subject: [PATCH 003/252] Task #860q2vhvg add sync HR --- app/Http/Controllers/HumanResourceController.php | 5 +++++ routes/web.php | 1 + 2 files changed, 6 insertions(+) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 0defd38..8e23f87 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Models\HumanResource; use App\Models\UserToActivity; use App\Models\UserToProyek; +use Illuminate\Support\Facades\Artisan; class HumanResourceController extends Controller { @@ -170,4 +171,8 @@ class HumanResourceController extends Controller return response()->json(['status'=>'failed','message'=>'old_password is required!','code'=>400], 400); } } + + public function sync(){ + Artisan::call('sync:integration-human-resources'); + } } diff --git a/routes/web.php b/routes/web.php index b403f54..c3f9058 100644 --- a/routes/web.php +++ b/routes/web.php @@ -108,6 +108,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $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'); From 8c78ab69d0a44cf51dea732ce7db84e643017871 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Tue, 4 Apr 2023 14:06:34 +0700 Subject: [PATCH 004/252] add gant to tree --- app/Http/Controllers/HierarchyFtthController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 1184109..2953325 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\HierarchyFtth; +use App\Models\VersionGantt; class HierarchyFtthController extends Controller { @@ -115,7 +116,12 @@ class HierarchyFtthController extends Controller { $finalData = []; $data = HierarchyFtth::where('project_id', $project_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); + foreach($data as $objRow){ + if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) { + $dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get(); + $objRow->dataGantt = $dataGantt; + } $objRow->key = rand(1, 1000); $objRow->children = $this->getChildren($project_id, $objRow->id); $finalData[] = $objRow; From 3d20bdf719eaf262a4f2fd91b98747d5d7c3de65 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 5 Apr 2023 11:55:40 +0700 Subject: [PATCH 005/252] Add key to datagantt --- app/Http/Controllers/HierarchyFtthController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 2953325..b29d298 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -118,11 +118,14 @@ class HierarchyFtthController extends Controller $data = HierarchyFtth::where('project_id', $project_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); foreach($data as $objRow){ + $objRow->key = rand(1, 1000); if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) { $dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get(); + foreach ($dataGantt as $gantt) { + $gantt->key = $objRow->key; + } $objRow->dataGantt = $dataGantt; } - $objRow->key = rand(1, 1000); $objRow->children = $this->getChildren($project_id, $objRow->id); $finalData[] = $objRow; } From 1ec6a69b9dc074d4c17b7a24ba27bb59e9e9f448 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 5 Apr 2023 15:54:12 +0700 Subject: [PATCH 006/252] Fix project activity type --- 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 02bfea2..ab5c490 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -132,7 +132,7 @@ class ActivityController extends Controller 'start_date'=> $project->mulai_proyek, 'end_date'=> $project->akhir_proyek, 'rencana_biaya'=> $project->rencana_biaya, - 'type_activity'=> 'header', + 'type_activity'=> 'project', 'created_by'=>$this->currentName, ]); From ce78de95a9a65f2833e1316b32a689ba765a1849 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Thu, 6 Apr 2023 09:26:31 +0700 Subject: [PATCH 007/252] code status --- app/Http/Controllers/HierarchyFtthController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index b29d298..a18c33f 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -41,7 +41,7 @@ class HierarchyFtthController extends Controller return response()->json([ 'message' => 'Hierarchy FTTH created successfully.', 'data' => $hierarchyFtth - ]); + ],200); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to create hierarchy FTTH.', @@ -72,7 +72,7 @@ class HierarchyFtthController extends Controller return response()->json([ 'message' => 'Hierarchy FTTH updated successfully.', 'data' => $hierarchyFtth - ]); + ],200); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to update hierarchy FTTH.', @@ -90,7 +90,7 @@ class HierarchyFtthController extends Controller return response()->json([ 'message' => 'Hierarchy FTTH deleted successfully.', 'data' => $hierarchyFtth - ]); + ],200); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to delete hierarchy FTTH.', From 046fe977194f92b949d46aff5187d7fceb066ad5 Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 6 Apr 2023 09:26:53 +0700 Subject: [PATCH 008/252] update versiont gantt --- app/Models/VersionGantt.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 12a765d..72c6185 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -21,6 +21,8 @@ class VersionGantt extends Model 'calculation_type', 'committed_cost', 'cost_to_complete', + 'progress', + 'hierarchy_ftth_id', 'created_at', 'created_by', 'updated_at', From 541ea823fa6054e48dd2995500e6f6871ee7249c Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 6 Apr 2023 09:46:05 +0700 Subject: [PATCH 009/252] update code success when store data --- app/Http/Controllers/HierarchyFtthController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index a18c33f..5790514 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -39,6 +39,8 @@ class HierarchyFtthController extends Controller $hierarchyFtth = HierarchyFtth::create($attributes); return response()->json([ + 'status'=>'success', + 'code' => 200, 'message' => 'Hierarchy FTTH created successfully.', 'data' => $hierarchyFtth ],200); From ba36843f287db655a4a081481468c85b7be2f59b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 10 Apr 2023 16:26:54 +0700 Subject: [PATCH 010/252] Task #860qeym7p --- .../Controllers/VersionGanttController.php | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index dbd7a6a..8f915d3 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -82,10 +82,35 @@ class VersionGanttController extends Controller $payload = $request->all(); $dataBuilder = $this->setUpPayload($payload, 'm_version_gantt'); $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; + // $countBuilder = $dataBuilder['count']; + $progress = $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, 'totalRecord'=>$totalRecord], 200); + // Loop through $dataGet collection + foreach ($dataGet as $item) { + // Loop through $progress collection + foreach ($progress as $progressItem) { + // Check if both have the same id + if ($item->id == $progressItem->id) { + // Set the progress of $item to the corresponding progress of $progressItem + dd($progressItem); + $item->progress = $progressItem->persentase_progress; + break; + } + } + } + // $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.progress') + ->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(); + + return $progress; } public function list() From a3833495ab7ee7c6a9396d479cbb1061b5923185 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 11 Apr 2023 01:13:01 +0700 Subject: [PATCH 011/252] Fix Task #860qeym7p --- .../Controllers/HierarchyFtthController.php | 17 +++++++++++++++++ app/Http/Controllers/VersionGanttController.php | 3 +-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 5790514..70c56fb 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -123,8 +123,14 @@ class HierarchyFtthController extends Controller $objRow->key = rand(1, 1000); if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) { $dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get(); + $progress = $this->ganttProgress('hierarchy_ftth_id', $objRow->id); foreach ($dataGantt as $gantt) { $gantt->key = $objRow->key; + foreach ($progress as $p) { + if ($p->id == $gantt->id) { + $gantt->progress = $p->persentase_progress; + } + } } $objRow->dataGantt = $dataGantt; } @@ -132,5 +138,16 @@ class HierarchyFtthController extends Controller $finalData[] = $objRow; } return $finalData; + } + + public function ganttProgress($column, $value){ + $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress') + ->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(); + + return $progress; } } diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index 8f915d3..c7b9f65 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -92,7 +92,6 @@ class VersionGanttController extends Controller // Check if both have the same id if ($item->id == $progressItem->id) { // Set the progress of $item to the corresponding progress of $progressItem - dd($progressItem); $item->progress = $progressItem->persentase_progress; break; } @@ -103,7 +102,7 @@ class VersionGanttController extends Controller } public function ganttProgress($column, $value){ - $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.progress') + $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress') ->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id') ->where("m_version_gantt.".$column, $value) ->where('m_activity.type_activity', "project") From 6d421ce34774fb6a0e57485d6e504a47f7f67e84 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 11 Apr 2023 15:44:17 +0700 Subject: [PATCH 012/252] Task #860qeyjyk calculate progress --- .../Controllers/HierarchyFtthController.php | 34 +++++++++++++++++++ .../Controllers/VersionGanttController.php | 23 +++++-------- app/Models/HierarchyFtth.php | 2 +- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 70c56fb..1a3ca56 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -100,9 +100,43 @@ class HierarchyFtthController extends Controller ], 500); } } + + public function countProgress($project_id) { + $ftthIds = VersionGantt::select('hierarchy_ftth_id') + ->where('proyek_id', $project_id) + ->groupBy('hierarchy_ftth_id') + ->get(); + + foreach ($ftthIds as $ftthId) { + $gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress'); + $ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); + + $ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); + $round = $gantts/$ganttCount; + $ftth->progress = round($round, 2); + $ftth->save(); + + if($ftth->parent_id){ + $this->countParent($ftth); + } + } + } + + public function countParent($ftth){ + $parent = HierarchyFtth::find($ftth->parent_id); + $children = HierarchyFtth::where('parent_id', $ftth->parent_id)->sum('progress'); + $childrenCount = HierarchyFtth::where('parent_id', $ftth->parent_id)->count(); + $round = $children/$childrenCount; + $parent->progress = round($round, 2); + $parent->save(); + if($parent->parent_id) { + $this->countParent($parent); + } + } public function getTreeByProject($project_id) { + $this->countProgress(intval($project_id)); $data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); $finalData = []; foreach($data as $objRow){ diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index c7b9f65..4dc9450 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -83,20 +83,9 @@ class VersionGanttController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_version_gantt'); $builder = $dataBuilder['builder']; // $countBuilder = $dataBuilder['count']; - $progress = $this->ganttProgress($request->columns[0]["name"], $request->columns[0]["value"]); + $this->ganttProgress($request->columns[0]["name"], $request->columns[0]["value"]); $dataGet = $builder->get(); - // Loop through $dataGet collection - foreach ($dataGet as $item) { - // Loop through $progress collection - foreach ($progress as $progressItem) { - // Check if both have the same id - if ($item->id == $progressItem->id) { - // Set the progress of $item to the corresponding progress of $progressItem - $item->progress = $progressItem->persentase_progress; - break; - } - } - } + // $totalRecord = $countBuilder->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet], 200); } @@ -108,8 +97,12 @@ class VersionGanttController extends Controller ->where('m_activity.type_activity', "project") ->where('m_activity.parent_id', null) ->get(); - - return $progress; + foreach($progress as $item) { + if($item->persentase_progress){ + $item->progress = $item->persentase_progress; + $item->save(); + } + } } public function list() diff --git a/app/Models/HierarchyFtth.php b/app/Models/HierarchyFtth.php index 649f1e5..9a94bfc 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' + 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress' ]; } From caa4eb549067babe15a8528eed3f805e8b5ee53d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 12 Apr 2023 13:08:41 +0700 Subject: [PATCH 013/252] Task #860q2vq5a use old import --- routes/web.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/web.php b/routes/web.php index c3f9058..eb8fe09 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-old', 'ActivityController@importOld'); $router->post('/task', 'ActivityController@add'); $router->get('/task/edit/{id}', 'ActivityController@edit'); $router->put('/task/{id}', 'ActivityController@update'); From 91c2bf6bfa84b63f88b09df774812fe61145833b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 12 Apr 2023 14:16:28 +0700 Subject: [PATCH 014/252] Hotfix hirarki ftth --- app/Http/Controllers/HierarchyFtthController.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 1a3ca56..03b42e6 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -140,8 +140,21 @@ class HierarchyFtthController extends Controller $data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); $finalData = []; foreach($data as $objRow){ - $objRow->children = $this->getChildren($project_id, $objRow->id); $objRow->key = rand(1, 1000); + if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) { + $dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get(); + $progress = $this->ganttProgress('hierarchy_ftth_id', $objRow->id); + foreach ($dataGantt as $gantt) { + $gantt->key = $objRow->key; + foreach ($progress as $p) { + if ($p->id == $gantt->id) { + $gantt->progress = $p->persentase_progress; + } + } + } + $objRow->dataGantt = $dataGantt; + } + $objRow->children = $this->getChildren($project_id, $objRow->id); $finalData[] = $objRow; } From 23252645c15d1ae7ee9a01785695601cb04a4157 Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 12 Apr 2023 15:10:42 +0700 Subject: [PATCH 015/252] update logic progress gantt --- app/Http/Controllers/VersionGanttController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index 4dc9450..b66dc3f 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -94,7 +94,7 @@ class VersionGanttController extends Controller $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress') ->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.type_activity', "project") ->where('m_activity.parent_id', null) ->get(); foreach($progress as $item) { From c64c329ae3a5a4043920acad4e4bc49241406ab0 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 17 Apr 2023 05:11:43 +0700 Subject: [PATCH 016/252] Fix user to activity & ftth count progress --- .../Controllers/HierarchyFtthController.php | 48 ++++++++++++------- .../Controllers/UserToActivityController.php | 8 ++-- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 03b42e6..388bb2a 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\HierarchyFtth; use App\Models\VersionGantt; +use Illuminate\Support\Facades\Log; class HierarchyFtthController extends Controller { @@ -106,18 +107,26 @@ class HierarchyFtthController extends Controller ->where('proyek_id', $project_id) ->groupBy('hierarchy_ftth_id') ->get(); + if($ftthIds){ + foreach ($ftthIds as $ftthId) { + $gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress'); + $ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); + + $ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); + if($ftth){ + $round = $gantts/$ganttCount; + $ftth->progress = round($round, 2); + try { + $ftth->save(); + } catch (\Exception $e) { + // Log the error or handle it in some other way + Log::error($e->getMessage()); + } - foreach ($ftthIds as $ftthId) { - $gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress'); - $ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); - - $ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); - $round = $gantts/$ganttCount; - $ftth->progress = round($round, 2); - $ftth->save(); - - if($ftth->parent_id){ - $this->countParent($ftth); + if($ftth->parent_id){ + $this->countParent($ftth); + } + } } } } @@ -126,11 +135,18 @@ class HierarchyFtthController extends Controller $parent = HierarchyFtth::find($ftth->parent_id); $children = HierarchyFtth::where('parent_id', $ftth->parent_id)->sum('progress'); $childrenCount = HierarchyFtth::where('parent_id', $ftth->parent_id)->count(); - $round = $children/$childrenCount; - $parent->progress = round($round, 2); - $parent->save(); - if($parent->parent_id) { - $this->countParent($parent); + if($parent){ + $round = $children/$childrenCount; + $parent->progress = round($round, 2); + try { + $parent->save(); + } catch (\Exception $e) { + // Log the error or handle it in some other way + Log::error($e->getMessage()); + } + if($parent->parent_id) { + $this->countParent($parent); + } } } diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 168af3d..1c70fc8 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -27,10 +27,10 @@ class UserToActivityController extends Controller public function addMultiple(Request $request){ $users_id = $request->user_id; - $data = UserToActivity::where("activity_id", $request->activity_id); - if($data){ - $data->delete(); - } + // $data = UserToActivity::where("activity_id", $request->activity_id); + // if($data){ + // $data->delete(); + // } if(is_array($users_id) && count($users_id) > 0){ $countRes = 0; From 20374de322c6c329cf1fd193b285e13cf0390dc1 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 17 Apr 2023 10:05:59 +0700 Subject: [PATCH 017/252] Fix judul gantt --- app/Http/Controllers/ActivityController.php | 51 ++++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index ab5c490..61902e9 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -16,8 +16,13 @@ class ActivityController extends Controller { public function getByGanttId($id, $proyek_id) { - if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) { - $this->cloneTemplate($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); + } } $dataGantt = $this->getDataActivity($id); @@ -120,21 +125,33 @@ class ActivityController extends Controller return $finalData; } - private function cloneTemplate($id, $proyek_id) - { - $project = Project::find($proyek_id); - - $rootActivity = Activity::create([ - 'version_gantt_id'=>$id, - 'proyek_id'=>$proyek_id, - 'name'=> $project->nama, - 'kode_sortname'=>$project->kode_sortname, - 'start_date'=> $project->mulai_proyek, - 'end_date'=> $project->akhir_proyek, - 'rencana_biaya'=> $project->rencana_biaya, - 'type_activity'=> 'project', - 'created_by'=>$this->currentName, - ]); + 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, + ]); + } 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, + ]); + } $resultTypeProject = TemplateGantt::where('proyek_type_id', $project->type_proyek_id) ->whereNull('parent_id') From e3c9770ebe35835a920785a5a10189fb37c92db5 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 18 Apr 2023 13:41:33 +0700 Subject: [PATCH 018/252] Task #860qh88mh fix uom --- app/Http/Controllers/Controller.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a02d0d1..c431f28 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -227,14 +227,14 @@ class Controller extends BaseController private function calculateAllHumanCost($activity_id, $proyek_id) { - $dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id") + $dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate") + ->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id") ->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id) ->where("ahp.proyek_id", $proyek_id) ->get(); $totalCost = 0; foreach ($dataHuman as $human) { - $uom = $human->uom_standart_rate; $totalCost += $this->calculateHumanCost($human, $activity_id); } @@ -247,6 +247,10 @@ class Controller extends BaseController $duration = $activity->duration; $standarRate = $human->standart_rate; $maxUsed = $human->max_used/100; + if ($human->uom_standart_rate == "Hour") { + $totalCost = ($standarRate*8*$duration)*$maxUsed; + return $totalCost; + } $totalCost = ($standarRate*$duration)*$maxUsed; return $totalCost; } From 9851f12cfc0353a551d47da87f973a617acc4333 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 26 Apr 2023 10:20:47 +0700 Subject: [PATCH 019/252] #860q2vq2t sortorder --- app/Http/Controllers/ActivityController.php | 43 +++++++++++++++++++-- app/Models/Activity.php | 2 +- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 61902e9..2c7025f 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -45,9 +45,9 @@ class ActivityController extends Controller $dataHeader->type = "header"; $dataHeader->text = $dataHeader->name; $finalData[] = $dataHeader; - $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); + $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get(); }else{ - $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); + $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get(); } foreach($data as $objRow){ @@ -68,6 +68,9 @@ class ActivityController extends Controller $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL; $objRow->progress = $objRow->persentase_progress / 100; + if ($objRow->sortorder == 0 || $objRow->sortorder == null) { + $objRow->sortorder = $objRow->id; + } $objRow->type = $type; $finalData[] = $objRow; $finalData = array_merge($finalData, $dataChildren); @@ -100,7 +103,7 @@ class ActivityController extends Controller private function getChildren($gantt_id, $parent_id) { $finalData = []; - $data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('id', 'asc')->get(); + $data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get(); foreach($data as $objRow){ $objRow->parent = $parent_id; $objRow->text = $objRow->name; @@ -111,6 +114,9 @@ class ActivityController extends Controller $objRow->end_date = date_format($endDate,"Y-m-d H:i:s"); $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL; + if ($objRow->sortorder == 0 || $objRow->sortorder == null) { + $objRow->sortorder = $objRow->id; + } $dataChildren = $this->getChildren($gantt_id, $objRow->id); if($objRow->type_activity=="milestone"){ $objRow->type = $objRow->type_activity; @@ -203,6 +209,7 @@ class ActivityController extends Controller $data['name'] = $request->text; $data['persentase_progress'] = $request->progress; $data['created_by'] = $this->currentName; + $data['sortorder'] = Activity::max("sortorder") + 1; $data['type_activity'] = "task"; $parent = $data['parent_id'] ?? null; @@ -246,6 +253,10 @@ class ActivityController extends Controller $dataUpdate['updated_by'] = $this->currentName; if($data->type_activity!='header') $dataUpdate['type_activity'] = $request->type; + + if($request->has("target")){ + $this->updateOrder($id, $request->target); + } if(!$data->update($dataUpdate)) return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400); @@ -253,6 +264,29 @@ class ActivityController extends Controller return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200); } + private function updateOrder($taskId, $target){ + $nextTask = false; + $targetId = $target; + + if(strpos($target, "next:") === 0){ + $targetId = substr($target, strlen("next:")); + $nextTask = true; + } + + if($targetId == "null") + return; + + $targetOrder = Activity::find($targetId)->sortorder; + if($nextTask) + $targetOrder++; + + Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder"); + + $updatedTask = Activity::find($taskId); + $updatedTask->sortorder = $targetOrder; + $updatedTask->save(); + } + public function updateRegular(Request $request, $id){ if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); @@ -326,7 +360,8 @@ class ActivityController extends Controller $input['bobot_planning'] = $activity_row['weight']; $input['persentase_progress'] = 0; $input['type_activity'] = $i == 0 ? "header" : "task"; - $input['created_by'] = $this->currentName; + $input['created_by'] = $this->currentName; + $input['sortorder'] = $activity_row['no']; if (!$activity = Activity::create($input)) { Activity::where('version_gantt_id', $data['ganttId'])->delete(); diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 4c436d8..ce49289 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -26,7 +26,7 @@ class Activity extends Model 'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom', 'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan', 'planned_start', 'planned_end', 'satuan_id', - 'created_at', 'created_by', 'updated_at', 'updated_by' + 'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder' ]; protected $appends = [ From 38adaac853cd69f135d4eb2d576b88427261284d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 2 May 2023 16:44:16 +0700 Subject: [PATCH 020/252] Fix HR Activity Role --- app/Http/Controllers/UserToActivityController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 1c70fc8..048825c 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -26,6 +26,7 @@ class UserToActivityController extends Controller 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){ @@ -34,11 +35,11 @@ class UserToActivityController extends Controller if(is_array($users_id) && count($users_id) > 0){ $countRes = 0; - foreach($users_id as $item){ + foreach($users_id as $index => $item){ $dataInsert = array( "user_id" => $item, "activity_id" => $request->activity_id, - "role_proyek_id" => $request->role_proyek_id, + "role_proyek_id" => $users_role[$index], "proyek_id" => $request->proyek_id, "created_by" => $this->currentName ); From b05d3984acec9ca860275a6419c53014a10d8e3d Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 3 May 2023 06:59:57 +0700 Subject: [PATCH 021/252] Fix sortorder --- app/Http/Controllers/ActivityController.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 2c7025f..a04c6e0 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -68,9 +68,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; $objRow->progress = $objRow->persentase_progress / 100; - if ($objRow->sortorder == 0 || $objRow->sortorder == null) { - $objRow->sortorder = $objRow->id; - } $objRow->type = $type; $finalData[] = $objRow; $finalData = array_merge($finalData, $dataChildren); @@ -114,9 +111,6 @@ class ActivityController extends Controller $objRow->end_date = date_format($endDate,"Y-m-d H:i:s"); $objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL; $objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL; - if ($objRow->sortorder == 0 || $objRow->sortorder == null) { - $objRow->sortorder = $objRow->id; - } $dataChildren = $this->getChildren($gantt_id, $objRow->id); if($objRow->type_activity=="milestone"){ $objRow->type = $objRow->type_activity; @@ -144,6 +138,7 @@ class ActivityController extends Controller 'rencana_biaya'=> $project->rencana_biaya, 'type_activity'=> 'project', 'created_by'=>$this->currentName, + 'sortorder'=>1 ]); } else { $rootActivity = Activity::create([ @@ -156,6 +151,7 @@ class ActivityController extends Controller 'rencana_biaya'=> $project->rencana_biaya, 'type_activity'=> 'project', 'created_by'=>$this->currentName, + 'sortorder'=>1 ]); } @@ -166,6 +162,7 @@ class ActivityController extends Controller 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, @@ -174,7 +171,8 @@ class ActivityController extends Controller '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 + 'created_by'=>$this->currentName, + 'sortorder'=>$max+1 ]); $this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek); } @@ -185,6 +183,7 @@ class ActivityController extends Controller $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, @@ -193,7 +192,8 @@ class ActivityController extends Controller 'name'=> $objRow->name_activity, 'start_date'=>$firstDay, 'end_date'=>$firstDay, - 'created_by'=>$this->currentName + 'created_by'=>$this->currentName, + 'sortorder'=>$max+1 ]); $this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay); } @@ -209,7 +209,8 @@ class ActivityController extends Controller $data['name'] = $request->text; $data['persentase_progress'] = $request->progress; $data['created_by'] = $this->currentName; - $data['sortorder'] = Activity::max("sortorder") + 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; @@ -251,6 +252,7 @@ class ActivityController extends Controller $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; From 3c35ce0b1864c51053f7374ee16cf0641ba59bbf Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 9 May 2023 00:38:13 +0700 Subject: [PATCH 022/252] 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 023/252] 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 6759c6fa52b783c85da07680334b62a188f23199 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 9 May 2023 17:49:18 +0700 Subject: [PATCH 024/252] fix upload dokumen --- app/Http/Controllers/ProjectDokumenController.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectDokumenController.php b/app/Http/Controllers/ProjectDokumenController.php index 466f09b..963208c 100644 --- a/app/Http/Controllers/ProjectDokumenController.php +++ b/app/Http/Controllers/ProjectDokumenController.php @@ -94,7 +94,12 @@ class ProjectDokumenController extends Controller if(!file_exists($this->pathDocument.$document->file)) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - $pathToFile = $this->pathDocument.$document->file; - return response()->download($pathToFile); + $pathToFile = $this->pathDocument.$document->file; + $name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION); + $headers = [ + 'Content-Disposition' => 'attachment; filename="'.$name.'"' + ]; + // dd($name, $headers); + return response()->download($pathToFile, $name, $headers); } } From d4ac659b85114b17bd392d4b598fb13b36a04faa Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 12 May 2023 10:16:55 +0700 Subject: [PATCH 025/252] Update empty weight calculation --- app/Http/Controllers/ActivityController.php | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index a04c6e0..710c655 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -11,6 +11,7 @@ use App\Models\VersionGantt; use App\Models\UserToActivity; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class ActivityController extends Controller { @@ -348,6 +349,52 @@ 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; + Log::info('level '.$data['activities'][$key]['level'].' bobot '.$data['activities'][$key]['weight'].' parent '.$parentWeight.' siblings '.$siblingsCount); + } + }; + } foreach ($data['activities'] as $i => $activity_row) { $startDate = \DateTime::createFromFormat('d-m-y', $activity_row['start_date']); $endDate = \DateTime::createFromFormat('d-m-y', $activity_row['end_date']); From fcf366a8e874029e719dd9a527796d7def106a38 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 12 May 2023 10:29:45 +0700 Subject: [PATCH 026/252] Remove log --- app/Http/Controllers/ActivityController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 710c655..74dca42 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -391,7 +391,6 @@ class ActivityController extends Controller } $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; - Log::info('level '.$data['activities'][$key]['level'].' bobot '.$data['activities'][$key]['weight'].' parent '.$parentWeight.' siblings '.$siblingsCount); } }; } From 0ce506a2aa1f3483d899b05233e9cca3b0c61388 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 12 May 2023 15:01:40 +0700 Subject: [PATCH 027/252] Disable 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 7b4ef5f..6120999 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 = MasterFunctionsHelper::curlReq($url); + // $url = config('api.adw').'/employees?page=1'; + // echo "Requesting to " . $url; + $response = null; if(!$response) return; diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 915b8f6..cf32a27 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -37,17 +37,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 $response; + // 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; } // to do diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 4689c04..32b8b38 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -389,12 +389,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 = MasterFunctionsHelper::curlReq($url); + $response = null; return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); diff --git a/app/Http/Controllers/RequestMaterialController.php b/app/Http/Controllers/RequestMaterialController.php index 605cf5f..35cb76d 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 = urlencode($request->name); + $search = null; 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 fecdfec..dc944ea 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 = urlencode($request->name); + $search = null; 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 e75d5e8925649d1ab6e98afdbd6324a7a3fb0be2 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 15 May 2023 10:58:21 +0700 Subject: [PATCH 028/252] Extending DatePeriod --- 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 a5092cf..17135fa 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -6,6 +6,7 @@ use App\Models\Activity; use App\Models\Project; use App\Models\VersionGantt; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class MasterFunctionsHelper { @@ -102,7 +103,8 @@ class MasterFunctionsHelper { $begin = new \DateTime($minDate.' Monday'); if(isset($dataPayload['end_date'])){ $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate); + $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 { @@ -112,6 +114,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'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); From fbf20963a02073419cc3d5fee3918f813aef1f92 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 15 May 2023 14:16:35 +0700 Subject: [PATCH 029/252] Handling empty gantt --- app/Helpers/MasterFunctionsHelper.php | 6 ++++++ app/Http/Controllers/DashboardBoDController.php | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 17135fa..ebd59b3 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -35,10 +35,16 @@ class MasterFunctionsHelper { 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; } diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index cf32a27..273d568 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -319,8 +319,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(); */ - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); - $project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); + 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); } From 564cfcbf6e707aa3411c28c318aac5b48234f6ab Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 16 May 2023 09:39:09 +0700 Subject: [PATCH 030/252] Fix end date formatting --- app/Http/Controllers/ActivityController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 74dca42..361826d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -396,14 +396,13 @@ class ActivityController extends Controller } foreach ($data['activities'] as $i => $activity_row) { $startDate = \DateTime::createFromFormat('d-m-y', $activity_row['start_date']); - $endDate = \DateTime::createFromFormat('d-m-y', $activity_row['end_date']); - + $endDate = \DateTime::createFromFormat('d-m-y H:i:sO', $activity_row['end_date']); $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'); + $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; From 0a506bdf48c9b6a4774a925a886a39ecad51ac8f Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 17 May 2023 09:36:03 +0700 Subject: [PATCH 031/252] 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 032/252] 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 033/252] 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 034/252] 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 035/252] 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 036/252] 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 037/252] 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 038/252] 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 039/252] 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 040/252] 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 041/252] 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 042/252] 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 043/252] 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 044/252] 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 045/252] 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 046/252] 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 047/252] 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 048/252] 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 049/252] 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 050/252] 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 051/252] 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 052/252] 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 053/252] 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 054/252] 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 055/252] 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 056/252] 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 057/252] 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 058/252] 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 059/252] 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 060/252] 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 061/252] 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 062/252] 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 063/252] 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 064/252] 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 065/252] 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 066/252] 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 067/252] 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 068/252] 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 069/252] 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 070/252] 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 071/252] 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 072/252] 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 073/252] 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 074/252] 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 075/252] 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 076/252] 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 077/252] 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 078/252] 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 079/252] 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 080/252] 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 081/252] 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 082/252] 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 083/252] 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 084/252] 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 085/252] 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 086/252] 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 087/252] 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 088/252] 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 089/252] 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 090/252] 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 091/252] 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 092/252] 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 093/252] 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 094/252] 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 095/252] 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 096/252] 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 097/252] 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 098/252] 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 099/252] 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 100/252] 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 101/252] 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 102/252] 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 103/252] 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 104/252] 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 105/252] 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 106/252] 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 107/252] 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 108/252] 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 109/252] 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 110/252] 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 111/252] 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 112/252] 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 113/252] 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 114/252] 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 115/252] 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 116/252] 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 117/252] 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 118/252] 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 119/252] 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 120/252] 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 121/252] 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 122/252] 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 123/252] 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 124/252] 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 125/252] 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 126/252] 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 127/252] 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 128/252] 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 129/252] 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 130/252] 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 131/252] 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 132/252] 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 133/252] 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 134/252] 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 135/252] 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 136/252] 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 137/252] 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 138/252] 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 139/252] 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 140/252] 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 141/252] 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 142/252] 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 143/252] 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 144/252] 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 145/252] 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 146/252] 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 147/252] 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 148/252] 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 149/252] 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 150/252] 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 151/252] 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 152/252] 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 153/252] 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 154/252] 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 155/252] 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 156/252] 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 157/252] 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 158/252] 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 159/252] 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 160/252] 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 161/252] 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 162/252] 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 163/252] 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 164/252] 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 165/252] 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 166/252] 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 167/252] 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 168/252] 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 169/252] 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 170/252] 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 171/252] 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 172/252] 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 173/252] 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 174/252] 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 175/252] 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 176/252] 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 177/252] 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 178/252] 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 179/252] 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 180/252] 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 181/252] 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 182/252] 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 183/252] 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 184/252] 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 185/252] 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 186/252] 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 187/252] 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 188/252] 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 189/252] 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 190/252] 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 191/252] 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 192/252] 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 193/252] 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 194/252] 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 195/252] 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 196/252] 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 197/252] 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 198/252] 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 199/252] 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 200/252] 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 201/252] 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 202/252] 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 203/252] 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 204/252] 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 205/252] 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 206/252] 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 207/252] 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 208/252] 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 209/252] 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 210/252] 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 211/252] 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 212/252] 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 213/252] 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()]); } From 937ae248cdd9412fb85244830e7c4b390da20ed7 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 17 Oct 2023 19:31:17 +0700 Subject: [PATCH 214/252] access creator only --- 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 f5b921b..91fbb3d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -229,6 +229,7 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; + $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); @@ -274,7 +275,9 @@ class ProjectController extends Controller 'created_by', 'updated_at', 'updated_by' - )->orderBy('id', 'desc')->get(); + )->orderBy('id', 'desc') + ->where("created_by",$this->currentName) + ->get(); $countData = $data->count(); if(!$data) From ea33a29ca81b669b675fc99dc99c3e76237b3055 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 18 Oct 2023 13:26:46 +0700 Subject: [PATCH 215/252] custom search for report analysis --- app/Http/Controllers/ProjectController.php | 4 ++-- app/Http/Controllers/UserToActivityController.php | 10 ++++++++++ routes/web.php | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 91fbb3d..46c529d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -229,7 +229,7 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; - $builder->where("selfTable.created_by",$this->currentName); + // $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); @@ -276,7 +276,7 @@ class ProjectController extends Controller 'updated_at', 'updated_by' )->orderBy('id', 'desc') - ->where("created_by",$this->currentName) + // ->where("created_by",$this->currentName) ->get(); $countData = $data->count(); diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 2c3a658..a1a9583 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -129,6 +129,16 @@ class UserToActivityController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); } + public function searchAnalysis(Request $request) + { + $dataBuilder = $this->setUpPayload($request->all(), '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 search(Request $request) { $payload = $request->all(); diff --git a/routes/web.php b/routes/web.php index 7f62207..f449cef 100644 --- a/routes/web.php +++ b/routes/web.php @@ -197,6 +197,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $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/search-analysis', 'UserToActivityController@searchAnalysis'); $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'); @@ -204,7 +205,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial'); $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); - $router->get('/activity/search', 'ActivityController@search'); + $router->post('/activity/search', 'ActivityController@search'); $router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld'); From 6ba8f63717f410405a5af5421b4b4372bafdc544 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 19 Oct 2023 08:03:40 +0700 Subject: [PATCH 216/252] fix endline --- app/Models/HumanResource.php | 76 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/app/Models/HumanResource.php b/app/Models/HumanResource.php index 222a835..d3c98d1 100644 --- a/app/Models/HumanResource.php +++ b/app/Models/HumanResource.php @@ -1,38 +1,38 @@ - Date: Thu, 19 Oct 2023 08:05:39 +0700 Subject: [PATCH 217/252] fix endline --- app/Models/CommentActivity.php | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/Models/CommentActivity.php b/app/Models/CommentActivity.php index e747af2..0cd259e 100644 --- a/app/Models/CommentActivity.php +++ b/app/Models/CommentActivity.php @@ -1,22 +1,22 @@ - Date: Thu, 19 Oct 2023 08:06:59 +0700 Subject: [PATCH 218/252] fix endline --- app/Models/VersionGantt.php | 154 ++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 4409af8..765ddf1 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -1,77 +1,77 @@ -updateActDuration(); - }); - } - - 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) { - $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++) { - $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(); - } - } -} +updateActDuration(); + }); + } + + 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) { + $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++) { + $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 ef500ad9754c954b4dcc270b42ee3e8990a19162 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 19 Oct 2023 10:21:54 +0700 Subject: [PATCH 219/252] custom activity search --- 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 acd94b0..df66558 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -527,6 +527,17 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } + public function searchAnalysis(Request $request) + { + $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); + $builder = $dataBuilder['builder']; + $dataGet = $builder->select('selfTable.*','m_version_gantt.name_version', 'm_users.name as user_name') + ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') + ->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') + ->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') + ->get(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); + } // before upload file public function importOld(Request $request) { diff --git a/routes/web.php b/routes/web.php index f449cef..73b90db 100644 --- a/routes/web.php +++ b/routes/web.php @@ -206,6 +206,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial'); $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->post('/activity/search', 'ActivityController@search'); + $router->post('/activity/search-analysis', 'ActivityController@searchAnalysis'); $router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld'); From 5b53d9f3a0cab4629db5b018f1ec53627cfb509d Mon Sep 17 00:00:00 2001 From: wahyuun Date: Thu, 19 Oct 2023 12:35:15 +0700 Subject: [PATCH 220/252] add color select --- 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 143af38..ebdf8a3 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -304,7 +304,7 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name') + $divisions = Divisi::select('id', 'name', 'color') ->with('children') ->whereNull('parent') ->get(); From 6d8bfa260279bfd86efd656177adc77167001522 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 19 Oct 2023 13:24:58 +0700 Subject: [PATCH 221/252] Fix endline --- .../Controllers/ActivityDokumenController.php | 190 +++++++++--------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/app/Http/Controllers/ActivityDokumenController.php b/app/Http/Controllers/ActivityDokumenController.php index f3a1143..999e860 100644 --- a/app/Http/Controllers/ActivityDokumenController.php +++ b/app/Http/Controllers/ActivityDokumenController.php @@ -1,95 +1,95 @@ -json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); - - $dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); - return response()->json(['status'=>'success','data'=>$dataDokumen,'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); - - $document = ActivityDokumen::find($id); - - if(!$document) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - if(file_exists($this->pathActivityDocument.$document->file)) - unlink($this->pathActivityDocument.$document->file); - - $document->delete(); - return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); - } - - public function uploadProjectDokumen(Request $request) - { - if(!$request->hasFile('dokumen')) - return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); - - $activity_id = $request->activity_id; - $document = $request->file('dokumen'); - $name = $document->getClientOriginalName(); - - $result = $document->move($this->pathActivityDocument, $name); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); - - $data = [ - 'activity_id' => (int)$activity_id, - 'file' => $name, - 'description' => $request->description - ]; - - $result = ActivityDokumen::create($data); - - if(!$result){ - unlink($this->pathActivityDocument.$name); - return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); - } - - return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); - } - - public function searchDocProject(Request $request){ - $payload = $request->all(); - - $dataBuilder = $this->setUpPayload($payload, 'm_document_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 downloadDokumen($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); - - $document = ActivityDokumen::find($id); - - if(!$document) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); - - if(file_exists($this->pathActivityDocument.$document->file)){ - $pathToFile = $this->pathActivityDocument.$document->file; - return response()->download($pathToFile); - } - - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); - } -} +json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); + + $dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); + return response()->json(['status'=>'success','data'=>$dataDokumen,'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); + + $document = ActivityDokumen::find($id); + + if(!$document) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + if(file_exists($this->pathActivityDocument.$document->file)) + unlink($this->pathActivityDocument.$document->file); + + $document->delete(); + return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); + } + + public function uploadProjectDokumen(Request $request) + { + if(!$request->hasFile('dokumen')) + return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); + + $activity_id = $request->activity_id; + $document = $request->file('dokumen'); + $name = $document->getClientOriginalName(); + + $result = $document->move($this->pathActivityDocument, $name); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + + $data = [ + 'activity_id' => (int)$activity_id, + 'file' => $name, + 'description' => $request->description + ]; + + $result = ActivityDokumen::create($data); + + if(!$result){ + unlink($this->pathActivityDocument.$name); + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + } + + return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); + } + + public function searchDocProject(Request $request){ + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_document_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 downloadDokumen($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); + + $document = ActivityDokumen::find($id); + + if(!$document) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); + + if(file_exists($this->pathActivityDocument.$document->file)){ + $pathToFile = $this->pathActivityDocument.$document->file; + return response()->download($pathToFile); + } + + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); + } +} From 66e72be3a2883ead8e2ab659fac2ab54a18773af Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 19 Oct 2023 14:11:48 +0700 Subject: [PATCH 222/252] access creator only --- app/Http/Controllers/ProjectController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 46c529d..91fbb3d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -229,7 +229,7 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; - // $builder->where("selfTable.created_by",$this->currentName); + $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); @@ -276,7 +276,7 @@ class ProjectController extends Controller 'updated_at', 'updated_by' )->orderBy('id', 'desc') - // ->where("created_by",$this->currentName) + ->where("created_by",$this->currentName) ->get(); $countData = $data->count(); From 736eb9c617e41c4f5c0bd08b962ceaae6551b613 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 20 Oct 2023 11:11:28 +0700 Subject: [PATCH 223/252] disable created by --- app/Http/Controllers/ProjectController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 301dc42..39042ec 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -229,7 +229,7 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; - $builder->where("selfTable.created_by",$this->currentName); + // $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); @@ -276,7 +276,7 @@ class ProjectController extends Controller 'updated_at', 'updated_by' )->orderBy('id', 'desc') - ->where("created_by",$this->currentName) + // ->where("created_by",$this->currentName) ->get(); $countData = $data->count(); From af307f413bb0b0f3370080b45351cb9fa16ad6e4 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 23 Oct 2023 11:34:46 +0700 Subject: [PATCH 224/252] update Logic Presence --- app/Http/Controllers/PresenceController.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 17843f4..5b2199b 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -135,13 +135,23 @@ class PresenceController extends Controller $checkLocation = $this->checkLocation($request); $statusBoundary = false; $date = date_create($request->time); + $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); // assign and in boundary - if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ - $statusBoundary = true; + if (count($checkLocation) > 0 && $statusRestriction->status_boundary == true) + { + if ($checkLocation[0]['boundary'] == true) + { + $statusBoundary = true; + } else { + $statusBoundary = false; + } } - $statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first(); - if (!$statusRestriction->status_boundary) { - $statusBoundary = true; + // assign and not in boundary or in boundary + else { + if ($checkLocation[0]['boundary'] == true || $checkLocation[0]['boundary'] == false) + { + $statusBoundary = true; + } } // not assign if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false && $statusBoundary == false){ From 0ceffeeb5fa82b68ce70c433d97dbeec12547741 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 23 Oct 2023 13:03:32 +0700 Subject: [PATCH 225/252] add filter scurve --- app/Helpers/MasterFunctionsHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index ae74952..20ca4fb 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -555,6 +555,7 @@ class MasterFunctionsHelper ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') ->where('a.type_activity', 'task') ->where('a.bobot_planning', '>', 0) + ->where('a.proyek_id', '=', $projectId) ->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'); @@ -563,6 +564,7 @@ class MasterFunctionsHelper ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') ->where('a.type_activity', 'task') ->where('a.bobot_planning', '>', 0) + ->where('a.proyek_id', '=', $projectId) ->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') From 95b78bda1d61ce0a6afc95b1e38771ebafb21917 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 23 Oct 2023 14:28:21 +0700 Subject: [PATCH 226/252] zero division handling --- 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 20ca4fb..1bed1bb 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -375,7 +375,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()]); } From 12edaab3021417eb54630cc50c3390a130a42e5d Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 24 Oct 2023 09:33:35 +0700 Subject: [PATCH 227/252] select activity --- app/Http/Controllers/ActivityController.php | 13 +++++++++++++ routes/web.php | 1 + 2 files changed, 14 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index df66558..0e23cdb 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -527,6 +527,19 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } + public function searchAnalysisPrep(Request $request) + { + $data = $request->all(); + $dataGet = DB::table('m_activity') + ->select('m_activity.name') + ->where('m_activity.proyek_id', $data['columns'][0]['value']) + ->where('m_activity.type_activity', 'task') + ->where('m_activity.persentase_progress', '>', 0) + ->groupByRaw('m_activity.name') + ->get(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); + } + public function searchAnalysis(Request $request) { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); diff --git a/routes/web.php b/routes/web.php index 73b90db..f9e79b4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -207,6 +207,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->post('/activity/search', 'ActivityController@search'); $router->post('/activity/search-analysis', 'ActivityController@searchAnalysis'); + $router->post('/activity/search-analysis-prep', 'ActivityController@searchAnalysisPrep'); $router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld'); From 86588d4892e1675e7504b06e9d94d4806e45c3b1 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 24 Oct 2023 13:12:53 +0700 Subject: [PATCH 228/252] hierarchy & gantt cascade delete --- app/Models/Activity.php | 12 +++++++++--- app/Models/HierarchyFtth.php | 16 +++++++++++----- app/Models/VersionGantt.php | 7 +++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 3a8e54c..5d9c1e7 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -79,8 +79,14 @@ class Activity extends Model }); static::deleted(function($data) { - if(Activity::where("parent_id", $data->parent_id)->count() == 0) - Activity::find($data->parent_id)->update(["type_activity"=>"task"]); + if (isset($data->parent_id)) { + if(Activity::where("parent_id", $data->parent_id)->count() == 0) { + $activity = Activity::find($data->parent_id); + if ($activity) { + $activity->update(["type_activity"=>"task"]); + } + } + } $data->updateBobot(true); $data->updateCostPlanning(); @@ -100,7 +106,7 @@ class Activity extends Model ->whereNull('parent_id') ->first(); - if($root->rencana_biaya > 0){ + if(isset($root) && $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) diff --git a/app/Models/HierarchyFtth.php b/app/Models/HierarchyFtth.php index fae503c..1a0ba8c 100644 --- a/app/Models/HierarchyFtth.php +++ b/app/Models/HierarchyFtth.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use App\Models\VersionGantt; class HierarchyFtth extends Model { @@ -14,15 +15,20 @@ 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(); - } + $ftths = HierarchyFtth::where('parent_id', $data->id)->get(); + foreach ($ftths as $ftth) { + $ftth->delete(); + } + + $gantts = VersionGantt::where('hierarchy_ftth_id', $data->id)->get(); + foreach ($gantts as $gantt) { + $gantt->delete(); + } }); } } diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 765ddf1..39b9b0f 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -38,6 +38,13 @@ class VersionGantt extends Model static::updated(function($data) { $data->updateActDuration(); + }); + + static::deleted(function ($data) { + $activities = Activity::where('version_gantt_id', $data->id)->get(); + foreach ($activities as $activity) { + $activity->delete(); + } }); } From 0c487fc05b2d731bb4400d90c717956ddd3cc168 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 24 Oct 2023 15:50:55 +0700 Subject: [PATCH 229/252] handling plan overflow --- app/Helpers/MasterFunctionsHelper.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 1bed1bb..add9de1 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -708,6 +708,9 @@ class MasterFunctionsHelper $tempTtlPercentPlan += $sumPercentagePlan; $tempTtlPercentActual += $sumPercentageActual; + if ($tempTtlPercentPlan >= 100) + $tempTtlPercentPlan = 100; + $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; @@ -715,6 +718,9 @@ class MasterFunctionsHelper $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); From c603efb1a62bec78795df29a22c6d2e260379642 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 25 Oct 2023 10:16:37 +0700 Subject: [PATCH 230/252] fix endline --- .../Controllers/ReportActivityController.php | 540 +++++++++--------- 1 file changed, 270 insertions(+), 270 deletions(-) diff --git a/app/Http/Controllers/ReportActivityController.php b/app/Http/Controllers/ReportActivityController.php index 6a458f5..94a8d89 100644 --- a/app/Http/Controllers/ReportActivityController.php +++ b/app/Http/Controllers/ReportActivityController.php @@ -1,270 +1,270 @@ -has('gantt')){ - $this->validate($request, [ - 'activity_id' => 'required', - 'user_id' => 'required', - 'report_date' => 'required', - 'job_count_report' => 'required' - ]); - }else{ - $this->validate($request, [ - 'activity_id' => 'required', - 'user_id' => 'required', - 'report_date' => 'required', - 'job_count_report' => 'required', - 'lat' => 'required', - 'lon' => 'required', - ]); - } - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = ReportActivity::create($data); - - if($result){ - $this->countForProgress($request->activity_id); - if($request->hasFile("files")){ - $this->uploadImage($request->file('files'), $result->id); - } - return response()->json(['status'=>'success','message'=>'add report activity, update progress activity successfully!','code'=>200,'last_inserted_id'=>$result->id], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add report activity failed!','code'=>400], 400); - } - } - - private function uploadImage($files, $ref_id) - { - $dokumen = $files; - $extension = $dokumen->extension(); - $name = $ref_id.date("YmdHis").".".$extension; - $resultMove = $dokumen->move($this->pathImage, $name); - if($resultMove){ - $data = [ - 'ref_id' => (int)$ref_id, - 'image' => $name, - 'category' => "report_activity" - ]; - - $result = Image::create($data); - - if($result){ - return true; - } - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = ReportActivity::select("report_activity.*", "u.name as user_name")->where("report_activity.id", $id)->join("m_users as u", "u.id", "=", "report_activity.user_id")->first(); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data report activity, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = ReportActivity::find($id); - - if($data){ - $dataUpdate = $request->all(); - $result = $data->update($dataUpdate); - if($result){ - if($request->hasFile("files")){ - $this->updateImage($request->file('files'), $id); - } - $this->countForProgress($data->activity_id); - return response()->json(['status'=>'success','message'=>'data report activity successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data report activity failed updated!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400); - die(); - } - } - - public function updateImage($files, $ref_id) - { - $image = Image::where("ref_id", $ref_id)->where("category", "report_activity")->first(); - if($image){ - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); - } - $image->delete(); - } - $dokumen = $files; - $extension = $dokumen->extension(); - $name = $ref_id.date("YmdHis").".".$extension; - $resultMove = $dokumen->move($this->pathImage, $name); - if($resultMove){ - $data = [ - 'ref_id' => (int)$ref_id, - 'image' => $name, - 'category' => "report_activity" - ]; - - $result = Image::create($data); - - if($result){ - return true; - } - } - } - - public function delete($id) - { - $data = ReportActivity::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400); - die(); - } - - - if($delete){ - $image = Image::where("ref_id", $id)->where("category", "report_activity")->first(); - if($image){ - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); - } - $image->delete(); - } - return response()->json(['status'=>'success','message'=>'data report activity successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data report activity failed deleted!','code'=>400], 400); - } - } - - private function countForProgress($id) - { - - $totalJobs = ReportActivity::where('activity_id', $id)->sum("job_count_report"); - $dataActivity = Activity::find($id); - $jobsActivity = (int)$dataActivity->jumlah_pekerjaan; - - if ($jobsActivity < 1) { - return false; - } - - if ($totalJobs < 1) { - return false; - } - - $persentaseActual = ($totalJobs/$jobsActivity)*100; - $dataUpdate = array( - "persentase_progress" => $persentaseActual, - "updated_by" => $this->currentName - ); - return $dataActivity->update($dataUpdate); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'report_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 = ReportActivity::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 report activity, please try again later!','code'=>400], 400); - } - } - - public function searchPoint(Request $request) { - $dataPayload = $request->all(); - $reqActivityId = []; - foreach ($dataPayload['project_id'] as $val) { - $reqActivityId[] = $this->getActivityByProjectId($val); - } - - $activity_id = []; - $getPoints = false; - - if (count($reqActivityId) > 0) { - for ($i=0; $i < count($reqActivityId); $i++) { - if (count($reqActivityId[$i]) > 0) { - foreach($reqActivityId[$i] as $reqAct) { - array_push($activity_id, $reqAct->id); - } - } - } - } - - if (count($activity_id) > 0) { - $getPoints = ReportActivity::select('report_activity.*', 'm_activity.name as activity_name', 'm_activity.jumlah_pekerjaan', 'm_proyek.nama as proyek_name') - ->leftJoin('m_activity', 'm_activity.id', '=', 'report_activity.activity_id') - ->leftJoin('m_proyek', 'm_proyek.id', '=', 'm_activity.proyek_id') - ->whereIn('report_activity.activity_id', $activity_id)->get(); - } - - if($getPoints){ - return response()->json(['status'=>'success','code'=>200,'data'=>$getPoints, 'totalRecord'=>count($getPoints)], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list points, please try again later!','code'=>400], 400); - } - } - - public function getActivityByProjectId($projectId) { - $data = Activity::select('id')->where('proyek_id', $projectId)->get(); - return $data; - } - - public function datatables(Request $request){ - $id_activity = $request->query('idact'); - $data = ReportActivity::select("report_activity.*", "u.name as user_name") - ->join("m_users as u", "u.id", "=", "report_activity.user_id") - ->where('report_activity.activity_id', $id_activity) - ->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('action', function($row){ - $actionBtn = ''; - $actionBtn .= ' '; - return $actionBtn; - }) - ->editColumn('report_date', function($row) { - $date = date_create($row->report_date); - return date_format($date,"d-m-Y H:i:s"); - }) - ->rawColumns(['action'])->make(true); - } -} +has('gantt')){ + $this->validate($request, [ + 'activity_id' => 'required', + 'user_id' => 'required', + 'report_date' => 'required', + 'job_count_report' => 'required' + ]); + }else{ + $this->validate($request, [ + 'activity_id' => 'required', + 'user_id' => 'required', + 'report_date' => 'required', + 'job_count_report' => 'required', + 'lat' => 'required', + 'lon' => 'required', + ]); + } + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = ReportActivity::create($data); + + if($result){ + $this->countForProgress($request->activity_id); + if($request->hasFile("files")){ + $this->uploadImage($request->file('files'), $result->id); + } + return response()->json(['status'=>'success','message'=>'add report activity, update progress activity successfully!','code'=>200,'last_inserted_id'=>$result->id], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add report activity failed!','code'=>400], 400); + } + } + + private function uploadImage($files, $ref_id) + { + $dokumen = $files; + $extension = $dokumen->extension(); + $name = $ref_id.date("YmdHis").".".$extension; + $resultMove = $dokumen->move($this->pathImage, $name); + if($resultMove){ + $data = [ + 'ref_id' => (int)$ref_id, + 'image' => $name, + 'category' => "report_activity" + ]; + + $result = Image::create($data); + + if($result){ + return true; + } + } + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = ReportActivity::select("report_activity.*", "u.name as user_name")->where("report_activity.id", $id)->join("m_users as u", "u.id", "=", "report_activity.user_id")->first(); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data report activity, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = ReportActivity::find($id); + + if($data){ + $dataUpdate = $request->all(); + $result = $data->update($dataUpdate); + if($result){ + if($request->hasFile("files")){ + $this->updateImage($request->file('files'), $id); + } + $this->countForProgress($data->activity_id); + return response()->json(['status'=>'success','message'=>'data report activity successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data report activity failed updated!','code'=>400], 400); + } + }else{ + return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400); + die(); + } + } + + public function updateImage($files, $ref_id) + { + $image = Image::where("ref_id", $ref_id)->where("category", "report_activity")->first(); + if($image){ + if(file_exists($this->pathImage.$image->image)){ + unlink($this->pathImage.$image->image); + } + $image->delete(); + } + $dokumen = $files; + $extension = $dokumen->extension(); + $name = $ref_id.date("YmdHis").".".$extension; + $resultMove = $dokumen->move($this->pathImage, $name); + if($resultMove){ + $data = [ + 'ref_id' => (int)$ref_id, + 'image' => $name, + 'category' => "report_activity" + ]; + + $result = Image::create($data); + + if($result){ + return true; + } + } + } + + public function delete($id) + { + $data = ReportActivity::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400); + die(); + } + + + if($delete){ + $image = Image::where("ref_id", $id)->where("category", "report_activity")->first(); + if($image){ + if(file_exists($this->pathImage.$image->image)){ + unlink($this->pathImage.$image->image); + } + $image->delete(); + } + return response()->json(['status'=>'success','message'=>'data report activity successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data report activity failed deleted!','code'=>400], 400); + } + } + + private function countForProgress($id) + { + + $totalJobs = ReportActivity::where('activity_id', $id)->sum("job_count_report"); + $dataActivity = Activity::find($id); + $jobsActivity = (int)$dataActivity->jumlah_pekerjaan; + + if ($jobsActivity < 1) { + return false; + } + + if ($totalJobs < 1) { + return false; + } + + $persentaseActual = ($totalJobs/$jobsActivity)*100; + $dataUpdate = array( + "persentase_progress" => $persentaseActual, + "updated_by" => $this->currentName + ); + return $dataActivity->update($dataUpdate); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'report_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 = ReportActivity::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 report activity, please try again later!','code'=>400], 400); + } + } + + public function searchPoint(Request $request) { + $dataPayload = $request->all(); + $reqActivityId = []; + foreach ($dataPayload['project_id'] as $val) { + $reqActivityId[] = $this->getActivityByProjectId($val); + } + + $activity_id = []; + $getPoints = false; + + if (count($reqActivityId) > 0) { + for ($i=0; $i < count($reqActivityId); $i++) { + if (count($reqActivityId[$i]) > 0) { + foreach($reqActivityId[$i] as $reqAct) { + array_push($activity_id, $reqAct->id); + } + } + } + } + + if (count($activity_id) > 0) { + $getPoints = ReportActivity::select('report_activity.*', 'm_activity.name as activity_name', 'm_activity.jumlah_pekerjaan', 'm_proyek.nama as proyek_name') + ->leftJoin('m_activity', 'm_activity.id', '=', 'report_activity.activity_id') + ->leftJoin('m_proyek', 'm_proyek.id', '=', 'm_activity.proyek_id') + ->whereIn('report_activity.activity_id', $activity_id)->get(); + } + + if($getPoints){ + return response()->json(['status'=>'success','code'=>200,'data'=>$getPoints, 'totalRecord'=>count($getPoints)], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list points, please try again later!','code'=>400], 400); + } + } + + public function getActivityByProjectId($projectId) { + $data = Activity::select('id')->where('proyek_id', $projectId)->get(); + return $data; + } + + public function datatables(Request $request){ + $id_activity = $request->query('idact'); + $data = ReportActivity::select("report_activity.*", "u.name as user_name") + ->join("m_users as u", "u.id", "=", "report_activity.user_id") + ->where('report_activity.activity_id', $id_activity) + ->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('action', function($row){ + $actionBtn = ''; + $actionBtn .= ' '; + return $actionBtn; + }) + ->editColumn('report_date', function($row) { + $date = date_create($row->report_date); + return date_format($date,"d-m-Y H:i:s"); + }) + ->rawColumns(['action'])->make(true); + } +} From 99185941b0bbf0106572798b91c529598280d98e Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 25 Oct 2023 11:26:19 +0700 Subject: [PATCH 231/252] update report analysis --- app/Http/Controllers/ActivityController.php | 14 +++++++++++++- app/Http/Controllers/Controller.php | 2 ++ app/Http/Controllers/UserToActivityController.php | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 0e23cdb..fddd137 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -544,10 +544,22 @@ class ActivityController extends Controller { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $builder = $dataBuilder['builder']; - $dataGet = $builder->select('selfTable.*','m_version_gantt.name_version', 'm_users.name as user_name') + $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', + 'm_version_gantt.name_version', 'm_users.name as user_name', + DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning', + 'assign_material_to_activity.id as join_third_id') ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') ->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') ->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') + ->join('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') + ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') + ->groupBy("selfTable.id") + ->groupBy("selfTable.name") + ->groupBy("selfTable.persentase_progress") + ->groupBy("m_version_gantt.name_version") + ->groupBy("m_users.name") + ->groupBy("assign_material_to_activity.qty_planning") + ->groupBy("assign_material_to_activity.id") ->get(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); } diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 507129d..7e00a8a 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -54,11 +54,13 @@ class Controller extends BaseController $tableName = $join['name']; $columnJoin = $join['column_join']; // foreign key table sini $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan + if (isset($join['column_results'])) { $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++; } diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index a1a9583..4ca00f8 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Models\UserToActivity; use App\Models\Activity; use App\Models\AssignMaterial; +use Illuminate\Support\Facades\DB; use Datatables; class UserToActivityController extends Controller @@ -134,6 +135,12 @@ class UserToActivityController extends Controller $dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; + $builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual')); + $builder->groupBy("m_activity.id"); + $builder->groupBy("selfTable.id"); + $builder->groupBy("m_users.name"); + $builder->groupBy("assign_material_to_activity.id"); + $builder->groupBy("m_version_gantt.name_version"); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); From 029ccfc6abf709e5e24416c5629bc7bbaa285b42 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 25 Oct 2023 13:06:26 +0700 Subject: [PATCH 232/252] update progress bar --- app/Helpers/MasterFunctionsHelper.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index add9de1..9cbc746 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -402,8 +402,9 @@ class MasterFunctionsHelper // if($tempTtlPercentActual >= $keyGantt['progress']) // $tempTtlPercentActual = $keyGantt['progress']; - if ($tempTtlPercentPlan >= 100) - $tempTtlPercentPlan = 100; + // todo + // if ($tempTtlPercentPlan >= 100) + // $tempTtlPercentPlan = 100; // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual // } @@ -707,9 +708,9 @@ class MasterFunctionsHelper if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { $tempTtlPercentPlan += $sumPercentagePlan; $tempTtlPercentActual += $sumPercentageActual; - - if ($tempTtlPercentPlan >= 100) - $tempTtlPercentPlan = 100; + // todo + // if ($tempTtlPercentPlan >= 100) + // $tempTtlPercentPlan = 100; $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; From a19d0ea5cdd4e5b9077340f9d7f015fde4b70d5c Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 26 Oct 2023 18:56:29 +0700 Subject: [PATCH 233/252] fix dashboard bod --- .../Controllers/DashboardBoDController.php | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index ebdf8a3..2de808e 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -133,7 +133,7 @@ class DashboardBoDController extends Controller ]; $projects = Project::where('mulai_proyek', 'like', $year)->get(); - foreach ($projects as $project) { + foreach ($projects as $index => $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $selisihProgress = 0; if ($project->scurve && $project->scurve[0]) { @@ -144,12 +144,18 @@ class DashboardBoDController extends Controller } $selisihProgress = $planningProgress - $actualProgress; try { - if ($selisihProgress > 0 && $selisihProgress <= 5) + if ($selisihProgress > 0 && $selisihProgress <= 5){ $return['warning'] += 1; - elseif ($selisihProgress == 0) + $projects[$index]->status = 'warning'; + } + elseif ($selisihProgress == 0){ $return['on-schedule'] += 1; - else + $projects[$index]->status = 'on-schedule'; + } + else { $return['behind-schedule'] += 1; + $projects[$index]->status = 'behind-schedule'; + } } catch (\Error $e) { return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); } @@ -163,7 +169,7 @@ class DashboardBoDController extends Controller $year = $this->interpolateYear($year); $divisions = Divisi::whereNull('parent')->get(); - foreach ($divisions as $division) { + foreach ($divisions as $index => $division) { $scheduleData = new Collection(); $behindSchedule = $warning = $onSchedule = 0; @@ -171,18 +177,29 @@ class DashboardBoDController extends Controller $projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get(); foreach ($projects as $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); - if (@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) + $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; + if ($selisihProgress > 0 && $selisihProgress <= 5){ $warning++; - elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) - $behindSchedule++; - elseif (@$project->scurve['difference'] == 0) + } + elseif ($selisihProgress == 0){ $onSchedule++; + } + else { + $behindSchedule++; + } } $scheduleData->prepend($behindSchedule, 'behindSchedule'); $scheduleData->prepend($warning, 'warning'); $scheduleData->prepend($onSchedule, 'onSchedule'); - $division->scheduleData = $scheduleData; + $divisions[$index]->scheduleData = $scheduleData; } return response()->json([ 'data' => [ From 8a26f1bcb1fda04baff94b29fdc78b56a6627777 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 27 Oct 2023 11:35:11 +0700 Subject: [PATCH 234/252] add parent select --- 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 ebdf8a3..78c614f 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -304,7 +304,7 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name', 'color') + $divisions = Divisi::select('id', 'name', 'parent', 'color') ->with('children') ->whereNull('parent') ->get(); From 7cd6e4ef307e0bf8db72822b4fd65649b4eede72 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 27 Oct 2023 13:19:07 +0700 Subject: [PATCH 235/252] rollback --- 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 78c614f..ebdf8a3 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -304,7 +304,7 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name', 'parent', 'color') + $divisions = Divisi::select('id', 'name', 'color') ->with('children') ->whereNull('parent') ->get(); From 6aa4ea2ca56c1c8a94e393c859444d1bf8a29cce Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 27 Oct 2023 14:09:33 +0700 Subject: [PATCH 236/252] fix actual start --- 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 fddd137..1c7fa55 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -187,7 +187,7 @@ class ActivityController extends Controller $actualStartValues = array_column(array_filter($dataFinal, function($item) { return isset($item['actual_start']); }), 'actual_start'); - $returnActualStartOrEnd = count($actualStartValues) == count($dataFinal) ? min($actualStartValues) : null; + $returnActualStartOrEnd = min($actualStartValues); if (isset($parent)) { $parent->actual_start = $returnActualStartOrEnd; $parent->save(); From 165247b46237ec6f9fc113a7a4090b880c4892f4 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 30 Oct 2023 08:57:33 +0700 Subject: [PATCH 237/252] update s curve --- app/Helpers/MasterFunctionsHelper.php | 95 ++++++++++++++++----------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 9cbc746..52708e6 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -7,7 +7,7 @@ use App\Models\Project; use App\Models\VersionGantt; use App\Models\HierarchyFtth; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Log; +use DateTime; class MasterFunctionsHelper { @@ -222,6 +222,7 @@ class MasterFunctionsHelper $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); $end = new \DateTime($maxDate->format('Y-m-d') . ' Friday'); $end->modify('next Friday'); + $end->modify('next Friday'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); @@ -285,24 +286,32 @@ class MasterFunctionsHelper $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'); + // $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'); + $sumVolPlan = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyPlanM->id) + ->groupBy('activity_id') + ->first(); + $weekCount = $keyPlanM->duration / 7; + $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; + $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; @@ -311,7 +320,7 @@ class MasterFunctionsHelper $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; try { $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan += $keyPlanM->bobot_planning; + $sumPercentagePlan += $weeklyProgress; if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; else @@ -507,11 +516,11 @@ class MasterFunctionsHelper $minDate = $dataProject->mulai_proyek; - $begin = new \DateTime($minDate); + $begin = new \DateTime($minDate . ' Monday'); $begin->modify('last Monday'); if (isset($dataPayload['end_date'])) { $maxDate = $dataPayload['end_date']; - $end = new \DateTime($maxDate); + $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 @@ -586,21 +595,31 @@ class MasterFunctionsHelper $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'); + // $sumVolPlan = DB::table(function ($query) use ($projectId) { + // $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.proyek_id', $projectId) + // ->unionAll(function ($query) use ($projectId) { + // $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.proyek_id', $projectId); + // })->orderBy('id', 'asc'); + // }, 'subquery') + // ->sum('bobot_planning'); + $sumVolPlan = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyPlanM->id) + ->groupBy('activity_id') + ->first(); + $weekCount = $keyPlanM->duration / 7; + $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; + $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; @@ -609,7 +628,7 @@ class MasterFunctionsHelper $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; try { $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; - $sumPercentagePlan += $keyPlanM->bobot_planning; + $sumPercentagePlan += $weeklyProgress; if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; else From 4e03656f13efe641eed5e8b4934ba6d98f701862 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 30 Oct 2023 12:45:14 +0700 Subject: [PATCH 238/252] update report analysis --- app/Http/Controllers/ActivityController.php | 11 ++++++----- app/Http/Controllers/UserToActivityController.php | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 1c7fa55..3375682 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -534,7 +534,7 @@ class ActivityController extends Controller ->select('m_activity.name') ->where('m_activity.proyek_id', $data['columns'][0]['value']) ->where('m_activity.type_activity', 'task') - ->where('m_activity.persentase_progress', '>', 0) + // ->where('m_activity.persentase_progress', '>', 0) ->groupByRaw('m_activity.name') ->get(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); @@ -544,14 +544,14 @@ class ActivityController extends Controller { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $builder = $dataBuilder['builder']; - $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', + $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', 'duration', 'assign_hr_to_activity.id', 'm_version_gantt.name_version', 'm_users.name as user_name', DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning', 'assign_material_to_activity.id as join_third_id') ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') - ->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') - ->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') - ->join('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') + ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') + ->leftJoin('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') + ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') ->groupBy("selfTable.id") ->groupBy("selfTable.name") @@ -560,6 +560,7 @@ class ActivityController extends Controller ->groupBy("m_users.name") ->groupBy("assign_material_to_activity.qty_planning") ->groupBy("assign_material_to_activity.id") + ->groupBy("assign_hr_to_activity.id") ->get(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); } diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 4ca00f8..b387c24 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -138,6 +138,8 @@ class UserToActivityController extends Controller $builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual')); $builder->groupBy("m_activity.id"); $builder->groupBy("selfTable.id"); + $builder->groupBy("selfTable.start_date"); + $builder->groupBy("selfTable.end_date"); $builder->groupBy("m_users.name"); $builder->groupBy("assign_material_to_activity.id"); $builder->groupBy("m_version_gantt.name_version"); From d6bbd6d75d84cadbe9aca539523566ac7bc277d4 Mon Sep 17 00:00:00 2001 From: wahyu Date: Mon, 30 Oct 2023 18:22:40 +0700 Subject: [PATCH 239/252] update actual start --- 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 3375682..ea48586 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -187,7 +187,7 @@ class ActivityController extends Controller $actualStartValues = array_column(array_filter($dataFinal, function($item) { return isset($item['actual_start']); }), 'actual_start'); - $returnActualStartOrEnd = min($actualStartValues); + $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; if (isset($parent)) { $parent->actual_start = $returnActualStartOrEnd; $parent->save(); From 4e69d7c35c8315fdeb0226d867d26260bc8fd454 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 31 Oct 2023 10:55:26 +0700 Subject: [PATCH 240/252] update dashboard bod --- app/Helpers/MasterFunctionsHelper.php | 2 +- app/Http/Controllers/DashboardBoDController.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 52708e6..d1c2c47 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -310,7 +310,7 @@ class MasterFunctionsHelper ->groupBy('activity_id') ->first(); $weekCount = $keyPlanM->duration / 7; - $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; + $weeklyPlan = $weekCount > 0 ? $sumVolPlan->ttl_qty_plan / $weekCount : 0; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 2de808e..deb8065 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -136,6 +136,9 @@ class DashboardBoDController extends Controller foreach ($projects as $index => $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $selisihProgress = 0; + $planningProgress = 0; + $actualProgress = 0; + if ($project->scurve && $project->scurve[0]) { $planningArray = $project->scurve[0]['data']['percentagePlan']; $actualArray = $project->scurve[0]['data']['percentageReal']; @@ -178,6 +181,9 @@ class DashboardBoDController extends Controller foreach ($projects as $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $selisihProgress = 0; + $planningProgress = 0; + $actualProgress = 0; + if ($project->scurve && $project->scurve[0]) { $planningArray = $project->scurve[0]['data']['percentagePlan']; $actualArray = $project->scurve[0]['data']['percentageReal']; From 2923ec649f9122cc7d5f5353738f27a26d4e2004 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 1 Nov 2023 16:00:55 +0700 Subject: [PATCH 241/252] update estimated finish --- app/Http/Controllers/ProjectController.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 39042ec..6540e1a 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -45,7 +45,7 @@ class ProjectController extends Controller { $this->validate($request, [ 'nama' => 'required', - 'mulai_proyek' => 'required', + 'mulai_proyek' => 'required', 'akhir_proyek' => 'required', 'rencana_biaya' => 'required', 'type_proyek_id' => 'required' @@ -519,12 +519,12 @@ class ProjectController extends Controller 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(); + $actualEndExist = Activity::where('proyek_id', $id)->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(); + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); $query = Activity::where('version_gantt_id', $ganttId); } @@ -533,11 +533,10 @@ class ProjectController extends Controller } 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'); + if($actualEndExist) + { + $maxEndDate = $query->max('id'); + $endDate = $query->where('id',$maxEndDate)->first()->end_date; } $plannedStart = Activity::where('version_gantt_id', $ganttId) From c6452c9cc231b106ecc748b708c55abdc0112d1d Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 2 Nov 2023 09:11:48 +0700 Subject: [PATCH 242/252] update report analysis --- 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 ea48586..16ccb60 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -544,8 +544,8 @@ class ActivityController extends Controller { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $builder = $dataBuilder['builder']; - $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', 'duration', 'assign_hr_to_activity.id', - 'm_version_gantt.name_version', 'm_users.name as user_name', + $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', 'duration', + 'm_version_gantt.name_version', DB::raw('STRING_AGG(m_users.name, \',\') as user_name'), DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning', 'assign_material_to_activity.id as join_third_id') ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') @@ -557,10 +557,8 @@ class ActivityController extends Controller ->groupBy("selfTable.name") ->groupBy("selfTable.persentase_progress") ->groupBy("m_version_gantt.name_version") - ->groupBy("m_users.name") ->groupBy("assign_material_to_activity.qty_planning") ->groupBy("assign_material_to_activity.id") - ->groupBy("assign_hr_to_activity.id") ->get(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); } From 228c7db9f8c4814b64e4bf94062b0af6997b6de8 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 2 Nov 2023 10:54:51 +0700 Subject: [PATCH 243/252] update dashboard bod --- app/Helpers/MasterFunctionsHelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index d1c2c47..53f0be8 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -852,6 +852,7 @@ class MasterFunctionsHelper $arr_ActualM = []; $tempDate = []; + $tempPercentage = []; $tempPercentagePlan = []; $tempPercentagePlanWhr = []; $tempPercentageReal = []; @@ -860,7 +861,8 @@ class MasterFunctionsHelper $currentACWP = 0; $currentBCWP = 0; - + $totalACWP = 0; + $totalBCWP = 0; foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); From 5f73a147ea82f3cf83a77e5f8e2f6d8a05f33118 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Thu, 2 Nov 2023 12:15:24 +0700 Subject: [PATCH 244/252] update condition type proyek --- app/Http/Controllers/ProjectController.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 6540e1a..42bcb6d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -519,8 +519,14 @@ class ProjectController extends Controller 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)->exists(); - $query = Activity::where('proyek_id', $id); + if($result['type_proyek_id'] === 9) + { + $actualEndExist = Activity::where('proyek_id', $id)->exists(); + $query = Activity::where('proyek_id', $id); + }else{ + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); + $query = Activity::where('version_gantt_id', $ganttId); + } } 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(); From 60fe1064a58232296400293d554b32c5c2b402d4 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 2 Nov 2023 13:02:51 +0700 Subject: [PATCH 245/252] update string agg --- app/Http/Controllers/ActivityController.php | 46 ++++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 16ccb60..70e84ff 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -544,22 +544,36 @@ class ActivityController extends Controller { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $builder = $dataBuilder['builder']; - $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', 'duration', - 'm_version_gantt.name_version', DB::raw('STRING_AGG(m_users.name, \',\') as user_name'), - DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning', - 'assign_material_to_activity.id as join_third_id') - ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') - ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') - ->leftJoin('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') - ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') - ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') - ->groupBy("selfTable.id") - ->groupBy("selfTable.name") - ->groupBy("selfTable.persentase_progress") - ->groupBy("m_version_gantt.name_version") - ->groupBy("assign_material_to_activity.qty_planning") - ->groupBy("assign_material_to_activity.id") - ->get(); + $dataGet = $builder->select( + 'selfTable.name', + 'persentase_progress', + 'selfTable.start_date', + 'selfTable.end_date', + 'duration', + 'm_version_gantt.name_version', + DB::raw('user_names.user_name as user_name'), + DB::raw('SUM(report_activity_material.qty) as qty'), + 'assign_material_to_activity.qty_planning', + 'assign_material_to_activity.id as join_third_id' + ) + ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') + ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') + ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') + ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') + ->leftJoin(DB::raw('(SELECT activity_id, STRING_AGG(m_users.name, \',\') as user_name + FROM assign_hr_to_activity + LEFT JOIN m_users ON assign_hr_to_activity.user_id = m_users.id + GROUP BY activity_id) as user_names'), function ($join) { + $join->on('user_names.activity_id', '=', 'selfTable.id'); + }) + ->groupBy('selfTable.id') + ->groupBy('selfTable.name') + ->groupBy('selfTable.persentase_progress') + ->groupBy('m_version_gantt.name_version') + ->groupBy('assign_material_to_activity.qty_planning') + ->groupBy('assign_material_to_activity.id') + ->groupBy('user_names.user_name') + ->get(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); } // before upload file From 69a48a16d802e5cfa29e6d6da1bd73616b92b92c Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 2 Nov 2023 16:28:48 +0700 Subject: [PATCH 246/252] update report analysis activity --- app/Http/Controllers/ActivityController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 70e84ff..733ee1d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -549,6 +549,10 @@ class ActivityController extends Controller 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', + 'selfTable.planned_start', + 'selfTable.planned_end', + 'selfTable.actual_start', + 'selfTable.actual_end', 'duration', 'm_version_gantt.name_version', DB::raw('user_names.user_name as user_name'), From 60b9eb39d122d1bed4a959c529b81e7595b3c469 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 13 Nov 2023 11:23:36 +0700 Subject: [PATCH 247/252] handle delete project --- app/Http/Controllers/ProjectController.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 42bcb6d..ca92810 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -9,13 +9,17 @@ use App\Models\Image; use App\Models\Holiday; use App\Models\Project; use App\Models\Activity; +use App\Models\ReportK3; use App\Jobs\ProcessSCurve; +use App\Models\AssignTools; use App\Models\OfficeHours; use App\Models\ProjectType; use App\Models\ProjectPhase; +use App\Models\ProjectRisks; use App\Models\UserToProyek; use App\Models\VersionGantt; use Illuminate\Http\Request; +use App\Models\HierarchyFtth; use App\Models\ProjectIssues; use App\Models\AssignMaterial; use App\Models\DokumenProject; @@ -26,13 +30,14 @@ use App\Models\UserToActivity; use App\Models\ActivityDokumen; use App\Models\CommentActivity; use App\Models\ProjectApproval; +use App\Models\RequestMaterial; use App\Models\ProjectMileStone; use App\Models\ProjectChecklists; use Illuminate\Support\Facades\DB; use App\Models\ProjectParticipants; use App\Models\FolderDocumentProyek; +use App\Models\ProjectToChecklistK3; use App\Helpers\MasterFunctionsHelper; -use App\Models\ProjectRisks; use App\Models\ReportActivityMaterial; use Illuminate\Support\Facades\Artisan; @@ -163,6 +168,12 @@ class ProjectController extends Controller ProjectChecklists::where('proyek_id', $project_id)->delete(); ProjectIssues::where('proyek_id', $project_id)->delete(); ProjectRisks::where('proyek_id', $project_id)->delete(); + ProjectToChecklistK3::where('proyek_id', $project_id)->delete(); + HierarchyFtth::where('project_id', $project_id)->delete(); + AssignTools::where('proyek_id', $project_id)->delete(); + OfficeHours::where('proyek_id', $project_id)->delete(); + ReportK3::where('proyek_id', $project_id)->delete(); + RequestMaterial::where('proyek_id', $project_id)->delete(); $this->deleteVersionGantt($project_id); $this->deleteDokumenProject($project_id); } From a90e077b9b58f88b68bc7573927be27c0f3fc237 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 13 Nov 2023 15:50:03 +0700 Subject: [PATCH 248/252] handle delete Gantt --- .../Controllers/VersionGanttController.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index c3fe398..c5fabab 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -2,8 +2,15 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Models\Link; +use App\Models\Holiday; +use App\Models\Activity; use App\Models\VersionGantt; +use Illuminate\Http\Request; +use App\Models\ShowHideColumn; +use App\Models\UserToActivity; +use App\Models\UserToVersionGantt; +use App\Models\ActivityProgressLog; class VersionGanttController extends Controller { @@ -49,6 +56,7 @@ class VersionGanttController extends Controller if($data){ $delete = $data->delete(); + $this->deleteRelative($data['id']); }else{ return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400); die(); @@ -62,6 +70,17 @@ class VersionGanttController extends Controller } } + private function deleteRelative($version_gantt_id) + { + UserToActivity::where('version_gantt_id', $version_gantt_id)->delete(); + Activity::where('version_gantt_id', $version_gantt_id)->delete(); + ShowHideColumn::where('version_gantt_id', $version_gantt_id)->delete(); + Link::where('version_gantt_id', $version_gantt_id)->delete(); + UserToVersionGantt::where('version_gantt_id', $version_gantt_id)->delete(); + Holiday::where('version_gantt_id', $version_gantt_id)->delete(); + ActivityProgressLog::where('version_gantt_id', $version_gantt_id)->delete(); + } + public function edit($id){ if(!$id || (int) $id < 0 || $id==""){ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); From 2bc036ac37492ae420b51e410ee6bdc56d319f4e Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 13 Nov 2023 17:21:43 +0700 Subject: [PATCH 249/252] handle delete activity --- app/Http/Controllers/ActivityController.php | 34 +++++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 733ee1d..21dc80c 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -1,22 +1,23 @@ json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); - + $this->deleteRelative($id); if (!$data->delete()) return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); } + private function deleteRelative($activity_id) + { + UserToActivity::where('activity_id', $activity_id)->delete(); + AssignMaterial::where('activity_id', $activity_id)->delete(); + $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); + foreach ($dataAd as $ad) { + if(file_exists($this->pathActivityDocument.$ad->file)){ + unlink($this->pathActivityDocument.$ad->file); + } + } + ActivityDokumen::where("activity_id", $activity_id)->delete(); + } + public function getUpdate($id) { if (!$data = Activity::find($id)) From 8b8ee50e45f62387f0fc0113c9446fd623711fef Mon Sep 17 00:00:00 2001 From: wahyuun Date: Tue, 21 Nov 2023 10:01:18 +0700 Subject: [PATCH 250/252] add getSCurveCarausell method --- app/Helpers/MasterFunctionsHelper.php | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 53f0be8..8448e3c 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -106,6 +106,35 @@ class MasterFunctionsHelper } } } + public static function getSCurveCarausell($request) + { + $allGantt = []; + if (!is_int($request->gantt_id) && !is_int($request->project_id) && !is_int($request->period)) { + if (isset($request->gantt_id)) { + $allGantt[] = $request->gantt_id; + } else { + $allGantt[] = MasterFunctionsHelper::getLatestGantt($request->project_id); + } + } else { + $allGantt[] = MasterFunctionsHelper::getLatestGantt($request->project_id); + } + foreach ($allGantt as $gantt) { + if (!isset($gantt['last_gantt_id'])) { + $ganttId = $gantt; + } else { + $ganttId = $gantt['last_gantt_id']; + } + $gantt = VersionGantt::find($ganttId)->toArray(); + 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) { From 2257469b848174d3e58aa6a8bf32c873ffd503a5 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Tue, 21 Nov 2023 10:02:44 +0700 Subject: [PATCH 251/252] create file --- .../ProjectCarausellController.php | 355 ++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 app/Http/Controllers/ProjectCarausellController.php diff --git a/app/Http/Controllers/ProjectCarausellController.php b/app/Http/Controllers/ProjectCarausellController.php new file mode 100644 index 0000000..7c2eb06 --- /dev/null +++ b/app/Http/Controllers/ProjectCarausellController.php @@ -0,0 +1,355 @@ +startOfDay(); + // $dateEnd = Carbon::now()->endOfDay(); + // // Mengatur waktu awal bulan dan mengurangkan 1 tahun + // $startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d'); + // // Mengatur waktu saat ini dan mengurangkan 1 tahun + // $endDate = Carbon::now()->subYear()->format('Y-m-d'); + + // if(empty($id) || !is_int((int)$id)){ + // return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + // } + + // $result = Project::select('id','nama','budget_health','kode_sortname','pm_id','rencana_biaya','company','scurve','calculation_status')->find($id); + // if(!$result){ + // return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); + // } + // $ganttData = VersionGantt::where('proyek_id', $id) + // ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete') + // ->get(); + + // // Get Id Gantt & hierarchy_ftth_id + // $gantt_id = $ganttData->pluck('id')->toArray(); + // $hierarchy_ftth_id = $ganttData->pluck('hierarchy_ftth_id')->toArray(); + + // // Heararchy + // $finalData = []; + // if($hierarchy_ftth_id){ + // $ftth = HierarchyFtth::whereIn('id',$hierarchy_ftth_id)->get(); + // if($ftth->first() != null) + // { + // array_push($finalData, $ftth->first()); + // } + // if($ftth->where('parent_id','!=', null)->first()){ + // $this->getParents($finalData, $ftth->pluck('parent_id')->toArray()); + // } + // } else { + // return $finalData; + // } + + // // SCurve + // $SCurve = MasterFunctionsHelper::getSCurveCarausell($result['id'],$gantt_id,'week'); + + // // Overdue Activities + // $endDate = Activity::where('proyek_id', $result['id']) + // ->orderByDesc('end_date') + // ->value('end_date'); + // $overdueActivities = Activity::whereIn('version_gantt_id', $gantt_id)->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); + + // // Project Comment + // $projectComment = ProjectComment::query() + // ->select('project_id','gantt_id','comment','created_at') + // ->where('project_id',$result['id']) + // ->whereIn('gantt_id',$gantt_id) + // ->get(); + + // // Manpower + // $manCount = UserToProyek::where('proyek_id', $result['id'])->count(); + // // Assigned + // $utAct = UserToActivity::query() + // ->whereIn('version_gantt_id', $gantt_id) + // ->get(); + // // Actual + // $presence = Presence::whereBetween('clock_in', [$dateStart, $dateEnd]) + // ->select('m_users.name','m_users.ktp_number') + // ->join('m_users','t_clock_in_out.user_id','m_users.id') + // ->get(); + + // // Report distribution + // $reportsDistribution = 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', '=', $result['id']) + // ->whereNotNull('ram.lat') + // ->whereBetween('ram.report_date', [$startDate, $startDate]); + + // // Check Existing + // $actualStartExist = Activity::whereIn('version_gantt_id',$gantt_id)->whereNotNull('actual_start')->exists(); + // $actualEndExist = Activity::whereIn('version_gantt_id',$gantt_id)->exists(); + + // $query = Activity::query()->whereIn('version_gantt_id', $gantt_id); + // // Start + // if ($actualStartExist) { + // $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start')) + // ->groupBy('version_gantt_id') + // ->get(); + // } else { + // $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start','version_gantt_id')) + // ->groupBy('version_gantt_id') + // ->orderBy('min_start', 'ASC') + // ->get(); + // } + // // End + // if($actualEndExist) + // { + // $maxIds = $query->selectRaw('MAX(id) as max_id') + // ->groupBy('version_gantt_id') + // ->pluck('max_id', 'version_gantt_id'); + + // $endDate = Activity::whereIn('id', $maxIds)->select('end_date','version_gantt_id')->get(); + // } + + // $plannedStart = $query->selectRaw('MIN(planned_start) as min_planned_start, version_gantt_id') + // ->groupBy('version_gantt_id') + // ->orderBy('min_planned_start') + // ->get(); + // $plannedEnd = $query->selectRaw('MAX(planned_end) as max_planned_end, version_gantt_id') + // ->groupBy('version_gantt_id') + // ->orderByDesc('max_planned_end') + // ->get(); + + // $projectManager = User::whereId($result['pm_id'])->value('name'); + // $key =1; + // foreach($ganttData as $gantt) + // { + // $pStart =$plannedStart->where('version_gantt_id',$gantt['id'])->first(); + // $actStart =$startDate->where('version_gantt_id',$gantt['id'])->first(); + // $actEnd =$endDate->where('version_gantt_id',$gantt['id'])->first(); + // $pEnd =$plannedEnd->where('version_gantt_id',$gantt['id'])->first(); + // $matchingActivities = $overdueActivities->where('version_gantt_id', $gantt['id']); + // $matchingProjectComment = $projectComment->where('version_gantt_id', $gantt['id']); + // $usAtc = $utAct->where('version_gantt_id', $gantt['id']); + // $arr[] = + // [ + // 'gantt_id'=>$gantt['id'], + // 'projectManager'=>$projectManager, + // 'name_version'=>$gantt['name_version'], + // 'cost_to_complete'=>$gantt['cost_to_complete'], + // 'schedule' => [ + // 'plannedStart'=> $pStart['min_planned_start'], + // 'actual_start'=>$actStart['min_start'], + // 'plannedFinish'=>$pEnd['max_planned_end'], + // 'estimatedFinish'=>$actEnd['end_date'] + // ], + // 'manpower'=>$manCount, + // 'assigned'=>$usAtc->toArray(), + // 'actual'=>count($presence->toArray()), + // 'overdue_activities'=>$matchingActivities->toArray(), + // 'project_comment'=>$matchingProjectComment->toArray(), + // 'hierarchy'=>$finalData, + // 'proyek'=>$result, + // 'key'=>$key++ + // ]; + // } + // return response()->json(['status'=>'success','code'=> 200,'data'=>$arr,'report_distribution'=>$reportsDistribution,'sCurve'=>$SCurve, 'count'=>count($arr)], 200); + // } + + // public function getParents(&$data, $id){ + // $ftth = HierarchyFtth::whereIn('id',$id)->get(); + // array_push($data, $ftth); + // if ($ftth->pluck('parent_id')->toArray()) { + // $this->getParents($data, $ftth->pluck('parent_id')->toArray()); + // } + // } + + public function invoke() + { + // Data Master + // Mengatur waktu awal bulan dan mengurangkan 1 tahun + $startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d'); + // Mengatur waktu saat ini dan mengurangkan 1 tahun + $endDate = Carbon::now()->subYear()->format('Y-m-d'); + $ganttData = VersionGantt::query() + ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id') + ->get(); + $projectData = Project::query() + ->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve") + ->get(); + // nested looping + $arr = []; + foreach($projectData as $project) { + $ganttForProject = []; + foreach ($ganttData as $gantt) { + if ($gantt['proyek_id'] === $project['id']) { + // Gantt + $ganttForProject[] = [ + "gantt_id" => $gantt['id'], + 'proyek_id' => $gantt['proyek_id'], + "name_version" => $gantt['name_version'], + "hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'], + "cost_to_complete" => $gantt['cost_to_complete'], + ]; + // Activity + $activity = Activity::query() + ->select('id','name','proyek_id','version_gantt_id','type_activity','parent_id','kode_sortname','rencana_biaya','start_date','end_date','biaya_actual','persentase_bobot','persentase_progress','planned_start','planned_end','actual_start','actual_end') + ->whereNull('parent_id') + ->where([ + ["proyek_id", $project['id']], + ["version_gantt_id", $gantt['id']] + ]) + ->first(); + $actualStartExist = Activity::query() + ->where('version_gantt_id', $gantt['id']) + ->whereNotNull('actual_start') + ->exists(); + $actualEndExist = Activity::query() + ->where('version_gantt_id', $gantt['id']) + ->exists(); + $query = Activity::where('version_gantt_id', $gantt['id']); + + if ($actualStartExist) { + $startDate = $query->orderBy('actual_start')->value('start_date'); + } else { + $startDate = $query->orderBy('start_date')->value('start_date'); + } + if($actualEndExist) + { + $maxEndDate = $query->max('id'); + $endDate = $query->where('id',$maxEndDate)->first()->end_date; + } + + $plannedStart = Activity::where('version_gantt_id', $gantt['id']) + ->orderBy('planned_start') + ->value('planned_start'); + $plannedEnd = Activity::where('version_gantt_id', $gantt['id']) + ->orderByDesc('planned_end') + ->value('planned_end'); + + // SCurve + $req = (object)[ + 'project_id' => $project['id'], + 'gantt_id' => $gantt['id'], + 'period' => 'week', + ]; + $SCurve = MasterFunctionsHelper::getSCurveCarausell($req); + + // Overdue + $endDate = Activity::where('proyek_id', $project['id']) + ->orderByDesc('end_date') + ->value('end_date'); + $overdueActivities = Activity::query() + ->where([ + ['version_gantt_id', $gantt['id']], + ['persentase_progress', '!=', 100] + ]) + ->whereNotNull('parent_id') + ->whereDate('end_date','<=',$endDate) + ->orderBy('end_date', 'asc') + ->get(); + + // Manpower + $manCount = UserToProyek::where('proyek_id', $project['id'])->count(); + // Assigned + $assigned = UserToActivity::query() + ->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(); + // Project Comment + $projectComment = ProjectComment::query() + ->select('m_users.name','m_users.username','m_project_comment.project_id','m_project_comment.gantt_id','m_project_comment.comment','m_project_comment.created_at') + ->join('m_users','m_project_comment.sender_id','m_users.id') + ->where([ + ['project_id',$project['id']], + ['gantt_id',$gantt['id']] + ]) + ->get(); + // Hierarchy + $finalData = []; + $ganttHierarchy = VersionGantt::find($gantt['id']); + if ($ganttHierarchy->hierarchy_ftth_id) { + $ftth = HierarchyFtth::find($ganttHierarchy->hierarchy_ftth_id); + array_push($finalData, $ftth); + if($ftth->parent_id){ + $this->getParents($finalData, $ftth->parent_id); + } + }else{ + $finalData = $finalData; + } + + $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', '=', $project['id']) + ->whereNotNull('ram.lat') + ->whereBetween('ram.report_date', [$startDate, $endDate]); + } + } + + $projectManager = User::where('id', $project['pm_id'])->value('name'); + + $arr[]= [ + "project"=> [ + "id"=>$project['id'], + "pm_id"=>$project['pm_id'], + "nama"=>$project['nama'], + "kode_sortname"=>$project['kode_sortname'], + "budget_health"=>$project['budget_health'], + "calculation_status"=>$project['calculation_status'], + "mulai_proyek"=>$project['mulai_proyek'], + "akhir_proyek"=>$project['akhir_proyek'], + "rencana_biaya"=>$project['rencana_biaya'], + "company"=>$project['company'], + "scurve"=>$project['scurve'], + "gantt"=>$ganttForProject + ], + "hierarchy"=>$finalData, + "manpower"=>$manCount, + "assigned"=>$assigned, + "actual"=>0, + "project_comment"=>$projectComment, + "project_manager"=> $projectManager, + "activity" => [ + "data" => $activity, + "start_date"=>$startDate, + "end_date"=>$endDate, + "planned_start"=>$plannedStart, + "planned_end"=>$plannedEnd + ], + "report_distribution"=>$reports, + "overdueActivities"=>$overdueActivities, + "SCurve"=>$SCurve + ]; + } + return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "count"=>count($arr)], 200); + } + + public function getParents(&$data, $id){ + $ftth = HierarchyFtth::find($id); + array_push($data, $ftth); + if ($ftth->parent_id) { + $this->getParents($data, $ftth->parent_id); + } + } +} From 08a37beeb8b8b30bfeee86f5f4a1edf9e86cb25a Mon Sep 17 00:00:00 2001 From: wahyuun Date: Tue, 21 Nov 2023 10:03:24 +0700 Subject: [PATCH 252/252] create endpoint --- routes/web.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/web.php b/routes/web.php index f9e79b4..816c9cf 100644 --- a/routes/web.php +++ b/routes/web.php @@ -79,6 +79,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout /* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */ /* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */ + $router->get('/project-carausell','ProjectCarausellController@invoke'); $router->post('/project-charter/search', 'ProjectCharterController@search'); $router->post('/project-charter/add', 'ProjectCharterController@add');