public function getApproveRequest($id) { $leavereq = Leave::find($id); $userid = Auth::id(); //=============Getting The Leave Balance of User $row = DB::table('leavebalance')->where('user_id', $leavereq->user_id)->where('leavetype_id', $leavereq->leavetype_id)->first(); //=========Getting the Month today $now = Carbon::now(); $monthnow = $now->format('F'); $yearnow = $now->format('Y'); //==========Querying the MonthRef to get the id $monthref = DB::table('monthref')->where('month', $monthnow)->first(); if ($leavereq->numDays() < $row->balance) { $leavereq->update(['status' => 'Approved']); DB::table('leavebalance')->where('user_id', $leavereq->user_id)->where('leavetype_id', $leavereq->leavetype_id)->update(['balance' => $row->balance - $leavereq->numDays()]); //==========Getting the balance after the update $getBalance = DB::table('leavebalance')->where('user_id', $leavereq->user_id)->where('leavetype_id', $leavereq->leavetype_id)->first(); //=============Insert data to Monthly Leave Balance $mlb = MonthlyLeaveBalance::create(['user_id' => $userid, 'leavetype_id' => $leavereq->leavetype_id, 'month_id' => $monthref->id, 'balance' => $getBalance->balance, 'remarks' => 'Approved', 'start_date' => $leavereq->start_date, 'end_date' => $leavereq->end_date, 'year' => $yearnow]); } else { // change this validation later, redirect with alert danger return Redirect::route('leave-requests', Auth::id())->with('alert', 'danger|Leave days requested is greater than remaining days'); } $audit = AuditTrail::create(['user_id' => Auth::id(), 'role' => 'Employee Management Admin', 'action' => 'approved ' . $leavereq->user->firstname . ' ' . $leavereq->user->lastname . '\'s Leave Request.']); return Redirect::route('leave-requests', Auth::id())->with('alert', 'success|Leave request has been approved'); }
public function getMyLeaveCard($id) { $months = MonthRef::all(); //========Query to get the Balance of the User monthly $vac = MonthlyLeaveBalance::where(function ($v) use($id) { //=====To get the Year today $now = Carbon::now(); $yearnow = $now->format('Y'); $v->where('user_id', $id); $v->where('year', $yearnow); })->orderBy('year')->get(); $sick = MonthlyLeaveBalance::where(function ($s) use($id) { //=====To get the Year today $now = Carbon::now(); $yearnow = $now->format('Y'); $s->where('user_id', $id); $s->where('year', $yearnow); })->orderBy('year')->get(); return View::make('my-leave-card')->with('months', $months)->with('vac', $vac); }