Ejemplo n.º 1
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.º 2
0
 /**
  * $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;
 }