|
|
@ -15,14 +15,17 @@ 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' |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$checkLocation = $this->checkLocation($request); |
|
|
|
|
|
|
|
$statusBoundary = false; |
|
|
|
|
|
|
|
$date = date_create($request->clock_time); |
|
|
|
|
|
|
|
// $ActivityId = null; |
|
|
|
|
|
|
|
if(count($checkLocation) > 0){ |
|
|
|
|
|
|
|
$statusBoundary = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if($request->type=="out"){ |
|
|
|
if($request->type=="out"){ |
|
|
|
|
|
|
|
|
|
|
@ -32,12 +35,31 @@ class PresenceController extends Controller |
|
|
|
"clock_out_lat" => $request->clock_out_lat, |
|
|
|
"clock_out_lat" => $request->clock_out_lat, |
|
|
|
"clock_out_lng" => $request->clock_out_lng, |
|
|
|
"clock_out_lng" => $request->clock_out_lng, |
|
|
|
"updated_by"=>$this->currentName, |
|
|
|
"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); |
|
|
|
$resultUpdate = $this->updateFormAdd($dataUpdate, $request->user_id); |
|
|
|
if($resultUpdate && $resultUpdate > 0){ |
|
|
|
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{ |
|
|
|
else{ |
|
|
|
return response()->json(['status'=>'failed','message'=>'clock out failed please try again!','code'=>400], 400); |
|
|
|
return response()->json(['status'=>'failed','message'=>'clock out failed please try again!','code'=>400], 400); |
|
|
@ -45,10 +67,8 @@ class PresenceController extends Controller |
|
|
|
die(); |
|
|
|
die(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$date = date_create($request->clock_time); |
|
|
|
|
|
|
|
$onlyDate = date_format($date,"Y-m-d"); |
|
|
|
$onlyDate = date_format($date,"Y-m-d"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$clock_in_loc = "-"; |
|
|
|
$clock_in_loc = "-"; |
|
|
|
|
|
|
|
|
|
|
|
$dataAdd = array( |
|
|
|
$dataAdd = array( |
|
|
@ -58,22 +78,35 @@ class PresenceController extends Controller |
|
|
|
'created_by' => $this->currentName, |
|
|
|
'created_by' => $this->currentName, |
|
|
|
'clock_in_lat' => $request->clock_in_lat, |
|
|
|
'clock_in_lat' => $request->clock_in_lat, |
|
|
|
'clock_in_lng' => $request->clock_in_lng, |
|
|
|
'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); |
|
|
|
$result = Presence::create($dataAdd); |
|
|
|
|
|
|
|
|
|
|
|
$data=array( |
|
|
|
$data=array( |
|
|
|
'id' => $result->id, |
|
|
|
'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); |
|
|
|
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){ |
|
|
|
private function checkLocation($params){ |
|
|
|
// cek user tersebut apakah punya assign task yang ada bondary nya |
|
|
|
// cek user tersebut apakah punya assign task yang ada bondary nya |
|
|
|
// geom ada di table activity |
|
|
|
// geom ada di table activity |
|
|
@ -82,12 +115,27 @@ class PresenceController extends Controller |
|
|
|
->where("ahta.user_id", $params->user_id) |
|
|
|
->where("ahta.user_id", $params->user_id) |
|
|
|
->whereDate("ma.start_date", "<=", $params->clock_time) |
|
|
|
->whereDate("ma.start_date", "<=", $params->clock_time) |
|
|
|
->whereDate("ma.end_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(); |
|
|
|
->get(); |
|
|
|
// Activity::select('geom')->where(''); |
|
|
|
$temp = []; |
|
|
|
// gejson to geom |
|
|
|
foreach($geom as $dataGeom){ |
|
|
|
// intersect dengan point req |
|
|
|
$valGeom = json_decode($dataGeom->geom); |
|
|
|
return $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){ |
|
|
|
public function edit($id){ |
|
|
@ -151,7 +199,6 @@ class PresenceController extends Controller |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function updateFormAdd($data, $id){ |
|
|
|
private function updateFormAdd($data, $id){ |
|
|
|
|
|
|
|
|
|
|
|
$date = date_create($data['clock_out']); |
|
|
|
$date = date_create($data['clock_out']); |
|
|
|
|
|
|
|
|
|
|
|
$onlyDate = date_format($date,"Y-m-d"); |
|
|
|
$onlyDate = date_format($date,"Y-m-d"); |
|
|
|