/** * @param integer $id * * @Method (AJAX) */ public function addAction($id) { $form = $this->form('BonusEdit'); $valiebles = ['Опоздание' => -1, 'Не отработано' => -1, 'Недостача' => -1, 'Экспедиторский бонус' => 1]; $form->setData('manager_id', $id); if ($this->request->is('POST')) { $form->handle($this->request->post); $form->setData('creator_id', $this->user->id); if ($this->is_allow) { $form->setData('is_approved', Bonus::STATUS_APPROVED); $form->setData('request', Bonus::REQUEST_SUSSES); } else { $form->setData('is_approved', Bonus::STATUS_NEW); } if (!$form->validate()) { return ['errors' => $form->getErrors()]; } if ($form->isSubmitted()) { $bonus = $form->save(); $s = null; if ($salary_id = $form->getData('salary_id', 0)) { $mSalary = $this->model('Salary'); $mSalary->updateBonus($salary_id); $s = $mSalary->getById($salary_id); } $bonus = Bonus::prepare($bonus); $is_main = false; if ($bonus['manager_id'] == $this->user->id) { $is_main = 1; } return ['bonus' => $bonus, 'salary' => $s, 'html' => $this->renderPartial('bonus/tr', ['bonus' => $bonus, 'is_rule' => $this->is_allow, 'is_chief' => $this->is_chief, 'is_main' => $is_main, 'salary_id' => $salary_id, 'auth_user' => $this->user->id])]; } } else { return $this->renderPartial('bonus/add', ['form' => $form->createBuilder(), 'valiebles' => $valiebles, 'bonus' => NULL]); } }
public function getData($id) { $user = []; $salary = []; $base = \Arr::path($this->esalary, $id . '.base', 0); $plans = \Arr::get($this->plans, $id, []); $baseplans = \Arr::get($this->base_plans, $id, []); $total_nobase = 0; //Не плановые показатели foreach ($plans as $plan) { $_salary = $plan; $_salary['value'] = \Arr::get($plan, 'value', 0); $_salary['plan'] = 0; $department_id = \Arr::get($plan, 'department_id', 0); $user_id = \Arr::get($plan, 'user_id', 0); if ($plan['is_common']) { $key_sheet = $plan['plan_id'] . ($department_id ? '_' . $department_id : ''); } else { $key_sheet = $plan['plan_id'] . ($user_id ? '_' . $user_id : '') . ($department_id ? '_' . $department_id : ''); } $sheet = \Arr::get($this->plan_sheets, $key_sheet, null); if (!$sheet) { if ($plan['is_common']) { $sheet = \Arr::get($this->plan_sheets, $plan['plan_id'], []); } } $_salary['fact'] = 0; if ($sheet) { $_salary['fact'] = \Arr::get($sheet, 'fact', 0); } $_total = $_salary['value'] * $_salary['fact']; $_total = round($_total, -2); //округлить до рублей $total_nobase += $_total; $_salary['total'] = $_total; $salary[] = $_salary; } $_summary_percent = 0; //Плановые показатели foreach ($baseplans as $plan) { $department_id = \Arr::get($plan, 'department_id', 0); $user_id = \Arr::get($plan, 'user_id', 0); $_salary = $plan; $_salary['plan'] = 0; if ($plan['is_common']) { $key_sheet = $plan['plan_id'] . ($department_id ? '_' . $department_id : ''); } else { $key_sheet = $plan['plan_id'] . ($user_id ? '_' . $user_id : '') . ($department_id ? '_' . $department_id : ''); } $sheet = \Arr::get($this->plan_sheets, $key_sheet, 0); if (!$sheet) { if ($plan['is_common']) { $sheet = \Arr::get($this->plan_sheets, $plan['plan_id'], []); } } $_salary['value'] = \Arr::get($plan, 'value', 0); $_salary['fact'] = 0; if ($sheet) { $_salary['fact'] = \Arr::get($sheet, 'fact', 0); $_salary['plan'] = \Arr::get($sheet, 'plan', 0); } if ($_salary['plan']) { $_salary['percent'] = $_salary['fact'] / $_salary['plan'] * 100; $_salary['percent'] = round($_salary['percent'], 2); } else { $_salary['percent'] = 0; } $_salary['tempo'] = $this->getTempo($_salary['fact'], $_salary['plan']); $_salary['summary_percent'] = $_salary['percent'] / 100 * ($_salary['value'] / 100) * 100; $_salary['summary_percent'] = round($_salary['summary_percent']); //ROUND $_summary_percent += $_salary['summary_percent']; $salary[] = $_salary; } $bonuses = \Arr::get($this->bonus, $id, []); array_walk($bonuses, function (&$bonus) { $bonus = Bonus::prepare($bonus); //$bonus['approved'] = Bonus::is_approved($bonus); }); $user = ['salary' => $salary, 'base' => $base, 'bonuses' => $bonuses, 'summary_percent' => $_summary_percent, 'esalary' => \Arr::get($this->esalary, $id), 'total_nobase' => $total_nobase]; return $user; }