|
|
|
@ -5,6 +5,7 @@ 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 Carbon\Carbon; |
|
|
|
@ -14,6 +15,10 @@ class PresenceController extends Controller
|
|
|
|
|
{ |
|
|
|
|
public function add(Request $request) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
// $test = $this->checkLocation($request); |
|
|
|
|
// return response()->json(['status'=>$test,'code'=>200], 200); |
|
|
|
|
$this->validate($request, [ |
|
|
|
|
'user_id' => 'required' |
|
|
|
|
]); |
|
|
|
@ -58,12 +63,32 @@ class PresenceController extends Controller
|
|
|
|
|
|
|
|
|
|
$result = Presence::create($dataAdd); |
|
|
|
|
|
|
|
|
|
$data=array( |
|
|
|
|
'id' => $result->id, |
|
|
|
|
'boundary' => true |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if($result){ |
|
|
|
|
return response()->json(['status'=>'success', 'id'=>$result->id,'message'=>'clock in successfully!','code'=>200], 200); |
|
|
|
|
return response()->json(['status'=>'success', 'data' => $data,'message'=>'clock in successfully!','code'=>200], 200); |
|
|
|
|
}else{ |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'clock in failed!','code'=>400], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
private function checkLocation($params){ |
|
|
|
|
// cek user tersebut apakah punya assign task yang ada bondary nya |
|
|
|
|
// geom ada di table activity |
|
|
|
|
$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) |
|
|
|
|
->whereDate("ma.start_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(); |
|
|
|
|
// Activity::select('geom')->where(''); |
|
|
|
|
// gejson to geom |
|
|
|
|
// intersect dengan point req |
|
|
|
|
return $geom; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function edit($id){ |
|
|
|
|
if(!$id || (int) $id < 0 || $id==""){ |
|
|
|
|