Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 84 |
| MyScheduleController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
506 | |
0.00% |
0 / 84 |
| index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| 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 |
|||
| fetchCalendarData | |
0.00% |
0 / 1 |
240 | |
0.00% |
0 / 74 |
|||
| <?php | |
| namespace App\Http\Controllers\ScheduleManagement; | |
| use App\Http\Controllers\Controller; | |
| use Illuminate\Http\Request; | |
| // use Illuminate\Support\Facades\Auth; | |
| use App\Models\Auth\User; | |
| use App\Models\Admin\UserDetailTeam; | |
| use App\Models\Admin\TeamShiftDetail; | |
| use App\Models\Admin\UserDetail; | |
| use App\Models\Schedule\ScheduleDetail; | |
| use App\Models\Leave\ApplyLeave; | |
| use App\Models\Schedule\Schedule; | |
| use App\Models\Auth\UserShift; | |
| use Carbon\Carbon; | |
| use App\Helpers\AttendanceHelper; | |
| class MyScheduleController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index(Request $request) | |
| { | |
| // For returning attendance marking for home controller | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| return view('ScheduleManagement.mySchedule', compact('val','valTeam','valUser')); | |
| } | |
| /** | |
| * 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) | |
| { | |
| // | |
| } | |
| /** | |
| * 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 ) | |
| { | |
| $start = $request->start; | |
| $end = $request->end; | |
| /* Find Out my team*/ | |
| // $user = User::where('id', auth()->id())->with('userdetailWithTeam')->first(); | |
| // $teams = $user->userdetailWithTeam['teams']; | |
| $user = User::where('id', auth()->id())->first(); | |
| $team = $user->userdetail->primary_team_id; | |
| $events = array(); | |
| // foreach ( $teams as $team ) { | |
| if(!empty($user->userdetail)){ | |
| $teamId = $user->userdetail->primary_team_id; | |
| //primary team name | |
| $teamName = $user->userdetail->primaryTeamName->team; | |
| /* Find Out Shift of my team*/ | |
| $teamShifts = TeamShiftDetail::where('team_id', $teamId)->with('shift')->whereHas('shift')->get(); | |
| $start = date('Y-m-d H:i:s', strtotime($start)); | |
| $end = date('Y-m-d H:i:s', strtotime($end)); | |
| $tableMetaData = array(); | |
| $shiftIdArray = $teamShifts->pluck('shift_id'); | |
| /* 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=''; | |
| $userShiftQuery = array( | |
| 'date' => $start, | |
| 'user_id'=>auth()->id() | |
| ); | |
| // apply loop in my all shift and check which one shift i am working on this date($start) | |
| foreach($shiftIdArray as $shiftId) { | |
| $userShift = UserShift::where($userShiftQuery)->where('shift_id', $shiftId)->with('shift')->whereHas('shift')->first(); | |
| if($userShift){ | |
| // checking on this date ($start) i was on leave. | |
| $isLeave = ApplyLeave::where('from_date', '<=', $start)->where('to_date', '>=', $start)->where('user_id', auth()->id())->where('is_process', true)->first(); | |
| $userNames .= ( '<br>' . ( isset($isLeave) ? '<span class="text-danger">Leave </span>' : '' ) ); | |
| $shiftStartTime = Carbon::parse($userShift->shift_start); | |
| $shiftStartTime->setTimezone(config('settings.time_zone')); | |
| $shiftStartTime = date(Config('settings.time_format'), strtotime($shiftStartTime)); | |
| $shiftEndTime = Carbon::parse($userShift->shift_end); | |
| $shiftEndTime->setTimezone(config('settings.time_zone')); | |
| $shiftEndTime = date(Config('settings.time_format'), strtotime($shiftEndTime)); | |
| $events[] = [ | |
| "start" => $start, | |
| "title" => "<br><b>{$userShift->shift->shift} - {$teamName}</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)) { | |
| $defaultScheduleQuery = array( | |
| 'is_default' => 1, | |
| 'status' => '0', | |
| 'team_id' => $teamId | |
| ); | |
| $activeSchedule = Schedule::where($defaultScheduleQuery) | |
| ->first(); | |
| } | |
| if(isset($activeSchedule)) { | |
| foreach ($teamShifts as $teamShift) { | |
| $day = date('D', strtotime($start)); | |
| $day = strtolower($day); | |
| $scheduleDetailQuery = array( | |
| $day => 1, | |
| 'schedule_id' => $activeSchedule->id, | |
| 'shift_id' => $teamShift->shift->id, | |
| 'is_active' => 1, | |
| // 'user_id' => $user->userdetailWithTeam['id'] | |
| 'user_id' => $user->id | |
| ); | |
| // get the users. loop over those and print the events pls. | |
| $userNames = ''; | |
| $schedules = ScheduleDetail::where($scheduleDetailQuery)->get(); | |
| // return $schedules; | |
| $j = 1; | |
| if(count($schedules) > 0) { | |
| foreach ($schedules as $schedule) { | |
| $isLeave = ApplyLeave::where('from_date', '<=', $start)->where('to_date', '>=', $start)->where('user_id', auth()->id())->where('is_process', true)->first(); | |
| $userNames .= ( '<br>' . ( isset($isLeave) ? '<span class="text-danger">Leave </span>' : '' ) ); | |
| $j++; | |
| } | |
| 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)); | |
| } | |
| $events[] = [ | |
| "start" => $start, | |
| "title" => "<br><b>{$teamShift->shift->shift} - {$teamName}</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 | |
| ); | |
| } | |
| } |