/**
  * Get a static reference to the storage object associated with this model object
  * 
  * @return the storage object
  */
 public static function get_instance()
 {
     if (self::$so == null) {
         self::$so = CreateObject('rental.socomposite');
     }
     return self::$so;
 }
 /**
  * Step 4: import the contracts from the file 'u_Kontrakt.csv'
  * @param $composites	array mapping facilit ids and protico ids for composites
  * @param $rentalobject_to_contract	array mapping composites and contracts
  * @param $parties	array mapping party ids
  * @param $default_values	the default accounts and project numbers
  * @return array	of contracts
  */
 protected function import_contracts($composites, $rentalobject_to_contract, $parties, $default_values)
 {
     $start_time = time();
     $socontract = rental_socontract::get_instance();
     $contracts = array();
     $datalines = $this->getcsvdata($this->path . "/u_Kontrakt.csv");
     $this->messages[] = "Read 'u_Kontrakt.csv' file in " . (time() - $start_time) . " seconds";
     $this->messages[] = "'u_Kontrakt.csv' contained " . count($datalines) . " lines";
     // Old->new ID mapping
     $contract_types = array(2 => 2, 3 => 1, 4 => 8, 5 => 4, 12 => 6, 13 => 7, 14 => 8, 15 => 3, 17 => NULL, 18 => 8, 19 => 8);
     foreach ($datalines as $data) {
         // Skip this contract if its data is incomplete
         if (count($data) <= 27) {
             continue;
         }
         // Create a new contract object
         $contract = new rental_contract();
         //Set the contract dates
         $date_start = is_numeric(strtotime($this->decode($data[3]))) ? strtotime($this->decode($data[3])) : null;
         $date_end = is_numeric(strtotime($this->decode($data[4]))) ? strtotime($this->decode($data[4])) : null;
         $contract->set_contract_date(new rental_contract_date($date_start, $date_end));
         // Set the old contract identifier
         $contract->set_old_contract_id($this->decode($data[5]));
         //cKontraktnr
         // Set the contract biling term
         $term = $data[10];
         //nTermin
         switch ($term) {
             case 1:
                 // Monthly
                 $contract->set_term_id(1);
                 break;
             case 2:
                 // Quarterly
                 $contract->set_term_id(4);
                 break;
             case 4:
                 // Half-year
                 $contract->set_term_id(3);
                 break;
             case 5:
                 // Yearly
                 $contract->set_term_id(2);
                 break;
         }
         // Report non-conforming price periods
         $price_period = $data[14];
         //nPrisPeriode (4=month, 8=year)
         if ($price_period == 4) {
             // The price period is month.  We ignore this but print a warning.
             $this->warnings[] = "Price period of contract " . $contract->get_old_contract_id() . " is month.  Ignored.";
             //echo "<br/>Price period of contract " . $contract->get_old_contract_id() . " is month.  Ignored.";
         } elseif ($price_period == 5) {
             // The price period is 5, which is unknown.  We ignore this but print a warning.
             $this->warnings[] = "Price period of contract " . $contract->get_old_contract_id() . " is unknown (value: 5).  Ignored.";
             //echo "<br/>Price period of contract " . $contract->get_old_contract_id() . " is unknown (value: 5).  Ignored.";
         }
         $contract_status = $data[6];
         if ($contract_status == 3) {
             // Report contracts under dismissal. Send warning if contract status is '3' (Under avslutning)
             $this->warnings[] = "Status of contract " . $contract->get_old_contract_id() . " is '" . lang('contract_under_dismissal') . "'";
         } else {
             if ($contract_status == 1) {
                 // Report contracts under plannning. Send warning if contract status is '1' (Under planlegging)
                 $this->warnings[] = "Status of contract " . $contract->get_old_contract_id() . " is 'Under planlegging'";
             } else {
                 if ($contract_status == 2) {
                     //Test: if the contract is running; is import date  within the contract period
                     if ($date_start != null && time() < $date_start) {
                         $this->warnings[] = "Status of contract " . $contract->get_old_contract_id() . " is 'Løpende' but the start date is in the future.";
                     } else {
                         if ($date_end != null && time() > $date_end) {
                             $this->warnings[] = "Status of contract " . $contract->get_old_contract_id() . " is 'Løpende' but the end date is in the past.";
                         }
                     }
                 } else {
                     if ($contract_status == 4) {
                         if ($date_end == null || time() < $date_end) {
                             $this->warnings[] = "Status of contract " . $contract->get_old_contract_id() . " is 'Avsluttet' but the end date not set or in the future.";
                         }
                     }
                 }
             }
         }
         // Set the billing start date for the contract
         $billing_start_date = is_numeric(strtotime($this->decode($data[16]))) ? strtotime($this->decode($data[16])) : null;
         $contract->set_billing_start_date($billing_start_date);
         // Deres ref.
         $contract->set_invoice_header($this->decode($data[17]));
         //cFakturaRef
         $contract->set_comment($this->decode($data[18]));
         //cMerknad
         $contract->set_contract_type_id($contract_types[$this->decode($data[1])]);
         //
         // Set the location identifier (responsibiity area)
         $contract->set_location_id($this->location_id);
         // Get the composite identifier for the composite included in this contract
         $composite_id = $composites[$rentalobject_to_contract[$data[0]]];
         // Retrieve the title for the responsibility area we are importing (to hande the respoonsibility areas differently)
         $title = $socontract->get_responsibility_title($this->location_id);
         // For external contract types the rented area resides on the composite ...
         if ($title == 'contract_type_eksternleie') {
             if ($composite_id) {
                 $socomposite = rental_socomposite::get_instance();
                 $contract->set_rented_area($socomposite->get_area($composite_id));
             }
         } else {
             if ($title == 'contract_type_innleie') {
                 $rented_area_on_contract = $this->decode($data[21]);
                 if (isset($rented_area_on_contract) && $rented_area_on_contract > 0) {
                     $contract->set_rented_area($rented_area_on_contract);
                 } else {
                     if ($composite_id) {
                         $socomposite = rental_socomposite::get_instance();
                         $contract->set_rented_area($socomposite->get_area($composite_id));
                     }
                 }
             } else {
                 // ... and for others contract types the rented area resides on the contract
                 $contract->set_rented_area($this->decode($data[21]));
             }
         }
         // Retrieve default values for accounts and project numbers
         if ($title == 'contract_type_eksternleie') {
             $type_id = $contract->get_contract_type_id();
             if (!in_array($type_id, array(6, 7, 8))) {
                 $contract->set_contract_type_id(8);
             }
         } else {
             if ($title == 'contract_type_internleie') {
                 //Set default account in/out and project numbers for internal contracts
                 $contract->set_account_in($default_values['account_in']);
                 $contract->set_account_out($default_values['account_out']);
                 $contract->set_project_id($default_values['project_number']);
                 // Ansvar/Tjenestested: F.eks: 080400.13000
                 $ansvar_tjeneste = $this->decode($data[26]);
                 //cSikkerhetsTekst
                 $ansvar_tjeneste_components = explode(".", $ansvar_tjeneste);
                 if (count($ansvar_tjeneste_components) == 2) {
                     $contract->set_responsibility_id($ansvar_tjeneste_components[0]);
                     $contract->set_service_id($ansvar_tjeneste_components[1]);
                 } else {
                     $this->warnings[] = "The contract (internal) " . $contract->get_old_contract_id() . " lacks service and responsibility ids";
                 }
             }
         }
         // Store contract
         if ($socontract->store($contract)) {
             // Map contract ids in Facilit and PE contract id (should be the same)
             $contracts[$data[0]] = $contract->get_id();
             // Check if this contract has a composite and if so add rental composite to contract
             if (!$this->is_null($rentalobject_to_contract[$data[0]]) && !$this->is_null($composite_id)) {
                 $socontract->add_composite($contract->get_id(), $composite_id);
             }
             // Check if this contract has a contract part and if so add party to contract
             if (!$this->is_null($data[2])) {
                 //nPersonForetakId
                 $party_id = $parties[$this->decode($data[2])];
                 $socontract->add_party($contract->get_id(), $party_id);
                 // Set this party to be the contract invoice recipient
                 $socontract->set_payer($contract->get_id(), $party_id);
             }
             $this->messages[] = "Successfully added contract (" . $contract->get_id() . "/" . $contract->get_old_contract_id() . ")";
         } else {
             $this->errors[] = "Failed to store contract " . $this->decode($data[5]);
         }
     }
     $this->messages[] = "Successfully imported " . count($contracts) . " contracts. (" . (time() - $start_time) . " seconds)";
     return $contracts;
 }
 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];
 }
 /**
  * Does all the dirty work by building all the lines of Agresso contents
  * from the billing job.
  */
 protected function run()
 {
     $this->lines = 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()));
     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()));
         // 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());
         $description = "{$invoice->get_old_contract_id()}, " . number_format($invoice->get_total_area(), 1, $decimal_separator, $thousands_separator) . " m2 - {$invoice->get_header()}";
         $responsibility_in = isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['responsibility']) ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['responsibility'] : '028120';
         $project_id_in = isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['project_id']) ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['project_id'] : '9';
         // The income side
         foreach ($price_items as $price_item) {
             $this->lines[] = $this->get_line($invoice->get_account_in(), $responsibility_in, $invoice->get_service_id(), $building_location_code, $project_id_in, $price_item->get_agresso_id(), -1.0 * $price_item->get_total_price(), $description, $invoice->get_contract_id(), $this->billing_job->get_year(), $this->billing_job->get_month());
         }
         // The receiver's outlay side
         $this->lines[] = $this->get_line($invoice->get_account_out(), $invoice->get_responsibility_id(), $invoice->get_service_id(), $building_location_code, $invoice->get_project_id(), '', $invoice->get_total_sum(), $description, $invoice->get_contract_id(), $this->billing_job->get_year(), $this->billing_job->get_month());
     }
 }
 /**
  * Create a new contract tied to the composite provided in the composite_id parameter
  */
 public function add_from_composite()
 {
     $contract = new rental_contract();
     $contract->set_location_id(phpgw::get_var('responsibility_id'));
     if ($contract->has_permission(PHPGW_ACL_EDIT)) {
         $so_contract = rental_socontract::get_instance();
         $db_contract = $so_contract->get_db();
         $db_contract->transaction_begin();
         if ($so_contract->store($contract)) {
             // Add that composite to the new contract
             $success = $so_contract->add_composite($contract->get_id(), phpgw::get_var('id'));
             if ($success) {
                 $db_contract->transaction_commit();
                 $comp_name = rental_socomposite::get_instance()->get_single(phpgw::get_var('id'))->get_name();
                 $message = lang('messages_new_contract_from_composite') . ' ' . $comp_name;
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => $message));
             } else {
                 $db_contract->transaction_abort();
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
             }
         } else {
             $db_contract->transaction_abort();
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
         }
     }
     // If no executive officer
     $this->render('permission_denied.php', array('error' => lang('permission_denied_new_contract')));
 }
 /**
  * Public method. Called when user wants to edit a composite.
  * @param HTTP::id	the composite ID
  */
 public function edit()
 {
     $GLOBALS['phpgw_info']['flags']['app_header'] .= '::' . lang('edit');
     // Get the composite ID
     $composite_id = (int) phpgw::get_var('id');
     // Retrieve the party object or create a new one if correct permissions
     if ($this->isExecutiveOfficer() || $this->isAdministrator()) {
         if (isset($composite_id) && $composite_id > 0) {
             $composite = rental_socomposite::get_instance()->get_single($composite_id);
         } else {
             $composite = new rental_composite();
         }
     } else {
         $this->render('permission_denied.php', array('error' => lang('permission_denied_edit')));
     }
     if (isset($_POST['save_composite'])) {
         if (isset($composite)) {
             $composite->set_name(phpgw::get_var('name'));
             $composite->set_custom_address_1(phpgw::get_var('address_1'));
             $composite->set_has_custom_address(phpgw::get_var('has_custom_address') == 'on' ? true : false);
             $composite->set_custom_house_number(phpgw::get_var('house_number'));
             $composite->set_custom_address_2(phpgw::get_var('address_2'));
             $composite->set_custom_postcode(phpgw::get_var('postcode'));
             $composite->set_custom_place(phpgw::get_var('place'));
             $composite->set_is_active(phpgw::get_var('is_active') == 'on' ? true : false);
             $composite->set_description(phpgw::get_var('description'));
             $composite->set_furnish_type_id(phpgw::get_var('furnish_type_id'));
             $composite->set_standard_id(phpgw::get_var('composite_standard_id', 'int'));
             if (rental_socomposite::get_instance()->store($composite)) {
                 $message = lang('messages_saved_form');
             } else {
                 $error = lang('messages_form_error');
             }
         }
     }
     return $this->render('composite.php', array('composite' => $composite, '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.uicomposite.index', 'populate_form' => 'yes'))));
 }
 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++;
         }
     }
 }
 /**
  * Create a new contract tied to the composite provided in the composite_id parameter
  */
 public function add_from_composite()
 {
     $contract = new rental_contract();
     $contract->set_location_id(phpgw::get_var('responsibility_id'));
     $contract->set_account_in(rental_socontract::get_instance()->get_default_account($contract->get_location_id(), true));
     $contract->set_account_out(rental_socontract::get_instance()->get_default_account($contract->get_location_id(), false));
     $contract->set_executive_officer_id($GLOBALS['phpgw_info']['user']['account_id']);
     $config = CreateObject('phpgwapi.config', 'rental');
     $config->read();
     $default_billing_term = $config->config_data['default_billing_term'];
     $contract->set_term_id($default_billing_term);
     $units = rental_socomposite::get_instance()->get_single(phpgw::get_var('id'))->get_units();
     $location_code = $units[0]->get_location()->get_location_code();
     $args = array('acl_location' => '.contract', 'location_code' => $location_code, 'contract' => &$contract);
     $hook_helper = CreateObject('rental.hook_helper');
     $hook_helper->add_contract_from_composite($args);
     //		_debug_array($contract); die();
     if ($contract->has_permission(PHPGW_ACL_EDIT)) {
         $so_contract = rental_socontract::get_instance();
         $db_contract = $so_contract->get_db();
         $db_contract->transaction_begin();
         if ($so_contract->store($contract)) {
             // Add standard price items to contract
             if ($contract->get_location_id() && ($this->isExecutiveOfficer() || $this->isAdministrator())) {
                 $so_price_item = rental_soprice_item::get_instance();
                 //get default price items for location_id
                 $default_price_items = $so_contract->get_default_price_items($contract->get_location_id());
                 foreach ($default_price_items as $price_item_id) {
                     $so_price_item->add_price_item($contract->get_id(), $price_item_id);
                 }
             }
             // Add that composite to the new contract
             $success = $so_contract->add_composite($contract->get_id(), phpgw::get_var('id'));
             if ($success) {
                 $db_contract->transaction_commit();
                 $comp_name = rental_socomposite::get_instance()->get_single(phpgw::get_var('id'))->get_name();
                 $message = lang('messages_new_contract_from_composite') . ' ' . $comp_name;
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => $message));
             } else {
                 $db_contract->transaction_abort();
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
             }
         } else {
             $db_contract->transaction_abort();
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
         }
     }
     // If no executive officer
     $this->render('permission_denied.php', array('error' => lang('permission_denied_new_contract')));
 }