/**
  * Store a newly created leaveapplication in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Leaveapplication::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     Leaveapplication::createLeaveApplication($data);
     return Redirect::to('leavemgmt');
 }
 /**
  * Store a newly created leaveapplication in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Leaveapplication::$rules, Leaveapplication::$messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $employee = Employee::find(array_get($data, 'employee_id'));
     $leavetype = Leavetype::find(array_get($data, 'leavetype_id'));
     $start_date = array_get($data, 'applied_start_date');
     $end_date = array_get($data, 'applied_end_date');
     $days_applied = Leaveapplication::getDays($start_date, $end_date);
     $balance_days = Leaveapplication::getBalanceDays($employee, $leavetype);
     if ($days_applied > $balance_days) {
         return Redirect::back()->with('info', 'The days you have applied are more than your balance. You have ' . $balance_days . ' days left');
     }
     Leaveapplication::createLeaveApplication($data);
     if (Confide::user()->user_type == 'member') {
         return Redirect::to('css/leave');
     } else {
         return Redirect::to('leavemgmt');
     }
 }