/** * Show the application registration form. * * @return \Illuminate\Http\Response */ public function getRegister() { $positions = Positions::all(); $shifts = Shifts::all(); $data = array('positions_all' => $positions, 'shifts' => $shifts); return view('auth.register')->with($data); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $inboxNotif = $this->inboxNotif(); $approvalNotif = $this->approvalNotif(); $profileImage = $this->getImage(); $positions = $this->position(); $positions_all = Positions::all(); $user_position = Auth::user()->position_id; $empDepartment = Positions::find($user_position)->departments; $count = $this->forms(); $data = array('title' => 'Edit Profile', 'positions' => $positions, 'positions_all' => $positions_all, 'profileImage' => $profileImage, 'inboxNotif' => $inboxNotif, 'approvalNotif' => $approvalNotif, 'empDepartment' => $empDepartment, 'count' => $count); return view('auth.editProfile')->with($data); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // $HR = Departments::where('id', 8); // if($this->auth->check()){ // if($this->auth->user()->position_id == 1){ // return $next($request); // } // } $id = $this->auth->user()->position_id; $empDepartment = Positions::find($id)->departments; if ($this->auth->check()) { if ($empDepartment->department_name == "Human Resource") { return $next($request); } } // echo "1"; return new RedirectResponse(url('/')); }
public function vehicles() { $cars_on = Events::select(["UnitId", DB::raw('count("Value")')])->where("Port", 'Ignition')->where("Value", 1)->groupBy("UnitId")->get()->toArray(); $cars_off = Events::select(["UnitId", DB::raw('count("Value")')])->where("Port", 'Ignition')->where("Value", 0)->groupBy("UnitId")->get()->toArray(); $cars_speed = Positions::select(["UnitId", DB::raw('count("Speed") as total'), DB::raw('sum("Speed") as sum')])->groupBy("UnitId")->get()->toArray(); for ($i = 0; $i < count($cars_on); $i++) { $cars_on[$i]['averageSpeed'] = "Not available"; $cars_on[$i]['count_two'] = 0; foreach ($cars_off as $car_off) { if ($cars_on[$i]['UnitId'] == $car_off['UnitId']) { $cars_on[$i]['count_two'] = $car_off['count']; break; } } } for ($i = 0; $i < count($cars_speed); $i++) { $cars_speed[$i]['averageSpeed'] = floor($cars_speed[$i]['sum'] / $cars_speed[$i]['total']); $cars_speed[$i]['count_two'] = 0; $cars_speed[$i]['count'] = 0; } foreach ($cars_speed as $car_speed) { $add_new = true; for ($i = 0; $i < count($cars_on); $i++) { if ($cars_on[$i]['UnitId'] == $car_speed['UnitId']) { $cars_on[$i]['averageSpeed'] = $car_speed['averageSpeed']; $add_new = false; break; } } if ($add_new) { array_push($cars_on, $car_speed); } } for ($i = 0; $i < count($cars_on); $i++) { $cars_on[$i]['failedStarts'] = $cars_on[$i]['count'] - $cars_on[$i]['count_two']; } return view('pages.vehicles')->with('cars', $cars_on); }
public function editLeave(array $data, $id) { $datas = Leaves::where('id', $id)->get(); $dateUpdate = date("Y-m-d H:i:s"); if ($data['typeofLeave'] == 1) { if (isset($data['VL_daysApplied'])) { $days_taken = Auth::user()->VL_taken + $data['VL_daysApplied']; if ($days_taken <= Auth::user()->VL_entitlement) { $department = Positions::find(Auth::user()->position_id)->departments; return Leaves::where('id', $id)->update(array('leave_type' => $data['typeofLeave'], 'purpose' => $data['reasonforAbsence'], 'permission_id1' => $data['recommendApproval'], 'permission_id2' => $data['approvedBy'], 'days_applied' => $data['VL_daysApplied'], 'updated_at' => $dateUpdate)); } } else { return false; } } else { if ($data['typeofLeave'] == 2) { if (isset($data['SL_daysApplied'])) { $days_taken = Auth::user()->SL_taken + $data['SL_daysApplied']; if ($days_taken <= Auth::user()->SL_entitlement) { $department = Positions::find(Auth::user()->position_id)->departments; return Leaves::where('id', $id)->update(array('leave_type' => $data['typeofLeave'], 'purpose' => $data['reasonforAbsence'], 'permission_id1' => $data['recommendApproval'], 'permission_id2' => $data['approvedBy'], 'days_applied' => $data['SL_daysApplied'], 'updated_at' => $dateUpdate)); } } else { return false; } // dd($data); } else { if ($data['typeofLeave'] == 3) { if (isset($data['ML_daysApplied'])) { $days_taken = Auth::user()->ML_taken + $data['ML_daysApplied']; if ($days_taken <= Auth::user()->ML_entitlement) { $department = Positions::find(Auth::user()->position_id)->departments; return Leaves::where('id', $id)->update(array('leave_type' => $data['typeofLeave'], 'purpose' => $data['reasonforAbsence'], 'permission_id1' => $data['recommendApproval'], 'permission_id2' => $data['approvedBy'], 'days_applied' => $data['ML_daysApplied'], 'updated_at' => $dateUpdate)); } } else { return false; } } else { if ($data['typeofLeave'] == 4) { if (isset($data['PL_daysApplied'])) { $days_taken = Auth::user()->PL_taken + $data['PL_daysApplied']; if ($days_taken <= Auth::user()->PL_entitlement) { $department = Positions::find(Auth::user()->position_id)->departments; return Leaves::where('id', $id)->update(array('leave_type' => $data['typeofLeave'], 'purpose' => $data['reasonforAbsence'], 'permission_id1' => $data['recommendApproval'], 'permission_id2' => $data['approvedBy'], 'days_applied' => $data['PL_daysApplied'], 'updated_at' => $dateUpdate)); } } else { return false; } } } } } }
public function viewUserPaternity($id) { $users = User::find($id); // dd($user) $paternityUser = Leaves::where('leave_type', 4)->where('user_id', $id)->first(); if ($paternityUser) { $positions = $this->position(); $profileImage = $this->getImage(); $inboxNotif = $this->inboxNotif(); $approvalNotif = $this->approvalNotif(); $id_user = Auth::user()->position_id; $empDepartment = Positions::find($id_user)->departments; $paternityRecords = Leaves::where('leave_type', 4)->where('user_id', $id)->get(); $count = $this->forms(); $balance = 0; foreach ($paternityRecords as $paternity) { $balance = $paternity->users->PL_entitlement - $paternity->users->PL_taken; $PL_entitlement = $paternity->users->PL_entitlement; } $data = array('title' => 'View User Paternity Leaves', 'positions' => $positions, 'profileImage' => $profileImage, 'inboxNotif' => $inboxNotif, 'approvalNotif' => $approvalNotif, 'empDepartment' => $empDepartment, 'count' => $count, 'paternityRecords' => $paternityRecords, 'balance' => max($balance, 0), 'PL_entitlement' => $PL_entitlement, 'users' => $users); return view('record.userPaternity')->with($data); } else { return redirect('dashboard')->with('status', 'Error: No Paternity Records Found'); } }
public function deletePosition(Request $request) { $result = Positions::where('id', $request->input('position'))->update(array('status' => 1)); if ($result) { $status = "Success!"; } else { $status = "Failed!"; } return redirect('/accounts')->with('status', $status); }
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()); }