@ -5,9 +5,9 @@ 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 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;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\DB;
@ -22,13 +22,31 @@ class PresenceController extends Controller
$checkLocation = $this->checkLocation($request);
$checkLocation = $this->checkLocation($request);
$statusBoundary = false;
$statusBoundary = false;
$date = date_create($request->clock_time);
$date = date_create($request->clock_time);
// $ActivityId = null;
// assign and in boundary
if(count($checkLocation) > 0){
if(count($checkLocation) > 0 & & $checkLocation[0]['boundary']){
// $checkLocation[0]['status_assign'] ? $statusBoundary = true
// :
$statusBoundary = true;
$statusBoundary = true;
}
}
// not assign
if(!$checkLocation[0]['status_assign'] & & $checkLocation[0]['boundary'] == false){
$data=array(
'id' => null,
'boundary' => $statusBoundary
);
return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200);
}
// assign and not in boundary
if($checkLocation[0]['status_assign'] & & $checkLocation[0]['boundary'] == false){
$data=array(
'id' => null,
'boundary' => true
);
return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda berada di luar area kerja.','code'=>200], 200);
}
if($request->type=="out"){
if($request->type=="out"){
$clock_out_loc = $this->getLoc($request->clock_out_lat, $request->clock_out_lng)->display_name;
$clock_out_loc = $this->getLoc($request->clock_out_lat, $request->clock_out_lng)->display_name;
$dataUpdate = array(
$dataUpdate = array(
"clock_out"=>$request->clock_time,
"clock_out"=>$request->clock_time,
@ -125,14 +143,33 @@ class PresenceController extends Controller
$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"));
$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) {
foreach ($check as $key) {
// assign and in boundary
if($key->boundary){
if($key->boundary){
$temp[]=array(
$temp[]=array(
"activity_id" => $dataGeom->id,
"activity_id" => $dataGeom->id,
"boundary" => $key->boundary
"boundary" => $key->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;
return $temp;
}
}
@ -152,14 +189,10 @@ class PresenceController extends Controller
}
}
}
}
public function clockinout($id) {
public function clockinout($id) {
$dateTimeNow = Carbon::now()->addHour(7);
$dateTimeNow = Carbon::now()->addHour(7);
$dataPresence = Presence::where('user_id', $id)->orderBy('id', 'DESC')->first();
$dataPresence = Presence::where('user_id', $id)->orderBy('id', 'DESC')->first();
if($dataPresence){
if($dataPresence){
$dateNow = date("Y-m-d");
$dateNow = date("Y-m-d");
@ -199,10 +232,8 @@ 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");
$dataPresence = Presence::where('user_id',$id)
$dataPresence = Presence::where('user_id',$id)
->where("clock_in", "< =", $data["clock_out"])
->where("clock_in", "< =", $data["clock_out"])
->orderByDesc("id")
->orderByDesc("id")
@ -237,7 +268,6 @@ class PresenceController extends Controller
die();
die();
}
}
if($result){
if($result){
return response()->json(['status'=>'success','message'=>'data presence successfully updated!','code'=>200], 200);
return response()->json(['status'=>'success','message'=>'data presence successfully updated!','code'=>200], 200);
}else{
}else{
@ -256,7 +286,6 @@ class PresenceController extends Controller
die();
die();
}
}
if($delete){
if($delete){
return response()->json(['status'=>'success','message'=>'data presence successfully deleted!','code'=>200], 200);
return response()->json(['status'=>'success','message'=>'data presence successfully deleted!','code'=>200], 200);
}else{
}else{