|
|
|
@ -263,33 +263,136 @@ class PresenceController extends Controller
|
|
|
|
|
foreach($geom as $dataGeom){ |
|
|
|
|
$valGeom = json_decode($dataGeom->geom); |
|
|
|
|
if($params->clock_in_out['type']=="out"){ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
if($valGeom->type == "FeatureCollection"){ |
|
|
|
|
// return count($valGeom->features); |
|
|
|
|
$multiArea = $valGeom->features; |
|
|
|
|
foreach($multiArea as $area){ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); |
|
|
|
|
if($check[0]->boundary){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
if($valGeom->type == "FeatureCollection"){ |
|
|
|
|
// return count($valGeom->features); |
|
|
|
|
$multiArea = $valGeom->features; |
|
|
|
|
foreach($multiArea as $area){ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); |
|
|
|
|
if($check[0]->boundary){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(count($check)>0){ |
|
|
|
|
if($check[0]->boundary){ |
|
|
|
|
$temp[]=array( |
|
|
|
|
"activity_id" => $dataGeom->id, |
|
|
|
|
"boundary" => $check[0]->boundary, |
|
|
|
|
"status_assign" => true |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if($check[0]->boundary){ |
|
|
|
|
$temp[]=array( |
|
|
|
|
"activity_id" => $dataGeom->id, |
|
|
|
|
"boundary" => $check[0]->boundary, |
|
|
|
|
"status_assign" => true |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// assign and not in boundary |
|
|
|
|
if(count($temp) < 1){ |
|
|
|
|
$temp[]=array( |
|
|
|
|
"activity_id" => null, |
|
|
|
|
"boundary" => false, |
|
|
|
|
"status_assign" => true |
|
|
|
|
// "geom" => $geom, |
|
|
|
|
// "cek" => $check[0]->boundary |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
// not assign |
|
|
|
|
$temp[]=array( |
|
|
|
|
"activity_id" => null, |
|
|
|
|
"boundary" => false, |
|
|
|
|
"status_assign" => false |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
return $temp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function checkLocationTest(Request $request){ |
|
|
|
|
// cek user tersebut apakah punya assign task yang ada bondary nya |
|
|
|
|
// geom ada di table activity |
|
|
|
|
// $clock_time = |
|
|
|
|
$params = $request; |
|
|
|
|
$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) |
|
|
|
|
->whereNotNull("ma.geom") |
|
|
|
|
->whereDate("ma.start_date", "<=", $params->time) |
|
|
|
|
->whereDate("ma.end_date", ">=", $params->time) |
|
|
|
|
->get(); |
|
|
|
|
$temp = []; |
|
|
|
|
if (count($geom) > 0) { |
|
|
|
|
foreach($geom as $dataGeom){ |
|
|
|
|
$valGeom = json_decode($dataGeom->geom); |
|
|
|
|
if($params->clock_in_out['type']=="out"){ |
|
|
|
|
if($valGeom->type == "FeatureCollection"){ |
|
|
|
|
// return count($valGeom->features); |
|
|
|
|
$multiArea = $valGeom->features; |
|
|
|
|
foreach($multiArea as $area){ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); |
|
|
|
|
if($check[0]->boundary){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
if($valGeom->type == "FeatureCollection"){ |
|
|
|
|
// return count($valGeom->features); |
|
|
|
|
$multiArea = $valGeom->features; |
|
|
|
|
foreach($multiArea as $area){ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); |
|
|
|
|
if($check[0]->boundary){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), |
|
|
|
|
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// assign and not in boundary |
|
|
|
|
if(count($temp) < 1){ |
|
|
|
|
$temp[]=array( |
|
|
|
|
"activity_id" => null, |
|
|
|
|
"boundary" => false, |
|
|
|
|
"status_assign" => true |
|
|
|
|
// "geom" => $geom, |
|
|
|
|
// "cek" => $check[0]->boundary |
|
|
|
|
); |
|
|
|
|
if(count($check)>0){ |
|
|
|
|
if($check[0]->boundary){ |
|
|
|
|
$temp[]=array( |
|
|
|
|
"activity_id" => $dataGeom->id, |
|
|
|
|
"boundary" => $check[0]->boundary, |
|
|
|
|
"status_assign" => true |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// assign and not in boundary |
|
|
|
|
if(count($temp) < 1){ |
|
|
|
|
$temp[]=array( |
|
|
|
|
"activity_id" => null, |
|
|
|
|
"boundary" => false, |
|
|
|
|
"status_assign" => true |
|
|
|
|
// "geom" => $geom, |
|
|
|
|
// "cek" => $check[0]->boundary |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
// not assign |
|
|
|
|
$temp[]=array( |
|
|
|
|