Exemplo n.º 1
0
 /**
  * Store a newly created branch in storage.
  *
  * @return Response
  */
 public function store()
 {
     $employees = Employee::all();
     foreach ($employees as $employee) {
         $payroll = new Payroll();
         $payroll->employee_id = $employee->personal_file_number;
         $payroll->basic_pay = $employee->basic_pay;
         $payroll->earning_amount = Payroll::total_benefits($employee->id);
         $payroll->taxable_income = Payroll::gross($employee->id);
         $payroll->paye = Payroll::tax($employee->id);
         $payroll->nssf_amount = Payroll::nssf($employee->id);
         $payroll->nhif_amount = Payroll::nhif($employee->id);
         $payroll->other_deductions = Payroll::deductions($employee->id);
         $payroll->total_deductions = Payroll::total_deductions($employee->id);
         $payroll->net = Payroll::net($employee->id);
         $payroll->financial_month_year = Input::get('period');
         $payroll->account_id = Input::get('account');
         $payroll->save();
     }
     $allws = DB::table('employee_allowances')->join('allowances', 'employee_allowances.allowance_id', '=', 'allowances.id')->join('employee', 'employee_allowances.employee_id', '=', 'employee.id')->join('transact', 'employee.personal_file_number', '=', 'transact.employee_id')->select('employee.id', 'allowance_name', 'allowance_id', 'allowance_amount', 'financial_month_year')->get();
     foreach ($allws as $allw) {
         DB::table('transact_allowances')->insert(['employee_id' => $allw->id, 'allowance_name' => $allw->allowance_name, 'allowance_id' => $allw->allowance_id, 'allowance_amount' => $allw->allowance_amount, 'financial_month_year' => $allw->financial_month_year]);
     }
     $deds = DB::table('employee_deductions')->join('deductions', 'employee_deductions.deduction_id', '=', 'deductions.id')->join('employee', 'employee_deductions.employee_id', '=', 'employee.id')->join('transact', 'employee.personal_file_number', '=', 'transact.employee_id')->select('employee.id', 'deduction_name', 'deduction_id', 'deduction_amount', 'financial_month_year')->get();
     foreach ($deds as $ded) {
         DB::table('transact_deductions')->insert(['employee_id' => $ded->id, 'deduction_name' => $ded->deduction_name, 'deduction_id' => $ded->deduction_id, 'deduction_amount' => $ded->deduction_amount, 'financial_month_year' => $ded->financial_month_year]);
     }
     $earns = DB::table('earnings')->join('employee', 'earnings.employee_id', '=', 'employee.id')->join('transact', 'employee.personal_file_number', '=', 'transact.employee_id')->select('earnings.employee_id', 'earnings_name', 'financial_month_year', 'earnings_amount')->get();
     foreach ($earns as $earn) {
         DB::table('transact_earnings')->insert(['employee_id' => $earn->employee_id, 'earning_name' => $earn->earnings_name, 'earning_amount' => $earn->earnings_amount, 'financial_month_year' => $earn->financial_month_year]);
     }
     $period = Input::get('period');
     Audit::logaudit('Payroll', 'process', 'processed payroll for ' . $period);
     return Redirect::route('payroll.index')->withFlashMessage('Payroll successfully processed!');
 }