public function download_agresso() { $browser = CreateObject('phpgwapi.browser'); $browser->content_header('export.txt', 'text/plain'); print rental_soparty::get_instance()->get_export_data(); }
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; }
/** * Synchronization job to update company name on contract parties which are connected to Fellesdata. * * Uses property org_enhet_id on party to link party with unit from Fellesdata. * To be run as a scheduled job */ function syncronize_party_name() { $config = CreateObject('phpgwapi.config', 'rental'); $config->read(); $use_fellesdata = $config->config_data['use_fellesdata']; if (!$use_fellesdata) { return; } $bofelles = rental_bofellesdata::get_instance(); $parties = rental_soparty::get_instance()->get(); $result_count = rental_soparty::get_instance()->get_count(); $updated_parties; $updated_parties[] = "Total number of parties: {$result_count}"; if ($this->isExecutiveOfficer() || $this->isAdministrator()) { $count = 0; $count_result_unit_number = 0; $count_identifier = 0; $count_responsibility = 0; foreach ($parties as $party) { $unit_found = false; $fellesdata = NULL; if (isset($party)) { $sync_data = $party->get_sync_data(); $fellesdata = $bofelles->result_unit_exist($sync_data['result_unit_number'], 4); if ($fellesdata) { $updated_parties[] = "Unit id found {$fellesdata['UNIT_ID']} by result unit number check. The unit name is {$fellesdata['UNIT_NAME']}<br />"; $count_result_unit_number++; } if ($fellesdata && isset($fellesdata['UNIT_ID']) && is_numeric($fellesdata['UNIT_ID'])) { // We found a match, so store the new connection $party->set_org_enhet_id($fellesdata['UNIT_ID']); $old_party_name = $party->get_company_name(); $party->set_company_name($fellesdata['UNIT_NAME']); $updated_parties[] = "Updated company name on party {$party->get_id()} with unit ID {$party->get_org_enhet_id} from {$old_party_name} to {$party->get_company_name()}"; $count++; } else { // No match was found. Do nothing //$party->set_org_enhet_id(NULL); } rental_soparty::get_instance()->store($party); } } $updated_parties[] = "Number of parties found through result unit number {$count_result_unit_number}"; $updated_parties[] = "Number of parties that have been updated {$count}"; $this->log_sync_messages($updated_parties); } }
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]; }
/** * Public function to add a document. * * @param HTTP::contract_id the contract id * @param HTTP::party_id the party id * @return unknown_type */ public function add() { // Get target ids $contract_id = intval(phpgw::get_var('contract_id')); $party_id = intval(phpgw::get_var('party_id')); $data = array(); // Check permissions if contract id is set if (isset($contract_id) && $contract_id > 0) { //Load contract $contract = rental_socontract::get_instance()->get_single($contract_id); if (!$contract->has_permission(PHPGW_ACL_EDIT)) { $data['error'] = lang('permission_denied_add_document'); $this->render('permission_denied.php', $data); return; } } // Check permissions if party id is set if (isset($party_id) && $party_id > 0) { //Load party $party = rental_soparty::get_instance()->get_single($party_id); if (!($this->isAdministrator() || $this->isExecutiveOfficer())) { $data['error'] = lang('permission_denied_add_document'); $this->render('permission_denied.php', $data); return; } } // If no contract or party is loaded if (!(isset($party) || isset($contract))) { $data['error'] = lang('error_no_contract_or_party'); $this->render('permission_denied.php', $data); return; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Create a document object $document = new rental_document(); $document->set_title(phpgw::get_var('document_title')); $document->set_name($_FILES["file_path"]["name"]); $document->set_type_id(phpgw::get_var('document_type')); $document->set_contract_id($contract_id); $document->set_party_id($party_id); //Retrieve the document properties $document_properties = $this->get_type_and_id($document); // Move file from temporary storage to vfs $result = rental_sodocument::get_instance()->write_document_to_vfs($document_properties['document_type'], $_FILES["file_path"]["tmp_name"], $document_properties['id'], $_FILES["file_path"]["name"]); if ($result) { if (rental_sodocument::get_instance()->store($document)) { if (isset($party)) { $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uiparty.edit', 'id' => $party->get_id(), 'tab' => 'documents')); } else { if (isset($contract)) { $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'tab' => 'documents')); } } } else { // Handle failure on storing document $this->redirect($document, $document_propeties, '', ''); } } else { //Handle vfs failure to store document $this->redirect($document, $document_propeties, '', ''); } } }
/** * Common function for viewing or editing a contract * * @param $editable whether or not the contract should be editable in the view * @param $contract_id the id of the contract to show */ public function viewedit($editable, $contract_id, $contract = null, $location_id = null, $notification = null, string $message = null, string $error = null) { $cancel_link = self::link(array('menuaction' => 'rental.uicontract.index', 'populate_form' => 'yes')); $adjustment_id = (int) phpgw::get_var('adjustment_id'); if ($adjustment_id) { $cancel_link = self::link(array('menuaction' => 'rental.uiadjustment.show_affected_contracts', 'id' => $adjustment_id)); $cancel_text = 'contract_regulation_back'; } if (isset($contract_id) && $contract_id > 0) { if ($contract == null) { $contract = rental_socontract::get_instance()->get_single($contract_id); } if ($contract) { if ($editable && !$contract->has_permission(PHPGW_ACL_EDIT)) { $editable = false; $error .= '<br/>' . lang('permission_denied_edit_contract'); } if (!$editable && !$contract->has_permission(PHPGW_ACL_READ)) { $this->render('permission_denied.php', array('error' => lang('permission_denied_view_contract'))); return; } $parties = rental_soparty::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contract->get_id())); $party = reset($parties); // $contract_dates = $contract->get_contract_date(); $composites = rental_socomposite::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contract->get_id())); $composite = reset($composites); $units = $composite->get_units(); $price_items = rental_socontract_price_item::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contract->get_id())); $months = rental_socontract::get_instance()->get_months_in_term($contract->get_term_id()); $one_time_price_items = array(); $termin_price_items = array(); foreach ($price_items as $item) { if ($item->is_one_time()) { array_push($one_time_price_items, $item); } else { array_push($termin_price_items, $item); } } $data = array('contract' => $contract, 'months' => $months, 'contract_party' => $party, 'contract_dates' => $contract_dates, 'composite' => $composite, 'units' => $units, 'price_items' => $price_items, 'one_time_price_items' => $one_time_price_items, 'termin_price_items' => $termin_price_items, 'notification' => $notification, 'editable' => $editable, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'cancel_link' => $cancel_link, 'cancel_text' => $cancel_text); $contract->check_consistency(); $this->get_pdf_templates(); $template_file = 'pdf/' . $this->pdf_templates[$_GET[pdf_template]][1]; $this->render($template_file, $data); } } else { if ($this->isAdministrator() || $this->isExecutiveOfficer()) { if (!isset($contract)) { $contract = new rental_contract(); $fields = rental_socontract::get_instance()->get_fields_of_responsibility(); $contract->set_location_id($location_id); $contract->set_contract_type_title($fields[$location_id]); } if ($contract) { $data = array('contract' => $contract, 'notification' => $notification, 'editable' => true, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'cancel_link' => $cancel_link, 'cancel_text' => $cancel_text); $this->render('contract.php', $data); } } else { $this->render('permission_denied.php', array('error' => lang('permission_denied_new_contract'))); return; } } }
/** * * @param array $org_unit_ids */ public static function get_property_locations($array, $top_org_units) { foreach ($array as $row) { /* * 1. hent alle kontraktsparter som har org unit id (foreløpig bruker vi result_unit_number i rentalparty) * 2. hent alle kontrakter på kontraktspartene * 3. hent alle leieobjekt på kontraktene * 4. hent ut bygg-ider, location_code, fra leieobjektet */ if (is_array($row)) { if (!isset($row['ORG_UNIT_ID']) || $row['ORG_UNIT_ID'] == '') { continue; } $parties = self::get_all_parties($top_org_units, $row['ORG_UNIT_ID']); } else { $parties = rental_soparty::get_instance()->get(null, null, null, null, null, null, array('email' => $row)); $parties = array_keys($parties); } $contracts = array(); $composites = array(); $sorental = CreateObject('frontend.sorental'); //For all parties connected to the internal organization unit $locations = $sorental->get_location($parties); } return $locations; }
public function delete_party() { $party_id = phpgw::get_var('id'); if ($this->isExecutiveOfficer() || $this->isAdministrator()) { if (isset($party_id) && $party_id > 0) { if (rental_soparty::get_instance()->delete_party($party_id)) { $message = lang('messages_saved_form'); } else { $error = lang('messages_form_error'); } } } else { $this->render('permission_denied.php', array('error' => lang('permission_denied_edit'))); } }