From 5afcf08a59272084c09903485ad9440f87588027 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 4 Aug 2023 13:31:23 +0700 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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 );