Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 151 |
| ApplyCompOffLeaveController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
2070 | |
0.00% |
0 / 151 |
| index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
| create | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 12 |
|||
| store | |
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 36 |
|||
| 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 / 5 |
|||
| destroy | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| checkCompOffLeaveexists | |
0.00% |
0 / 1 |
930 | |
0.00% |
0 / 87 |
|||
| <?php | |
| namespace App\Http\Controllers\Leave; | |
| use App\Http\Controllers\FirebaseController\FirebaseCloudMessaging; | |
| use Illuminate\Http\Request; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Admin\Leave; | |
| use App\Models\Auth\User; | |
| use App\Models\Leave\ApplyLeave; | |
| use App\Models\Leave\LeaveEntitlement; | |
| use App\Models\Admin\Weekend; | |
| use Illuminate\Support\Facades\Validator; | |
| use Session; | |
| use Carbon\Carbon; | |
| use Auth; | |
| use DB; | |
| use Illuminate\Support\Facades\Log; | |
| //use App\Models\NotificationModel\NotificationList; | |
| use App\Notifications\ApplyLeaveNotifications; | |
| use App\Models\Admin\Holiday; | |
| use App\Helpers\HolidayHelper; | |
| use App\Helpers\LeaveHelper; | |
| use App\Models\Admin\Setting; | |
| use App\Notifications\AppNotifications; | |
| use App\Models\Leave\CompOffLeave; | |
| use App\Models\Dashboard\AttendanceDetail; | |
| use App\Models\Auth\UserWeeklyOff; | |
| use App\Models\Admin\Team; | |
| use App\Helpers\AttendanceHelper; | |
| class ApplyCompOffLeaveController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index(Request $request) | |
| { | |
| $title = '/Leave/Leave Report'; | |
| $leave = CompOffLeave::orderBy('created_at', 'DESC')->get(); | |
| // For returning attendance marking for home controller | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| return view('leave.applyCompOffLeaveTable', compact('title', 'leave','val','valTeam','valUser')); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create(Request $request) | |
| { | |
| $title = '/Leave/Apply Comp Off Leave Balance'; | |
| $allow_coff_for_future_dates = Setting::where('name', 'allow_coff_for_future_dates')->first(); | |
| if(!empty($allow_coff_for_future_dates)){ | |
| $all_future_date = $allow_coff_for_future_dates->value; | |
| $future_requests_till_days = Setting::where('name', 'future_requests_till_days')->pluck('value')->first(); | |
| }else{ | |
| $all_future_date = null; | |
| $future_requests_till_days = null; | |
| } | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| return view('leave.applyCompOffLeaveForm', compact('title','all_future_date', | |
| 'future_requests_till_days','val','valTeam','valUser')); | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| $user = Auth::user(); | |
| $date = Carbon::parse(Carbon::createFromFormat(config('settings.php_date_format'), $request->date))->format('Y-m-d'); | |
| $checkCompOffLeave = Leave::where('name', 'Comp off Leave - Paid')->where('system_generated', 1)->first(); | |
| //primary reporting manager | |
| $primary_reporting_manager_id = $user->userdetail->primary_reporting_manager_id; | |
| //secondary reporting manager | |
| $secondaryManagers = $user->userdetail->secondaryManager; | |
| $requestDate = Carbon::parse(Carbon::createFromFormat(config('settings.php_date_format'), $request->date)); | |
| $todayDate = Carbon::now(config('settings.time_zone')); | |
| if($requestDate->gt($todayDate)){ | |
| $is_future = 'true'; | |
| }else{ | |
| $is_future = 'false'; | |
| } | |
| if (!empty($user->userdetail)) { | |
| CompOffLeave::create([ | |
| 'date' => $date, | |
| 'is_process' => 'false', | |
| 'is_future' => $is_future, | |
| 'user_id' => $user->id, | |
| 'leave_id' => $checkCompOffLeave->id, | |
| 'status' => 'Pending' | |
| ]); | |
| $title = "Comp Off Leave Balance Request"; | |
| $arr = null; | |
| $message = ( "Comp Off Leave Balance requested by ".$user->name . ' ' . $user->lastName); | |
| $arr = [$title, $message, null]; | |
| 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)) { | |
| $primary_reporting_manager->notify(new AppNotifications($arr)); | |
| $firebaseObject = new FirebaseCloudMessaging(); | |
| $firebaseObject->sendFirebaseNotification($title,$message,$primary_reporting_manager_id); | |
| } | |
| } | |
| //secondary reporting managers | |
| if (count($secondaryManagers) > 0) { | |
| foreach ($secondaryManagers as $secondaryManager) { | |
| if ($primary_reporting_manager_id != $secondaryManager->id) { | |
| $secondaryManager->notify(new AppNotifications($arr)); | |
| $firebaseObject = new FirebaseCloudMessaging(); | |
| $firebaseObject->sendFirebaseNotification($title,$message,$secondaryManager->id); | |
| } | |
| } | |
| } | |
| } | |
| Session::flash('success', ' Submit Comp Off Leave Balance Request Successfully!'); | |
| return redirect()->route('apply-comp-off-leave.create'); | |
| } | |
| /** | |
| * 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) | |
| { | |
| $leaves = CompOffLeave::find($id); | |
| $leaves->is_process = 'true'; | |
| $leaves->update($request->all()); | |
| Session::flash('warning', 'Cancel Comp Off Leave Successfully!'); | |
| return redirect()->route('apply-comp-off-leave.index')->withErrors($this); | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy($id) | |
| { | |
| $leave = CompOffLeave::find($id); | |
| $leave->delete(); | |
| return redirect()->route('apply-comp-off-leave.index')->with('success', 'Comp Off Leave Deleted Successfully'); | |
| } | |
| public function checkCompOffLeaveexists(Request $request) | |
| { | |
| $leaves = Leave::where('name', 'Comp off Leave - Paid')->where('system_generated', 1)->get(); | |
| $comp_off = Setting::where('name','comp_off')->first(); | |
| if(empty($comp_off)){ | |
| return response()->json([ | |
| 'status' => '100', | |
| 'message' => 'Comp off Leave Setting is not enabled' | |
| ]); | |
| }else{ | |
| $include_weekend = Setting::where('name', 'include_weekend')->first(); | |
| $allow_coff_for_future_dates = Setting::where('name', 'allow_coff_for_future_dates')->first(); | |
| $all_future_date = $allow_coff_for_future_dates->value; | |
| $get_request_approval_days = Setting::where('name', 'request_approval_days')->first(); | |
| $request_approval_days = $get_request_approval_days->value; | |
| $date = Carbon::parse(Carbon::createFromFormat(config('settings.php_date_format'), $request->date))->format('Y-m-d'); | |
| $startDateForCompOffDay = Carbon::parse($date . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $endDateForCompOffDay = Carbon::parse(Carbon::parse($date)->addDay()->toDateString() . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $dateWithTimezone = Carbon::parse(Carbon::createFromFormat(config('settings.php_date_format'), $request->date)); | |
| $nowDate = Carbon::now(config('settings.time_zone')); | |
| $greaterDate = $dateWithTimezone->gt($nowDate); | |
| $userid = Auth::user()->id; | |
| $user = Auth::user(); | |
| $day = []; | |
| if (!empty($user->userdetail) && count($user->userdetail->shifts) > 0) { | |
| //user on weekend | |
| $weekend = $user->userdetail->shifts[0]->weekend; | |
| if ($weekend['monday'] == 1) { | |
| $day[] = 'Monday'; | |
| } | |
| if ($weekend['tuesday'] == 1) { | |
| $day[] = 'Tuesday'; | |
| } | |
| if ($weekend['wednesday'] == 1) { | |
| $day[] = 'Wednesday'; | |
| } | |
| if ($weekend['thursday'] == 1) { | |
| $day[] = 'Thursday'; | |
| } | |
| if ($weekend['friday'] == 1) { | |
| $day[] = 'Friday'; | |
| } | |
| if ($weekend['saturday'] == 1) { | |
| $day[] = 'Saturday'; | |
| } | |
| if ($weekend['sunday'] == 1) { | |
| $day[] = 'Sunday'; | |
| } | |
| } | |
| //primary team id | |
| $teamId = Auth::user()->userdetail->primary_team_id; | |
| $team = Team::find($teamId); | |
| $comp_off_leave = CompOffLeave::where('user_id', '=', $userid) | |
| ->where('date', '=', $date) | |
| ->where('status', '!=', 'Cancel') | |
| ->first(); | |
| //get holidays | |
| $holidayIds = HolidayHelper::getholidayList($userid); | |
| $holiday = Holiday::where('date', $date)->whereIn('id', $holidayIds)->first(); | |
| //user sub day weekly off | |
| if (!empty($include_weekend) && $include_weekend->value == 'yes') { | |
| $userWeeklyOff = UserWeeklyOff::where('user_id', $userid) | |
| ->whereBetween('created_at', [$startDateForCompOffDay, $endDateForCompOffDay]) | |
| ->where('weekly_off', 1)->first(); | |
| $text = 'holiday/weekend'; | |
| $weekend = 'yes'; | |
| } else { | |
| $userWeeklyOff = []; | |
| $text = 'holiday'; | |
| $weekend = 'no'; | |
| } | |
| $attendance = AttendanceDetail::where('user_id', $userid) | |
| ->whereBetween('check_in', [$startDateForCompOffDay, $endDateForCompOffDay]) | |
| ->first(); | |
| if (isset($comp_off_leave) && !empty($comp_off_leave)) { | |
| return response()->json([ | |
| 'status' => '100', | |
| 'message' => 'Already Applied Comp off Leave Balance On ' . $request->date | |
| ]); | |
| } else if ($all_future_date == 'no' || $greaterDate != 1) { | |
| if (!empty($holiday) || (!empty($userWeeklyOff) && $weekend == 'yes')) { | |
| if (!empty($attendance)) { | |
| $difference = $dateWithTimezone->diffInDays($nowDate); | |
| if(($request_approval_days != NULL || | |
| $request_approval_days != 0 )&& | |
| $difference > $request_approval_days){ | |
| return response()->json([ | |
| 'status' => '100', | |
| 'message' => 'Comp off should be applied within '.$request_approval_days.' days' | |
| ]); | |
| } | |
| }else{ | |
| return response()->json([ | |
| 'status' => '100', | |
| 'message' => 'Attendance is not marked On ' . $request->date | |
| ]); | |
| } | |
| } else { | |
| return response()->json([ | |
| 'status' => '100', | |
| 'message' => $request->date . ' is not '.$text | |
| ]); | |
| } | |
| } else { | |
| if ($team->has_schedule == 0) { | |
| if (!empty($holiday) || (in_array($dateWithTimezone->format('l'), $day) == 1) && $weekend == 'yes') { | |
| }else{ | |
| return response()->json([ | |
| 'status' => '100', | |
| 'message' => $request->date . ' is not '.$text | |
| ]); | |
| } | |
| }else if($team->has_schedule == 1){ | |
| if(empty($holiday)){ | |
| return response()->json([ | |
| 'status' => '100', | |
| 'message' => $request->date . ' is not holiday' | |
| ]); | |
| } | |
| } | |
| } | |
| return response()->json([ | |
| 'status' => '200', | |
| 'message' => 'success' | |
| ]); | |
| } | |
| } | |
| } |