Ejemplo n.º 1
0
 /**
  * Updates the Profile - Salary.
  *
  * @Patch("profile/salary")
  * @Patch("pim/employee-list/{id}/salary")
  *
  * @param SalaryRequest $request
  * @return \Illuminate\Http\RedirectResponse
  * @author Bertrand Kintanar
  */
 public function update(SalaryRequest $request)
 {
     $id = $request->get('employee_id');
     $fields = $request->except('_method', '_token', 'employee_id');
     foreach ($fields as $value) {
         $value['employee_id'] = $id;
         if ($value['effective_date'] == 0) {
             $value['effective_date'] = date('Y-m-d');
         }
         try {
             $employee_salary_component = $this->employee_salary_component->getCurrentComponentValue($id, $value['component_id']);
             if ($employee_salary_component->value != 0 && $employee_salary_component->value != $value['value']) {
                 $this->employee_salary_component->create($value);
             } else {
                 $employee_salary_component->value = $value['value'];
                 $employee_salary_component->effective_date = $value['effective_date'];
                 $employee_salary_component->save();
             }
         } catch (Exception $e) {
             return redirect()->to($request->path())->with('danger', UNABLE_UPDATE_MESSAGE);
         }
     }
     return redirect()->to($request->path())->with('success', SUCCESS_UPDATE_MESSAGE);
 }