Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 136 |
| ViewScheduleController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
992 | |
0.00% |
0 / 136 |
| index | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 25 |
|||
| 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 / 7 |
|||
| 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 |
|||
| fetchCalendarData | |
0.00% |
0 / 1 |
380 | |
0.00% |
0 / 99 |
|||
| <?php | |
| namespace App\Http\Controllers\ScheduleManagement; | |
| use App\Http\Controllers\Controller; | |
| use Illuminate\Http\Request; | |
| use App\Models\Admin\Team; | |
| use App\Models\Schedule\Schedule; | |
| use App\Models\Admin\UserDetailTeam; | |
| use App\Models\Admin\TeamShiftDetail; | |
| use App\Models\Admin\UserDetail; | |
| use App\Models\Admin\Weekend; | |
| use App\Models\Schedule\ScheduleDetail; | |
| use App\Models\Leave\ApplyLeave; | |
| use App\Models\Auth\UserShift; | |
| use Carbon\Carbon; | |
| use App\Helpers\AttendanceHelper; | |
| use App\Models\Admin\UserDetailUser; | |
| class ViewScheduleController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index(Request $request) | |
| { | |
| /*get teams for select box in manage schedule | |
| - get teams of this sytyem | |
| */ | |
| $title = '/View Team Schedule'; | |
| $users=[]; | |
| // For Attendance Marking | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| $reportingTeam = UserDetail::select('primary_team_id') | |
| ->where('primary_reporting_manager_id', (Auth()->user()->id)) | |
| ->get(); | |
| // Extract team IDs from the collection | |
| $teamIds = $reportingTeam->pluck('primary_team_id')->toArray(); | |
| $reportTeamDetails = Team::whereIn('id', $teamIds)->get(); | |
| $matchingUserIds = array(); | |
| $reportingUserIds = UserDetailUser::where('user_id', Auth()->user()->id) | |
| ->pluck('user_detail_id'); | |
| foreach ($reportingUserIds as $reportingUserId){ | |
| // $users[] = UserDetail::select('primary_team_id')->where('id',$reportingUserId)->get(); | |
| $users[] = UserDetail::where('id', $reportingUserId)->pluck('primary_team_id')->first(); | |
| } | |
| foreach ($users as $user){ | |
| // if(count($user)==0){ | |
| // continue; | |
| // } | |
| // $matchingUserIds[] = Team::where('id',$user)->get(); | |
| $matchingUserIds[] = Team::find($user); | |
| } | |
| // if($reportTeamDetails->isEmpty() == true){ | |
| // foreach($matchingUserIds as $matchingUser){ | |
| // // $reportTeamDetails = Team::where('id', '=' ,$matchingUser[0]->id)->get(); | |
| // $reportTeamDetails[] = Team::find($matchingUser->id); | |
| // } | |
| // } | |
| // foreach($matchingUserIds as $matchingUser){ | |
| // if ($matchingUser) { | |
| // $reportTeamDetails[] = Team::find($matchingUser->id); | |
| // } | |
| // } | |
| $uniqueTeams = []; // Use an associative array to store unique team IDs | |
| foreach ($matchingUserIds as $matchingUser) { | |
| if ($matchingUser) { | |
| $teamId = $matchingUser->id; | |
| // Check if the team ID is not already in the array | |
| if (!isset($uniqueTeams[$teamId])) { | |
| $uniqueTeams[$teamId] = Team::find($teamId); | |
| } | |
| } | |
| } | |
| // Convert the associative array back to a regular indexed array | |
| $reportTeamDetails = array_values($uniqueTeams); | |
| return view('ScheduleManagement.ViewShowTeam', compact('title','val','valTeam','valUser','reportTeamDetails','matchingUserIds'))->with('show',Team::all()); | |
| } | |
| /** | |
| * 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(Request $request, $id) | |
| { | |
| /*send team detail on View Team Schedule*/ | |
| $id = base64_decode($id); | |
| $title = '/ View Team Schedule'; | |
| // 0. loop over all dates of a particular month | |
| // 1. Find out which schedule is active on a particular date. | |
| // 2. find which shifts are available on that particular schedule on a particular date | |
| // 3. which team members are active / marked active on this particular date for that shift of a particular schedule. | |
| $team = Team::where('id' ,$id)->first(); | |
| // For Attendance Marking | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| // $teamShifts = TeamShiftDetail::where('team_id', $id)->with('shift')->get(); | |
| // $teamUserId = UserDetailTeam::where('team_id', $id)->pluck('user_detail_id'); | |
| // $teamUsers= UserDetail::whereIn('id', $teamUserId)->with('user')->get(); | |
| // $schedule = Schedule::where('team_id',$id)->get(); | |
| // // echo( $schedule); | |
| // // die(); | |
| // foreach ($schedule as $schedules) { | |
| // foreach ($teamShifts as $teamShift) { | |
| // foreach ($teamUsers as $teamUser) { | |
| // $Events[] = [ | |
| // "start" => "$schedules->from_date", | |
| // // "end" => "$schedules->to_date", | |
| // "title" => "<b>{$teamShift->shift->shift}</b> | |
| // <br>{$teamShift->shift->start_time} To {$teamShift->shift->end_time} </br> | |
| // <br>{$teamUser->user['name']}", | |
| // "editable" => FALSE, | |
| // ]; | |
| // } | |
| // } | |
| // } | |
| // if(isset($Events)) { | |
| // return view('ScheduleManagement.ViewTeamSchedule',compact('title','schedule', 'Events','team')); | |
| // } else { | |
| return view('ScheduleManagement.ViewTeamSchedule',compact('title','team','val','valTeam','valUser')); | |
| // } | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit($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) | |
| { | |
| // | |
| } | |
| /** | |
| * Fetch the calendar Data. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function fetchCalendarData( Request $request, $teamId ) | |
| { | |
| $start = $request->start; // date_format( $request->start, "m" ); | |
| $end = $request->end; | |
| /* Find Out Shifts of given teamId*/ | |
| $teamShifts = TeamShiftDetail::where('team_id', $teamId)->with('shift')->whereHas('shift')->get(); | |
| $start = date('Y-m-d', strtotime($start)); | |
| $end = date('Y-m-d', strtotime($end)); | |
| $tableMetaData = array(); | |
| $shiftIdArray = $teamShifts; | |
| //$shiftIdArray = $teamShifts->pluck('shift_id','shift','start_time','end_time'); | |
| /* Apply Loop form given start date to end date | |
| - check if start date is less than form today date then data will be find out form usershift table bcz we stored daily attendance record in this table else goes into schedule_details table | |
| */ | |
| while ( $start <= $end ) { | |
| $todayDate = Carbon::now(config('settings.time_zone')); | |
| if($start < $todayDate){ | |
| $userNames = ''; $shiftStartTime=""; $shiftEndTime=''; | |
| $teamShift=''; | |
| foreach($shiftIdArray as $shiftarr) { | |
| $userShiftQuery = array( | |
| 'team_id' => $teamId, | |
| 'shift_id' => $shiftarr->shift->id, | |
| 'date' => $start | |
| ); | |
| $userShifts = UserShift::where($userShiftQuery)->with('shift')->whereHas('shift')->get(); | |
| $j = 1; | |
| // check week end here | |
| $day = date('D', strtotime($start)); | |
| $dayFull = date('l', strtotime($start)); | |
| $weekendQuery = array( | |
| $dayFull => 1, | |
| 'shift_id' =>$shiftarr->shift->id | |
| ); | |
| // $isWeekend = Weekend::where($weekendQuery)->first(); | |
| // if(!isset($isWeekend)) { | |
| $userNames = ''; | |
| foreach ($userShifts as $userShift) { | |
| if ($userShift->user && is_object($userShift->user)) { | |
| $isLeave = ApplyLeave::where('from_date', '<=', $start) | |
| ->where('to_date', '>=', $start) | |
| ->where('user_id', $userShift->user->id) | |
| ->where('is_process', true) | |
| ->first(); | |
| $userNames .= ('<br>' . $j . '. ' . (isset($isLeave) ? '<span class="text-danger">Leave - </span>' : '') . $userShift->user->name." ".$userShift->user->lastName); | |
| if (!isset($tableMetaData[$userShift->user->name." ".$userShift->user->lastName])) { | |
| $tableMetaData[$userShift->user->name." ".$userShift->user->lastName] = 0; | |
| } | |
| $tableMetaData[$userShift->user->name." ".$userShift->user->lastName] += 1; | |
| $j++; | |
| } | |
| } | |
| $shiftStartTime = Carbon::parse($shiftarr->shift->start_time); | |
| $shiftStartTime->setTimezone(config('settings.time_zone')); | |
| $shiftStartTime = date(Config('settings.time_format'), strtotime($shiftStartTime)); | |
| $shiftEndTime = Carbon::parse($shiftarr->shift->end_time); | |
| $shiftEndTime->setTimezone(config('settings.time_zone')); | |
| $shiftEndTime = date(Config('settings.time_format'), strtotime($shiftEndTime)); | |
| $teamShift = $shiftarr->shift->shift; | |
| $events[] = [ | |
| "start" => $start, | |
| "start_time" => $shiftStartTime, | |
| //"end" => "$schedules->to_date", | |
| "title" => "<b>{$teamShift}</b><br>{$shiftStartTime} - {$shiftEndTime}" . $userNames, | |
| "allDay" => true | |
| ]; | |
| // } | |
| } | |
| }else{ | |
| // 1. Find out schedule on start date | |
| $specialSchedule = Schedule::where('from_date', '<=', $start) | |
| ->where('to_date', '>=', $start)->where('status', '0') | |
| ->where('team_id', $teamId) | |
| ->first(); | |
| $activeSchedule = $specialSchedule; | |
| // if spacial schedule not find out then goes to default(regular) schedule | |
| if(!isset($specialSchedule)) { | |
| $activeSchedule = Schedule::where('is_default', 1) | |
| ->where('status', '0') | |
| ->where('team_id', $teamId) | |
| ->first(); | |
| } | |
| if(isset($activeSchedule)) { | |
| // start loop on team shifts | |
| foreach ($teamShifts as $teamShift) { | |
| $day = date('D', strtotime($start)); | |
| $dayFull = date('l', strtotime($start)); | |
| $weekendQuery = array( | |
| $dayFull => 1, | |
| 'shift_id' => $teamShift->shift->id | |
| ); | |
| // $isWeekend = Weekend::where($weekendQuery)->first(); | |
| // if(!isset($isWeekend)) { | |
| $day = strtolower($day); | |
| $scheduleDetailQuery = array( | |
| $day => 1, | |
| 'schedule_id' => $activeSchedule->id, | |
| 'shift_id' => $teamShift->shift->id, | |
| 'is_active' => 1, | |
| 'team_id'=> $teamId | |
| ); | |
| if(isset($teamShift->shift->start_time)) { | |
| $shiftStartTime = Carbon::parse($teamShift->shift->start_time); | |
| $shiftStartTime->setTimezone(config('settings.time_zone')); | |
| $shiftStartTime = date(Config('settings.time_format'), strtotime($shiftStartTime)); | |
| } | |
| if(isset($teamShift->shift->end_time)) { | |
| $shiftEndTime = Carbon::parse($teamShift->shift->end_time); | |
| $shiftEndTime->setTimezone(config('settings.time_zone')); | |
| $shiftEndTime = date(Config('settings.time_format'), strtotime($shiftEndTime)); | |
| } | |
| // get the users. loop over those and print the events pls. | |
| $userNames = ''; | |
| $schedules = ScheduleDetail::where($scheduleDetailQuery)->with('user')->get(); | |
| $j = 1; | |
| /*print_r($schedules); | |
| exit;*/ | |
| foreach ($schedules as $schedule) { | |
| if ($schedule->user && is_object($schedule->user)) { | |
| $isLeave = ApplyLeave::where('from_date', '<=', $start) | |
| ->where('to_date', '>=', $start) | |
| ->where('user_id', $schedule->user->id) | |
| ->where('is_process', true) | |
| ->first(); | |
| $userNames .= ('<br>' . $j . '. ' . (isset($isLeave) ? '<span class="text-danger">Leave - </span>' : '') . $schedule->user->name . ' ' . $schedule->user->lastName); | |
| $fullName = $schedule->user->name . ' ' . $schedule->user->lastName; | |
| if (!isset($tableMetaData[$fullName])) { | |
| $tableMetaData[$fullName] = 0; | |
| } | |
| $tableMetaData[$fullName] += 1; | |
| $j++; | |
| } | |
| } | |
| $events[] = [ | |
| "start" => $start, | |
| "start_time" => $shiftStartTime, | |
| // "end" => "$schedules->to_date", | |
| "title" => "<b>{$teamShift->shift->shift}</b><br>{$shiftStartTime} - {$shiftEndTime}" . $userNames, | |
| "allDay" => true | |
| ]; | |
| //} | |
| } | |
| } | |
| // get available schedule of the day | |
| } | |
| $start = date('Y-m-d', strtotime($start . ' +1 day')); | |
| } | |
| return array( | |
| 'events' => $events, | |
| 'tableData' => $tableMetaData | |
| ); | |
| } | |
| } |