where('api_token',$request->api_token)->first();
if(empty($staff)){
return $this->sendError('Invalid', 'Staff not existed');
}else {
$dataLatLong = [
'latitude' => $request->latitude,
'longitude' => $request->longitude,
'status' => 'normal',
];
$staff->tracklocation()->create($dataLatLong);
if(!empty($staff->CurrentLocation)){
$staff->CurrentLocation->latitude = $request->latitude;
$staff->CurrentLocation->longitude = $request->longitude;
$staff->CurrentLocation->save();
}else{
$staff->currentlocation()->create($dataLatLong);
}
return $this->sendResponse($dataLatLong, 'Coordinates been saved successfully');
}
}
public function getStaffList(){
$data = array();
$location = CurrentLocation::all();
foreach ($location as $key => $l) {
$staff = $staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->first();
if(!empty($staff)){
array_push($data, array(
'id' => $l->staff_id,
'nama' => $staff->StaffDetail->full_name,
'no_badan' => $staff->StaffDetail->no_badan,
));
}
}
return $this->sendResponse($data, 'Successfully get enforcer list');
}
public function getNearestLocation($id, $company_id){
$data = array();
$latitude = 2.926412; $longitude = 101.6293333;
$location = CurrentLocation::all();
foreach ($location as $key => $l) {
$last_update = $l->updated_at;
$now = now();
$diff = $now->diffInMinutes($last_update);
$status = '';
if($diff <= 5){
$status = 'Online/b>';
}else{
$status = 'Offline';
}
if($company_id == 'null'){
$staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->first();
}else{
$staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->where('company_id', $company_id)->first();
}
if($l->staff_id == ''){
array_push($data, array(
'_id' => $l->_id,
'latitude' => '2.926412',
'longitude' => '101.6293333',
'title' => 'Allo Technology Sdn Bhd',
'content' => 'Main Office',
'icon' => url('/uploads/map_marker/mpkb_map.png'),
'status' => 'main',
'zindex' => $key+1
));
}else{
if(!empty($staff)){
array_push($data, array(
'_id' => $staff->_id,
'latitude' => $l->latitude,
'longitude' => $l->longitude,
'title' => $staff->StaffDetail->name,
'content' => $status,
'icon' => url('/uploads/map_marker/officer.png'),
'status' => $l->status,
'zindex' => $key+1
));
}
}
}
return $this->sendResponse($data, 'Successfully display coordinates');
}
}