@ -5,9 +5,9 @@ namespace App\Http\Controllers;
use Log;
use Illuminate\Http\Request;
use App\Models\Presence;
use App\Models\Activity;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;
// use App\Models\Activity;
// use GuzzleHttp\Client;
// use Illuminate\Support\Facades\Http;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
@ -24,11 +24,27 @@ class PresenceController extends Controller
$date = date_create($request->clock_time);
// $ActivityId = null;
if(count($checkLocation) > 0){
$statusBoundary = true;
$checkLocation[0]['status_assign'] ? $statusBoundary = true
: $statusBoundary = false;
}
if(!$checkLocation[0]['status_assign'] & & $checkLocation[0]['boundary'] == null){
$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);
}
if($checkLocation[0]['status_assign'] & & $checkLocation[0]['boundary'] == null){
$data=array(
'id' => null,
'boundary' => $statusBoundary
);
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"){
$clock_out_loc = $this->getLoc($request->clock_out_lat, $request->clock_out_lng)->display_name;
$dataUpdate = array(
"clock_out"=>$request->clock_time,
@ -128,11 +144,25 @@ class PresenceController extends Controller
if($key->boundary){
$temp[]=array(
"activity_id" => $dataGeom->id,
"boundary" => $key->boundary
"boundary" => $key->boundary,
"status_assign" => true
);
}
}
}
if(count($temp) < 1 ) {
$temp[]=array(
"activity_id" => null,
"boundary" => null,
"status_assign" => true
);
}
}
}else{
$temp[]=array(
"activity_id" => null,
"boundary" => null,
"status_assign" => false
);
}
return $temp;
}
@ -152,14 +182,10 @@ class PresenceController extends Controller
}
}
public function clockinout($id) {
$dateTimeNow = Carbon::now()->addHour(7);
$dataPresence = Presence::where('user_id', $id)->orderBy('id', 'DESC')->first();
if($dataPresence){
$dateNow = date("Y-m-d");
@ -199,10 +225,8 @@ class PresenceController extends Controller
private function updateFormAdd($data, $id){
$date = date_create($data['clock_out']);
$onlyDate = date_format($date,"Y-m-d");
$dataPresence = Presence::where('user_id',$id)
->where("clock_in", "< =", $data["clock_out"])
->orderByDesc("id")
@ -237,7 +261,6 @@ class PresenceController extends Controller
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data presence successfully updated!','code'=>200], 200);
}else{
@ -256,7 +279,6 @@ class PresenceController extends Controller
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data presence successfully deleted!','code'=>200], 200);
}else{