Ejemplo n.º 1
0
 /**
  * @param integer $id
  *
  * @Method (AJAX)
  */
 public function viewAction($id)
 {
     $form = $this->form('BonusEdit');
     $valiebles = ['Опоздание' => -1, 'Не отработано' => -1, 'Недостача' => -1, 'Экспедиторский бонус' => 1];
     $filter = $this->form('BonusFilter');
     $filter->setData('user_id', $id);
     if ($this->request->is('POST')) {
         $filter->handle($this->request->post);
         if ($filter->validate()) {
             $query = $filter->buildQuery();
             $this->redirect('/admin/employee/bonus/view/' . $id . $query);
         }
     }
     $filter->setData($this->request->query->all());
     $data = $filter->getSafeData();
     $bonuses = $this->model('Bonus')->getByList($data);
     array_walk($bonuses, function (&$bonus) {
         $bonus['approved'] = Bonus::is_approved($bonus);
     });
     $month = $filter->getData('month', date('m'));
     $year = $filter->getData('year', date('Y'));
     $bonus_mount = $year . '-' . $month;
     if ($bonus_mount == date('Y-m')) {
         $bonus_mount = date('Y-m-d');
     } else {
         $bonus_mount = $bonus_mount . '-' . date('d');
     }
     $form->setData('date', $bonus_mount);
     $form->setData('manager_id', $id);
     // оклад
     $oklad = $this->model('EmployeeSalary')->getByOkladUserId($id);
     $start = date('Y-m-d', strtotime($bonus_mount));
     $_date = new \DateTime($start);
     $_date->add(new \DateInterval('P1M'));
     $_date->sub(new \DateInterval('P1D'));
     $end = $_date->format('Y-m-d');
     $coun_word_day = Calendar::GetWorkingDayCount($start, $end);
     // кол-во рабочих дней
     if ($coun_word_day) {
         $price_hour = $oklad / ($coun_word_day * 8);
     } else {
         $price_hour = 0;
     }
     return $this->renderPartial('bonus/view', ['filter' => $filter->createBuilder(), 'bonuses' => $bonuses, 'user_id' => $id, 'auth_user' => $this->user->id, 'is_rule' => $this->is_allow, 'form' => $form->createBuilder(), 'valiebles' => $valiebles, 'auth_user' => $this->user->id, 'price_hour' => $price_hour]);
 }
Ejemplo n.º 2
0
 /**
  * update bonuses 
  */
 public function updateBonus($id = NULL)
 {
     $salary = $this->getById($id);
     if (null !== $salary) {
         $mBonus = new Bonus($this->db, $this->user);
         $stamp = strtotime($salary['date']);
         $filter = Calendar::getMonthYear($salary['date']);
         $filter['user_id'] = $salary['user_id'];
         $bonuses = $mBonus->getByList($filter);
         $plus = 0;
         $total_bonus = 0;
         foreach ($bonuses as $bonus) {
             if (Bonus::is_approved($bonus)) {
                 if ($bonus['amount'] < 0) {
                     $total_bonus += $bonus['amount'];
                     // все депремирования
                 } else {
                     $plus += $bonus['amount'];
                 }
             }
         }
         $total_bonus = round($total_bonus, -2);
         //ROUND до рублей
         $plus = round($plus, -2);
         //ROUND до рублей
         $_total = $salary['total'] + $salary['bonus'] - $salary['plus'];
         //чисто без Демотиваторов ! bonus в БД лежат плюсом
         $total = $_total + $total_bonus + $plus;
         //ROUND до рублей
         $total = round($total, -2);
         //ROUND до рублей
         $balance = $salary['balance'] + ($total - $salary['total']);
         $data = ['id' => $salary['id'], 'total' => $total, 'balance' => $balance, 'bonus' => -$total_bonus, 'plus' => $plus];
         $this->upsert($data);
     }
 }
Ejemplo n.º 3
0
 public function calculate_all()
 {
     $users = [];
     $cdPercent = $this->GetCurrentDayPercent();
     $factAll = [];
     if (!$this->is_fact) {
         foreach ($this->users_plans as $alias => $dusers) {
             $dusers['users'] = array_unique($dusers['users']);
             $dusers['departments'] = array_unique($dusers['departments']);
             $factAll[$alias] = $this->_calculate($alias, $dusers['users'], $dusers['departments']);
         }
     }
     foreach ($this->ids as $id) {
         $total = 0;
         $max = 0;
         $salary = [];
         $base = \Arr::path($this->esalary, $id . '.base', 0);
         $plans = \Arr::get($this->plans, $id, []);
         $baseplans = \Arr::get($this->base_plans, $id, []);
         //Не плановые показатели
         foreach ($plans as $_u_p_key => $plan) {
             $plan['u_key'] = $_u_p_key;
             $_salary = $plan;
             $_salary['value'] = \Arr::get($plan, 'value', 0);
             $_salary['plan'] = 0;
             $_salary['fact'] = \Arr::get($factAll, $_salary['alias'], []);
             $department_id = \Arr::get($plan, 'department_id', 0);
             $user_id = \Arr::get($plan, 'user_id', 0);
             if ($plan['is_common']) {
                 if ($department_id) {
                     $_salary['fact'] = \Arr::path($_salary['fact'], $department_id . '.cnt');
                     //department
                     if (empty($_salary['fact'])) {
                         $_salary['fact'] = \Arr::path($_salary['fact'], 'cnt');
                         //department
                     }
                 } else {
                     $_salary['fact'] = \Arr::get($_salary['fact'], 'cnt');
                     //no department
                 }
                 $key_sheet = $plan['plan_id'] . ($department_id ? '_' . $department_id : '');
             } else {
                 $_salary['fact'] = \Arr::path($_salary['fact'], $id . '.cnt');
                 $key_sheet = $plan['plan_id'] . ($user_id ? '_' . $user_id : '') . ($department_id ? '_' . $department_id : '');
             }
             $sheet = \Arr::get($this->plan_sheets, $key_sheet, []);
             if ($sheet) {
                 $_salary['plansheet_id'] = $sheet['plansheet_id'];
             } else {
                 if ($plan['is_common']) {
                     $sheet = \Arr::get($this->plan_sheets, $plan['plan_id'], []);
                     if ($sheet) {
                         $_salary['plansheet_id'] = $sheet['plansheet_id'];
                     }
                 }
             }
             //
             if ($this->is_fact) {
                 if ($sheet) {
                     $_salary['fact'] = $sheet['fact'];
                 } else {
                     $_salary['fact'] = 1;
                 }
             }
             $_total = $_salary['value'] * $_salary['fact'];
             $_total = round($_total, -2);
             //округлить до рублей
             $_salary['total'] = $_total;
             $_u_key = $_salary['plan_id'] . '_' . $_salary['department_id'];
             $salary[$_u_key] = $_salary;
             $total = $total + $_total;
             $max = $max + $_total;
             //теоритический максимум
         }
         $K = $K_MAX = 0;
         $is_plan_user = 0;
         $_summary_percent = 0;
         $_summaryValue = 0;
         //Плановые показатели
         foreach ($baseplans as $_u_p_key => $plan) {
             $plan['u_key'] = $_u_p_key;
             $department_id = \Arr::get($plan, 'department_id', 0);
             $user_id = \Arr::get($plan, 'user_id', 0);
             if (!$is_plan_user) {
                 $is_plan_user = 1;
             }
             $_salary = $plan;
             $sheet = [];
             $_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, []);
             if ($sheet) {
                 $_salary['plan'] = $sheet['plan'];
                 $_salary['plansheet_id'] = $sheet['plansheet_id'];
             } else {
                 if ($plan['is_common']) {
                     $sheet = \Arr::get($this->plan_sheets, $plan['plan_id'], []);
                     if ($sheet) {
                         $_salary['plansheet_id'] = $sheet['plansheet_id'];
                     }
                 }
             }
             $_users = \Arr::path($this->users_plans, $plan['alias'] . '.users', []);
             $departments = \Arr::get($this->users_plans, $plan['alias'] . '.departments', []);
             $_salary['value'] = \Arr::get($plan, 'value', 0);
             $_summaryValue += $_salary['value'];
             $_salary['fact'] = \Arr::get($factAll, $_salary['alias'], []);
             $fact = \Arr::get($_salary['fact'], 'cnt', 0);
             if (!$fact) {
                 $fact = \Arr::path($_salary['fact'], $department_id . '.cnt', 0);
                 if (!$fact) {
                     $fact = \Arr::path($_salary['fact'], $id . '.cnt', 0);
                 }
             }
             //факт из plan_sheet
             if ($this->is_fact) {
                 if ($sheet) {
                     $fact = $sheet['fact'];
                 }
             }
             $_salary['fact'] = $fact;
             $_is_negative = 0;
             if ($plan['is_negative'] == 1) {
                 if ($_salary['plan']) {
                     $percent = 2 - $fact / $_salary['plan'];
                 } else {
                     $percent = 1;
                 }
                 $_is_negative = 1;
             } else {
                 if ($_salary['plan']) {
                     $percent = $fact / $_salary['plan'];
                 } else {
                     $percent = 0;
                 }
             }
             $percent = round($percent, 2);
             $_salary['tempo'] = $this->getTempo($cdPercent, $percent, $_salary['is_negative']);
             $_salary['summary_percent'] = $percent * ($_salary['value'] / 100) * 100;
             $_salary['summary_percent'] = round($_salary['summary_percent']);
             //ROUND
             $_summary_percent += $_salary['summary_percent'];
             $_K = 0;
             if (0 < $cdPercent) {
                 //$_K = $percent * $_salary['value']/(100/$cdPercent);
                 $_K = $percent * $_salary['value'] / 100 / $cdPercent;
             }
             /*$_K = round($_K,3);*/
             $K1 = $K;
             $K = $K + $_K;
             $_salary['K'] = $K;
             /*max
              */
             $max_percent = 1;
             $K_MAX = $K_MAX + $max_percent * $_salary['value'] / (100 / 1);
             $salary[] = $_salary;
         }
         $total_plan = 0;
         if ($is_plan_user) {
             $_total = $_summaryValue ? (atan($K * 3.5 - 3.5) * ($base * 0.5) * 2 / pi() + $base) * $cdPercent : 0;
             $_total = round($_total, -2);
             //округлить до рублей
             $total = $total + $_total;
             $_total_max = $_summaryValue ? (atan($K_MAX * 3.5 - 3.5) * ($base * 0.5) * 2 / pi() + $base) * 1 : 0;
             $max = $max + $_total_max;
             $total_plan = $_total;
         }
         // bonus
         $bonuses = \Arr::get($this->bonus, $id, []);
         array_walk($bonuses, function (&$bonus) {
             $bonus = Bonus::prepare($bonus);
             //$bonus['approved'] = Bonus::is_approved($bonus);
         });
         $total_bonus = 0;
         $total_skip = 0;
         // За пропуски
         $plus = 0;
         $lateness = [];
         // Опоздание
         $is_request = 0;
         $skip_time = 0;
         foreach ($bonuses as $bonus) {
             if (Bonus::is_approved($bonus)) {
                 if ($bonus['amount'] < 0) {
                     $total_bonus += $bonus['amount'];
                     // все депремирования
                 } else {
                     $plus += $bonus['amount'];
                 }
                 if (!empty($bonus['skip_time'])) {
                     $skip_time += $bonus['skip_time'];
                 }
             }
             if ($bonus['is_request']) {
                 $is_request++;
             }
         }
         $total_bonus = round($total_bonus, -2);
         //ROUND до рублей
         $plus = round($plus, -2);
         //ROUND до рублей
         $max = $max + $plus;
         $total = $total + $total_bonus + $plus;
         $total = round($total, -2);
         //ROUND до рублей
         $income = $total - $total_bonus;
         $esalary = \Arr::get($this->esalary, $id);
         $basic = $this->getByOkladUserId($plans, $baseplans, $esalary);
         $hour = $basic / (25 * 8);
         $basic_interval = $this->getByOkladUserIdInterval($plans, $baseplans, $esalary);
         $users[$id] = ['salary' => $salary, 'bonuses' => $bonuses, 'skip_time' => $skip_time, 'total' => $total, 'income' => $income, 'plus' => $plus, 'total_plan' => $total_plan, 'total_bonus' => $total_bonus, 'total_skip' => $total_skip, 'summary_percent' => $_summary_percent, 'max' => $max > $total ? $max : $total, 'K' => $K, 'base' => $base, 'base_hour' => $hour, 'base_min' => $basic_interval['min'], 'base_max' => $basic_interval['max'], 'esalary' => $esalary, 'basic' => $basic, 'is_request' => $is_request];
     }
     return $users;
 }