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); } }
public function edit() { $adjustment_id = (int) phpgw::get_var('id'); $responsibility_id = (int) phpgw::get_var('responsibility_id'); $message = null; $error = null; if (isset($_POST['save'])) { if (isset($adjustment_id) && $adjustment_id > 0) { $adjustment = rental_soadjustment::get_instance()->get_single($adjustment_id); if (!$adjustment->has_permission(PHPGW_ACL_EDIT)) { unset($adjustment); $this->render('permission_denied.php', array('error' => lang('permission_denied_edit_adjustment'))); } } else { if (isset($responsibility_id) && ($this->isExecutiveOfficer() || $this->isAdministrator())) { $adjustment = new rental_adjustment(); $fields = rental_socontract::get_instance()->get_fields_of_responsibility(); $adjustment->set_responsibility_id($responsibility_id); } } $adjustment_date = strtotime(phpgw::get_var('adjustment_date_hidden')); if (isset($adjustment)) { $adjustment->set_year(phpgw::get_var('adjustment_year')); $adjustment->set_adjustment_date($adjustment_date); $adjustment->set_price_item_id(0); if (isset($responsibility_id) && $responsibility_id > 0) { $adjustment->set_responsibility_id($responsibility_id); // only present when new contract } $adjustment->set_new_price(0); $adjustment->set_percent(phpgw::get_var('percent')); $adjustment->set_interval(phpgw::get_var('interval')); $adjustment->set_adjustment_type(phpgw::get_var('adjustment_type')); $adjustment->set_extra_adjustment(phpgw::get_var('extra_adjustment') == 'on' ? true : false); $so_adjustment = rental_soadjustment::get_instance(); if ($so_adjustment->store($adjustment)) { $message = lang('messages_saved_form'); $adjustment_id = $adjustment->get_id(); } else { $error = lang('messages_form_error'); } } $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uiadjustment.edit', 'id' => $adjustment->get_id(), 'message' => $message, 'error' => $error)); } return $this->viewedit(true, $adjustment_id, null, $responsibility_id, $message, $error); }
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; }