From 19049cb71fd41aa3e24f65eb861de2ce7e39c34c Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 8 Feb 2023 17:13:03 +0700 Subject: [PATCH 1/6] done cico with check geotagging --- app/Http/Controllers/PresenceController.php | 89 ++++++++++++++++----- app/Models/Presence.php | 3 +- 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 192abea..a2664b4 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -15,14 +15,17 @@ class PresenceController extends Controller { public function add(Request $request) { - - // - // $test = $this->checkLocation($request); - // return response()->json(['status'=>$test,'code'=>200], 200); $this->validate($request, [ 'user_id' => 'required' ]); - + + $checkLocation = $this->checkLocation($request); + $statusBoundary = false; + $date = date_create($request->clock_time); + // $ActivityId = null; + if(count($checkLocation) > 0){ + $statusBoundary = true; + } if($request->type=="out"){ @@ -32,12 +35,31 @@ class PresenceController extends Controller "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_loc" => $clock_out_loc, + "clock_out_boundary" => $statusBoundary ); $resultUpdate = $this->updateFormAdd($dataUpdate, $request->user_id); if($resultUpdate && $resultUpdate > 0){ - return response()->json(['status'=>'success', 'id'=>$resultUpdate,'message'=>'clock out success!','code'=>200], 200); + 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); @@ -45,35 +67,46 @@ class PresenceController extends Controller die(); } - $date = date_create($request->clock_time); $onlyDate = date_format($date,"Y-m-d"); - $clock_in_loc = "-"; $dataAdd = array( 'user_id'=> $request->user_id, 'clock_in'=> $request->clock_time, 'date_presence'=> $onlyDate, - 'created_by' =>$this->currentName, + '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_loc' => $clock_in_loc, + 'clock_in_boundary' => $statusBoundary ); $result = Presence::create($dataAdd); - $data=array( 'id' => $result->id, - 'boundary' => true + 'boundary' => $statusBoundary ); - - if($result){ + 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); } } + private function checkLocation($params){ // cek user tersebut apakah punya assign task yang ada bondary nya // geom ada di table activity @@ -82,12 +115,27 @@ class PresenceController extends Controller ->where("ahta.user_id", $params->user_id) ->whereDate("ma.start_date", "<=", $params->clock_time) ->whereDate("ma.end_date", ">=", $params->clock_time) - ->where(DB::raw("ST_Intersects(ST_GeomFromGeoJSON('ma.geom'), ST_GeomFromText('POINT(".$params->clock_out_lng." ".$params->clock_out_lat.")', 4326))")) ->get(); - // Activity::select('geom')->where(''); - // gejson to geom - // intersect dengan point req - return $geom; + $temp = []; + foreach($geom as $dataGeom){ + $valGeom = json_decode($dataGeom->geom); + if($params->type=="out"){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_out_lng." ".$params->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_lng." ".$params->clock_in_lat.")', 4326)) as boundary")); + } + foreach ($check as $key) { + if($key->boundary){ + $temp[]=array( + "activity_id" => $dataGeom->id, + "boundary" => $key->boundary + ); + } + } + + + } + return $temp; } public function edit($id){ @@ -151,7 +199,6 @@ class PresenceController extends Controller } private function updateFormAdd($data, $id){ - $date = date_create($data['clock_out']); $onlyDate = date_format($date,"Y-m-d"); diff --git a/app/Models/Presence.php b/app/Models/Presence.php index e5276cc..620a91e 100644 --- a/app/Models/Presence.php +++ b/app/Models/Presence.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\DB; class Presence extends Model { @@ -14,7 +15,7 @@ class Presence extends Model protected $fillable = [ 'user_id', 'clock_in', 'clock_out', 'date_presence', 'clock_in_lat', 'clock_in_lng', 'clock_out_lat', 'clock_out_lng', - 'clock_in_loc', 'clock_out_loc', + 'clock_in_loc', 'clock_out_loc','clock_in_boundary', 'clock_out_boundary', 'created_at', 'created_by', 'updated_at', 'updated_by' ]; } From f060db4539bb8e6bb603e895f665c519f2a8311a Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 8 Feb 2023 17:13:45 +0700 Subject: [PATCH 2/6] done cico with check geotagging --- rest-client.http | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/rest-client.http b/rest-client.http index 6417009..29a58e5 100644 --- a/rest-client.http +++ b/rest-client.http @@ -1,22 +1,21 @@ -@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLXN0YWdpbmctYWR3Lm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjU5NDc0MDY3LCJleHAiOjE2NjAwNzg4NjcsIm5iZiI6MTY1OTQ3NDA2NywianRpIjoia0ljaHBFOEpiaFI0TjN3UyIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.PxGL0NcRtxzhG2J21Ca-zgMbr1anY7vhNzEOpZHSNOk +@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODQ0NFwvYXBpXC9sb2dpbiIsImlhdCI6MTY3NTgzNTM3NSwiZXhwIjoxNjc2NDQwMTc1LCJuYmYiOjE2NzU4MzUzNzUsImp0aSI6IlhyVjlkTW55TXpOazlrTUIiLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.41uAX7bnRwftkC_daRiVwwKcFIN7EDV0Ly_zDuq4_MY - -# @hostname = https://kit-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:8099/api +@hostname = http://localhost:8444/api # @hostname = http://103.73.125.81:8444/api ###### login POST {{hostname}}/login # Authorization: Bearer xxx -# X-REQUEST-TYPE: GraphQL +# X-REQUEST-TYPE: GraphQL 1123150023 content-type: application/json { "username": "admin", - "password": "admin123" + "password": "1nt3gr4s14" } ###### Tools Req @@ -798,15 +797,23 @@ content-type: application/json ###### - POST {{hostname}}/presence/add Authorization: Bearer {{token}} content-type: application/json { - "clock_out_lat": -6.2622811, - "clock_out_lng": 106.7881746, - "clock_time": "2022-04-25T16:40:17+07:00", - "type": "out", - "user_id": 262 -} \ No newline at end of file + "clock_in_lat": -6.2622811, + "clock_in_lng": 106.7881746, + "clock_time": "2023-02-06T16:40:17+07:00", + "type": "in", + "user_id": 1 +} + + +###### +# POST {{hostname}}/ + + +GET {{hostname}}/assign-material/datatablesForReportActivity?draw=2&columns[0][data]=material_name&columns[0][name]=material_name&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=type&columns[1][name]=type&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=qty_planning&columns[2][name]=&columns[2][searchable]=true&columns[2][orderable]=true&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=qty_sum&columns[3][name]=&columns[3][searchable]=true&columns[3][orderable]=true&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=uom&columns[4][name]=uom&columns[4][searchable]=true&columns[4][orderable]=true&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=action&columns[5][name]=action&columns[5][searchable]=true&columns[5][orderable]=true&columns[5][search][value]=&columns[5][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=10&search[value]=&search[regex]=false&idact=2511&_=1675418553660 +Authorization: Bearer {{token}} +content-type: application/json From efe6efcbd0147ffa80eb54f3e799caa196ae0ce1 Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 8 Feb 2023 22:00:06 +0700 Subject: [PATCH 3/6] update bug fix login --- app/Http/Controllers/AuthController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index d898cf9..bb31e8c 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -31,7 +31,7 @@ class AuthController extends Controller $usernameCheck = false; $passwordCheck = false; - if (User::where('username', $username)->exist()) + if (User::where('username', $username)->exists()) $usernameCheck = true; if (User::where('password', md5($password))->exists()) From 360015d90b09bd6bc3b24381b84cbdd87c00a555 Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 9 Feb 2023 12:07:35 +0700 Subject: [PATCH 4/6] update todo in presence, and update replace mandatory field parent in page divisi --- app/Http/Controllers/DivisiController.php | 4 ++-- app/Http/Controllers/PresenceController.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index ea7c3d4..aad3c90 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -20,8 +20,8 @@ class DivisiController extends Controller public function add(Request $request){ $this->validate($request, [ 'name' => 'required', - 'description' => 'string', - 'parent' => 'integer' + 'description' => 'string' + // 'parent' => 'integer' ]); $data = $request->all(); diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index a2664b4..5086ce1 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -28,7 +28,7 @@ class PresenceController extends Controller } if($request->type=="out"){ - + // $clock_out_loc get data from api.nominatim url serach address payload (lat lot); $clock_out_loc = "-"; $dataUpdate = array( "clock_out"=>$request->clock_time, @@ -69,6 +69,7 @@ class PresenceController extends Controller $onlyDate = date_format($date,"Y-m-d"); + // $clock_in_loc get data from api.nominatim url serach address payload (lat lot); $clock_in_loc = "-"; $dataAdd = array( From ff2e8bbc7618d59cb1bd6ae44df5bd06cc5cc000 Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 9 Feb 2023 12:10:19 +0700 Subject: [PATCH 5/6] add example hit api.nominatim --- rest-client.http | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rest-client.http b/rest-client.http index 5fc4e13..dae46c8 100644 --- a/rest-client.http +++ b/rest-client.http @@ -814,8 +814,26 @@ content-type: application/json ###### # POST {{hostname}}/ +GET {{hostname}}/assign-material/datatablesForReportActivity?draw=2&columns[0][data]=material_name&columns[0][name]=material_name&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=type&columns[1][name]=type&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=qty_planning&columns[2][name]=&columns[2][searchable]=true&columns[2][orderable]=true&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=qty_sum&columns[3][name]=&columns[3][searchable]=true&columns[3][orderable]=true&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=uom&columns[4][name]=uom&columns[4][searchable]=true&columns[4][orderable]=true&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=action&columns[5][name]=action&columns[5][searchable]=true&columns[5][orderable]=true&columns[5][search][value]=&columns[5][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=10&search[value]=&search[regex]=false&idact=2511&_=1675418553660 +Authorization: Bearer {{token}} +content-type: application/json +###### +GET {{hostname}}/dashboard/get-total-project-per-schedule-health +Authorization: Bearer {{token}} +content-type: application/json -GET {{hostname}}/assign-material/datatablesForReportActivity?draw=2&columns[0][data]=material_name&columns[0][name]=material_name&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=type&columns[1][name]=type&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=qty_planning&columns[2][name]=&columns[2][searchable]=true&columns[2][orderable]=true&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=qty_sum&columns[3][name]=&columns[3][searchable]=true&columns[3][orderable]=true&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=uom&columns[4][name]=uom&columns[4][searchable]=true&columns[4][orderable]=true&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=action&columns[5][name]=action&columns[5][searchable]=true&columns[5][orderable]=true&columns[5][search][value]=&columns[5][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=10&search[value]=&search[regex]=false&idact=2511&_=1675418553660 +###### +GET {{hostname}}/dashboard/get-detail-expenditure Authorization: Bearer {{token}} content-type: application/json + + +###### +GET {{hostname}}/presence/bulk-update-location +Authorization: Bearer {{token}} +content-type: application/json + + +##### +GET https://nominatim.oslogdev.com/reverse?lat=-6.2622811&lon=106.7881746&format=json \ No newline at end of file From d6ca4b1d0e97b04bbf6e8914cd9c7d0e83055a7f Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 9 Feb 2023 14:07:00 +0700 Subject: [PATCH 6/6] Display name clock in clock out --- app/Http/Controllers/Controller.php | 5 +++++ app/Http/Controllers/PresenceController.php | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 742db50..a1f786f 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -250,4 +250,9 @@ class Controller extends BaseController $totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost"); return $totalCost; } + + private function getLoc($lat, $lng){ + $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); + return $response; + } } diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index a2664b4..4c73a5b 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -274,7 +274,12 @@ class PresenceController extends Controller $dataGet = $builder->get(); $finalData = []; - + foreach($dataGet as $data){ + $responseIn = $this.getLoc($clock_in_lat, $clock_in_lng); + $responseOut = $this.getLoc($clock_in_lat, $clock_in_lng); + $data->clock_in_loc = $responseIn->json()["display_name"]; + $data->clock_out_loc = $responseOut->json()["display_name"]; + } $totalRecord = $countBuilder->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); }