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()) 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/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 192abea..7fe5ae3 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -15,29 +15,51 @@ 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"){ - + // $clock_out_loc get data from api.nominatim url serach address payload (lat lot); $clock_out_loc = "-"; $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_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,47 @@ class PresenceController extends Controller die(); } - $date = date_create($request->clock_time); $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( '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 +116,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 +200,6 @@ class PresenceController extends Controller } private function updateFormAdd($data, $id){ - $date = date_create($data['clock_out']); $onlyDate = date_format($date,"Y-m-d"); @@ -227,7 +275,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); } 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' ]; } diff --git a/rest-client.http b/rest-client.http index a27147a..a7a710b 100644 --- a/rest-client.http +++ b/rest-client.http @@ -1,20 +1,17 @@ -@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA3NFwvYWR3LWJhY2tlbmRcL2FwaVwvbG9naW4iLCJpYXQiOjE2NzU3NjY2NzcsImV4cCI6MTY3NjM3MTQ3NywibmJmIjoxNjc1NzY2Njc3LCJqdGkiOiJwODNpWG1kU3pTV2ZVMGs3Iiwic3ViIjoxMjQ3LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.I9Q6uI-IOHR8JKaMJfjfAizOM8KNPQsm8EyWM8f6Qbk +@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 -# @hostname = http://localhost:8074/adw-backend/api -@hostname = http://172.20.10.2:8074/adw-backend/api +# @hostname = http://172.20.10.2:8074/adw-backend/api ###### login POST {{hostname}}/login # Authorization: Bearer xxx -# X-REQUEST-TYPE: GraphQL +# X-REQUEST-TYPE: GraphQL 1123150023 content-type: application/json { @@ -799,9 +796,10 @@ 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 @@ -809,11 +807,38 @@ content-type: application/json { "clock_out_lat": -6.2622811, "clock_out_lng": 106.7881746, - "clock_time": "2022-04-25T16:40:17+07:00", + "clock_time": "2023-02-06T16:40:17+07:00", "type": "out", - "user_id": 262 + "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 + +###### +GET {{hostname}}/dashboard/get-total-project-per-schedule-health +Authorization: Bearer {{token}} +content-type: application/json + +###### +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 + ###### POST {{hostname}}/waypoint/add @@ -888,5 +913,4 @@ content-type: application/json "datesend": "2023-02-07T10:44:17+07:00" } ] -} - +} \ No newline at end of file