From c75350c46681f6592ce8de7178c8df146b002ae7 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 21 Aug 2023 16:10:58 +0700 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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);