/**
  * Function that defines workers state for today.
  *
  * @return Response
  */
 public function addDay()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('staffId' => 'required', 'dayType' => 'required'));
     if ($validator->fails()) {
         // No reason why staffId and dayType would not be provided so return nothing.
         return response()->json(array());
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         // If they are unauthorized no point in returning anything.
         return response()->json(array());
     }
     // Get the worker of given Id.
     $response = array();
     $worker = Worker::where('Cedula', '=', Input::get('staffId'))->first();
     if ($worker) {
         // Make sure Worker hasn't already set today's state.
         $salary = WorkerSalary::where('WorkerId', '=', $worker->Id)->where('Date', '=', date('Y-m-d'))->first();
         if ($salary) {
             // Inform user or error.
             $response['error'] = array();
             array_push($response['error'], 'Ya ha sido agregado el día de hoy!');
         } else {
             // Now set worker's state for today.
             switch (Input::get('dayType')) {
                 // Full day of work.
                 case 1:
                     $worker->Vacation += 0.0843;
                     $worker->save();
                     // Check if worker is production based only.
                     if ($worker->BonusSource == 'productionexclusive') {
                         // Add Full day of work.
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     } else {
                         // Add Full day of work.
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => $worker->Basic, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     }
                     break;
                     // Half day of work.
                 // Half day of work.
                 case 2:
                     $worker->Vacation += 0.0843;
                     $worker->save();
                     // Check if worker is production based only.
                     if ($worker->BonusSource == 'productionexclusive') {
                         // Add Full day of work.
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     } else {
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => $worker->Basic / 2, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     }
                     break;
                     // Paid Vacation.
                 // Paid Vacation.
                 case 3:
                     // Reduce vacations due by 1 day.
                     $worker->Vacation--;
                     $worker->save();
                     WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => $worker->Basic, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     break;
                     // Day of training 75% full rate.
                 // Day of training 75% full rate.
                 case 4:
                     $worker->Vacation += 0.0843;
                     $worker->save();
                     // Check if worker is production based only.
                     if ($worker->BonusSource == 'productionexclusive') {
                         // Add Full day of work.
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     } else {
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => $worker->Basic * 0.75, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     }
                     break;
                     // Absent Day
                 // Absent Day
                 case 5:
                     // Check if worker is production based only.
                     if ($worker->BonusSource == 'productionexclusive') {
                         // Add Full day of work.
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     } else {
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     }
                     break;
                     // Paid day off.
                 // Paid day off.
                 case 6:
                     $worker->Vacation += 0.0843;
                     $worker->save();
                     // Check if worker is production based only.
                     if ($worker->BonusSource == 'productionexclusive') {
                         // Add Full day of work.
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     } else {
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => $worker->Basic, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     }
                     break;
                     // Double Pay day.
                 // Double Pay day.
                 case 7:
                     $worker->Vacation += 0.0843;
                     $worker->save();
                     // Check if worker is production based only.
                     if ($worker->BonusSource == 'productionexclusive') {
                         // Add Full day of work.
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     } else {
                         WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'Basic' => $worker->Basic * 2, 'Bonus' => 0, 'DayType' => Input::get('dayType'), 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
                     }
                     break;
             }
         }
         // Return response.
         return response()->json($response);
     } else {
         return response()->json(['error' => 'Trabajador inexistente']);
     }
 }
 public function staffAddDay()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('formData' => 'required', 'worker' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'Informacion incompleta!']);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         // If they are unauthorized no point in returning anything.
         return response()->json(array());
     }
     // Get the worker.
     $worker = Worker::where('Cedula', '=', Input::get('worker'))->first();
     // Check to see if this is a day type update.
     $salary = WorkerSalary::where('WorkerId', '=', $worker->Id)->where('Date', '=', date('Y-m-d', strtotime(Input::get('formData')['paDate'])))->first();
     if ($salary != null) {
         // If last type was paid vacation add extra day of vacation.
         if ($salary->DayType == 3) {
             $worker->Vacation++;
             $worker->save();
         }
         if ($salary->DayType != 3 || $salary->DayType != 5) {
             $worker->Vacation -= 0.0843;
             $worker->save();
         }
         // Update the salary.
         switch (Input::get('formData')['paDayType']) {
             // Full day of work.
             case 1:
                 // Add Full day of work.
                 $worker->Vacation += 0.0843;
                 $worker->save();
                 $salary->Basic = $worker->Basic;
                 $salary->SystemProcess = false;
                 $salary->DayType = Input::get('formData')['paDayType'];
                 $salary->save();
                 break;
                 // Half day of work.
             // Half day of work.
             case 2:
                 $worker->Vacation += 0.0843;
                 $worker->save();
                 $salary->Basic = $worker->Basic / 2;
                 $salary->SystemProcess = false;
                 $salary->DayType = Input::get('formData')['paDayType'];
                 $salary->save();
                 break;
                 // Paid Vacation.
             // Paid Vacation.
             case 3:
                 // Reduce vacations due by 1 day.
                 $worker->Vacation--;
                 $worker->save();
                 $salary->Basic = $worker->Basic;
                 $salary->SystemProcess = false;
                 $salary->DayType = Input::get('formData')['paDayType'];
                 $salary->save();
                 break;
                 // Day of training 75% full rate.
             // Day of training 75% full rate.
             case 4:
                 $worker->Vacation += 0.0843;
                 $worker->save();
                 $salary->Basic = $worker->Basic * 0.75;
                 $salary->SystemProcess = false;
                 $salary->DayType = Input::get('formData')['paDayType'];
                 $salary->save();
                 break;
                 // Absent Day
             // Absent Day
             case 5:
                 $salary->Basic = 0;
                 $salary->SystemProcess = false;
                 $salary->DayType = Input::get('formData')['paDayType'];
                 $salary->save();
                 break;
                 // Paid day off.
             // Paid day off.
             case 6:
                 $worker->Vacation += 0.0843;
                 $worker->save();
                 $salary->Basic = $worker->Basic;
                 $salary->SystemProcess = false;
                 $salary->DayType = Input::get('formData')['paDayType'];
                 $salary->save();
                 break;
                 // Double Pay day.
             // Double Pay day.
             case 7:
                 $worker->Vacation += 0.0843;
                 $worker->save();
                 $salary->Basic = $worker->Basic * 2;
                 $salary->SystemProcess = false;
                 $salary->DayType = Input::get('formData')['paDayType'];
                 $salary->save();
                 break;
         }
         $response['state'] = 'Success';
         $response['message'] = 'Dia actualizado exitosamente!';
         return response()->json($response);
     }
     // Add day.
     switch (Input::get('formData')['paDayType']) {
         // Full day of work.
         case 1:
             $worker->Vacation += 0.0843;
             $worker->save();
             // Add Full day of work.
             WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d', strtotime(Input::get('formData')['paDate'])), 'Basic' => $worker->Basic, 'Bonus' => 0, 'DayType' => Input::get('formData')['paDayType'], 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
             break;
             // Half day of work.
         // Half day of work.
         case 2:
             $worker->Vacation += 0.0843;
             $worker->save();
             WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d', strtotime(Input::get('formData')['paDate'])), 'Basic' => $worker->Basic / 2, 'Bonus' => 0, 'DayType' => Input::get('formData')['paDayType'], 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
             break;
             // Paid Vacation.
         // Paid Vacation.
         case 3:
             // Reduce vacations due by 1 day.
             $worker->Vacation--;
             $worker->save();
             WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d', strtotime(Input::get('formData')['paDate'])), 'Basic' => $worker->Basic, 'Bonus' => 0, 'DayType' => Input::get('formData')['paDayType'], 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
             break;
             // Day of training 75% full rate.
         // Day of training 75% full rate.
         case 4:
             $worker->Vacation += 0.0843;
             $worker->save();
             WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d', strtotime(Input::get('formData')['paDate'])), 'Basic' => $worker->Basic * 0.75, 'Bonus' => 0, 'DayType' => Input::get('formData')['paDayType'], 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
             break;
             // Absent Day
         // Absent Day
         case 5:
             WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d', strtotime(Input::get('formData')['paDate'])), 'Basic' => 0, 'Bonus' => 0, 'DayType' => Input::get('formData')['paDayType'], 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
             break;
             // Paid day off.
         // Paid day off.
         case 6:
             $worker->Vacation += 0.0843;
             $worker->save();
             WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d', strtotime(Input::get('formData')['paDate'])), 'Basic' => $worker->Basic, 'Bonus' => 0, 'DayType' => Input::get('formData')['paDayType'], 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
             break;
             // Double Pay day.
         // Double Pay day.
         case 7:
             $worker->Vacation += 0.0843;
             $worker->save();
             WorkerSalary::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d', strtotime(Input::get('formData')['paDate'])), 'Basic' => $worker->Basic * 2, 'Bonus' => 0, 'DayType' => Input::get('formData')['paDayType'], 'Processed' => false, 'SystemProcess' => false, 'AguinaldoPaid' => false));
             break;
     }
     // Return response.
     $response['state'] = 'Success';
     $response['message'] = 'Dia agregado exitosamente!';
     return response()->json($response);
 }