public static function send_contract_message(int $contract_id, string $contract_message, string $from_address)
 {
     $contract = rental_socontract::get_instance()->get_single($contract_id);
     if (isset($contract) && isset($contract_message) && $contract_message != '') {
         $title = lang('title_contract_message');
         $title .= " " . $contract->get_old_contract_id();
         $title .= "(" . lang($contract->get_contract_type_title()) . ")";
         $config = CreateObject('phpgwapi.config', 'frontend');
         $config->read();
         $to = $config->config_data['email_contract_messages'];
         if (isset($contract_message) && isset($to) && isset($from_address)) {
             if (isset($GLOBALS['phpgw_info']['server']['smtp_server']) && $GLOBALS['phpgw_info']['server']['smtp_server']) {
                 if (!is_object($GLOBALS['phpgw']->send)) {
                     $GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
                 }
                 $from = "{$GLOBALS['phpgw_info']['user']['fullname']}<{$from_address}>";
                 $receive_notification = false;
                 $rcpt = $GLOBALS['phpgw']->send->msg('email', $to, $title, stripslashes(nl2br($contract_message)), '', $from, '', $from, $GLOBALS['phpgw_info']['user']['fullname'], 'html', '', array(), $receive_notification);
                 if ($rcpt) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
 /**
  * This method adds a price item to a contract. Updates last edited history.
  * 
  * @param $contract_id	the given contract
  * @param $price_item	the price item to add
  * @return true if successful, false otherwise
  */
 function add_price_item($contract_id, $price_item_id, $factor)
 {
     $factor = $factor ? (double) $factor : 1;
     $price_item = $this->get_single($price_item_id);
     $contract = rental_socontract::get_instance()->get_single($contract_id);
     $rented_area = 0;
     $total_price = 0;
     if ($price_item->is_area()) {
         $rented_area = $contract->get_rented_area();
         if ($rented_area == '') {
             $rented_area = 0;
         }
         $total_price = $rented_area * $price_item->get_price() * $factor;
         //var_dump($total_price, $rented_area, $price_item->get_price());
     }
     if ($price_item) {
         $values = array($price_item_id, $contract_id, "'" . $price_item->get_title() . "'", str_replace(',', '.', $rented_area), "'" . $price_item->get_agresso_id() . "'", $price_item->is_area() ? 'true' : 'false', str_replace(',', '.', $price_item->get_price()) * $factor, str_replace(',', '.', $total_price));
         $start_date_field = '';
         $end_date_field = '';
         if ($start_date = $contract->get_billing_start_date()) {
             $values[] = $start_date;
             $start_date_field = ", date_start";
         }
         if ($end_date = $contract->get_billing_end_date()) {
             $values[] = $end_date;
             $end_date_field = ", date_end";
         }
         $q = "INSERT INTO rental_contract_price_item (price_item_id, contract_id, title, area, agresso_id, is_area, price, total_price {$start_date_field} {$end_date_field}) VALUES (" . join(',', $values) . ")";
         //var_dump($q);
         $result = $this->db->query($q);
         if ($result) {
             rental_socontract::get_instance()->last_updated($contract_id);
             rental_socontract::get_instance()->last_edited_by($contract_id);
             return true;
         }
     }
     return false;
 }
 public function index()
 {
     // No messages so far
     $errorMsgs = array();
     $warningMsgs = array();
     $infoMsgs = array();
     $step = null;
     // Used for overriding the user's selection and choose where to go by code
     // Step 3 - the billing job
     if (phpgw::get_var('step') == '2' && phpgw::get_var('next') != null) {
         $use_existing = phpgw::get_var('use_existing');
         $existing_billing = phpgw::get_var('existing_billing');
         if ($use_existing < 1) {
             $existing_billing = 0;
         }
         $contract_ids = phpgw::get_var('contract');
         // Ids of the contracts to bill
         $contract_ids_override = phpgw::get_var('override_start_date');
         //Ids of the contracts that should override billing start date with first day in period
         $contract_bill_only_one_time = phpgw::get_var('bill_only_one_time');
         if ($contract_ids != null && is_array($contract_ids) && count($contract_ids) > 0 || isset($contract_bill_only_one_time) && is_array($contract_bill_only_one_time) && count($contract_bill_only_one_time) > 0) {
             $missing_billing_info = rental_sobilling::get_instance()->get_missing_billing_info(phpgw::get_var('billing_term'), phpgw::get_var('year'), phpgw::get_var('month'), $contract_ids, $contract_ids_override, phpgw::get_var('export_format'));
             if ($missing_billing_info == null || count($missing_billing_info) == 0) {
                 $billing_job = rental_sobilling::get_instance()->create_billing(isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['currency_decimal_places']) ? isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['currency_decimal_places']) : 2, phpgw::get_var('contract_type'), phpgw::get_var('billing_term'), phpgw::get_var('year'), phpgw::get_var('month'), phpgw::get_var('title'), $GLOBALS['phpgw_info']['user']['account_id'], $contract_ids, $contract_ids_override, phpgw::get_var('export_format'), $existing_billing, $contract_bill_only_one_time);
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uibilling.view', 'id' => $billing_job->get_id()));
                 return;
             } else {
                 foreach ($missing_billing_info as $contract_id => $info_array) {
                     if ($info_array != null && count($info_array) > 0) {
                         $errorMsgs[] = lang('Missing billing information.', $contract_id);
                         foreach ($info_array as $info) {
                             $errorMsgs[] = ' - ' . lang($info);
                         }
                     }
                 }
                 $step = 2;
                 // Go back to step 2
             }
         } else {
             $errorMsgs[] = lang('No contracts were selected.');
             $step = 2;
             // Go back to step 2
         }
     }
     // Step 2 - list of contracts that should be billed
     if ($step == 2 || phpgw::get_var('step') == '1' && phpgw::get_var('next') != null || phpgw::get_var('step') == '3' && phpgw::get_var('previous') != null) {
         //Responsibility area
         $contract_type = phpgw::get_var('contract_type');
         //Check permission
         $names = $this->locations->get_name($contract_type);
         if ($names['appname'] == $GLOBALS['phpgw_info']['flags']['currentapp']) {
             if (!$this->hasPermissionOn($names['location'], PHPGW_ACL_ADD)) {
                 $this->render('permission_denied.php');
                 return;
             }
         }
         //Get year
         $year = phpgw::get_var('year');
         //Get term and month
         if ($step == 2) {
             $billing_term_tmp = phpgw::get_var('billing_term_selection');
         } else {
             $billing_term_tmp = phpgw::get_var('billing_term');
         }
         $billing_term_selection = $billing_term_tmp;
         $billing_term = substr($billing_term_tmp, 0, 1);
         $billing_month = substr($billing_term_tmp, 2);
         if ($billing_term == '1') {
             // monthly
             $month = $billing_month;
         } else {
             if ($billing_term == '4') {
                 // quarterly
                 if ($billing_month == '1') {
                     //1. quarter
                     $month = 3;
                     $billing_term_label = lang('first_quarter');
                 } else {
                     if ($billing_month == '2') {
                         //2. quarter
                         $month = 6;
                         $billing_term_label = lang('second_quarter');
                     } else {
                         if ($billing_month == '3') {
                             //3. quarter
                             $month = 9;
                             $billing_term_label = lang('third_quarter');
                         } else {
                             //4. quarter
                             $month = 12;
                             $billing_term_label = lang('fourth_quarter');
                         }
                     }
                 }
             } else {
                 if ($billing_term == '3') {
                     // half year
                     if ($billing_month == '1') {
                         $month = 6;
                         $billing_term_label = lang('first_half');
                     } else {
                         $month = 12;
                         $billing_term_label = lang('second_half');
                     }
                 } else {
                     $month = 12;
                     $billing_term_label = lang('annually');
                 }
             }
         }
         //Use existing billing?
         $use_existing = false;
         $existing_billing = phpgw::get_var('existing_billing');
         if ($existing_billing != 'new_billing') {
             $use_existing = true;
         }
         //Determine title
         $title = phpgw::get_var('title');
         if (!isset($title) || $title == '') {
             $fields = rental_socontract::get_instance()->get_fields_of_responsibility();
             foreach ($fields as $id => $label) {
                 if ($id == $contract_type) {
                     $description = lang($label) . ' ';
                 }
             }
             $description .= lang('month ' . $month) . ' ';
             $description .= $year;
             $title = $description;
         }
         if ($use_existing) {
             $billing_tmp = rental_sobilling::get_instance()->get_single($existing_billing);
             $title = $billing_tmp->get_title();
         }
         //Check to see if the period har been billed before
         if (rental_sobilling::get_instance()->has_been_billed($contract_type, $billing_term, $year, $month)) {
             // We only give a warning and let the user go to step 2
             $warningMsgs[] = lang('the period has been billed before.');
         } else {
             $contracts_with_one_time = array();
             //... and if not start retrieving contracts for billing
             $socontract_price_item = rental_socontract_price_item::get_instance();
             //... 1. Contracts following regular billing cycle
             $filters = array('contracts_for_billing' => true, 'contract_type' => $contract_type, 'billing_term_id' => $billing_term, 'year' => $year, 'month' => $month);
             $contracts = rental_socontract::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             //... 2. Contracts with one-time price items
             $filters2 = array('contract_ids_one_time' => true, 'billing_term_id' => $billing_term, 'year' => $year, 'month' => $month);
             $contract_price_items = $socontract_price_item->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters2);
             foreach ($contract_price_items as $contract_price_item) {
                 if (!array_key_exists($contract_price_item->get_contract_id(), $contracts)) {
                     $aditional_contracts = rental_socontract::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contract_price_item->get_contract_id(), 'contract_type' => $contract_type));
                     if (count($aditional_contracts) == 1) {
                         $c = $aditional_contracts[$contract_price_item->get_contract_id()];
                         $c->set_bill_only_one_time();
                         //$contracts[$contract_price_item->get_contract_id()] = $c;
                         $contracts_with_one_time[$contract_price_item->get_contract_id()] = $c;
                         // used for information purposes
                     }
                 } else {
                     $cid = $contract_price_item->get_contract_id();
                     $contracts_with_one_time[$cid] = $contracts[$cid];
                 }
             }
             foreach ($contracts_with_one_time as $id => &$contract) {
                 $total_price = $socontract_price_item->get_total_price_invoice($contract->get_id(), $billing_term, $month, $year);
                 $contract->set_total_price($total_price);
             }
             unset($contract);
             // Get the number of months in selected term for contract
             $months = rental_socontract::get_instance()->get_months_in_term($billing_term);
             // The billing should start from the first date of the periode (term) we're billing for
             $first_day_of_selected_month = strtotime($year . '-' . $month . '-01');
             $bill_from_timestamp = strtotime('-' . ($months - 1) . ' month', $first_day_of_selected_month);
             foreach ($contracts as $id => $contract) {
                 if (isset($contract)) {
                     $total_price = $socontract_price_item->get_total_price_invoice($contract->get_id(), $billing_term, $month, $year);
                     $type_id = $contract->get_contract_type_id();
                     $responsible_type_id = $contract->get_location_id();
                     // Gets location title from table rental_contract_responsibility
                     $location_title = rental_socontract::get_instance()->get_responsibility_title($responsible_type_id);
                     if ($type_id == 4) {
                         $warningMsgs[] = lang('billing_removed_KF_contract') . " " . $contract->get_old_contract_id();
                         unset($contracts[$id]);
                         $removed_contracts[$contract->get_id()] = $contract;
                     } else {
                         if ($type_id == 0 && strcmp($location_title, "contract_type_eksternleie") == 0 || empty($type_id) && strcmp($location_title, "contract_type_eksternleie") == 0) {
                             $contract->set_total_price($total_price);
                             $warningMsgs[] = lang('billing_removed_contract_part_1') . " " . $contract->get_old_contract_id() . " " . lang('billing_removed_external_contract');
                             unset($contracts[$id]);
                             $removed_contracts[$contract->get_id()] = $contract;
                         } else {
                             if (isset($total_price) && $total_price == 0) {
                                 $warningMsgs[] = lang('billing_removed_contract_part_1') . " " . $contract->get_old_contract_id() . " " . lang('billing_removed_contract_part_2');
                                 unset($contracts[$id]);
                                 $removed_contracts[$id] = $contract;
                             } else {
                                 $contract->set_total_price($total_price);
                                 // Find the last day of the last period the contract was billed before the specified date
                                 $last_bill_timestamp = $contract->get_last_invoice_timestamp($bill_from_timestamp);
                                 // If the contract has not been billed before, select the billing start date
                                 if ($last_bill_timestamp == null) {
                                     $next_bill_timestamp = $contract->get_billing_start_date();
                                     $not_billed_contracts[$id] = $contract;
                                     $irregular_contracts[$id] = $contract;
                                     unset($contracts[$id]);
                                 } else {
                                     // ... select the next that day that the contract should be billed from
                                     $next_bill_timestamp = strtotime('+1 day', $last_bill_timestamp);
                                     $contract->set_next_bill_timestamp($next_bill_timestamp);
                                     // The next time the contract should be billed from equals the first day of the current selected period
                                     if ($next_bill_timestamp == $bill_from_timestamp) {
                                         //The contract follows the regular billing cycle
                                     } else {
                                         unset($contracts[$id]);
                                         $irregular_contracts[$id] = $contract;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $data = array('contracts' => $contracts, 'irregular_contracts' => $irregular_contracts, 'removed_contracts' => $removed_contracts, 'not_billed_contracts' => $not_billed_contracts, 'contracts_with_one_time' => $contracts_with_one_time, 'bill_from_timestamp' => $bill_from_timestamp, 'contract_type' => phpgw::get_var('contract_type'), 'billing_term' => $billing_term, 'billing_term_label' => $billing_term_label, 'billing_term_selection' => $billing_term_selection, 'year' => $year, 'month' => $month, 'title' => $title, 'use_existing' => $use_existing, 'existing_billing' => $existing_billing, 'export_format' => phpgw::get_var('export_format'), 'errorMsgs' => $errorMsgs, 'warningMsgs' => $warningMsgs, 'infoMsgs' => $infoMsgs);
         $this->render('billing_step2.php', $data);
     } else {
         if ($step == 1 || phpgw::get_var('step') == '0' && phpgw::get_var('next') != null || phpgw::get_var('step') == '2' && phpgw::get_var('previous') != null) {
             $contract_type = phpgw::get_var('contract_type');
             $export_format = rental_sobilling::get_instance()->get_agresso_export_format($contract_type);
             $data = array('contract_type' => phpgw::get_var('contract_type'), 'billing_term' => phpgw::get_var('billing_term'), 'billing_term_selection' => phpgw::get_var('billing_term_selection'), 'title' => phpgw::get_var('title'), 'year' => phpgw::get_var('year'), 'existing_billing' => phpgw::get_var('existing_billing'), 'export_format' => $export_format, 'errorMsgs' => $errorMsgs, 'warningMsgs' => $warningMsgs, 'infoMsgs' => $infoMsgs);
             $this->render('billing_step1.php', $data);
         } else {
             $data = array('contract_type' => phpgw::get_var('contract_type'), 'billing_term' => phpgw::get_var('billing_term'), 'year' => phpgw::get_var('year'), 'month' => phpgw::get_var('month'), 'errorMsgs' => $errorMsgs, 'warningMsgs' => $warningMsgs, 'infoMsgs' => $infoMsgs);
             $this->render('billing_step0.php', $data);
         }
     }
 }
 public function edit()
 {
     $acl_location = '.demo_location';
     if (!$this->acl_add) {
         $this->no_access();
         return;
     }
     $output = self::get_output();
     $demo_id = phpgw::get_var('demo_id', 'int');
     $values = phpgw::get_var('values', 'string', 'POST');
     $values_attribute = phpgw::get_var('values_attribute', 'string', 'POST');
     $insert_record_values = $GLOBALS['phpgw']->session->appsession('insert_record_values' . $acl_location, 'demo');
     if (isset($insert_record_values) && is_array($insert_record_values)) {
         for ($j = 0; $j < count($insert_record_values); $j++) {
             $insert_record['extra'][$insert_record_values[$j]] = $insert_record_values[$j];
         }
     }
     if (isset($values) && is_array($values)) {
         if (!$this->acl_edit) {
             $this->no_access();
             return;
         }
         if (isset($insert_record['extra']) && is_array($insert_record['extra'])) {
             while (is_array($insert_record['extra']) && (list($key, $column) = each($insert_record['extra']))) {
                 if ($_POST[$key]) {
                     $values['extra'][$column] = $_POST[$key];
                 }
             }
         }
         if (isset($values['save']) && $values['save'] || isset($values['apply']) && $values['apply']) {
             if ($GLOBALS['phpgw']->session->is_repost()) {
                 $receipt['error'][] = array('msg' => lang('Hmm... looks like a repost!'));
             }
             if (!$values['cat_id'] || $values['cat_id'] == 'none') {
                 $receipt['error'][] = array('msg' => lang('Please select a category!'));
             }
             if (!$values['name']) {
                 $receipt['error'][] = array('msg' => lang('Please enter a name !'));
             }
             if (!$values['address']) {
                 $receipt['error'][] = array('msg' => lang('Please enter an address !'));
             }
             if (!$values['zip']) {
                 $receipt['error'][] = array('msg' => lang('Please enter a zip code !'));
             } else {
                 if (!ctype_digit($values['zip'])) {
                     $receipt['error'][] = array('msg' => lang('Please enter a integer as zip code !'));
                 }
             }
             if (!$values['town']) {
                 $receipt['error'][] = array('msg' => lang('Please enter a town !'));
             }
             if (isset($values_attribute) && is_array($values_attribute)) {
                 foreach ($values_attribute as $attribute) {
                     if ($attribute['allow_null'] != 'true' && !$attribute['value']) {
                         $receipt['error'][] = array('msg' => lang('Please enter value for attribute %1', $attribute['input_text']));
                     }
                 }
             }
             if ($demo_id) {
                 $values['demo_id'] = $demo_id;
             }
             if (!isset($receipt['error']) || !$receipt['error']) {
                 $receipt = $this->bo->save($values, $values_attribute);
                 $demo_id = $receipt['demo_id'];
                 if (isset($values['save']) && $values['save']) {
                     $GLOBALS['phpgw']->session->appsession('session_data', 'demo_receipt', $receipt);
                     $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'demo.uidemo.index2', 'output' => $output));
                 }
             }
         } else {
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'demo.uidemo.index2', 'output' => $output));
         }
     }
     $values = $this->bo->read_single($demo_id);
     /* Preserve attribute values from post */
     if (isset($receipt['error']) && (isset($values_attribute) && is_array($values_attribute))) {
         $values = $this->bo->preserve_attribute_values($values, $values_attribute);
     }
     if ($demo_id) {
         $function_msg = lang('edit demo');
     } else {
         $function_msg = lang('add demo');
     }
     $link_data = array('menuaction' => 'demo.uidemo.edit', 'demo_id' => $demo_id, 'output' => $output);
     $generic_list_1 = array();
     for ($i = 1; $i < 9; $i++) {
         $generic_list_1[] = array('id' => $i, 'name' => "Element A {$i}");
     }
     $generic_list_1[2]['selected'] = 1;
     $generic_list_2 = array();
     for ($i = 1; $i < 4; $i++) {
         $generic_list_2[] = array('id' => $i, 'name' => "Element B {$i}");
     }
     // date 1 (jscalendar)
     execMethod('phpgwapi.jscalendar.add_listener', 'values_start_date');
     // date 2 (YUI)
     $end_date = $GLOBALS['phpgw']->yuical->add_listener('end_date', date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], time()));
     //inline tables
     $values['consume'][] = array('amount' => 123456, 'date' => 2012, 'delete' => '');
     $values['consume'][] = array('amount' => 6789012, 'date' => 2013, 'delete' => '');
     $datavalues[0] = array('name' => "0", 'values' => json_encode($values['consume']), 'total_records' => count($values['consume']), 'edit_action' => "''", 'is_paginator' => 1, 'footer' => 0);
     $myColumnDefs[0] = array('name' => "0", 'values' => json_encode(array(array('key' => 'amount', 'label' => lang('amount'), 'sortable' => true, 'resizeable' => true, 'formatter' => FormatterRight), array('key' => 'date', 'label' => lang('date'), 'sortable' => true, 'resizeable' => true), array('key' => 'delete', 'label' => lang('delete'), 'sortable' => false, 'resizeable' => false))));
     $msgbox_data = isset($receipt) ? $GLOBALS['phpgw']->common->msgbox_data($receipt) : '';
     $data = array('contract' => rental_socontract::get_instance()->get_single(19)->toArray(), 'value_entry_date' => isset($values['entry_date']) ? $values['entry_date'] : '', 'value_name' => isset($values['name']) ? $values['name'] : '', 'value_address' => isset($values['address']) ? $values['address'] : '', 'value_zip' => isset($values['zip']) ? $values['zip'] : '', 'value_town' => isset($values['town']) ? $values['town'] : '', 'value_remark' => isset($values['remark']) ? $values['remark'] : '', 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'form_action' => $GLOBALS['phpgw']->link('/index.php', $link_data), 'value_id' => $demo_id, 'cat_select' => $this->cats->formatted_xslt_list(array('select_name' => 'values[cat_id]', 'selected' => isset($values['cat_id']) ? $values['cat_id'] : '')), 'custom_attributes' => array('attributes' => $values['attributes']), 'value_access' => isset($values['access']) ? $values['access'] : '', 'generic_list_1' => array('options' => $generic_list_1), 'generic_list_2' => array('options' => $generic_list_2), 'value_start_date' => date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], time()), 'img_cal' => $GLOBALS['phpgw']->common->image('phpgwapi', 'cal'), 'end_date' => $end_date, 'property_js' => json_encode($GLOBALS['phpgw_info']['server']['webserver_url'] . "/property/js/yahoo/property2.js"), 'datatable' => $datavalues, 'myColumnDefs' => $myColumnDefs, 'tabs' => self::_generate_tabs(), 'textareacols' => 60, 'textarearows' => 10);
     $GLOBALS['phpgw']->richtext->replace_element('remark');
     $GLOBALS['phpgw']->richtext->generate_script();
     $appname = lang('demo');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('demo') . " - {$appname}: {$function_msg}";
     $GLOBALS['phpgw']->xslttpl->add_file(array('edit', 'attributes_form'));
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('edit' => $data));
     $GLOBALS['phpgw']->js->validate_file('yahoo', 'demo.edit', 'demo');
     phpgwapi_yui::load_widget('dragdrop');
     phpgwapi_yui::load_widget('datatable');
     //	phpgwapi_yui::load_widget('menu');
     phpgwapi_yui::load_widget('connection');
     phpgwapi_yui::load_widget('loader');
     phpgwapi_yui::load_widget('tabview');
     phpgwapi_yui::load_widget('paginator');
     phpgwapi_yui::load_widget('animation');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
 }
 /**
  * (non-PHPdoc)
  * @see rental/inc/rental_uicommon#query()
  */
 public function query()
 {
     if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) {
         $user_rows_per_page = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $user_rows_per_page = 10;
     }
     // YUI variables for paging and sorting
     $start_index = phpgw::get_var('startIndex', 'int');
     $num_of_objects = phpgw::get_var('results', 'int', 'GET', $user_rows_per_page);
     $sort_field = phpgw::get_var('sort', 'string', 'GET', 'identifier');
     $sort_ascending = phpgw::get_var('dir') == 'desc' ? false : true;
     // Form variables
     $search_for = phpgw::get_var('query');
     $search_type = phpgw::get_var('search_option');
     // Create an empty result set
     $result_objects = array();
     $result_count = 0;
     //Create an empty result set
     $parties = array();
     $exp_param = phpgw::get_var('export');
     $export = false;
     if (isset($exp_param)) {
         $export = true;
         $num_of_objects = null;
     }
     //Retrieve a contract identifier and load corresponding contract
     $contract_id = phpgw::get_var('contract_id');
     if (isset($contract_id)) {
         $contract = rental_socontract::get_instance()->get_single($contract_id);
     }
     //Retrieve the type of query and perform type specific logic
     $type = phpgw::get_var('type');
     $config = CreateObject('phpgwapi.config', 'rental');
     $config->read();
     $use_fellesdata = $config->config_data['use_fellesdata'];
     switch ($type) {
         case 'included_parties':
             // ... get all parties incolved in the contract
             $filters = array('contract_id' => $contract_id);
             break;
         case 'not_included_parties':
             // ... get all parties not included in the contract
             $filters = array('not_contract_id' => $contract_id, 'party_type' => phpgw::get_var('party_type'));
             break;
         case 'sync_parties':
         case 'sync_parties_res_unit':
         case 'sync_parties_identifier':
         case 'sync_parties_org_unit':
             $filters = array('sync' => $type, 'party_type' => phpgw::get_var('party_type'), 'active' => phpgw::get_var('active'));
             if ($use_fellesdata) {
                 $bofelles = rental_bofellesdata::get_instance();
             }
             break;
         default:
             // ... get all parties of a given type
             phpgwapi_cache::session_set('rental', 'party_query', $search_for);
             phpgwapi_cache::session_set('rental', 'party_search_type', $search_type);
             phpgwapi_cache::session_set('rental', 'party_type', phpgw::get_var('party_type'));
             phpgwapi_cache::session_set('rental', 'party_status', phpgw::get_var('active'));
             $filters = array('party_type' => phpgw::get_var('party_type'), 'active' => phpgw::get_var('active'));
             break;
     }
     $result_objects = rental_soparty::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
     $result_count = rental_soparty::get_instance()->get_count($search_for, $search_type, $filters);
     // Create an empty row set
     $rows = array();
     foreach ($result_objects as $party) {
         if (isset($party)) {
             $serialized = $party->serialize($contract);
             if ($use_fellesdata) {
                 $sync_data = $party->get_sync_data();
                 if ($type == 'sync_parties') {
                     $unit_name_and_id = $bofelles->responsibility_id_exist($sync_data['responsibility_id']);
                 } else {
                     if ($type == 'sync_parties_res_unit') {
                         $unit_name_and_id = $bofelles->result_unit_exist($sync_data['result_unit_number']);
                     } else {
                         if ($type == 'sync_parties_identifier') {
                             $unit_name_and_id = $bofelles->result_unit_exist($party->get_identifier());
                         } else {
                             if ($type == 'sync_parties_org_unit') {
                                 $unit_name_and_id = $bofelles->org_unit_exist($sync_data['org_enhet_id']);
                             }
                         }
                     }
                 }
                 if (isset($unit_name_and_id)) {
                     $unit_id = $unit_name_and_id['UNIT_ID'];
                     $unit_name = $unit_name_and_id['UNIT_NAME'];
                     if (isset($unit_id) && is_numeric($unit_id)) {
                         $serialized['org_unit_name'] = isset($unit_name) ? $unit_name : lang('no_name');
                         $serialized['org_unit_id'] = $unit_id;
                     }
                     // Fetches data from Fellesdata
                     $org_unit_id = $sync_data['org_enhet_id'];
                     $org_unit_with_leader = $bofelles->get_result_unit_with_leader($org_unit_id);
                     $org_department = $bofelles->get_department_for_org_unit($org_unit_id);
                     $org_name = $org_unit_with_leader['ORG_UNIT_NAME'];
                     $org_email = $org_unit_with_leader['ORG_EMAIL'];
                     $unit_leader_fullname = $org_unit_with_leader['LEADER_FULLNAME'];
                     $dep_org_name = $org_department['DEP_ORG_NAME'];
                     // Fields are displayed in syncronization table
                     $serialized['org_unit_name'] = $org_name;
                     $serialized['unit_leader'] = $unit_leader_fullname;
                     $serialized['org_email'] = $org_email;
                     $serialized['dep_org_name'] = $dep_org_name;
                 }
             }
             //check if party is a part of a contract
             $party_in_contract = rental_soparty::get_instance()->has_contract($party->get_id());
             $serialized['party_in_contract'] = $party_in_contract ? true : false;
             $rows[] = $serialized;
         }
     }
     // ... add result data
     $party_data = array('results' => $rows, 'total_records' => $result_count);
     $editable = phpgw::get_var('editable') == 'true' ? true : false;
     if (!$export) {
         array_walk($party_data['results'], array($this, 'add_actions'), array($contract_id, $type, isset($contract) ? $contract->serialize() : null, $editable, $this->type_of_user));
     }
     return $this->yui_results($party_data, 'total_records', 'results');
 }
 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;
         }
     }
 }
 /**
  * Visible controller function for dismissing all workbench notifications originated 
  * from a given notification. The user must have EDIT privileges on a contract for
  * this action.
  * 
  * @return true on success/false otherwise
  */
 public function dismiss_notification_for_all()
 {
     //the source notification
     $notification_id = (int) phpgw::get_var('id');
     $contract_id = (int) phpgw::get_var('contract_id');
     $contract = rental_socontract::get_instance()->get_single($contract_id);
     if ($contract->has_permission(PHPGW_ACL_EDIT)) {
         rental_soworkbench_notification::get_instance()->dismiss_notification_for_all($notification_id);
         return true;
     }
     return false;
 }
/**
 * Get HTML checkbox with contract_types that are valid for new contracts
 *
 * @param $config
 * @return string HTML checkboxes to be placed in a table
 */
function contract_types($config)
{
    phpgw::import_class('rental.socontract');
    $types = rental_socontract::get_instance()->get_fields_of_responsibility();
    $types_assigned = isset($config['contract_types']) ? $config['contract_types'] : array();
    $out = '';
    foreach ($types as $type => $_label) {
        $label = $GLOBALS['phpgw']->translation->translate($_label, array(), false, 'rental');
        $checked = '';
        if (in_array($type, $types_assigned)) {
            $checked = ' checked';
        }
        $out .= <<<HTML
\t\t\t<tr><td><input type="checkbox" name="newsettings[contract_types][]" value="{$type}" {$checked}><label>{$label}</label></td></tr>
HTML;
    }
    return $out;
}
 public function get_total_price()
 {
     $so_contract = rental_socontract::get_instance();
     $so_contract_price_item = rental_socontract_price_item::get_instance();
     $contract_id = (int) phpgw::get_var('contract_id');
     $total_price = $so_contract_price_item->get_total_price($contract_id);
     $contract = $so_contract->get_single($contract_id);
     $area = $contract->get_rented_area();
     if (isset($area) && $area > 0) {
         $price_per_unit = $total_price / $area;
     }
     $result_array = array('total_price' => $total_price, 'area' => $area, 'price_per_unit' => $price_per_unit);
     $result_data = array('results' => $result_array, 'total_records' => 1);
     return $this->yui_results($result_data, 'total_records', 'results');
 }
 public function query()
 {
     if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) {
         $user_rows_per_page = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $user_rows_per_page = 10;
     }
     // YUI variables for paging and sorting
     $start_index = phpgw::get_var('startIndex', 'int');
     $num_of_objects = phpgw::get_var('results', 'int', 'GET', $user_rows_per_page);
     $sort_field = phpgw::get_var('sort');
     $sort_ascending = phpgw::get_var('dir') == 'desc' ? false : true;
     // Form variables
     $search_for = phpgw::get_var('query');
     $search_type = phpgw::get_var('search_option');
     // Create an empty result set
     $result_objects = array();
     $result_count = 0;
     $district_id = phpgw::get_var('district_id', 'int');
     //Retrieve a contract identifier and load corresponding contract
     $contract_id = phpgw::get_var('contract_id');
     $exp_param = phpgw::get_var('export');
     $export = false;
     if (isset($exp_param)) {
         $export = true;
         $num_of_objects = null;
     }
     //Retrieve the type of query and perform type specific logic
     $query_type = phpgw::get_var('type');
     switch ($query_type) {
         case 'available_composites':
             // ... get all vacant composites
             $filters = array('is_vacant' => 'vacant');
             $result_objects = rental_socomposite::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_socomposite::get_instance()->get_count($search_for, $search_type, $filters);
             break;
         case 'included_composites':
             // ... get all composites in contract
             $filters = array('contract_id' => $contract_id);
             $result_objects = rental_socomposite::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_socomposite::get_instance()->get_count($search_for, $search_type, $filters);
             break;
         case 'not_included_composites':
             // ... get all vacant and active composites not in contract
             $filters = array('is_active' => phpgw::get_var('is_active'), 'is_vacant' => phpgw::get_var('occupancy'), 'not_in_contract' => phpgw::get_var('contract_id'));
             $result_objects = rental_socomposite::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_socomposite::get_instance()->get_count($search_for, $search_type, $filters);
             break;
         case 'all_composites':
             // ... all composites, filters (active and vacant)
             phpgwapi_cache::session_set('rental', 'composite_query', $search_for);
             phpgwapi_cache::session_set('rental', 'composite_search_type', $search_type);
             phpgwapi_cache::session_set('rental', 'composite_status', phpgw::get_var('is_active'));
             phpgwapi_cache::session_set('rental', 'composite_status_contract', phpgw::get_var('has_contract'));
             phpgwapi_cache::session_set('rental', 'composite_furnished_status', phpgw::get_var('furnished_status'));
             $filters = array('furnished_status' => phpgw::get_var('furnished_status'), 'is_active' => phpgw::get_var('is_active'), 'is_vacant' => phpgw::get_var('occupancy'), 'has_contract' => phpgw::get_var('has_contract'), 'availability_date_from' => phpgw::get_var('availability_date_from_hidden'), 'availability_date_to' => phpgw::get_var('availability_date_to_hidden'), 'district_id' => $district_id);
             $result_objects = rental_socomposite::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_socomposite::get_instance()->get_count($search_for, $search_type, $filters);
             break;
         case 'included_areas':
             // Returns areas/units added to a specified composite
             $filters = array('included_areas' => phpgw::get_var('composite_id'));
             // Composite id
             $result_objects = rental_sounit::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_sounit::get_instance()->get_count($search_for, $search_type, $filters);
             break;
         case 'available_areas':
             // Returns areas/units available for a specified composite
             $filters = array('available_areas' => phpgw::get_var('id'));
             // Composite id
             $result_objects = rental_sounit::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_sounit::get_instance()->get_count($search_for, $search_type, $filters);
             break;
     }
     //Create an empty row set
     $rows = array();
     foreach ($result_objects as $result) {
         if (isset($result)) {
             if (!$result->is_active()) {
                 $result->set_status('Ikke i drift');
             }
             $rows[] = $result->serialize();
         }
     }
     // ... add result data
     $result_data = array('results' => $rows, 'total_records' => $object_count);
     $editable = phpgw::get_var('editable') == 'true' ? true : false;
     $contract_types = rental_socontract::get_instance()->get_fields_of_responsibility();
     $config = CreateObject('phpgwapi.config', 'rental');
     $config->read();
     $valid_contract_types = array();
     if (isset($config->config_data['contract_types']) && is_array($config->config_data['contract_types'])) {
         foreach ($config->config_data['contract_types'] as $_key => $_value) {
             if ($_value) {
                 $valid_contract_types[] = $_value;
             }
         }
     }
     $create_types = array();
     foreach ($contract_types as $id => $label) {
         if ($valid_contract_types && !in_array($id, $valid_contract_types)) {
             continue;
         }
         $names = $this->locations->get_name($id);
         if ($names['appname'] == $GLOBALS['phpgw_info']['flags']['currentapp']) {
             if ($this->hasPermissionOn($names['location'], PHPGW_ACL_ADD)) {
                 // adding allowed contract_types for context menu creation
                 $create_types[] = array($id, $label);
             }
         }
     }
     if (!$export) {
         //Add action column to each row in result table
         array_walk($result_data['results'], array($this, 'add_actions'), array($contract_id, $query_type, $editable, $create_types));
     }
     return $this->yui_results($result_data, 'total_records', 'results');
 }
 protected function run_excel_export($excel_export_type)
 {
     switch ($excel_export_type) {
         case 'bk':
             $get_order_excel = 'get_order_excel_bk';
             break;
         case 'nlsh':
             $get_order_excel = 'get_order_excel_nlsh';
             break;
         default:
             $get_order_excel = 'get_order_excel_bk';
             break;
     }
     $this->orders = array();
     $decimal_separator = isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator']) ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'] : ',';
     $thousands_separator = isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator']) ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'] : '.';
     // We need all invoices for this billing
     $invoices = rental_soinvoice::get_instance()->get(null, null, 'id', true, null, null, array('billing_id' => $this->billing_job->get_id()));
     $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
     foreach ($invoices as $invoice) {
         // We need all price items in the invoice
         $price_items = rental_soinvoice_price_item::get_instance()->get(null, null, null, null, null, null, array('invoice_id' => $invoice->get_id()));
         $composite_name = '';
         // We need to get the composites to get a composite name for the Agresso export
         $composites = rental_socomposite::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $invoice->get_contract_id()));
         if ($composites != null && count($composites) > 0) {
             $keys = array_keys($composites);
             $composite_name = $composites[$keys[0]]->get_name();
         }
         // HACK to get the needed location code for the building
         $building_location_code = rental_socomposite::get_instance()->get_building_location_code($invoice->get_contract_id());
         /**Sigurd:Start contract type**/
         $contract = rental_socontract::get_instance()->get_single($invoice->get_contract_id());
         $current_contract_type_id = $contract->get_contract_type_id();
         $contract_type_label = lang(rental_socontract::get_instance()->get_contract_type_label($current_contract_type_id));
         $contract_id = $contract->get_old_contract_id();
         $party_names = explode('<br/>', rtrim($contract->get_party_name(), '<br/>'));
         $start_date = $GLOBALS['phpgw']->common->show_date($contract->get_contract_date()->get_start_date(), $dateformat);
         $end_date = $GLOBALS['phpgw']->common->show_date($contract->get_contract_date()->get_end_date(), $dateformat);
         $billing_start_date = $GLOBALS['phpgw']->common->show_date($contract->get_billing_start_date(), $dateformat);
         $billing_end_date = $GLOBALS['phpgw']->common->show_date($contract->get_billing_end_date(), $dateformat);
         /**End contract type**/
         $price_item_data = array();
         $price_item_counter = 0;
         foreach ($price_items as $price_item) {
             $data = array();
             $data['amount'] = $price_item->get_total_price();
             $description = $price_item->get_title();
             $start = $price_item->get_timestamp_start();
             $stop = $price_item->get_timestamp_end();
             if (isset($start) && isset($stop)) {
                 $description .= ' ' . date('j/n', $start) . '-' . date('j/n', $stop);
             }
             $data['article_description'] = $description;
             $data['article_code'] = $price_item->get_agresso_id();
             $price_item_data[] = $data;
             $serialized_party = $invoice->get_party()->serialize();
             $party_name = $serialized_party['name'];
             $_party_names = array();
             if (count($party_names) > 1) {
                 foreach ($party_names as $value) {
                     if ($party_name == $value) {
                         continue;
                     }
                     $_party_names[] = $value;
                 }
             } else {
                 $_party_names = $party_names;
             }
             $party_full_name = implode(', ', $_party_names);
             $this->orders[] = $this->{$get_order_excel}($start_date, $end_date, $billing_start_date, $billing_end_date, $invoice->get_header(), $invoice->get_party()->get_identifier(), $party_name, $serialized_party['address'], $party_full_name, $invoice->get_id(), $this->billing_job->get_year(), $this->billing_job->get_month(), $invoice->get_account_out(), $data, $invoice->get_responsibility_id(), $invoice->get_service_id(), $building_location_code, $invoice->get_project_id(), $composite_name, $invoice->get_reference(), $price_item_counter, $invoice->get_account_in(), $invoice->get_responsibility_id(), $contract_type_label, $contract_id);
             $price_item_counter++;
         }
     }
 }
 public function create_billing(int $decimals, int $contract_type, int $billing_term, int $year, int $month, $title, int $created_by, array $contracts_to_bill, array $contracts_overriding_billing_start, string $export_format, int $existing_billing, array $contracts_bill_only_one_time)
 {
     if ($contracts_overriding_billing_start == null) {
         $contracts_overriding_billing_start = array();
     }
     if ($contracts_bill_only_one_time == null) {
         $contracts_bill_only_one_time = array();
     }
     // We start a transaction before running the billing
     $this->db->transaction_begin();
     if ($existing_billing < 1) {
         //new billing
         $billing = new rental_billing(-1, $contract_type, $title, $created_by);
         // The billing job itself
         $billing->set_timestamp_start(time());
         // Start of run
         $billing->set_export_format($export_format);
         $billing->set_title($title);
         $this->store($billing);
         // Store job as it is
         $billing_end_timestamp = strtotime('-1 day', strtotime(($month == 12 ? $year + 1 : $year) . '-' . ($month == 12 ? '01' : $month + 1) . '-01'));
         // Last day of billing period is the last day of the month we're billing
         $counter = 0;
         $total_sum = 0;
     } else {
         $billing = $this->get_single($existing_billing);
         $billing_end_timestamp = strtotime('-1 day', strtotime(($month == 12 ? $year + 1 : $year) . '-' . ($month == 12 ? '01' : $month + 1) . '-01'));
         // Last day of billing period is the last day of the month we're billing
         $total_sum = $billing->get_total_sum();
     }
     $billing_info = new rental_billing_info(null, $billing->get_id(), $contract_type, $billing_term, $year, $month);
     $res = rental_sobilling_info::get_instance()->store($billing_info);
     // Get the number of months in selected term for contract
     $months = rental_socontract::get_instance()->get_months_in_term($billing_term);
     // The billing should start from the first date of the periode (term) we're billing for
     $first_day_of_selected_month = strtotime($year . '-' . $month . '-01');
     $bill_from_timestamp = strtotime('-' . ($months - 1) . ' month', $first_day_of_selected_month);
     foreach ($contracts_to_bill as $contract_id) {
         $invoice = rental_invoice::create_invoice($decimals, $billing->get_id(), $contract_id, in_array($contract_id, $contracts_overriding_billing_start) ? true : false, $bill_from_timestamp, $billing_end_timestamp, in_array($contract_id, $contracts_bill_only_one_time) ? true : false, false, $billing_term);
         // Creates an invoice of the contract
         if ($invoice != null) {
             $total_sum += $invoice->get_total_sum();
         }
     }
     $billing->set_total_sum(round($total_sum, $decimals));
     $billing->set_timestamp_stop(time());
     //  End of run
     $billing->set_success(true);
     // Billing job is a success
     $this->store($billing);
     // Store job now that we're done
     // End of transaction!
     if ($this->db->transaction_commit()) {
         return $billing;
     }
     throw new UnexpectedValueException('Transaction failed.');
 }
 /**
  * Add a new contract_price_item to the database.  Adds the new insert id to the object reference.
  *
  * @param $price_item the contract_price_item to be added
  * @return mixed receipt from the db operation
  */
 protected function add(&$price_item)
 {
     $price = $price_item->get_price() ? $price_item->get_price() : 0;
     $total_price = $price_item->get_total_price() ? $price_item->get_total_price() : 0;
     $rented_area = $price_item->get_area();
     $contract = rental_socontract::get_instance()->get_single($price_item->get_contract_id);
     if ($price_item->is_area()) {
         $rented_area = $contract->get_rented_area();
         if ($rented_area == '') {
             $rented_area = 0;
         }
         $total_price = $rented_area * $price;
     }
     // Build a db-friendly array of the composite object
     $values = array($price_item->get_price_item_id(), $price_item->get_contract_id(), '\'' . $price_item->get_title() . '\'', '\'' . $price_item->get_agresso_id() . '\'', $price_item->is_area() ? "true" : "false", str_replace(',', '.', $price), str_replace(',', '.', $rented_area), str_replace(',', '.', $price_item->get_count()), str_replace(',', '.', $total_price), $price_item->is_one_time() ? "true" : "false", $price_item->is_billed() ? "true" : "false");
     $cols = array('price_item_id', 'contract_id', 'title', 'agresso_id', 'is_area', 'price', 'area', 'count', 'total_price', 'is_one_time', 'is_billed');
     if ($price_item->get_date_start()) {
         $values[] = $this->marshal($price_item->get_date_start(), 'int');
         $cols[] = 'date_start';
     }
     if ($price_item->get_date_end()) {
         $values[] = $this->marshal($price_item->get_date_end(), 'int');
         $cols[] = 'date_end';
     }
     $q = "INSERT INTO rental_contract_price_item (" . join(',', $cols) . ") VALUES (" . join(',', $values) . ")";
     $result = $this->db->query($q);
     $receipt['id'] = $this->db->get_last_insert_id("rental_contract_price_item", 'id');
     $price_item->set_id($receipt['id']);
     return $receipt;
 }
 /**
  * (non-PHPdoc)
  * @see rental/inc/rental_uicommon#query()
  */
 public function query()
 {
     if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) {
         $user_rows_per_page = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $user_rows_per_page = 10;
     }
     // YUI variables for paging and sorting
     $start_index = phpgw::get_var('startIndex', 'int');
     $num_of_objects = phpgw::get_var('results', 'int', 'GET', $user_rows_per_page);
     $sort_field = phpgw::get_var('sort');
     if ($sort_field == null) {
         $sort_field = 'agresso_id';
     }
     $sort_ascending = phpgw::get_var('dir') == 'desc' ? false : true;
     //Create an empty result set
     $records = array();
     //Retrieve a contract identifier and load corresponding contract
     $contract_id = phpgw::get_var('contract_id');
     if (isset($contract_id)) {
         $contract = rental_socontract::get_instance()->get_single($contract_id);
     }
     //Retrieve the type of query and perform type specific logic
     $type = phpgw::get_var('type');
     switch ($type) {
         case 'included_price_items':
             if (isset($contract)) {
                 $filters = array('contract_id' => $contract->get_id());
                 $result_objects = rental_socontract_price_item::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
                 $object_count = rental_socontract_price_item::get_instance()->get_count($search_for, $search_type, $filters);
             }
             break;
         case 'not_included_price_items':
             // We want to show price items in the source list even after they've been added to a contract
             $filters = array('price_item_status' => 'active', 'responsibility_id' => phpgw::get_var('responsibility_id'));
             $result_objects = rental_soprice_item::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_soprice_item::get_instance()->get_count($search_for, $search_type, $filters);
             break;
         case 'manual_adjustment':
             $filters = array('price_item_status' => 'active', 'is_adjustable' => 'false');
             $result_objects = rental_soprice_item::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_soprice_item::get_instance()->get_count($search_for, $search_type, $filters);
             break;
         default:
             //$filters = array('price_item_status' => 'active','responsibility_id' => phpgw::get_var('responsibility_id'));
             $result_objects = rental_soprice_item::get_instance()->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = rental_soprice_item::get_instance()->get_count($search_for, $search_type, $filters);
             break;
     }
     // Create an empty row set
     $rows = array();
     foreach ($result_objects as $record) {
         if (isset($record)) {
             // ... add a serialized record
             $rows[] = $record->serialize();
         }
     }
     $data = array('results' => $rows, 'total_records' => $object_count);
     $editable = phpgw::get_var('editable') == 'true' ? true : false;
     //Add action column to each row in result table
     array_walk($data['results'], array($this, 'add_actions'), array($contract_id, $type, $editable));
     return $this->yui_results($data, 'total_records', 'results');
 }
 public function adjust_contracts($adjustments)
 {
     /*
      * 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
      */
     $current_year = (int) date('Y');
     //var_dump("innicontr");
     foreach ($adjustments as $adjustment) {
         //gather all adjustable contracts
         $adjustable_contracts = "SELECT id, adjustment_share, date_start, adjustment_year FROM rental_contract ";
         $adjustable_contracts .= "WHERE location_id = '{$adjustment->get_responsibility_id()}' AND adjustable ";
         $adjustable_contracts .= "AND adjustment_interval = {$adjustment->get_interval()} ";
         $adjustable_contracts .= "AND (((adjustment_year + {$adjustment->get_interval()}) <= {$adjustment->get_year()})";
         $adjustable_contracts .= " OR ";
         $adjustable_contracts .= "(";
         if ($adjustment->is_extra_adjustment()) {
             $adjustable_contracts .= "adjustment_year = {$adjustment->get_year()}";
             $adjustable_contracts .= " OR ";
         }
         $adjustable_contracts .= "(adjustment_year IS NULL OR adjustment_year = 0)";
         $adjustable_contracts .= "))";
         //var_dump($adjustable_contracts);
         //die();
         $result = $this->db->query($adjustable_contracts);
         while ($this->db->next_record()) {
             $contract_id = $this->unmarshal($this->db->f('id', true), 'int');
             $adjustment_share = $this->unmarshal($this->db->f('adjustment_share', true), 'int');
             $date_start = $this->unmarshal($this->db->f('date_start', true), 'int');
             $adj_year = $this->unmarshal($this->db->f('adjustment_year', true), 'int');
             $start_year = date('Y', $date_start);
             $contract = rental_socontract::get_instance()->get_single($contract_id);
             $firstJanAdjYear = mktime(0, 0, 0, 1, 1, $adjustment->get_year());
             if ($contract->is_active($firstJanAdjYear) && ($adj_year != null && $adj_year > 0 || ($adj_year == null || $adj_year == 0) && $start_year + $adjustment->get_interval() <= $adjustment->get_year())) {
                 //update adjustment_year on contract
                 rental_socontract::get_instance()->update_adjustment_year($contract_id, $adjustment->get_year());
                 //gather price items to be adjusted
                 $contract_price_items = rental_socontract_price_item::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contract_id));
                 foreach ($contract_price_items as $cpi) {
                     //update price according to adjustment info
                     $cpi_old_price = $cpi->get_price();
                     $cpi_adjustment = $cpi_old_price * ($adjustment->get_percent() / 100) * ($adjustment_share / 100);
                     $cpi_new_price = $cpi_old_price + $cpi_adjustment;
                     $cpi->set_price($cpi_new_price);
                     rental_socontract_price_item::get_instance()->store($cpi);
                 }
             }
         }
         //TODO: update price book
         if ($adjustment->get_interval() == 1) {
             $adjustable_price_items = "SELECT * FROM rental_price_item WHERE responsibility_id = {$adjustment->get_responsibility_id()} AND is_adjustable";
             $result = $this->db->query($adjustable_price_items);
             $price_items = array();
             while ($this->db->next_record()) {
                 $price_item = new rental_price_item($this->unmarshal($this->db->f('id'), 'int'));
                 $price_item->set_title($this->unmarshal($this->db->f('title'), 'string'));
                 $price_item->set_agresso_id($this->unmarshal($this->db->f('agresso_id'), 'string'));
                 $price_item->set_is_area($this->unmarshal($this->db->f('is_area'), 'bool'));
                 $price_item->set_is_inactive($this->unmarshal($this->db->f('is_inactive'), 'bool'));
                 $price_item->set_is_adjustable($this->unmarshal($this->db->f('is_adjustable'), 'bool'));
                 $price_item->set_price($this->unmarshal($this->db->f('price'), 'float'));
                 $price_item->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id', true), 'int'));
                 $price_item->set_responsibility_title($this->unmarshal($this->db->f('resp_title', true), 'string'));
                 $price_items[] = $price_item;
             }
             foreach ($price_items as $pi) {
                 $pi_old_price = $pi->get_price();
                 $pi_adjustment = $pi_old_price * ($adjustment->get_percent() / 100);
                 $pi_new_price = $pi_old_price + $pi_adjustment;
                 $pi->set_price($pi_new_price);
                 rental_soprice_item::get_instance()->store($pi);
             }
         }
         $adjustment->set_is_executed(true);
         $this->update($adjustment);
         //notify all users with write access on the field of responsibility
         $location_id = $adjustment->get_responsibility_id();
         if ($location_id) {
             $location_names = $GLOBALS['phpgw']->locations->get_name($location_id);
             if ($location_names['appname'] == $GLOBALS['phpgw_info']['flags']['currentapp']) {
                 $responsible_accounts = $GLOBALS['phpgw']->acl->get_user_list_right(PHPGW_ACL_EDIT, $location_names['location']);
                 foreach ($responsible_accounts as $ra) {
                     $account_ids[] = $ra['account_id'];
                 }
             }
         }
         $location_label = rental_socontract::get_instance()->get_responsibility_title($location_id);
         $adj_interval = $adjustment->get_interval();
         $day = date("Y-m-d", strtotime('now'));
         $ts_today = strtotime($day);
         //notify each unique account
         foreach ($account_ids as $account_id) {
             if ($account_id && $account_id > 0) {
                 $notification = new rental_notification(0, $account_id, 0, null, $ts_today, $location_label . '_' . $adj_interval, null, null, null, null);
                 rental_soworkbench_notification::get_instance()->store($notification);
             }
         }
     }
     return true;
 }
Exemple #16
0
<?php 
echo rental_uicommon::get_page_error($error);
echo rental_uicommon::get_page_message($message);
?>

<form action="#" method="post">
	<dl class="proplist">
		<dt>
			<label for="name"><?php 
echo lang('field_of_responsibility');
?>
</label>
		</dt>
		<dd>
			<?php 
echo lang(rental_socontract::get_instance()->get_responsibility_title($adjustment->get_responsibility_id()));
?>
		</dd>
		<dt>
			<label for="adjustment_type"><?php 
echo lang('adjustment_type');
?>
</label>
		</dt>
		<dd>
			<?php 
if ($editable) {
    ?>
				<select name="adjustment_type">
					<option value="adjustment_type_KPI" <?php 
    echo $adjustment->get_adjustment_type() == 'adjustment_type_KPI' ? 'selected' : '';
 /**
  * Create invoice
  * 
  * @param int $decimals	the number of decimals on the total sum of the onvoice
  * @param int $billing_id	the billing this invoice is part of
  * @param int $contract_id	the contract
  * @param bool $override	flag to indicate if the invoice start period should be overridden with the billing start date of contract
  * @param int $timestamp_invoice_start	the startdate of the invoice period
  * @param int $timestamp_invoice_end	the enddate of the invoice period
  * @param bool $bill_only_one_time	flag to indicate if the the invoice should only bil one time price elements
  * @return rental_invoice	the newly created invoice
  */
 public static function create_invoice(int $decimals, int $billing_id, int $contract_id, bool $override, int $timestamp_invoice_start, int $timestamp_invoice_end, $bill_only_one_time, $dry_run = false, $billing_term = 0)
 {
     $contract = rental_socontract::get_instance()->get_single($contract_id);
     // If the invoice period should be overriden with the biling start date
     if ($override) {
         $timestamp_invoice_start = $contract->get_billing_start_date();
     }
     // If no account out is specified: check if the contract type defines any data to be used in this field (AGRESSO specific logic)
     $account_out = $contract->get_account_out();
     if (!isset($account_out) || $account_out == '') {
         //If no account out - check the contract type for default
         $account_tmp = rental_socontract::get_instance()->get_contract_type_account($contract->get_contract_type_id());
         if (isset($account_tmp) && $account_tmp != '') {
             $account_out = $account_tmp;
         } else {
             $account_out = rental_socontract::get_instance()->get_default_account($contract->get_location_id(), false);
         }
     }
     // Create invoice ...
     $invoice = new rental_invoice(-1, $billing_id, $contract_id, time(), $timestamp_invoice_start, $timestamp_invoice_end, 0, $contract->get_rented_area(), $contract->get_invoice_header(), $contract->get_account_in(), $account_out, $contract->get_service_id(), $contract->get_responsibility_id());
     // ... and add party identifier, project number and the old contract identifier
     $invoice->set_party_id($contract->get_payer_id());
     $invoice->set_project_id($contract->get_project_id());
     $invoice->set_old_contract_id($contract->get_old_contract_id());
     if (!$dry_run) {
         rental_soinvoice::get_instance()->store($invoice);
         // We must store the invoice at this point to have an id to give to the price item
     }
     // Retrieve the contract price items: only one-time or all
     if ($bill_only_one_time) {
         $filters2 = array('contract_id' => $contract->get_id(), 'contract_ids_one_time' => true, 'billing_term_id' => $billing_term, 'year' => date('Y', $timestamp_invoice_start), 'month' => date('m', $timestamp_invoice_start));
         //$contract_price_items = $socontract_price_item->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters2);
         $contract_price_items = rental_socontract_price_item::get_instance()->get(null, null, null, null, null, null, $filters2);
         //$contract_price_items = rental_socontract_price_item::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contract->get_id(), 'one_time' => true));
     } else {
         $contract_price_items = rental_socontract_price_item::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contract->get_id()));
     }
     $total_sum = 0;
     // Holding the total price of the invoice
     $contract_dates = $contract->get_contract_date();
     if (isset($contract_dates)) {
         $contract_start = $contract->get_contract_date()->get_start_date();
         $contract_end = $contract->get_contract_date()->get_end_date();
     }
     // Run through the contract price items
     foreach ($contract_price_items as $contract_price_item) {
         // ---- Period calculation ---
         // Determine start date for price item
         $contract_price_item_start = $contract_price_item->get_date_start();
         if ($contract_price_item_start == null || $contract_price_item_start == '') {
             // We just use the invoice date for our calculations
             $contract_price_item_start = $timestamp_invoice_start;
         }
         // Determine end date for price item
         $contract_price_item_end = $contract_price_item->get_date_end();
         if ($contract_price_item_end == null || $contract_price_item_end == '') {
             // We just use the invoice date for our calculations
             $contract_price_item_end = $timestamp_invoice_end;
         }
         // Sanity check - end date should never be before start date
         if ($contract_price_item_end < $contract_price_item_start) {
             continue;
             // We don't add this price item - continue to next
         }
         // Checking the start date against the invoice dates
         if ($contract_price_item_start < $timestamp_invoice_start) {
             $invoice_price_item_start = $timestamp_invoice_start;
             // We use the invoice start
         } else {
             if ($contract_price_item_start > $timestamp_invoice_end) {
                 continue;
                 // We don't add this price item - continue to next
             } else {
                 $invoice_price_item_start = $contract_price_item_start;
                 // We use the price item start
             }
         }
         // Checking the end date against invoice dates
         if ($contract_price_item_end < $timestamp_invoice_start) {
             continue;
             // We don't add this price item - continue to next
         } else {
             if ($contract_price_item_end < $timestamp_invoice_end) {
                 $invoice_price_item_end = $contract_price_item_end;
                 // We use the price item end
             } else {
                 $invoice_price_item_end = $timestamp_invoice_end;
                 // We use the invoice end
             }
         }
         // Checking the contract dates against the temporary price item dates
         if (isset($contract_start) && !$contract_price_item->is_one_time()) {
             if ($contract_start > $timestamp_invoice_end) {
                 continue;
                 //No price items for this contract will be billed
             }
             if ($contract_start > $invoice_price_item_start) {
                 $invoice_price_item_start = $contract_start;
             }
         }
         if (isset($contract_end) && !$contract_price_item->is_one_time()) {
             if ($contract_end < $timestamp_invoice_start) {
                 continue;
                 //No price items for this contract will be billed
             }
             if ($contract_end < $invoice_price_item_end) {
                 $invoice_price_item_end = $contract_end;
             }
         }
         // --- End of period calculation ---
         // Create a new invoice price item
         $invoice_price_item = new rental_invoice_price_item($decimals, -1, $invoice->get_id(), $contract_price_item->get_title(), $contract_price_item->get_agresso_id(), $contract_price_item->is_area(), $contract_price_item->get_price(), $contract_price_item->get_area(), $contract_price_item->get_count(), $invoice_price_item_start, $invoice_price_item_end);
         // If the contract price item is of type one-time and it's dates are within the invoice period ...
         if ($contract_price_item->is_one_time()) {
             if ($contract_price_item_start >= $timestamp_invoice_start && $contract_price_item_start <= $timestamp_invoice_end) {
                 // ... set the total price of the invoice price item to the total price of the contract price item
                 $invoice_price_item->set_total_price($contract_price_item->get_total_price());
                 // ... and set the contract price item as billed
                 $contract_price_item->set_is_billed(true);
                 if (!$dry_run) {
                     rental_socontract_price_item::get_instance()->store($contract_price_item);
                 }
             }
         }
         if (!$dry_run) {
             // Store the invoice price item
             rental_soinvoice_price_item::get_instance()->store($invoice_price_item);
         }
         // Add the price item to the invoice
         $invoice->add_invoice_price_item($invoice_price_item);
         // Add this price item's total sum to the tota sum of the invoice
         $total_sum += $invoice_price_item->get_total_price();
     }
     // end of looping through the contract price items
     // Set the total sum of the invoice rounded to the specified number of decimals
     $invoice->set_total_sum(round($total_sum, $decimals));
     if (!$dry_run) {
         // ... and store the invoice
         rental_soinvoice::get_instance()->store($invoice);
     }
     return $invoice;
 }
 /**
  * Do end-of-import clean up
  */
 protected function clean_up()
 {
     $socontract = rental_socontract::get_instance();
     $socontract->clear_last_edited_table();
 }
 /**
  * Utiity method for checking the users permission on this document. If the
  * document is bound to a contract, then the user must have edit privileges
  * on the given contract. If no contract, the user must be an executive 
  * officer or an administrator.
  * 
  * @param $document	the document in question
  * @param $document_properties	the document type and object id
  * @return true if correct privileges, false otherwise
  */
 private function check_permissions($document, $document_properties)
 {
     if ($document_properties == rental_sodocument::$CONTRACT_DOCUMENTS) {
         $contract = rental_socontract::get_instance()->get_single($document_properties['id']);
         if (!$contract->has_permission(PHPGW_ACL_EDIT)) {
             return false;
         }
     } else {
         if (!($this->isExecutiveOfficer() || $this->isAdministrator())) {
             return false;
         }
     }
     return true;
 }
 public function serialize()
 {
     //			require_once PHPGW_API_INC.'/adodb/adodb-time.inc.php';
     $date_format = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
     if (!isset($this->total_price)) {
         $this->total_price = rental_socontract_price_item::get_instance()->get_total_price($this->get_id());
     }
     if (!isset($this->total_price_current_year)) {
         $this->total_price_current_year = $this->get_total_price_current_year();
         //$this->total_price_current_year =  rental_socontract_price_item::get_instance()->get_total_price_invoice($this->get_id());
     }
     return array('id' => $this->get_id(), 'date_start' => $this->get_contract_date() && $this->get_contract_date()->has_start_date() ? date($date_format, $this->get_contract_date()->get_start_date()) : '', 'date_end' => $this->get_contract_date() && $this->get_contract_date()->has_end_date() ? date($date_format, $this->get_contract_date()->get_end_date()) : '', 'type' => lang($this->get_contract_type_title()) . ' / ' . lang(rental_socontract::get_instance()->get_contract_type_label($this->get_contract_type_id())), 'composite' => $this->get_composite_name(), 'party' => $this->get_party_name(), 'department' => $this->get_party_department(), 'old_contract_id' => $this->get_old_contract_id(), 'last_edited_by_current_user' => $this->get_last_edited_by_current_user() ? date($date_format, $this->get_last_edited_by_current_user()) : '', 'payer_id' => $this->get_payer_id(), 'last_updated' => $this->get_last_updated() ? date($date_format, $this->get_last_updated()) : '', 'service_id' => $this->get_service_id(), 'responsibility_id' => $this->get_responsibility_id(), 'due_date' => $this->get_due_date() ? date($date_format, $this->get_due_date()) : '', 'contract_type_id' => $this->get_contract_type_id(), 'total_price' => $this->total_price, 'max_area' => $this->rented_area, 'contract_status' => $this->get_contract_status(), 'contract_notification_status' => $this->get_contract_notification_status(), 'rented_area' => $this->get_rented_area(), 'adjustment_interval' => $this->get_adjustment_interval(), 'adjustment_share' => $this->get_adjustment_share(), 'adjustment_year' => $this->get_adjustment_year(), 'comment' => $this->get_comment(), 'publish_comment' => $this->get_publish_comment(), 'term_label' => $this->get_term_id_title(), 'total_price_current_year' => $this->total_price_current_year);
 }
 private function get_contracts_per_location()
 {
     $org_unit = $this->header_state['selected_org_unit'];
     if ($org_unit == 'all' || $org_unit == 'none') {
         phpgwapi_cache::message_set('Velg organisasjon', 'error');
         return array();
     }
     $values = phpgwapi_cache::session_get('frontend', $this->contracts_per_location_identifier);
     if (isset($values[$org_unit])) {
         return $values[$org_unit];
     }
     $parties = rental_soparty::get_instance()->get(null, null, null, null, null, null, array('org_unit_id' => $org_unit));
     $types = rental_socontract::get_instance()->get_fields_of_responsibility();
     $location_id_internal = array_search('contract_type_internleie', $types);
     $location_id_in = array_search('contract_type_innleie', $types);
     $location_id_ex = array_search('contract_type_eksternleie', $types);
     $contracts_per_location = array();
     $contracts_in_per_location = array();
     $contracts_ex_per_location = array();
     //For all parties connected to the internal organization unit
     foreach ($parties as $party) {
         //... get the contracts
         $contracts = rental_socontract::get_instance()->get(null, null, null, null, null, null, array('party_id' => $party->get_id()));
         //... and for each contract connected to this contract part
         foreach ($contracts as $id => $contract) {
             //... get the composites
             $composites = rental_socomposite::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contracts[$id]->get_id()));
             //...and for each composite in the contract in which this contract part is connected
             foreach ($composites as $composite) {
                 //... get the units
                 $units = $composite->get_units();
                 //... and for each unit retrieve the property locations we are after
                 foreach ($units as $unit) {
                     $property_location = $unit->get_location();
                     $property_locations[$property_location->get_location_code()] = $property_location;
                     // Contract holders: contracts_per_location (internal) and contracts_in_per_location (in)
                     // Internal contract should have impact on total price
                     if ($contract->get_location_id() == $location_id_internal) {
                         $total_price = rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
                         $contract->set_total_price($total_price);
                         if (!is_array($contracts_per_location[$org_unit][$property_location->get_location_code()])) {
                             $contracts_per_location[$org_unit][$property_location->get_location_code()] = array();
                         }
                         array_push($contracts_per_location[$org_unit][$property_location->get_location_code()], $contract);
                     } else {
                         if ($contract->get_location_id() == $location_id_in) {
                             $total_price = rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
                             $contract->set_total_price($total_price);
                             if (!is_array($contracts_in_per_location[$org_unit][$property_location->get_location_code()])) {
                                 $contracts_in_per_location[$org_unit][$property_location->get_location_code()] = array();
                             }
                             array_push($contracts_in_per_location[$org_unit][$property_location->get_location_code()], $contract);
                         } else {
                             if ($contract->get_location_id() == $location_id_ex) {
                                 $total_price = rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
                                 $contract->set_total_price($total_price);
                                 if (!is_array($contracts_ex_per_location[$org_unit][$property_location->get_location_code()])) {
                                     $contracts_ex_per_location[$org_unit][$property_location->get_location_code()] = array();
                                 }
                                 array_push($contracts_ex_per_location[$org_unit][$property_location->get_location_code()], $contract);
                             }
                         }
                     }
                 }
             }
         }
     }
     phpgwapi_cache::session_set('frontend', 'contracts_per_location', $contracts_per_location);
     phpgwapi_cache::session_set('frontend', 'contracts_in_per_location', $contracts_in_per_location);
     phpgwapi_cache::session_set('frontend', 'contracts_ex_per_location', $contracts_ex_per_location);
     return ${$this}->contracts_per_location_identifier[$org_unit];
 }
$config->read();
$area_suffix = isset($config->config_data['area_suffix']) ? $config->config_data['area_suffix'] : '';
$valuta_prefix = isset($config->config_data['currency_prefix']) ? $config->config_data['currency_prefix'] : '';
$valuta_suffix = isset($config->config_data['currency_suffix']) ? $config->config_data['currency_suffix'] : '';
?>

<div id="invoice_details">
<h3>Fakturakjøringsdetaljer</h3>
	<dl>
		<dt><?php 
echo lang('contract_type');
?>
</dt>
		<dd>
			<?php 
$fields = rental_socontract::get_instance()->get_fields_of_responsibility();
foreach ($fields as $id => $label) {
    if ($id == $contract_type) {
        echo lang($label);
    }
}
?>
		</dd>
		<dt><?php 
echo lang('billing_start');
?>
</dt>
		<dd><?php 
echo date($date_format, $bill_from_timestamp);
?>
</dd>
 public function serialize()
 {
     $date_format = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
     return array('id' => $this->get_id(), 'price_item_id' => $this->get_price_item_id(), 'responsibility_title' => lang(rental_socontract::get_instance()->get_responsibility_title($this->get_responsibility_id())), 'responsibility_id' => $this->get_responsibility_id(), 'new_price' => $this->get_new_price(), 'percent' => $this->get_percent(), 'interval' => $this->get_interval(), 'adjustment_type' => lang($this->get_adjustment_type() ? $this->get_adjustment_type() : 'none'), 'adjustment_date' => date($date_format, $this->get_adjustment_date()), 'extra_adjustment' => lang($this->is_extra_adjustment() ? 'yes' : 'no'), 'is_executed' => lang($this->is_executed() ? 'yes' : 'no'), 'year' => $this->get_year());
 }