From 4ca0f1105e78075d1e23a9494b186b332b5fea01 Mon Sep 17 00:00:00 2001 From: ibnu Date: Sun, 12 Feb 2023 15:16:59 +0700 Subject: [PATCH 1/3] update sample presence --- rest-client.http | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/rest-client.http b/rest-client.http index a7a710b..e7b5a5a 100644 --- a/rest-client.http +++ b/rest-client.http @@ -796,22 +796,31 @@ GET {{hostname}}/presence/clockinout/262 Authorization: Bearer {{token}} content-type: application/json -####### -"clock_out_lat": -1.4264273154149407, - "clock_out_lng": 113.98530036945851, ###### POST {{hostname}}/presence/add Authorization: Bearer {{token}} content-type: application/json { - "clock_out_lat": -6.2622811, - "clock_out_lng": 106.7881746, + "clock_in_lat": -6.2622811, + "clock_in_lng": 106.7881746, "clock_time": "2023-02-06T16:40:17+07:00", - "type": "out", + "type": "in", "user_id": 1 } +###### +POST {{hostname}}/presence/add +Authorization: Bearer {{token}} +content-type: application/json + +{ + "clock_out_lat": -1.4264273154149407, + "clock_out_lng": 113.98530036945851, + "clock_time": "2023-02-06T16:40:17+07:00", + "type": "in", + "user_id": 1 +} ###### # POST {{hostname}}/ From fb674e529e753fdacda70272ba1c58d19363d229 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 14 Feb 2023 01:42:45 +0700 Subject: [PATCH 2/3] update presensi add policy boundary --- app/Http/Controllers/PresenceController.php | 196 +++++++++++--------- rest-client.http | 8 +- 2 files changed, 113 insertions(+), 91 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 5dafe10..a472138 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -5,9 +5,9 @@ namespace App\Http\Controllers; use Log; use Illuminate\Http\Request; use App\Models\Presence; -use App\Models\Activity; -use GuzzleHttp\Client; -use Illuminate\Support\Facades\Http; +// use App\Models\Activity; +// use GuzzleHttp\Client; +// use Illuminate\Support\Facades\Http; use Carbon\Carbon; use Illuminate\Support\Facades\DB; @@ -24,86 +24,102 @@ class PresenceController extends Controller $date = date_create($request->clock_time); // $ActivityId = null; if(count($checkLocation) > 0){ - $statusBoundary = true; + $checkLocation[0]['status_assign'] ? $statusBoundary = true + : $statusBoundary = false; } - 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 + if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == null){ + $data=array( + 'id' => null, + '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(); + return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200); } - $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); + if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == null){ + $data=array( + 'id' => null, + 'boundary' => $statusBoundary + ); + 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); + // } } private function checkLocation($params){ @@ -128,11 +144,25 @@ class PresenceController extends Controller if($key->boundary){ $temp[]=array( "activity_id" => $dataGeom->id, - "boundary" => $key->boundary + "boundary" => $key->boundary, + "status_assign" => true ); - } + } + } + if(count($temp) < 1){ + $temp[]=array( + "activity_id" => null, + "boundary" => null, + "status_assign" => true + ); } } + }else{ + $temp[]=array( + "activity_id" => null, + "boundary" => null, + "status_assign" => false + ); } return $temp; } @@ -152,14 +182,10 @@ class PresenceController extends Controller } } - - 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"); @@ -199,10 +225,8 @@ class PresenceController extends Controller 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") @@ -237,7 +261,6 @@ class PresenceController extends Controller die(); } - if($result){ return response()->json(['status'=>'success','message'=>'data presence successfully updated!','code'=>200], 200); }else{ @@ -256,7 +279,6 @@ class PresenceController extends Controller die(); } - if($delete){ return response()->json(['status'=>'success','message'=>'data presence successfully deleted!','code'=>200], 200); }else{ diff --git a/rest-client.http b/rest-client.http index 416c9b0..120334f 100644 --- a/rest-client.http +++ b/rest-client.http @@ -1,12 +1,12 @@ -@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA3NFwvYWR3LWJhY2tlbmRcL2FwaVwvbG9naW4iLCJpYXQiOjE2NzYxODQ5ODgsImV4cCI6MTY3Njc4OTc4OCwibmJmIjoxNjc2MTg0OTg4LCJqdGkiOiJSMkk1R3FLdXM3bWhMUWwzIiwic3ViIjoxMjQ3LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.GlxG-DaiY1Slc0dR8sRK6CvU-F7MTjT47989MImubJ0 +@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODQ0NFwvYXBpXC9sb2dpbiIsImlhdCI6MTY3NjI5MTQwNiwiZXhwIjoxNjc2ODk2MjA2LCJuYmYiOjE2NzYyOTE0MDYsImp0aSI6IkNNRVNGMEcwVzVNQlRLenoiLCJzdWIiOjEyNDcsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.ZV2ncAf6H61vnK7fmg-bMfeqBTcxm0aFE5zs_4tor8g # @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:8074/adw-backend/api +# @hostname = http://localhost:8444/adw-ba/api ###### login POST {{hostname}}/login @@ -817,7 +817,7 @@ content-type: application/json { "clock_out_lat": -1.4264273154149407, "clock_out_lng": 113.98530036945851, - "clock_time": "2023-02-06T16:40:17+07:00", + "clock_time": "2023-02-13T16:40:17+07:00", "type": "in", "user_id": 1 } From f4f7e15ea05d6888f65f22a1212b69b9d4985b9c Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 14 Feb 2023 02:46:01 +0700 Subject: [PATCH 3/3] update presensi --- app/Http/Controllers/PresenceController.php | 142 ++++++++++---------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index a472138..0e844d0 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -44,82 +44,82 @@ class PresenceController extends Controller 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 - // ); + 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 - // ); + $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(); - // } + 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; + $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 - // ); + $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); - // } + $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); + } } private function checkLocation($params){