コード例 #1
0
 public function adjust_price()
 {
     if (!self::isExecutiveOfficer()) {
         $this->render('permission_denied.php');
         return;
     }
     $id = (int) phpgw::get_var('price_item_id');
     $new_price = phpgw::get_var('new_price');
     $new_price = str_replace(',', '.', $new_price);
     if ($new_price != null && is_numeric($new_price)) {
         $price_item = rental_price_item::get($id);
         $price_item->set_price($new_price);
         if (rental_soprice_item::get_instance()->store($price_item)) {
             $adjustment = new rental_adjustment();
             $adjustment->set_price_item_id($price_item->get_id());
             $adjustment->set_new_price($new_price);
             $adjustment->set_year(date('Y'));
             $adjustment->set_percent(0);
             $adjustment->set_interval(0);
             $adjustment->set_responsibility_id($price_item->get_responsibility_id());
             $adjustment->set_is_manual(true);
             $adjustment->set_adjustment_date(time());
             rental_soadjustment::get_instance()->store($adjustment);
             $message[] = "Priselement med Agresso id {$price_item->get_agresso_id()} er oppdatert med ny pris {$new_price}";
             //update affected contract_price_items
             $no_of_contracts_updated = rental_soprice_item::get_instance()->adjust_contract_price_items($id, $new_price);
             if ($no_of_contracts_updated > 0) {
                 $message[] = $no_of_contracts_updated . ' priselementer på kontrakter er oppdatert';
             } else {
                 $message[] = "Ingen kontrakter er oppdatert";
             }
             $data = array('price_item_id' => $id, 'message' => $message);
             self::set_active_menu('rental::contracts::price_item_list::manual_adjustment');
             $this->render('admin_price_item_manual_adjustment.php', $data);
         } else {
             $data = array('price_item_id' => $id, 'error' => $error);
             self::set_active_menu('rental::contracts::price_item_list::manual_adjustment');
             $this->render('admin_price_item_manual_adjustment.php', $data);
         }
     } else {
         $data = array('price_item_id' => $id, 'error' => lang('price_not_numeric'));
         self::set_active_menu('rental::contracts::price_item_list::manual_adjustment');
         $this->render('admin_price_item_manual_adjustment.php', $data);
     }
 }
コード例 #2
0
 public function run_adjustments()
 {
     /* check if there are incomplete adjustments (for today)
      * gather all adjustable contracts with 
      * 		interval = adjustment interval and this year = last adjusted + interval
      * 		or
      * 		last adjusted is null / 0 (use contract start year)
      * adjust each contract's price items according to adjustment info (percent, adjustment_percent)
      * Run as transaction
      * update adjustment -> set is_executed to true
      * update price book elements according to type if interval=1
      */
     $prev_day = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
     $next_day = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'));
     //get incomplete adjustments for today
     $adjustments_query = "SELECT * FROM rental_adjustment WHERE NOT is_executed AND (adjustment_date < {$next_day} AND adjustment_date >= {$prev_day})";
     //var_dump($adjustments_query);
     $result = $this->db->query($adjustments_query);
     //var_dump("etter spr");
     //there are un-executed adjustments
     $adjustments = array();
     while ($this->db->next_record()) {
         $adjustment_id = $this->unmarshal($this->db->f('id', true), 'int');
         $adjustment = new rental_adjustment($adjustment_id);
         $adjustment->set_price_item_id($this->unmarshal($this->db->f('price_item_id', true), 'int'));
         $adjustment->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id', true), 'int'));
         $adjustment->set_new_price($this->unmarshal($this->db->f('new_price', true), 'float'));
         $adjustment->set_percent($this->unmarshal($this->db->f('percent', true), 'float'));
         $adjustment->set_interval($this->unmarshal($this->db->f('adjustment_interval', true), 'int'));
         $adjustment->set_adjustment_date($this->unmarshal($this->db->f('adjustment_date', true), 'int'));
         $adjustment->set_adjustment_type($this->unmarshal($this->db->f('adjustment_type'), 'string'));
         $adjustment->set_is_manual($this->unmarshal($this->db->f('is_manual'), 'bool'));
         $adjustment->set_is_executed($this->unmarshal($this->db->f('is_executed'), 'bool'));
         $adjustment->set_extra_adjustment($this->unmarshal($this->db->f('extra_adjustment'), 'bool'));
         $adjustment->set_year($this->unmarshal($this->db->f('year'), 'int'));
         $adjustments[] = $adjustment;
     }
     if (count($adjustments) > 0) {
         $this->db->transaction_begin();
         $success = $this->adjust_contracts($adjustments);
         if ($success) {
             $this->db->transaction_commit();
         } else {
             $this->db->transaction_abort();
         }
         return $success;
     }
     return false;
 }