Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 17 |
CRAP | |
0.00% |
0 / 802 |
| AttendanceDetailController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 17 |
24492 | |
0.00% |
0 / 802 |
| index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| store | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| show | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| edit | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| update | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| destroy | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| processAttendance | |
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 26 |
|||
| processAttendanceSelfService | |
0.00% |
0 / 1 |
1122 | |
0.00% |
0 / 241 |
|||
| populateAttendanceDataSameDayShiftSelfService | |
0.00% |
0 / 1 |
1190 | |
0.00% |
0 / 171 |
|||
| populateAttendanceDataTwoDayShiftSelfService | |
0.00% |
0 / 1 |
870 | |
0.00% |
0 / 161 |
|||
| populateAttendanceDataSameDayShift | |
0.00% |
0 / 1 |
272 | |
0.00% |
0 / 65 |
|||
| populateAttendanceDataTwoDayShift | |
0.00% |
0 / 1 |
420 | |
0.00% |
0 / 81 |
|||
| isHoliday | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 7 |
|||
| isLeave | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| getShiftDetails | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| didNotCheckinNotification | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 36 |
|||
| <?php | |
| namespace App\Http\Controllers\Dashboard; | |
| use App\Http\Controllers\FirebaseController\FirebaseCloudMessaging; | |
| use Illuminate\Http\Request; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Dashboard\AttendanceDetail; | |
| use App\Models\BiometricData\BiometricData; | |
| use App\Models\Admin\Leave; | |
| use App\Models\Admin\Holiday; | |
| use App\Models\Admin\UserDetail; | |
| use App\Models\Auth\User; | |
| use App\Models\Auth\UserShift; | |
| use Session; | |
| use Carbon\Carbon; | |
| use Illuminate\Support\Facades\Auth; | |
| use App\Models\Admin\Team; | |
| use App\Models\Leave\ApplyLeave; | |
| use App\Notifications\AttendanceDetailNotifications; | |
| use App\Notifications\SlackNotifications; | |
| use App\Models\AttendanceRequests\UserAttendanceRequests; | |
| use App\Helpers\GetShiftDetailHelper; | |
| use App\Helpers\AttendanceHelper; | |
| use DB; | |
| use GuzzleHttp\Client; | |
| use App\Helpers\PlatformHelper; | |
| use Jenssegers\Agent\Agent; | |
| use App\Http\Controllers\Auth\cliqController; | |
| class AttendanceDetailController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index() | |
| { | |
| //return view('dashboard.layout'); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create() | |
| { | |
| // | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function show($id) | |
| { | |
| // | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit($id) | |
| { | |
| // $biometric = BiometricData::find($id); | |
| // return view('dashboard.layout', compact($biometric))->with('biometric',BiometricData::find($id)); | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function update(Request $request, $id) | |
| { | |
| // | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy($id) | |
| { | |
| // | |
| } | |
| public function processAttendance($id) //process attendance from various sources and update attendanceDetail controller | |
| { | |
| $biometricData = BiometricData::findOrFail($id); | |
| $biometricUserId = $biometricData->UserId; | |
| $userDetail = UserDetail::where('biometric_id', '=', $biometricUserId)->first(); | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($id); | |
| $valUser = AttendanceHelper::getAttendanceUser($id); | |
| $attendanceValue = null; | |
| if ($valUser) { | |
| $attendanceValue = $valUser; | |
| } elseif ($valTeam) { | |
| $attendanceValue = $valTeam; | |
| } elseif ($val) { | |
| $attendanceValue = $val; | |
| } else { | |
| $attendanceValue = null; | |
| } | |
| if (isset($userDetail->user_id)) { | |
| $user = User::find($userDetail->user_id); | |
| $shiftDetails = $this->getShiftDetails($user); | |
| } else { | |
| return; // user/userdetail not entered in AMS | |
| } | |
| if ($shiftDetails->count() == 1) //if there is only one applicable shift for a user | |
| { | |
| foreach ($shiftDetails as $shift) { | |
| $shiftStartTime = $shift->start_time; | |
| $shiftEndTime = $shift->end_time; | |
| } | |
| if ($shiftStartTime > $shiftEndTime) // to check if the shift ends the next day | |
| { | |
| $this->populateAttendanceDataTwoDayShift($shiftStartTime, $shiftEndTime, $biometricData, $attedanceValue); | |
| } else { | |
| $this->populateAttendanceDataSameDayShift($shiftStartTime, $shiftEndTime, $biometricData, $attedanceValue); | |
| } | |
| } | |
| return; | |
| // checkinCheckout | |
| } | |
| public function processAttendanceSelfService(Request $request) | |
| { | |
| $startDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->toDateString() . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $endDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->addDay()->toDateString() . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| $attendanceValue = null; | |
| $latitude = $request->input('latitude'); | |
| $longitude = $request->input('longitude'); | |
| $client = new Client(); | |
| // $client = new Client(['verify' =>storage_path("cert.pem")]); | |
| $response = $client->request('GET', 'https://nominatim.openstreetmap.org/reverse', [ | |
| 'query' => [ | |
| 'format' => 'json', | |
| 'lat' => $latitude, | |
| 'lon' => $longitude | |
| ] | |
| ]); | |
| $stream = $response->getBody(); | |
| $address = json_decode($stream->getContents()); | |
| $decodeAddress = $address->display_name; | |
| if ($valUser) { | |
| $attendanceValue = $valUser; | |
| } elseif ($valTeam) { | |
| $attendanceValue = $valTeam; | |
| } elseif ($val) { | |
| $attendanceValue = $val; | |
| } else { | |
| $attendanceValue = null; | |
| } | |
| //check if there is reason for checkin or checkout | |
| $reasonTitle = null; | |
| $reason = null; | |
| $currUser = Auth::user()->id; | |
| $curDate = Carbon::now(config('settings.time_zone'))->toDateString(); | |
| $pendingCheck = UserAttendanceRequests::select(DB::raw('DATE(check_in) as check_in_date')) | |
| ->where('user_id', '=', $currUser) | |
| ->where(DB::raw('DATE(check_in)'), '=', $curDate) | |
| ->where('requested_for', '=', 'Late Checkin') | |
| ->where('status', '=', 'pending') | |
| ->first(); | |
| if (empty($pendingCheck)) { | |
| $pendingCheck = "1"; | |
| } else { | |
| $pendingCheck = "0"; | |
| } | |
| //if checkin/checkut has title means it is late checkin or early checkout | |
| if ($request->has('reasonTitle')) { | |
| $reasonTitle = $request->input('reasonTitle'); | |
| $reason = $request->input('reason'); | |
| $today_date_time = Carbon::now('UTC'); | |
| //check if user is late checkin/early checkout | |
| if ($reasonTitle == 'Late Checkin') { | |
| $checkin = $today_date_time; | |
| $latitude = $latitude; | |
| $longitude = $longitude; | |
| $combinedCheckinLocation = $latitude . ', ' . $longitude; | |
| $combinedCheckinLocationAddress = $decodeAddress; | |
| $checkout = null; | |
| $combinedCheckoutLocation = null; | |
| $combinedCheckoutLocationAddress = null; | |
| } elseif ($reasonTitle == 'Early Checkout' && $pendingCheck == "0") { | |
| $checkin = UserAttendanceRequests::where('user_id', '=', $currUser) | |
| ->whereRaw("DATE(check_in) = '" . $curDate . "'") | |
| ->where('requested_for', '=', 'Late Checkin') | |
| ->value('check_in'); | |
| $combinedCheckinLocation = UserAttendanceRequests::where('user_id', '=', $currUser) | |
| ->whereRaw("DATE(check_in) = '" . $curDate . "'") | |
| ->where('requested_for', '=', 'Late Checkin') | |
| ->value('check_in_location'); | |
| $combinedCheckinLocationAddress = UserAttendanceRequests::where('user_id', '=', $currUser) | |
| ->whereRaw("DATE(check_in) = '" . $curDate . "'") | |
| ->where('requested_for', '=', 'Late Checkin') | |
| ->value('check_in_location_address'); | |
| $checkout = $today_date_time; | |
| $combinedCheckoutLocation = $latitude . ', ' . $longitude; | |
| $combinedCheckoutLocationAddress = $decodeAddress; | |
| } else { | |
| $attendanceDetail = AttendanceDetail::where('user_id', '=', Auth::user()->id) | |
| ->whereBetween('check_in', [$startDate, $endDate]) | |
| ->first(); | |
| $checkin = $attendanceDetail->check_in; | |
| $combinedCheckinLocation = AttendanceDetail::where('user_id', '=', $currUser) | |
| ->whereRaw("DATE(check_in) = '" . $curDate . "'") | |
| ->value('check_in_location'); | |
| $combinedCheckinLocationAddress = AttendanceDetail::where('user_id', '=', $currUser) | |
| ->whereRaw("DATE(check_in) = '" . $curDate . "'") | |
| ->value('check_in_location_address'); | |
| $checkout = $today_date_time; | |
| $combinedCheckoutLocation = $latitude . ", " . $longitude; | |
| $combinedCheckoutLocationAddress = $decodeAddress; | |
| } | |
| //get shift details | |
| $shift = GetShiftDetailHelper::getShiftDetail(Auth::user()->id, $startDate, $endDate); | |
| if ($shift != null) { | |
| $shiftStartTime = $shift['shiftStartTime']; | |
| $shiftEndTime = $shift['shiftEndTime']; | |
| } | |
| //check already exists data | |
| $attendanceRequest = UserAttendanceRequests::where('user_id', '=', Auth::user()->id) | |
| ->where('requested_for', $reasonTitle); | |
| //check if user is late checkin/early checkout | |
| if ($reasonTitle == 'Late Checkin') { | |
| $attendanceRequest = $attendanceRequest->whereDate('check_in', $today_date_time); | |
| } else { | |
| $attendanceRequest = $attendanceRequest->whereDate('check_out', $today_date_time); | |
| } | |
| $attendanceRequest = $attendanceRequest->first(); | |
| if (!empty($attendanceRequest)) { | |
| // Session::flash('warning', 'You already requested for this'); | |
| // redirect()->route('home')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Warning', | |
| 'message' => 'You already requested for ' . $reasonTitle, | |
| ], | |
| 200 | |
| ); | |
| } else { | |
| //create request attendance | |
| $atdnce = UserAttendanceRequests::create( | |
| [ | |
| 'user_id' => Auth::user()->id, | |
| 'attendance_setting' => $attendanceValue, | |
| 'check_in' => $checkin, | |
| 'check_in_location' => $combinedCheckinLocation, | |
| 'check_in_location_address' => $combinedCheckinLocationAddress, | |
| 'check_out' => $checkout, | |
| 'check_out_location' => $combinedCheckoutLocation, | |
| 'check_out_location_address' => $combinedCheckoutLocationAddress, | |
| 'requested_for' => $reasonTitle, | |
| 'comments' => $reason, | |
| 'status' => "pending", | |
| 'start_time' => $shiftStartTime, | |
| 'end_time' => $shiftEndTime | |
| ] | |
| ); | |
| // Session::flash('success', 'Your '.$reasonTitle.' request is sent to manager for approval.'); | |
| // redirect()->route('home')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Success', | |
| 'message' => 'Your ' . $reasonTitle . ' request is sent to manager for approval.', | |
| 'url' => '/home' | |
| ], | |
| 200 | |
| ); | |
| } | |
| } else { | |
| $user = Auth::user(); | |
| if (isset($user)) { | |
| $shiftDetails = $this->getShiftDetails($user); | |
| } else { | |
| //return; // user/userdetail not entered in AMS | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'msg' => 'error' | |
| ], | |
| 200 | |
| ); | |
| } | |
| //user teams | |
| // $userAttendanceTeam = $user->userdetail->teams; | |
| // foreach ($userAttendanceTeam as $userTeam) { | |
| // $teamId = $userTeam->id; | |
| // } | |
| //primary team id | |
| $teamId = $user->userdetail->primary_team_id; | |
| $team = Team::find($teamId); | |
| //current time | |
| $today_date_time = Carbon::now(config('settings.time_zone')); | |
| $time_now = $today_date_time->toTimeString(); | |
| $currentDate = Carbon::now(config('settings.time_zone'))->toDateString(); | |
| $subdayWithTimezone = Carbon::now(config('settings.time_zone'))->subday()->toDateString(); | |
| // if user is on scheduled team | |
| if ($team->has_schedule == 1) { | |
| //get sub day user shift first | |
| $subday_date = Carbon::now(config('settings.time_zone'))->subday()->toDateString(); | |
| $startDateForSubday = Carbon::parse($subday_date . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $endDateForSubday = Carbon::parse(Carbon::parse($subday_date)->addDay()->toDateString() . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| //get user shift for sub day | |
| $userShiftForSubday = UserShift::where('user_id', $user->id) | |
| ->whereBetween('created_at', [$startDateForSubday, $endDateForSubday]) | |
| ->first(); | |
| //if user shift for sub day is not empty | |
| if (!empty($userShiftForSubday)) { | |
| $shiftStartTime = $userShiftForSubday->shift_start; | |
| $shiftEndTime = $userShiftForSubday->shift_end; | |
| //get shift start time for settings timezone | |
| $shiftStartTimeForSubday = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')); | |
| $shiftStartTimeForSubday->setTimezone(config('settings.time_zone')); | |
| $shiftStartTimeForSubday = $shiftStartTimeForSubday->toTimeString(); | |
| //get shift end time for settings timezone | |
| $shiftEndTimeForSubday = Carbon::createFromFormat('H:i:s', $shiftEndTime, Config('app.timezone')); | |
| $shiftEndTimeForSubday->setTimezone(config('settings.time_zone')); | |
| $shiftEndTimeForSubday = $shiftEndTimeForSubday->toTimeString(); | |
| //check user is on two day shift | |
| if ($shiftStartTimeForSubday > $shiftEndTimeForSubday) { | |
| //offset start time for two day shift | |
| $offsetStartTime = Carbon::parse($shiftStartTimeForSubday); | |
| $offsetStartTime = $offsetStartTime->subHours(4)->toTimeString(); | |
| //offset end time for two day shift | |
| $offsetEndTime = Carbon::parse($shiftEndTimeForSubday); | |
| $offsetEndTime = $offsetEndTime->addHours(4)->toTimeString(); | |
| $time = Carbon::now(config('settings.time_zone')); | |
| $day = $time->day + 1; | |
| //set a time to shift start time | |
| $setShiftStartTime = Carbon::createFromFormat('Y-m-d H:i:s', $time->year . '-' . $time->month . '-' . $time->day . ' ' . $offsetStartTime, config('settings.time_zone')); | |
| //set time to next day 12am | |
| $set12am = Carbon::createFromFormat('Y-m-d H:i:s', $time->year . '-' . $time->month . '-' . $day . ' 00:00:00', config('settings.time_zone')); | |
| //checking current time for sub day shift | |
| if (!$time->between($setShiftStartTime, $set12am, true) && $time_now < $offsetEndTime) { | |
| } else { | |
| //if user is single day shift check user shift for today | |
| $userShift = UserShift::where('user_id', $user->id) | |
| ->whereBetween('created_at', [$startDate, $endDate]) | |
| ->first(); | |
| if (!empty($userShift)) { | |
| $shiftStartTime = $userShift->shift_start; | |
| $shiftEndTime = $userShift->shift_end; | |
| //set the time for settings timezone | |
| $shiftStartTimeForToday = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')); | |
| $shiftStartTimeForToday->setTimezone(config('settings.time_zone')); | |
| //set time | |
| $shiftStartTimeForToday = $shiftStartTimeForToday->toTimeString(); | |
| //get shift time with date | |
| $setShiftStartTime = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')) | |
| ->setTimezone(config('settings.time_zone')) | |
| ->format('Y-m-d H:i:s'); | |
| //set offset time with date | |
| $offsetStartTime = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')) | |
| ->setTimezone(config('settings.time_zone')) | |
| ->subHours(4) | |
| ->format('Y-m-d H:i:s'); | |
| //time for check | |
| $time = Carbon::now(config('settings.time_zone')); | |
| //check offset start time and shift start time | |
| if ( | |
| ($time->between($offsetStartTime, $setShiftStartTime)) || | |
| ($time_now == $shiftStartTimeForToday) || ($time_now > $shiftStartTimeForToday) | |
| ) { //if time now is near to shift start time | |
| } else { | |
| // Session::flash('warning', 'Shift not assigned for you in schedule. Please request attendance.'); | |
| // redirect()->route('request-attendance.index')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Warning', | |
| 'message' => 'Shift not assigned for you in schedule. Please request attendance.', | |
| 'url' => '/request-attendance' | |
| ], | |
| 200 | |
| ); | |
| } | |
| } else { | |
| // Session::flash('warning', 'Shift not assigned for you in schedule. Please request attendance.'); | |
| // redirect()->route('request-attendance.index')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Warning', | |
| 'message' => 'Shift not assigned for you in schedule. Please request attendance.', | |
| 'url' => '/request-attendance' | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } else { | |
| //if user is single day shift check user shift for today | |
| $userShift = UserShift::where('user_id', $user->id) | |
| ->whereBetween('created_at', [$startDate, $endDate]) | |
| ->first(); | |
| if (!empty($userShift)) { | |
| $shiftStartTime = $userShift->shift_start; | |
| $shiftEndTime = $userShift->shift_end; | |
| $shiftStartTimeForToday = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')); | |
| $shiftStartTimeForToday->setTimezone(config('settings.time_zone')); | |
| //set time | |
| $shiftStartTimeForToday = $shiftStartTimeForToday->toTimeString(); | |
| //get shift time with date | |
| $setShiftStartTime = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')) | |
| ->setTimezone(config('settings.time_zone')) | |
| ->format('Y-m-d H:i:s'); | |
| //set offset time with date | |
| $offsetStartTime = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')) | |
| ->setTimezone(config('settings.time_zone')) | |
| ->subHours(4) | |
| ->format('Y-m-d H:i:s'); | |
| //time for check | |
| $time = Carbon::now(config('settings.time_zone')); | |
| //check offset start time and shift start time | |
| if ( | |
| ($time->between($offsetStartTime, $setShiftStartTime)) || | |
| ($time_now == $shiftStartTimeForToday) || ($time_now > $shiftStartTimeForToday) | |
| ) { //if time now is near to shift start time | |
| } else { | |
| // Session::flash('warning', 'Shift not assigned for you in schedule. Please request attendance.'); | |
| // redirect()->route('request-attendance.index')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Warning', | |
| 'message' => 'Shift not assigned for you in schedule. Please request attendance.', | |
| 'url' => '/request-attendance' | |
| ], | |
| 200 | |
| ); | |
| } | |
| } else { | |
| // Session::flash('warning', 'Shift not assigned for you in schedule. Please request attendance.'); | |
| // redirect()->route('request-attendance.index')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Warning', | |
| 'message' => 'Shift not assigned for you in schedule. Please request attendance.', | |
| 'url' => '/request-attendance' | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } else { | |
| //if empty check user shift for today | |
| $userShift = UserShift::where('user_id', $user->id) | |
| ->whereBetween('created_at', [$startDate, $endDate]) | |
| ->first(); | |
| if (!empty($userShift)) { | |
| $shiftStartTime = $userShift->shift_start; | |
| $shiftEndTime = $userShift->shift_end; | |
| $shiftStartTimeForToday = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')); | |
| $shiftStartTimeForToday->setTimezone(config('settings.time_zone')); | |
| //set time | |
| $shiftStartTimeForToday = $shiftStartTimeForToday->toTimeString(); | |
| //get shift time with date | |
| $setShiftStartTime = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')) | |
| ->setTimezone(config('settings.time_zone')) | |
| ->format('Y-m-d H:i:s'); | |
| //set offset time with date | |
| $offsetStartTime = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')) | |
| ->setTimezone(config('settings.time_zone')) | |
| ->subHours(4) | |
| ->format('Y-m-d H:i:s'); | |
| //time for check | |
| $time = Carbon::now(config('settings.time_zone')); | |
| //check offset start time and shift start time | |
| if ( | |
| ($time->between($offsetStartTime, $setShiftStartTime)) || | |
| ($time_now == $shiftStartTimeForToday) || ($time_now > $shiftStartTimeForToday) | |
| ) { //if time now is near to shift start time | |
| } else { | |
| // Session::flash('warning', 'Shift not assigned for you in schedule. Please request attendance.'); | |
| // redirect()->route('request-attendance.index')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Warning', | |
| 'message' => 'Shift not assigned for you in schedule. Please request attendance.', | |
| 'url' => '/request-attendance' | |
| ], | |
| 200 | |
| ); | |
| } | |
| } else { | |
| // Session::flash('warning', 'Shift not assigned for you in schedule. Please request attendance.'); | |
| // redirect()->route('request-attendance.index')->send(); | |
| return response()->json( | |
| [ | |
| 'status' => 'Warning', | |
| 'message' => 'Shift not assigned for you in schedule. Please request attendance.', | |
| 'url' => '/request-attendance' | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } else { | |
| if ($shiftDetails->count() == 1) //if there is only one applicable shift for a user | |
| { | |
| foreach ($shiftDetails as $shift) { | |
| $shiftStartTime = $shift->start_time; | |
| $shiftEndTime = $shift->end_time; | |
| } | |
| } | |
| } | |
| //change start time and end time to settings timezone ' | |
| $shiftStartTimeForTimezone = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')); | |
| $shiftStartTimeForTimezone->setTimezone(config('settings.time_zone')); | |
| $shiftStartTimeForTimezone = $shiftStartTimeForTimezone->toTimeString(); | |
| $shiftEndTimeForTimezone = Carbon::createFromFormat('H:i:s', $shiftEndTime, Config('app.timezone')); | |
| $shiftEndTimeForTimezone->setTimezone(config('settings.time_zone')); | |
| $shiftEndTimeForTimezone = $shiftEndTimeForTimezone->toTimeString(); | |
| if ($shiftStartTimeForTimezone > $shiftEndTimeForTimezone) // to check if the shift ends the next day | |
| { | |
| return $this->populateAttendanceDataTwoDayShiftSelfService($request, $shiftStartTime, $shiftEndTime, $shiftStartTimeForTimezone, $shiftEndTimeForTimezone, $attendanceValue); | |
| } | |
| else | |
| { | |
| return $this->populateAttendanceDataSameDayShiftSelfService($request, $shiftStartTime, $shiftEndTime, $shiftStartTimeForTimezone, $shiftEndTimeForTimezone, $attendanceValue); | |
| } | |
| // return redirect()->back(); | |
| } | |
| } | |
| public function populateAttendanceDataSameDayShiftSelfService(Request $request, $shiftStartTime, $shiftEndTime, $shiftStartTimeForTimezone, $shiftEndTimeForTimezone, $attendanceValue) | |
| { | |
| $today_date_time = Carbon::now('UTC'); | |
| //for cliq integration | |
| $ob = new cliqController(); | |
| // $user_id = Auth::user()->userdetail->biometric_id; | |
| $user_id = Auth::user()->id; | |
| // $today_date_time = Carbon::now('Asia/Kolkata'); | |
| // $time_now = $today_date_time->toTimeString(); | |
| $time_now = Carbon::now(config('settings.time_zone'))->toTimeString(); | |
| $startDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->toDateString() . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $endDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->addDay()->toDateString() . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| //get attendance detail | |
| $query = AttendanceDetail::query(); | |
| //$query->whereDate('check_in', '=', $today_date_time); | |
| $query->whereBetween('check_in', [$startDate, $endDate]); | |
| $query->where('user_id', '=', $user_id); | |
| $attendanceDetail = $query->get(); | |
| $latitude = $request->input('latitude'); | |
| $longitude = $request->input('longitude'); | |
| $client = new Client(); | |
| // $client = new Client(['verify' =>storage_path("cert.pem")]); | |
| $response = $client->request('GET', 'https://nominatim.openstreetmap.org/reverse', [ | |
| 'query' => [ | |
| 'format' => 'json', | |
| 'lat' => $latitude, | |
| 'lon' => $longitude | |
| ] | |
| ]); | |
| $stream = $response->getBody(); | |
| $address = json_decode($stream->getContents()); | |
| $decodeAddress = $address->display_name; | |
| if ($attendanceDetail->isEmpty()) //if no attendance is marked for the user that particular day | |
| { | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceValue == 1) { | |
| //save checkin with shift details when no checkin/no checkout is selected | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Self Service'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $user_id; | |
| $attendance->check_in = null; | |
| $attendance->check_in_location = null; | |
| $attendance->check_in_location_address = null; | |
| $attendance->check_out = null; | |
| $attendance->check_out_location = null; | |
| $attendance->check_out_location_address = null; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| $attendance->save(); | |
| } | |
| //check if time is shift start time and end time | |
| if ( | |
| ($time_now < $shiftStartTimeForTimezone) || ($time_now == $shiftStartTimeForTimezone) || | |
| ($time_now > $shiftStartTimeForTimezone && $time_now < $shiftEndTimeForTimezone) | |
| ) { | |
| //save checkin with shift details | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Self Service'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $user_id; | |
| $attendance->check_in = $today_date_time; | |
| $combinedLocation = $latitude . ', ' . $longitude; | |
| $attendance->check_in_location = $combinedLocation; | |
| $attendance->check_in_location_address = $decodeAddress; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| $attendance->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_in'); | |
| } | |
| //checkin and checkout details for displaying date in dashboard | |
| if ($attendance->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendance->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendance->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendance->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| } | |
| // else | |
| // { | |
| // $attendance = new AttendanceDetail; | |
| // $attendance->mode = 'Self Service'; | |
| // $attendance->user_id = $user_id; | |
| // $attendance->check_out = $today_date_time; | |
| // $attendance->shift_start = $shiftStartTime; | |
| // $attendance->shift_end = $shiftEndTime; | |
| // } | |
| else if ($time_now > $shiftEndTimeForTimezone) { // check current time is greater thn shift end time | |
| $this->didNotCheckinNotification(); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } else { | |
| foreach ($attendanceDetail as $attendanceEntry) { | |
| if ($attendanceEntry->check_in != null) //check_in | |
| { | |
| // $checkin =Carbon::parse($attendanceEntry->check_in)->format('H:i:s'); | |
| // exit; | |
| // echo date('H:i:s', $attendanceEntry->check_in)."<br>".$time_now."<br>"; | |
| $checkInForTimezone = Carbon::createFromFormat('H:i:s', Carbon::parse($attendanceEntry->check_in)->toTimeString(), Config('app.timezone')); | |
| $checkInForTimezone->setTimezone(config('settings.time_zone')); | |
| $checkInForTimezone = $checkInForTimezone->toTimeString(); | |
| if ($checkInForTimezone > $time_now) { | |
| $attendanceEntry->check_in = $today_date_time; | |
| $combinedLocation = $latitude . ', ' . $longitude; | |
| $attendanceEntry->check_in_location = $combinedLocation; | |
| $attendanceEntry->check_in_location_address = $decodeAddress; | |
| $attendanceEntry->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_in'); | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceEntry->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceEntry->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendanceEntry->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceEntry->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } else { | |
| if ( | |
| ($time_now < $shiftStartTimeForTimezone) || ($time_now == $shiftStartTimeForTimezone) || | |
| ($time_now > $shiftStartTimeForTimezone && $time_now < $shiftEndTimeForTimezone) | |
| ) { | |
| $attendanceEntry->check_in = $today_date_time; | |
| $combinedLocation = $latitude . ', ' . $longitude; | |
| $attendanceEntry->check_in_location = $combinedLocation; | |
| $attendanceEntry->check_in_location_address = $decodeAddress; | |
| $attendanceEntry->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_in'); | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceEntry->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceEntry->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendanceEntry->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceEntry->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| if ($attendanceEntry->check_out != null) //check out | |
| { | |
| $checkOutForTimezone = Carbon::createFromFormat('H:i:s', Carbon::parse($attendanceEntry->check_out)->toTimeString(), Config('app.timezone')); | |
| $checkOutForTimezone->setTimezone(config('settings.time_zone')); | |
| $checkOutForTimezone = $checkOutForTimezone->toTimeString(); | |
| if ($checkOutForTimezone < $time_now) { | |
| if (Carbon::parse($attendanceEntry->check_in)->addMinutes(3) < $today_date_time) { | |
| $attendanceEntry->check_out = $today_date_time; | |
| $combinedCheckoutLocation = $latitude . ', ' . $longitude; | |
| $attendanceEntry->check_out_location = $combinedCheckoutLocation; | |
| $attendanceEntry->check_out_location_address = $decodeAddress; | |
| $attendanceEntry->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_out'); | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceEntry->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceEntry->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendanceEntry->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceEntry->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } else { | |
| if (Carbon::parse($attendanceEntry->check_in)->addMinutes(3) < $today_date_time) { | |
| $attendanceEntry->check_out = $today_date_time; | |
| $combinedCheckoutLocation = $latitude . ', ' . $longitude; | |
| $attendanceEntry->check_out_location = $combinedCheckoutLocation; | |
| $attendanceEntry->check_out_location_address = $decodeAddress; | |
| $attendanceEntry->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_out'); | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceEntry->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceEntry->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendanceEntry->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceEntry->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| public function populateAttendanceDataTwoDayShiftSelfService(Request $request, $shiftStartTime, $shiftEndTime, $shiftStartTimeForTimezone, $shiftEndTimeForTimezone, $attendanceValue) | |
| { | |
| $ob = new CliqController(); | |
| // $user_id = Auth::user()->userdetail->biometric_id; | |
| $today_date_time = Carbon::now('UTC'); | |
| $user_id = Auth::user()->id; | |
| // $today_date_time = Carbon::now('Asia/Kolkata'); | |
| // $time_now = $today_date_time->toTimeString(); | |
| $time_now = Carbon::now(config('settings.time_zone'))->toTimeString(); | |
| //get data from attendetail table | |
| $query = AttendanceDetail::query(); | |
| $query->whereDate('check_in', '=', $today_date_time); | |
| $query->where('user_id', '=', $user_id); | |
| $attendanceDetail = $query->get(); | |
| //offset time for shift start time | |
| $offsetStartTime = Carbon::parse($shiftStartTimeForTimezone); | |
| $offsetStartTime = $offsetStartTime->subHours(4)->toTimeString(); | |
| //offset time for shift end time | |
| $offsetEndTime = Carbon::parse($shiftEndTimeForTimezone); | |
| $offsetEndTime = $offsetEndTime->addHours(4)->toTimeString(); | |
| $currentDate = Carbon::now(config('settings.time_zone'))->toDateString(); | |
| $subdayWithTimezone = Carbon::now(config('settings.time_zone'))->subday()->toDateString(); | |
| $latitude = $request->input('latitude'); | |
| $longitude = $request->input('longitude'); | |
| $client = new Client(); | |
| // $client = new Client(['verify' =>storage_path("cert.pem")]); | |
| $response = $client->request('GET', 'https://nominatim.openstreetmap.org/reverse', [ | |
| 'query' => [ | |
| 'format' => 'json', | |
| 'lat' => $latitude, | |
| 'lon' => $longitude | |
| ] | |
| ]); | |
| $stream = $response->getBody(); | |
| $address = json_decode($stream->getContents()); | |
| $decodeAddress = $address->display_name; | |
| if ($attendanceDetail->isEmpty()) //if no attendance is marked for the user that particular day | |
| { | |
| if ($attendanceValue == 1) { | |
| //save checkin with shift details when no checkin/no checkout is selected | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Self Service'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $user_id; | |
| $attendance->check_in = null; | |
| $attendance->check_in_location = null; | |
| $attendance->check_in_location_address = null; | |
| $attendance->check_out = null; | |
| $attendance->check_out_location = null; | |
| $attendance->check_out_location_address = null; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| $attendance->save(); | |
| } | |
| //if current time between shift start time and end time | |
| if ( | |
| ($time_now < $shiftStartTimeForTimezone && $time_now > $offsetStartTime) || | |
| ($time_now == $shiftStartTimeForTimezone) || ($time_now > $shiftStartTimeForTimezone && ($offsetEndTime < $time_now)) | |
| ) { | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Self Service'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $user_id; | |
| $attendance->check_in = $today_date_time; | |
| $combinedLocation = $latitude . ', ' . $longitude; | |
| $attendance->check_in_location = $combinedLocation; | |
| $attendance->check_in_location_address = $decodeAddress; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| } else { | |
| $subday_date_time = Carbon::now('UTC')->subday()->toDateString(); | |
| $query = AttendanceDetail::query(); | |
| $query->whereDate('check_in', '=', $subday_date_time); | |
| $query->where('user_id', '=', $user_id); | |
| $attendanceDetail = $query->get(); | |
| if ($attendanceDetail->isEmpty()) //if no attendance is marked for the user that particular day | |
| { | |
| // $attendance = new AttendanceDetail; | |
| // $attendance->mode = 'Self Service'; | |
| // $attendance->user_id = $user_id; | |
| // $attendance->check_out = $today_date_time; | |
| // $attendance->shift_start = $shiftStartTime; | |
| // $attendance->shift_end = $shiftEndTime; | |
| if ($offsetEndTime > $time_now) { | |
| $this->didNotCheckinNotification(); | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } else { | |
| foreach ($attendanceDetail as $attendanceEntry) { | |
| if (Carbon::parse($attendanceEntry->check_in)->diffInMinutes($today_date_time) > 3) { | |
| $attendanceEntry->check_out = $today_date_time; | |
| $combinedCheckoutLocation = $latitude . ', ' . $longitude; | |
| $attendanceEntry->check_out_location = $combinedCheckoutLocation; | |
| $attendanceEntry->check_out_location_address = $decodeAddress; | |
| $attendanceEntry->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_out'); | |
| } | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceEntry->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceEntry->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendanceEntry->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceEntry->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } | |
| $attendance->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_in'); | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendance->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendance->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendance->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendance->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } else { | |
| foreach ($attendanceDetail as $attendanceEntry) { | |
| if ($attendanceEntry->check_out != null) //check out | |
| { | |
| $checkOutForTimezone = Carbon::createFromFormat('H:i:s', Carbon::parse($attendanceEntry->check_out)->toTimeString(), Config('app.timezone')); | |
| $checkOutForTimezone->setTimezone(config('settings.time_zone')); | |
| $checkOutForTimezone = $checkOutForTimezone->toTimeString(); | |
| if ($checkOutForTimezone < $time_now) { | |
| if (Carbon::parse($attendanceEntry->check_in)->addMinutes(3) < $today_date_time) { | |
| $attendanceEntry->check_out = $today_date_time; | |
| $combinedCheckoutLocation = $latitude . ', ' . $longitude; | |
| $attendanceEntry->check_out_location = $combinedCheckoutLocation; | |
| $attendanceEntry->check_out_location_address = $decodeAddress; | |
| $attendanceEntry->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_out'); | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceEntry->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceEntry->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendanceEntry->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceEntry->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } else { | |
| if (Carbon::parse($attendanceEntry->check_in)->addMinutes(3) < $today_date_time) { | |
| $attendanceEntry->check_out = $today_date_time; | |
| $combinedCheckoutLocation = $latitude . ', ' . $longitude; | |
| $attendanceEntry->check_out_location = $combinedCheckoutLocation; | |
| $attendanceEntry->check_out_location_address = $decodeAddress; | |
| $attendanceEntry->save(); | |
| if(env('CLIQ_WEBHOOK')){ | |
| $ob->sendMessage($today_date_time,'check_out'); | |
| } | |
| $dcheck_in = null; | |
| $dcheck_out = null; | |
| if ($attendanceEntry->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceEntry->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| if ($attendanceEntry->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceEntry->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') . ' ' . config('settings.time_format')); | |
| } | |
| return response()->json( | |
| [ | |
| 'status' => 'return', | |
| 'check_in' => $dcheck_in, | |
| 'check_out' => $dcheck_out | |
| ], | |
| 200 | |
| ); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| public function populateAttendanceDataSameDayShift($shiftStartTime, $shiftEndTime, $biometricData, $attedanceValue) | |
| { | |
| $biometricOperationTimestamp = Carbon::createFromTimestamp($biometricData->OperationTime, Config('app.timezone'))->toDateTimeString(); | |
| $biometricOperationtime = Carbon::parse($biometricOperationTimestamp, Config('app.timezone'))->toTimeString(); | |
| $biometricDate = Carbon::parse($biometricOperationTimestamp, Config('app.timezone'))->toDateString(); | |
| $query = AttendanceDetail::query(); | |
| $query->whereDate('check_in', '=', $biometricDate); | |
| $query->where('user_id', '=', $biometricData->UserId); | |
| $attendanceDetail = $query->get(); | |
| if ($attendanceDetail->isEmpty()) //if no attendance is marked for the user that particular day | |
| { | |
| if ($attendanceValue == 1) { | |
| //save checkin with shift details when no checkin/no checkout is selected | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Biometric'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $biometricData->UserId; | |
| $attendance->check_in = null; | |
| $attendance->check_out = null; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| } | |
| if ( | |
| ($biometricOperationtime < $shiftStartTime) || ($biometricOperationtime == $shiftStartTime) || | |
| ($biometricOperationtime > $shiftStartTime && $biometricOperationtime < $shiftEndTime) | |
| ) { | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Biometric'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $biometricData->UserId; | |
| $attendance->check_in = $biometricOperationTimestamp; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| } else { | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Biometric'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $biometricData->UserId; | |
| $attendance->check_out = $biometricOperationTimestamp; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| } | |
| $attendance->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } else { | |
| foreach ($attendanceDetail as $attendanceEntry) { | |
| if ($attendanceEntry->check_in != null) //check_in | |
| { | |
| if (Carbon::parse($attendanceEntry->check_in, Config('app.timezone'))->toTimeString() > $biometricOperationtime) { | |
| $attendanceEntry->check_in = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } else { | |
| if ( | |
| ($biometricOperationtime < $shiftStartTime) || ($biometricOperationtime == $shiftStartTime) || | |
| ($biometricOperationtime > $shiftStartTime && $biometricOperationtime < $shiftEndTime) | |
| ) { | |
| $attendanceEntry->check_in = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } | |
| if ($attendanceEntry->check_out != null) //check out | |
| { | |
| if (Carbon::parse($attendanceEntry->check_out, Config('app.timezone'))->toTimeString() < $biometricOperationtime) { | |
| $attendanceEntry->check_out = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } else { | |
| $attendanceEntry->check_out = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } | |
| } | |
| } | |
| public function populateAttendanceDataTwoDayShift(Request $request, $shiftStartTime, $shiftEndTime, $biometricData, $attedanceValue) | |
| { | |
| $biometricOperationTimestamp = Carbon::createFromTimestamp($biometricData->OperationTime, Config('app.timezone'))->toDateTimeString(); | |
| $biometricOperationtime = Carbon::parse($biometricOperationTimestamp, Config('app.timezone'))->toTimeString(); | |
| $biometricDate = Carbon::parse($biometricOperationTimestamp, Config('app.timezone'))->toDateString(); | |
| $query = AttendanceDetail::query(); | |
| $query->whereDate('check_in', '=', $biometricDate); | |
| $query->where('user_id', '=', $biometricData->UserId); | |
| $attendanceDetail = $query->get(); | |
| $offsetStartTime = Carbon::parse($shiftStartTime); | |
| $offsetStartTime = $offsetStartTime->subHours(4)->toTimeString(); | |
| $offsetEndTime = Carbon::parse($shiftEndTime); | |
| $offsetEndTime = $offsetEndTime->addHours(4)->toTimeString(); | |
| if ($attendanceDetail->isEmpty()) //if no attendance is marked for the user that particular day | |
| { | |
| if ($attendanceValue == 1) { | |
| //save checkin with shift details when no checkin/no checkout is selected | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Biometric'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $biometricData->UserId; | |
| $attendance->check_in = null; | |
| $attendance->check_out = null; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| } | |
| if ( | |
| ($biometricOperationtime < $shiftStartTime && $biometricOperationtime > $offsetStartTime) || | |
| ($biometricOperationtime == $shiftStartTime) || ($biometricOperationtime > $shiftStartTime && ($offsetEndTime < $biometricOperationtime)) | |
| ) { | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Biometric'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $biometricData->UserId; | |
| $attendance->check_in = $biometricOperationTimestamp; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| } else { | |
| $biometricDate = Carbon::createFromTimestamp($biometricData->OperationTime, 'UTC')->subday()->toDateString(); | |
| $query = AttendanceDetail::query(); | |
| $query->whereDate('check_in', '=', $biometricDate); | |
| $query->where('user_id', '=', $biometricData->UserId); | |
| $attendanceDetail = $query->get(); | |
| if ($attendanceDetail->isEmpty()) //if no attendance is marked for the user that particular day | |
| { | |
| $attendance = new AttendanceDetail; | |
| $attendance->mode = 'Biometric'; | |
| $attendance->attendance_setting = $attendanceValue; | |
| $attendance->user_id = $biometricData->UserId; | |
| $attendance->check_out = $biometricOperationTimestamp; | |
| $attendance->shift_start = $shiftStartTime; | |
| $attendance->shift_end = $shiftEndTime; | |
| } else { | |
| foreach ($attendanceDetail as $attendanceEntry) { | |
| $attendanceEntry->check_out = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } | |
| } | |
| $attendance->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } else { | |
| foreach ($attendanceDetail as $attendanceEntry) { | |
| if ($attendanceEntry->check_in != null) //check_in | |
| { | |
| if (Carbon::parse($attendanceEntry->check_in)->toTimeString() > $biometricOperationtime) { | |
| $attendanceEntry->check_in = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } else { | |
| if ( | |
| ($biometricOperationtime < $shiftStartTime && $biometricOperationtime > $offsetStartTime) || | |
| ($biometricOperationtime == $shiftStartTime) || ($biometricOperationtime > $shiftStartTime && ($offsetEndTime < $biometricOperationtime)) | |
| ) { | |
| $attendanceEntry->check_in = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } | |
| if ($attendanceEntry->check_out != null) //check out | |
| { | |
| if (Carbon::parse($attendanceEntry->check_out)->toTimeString() < $biometricOperationtime) { | |
| $attendanceEntry->check_out = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } else { | |
| $attendanceEntry->check_out = $biometricOperationTimestamp; | |
| $attendanceEntry->save(); | |
| $biometricData->isProcessed = true; | |
| $biometricData->save(); | |
| return; | |
| } | |
| } | |
| } | |
| } | |
| public function isHoliday() | |
| { | |
| $holidaydate = Session::get('session_biometricdata_id'); | |
| $biometric = BiometricData::findOrFail($holidaydate); | |
| $machinedata = $biometric->OperationTime; | |
| $holiday = Holiday::findorFail($holidaydate); | |
| $holidaydetail = $holiday->date == $machinedata; | |
| $holidaydate = $holidaydetail; | |
| } | |
| public function isLeave() | |
| { | |
| $id = Session::get('session_biometricdata_id'); | |
| $leave = Leave::findOrFail($id); | |
| $leavedetail = $leave->user_id; | |
| $id = $leavedetail; | |
| } | |
| public function getShiftDetails($user) | |
| { | |
| $shift = $user->userdetail; | |
| return $user->userdetail->shifts; | |
| } | |
| public function didNotCheckinNotification() | |
| { | |
| $userAttendance = User::find(Auth::user()->id); | |
| $userDetail = UserDetail::where('user_id', '=', Auth::user()->id)->first(); | |
| $todayDate = Carbon::now(config('settings.time_zone'))->format(config('settings.php_date_format')); | |
| //primary reporting manager | |
| $primary_reporting_manager_id = $userDetail->primary_reporting_manager_id; | |
| //secondary reporting manager | |
| $secondaryManagers = $userDetail->secondaryManager; | |
| //primary team name | |
| $userInTeam = $userDetail->primaryTeamName->team; | |
| $subjectLine = $userAttendance->name . ' ' . $userAttendance->lastName . ' did not Check In for ' . $todayDate; | |
| $title = 'Did not Checkin'; | |
| $checkTime = 'Check-In-Time - ' . ''; | |
| if ($primary_reporting_manager_id != 0) { | |
| //primary reporting manager | |
| $primary_reporting_manager = User::find($primary_reporting_manager_id); | |
| //check if user is exists | |
| if (!empty($primary_reporting_manager)) { | |
| $arr = null; | |
| $arr = [$userInTeam, $userAttendance->name . ' ' . $userAttendance->lastName, $checkTime, $subjectLine, $title]; | |
| $primary_reporting_manager->notify(new AttendanceDetailNotifications($arr)); | |
| $firebaseObject = new FirebaseCloudMessaging(); | |
| $firebaseObject->sendFirebaseNotification($title,$subjectLine,$primary_reporting_manager_id); | |
| } | |
| } | |
| //secondary reporting managers | |
| if (count($secondaryManagers) > 0) { | |
| foreach ($secondaryManagers as $secondaryManager) { | |
| if ($primary_reporting_manager_id != $secondaryManager->id) { | |
| $message="FCM Backend"; | |
| $arr = null; | |
| $arr = [$userInTeam, $userAttendance->name . ' ' . $userAttendance->lastName, $checkTime, $subjectLine, $title]; | |
| $secondaryManager->notify(new AttendanceDetailNotifications($arr)); | |
| $firebaseObject = new FirebaseCloudMessaging(); | |
| $firebaseObject->sendFirebaseNotification($title,$message,$secondaryManager->id); | |
| } | |
| } | |
| } | |
| $subjectLine = 'You did not Check In for ' . $todayDate; | |
| $arr = null; | |
| $arr = [$userInTeam, $userAttendance->name . ' ' . $userAttendance->lastName, $checkTime, $subjectLine, $title]; | |
| $userAttendance->notify(new AttendanceDetailNotifications($arr)); | |
| $firebaseObject = new FirebaseCloudMessaging(); | |
| $firebaseObject->sendFirebaseNotification($title,$message,$userAttendance); | |
| $slackMessage = 'Did not check in. Team:' . ' ' . $userInTeam . ', ' . 'Name:' . ' ' . $userAttendance->name . ' ' . | |
| $userAttendance->lastName; | |
| $userAttendance->notify(new SlackNotifications($slackMessage)); //username or checked in time | |
| } | |
| } |