예제 #1
0
 /**
  * Get a static reference to the storage object associated with this model object
  *
  * @return the storage object
  */
 public static function get_so()
 {
     if (self::$so == null) {
         self::$so = CreateObject('rental.socontract');
     }
     return self::$so;
 }
예제 #2
0
 /**
  * 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;
 }
 function populate(int $contract_id, &$contract)
 {
     if ($contract == null) {
         $contract_id = (int) $contract_id;
         $contract = new rental_contract($contract_id);
         $contract->set_contract_date(new rental_contract_date($this->unmarshal($this->db->f('date_start'), 'int'), $this->unmarshal($this->db->f('date_end'), 'int')));
         $contract->set_billing_start_date($this->unmarshal($this->db->f('billing_start'), 'int'));
         $contract->set_billing_end_date($this->unmarshal($this->db->f('billing_end'), 'int'));
         $contract->set_old_contract_id($this->unmarshal($this->db->f('old_contract_id'), 'string'));
         $contract->set_contract_type_title($this->unmarshal($this->db->f('title'), 'string'));
         $contract->set_comment($this->unmarshal($this->db->f('comment'), 'string'));
         $contract->set_last_edited_by_current_user($this->unmarshal($this->db->f('edited_on'), 'int'));
         $contract->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
         $contract->set_last_updated($this->unmarshal($this->db->f('last_updated'), 'int'));
         $contract->set_service_id($this->unmarshal($this->db->f('service_id'), 'string'));
         $contract->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id'), 'string'));
         $contract->set_reference($this->unmarshal($this->db->f('reference'), 'string'));
         $contract->set_invoice_header($this->unmarshal($this->db->f('invoice_header'), 'string'));
         $contract->set_account_in($this->unmarshal($this->db->f('account_in'), 'string'));
         $contract->set_account_out($this->unmarshal($this->db->f('account_out'), 'string'));
         $contract->set_project_id($this->unmarshal($this->db->f('project_id'), 'string'));
         $contract->set_executive_officer_id($this->unmarshal($this->db->f('executive_officer'), 'int'));
         $contract->set_term_id($this->unmarshal($this->db->f('term_id'), 'int'));
         $contract->set_term_id_title($this->unmarshal($this->db->f('term_title'), 'string'));
         $contract->set_security_type($this->unmarshal($this->db->f('security_type'), 'int'));
         $contract->set_security_amount($this->unmarshal($this->db->f('security_amount'), 'string'));
         $contract->set_due_date($this->unmarshal($this->db->f('due_date'), 'int'));
         $contract->set_contract_type_id($this->unmarshal($this->db->f('contract_type_id'), int));
         $contract->set_rented_area($this->unmarshal($this->db->f('rented_area'), 'float'));
         $contract->set_adjustable($this->unmarshal($this->db->f('adjustable'), 'bool'));
         $contract->set_adjustment_interval($this->unmarshal($this->db->f('adjustment_interval'), 'int'));
         $contract->set_adjustment_share($this->unmarshal($this->db->f('adjustment_share'), 'int'));
         $contract->set_adjustment_year($this->unmarshal($this->db->f('adjustment_year'), 'int'));
         $contract->set_publish_comment($this->unmarshal($this->db->f('publish_comment'), 'bool'));
         $contract->set_notify_before($this->unmarshal($this->db->f('notify_before'), 'int'));
         $contract->set_notify_before_due_date($this->unmarshal($this->db->f('notify_before_due_date'), 'int'));
         $contract->set_notify_after_termination_date($this->unmarshal($this->db->f('notify_after_termination_date'), 'int'));
     }
     $timestamp_end = $this->unmarshal($this->db->f('timestamp_end'), 'int');
     $billing_deleted = $this->unmarshal($this->db->f('deleted'), 'bool');
     if ($timestamp_end && !$billing_deleted) {
         $contract->add_bill_timestamp($timestamp_end);
     }
     $total_price = $this->unmarshal($this->db->f('total_price'), 'int');
     if ($total_price) {
         $contract->set_total_price($total_price);
     }
     $party_id = $this->unmarshal($this->db->f('party_id', true), 'int');
     if ($party_id) {
         $party = new rental_party($party_id);
         $party->set_first_name($this->unmarshal($this->db->f('first_name', true), 'string'));
         $party->set_last_name($this->unmarshal($this->db->f('last_name', true), 'string'));
         $party->set_company_name($this->unmarshal($this->db->f('company_name', true), 'string'));
         $party->set_department($this->unmarshal($this->db->f('department', true), 'string'));
         $party->set_org_enhet_id($this->unmarshal($this->db->f('org_enhet_id'), 'int'));
         $is_payer = $this->unmarshal($this->db->f('is_payer', true), 'bool');
         if ($is_payer) {
             $contract->set_payer_id($party_id);
         }
         $contract->add_party($party);
     }
     $composite_id = $this->unmarshal($this->db->f('composite_id', true), 'int');
     if ($composite_id) {
         $composite = new rental_composite($composite_id);
         $composite->set_name($this->unmarshal($this->db->f('composite_name', true), 'string'));
         $contract->add_composite($composite);
     }
     return $contract;
 }
예제 #4
0
 public function serialize(rental_contract $contract = null)
 {
     $is_payer = '';
     if (isset($contract) && $contract->get_payer_id() == $this->id) {
         $is_payer = lang('is_payer');
     }
     $address_elements = array($this->address_1, $this->address_2, "{$this->postal_code} {$this->place}");
     $address = '';
     foreach ($address_elements as $element) {
         if ($element != null && $element != '') {
             if ($address != '') {
                 $address .= ', ';
             }
             $address .= $element;
         }
     }
     $location_name = $GLOBALS['phpgw']->locations->get_name($this->location_id);
     $result_unit_number = result_unit::get_identifier_from_name($location_name['location']);
     return array('id' => $this->id, 'name' => $this->get_name(), 'identifier' => $this->identifier, 'firstname' => $this->first_name, 'lastname' => $this->last_name, 'title' => $this->title, 'company_name' => $this->company_name, 'department' => $this->department, 'address' => $address, 'address1' => $this->address_1, 'address2' => $this->address_2, 'postal_code' => $this->postal_code, 'place' => $this->place, 'phone' => $this->phone, 'mobile_phone' => $this->mobile_phone, 'fax' => $this->fax, 'email' => $this->email, 'url' => $this->url, 'location_id' => $this->location_id, 'account_number' => $this->account_number, 'reskontro' => $this->reskontro, 'is_inactive' => $this->is_inactive, 'is_payer' => $is_payer, 'result_unit_number' => $result_unit_number, 'service_id' => $this->sync_data['service_id'], 'responsibility_id' => $this->sync_data['responsibility_id'], 'org_enhet_id' => $this->get_org_enhet_id(), 'unit_leader' => $this->get_unit_leader(), 'sync_message' => implode('<br/>', $this->get_sync_problems()));
 }
예제 #5
0
		</dd>
		<dt>
			<label for="adjustment_year"><?php 
echo lang('year');
?>
</label>
		</dt>
		<dd>
			<?php 
if ($editable) {
    ?>
				<select name="adjustment_year" id="adjustment_year">
				<?php 
    $this_year = date('Y');
    $adjustment_year = $adjustment->get_year();
    $years = rental_contract::get_year_range();
    foreach ($years as $year) {
        ?>
						<option value="<?php 
        echo $year;
        ?>
"<?php 
        echo $adjustment_year == $year ? ' selected="selected"' : '';
        ?>
><?php 
        echo $year;
        ?>
</option>
						<?php 
    }
    ?>
 /**
  * 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')));
 }
 function populate(int $composite_id, &$composite)
 {
     if ($composite == null) {
         $composite = new rental_composite($composite_id);
         $composite->set_description($this->unmarshal($this->db->f('description', true), 'string'));
         $composite->set_is_active($this->db->f('is_active'));
         $composite_name = $this->unmarshal($this->db->f('name', true), 'string');
         if ($composite_name == null || $composite_name == '') {
             $composite_name = lang('no_name_composite', $composite_id);
         }
         $composite->set_name($composite_name);
         $composite->set_has_custom_address($this->unmarshal($this->db->f('has_custom_address', true), 'bool'));
         $composite->set_custom_address_1($this->unmarshal($this->db->f('address_1', true), 'string'));
         $composite->set_custom_address_2($this->unmarshal($this->db->f('address_2', true), 'string'));
         $composite->set_custom_house_number($this->unmarshal($this->db->f('house_number', true), 'string'));
         $composite->set_custom_postcode($this->unmarshal($this->db->f('postcode', true), 'string'));
         $composite->set_custom_place($this->unmarshal($this->db->f('place', true), 'string'));
         $composite->set_area($this->unmarshal($this->db->f('area', true), 'float'));
         $composite->set_furnish_type_id($this->unmarshal($this->db->f('furnish_type_id'), 'int'));
         $composite->set_standard_id($this->unmarshal($this->db->f('standard_id'), 'int'));
     }
     // Location code
     $location_code = $this->unmarshal($this->db->f('location_code', true), 'string');
     //Status
     $database_status = $this->unmarshal($this->db->f('status', true), 'string');
     $composite_status = $composite->get_status();
     if ($composite_status != 'Ikke ledig') {
         $composite->set_status($database_status);
     }
     $contract_id = $this->unmarshal($this->db->f('contract_id', true), 'int');
     // Adds contract to array in composite object if it's not already added
     if ($contract_id != 0 & !$composite->contains_contract($contract_id)) {
         $contract = new rental_contract($contract_id);
         $start_date = $this->unmarshal($this->db->f('date_start', true), 'int');
         $end_date = $this->unmarshal($this->db->f('date_end', true), 'int');
         $old_contract_id = $this->unmarshal($this->db->f('old_contract_id', true), 'string');
         // Adds contract if end date is not specified or greater than todays date
         if ($end_date == 0 || $end_date > time()) {
             $contract_date = new rental_contract_date($start_date, $end_date);
             $contract->set_contract_date($contract_date);
             $contract->set_old_contract_id($old_contract_id);
             $composite->add_contract($contract);
         }
     }
     if (!$composite->contains_unit($location_code)) {
         //composite inneholder ikke unit -> legg den til
         $location = null;
         try {
             // We get the data from the property module
             $data = @execMethod('property.bolocation.read_single', array('location_code' => $location_code, 'extra' => array('view' => true)));
             if ($data != null) {
                 $level = -1;
                 $names = array();
                 $levelFound = false;
                 for ($i = 1; $i < 6; $i++) {
                     $loc_name = 'loc' . $i . '_name';
                     if (array_key_exists($loc_name, $data)) {
                         $level = $i;
                         $names[$level] = $data[$loc_name];
                     }
                 }
                 $gab_id = '';
                 $gabinfos = @execMethod('property.sogab.read', array('location_code' => $location_code, 'allrows' => true));
                 if ($gabinfos != null && is_array($gabinfos) && count($gabinfos) == 1) {
                     $gabinfo = array_shift($gabinfos);
                     $gab_id = $gabinfo['gab_id'];
                 }
                 $location = new rental_property_location($location_code, rental_uicommon::get_nicely_formatted_gab_id($gab_id), $level, $names);
                 if (isset($data['street_name']) && $data['street_name']) {
                     $location->set_address_1($data['street_name'] . ' ' . $data['street_number']);
                 }
                 //$location->set_address_1($data['address']);
                 foreach ($data['attributes'] as $attributes) {
                     switch ($attributes['column_name']) {
                         case 'area_gross':
                             $location->set_area_gros($attributes['value']);
                             break;
                         case 'area_net':
                             $location->set_area_net($attributes['value']);
                             break;
                     }
                 }
             } else {
                 $location = new rental_property_location($location_code, null, 1, array());
             }
         } catch (Exception $e) {
             $location = new rental_property_location($location_code, null, 1, array());
         }
         $composite->add_unit(new rental_unit($this->unmarshal($this->db->f('unit_id', true), 'int'), $composite_id, $location));
     }
     return $composite;
 }
 /**
  * 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')));
 }