Browse Source

update presence boundary

pull/3/head
ibnu 2 years ago
parent
commit
0f1bc0f32f
  1. 27
      app/Http/Controllers/PresenceController.php

27
app/Http/Controllers/PresenceController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Log; use Log;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Presence; use App\Models\Presence;
use App\Models\Activity;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Carbon\Carbon; use Carbon\Carbon;
@ -14,6 +15,10 @@ class PresenceController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
//
// $test = $this->checkLocation($request);
// return response()->json(['status'=>$test,'code'=>200], 200);
$this->validate($request, [ $this->validate($request, [
'user_id' => 'required' 'user_id' => 'required'
]); ]);
@ -58,12 +63,32 @@ class PresenceController extends Controller
$result = Presence::create($dataAdd); $result = Presence::create($dataAdd);
$data=array(
'id' => $result->id,
'boundary' => true
);
if($result){ 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{ }else{
return response()->json(['status'=>'failed','message'=>'clock in failed!','code'=>400], 400); 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){ public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $id==""){

Loading…
Cancel
Save