public function forms()
 {
     $exitPass = ExitPass::where('status', '!=', 3)->get();
     $leaveForm = Leaves::where('status', '!=', 3)->get();
     $changeSchedule = Change::where('status', '!=', 3)->get();
     $oas = Overtime::where('status', '!=', 3)->get();
     return count($exitPass) + count($leaveForm) + count($changeSchedule) + count($oas);
 }
 public function editOver(array $data, $id)
 {
     $dateUpdate = date("Y-m-d H:i:s");
     // dd($data);
     $count = $data['count'];
     $i = 1;
     echo $count;
     while ($count != 0) {
         $dateTime = DateTimeOvertime::where('id', $data['id' . $i])->update(array('date_overtime' => $data['dateOvertime' . $i], 'time_overtime' => $data['timeOvertime' . $i], 'updated_at' => $dateUpdate));
         $i++;
         $count--;
     }
     return Overtime::where('id', $id)->update(array('permission_id1' => $data['supervisor'], 'purpose' => $data['purpose'], 'updated_at' => $dateUpdate));
 }
 public function editOver(array $data, $id)
 {
     // dd($data);
     $count = $data['count'];
     $daysTotal = 0;
     $hoursTotal = 0;
     $minutesTotal = 0;
     $secondsTotal = 0;
     $i = 1;
     // echo $count;
     // dd($data);
     while ($count != 0) {
         $seconds = strtotime($data['dateToOvertime' . $i] . $data['timeToOvertime' . $i]) - strtotime($data['dateFromOvertime' . $i] . $data['timeFromOvertime' . $i]);
         $days = floor($seconds / 86400);
         $hours = floor(($seconds - $days * 86400) / 3600);
         $minutes = floor(($seconds - $days * 86400 - $hours * 3600) / 60);
         $seconds = floor($seconds - $days * 86400 - $hours * 3600 - $minutes * 60);
         $daysTotal += $days;
         $hoursTotal += $hours;
         $minutesTotal += $minutes;
         $secondsTotal += $seconds;
         $dateTime = DateTimeOvertime::where('id', $data['id' . $i])->update(array('dateFromOvertime' => $data['dateFromOvertime' . $i], 'timeFromOvertime' => $data['timeFromOvertime' . $i], 'dateToOvertime' => $data['dateToOvertime' . $i], 'timeToOvertime' => $data['timeToOvertime' . $i]));
         // echo $daysTotal . '<br/>';
         // echo $hoursTotal . '<br/>';
         // echo $minutesTotal . '<br/>';
         // echo $data['dateFromOvertime'.$i] . '=' . $data['timeFromOvertime'.$i] . '<br/>';
         // echo $data['dateToOvertime'.$i] . '=' .$data['timeToOvertime' .$i] . '<br/>';
         // echo 'id: ' . $data['id'. $i];
         $i++;
         $count--;
     }
     if ($minutesTotal == 0) {
         $overtime = $daysTotal * 24 + $hoursTotal . ':00';
     } elseif ($minutesTotal > 0 && $minutesTotal < 10) {
         $overtime = $daysTotal * 24 + $hoursTotal . ':0' . $minutesTotal;
     } else {
         $overtime = $daysTotal * 24 + $hoursTotal . ':' . $minutesTotal;
     }
     // echo $overtime;
     return Overtime::where('id', $id)->update(array('permission_id1' => $data['supervisor'], 'purpose' => $data['purpose'], 'total_overtime' => $overtime));
 }
 public function postovertimeAuthSlip(Request $request)
 {
     // $rules = array('purpose' => 'required',
     //                'supervisor' => 'required',
     //                'dateFromOvertime' => 'required',
     //                'timeFromOvertime' => 'required',
     //                'dateToOvertime' => 'required',
     //                'timeToOvertime' => 'required');
     // $validator = Validator::make($request->all(), $rules);
     // if ($validator->fails()) {
     //     $this->throwValidationException(
     //         $request, $validator
     //     );
     // }
     // dd($request->all());
     $department = Positions::find(Auth::user()->position_id)->departments;
     $dateFromOvertime = strtotime($request->input('dateFromOvertime'));
     $timeFromOvertime = strtotime($request->input('timeFromOvertime'));
     $dateToOvertime = strtotime($request->input('dateToOvertime'));
     $timeToOvertime = strtotime($request->input('timeToOvertime'));
     $user_shift = Shifts::find(Auth::user()->shift_id);
     $daysTotal = 0;
     $hoursTotal = 0;
     $minutesTotal = 0;
     $secondsTotal = 0;
     // dd($user_shift);
     $dateToday = strtotime(date("Y-m-d"));
     if ($dateFromOvertime >= $dateToday && $dateToOvertime >= $dateFromOvertime) {
         if (strtotime($request->input('timeFromOvertime')) >= strtotime($user_shift->shift_to)) {
             $i = 1;
             $var = $request->input('number');
             if ($var > 1) {
                 $seconds = strtotime($request->input('dateToOvertime') . $request->input('timeToOvertime')) - strtotime($request->input('dateFromOvertime') . $request->input('timeFromOvertime'));
                 $days = floor($seconds / 86400);
                 $hours = floor(($seconds - $days * 86400) / 3600);
                 $minutes = floor(($seconds - $days * 86400 - $hours * 3600) / 60);
                 $seconds = floor($seconds - $days * 86400 - $hours * 3600 - $minutes * 60);
                 $daysTotal = $days;
                 $hoursTotal = $hours;
                 $minutesTotal = $minutes;
                 $secondsTotal = $seconds;
                 $overtime_id = Overtime::insertGetId(['user_id' => Auth::user()->id, 'department_id' => $department->id, 'purpose' => $request->input('purpose'), 'permission_id1' => $request->input('supervisor')]);
                 $firstdateTime = new DateTimeOvertime(array('user_id' => Auth::user()->id, 'dateFromOvertime' => $request->input('dateFromOvertime'), 'timeFromOvertime' => $request->input('timeFromOvertime'), 'dateToOvertime' => $request->input('dateToOvertime'), 'timeToOvertime' => $request->input('timeToOvertime'), 'overtime_id' => $overtime_id));
                 if ($firstdateTime->save()) {
                     while ($var != 0) {
                         if ($request->input('dateFromOvertime' . $i) != '' && $request->input('dateToOvertime' . $i) != '' && $request->input('timeFromOvertime' . $i) != '' && $request->input('timeFromOvertime' . $i) != '') {
                             $seconds = strtotime($request->input('dateToOvertime' . $i) . $request->input('timeToOvertime' . $i)) - strtotime($request->input('dateFromOvertime' . $i) . $request->input('timeFromOvertime' . $i));
                             $days = floor($seconds / 86400);
                             $hours = floor(($seconds - $days * 86400) / 3600);
                             $minutes = floor(($seconds - $days * 86400 - $hours * 3600) / 60);
                             $seconds = floor($seconds - $days * 86400 - $hours * 3600 - $minutes * 60);
                             $daysTotal += $days;
                             $hoursTotal += $hours;
                             $minutesTotal += $minutes;
                             $secondsTotal += $seconds;
                             $overtimeDatesTime = new DateTimeOvertime(array('user_id' => Auth::user()->id, 'dateFromOvertime' => $request->input('dateFromOvertime'), 'timeFromOvertime' => $request->input('timeFromOvertime'), 'dateToOvertime' => $request->input('dateToOvertime'), 'timeToOvertime' => $request->input('timeToOvertime'), 'overtime_id' => $overtime_id));
                             $overtimeDatesTime->save();
                         }
                         $var--;
                         $i++;
                     }
                     if ($minutesTotal == 0) {
                         $overtime = $daysTotal * 24 + $hoursTotal . ':00';
                     } elseif ($minutesTotal > 0 && $minutesTotal < 10) {
                         $overtime = $daysTotal * 24 + $hoursTotal . ':0' . $minutesTotal;
                     } else {
                         $overtime = $daysTotal * 24 + $hoursTotal . ':' . $minutesTotal;
                     }
                     $updateOvertime = Overtime::where('id', $overtime_id)->update(array('total_overtime' => $overtime));
                     if ($updateOvertime) {
                         $status = "Success!";
                     } else {
                         $status = "Failed!";
                     }
                 }
                 // $status = "Failed!";
                 // echo $overtime;
             } else {
                 if ($dateToOvertime > $dateFromOvertime) {
                     $seconds = strtotime($request->input('dateToOvertime') . $request->input('timeToOvertime')) - strtotime($request->input('dateFromOvertime') . $request->input('timeFromOvertime'));
                     $days = floor($seconds / 86400);
                     $hours = floor(($seconds - $days * 86400) / 3600);
                     $minutes = floor(($seconds - $days * 86400 - $hours * 3600) / 60);
                     $seconds = floor($seconds - $days * 86400 - $hours * 3600 - $minutes * 60);
                     // $day = $days*24;
                     if ($minutes == 0) {
                         $overtime = $days * 24 + $hours . ':00';
                     } elseif ($minutes > 0 && $minutes < 10) {
                         $overtime = $days * 24 + $hours . ':0' . $minutes;
                     } else {
                         $overtime = $days * 24 + $hours . ':' . $minutes;
                     }
                     $overtime_id = Overtime::insertGetId(['user_id' => Auth::user()->id, 'department_id' => $department->id, 'total_overtime' => $overtime, 'purpose' => $request->input('purpose'), 'permission_id1' => $request->input('supervisor')]);
                     $firstdateTime = new DateTimeOvertime(array('user_id' => Auth::user()->id, 'dateFromOvertime' => $request->input('dateFromOvertime'), 'timeFromOvertime' => $request->input('timeFromOvertime'), 'dateToOvertime' => $request->input('dateToOvertime'), 'timeToOvertime' => $request->input('timeToOvertime'), 'overtime_id' => $overtime_id));
                     $firstdateTime->save();
                     if ($firstdateTime) {
                         $status = "Success!";
                     } else {
                         $status = "Failed!";
                     }
                 } elseif ($dateToOvertime == $dateFromOvertime) {
                     if ($timeToOvertime > $timeFromOvertime) {
                         $to_time = strtotime(date('Y-m-d', $dateToOvertime) . date(' H:i:s', $timeToOvertime));
                         $from_time = strtotime(date('Y-m-d', $dateFromOvertime) . date(' H:i:s', $timeFromOvertime));
                         $minutes = round(abs($to_time - $from_time) / 60, 2);
                         $seconds = abs($to_time - $from_time) % 60;
                         $overtime = gmdate("H:i", $minutes * 60);
                         $overtime_id = Overtime::insertGetId(['user_id' => Auth::user()->id, 'department_id' => $department->id, 'total_overtime' => $overtime, 'purpose' => $request->input('purpose'), 'permission_id1' => $request->input('supervisor')]);
                         $firstdateTime = new DateTimeOvertime(array('user_id' => Auth::user()->id, 'dateFromOvertime' => $request->input('dateFromOvertime'), 'timeFromOvertime' => $request->input('timeFromOvertime'), 'dateToOvertime' => $request->input('dateToOvertime'), 'timeToOvertime' => $request->input('timeToOvertime'), 'overtime_id' => $overtime_id));
                         $firstdateTime->save();
                         if ($firstdateTime) {
                             $status = "Success!";
                         } else {
                             $status = "Failed!";
                         }
                     } else {
                         $status = "Error: Double Check your Time inputted";
                         // echo $status;
                     }
                 }
             }
         } else {
             $status = "Error: Double Check your Time inputted";
             // echo "2";
         }
     } else {
         $status = "Error: Double Check your Date inputted";
     }
     // dd($request->all());
     return redirect('inbox')->with('status', $status);
     // dd($request->all());
 }