From eee1bdcfc1292cee5204ac9ed33d94529b57c0fa Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 7 Aug 2023 09:33:26 +0700 Subject: [PATCH] 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();