/**
  * 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.soparty');
     }
     return self::$so;
 }
 public function remove_party(rental_party $party_to_remove)
 {
     unset($this->parties[$party_to_remove]);
     $so = self::get_so();
     $so->remove_party($this->get_id(), $party_to_remove->get_id());
 }
 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;
 }
 protected function populate(int $party_id, &$party)
 {
     if ($party == null) {
         $party = new rental_party((int) $party_id);
         $party->set_account_number($this->unmarshal($this->db->f('account_number'), 'string'));
         $party->set_address_1($this->unmarshal($this->db->f('address_1'), 'string'));
         $party->set_address_2($this->unmarshal($this->db->f('address_2'), 'string'));
         $party->set_comment($this->unmarshal($this->db->f('comment'), 'string'));
         $party->set_company_name($this->unmarshal($this->db->f('company_name'), 'string'));
         $party->set_department($this->unmarshal($this->db->f('department'), 'string'));
         $party->set_email($this->unmarshal($this->db->f('email'), 'string'));
         $party->set_fax($this->unmarshal($this->db->f('fax'), 'string'));
         $party->set_first_name($this->unmarshal($this->db->f('first_name'), 'string'));
         $party->set_is_inactive($this->unmarshal($this->db->f('is_inactive'), 'bool'));
         $party->set_last_name($this->unmarshal($this->db->f('last_name'), 'string'));
         $party->set_location_id($this->unmarshal($this->db->f('org_location_id'), 'int'));
         $party->set_identifier($this->unmarshal($this->db->f('identifier'), 'string'));
         $party->set_mobile_phone($this->unmarshal($this->db->f('mobile_phone'), 'string'));
         $party->set_place($this->unmarshal($this->db->f('place'), 'string'));
         $party->set_postal_code($this->unmarshal($this->db->f('postal_code'), 'string'));
         $party->set_reskontro($this->unmarshal($this->db->f('reskontro'), 'string'));
         $party->set_title($this->unmarshal($this->db->f('title'), 'string'));
         $party->set_url($this->unmarshal($this->db->f('url'), 'string'));
         $party->set_org_enhet_id($this->unmarshal($this->db->f('org_enhet_id'), 'string'));
         $party->set_unit_leader($this->unmarshal($this->db->f('unit_leader'), 'string'));
         $sync_message = $party->set_sync_data(array('responsibility_id' => $this->unmarshal($this->db->f('responsibility_id'), 'string'), 'org_enhet_id' => $this->unmarshal($this->db->f('org_enhet_id'), 'string'), 'result_unit_number' => $this->unmarshal($this->db->f('result_unit_number'), 'string')));
         if (isset($sync_message) && $sync_message != '') {
             $party->add_sync_problem($sync_message);
         }
     }
     return $party;
 }
 protected function import_parties()
 {
     $start_time = time();
     $soparty = rental_soparty::get_instance();
     $parties = array();
     //Check to see if there is any parties in the database. If so, do not store these
     //... double checking to  ensure that the user has not logged out and in again during import
     $alreay_imported_parties = false;
     $number_of_parties = $soparty->get_number_of_parties();
     if ($number_of_parties > 0) {
         return;
     }
     $datalines = $this->getcsvdata($this->path . "/u_PersonForetak.csv", true);
     $this->messages[] = "Read 'u_PersonForetak.csv' file in " . (time() - $start_time) . " seconds";
     $this->messages[] = "'u_PersonForetak.csv' contained " . count($datalines) . " lines";
     $counter = 1;
     // Loop through each line of the file, parsing CSV data to a php array
     foreach ($datalines as $data) {
         if (count($data) <= 30) {
             continue;
         }
         // Create a new rental party we can fill with info from this line from the file
         $party = new rental_party();
         $identifier = $this->decode($data[24]);
         //cPersonForetaknr
         //Removed whitespace characters
         $identifier = str_replace(' ', '', '' . $identifier);
         // Default information
         $party->set_address_1($this->decode($data[3]));
         //cAdresse1
         $party->set_address_2($this->decode($data[4]));
         //cAdresse2
         $party->set_postal_code($this->decode($data[5]));
         //cPostnr
         $party->set_mobile_phone($this->decode($data[7]));
         //cMobil
         $party->set_phone($this->decode($data[8]));
         //cTelefon
         $party->set_fax($this->decode($data[9]));
         //cTelefaks
         $party->set_title($this->decode($data[12]));
         //cArbeidstittel
         $party->set_email($this->decode($data[25]));
         //cEpost
         $party->set_company_name($this->decode($data[10]));
         //cArbeidsgiver
         $party->set_department($this->decode($data[11]));
         //cAvdeling
         $party->set_account_number($this->decode($data[14]));
         //cBankkontonr
         $party->set_reskontro($this->decode($data[23]));
         //cReskontronr
         $party->set_comment($this->decode($data[26]));
         //cMerknad
         // Insert contract person in comment if present
         $contact_person = $this->decode($data[6]);
         if (isset($contact_person)) {
             $party->set_comment($party->get_comment() . "\n\nKontaktperson: " . $contact_person);
             //cKontaktPerson
         }
         $valid_identifier = false;
         switch (strlen('' . $identifier)) {
             case 4:
                 // Intern organisasjonstilknytning
                 //Should be four number or on the form 'KFxx'
                 if (is_numeric($identifier) || substr($identifier, 0, 2) == 'KF' && is_numeric(substr($identifier, 2, 2))) {
                     $party->set_company_name($this->decode($data[2]));
                     //cForetaksnavn
                     $party->set_first_name(null);
                     $party->set_last_name(null);
                     // Get location ID
                     $locations = $GLOBALS['phpgw']->locations;
                     $subs = $locations->get_subs_from_pattern('rental', '.ORG.BK.__.' . $identifier);
                     //cPersonForetaknr
                     if (count($subs) > 0) {
                         $party->set_location_id($subs[0]['location_id']);
                     } else {
                         $this->warnings[] = "Party with valid identifier ({$identifier}) not found in internal organisation tree. Company name({$party->get_company_name()})";
                     }
                     $valid_identifier = true;
                 }
                 break;
             case 5:
                 //Internal, Should be a result unit on the form 'Rxxxx'
                 if (substr($identifier, 0, 1) == 'R' && is_numeric(substr($identifier, 1, 4))) {
                     $identifier = substr($identifier, 1, 4);
                     $party->set_company_name($this->decode($data[2]));
                     //cForetaksnavn
                     $party->set_first_name(null);
                     $party->set_last_name(null);
                     // Get location ID
                     $locations = $GLOBALS['phpgw']->locations;
                     $subs = $locations->get_subs_from_pattern('rental', '.ORG.BK.__.' . $identifier);
                     //cPersonForetaknr
                     if (count($subs) > 0) {
                         $party->set_location_id($subs[0]['location_id']);
                     } else {
                         $this->warnings[] = "Party with valid identifier ({$identifier}- original R{$identifier}) not found in internal organisation tree. Company name({$party->get_company_name()})";
                     }
                     $valid_identifier = true;
                 }
                 break;
             case 6:
                 // Foretak (agresso-id)
             // Foretak (agresso-id)
             case 9:
                 // Foretak (org.nr)
                 if (is_numeric($identifier)) {
                     $party->set_company_name($this->decode($data[2]));
                     //cForetaksnavn
                     $party->set_first_name(null);
                     $party->set_last_name(null);
                     $valid_identifier = true;
                 }
                 break;
             case 11:
                 // Personnr
                 if (is_numeric($identifier)) {
                     if (!$this->is_null($data[0])) {
                         $party->set_first_name($this->decode($data[0]));
                         //cFornavn
                         $party->set_last_name($this->decode($data[1]));
                         //cEtternavn
                     } else {
                         $company_name = explode(' ', $this->decode($data[2]), 2);
                         //cForetaksnavn
                         $party->set_first_name($company_name[0]);
                         //cFornavn
                         $party->set_last_name($company_name[1]);
                         //cEtternavn
                     }
                     $valid_identifier = true;
                 }
                 break;
         }
         if (!$valid_identifier) {
             $party->set_first_name($this->decode($data[0]));
             //cFornavn
             $party->set_last_name($this->decode($data[1]));
             //cEtternavn
             $party->set_company_name($this->decode($data[2]));
             //cForetaksnavn
             $party->set_is_inactive(true);
             $this->warnings[] = "Party with unknown 'cPersonForetaknr' format ({$identifier}). First name ({$party->get_first_name()}). Last name({$party->get_last_name()}). Company name({$party->get_company_name()}) Setting as inactive.";
         }
         // Fødselsnr/Foretaksnr/AgressoID
         $party->set_identifier($identifier);
         // Store party and log message
         if ($soparty->store($party)) {
             // Add party to collection of parties keyed by its facilit ID so we can refer to it later.
             $facilit_id = $data[17];
             //nPersonForetakId
             $parties[$facilit_id] = $party->get_id();
             $this->messages[] = "Successfully added party " . $party->get_name() . " (" . $party->get_id() . ")";
         } else {
             $this->errors[] = "Failed to store party " . $party->get_name();
         }
     }
     $this->messages[] = "Successfully imported " . count($parties) . " contract parties. (" . (time() - $start_time) . " seconds).";
     //Clean up
     //unset();
     return $parties;
 }
Example #6
0
$sql_contracts = "SELECT contract_id from rental_invoice, rental_billing where rental_invoice.billing_id = rental_billing.id and rental_billing.id = {$billing_id}";
$this->db->query($sql_contracts, __LINE__, __FILE__);
while ($this->db->next_record()) {
    $contract_ids[] = $this->unmarshal($this->db->f('contract_id'), 'int');
}
foreach ($contract_ids as $contract_id) {
    $sql_parties = "select rental_party.* ";
    $sql_parties .= "from rental_party, rental_contract_party, rental_contract ";
    $sql_parties .= "where rental_contract_party.contract_id = rental_contract.id ";
    $sql_parties .= "and rental_contract_party.is_payer ";
    $sql_parties .= "and rental_party.id = rental_contract_party.party_id ";
    $sql_parties .= "and rental_contract.id = {$contract_id}";
    $this->db->query($sql_parties, __LINE__, __FILE__);
    while ($this->db->next_record()) {
        //generate party-objects
        $party = new rental_party($this->unmarshal($this->db->f('id'), 'string'));
        $party->set_account_number($this->unmarshal($this->db->f('account_number'), 'string'));
        $party->set_address_1($this->unmarshal($this->db->f('address_1'), 'string'));
        $party->set_address_2($this->unmarshal($this->db->f('address_2'), 'string'));
        $party->set_comment($this->unmarshal($this->db->f('comment'), 'string'));
        $party->set_company_name($this->unmarshal($this->db->f('company_name'), 'string'));
        $party->set_department($this->unmarshal($this->db->f('department'), 'string'));
        $party->set_email($this->unmarshal($this->db->f('email'), 'string'));
        $party->set_fax($this->unmarshal($this->db->f('fax'), 'string'));
        $party->set_first_name($this->unmarshal($this->db->f('first_name'), 'string'));
        $party->set_is_inactive($this->unmarshal($this->db->f('is_inactive'), 'bool'));
        $party->set_last_name($this->unmarshal($this->db->f('last_name'), 'string'));
        $party->set_location_id($this->unmarshal($this->db->f('org_location_id'), 'int'));
        $party->set_identifier($this->unmarshal($this->db->f('identifier'), 'string'));
        $party->set_mobile_phone($this->unmarshal($this->db->f('mobile_phone'), 'string'));
        $party->set_place($this->unmarshal($this->db->f('place'), 'string'));
 /**
  * Public method. Called when user wants to edit a contract party.
  * @param HTTP::id	the party ID
  */
 public function edit()
 {
     $GLOBALS['phpgw_info']['flags']['app_header'] .= '::' . lang('edit');
     // Get the contract part id
     $party_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($party_id) && $party_id > 0) {
             $party = rental_soparty::get_instance()->get_single($party_id);
         } else {
             $party = new rental_party();
         }
     } else {
         $this->render('permission_denied.php', array('error' => lang('permission_denied_edit')));
     }
     if (isset($_POST['save_party'])) {
         if (isset($party)) {
             // ... set all parameters
             $party->set_identifier(phpgw::get_var('identifier'));
             $party->set_first_name(phpgw::get_var('firstname'));
             $party->set_last_name(phpgw::get_var('lastname'));
             $party->set_title(phpgw::get_var('title'));
             $party->set_company_name(phpgw::get_var('company_name'));
             $party->set_department(phpgw::get_var('department'));
             $party->set_address_1(phpgw::get_var('address1'));
             $party->set_address_2(phpgw::get_var('address2'));
             $party->set_postal_code(phpgw::get_var('postal_code'));
             $party->set_place(phpgw::get_var('place'));
             $party->set_phone(phpgw::get_var('phone'));
             $party->set_mobile_phone(phpgw::get_var('mobile_phone'));
             $party->set_fax(phpgw::get_var('fax'));
             $party->set_email(phpgw::get_var('email'));
             $party->set_url(phpgw::get_var('url'));
             $party->set_account_number(phpgw::get_var('account_number'));
             $party->set_reskontro(phpgw::get_var('reskontro'));
             $party->set_is_inactive(phpgw::get_var('is_inactive') == 'on' ? true : false);
             $party->set_comment(phpgw::get_var('comment'));
             //$party->set_location_id(phpgw::get_var('location_id'));
             $party->set_org_enhet_id(phpgw::get_var('org_enhet_id'));
             $party->set_unit_leader(phpgw::get_var('unit_leader'));
             if (rental_soparty::get_instance()->store($party)) {
                 $message = lang('messages_saved_form');
             } else {
                 $error = lang('messages_form_error');
             }
         }
     }
     $config = CreateObject('phpgwapi.config', 'rental');
     $config->read();
     return $this->render('party.php', array('party' => $party, '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.uiparty.index', 'populate_form' => 'yes')), 'use_fellesdata' => $config->config_data['use_fellesdata']));
 }
 protected function populate(int $invoice_id, &$invoice)
 {
     if ($invoice == null) {
         $invoice = new rental_invoice($this->db->f('id', true), $this->db->f('billing_id', true), $this->db->f('contract_id', true), $this->db->f('timestamp_created', true), $this->db->f('timestamp_start', true), $this->db->f('timestamp_end', true), $this->db->f('total_sum', true), $this->db->f('total_area', true), $this->db->f('header', true), $this->db->f('account_in', true), $this->db->f('account_out', true), $this->db->f('service_id', true), $this->db->f('responsibility_id', true), $this->db->f('project_id', true));
         $invoice->set_party_id($this->unmarshal($this->db->f('party_id'), 'int'));
         $invoice->set_project_id($this->unmarshal($this->db->f('project_id'), 'string'));
         $invoice->set_old_contract_id($this->unmarshal($this->db->f('old_contract_id'), 'string'));
         $invoice->set_term_id($this->unmarshal($this->db->f('term_id'), 'int'));
         $invoice->set_month($this->unmarshal($this->db->f('month'), 'int'));
         $invoice->set_billing_title($this->unmarshal($this->db->f('billing_title'), 'string'));
         $invoice->set_serial_number($this->unmarshal($this->db->f('serial_number'), 'int'));
         $invoice->set_reference($this->unmarshal($this->db->f('reference'), 'string'));
         $party = new rental_party($this->unmarshal($this->db->f('party_id'), 'int'));
         $party->set_account_number($this->unmarshal($this->db->f('party_account_number'), 'string'));
         $party->set_address_1($this->unmarshal($this->db->f('party_address_1'), 'string'));
         $party->set_address_2($this->unmarshal($this->db->f('party_address_2'), 'string'));
         $party->set_comment($this->unmarshal($this->db->f('party_comment'), 'string'));
         $party->set_company_name($this->unmarshal($this->db->f('party_company_name'), 'string'));
         $party->set_department($this->unmarshal($this->db->f('party_department'), 'string'));
         $party->set_email($this->unmarshal($this->db->f('party_email'), 'string'));
         $party->set_fax($this->unmarshal($this->db->f('party_fax'), 'string'));
         $party->set_first_name($this->unmarshal($this->db->f('party_first_name'), 'string'));
         $party->set_is_inactive($this->unmarshal($this->db->f('party_in_active'), 'bool'));
         $party->set_last_name($this->unmarshal($this->db->f('party_last_name'), 'string'));
         $party->set_location_id($this->unmarshal($this->db->f('party_org_location_id'), 'int'));
         $party->set_identifier($this->unmarshal($this->db->f('party_identifier'), 'string'));
         $party->set_mobile_phone($this->unmarshal($this->db->f('party_mobile_phone'), 'string'));
         $party->set_place($this->unmarshal($this->db->f('party_place'), 'string'));
         $party->set_postal_code($this->unmarshal($this->db->f('party_postal_code'), 'string'));
         $party->set_reskontro($this->unmarshal($this->db->f('party_reskontro'), 'string'));
         $party->set_title($this->unmarshal($this->db->f('party_title'), 'string'));
         $party->set_url($this->unmarshal($this->db->f('party_url'), 'string'));
         $invoice->set_party($party);
         if ($invoice->get_term_id() == 2) {
             // yearly
             $invoice->set_term_label(lang('annually'));
         } else {
             if ($invoice->get_term_id() == 3) {
                 // half year
                 if ($invoice->get_month() == 6) {
                     $invoice->set_term_label(lang('first_half'));
                 } else {
                     $invoice->set_term_label(lang('second_half'));
                 }
             } else {
                 if ($invoice->get_term_id() == 4) {
                     // quarterly
                     if ($invoice->get_month() == 3) {
                         $invoice->set_term_label(lang('first_quarter'));
                     } else {
                         if ($invoice->get_month() == 6) {
                             $invoice->set_term_label(lang('second_quarter'));
                         } else {
                             if ($invoice->get_month() == 9) {
                                 $invoice->set_term_label(lang('third_quarter'));
                             } else {
                                 $invoice->set_term_label(lang('fourth_quarter'));
                             }
                         }
                     }
                 } else {
                     $invoice->set_term_label(lang('month ' . $invoice->get_month() . ' capitalized'));
                 }
             }
         }
     }
     $invoice->add_composite_name($this->unmarshal($this->db->f('composite_name'), 'string'));
     return $invoice;
 }