From 0f1bc0f32f3f148c2b6bb8797755556eb005ba62 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 7 Feb 2023 09:59:03 +0700 Subject: [PATCH] update presence boundary --- app/Http/Controllers/PresenceController.php | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 3feced9..192abea 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -5,6 +5,7 @@ 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 Carbon\Carbon; @@ -14,6 +15,10 @@ 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' ]); @@ -58,12 +63,32 @@ class PresenceController extends Controller $result = Presence::create($dataAdd); + $data=array( + 'id' => $result->id, + 'boundary' => true + ); + if($result){ - return response()->json(['status'=>'success', 'id'=>$result->id,'message'=>'clock in successfully!','code'=>200], 200); + 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 + $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") + ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") + ->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; + } public function edit($id){ if(!$id || (int) $id < 0 || $id==""){