コード例 #1
0
ファイル: BonusController.php プロジェクト: Kulkow/employee
 /**
  * @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]);
     }
 }
コード例 #2
0
ファイル: Salary.php プロジェクト: Kulkow/employee
 /**
  * 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);
     }
 }
コード例 #3
0
ファイル: Calculate.php プロジェクト: Kulkow/employee
 /**
  * $ids - бонусы пользователей
  **/
 public function getBonus(array $ids)
 {
     $bonuses = [];
     $bonus = new Bonus($this->db, $this->user);
     foreach ($bonus->getByList(['month' => $this->mount, 'year' => $this->year, 'user_id' => $ids]) as $bonus) {
         if (!isset($bonuses[$bonus['user_id']])) {
             $bonuses[$bonus['user_id']] = [];
         }
         $bonuses[$bonus['user_id']][] = $bonus;
     }
     return $bonuses;
 }