Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 207 |
| GetShiftDetailHelper | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
2450 | |
0.00% |
0 / 207 |
| getShiftDetail | |
0.00% |
0 / 1 |
650 | |
0.00% |
0 / 140 |
|||
| getMyReportingEmployees | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| getMyReport | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| getCollabratorLeaves | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| getMyReportingEmployeesIds | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| getMyteamMembers | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 16 |
|||
| getMyteams | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 10 |
|||
| getMyteamIds | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 10 |
|||
| getPrimaryReportingManager | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
| checkReportingManagers | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 8 |
|||
| checkUserIsSecondaryManager | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| <?php | |
| namespace App\Helpers; | |
| use App\Models\Auth\User; | |
| use App\Models\Admin\Team; | |
| use App\Models\Auth\UserShift; | |
| use Carbon\Carbon; | |
| use App\Models\Admin\Shift; | |
| use App\Models\Admin\UserDetail; | |
| use App\Models\Admin\UserDetailTeam; | |
| use App\Models\Admin\UserDetailUser; | |
| use App\Models\Auth\userRequestCollaborator; | |
| use App\Models\AttendanceRequests\UserAttendanceRequests; | |
| class GetShiftDetailHelper{ | |
| public static function getShiftDetail($user_id,$startDate,$endDate){ | |
| $isShift = 1; | |
| $user = User::where('id',$user_id)->first(); | |
| if(!empty($user)){ | |
| //if user has details in user_details table and primary team | |
| if(!empty($user->userdetail) && $user->userdetail->primary_team_id != 0){ | |
| //get shift details | |
| $shiftDetails = $user->userdetail->shifts; | |
| foreach ($shiftDetails as $shift) { | |
| $shiftStartTime = $shift->start_time; | |
| $shiftEndTime = $shift->end_time; | |
| $bufferCheckinTime = $shift->buffer_on_checkin; | |
| $bufferCheckoutTime = $shift->buffer_on_checkout; | |
| } | |
| //primary team id | |
| $teamId = $user->userdetail->primary_team_id; | |
| $team = Team::find($teamId); | |
| //Scheduled Users shift | |
| $userShift = UserShift::where('user_id',$user->id) | |
| ->whereBetween('created_at', [$startDate, $endDate]) | |
| ->first(); | |
| //current time | |
| $today_date_time = Carbon::now(config('settings.time_zone')); | |
| $time_now = $today_date_time->toTimeString(); | |
| //if user's team has schedule | |
| 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')); | |
| $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 buffer timings | |
| $bufferTime = Shift::where('id',$userShiftForSubday->shift_id)->select('buffer_on_checkin','buffer_on_checkout')->first(); | |
| $bufferCheckinTime = $bufferTime->buffer_on_checkin; | |
| $bufferCheckoutTime = $bufferTime->buffer_on_checkout; | |
| //get shift start time | |
| $shiftStartTimeForSubday = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')); | |
| $shiftStartTimeForSubday->setTimezone(config('settings.time_zone')); | |
| $shiftStartTimeForSubday = $shiftStartTimeForSubday->toTimeString(); | |
| //get shift end time | |
| $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 time to shift offset 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 for current time is not between shift timings | |
| 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; | |
| $bufferTime = Shift::where('id',$userShift->shift_id)->select('buffer_on_checkin','buffer_on_checkout')->first(); | |
| $bufferCheckinTime = $bufferTime->buffer_on_checkin; | |
| $bufferCheckoutTime = $bufferTime->buffer_on_checkout; | |
| $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{ | |
| $isShift = 0; | |
| } | |
| }else{ | |
| $isShift = 0; | |
| } | |
| } | |
| }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; | |
| $bufferTime = Shift::where('id',$userShift->shift_id)->select('buffer_on_checkin','buffer_on_checkout')->first(); | |
| $bufferCheckinTime = $bufferTime->buffer_on_checkin; | |
| $bufferCheckoutTime = $bufferTime->buffer_on_checkout; | |
| $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{ | |
| $isShift = 0; | |
| } | |
| }else{ | |
| $isShift = 0; | |
| } | |
| } | |
| }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; | |
| $bufferTime = Shift::where('id',$userShift->shift_id)->select('buffer_on_checkin','buffer_on_checkout')->first(); | |
| $bufferCheckinTime = $bufferTime->buffer_on_checkin; | |
| $bufferCheckoutTime = $bufferTime->buffer_on_checkout; | |
| $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{ | |
| $isShift = 0; | |
| } | |
| }else{ | |
| $isShift = 0; | |
| } | |
| } | |
| }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; | |
| $bufferCheckinTime = $shift->buffer_on_checkin; | |
| $bufferCheckoutTime = $shift->buffer_on_checkout; | |
| } | |
| } | |
| } | |
| if($isShift == 1 ){ | |
| //change start time and end time to settings timezone | |
| $shiftStartTime = Carbon::createFromFormat('H:i:s', $shiftStartTime, Config('app.timezone')); | |
| $shiftStartTime->setTimezone(config('settings.time_zone')); | |
| $shiftStartTime = $shiftStartTime->toTimeString(); | |
| $shiftEndTime = Carbon::createFromFormat('H:i:s', $shiftEndTime, Config('app.timezone')); | |
| $shiftEndTime->setTimezone(config('settings.time_zone')); | |
| $shiftEndTime = $shiftEndTime->toTimeString(); | |
| $shift_details['shiftStartTime'] = $shiftStartTime; | |
| $shift_details['shiftEndTime'] = $shiftEndTime; | |
| $shift_details['bufferCheckinTime'] = $bufferCheckinTime; | |
| $shift_details['bufferCheckoutTime'] = $bufferCheckoutTime; | |
| return $shift_details; | |
| } | |
| } | |
| } | |
| } | |
| public static function getMyReportingEmployees(){ | |
| $user = User::find(auth()->id()); | |
| $userDetailId = $user->userReportingEmployee->pluck('user_detail_id'); | |
| return $userIds = UserDetail::whereIn('id', $userDetailId) | |
| ->orWhere('primary_reporting_manager_id',auth()->id()) | |
| ->get()->pluck('user_id'); | |
| } | |
| public static function getMyReport(){ | |
| $user = User::find(auth()->id()); | |
| $userID = $user->id; | |
| // dd($userID); | |
| return $userId = UserDetail::Where('user_id', $userID) | |
| ->get()->pluck('user_id'); | |
| } | |
| public static function getCollabratorLeaves($leave){ | |
| // Auth user is collaborator to leave/attendance request | |
| return userRequestCollaborator::where('module', $leave) | |
| ->where('user_id', auth()->id()) | |
| ->get()->pluck('context_id'); | |
| } | |
| public static function getMyReportingEmployeesIds(){ | |
| $user = User::find(auth()->id()); | |
| $userDetailId = $user->userReportingEmployee->pluck('user_detail_id'); | |
| return $userIds = UserDetail::whereIn('id', $userDetailId) | |
| ->orWhere('primary_reporting_manager_id',auth()->id()) | |
| ->pluck('user_id')->toArray(); | |
| } | |
| public static function getMyteamMembers(){ | |
| $user = User::where('id', auth()->id())->with('userdetailWithTeam')->first(); | |
| if (!empty($user->userdetail) && count($user->userdetail->shifts) > 0) { | |
| $teams = $user->userdetailWithTeam['teams']; | |
| $teamId = []; | |
| if($user->userdetail->primary_team_id != 0){ | |
| //primary team id | |
| $teamId[] = $user->userdetail->primary_team_id; | |
| } | |
| if(!empty($teams)){ | |
| foreach ( $teams as $team ) { | |
| $teamId[] = $team->id; | |
| } | |
| } | |
| $teamUserDetialIds = UserDetailTeam::whereIn('team_id', $teamId)->pluck('user_detail_id'); | |
| $teamUserIds = UserDetail::whereIn('id', $teamUserDetialIds) | |
| ->where('deleted_at', NULL) | |
| ->orWhereIn('primary_team_id',$teamId ) | |
| ->pluck('user_id'); | |
| return $teamUserIds; | |
| }else{ | |
| return [0]; | |
| } | |
| } | |
| public static function getMyteams(){ | |
| $user = User::where('id', auth()->id())->with('userdetailWithTeam')->first(); | |
| $teamIds = []; | |
| if($user->userdetail->primary_team_id != 0){ | |
| //primary team id | |
| $teamIds[] = $user->userdetail->primary_team_id; | |
| } | |
| $teams = $user->userdetailWithTeam['teams']; | |
| if(!empty($teams)){ | |
| $getTeamIds = $teams->pluck('id')->unique()->toArray(); | |
| foreach($getTeamIds as $teamId){ | |
| $teamIds[] = $teamId; | |
| } | |
| } | |
| return $teams =Team::whereIn('id', $teamIds)->get(); | |
| } | |
| public static function getMyteamIds(){ | |
| $user = User::where('id', auth()->id())->with('userdetailWithTeam')->first(); | |
| $teamIds = []; | |
| if($user->userdetail->primary_team_id != 0){ | |
| //primary team id | |
| $teamIds[] = $user->userdetail->primary_team_id; | |
| } | |
| $teams = $user->userdetailWithTeam['teams']; | |
| if(!empty($teams)){ | |
| $getTeamIds = $teams->pluck('id')->unique()->toArray(); | |
| foreach($getTeamIds as $teamId){ | |
| $teamIds[] = $teamId; | |
| } | |
| } | |
| return $teamIds; | |
| } | |
| //get user's primary reporting manager | |
| public static function getPrimaryReportingManager($user_id){ | |
| $user = User::where('id',$user_id)->first(); | |
| if(!empty($user->userdetail)){ | |
| $primaryReportingManager = $user->userdetail->primary_reporting_manager_id; | |
| return $primaryReportingManager; | |
| }else{ | |
| return 0; | |
| } | |
| } | |
| //get user's secondary reporting managers | |
| public static function checkReportingManagers($user_id){ | |
| $user = User::where('id',$user_id)->first(); | |
| if(!empty($user->userdetail)){ | |
| //secondary reporting managers | |
| $secondaryManagers = $user->userdetail->secondaryManager; | |
| $managers = []; | |
| foreach($secondaryManagers as $secondaryManager){ | |
| $managers[] = $secondaryManager->id; | |
| } | |
| return in_array(auth()->id(), $managers); | |
| }else{ | |
| return false; | |
| } | |
| } | |
| //check user is secondary manager for any user | |
| public static function checkUserIsSecondaryManager($user_id){ | |
| return UserDetailUser::where('user_id',$user_id)->get(); | |
| } | |
| } | |