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 editExit(array $data, $id)
 {
     $dateUpdate = date("Y-m-d H:i:s");
     $dateFrom = $data['dateFrom'];
     $dateTo = $data['dateTo'];
     // echo $newDate;
     $newFormatdateFrom = date('Y-m-d H:i:s', strtotime($dateFrom));
     $newFormatdateTo = date('Y-m-d H:i:s', strtotime($dateTo));
     $newFormattimeFrom = date('H:i:s', strtotime($dateFrom));
     $newFormattimeTo = date('H:i:s', strtotime($dateTo));
     if ($newFormattimeTo - $newFormattimeFrom > 5) {
         return "You are execeeded from your maximum hours to Exit!";
     } else {
         return ExitPass::where('id', $id)->update(array('date_from' => $newFormatdateFrom, 'date_to' => $newFormatdateTo, 'purpose' => $data['textPurpose'], 'permission_id1' => $data['supervisor'], 'permission_id2' => $data['projectManager'], 'permission_id3' => $data['HR'], 'permission_id4' => $data['companyRep'], 'updated_at' => $dateUpdate));
     }
 }
 public function postexitForm(Request $request)
 {
     $rules = array('dateFrom' => 'required', 'dateTo' => 'required', 'purpose' => 'required|max:255', 'supervisor' => 'required', 'projectManager' => 'required', 'HR' => 'required', 'companyRep' => 'required');
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $id = Auth::user()->id;
     $department = Positions::find(Auth::user()->position_id)->departments;
     $dateUpdate = date("Y-m-d H:i:s");
     $dateFrom = $request->input('dateFrom');
     $dateTo = $request->input('dateTo');
     $count = $this->forms();
     $newFormatdateFrom = date('Y-m-d H:i:s', strtotime($dateFrom));
     $newFormatdateTo = date('Y-m-d H:i:s', strtotime($dateTo));
     $newFormattimeFrom = date('H:i:s', strtotime($dateFrom));
     $newFormattimeTo = date('H:i:s', strtotime($dateTo));
     if ($newFormattimeTo - $newFormattimeFrom > 5) {
         $status = "You are execeeded from your maximum hours to Exit!";
     } else {
         $exitPass = new ExitPass(array('user_id' => $id, 'created_at' => $request->input('dateCreated'), 'date_from' => $newFormatdateFrom, 'date_to' => $newFormatdateTo, 'purpose' => $request->input('purpose'), 'updated_at' => $dateUpdate, 'department_id' => $department->id, 'permission_id1' => $request->input('supervisor'), 'permission_id2' => $request->input('projectManager'), 'permission_id3' => $request->input('HR'), 'permission_id4' => $request->input('companyRep'), 'count' => $count));
         $save = $exitPass->save();
         if ($save) {
             $status = "Success!";
         } else {
             $status = "Failed!";
         }
     }
     return redirect('/inbox')->with('status', $status);
 }