public function viewedit($editable, $adjustment_id, $adjustment = null, $responsibility_id = null, string $message = null, string $error = null) { if (isset($adjustment_id) && $adjustment_id > 0) { if ($adjustment == null) { $adjustment = rental_soadjustment::get_instance()->get_single($adjustment_id); } if ($adjustment) { if ($editable && !$adjustment->has_permission(PHPGW_ACL_EDIT)) { $editable = false; $error .= '<br/>' . lang('permission_denied_edit_adjustment'); } if (!$editable && !$adjustment->has_permission(PHPGW_ACL_READ)) { $this->render('permission_denied.php', array('error' => lang('permission_denied_view_adjustment'))); return; } $data = array('adjustment' => $adjustment, 'editable' => $editable, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'cancel_link' => self::link(array('menuaction' => 'rental.uiadjustment.index'))); $this->render('adjustment.php', $data); } } else { if ($this->isAdministrator() || $this->isExecutiveOfficer()) { $adjustment = new rental_adjustment(); $fields = rental_socontract::get_instance()->get_fields_of_responsibility(); $adjustment->set_responsibility_id($responsibility_id); if ($adjustment) { $data = array('adjustment' => $adjustment, 'editable' => true, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'cancel_link' => self::link(array('menuaction' => 'rental.uiadjustment.index'))); $this->render('adjustment.php', $data); } } else { $this->render('permission_denied.php', array('error' => lang('permission_denied_new_adjustment'))); return; } } }
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); } }
protected function import_adjustments($contracts, $regulation_id_location_id) { $start_time = time(); $soadjustment = rental_soadjustment::get_instance(); $datalines = $this->getcsvdata($this->path . "/u_Regulering.csv"); $this->messages[] = "Read 'u_Regulering.csv' file in " . (time() - $start_time) . " seconds"; $this->messages[] = "'u_Regulering.csv' contained " . count($datalines) . " lines"; foreach ($datalines as $data) { if (count($data) <= 8) { continue; } $adjustment = new rental_adjustment(); $regulation_id = $this->decode($data[0]); //nReguleringId $loc_id = $regulation_id_location_id[$regulation_id]; if (isset($loc_id) && $loc_id != '') { $adjustment->set_responsibility_id($loc_id); } else { $this->messages[] = "This adjustment '" . $regulation_id . "' could not be linked to this responsibility area. Date ({$this->decode($data[1])}), Text ({$this->decode($data[4])}), Interval ({$this->decode($data[2])})"; continue; } $date_array = explode(".", $this->decode($data[1])); //dAktuellDato if (count($date_array) == 3) { $y = $date_array[2]; $m = $date_array[1]; $d = $date_array[0]; $date = strtotime($y . "-" . $m . "-" . $d); } $adjustment->set_adjustment_date($date); $description_array = explode(" ", $this->decode($data[4])); //cBeskrivelse $number = end($description_array); $percent = substr($number, 0, strlen($number) - 2); $percent = str_replace(',', '.', $percent); $adjustment->set_percent($percent); $adjustment->set_interval($this->decode($data[2])); $adjustment->set_new_price(0); $adjustment->set_price_item_id(0); if (!$soadjustment->adjustment_exist($adjustment)) { // All is good, store notification if ($soadjustment->store($adjustment)) { $this->messages[] = "Successfully imported adjustment: Date ({$this->decode($data[1])}), Percent ({$adjustment->get_percent()}), Interval ({$adjustment->get_interval()})"; } else { $this->errors[] = "Error importing adjustment: Date ({$this->decode($data[1])}), Percent ({$adjustment->get_percent()}), Interval ({$adjustment->get_interval()})"; } } else { $this->messages[] = "Adjustment already exist: Date ({$this->decode($data[1])}), Percent ({$adjustment->get_percent()}), Interval ({$adjustment->get_interval()})"; } } $this->messages[] = "Imported adjustments. (" . (time() - $start_time) . " seconds)"; return true; }
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; }