public function generateNewStandardSalaries() { if (!$this->checkStandardSalaryNow()) { return at('Salary standard has been generated'); } $year_bef = $this->year - 1; $ump_bef = $this->getUMPBefore(); if (count($ump_bef) == 0) { return at('Can not generate salary standard, because of UMP before not found.'); } else { $salaries = $this->getStandardSalaryBefore(); if (count($salaries) == 0) { return at('Can not generate salary standard, because of salary standard before not found.'); } else { $inc = ($this->values - $ump_bef->values) / $ump_bef->values; foreach ($salaries as $salary) { $model = new PayrollBasedSalaries(); $model->year = $this->year; $model->city_id = $this->city_id; $model->department_id = $salary->department_id; $model->section_id = $salary->section_id; $model->position_id = $salary->position_id; $model->years_of_service_start = $salary->years_of_service_start; $model->years_of_service_end = $salary->years_of_service_end; $model->level_id = $salary->level_id; $model->grade_id = $salary->grade_id; $model->basic_salary_from = round((1 + $inc) * $salary->basic_salary_from, 0); $model->basic_salary_to = round((1 + $inc) * $salary->basic_salary_to, 0); $model->basic_salary_inc_amount = $model->basic_salary_from - $salary->basic_salary_inc_amount; $model->basic_salary_inc_percentage = round($inc * 100, 2); $model->save(); $allowances = $salary->payrollBasedAllowances; foreach ($allowances as $allowance) { $childmodel = new payrollBasedAllowances(); $childmodel->standard_id = $model->id; $childmodel->allowance_id = $allowance->allowance_id; $childmodel->calc_type = $allowance->calc_type; $childmodel->formula = $allowance->formula; $childmodel->values = $allowance->values; $childmodel->save(); } } } } return ''; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return PayrollBasedSalaries the loaded model * @throws CHttpException */ public function loadModel($id) { $model = PayrollBasedSalaries::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function newSalary($id) { $employee = $this->loadModel($id); $base = PayrollBasedSalaries::model()->findByAttributes(array('year' => date('Y'), 'city_id' => $employee->city_area_id, 'department_id' => $employee->department_id, 'section_id' => $employee->section_id, 'position_id' => $employee->position_id, 'level_id' => $employee->level_id, 'grade_id' => $employee->grade_id)); if (!isset($base)) { $base = PayrollBasedSalaries::model()->findByAttributes(array('year' => date('Y'))); } $salary = new PayrollEmployeeSalary(); $salary->employee_id = $id; $salary->salary_id = $base->id; $salary->basic_salary = 0; $salary->save(); }