function countyOptions() { $county = new County(); $data = $county->get_countyOptions(trim($_GET['v1']), trim($_GET['v']), 'N'); if (count($data) < 1) { return '<input name="txtcounty" type="text" size="30" maxlength="100" /> '; } $ret = ' <select class="select" name="txtcounty" onchange="javascript: cascadeCountyAdmin(this.value,this.form.txt_country.value, this.form.txtstateprovince.value,\'txtcity\');" >'; $ret .= '<option value="">' . get_lang('select_text') . '</option>'; foreach ($data as $k => $y) { if ($k != 'AA') { $ret .= "<option value='{$k}'>{$y}</option>"; } } unset($data); return $ret .= '</select>'; }
public function address() { $address = ""; if (isset($this->address) && !empty($this->address)) { $address .= $this->address . ":"; } if (isset($this->address2) && !empty($this->address2)) { $address .= $this->address2 . ":"; } if (isset($this->city) && !empty($this->city)) { $city = City::find_by_code($this->country, $this->state_province, $this->county, $this->city); $address .= $city->name . ":"; } //county if (isset($this->county) && !empty($this->county)) { $county = County::find_by_code($this->country, $this->state_province, $this->county); $address .= $county->name . ":"; } //states if (isset($this->state_province) && !empty($this->state_province)) { $state_province = StateProvince::find_by_code($this->country, $this->state_province); $address .= $state_province->name . ":"; } //post code if (isset($this->post_code) && !empty($this->post_code)) { $address .= $this->post_code . ":"; } //country if (isset($this->country) && !empty($this->country)) { $country = Country::find_by_code($this->country); $address .= $country->name . ":"; } else { return ""; } return $address; }
public static function getCarrierTaxRate($id_carrier, $id_address = null) { global $cookie, $defaultCountry; $id_country = (int) Country::getDefaultCountryId(); if ($id_country == _PS_COUNTRY_DEFAULT_ && isset($cookie->id_country) && $cookie->id_country != (int) _PS_COUNTRY_DEFAULT_) { $country = new Country((int) $cookie->id_country, $cookie->id_lang); if (ValidaTe::isLoadedObject($country) && $country->active) { $id_country = (int) $country->id; $defaultCountry = $country; } } $id_state = 0; $id_county = 0; if (!empty($id_address)) { $address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) { $id_country = (int) $address_infos['id_country']; $id_state = (int) $address_infos['id_state']; $id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']); } if (!empty($address_infos['vat_number']) && $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') && Configuration::get('VATNUMBER_MANAGEMENT')) { return 0; } } return TaxRulesGroup::getTaxesRate((int) Carrier::getIdTaxRulesGroupByIdCarrier((int) $id_carrier), (int) $id_country, (int) $id_state, (int) $id_county); }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); // create connection to import database $this->logSection('connection', 'creating connection to import source'); $source = Propel::getConnection($options['source'] ? $options['source'] : null); // create static counties and offices $this->logSection('static', 'creating static counties and offices'); $connection->beginTransaction(); try { OfficePeer::doDeleteAll($connection); $o1 = new Office(); $o1->setName('Plattsburgh'); $o1->save($connection); $o1 = new Office(); $o1->setName('Rouses Point'); $o1->save($connection); CountyPeer::doDeleteAll($connection); $c1 = new County(); $c1->setName('Clinton'); $c1->save($connection); $c1 = new County(); $c1->setName('Essex'); $c1->save($connection); $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // read in and create objects for district, frequency, icd9, job, services tables // DISTRICT $query = 'SELECT * FROM %s'; $query = sprintf($query, 'tbl_district'); $statement = $source->prepare($query); $statement->execute(); $districts = $statement->fetchAll(); $connection->beginTransaction(); try { DistrictPeer::doDeleteAll($connection); foreach ($districts as $district) { $this->logSection('district', 'creating district ' . $district['district_name']); $d1 = new District(); $d1->setName($district['district_name']); $d1->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // FREQUENCY $query = 'SELECT * FROM %s'; $query = sprintf($query, 'tbl_frequency'); $statement = $source->prepare($query); $statement->execute(); $frequencies = $statement->fetchAll(); $connection->beginTransaction(); try { FrequencyPeer::doDeleteAll($connection); foreach ($frequencies as $freq) { $this->logSection('freq', 'reading frequency ' . $freq['freq_title']); $f1 = new Frequency(); $f1->setName($freq['freq_title']); $f1->setDescription($freq['freq_description']); $f1->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // ICD9 $query = 'SELECT * FROM %s'; $query = sprintf($query, 'tbl_icd9'); $statement = $source->prepare($query); $statement->execute(); $icd9s = $statement->fetchAll(); $connection->beginTransaction(); try { Icd9Peer::doDeleteAll($connection); foreach ($icd9s as $icd9) { $this->logSection('icd9', 'reading icd9 ' . $icd9['icd9_value']); $i1 = new Icd9(); $i1->setName($icd9['icd9_value']); $i1->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // JOB $query = 'SELECT * FROM %s'; $query = sprintf($query, 'tbl_job'); $statement = $source->prepare($query); $statement->execute(); $jobs = $statement->fetchAll(); $connection->beginTransaction(); try { JobPeer::doDeleteAll($connection); foreach ($jobs as $job) { $this->logSection('job', 'reading job ' . $job['job_title']); $j1 = new Job(); $j1->setName($job['job_title']); $j1->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // SERVICES $query = 'SELECT * FROM %s'; $query = sprintf($query, 'tbl_services'); $statement = $source->prepare($query); $statement->execute(); $services = $statement->fetchAll(); $connection->beginTransaction(); try { ServicePeer::doDeleteAll($connection); foreach ($services as $service) { $this->logSection('service', 'reading service ' . $service['service_title']); $s1 = new Service(); $s1->setName($service['service_title']); $s1->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // EMPLOYEES $query = 'SELECT * FROM %s LEFT JOIN (%s) ON (%s.emp_job_title = %s.job_id)'; $query = sprintf($query, 'tbl_employee', 'tbl_job', 'tbl_employee', 'tbl_job'); $statement = $source->prepare($query); $statement->execute(); $employees = $statement->fetchAll(); $connection->beginTransaction(); try { EmployeePeer::doDeleteAll($connection); foreach ($employees as $employee) { $this->logSection('employee', 'reading employee ' . $employee['emp_id']); $emp = new Employee(); $emp_fields = array('clearance' => $employee['emp_scr_clearance'], 'first_name' => $employee['emp_fn'], 'middle' => $employee['emp_mi'], 'last_name' => $employee['emp_ln'], 'address' => $employee['emp_address'], 'address_2' => $employee['emp_address2'], 'city' => $employee['emp_city'], 'state' => $employee['emp_state'], 'zip' => $employee['emp_zip'], 'home_phone' => $employee['emp_phone'], 'cell_phone' => $employee['emp_cell'], 'company_email' => $employee['emp_email'], 'personal_email' => $employee['emp_p_email'], 'license_number' => $employee['emp_license_number'], 'license_expiration' => $employee['emp_license_exp'], 'dob' => $employee['emp_dob'], 'doh' => $employee['emp_hire_date'], 'dof' => $employee['emp_end_date'], 'ssn' => $employee['emp_ssn'], 'health_insurance' => $employee['emp_health'], 'retirement_plan' => $employee['emp_401k'], 'suplimental_health' => $employee['emp_health_sup'], 'health_type' => $employee['emp_health_type'], 'tb_date' => $employee['emp_tb'], 'osha_date' => $employee['emp_osha'], 'cpr_date' => $employee['emp_cpr'], 'finger_prints' => $employee['emp_fp'], 'finger_print_notes' => $employee['emp_fp_n'], 'notes' => $employee['emp_notes']); $emp->fromArray($emp_fields, BasePeer::TYPE_FIELDNAME); // find the job - check for errors $emp->setJob(JobPeer::getByName($employee['job_title'])); // if physical has a date then create a new physical object for employee if ($employee['emp_physical']) { $this->logSection('physical', 'employee ' . $employee['emp_fn'] . ' had a physical on ' . $employee['emp_physical']); $ph1 = new Physical(); $ph1->setEmployee($emp); $ph1->setDateGiven($employee['emp_physical']); $ph1->save($connection); } $emp->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // read in and create client objects - linking to employee // CLIENTS $query = 'SELECT * FROM %s LEFT JOIN (%s) ON (%s.client_district = %s.district_id)'; $query = sprintf($query, 'tbl_client', 'tbl_district', 'tbl_client', 'tbl_district'); $statement = $source->prepare($query); $statement->execute(); $clients = $statement->fetchAll(); $connection->beginTransaction(); try { ClientPeer::doDeleteAll($connection); foreach ($clients as $client) { $this->logSection('client', 'reading client ' . $client['client_ln']); $cl = new Client(); $client_fields = array('first_name' => $client['client_fn'], 'last_name' => $client['client_ln'], 'dob' => $client['client_dob'], 'parent_first' => $client['client_parent_fn'], 'parent_last' => $client['client_parent_ln'], 'address' => $client['client_address'], 'address_2' => $client['client_address2'], 'city' => $client['client_city'], 'state' => $client['client_state'], 'zip' => $client['client_zip'], 'home_phone' => $client['home_phone'], 'work_phone' => $client['work_phone'], 'cell_phone' => $client['cell_phone'], 'blue_card' => $client['blue_card'], 'physical_exp' => $client['physical_exp_date'], 'immunizations' => $client['immunizations'], 'waiting_list' => $client['waiting_list']); // county $cl->setCounty(CountyPeer::getByName($client['client_county'])); // district $cl->setDistrict(DistrictPeer::getByName($client['district_name'])); $cl->fromArray($client_fields, BasePeer::TYPE_FIELDNAME); $cl->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // CLIENT SERVICES // CLASSROOM $query = 'SELECT * FROM tbl_classroom LEFT JOIN (tbl_client) ON (tbl_classroom.class_client_id = tbl_client.client_id) LEFT JOIN (tbl_employee) ON (tbl_classroom.class_provider_id = tbl_employee.emp_id) LEFT JOIN (tbl_services) ON (tbl_classroom.class_service_id = tbl_services.service_id) LEFT JOIN (tbl_frequency) ON (tbl_classroom.class_freq_id = tbl_frequency.freq_id)'; $statement = $source->prepare($query); $statement->execute(); $classrooms = $statement->fetchAll(); $connection->beginTransaction(); $c = new Criteria(); $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_CLASSROOM); try { ClientServicePeer::doDelete($c, $connection); foreach ($classrooms as $classroom) { $this->logSection('classroom', 'reading service ' . $classroom['class_id']); $cr_cl = new Classroom(); $cr_cl->setStartDate($classroom['class_start_date']); $cr_cl->setEndDate($classroom['class_exp_date']); $cr_cl->setChangeDate($classroom['class_chng_date']); $cr_cl->setNotes($classroom['class_notes']); // client $cr_cl->setClient(ClientPeer::getByFullName($classroom['client_fn'], $classroom['client_ln'])); // employee $cr_cl->setEmployee(EmployeePeer::getByFullName($classroom['emp_fn'], $classroom['emp_ln'])); // service $cr_cl->setService(ServicePeer::getByName($classroom['service_title'])); // frequency $cr_cl->setFrequency(FrequencyPeer::getByName($classroom['freq_title'])); // office $cr_cl->setOffice(OfficePeer::getByName($classroom['class_location'])); $cr_cl->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // EI $query = 'SELECT * FROM tbl_ei LEFT JOIN (tbl_client) ON (tbl_ei.ei_client_id = tbl_client.client_id) LEFT JOIN (tbl_employee) ON (tbl_ei.ei_provider_id = tbl_employee.emp_id) LEFT JOIN (tbl_services) ON (tbl_ei.ei_service_id = tbl_services.service_id) LEFT JOIN (tbl_frequency) ON (tbl_ei.ei_freq_id = tbl_frequency.freq_id) LEFT JOIN (tbl_icd9) ON (tbl_ei.ei_icd9_id = tbl_icd9.icd9_id)'; $statement = $source->prepare($query); $statement->execute(); $eis = $statement->fetchAll(); $connection->beginTransaction(); $c = new Criteria(); $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_EI); try { ClientServicePeer::doDelete($c, $connection); foreach ($eis as $ei) { $this->logSection('ei', 'reading service ' . $ei['ei_id']); $ei_cl = new Ei(); $ei_cl->setStartDate($ei['ei_start_date']); $ei_cl->setEndDate($ei['ei_exp_date']); $ei_cl->setChangeDate($ei['ei_chng_date']); $ei_cl->setNotes($ei['ei_serv_notes']); $ei_cl->setAuthorization($ei['ei_auth']); $ei_cl->setPhysiciansOrder($ei['ei_p_order']); // client $ei_cl->setClient(ClientPeer::getByFullName($ei['client_fn'], $ei['client_ln'])); // employee $ei_cl->setEmployee(EmployeePeer::getByFullName($ei['emp_fn'], $ei['emp_ln'])); // service $ei_cl->setService(ServicePeer::getByName($ei['service_title'])); // frequency $ei_cl->setFrequency(FrequencyPeer::getByName($ei['freq_title'])); // office $ei_cl->setIcd9(Icd9Peer::getByName($ei['icd9_value'])); $ei_cl->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // PRESCHOOL $query = 'SELECT * FROM tbl_preschool LEFT JOIN (tbl_client) ON (tbl_preschool.pre_client_id = tbl_client.client_id) LEFT JOIN (tbl_employee) ON (tbl_preschool.pre_provider_id = tbl_employee.emp_id) LEFT JOIN (tbl_services) ON (tbl_preschool.pre_service_id = tbl_services.service_id) LEFT JOIN (tbl_frequency) ON (tbl_preschool.pre_freq_id = tbl_frequency.freq_id)'; $statement = $source->prepare($query); $statement->execute(); $preschools = $statement->fetchAll(); $connection->beginTransaction(); $c = new Criteria(); $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_PRESCHOOL); try { ClientServicePeer::doDelete($c, $connection); foreach ($preschools as $preschool) { $this->logSection('preschool', 'reading service ' . $preschool['pre_id']); $pr_cl = new Preschool(); $pr_cl->setStartDate($preschool['pre_start_date']); $pr_cl->setEndDate($preschool['pre_exp_date']); $pr_cl->setChangeDate($preschool['pre_chng_date']); // client $pr_cl->setClient(ClientPeer::getByFullName($preschool['client_fn'], $preschool['client_ln'])); // employee $pr_cl->setEmployee(EmployeePeer::getByFullName($preschool['emp_fn'], $preschool['emp_ln'])); // service $pr_cl->setService(ServicePeer::getByName($preschool['service_title'])); // frequency $pr_cl->setFrequency(FrequencyPeer::getByName($preschool['freq_title'])); $pr_cl->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // SEIT $query = 'SELECT * FROM tbl_seit LEFT JOIN (tbl_client) ON (tbl_seit.seit_client_id = tbl_client.client_id) LEFT JOIN (tbl_employee) ON (tbl_seit.seit_provider_id = tbl_employee.emp_id) LEFT JOIN (tbl_services) ON (tbl_seit.seit_service_id = tbl_services.service_id) LEFT JOIN (tbl_frequency) ON (tbl_seit.seit_freq_id = tbl_frequency.freq_id)'; $statement = $source->prepare($query); $statement->execute(); $seits = $statement->fetchAll(); $connection->beginTransaction(); $c = new Criteria(); $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_SEIT); try { ClientServicePeer::doDelete($c, $connection); foreach ($seits as $seit) { $this->logSection('seit', 'reading service ' . $seit['seit_id']); $seit_cl = new Seit(); $seit_cl->setStartDate($seit['seit_start_date']); $seit_cl->setEndDate($seit['seit_exp_date']); $seit_cl->setChangeDate($seit['seit_chng_date']); $seit_cl->setNotes($seit['seit_notes']); // client $seit_cl->setClient(ClientPeer::getByFullName($seit['client_fn'], $seit['client_ln'])); // employee $seit_cl->setEmployee(EmployeePeer::getByFullName($seit['emp_fn'], $seit['emp_ln'])); // service $seit_cl->setService(ServicePeer::getByName($seit['service_title'])); // frequency $seit_cl->setFrequency(FrequencyPeer::getByName($seit['freq_title'])); $seit_cl->save($connection); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } }
protected function afterUpdate($object) { global $cookie; TaxRule::deleteByGroupId($object->id); foreach (Country::getCountries($cookie->id_lang, true) as $country) { $id_tax = (int) Tools::getValue('tax_' . $country['id_country'] . '_0'); // default country rule if (!empty($id_tax)) { $tr = new TaxRule(); $tr->id_tax_rules_group = $object->id; $tr->id_country = (int) $country['id_country']; $tr->id_state = 0; $tr->id_county = 0; $tr->id_tax = $id_tax; $tr->state_behavior = 0; $tr->county_behavior = 0; $tr->save(); } // state specific rule if (!empty($country['contains_states'])) { foreach ($country['states'] as $state) { $state_behavior = (int) Tools::getValue('behavior_state_' . $state['id_state']); if ($state_behavior != PS_PRODUCT_TAX) { $tr = new TaxRule(); $tr->id_tax_rules_group = $object->id; $tr->id_country = (int) $country['id_country']; $tr->id_state = (int) $state['id_state']; $tr->id_county = 0; $tr->id_tax = (int) Tools::getValue('tax_' . $country['id_country'] . '_' . $state['id_state']); $tr->state_behavior = $state_behavior; $tr->county_behavior = 0; $tr->save(); } // county specific rule if (State::hasCounties($state['id_state'])) { $counties = County::getCounties($state['id_state']); foreach ($counties as $county) { $county_behavior = (int) Tools::getValue('behavior_county_' . $county['id_county']); if ($county_behavior != County::USE_STATE_TAX) { $tr = new TaxRule(); $tr->id_tax_rules_group = $object->id; $tr->id_country = (int) $country['id_country']; $tr->id_state = (int) $state['id_state']; $tr->id_county = (int) $county['id_county']; $tr->id_tax = (int) Tools::getValue('tax_' . $country['id_country'] . '_' . $state['id_state'] . '_' . $county['id_county']); $tr->state_behavior = 0; $tr->county_behavior = $county_behavior; $tr->save(); } } } } } } }
public function isZipCodeRangePresent($zip_codes) { $res = false; list($from, $to) = $this->breakDownZipCode($zip_codes); if ($from == 0) { return false; } if ($to != 0) { $res = Db::getInstance()->getValue(' SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'county_zip_code` cz LEFT JOIN `' . _DB_PREFIX_ . 'county` c ON (c.`id_county` = cz.`id_county`) LEFT JOIN `' . _DB_PREFIX_ . 'state` s ON (s.`id_state` = c.`id_state`) WHERE `from_zip_code` >= ' . (int) $from . ' AND `to_zip_code` <= ' . (int) $to . ' AND s.`id_country` = (SELECT `id_country` FROM `' . _DB_PREFIX_ . 'state` s LEFT JOIN `' . _DB_PREFIX_ . 'county` c ON (c.`id_state` = s.`id_state`) WHERE `id_county` = ' . (int) $this->id . ' )'); } return $res or County::isZipCodePresent($from) or County::isZipCodePresent($to); }
public static function hasCounties($id_state) { return sizeof(County::getCounties((int) $id_state)); }
//locations //country $country_arry = Country::find_by_code($jobs->country); //$country_a($country_arry) ? $country_arry->code : $country_a; $country_var_name = $country_arry->var_name; $country_name = $country_arry->name; $smarty->assign('country', $country_name); $smarty->assign('country_url', $country_var_name); //states $state = StateProvince::find_by_code($jobs->country, $jobs->state_province); $state_name = empty($state) ? $jobs->state_province : $state->name; $state_var_name = $state ? $state->var_name : $jobs->state_province; $smarty->assign('state', $state_name); $smarty->assign('state_url', $country_var_name . "/" . $state_var_name . "/"); //county $county = County::find_by_code($jobs->country, $jobs->state_province, $jobs->county); $county_name = empty($county) ? $jobs->county : $county->name; $county_var_name = $county ? $county->var_name : $jobs->county; $smarty->assign('county', $county_name); $smarty->assign('county_url', $country_var_name . "/" . $state_var_name . "/" . $county_var_name . "/"); $city = City::find_by_code($jobs->country, $jobs->state_province, $jobs->county, $jobs->city); $city_name = empty($city) ? $jobs->city : $city->name; $city_var_name = empty($city) ? $jobs->city : $city->var_name; $smarty->assign('city', $city_name); $smarty->assign('city_url', $country_var_name . "/" . $state_var_name . "/" . $county_var_name . "/" . $city_var_name . "/"); //educations $educations = Education::find_by_id($jobs->fk_education_id); $education_name = !empty($educations) ? $educations->education_name : format_lang('not_provided'); $smarty->assign('education_var_name', $educations->var_name); $smarty->assign('education', $education_name); //career
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param County $value A County object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(County $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getFipsCode(); } // if key === null self::$instances[$key] = $obj; } }
$job_types = $job_type_arr ? $job_type_arr->type_name : format_lang('none'); $smarty->assign('job_type', $job_types); //where do you wont to work //country $country_arry = Country::find_by_code($cv_details->country); $country_var_name = $country_arry->var_name; $country_name = $country_arry->name; $smarty->assign('country', $country_name); //states $state = StateProvince::find_by_code($cv_details->country, $cv_details->state_province); $state_name = empty($state) ? $cv_details->state_province : $state->name; $state_var_name = $state ? $state->var_name : $cv_details->state_province; $smarty->assign('state', $state_name); $smarty->assign('state_url', $country_var_name . "/" . $state_var_name . "/"); //county $county = County::find_by_code($cv_details->country, $cv_details->state_province, $cv_details->county); $county_name = empty($county) ? $cv_details->county : $county->name; $county_var_name = $county ? $county->var_name : $cv_details->county; $smarty->assign('county', $county_name); $smarty->assign('county_url', $country_var_name . "/" . $state_var_name . "/" . $county_var_name . "/"); $city = City::find_by_code($cv_details->country, $cv_details->state_province, $cv_details->county, $cv_details->city); $city_name = empty($city) ? $cv_details->city : $city->name; $city_var_name = empty($city) ? $cv_details->city : $city->var_name; $smarty->assign('city', $city_name); $smarty->assign('city_url', $country_var_name . "/" . $state_var_name . "/" . $county_var_name . "/" . $city_var_name . "/"); //end of location $authorised_to_work = format_lang('select', 'authorised_to_work'); $aya = !empty($cv_details->are_you_auth) ? $authorised_to_work[$cv_details->are_you_auth] : format_lang('none'); $smarty->assign('aya', $aya); $wtr = !empty($cv_details->willing_to_relocate) ? $get_NoYes[$cv_details->willing_to_relocate] : format_lang('none'); $smarty->assign('wtr', $wtr);
?> "> </div> <div class="form-group"> <label for="aelocationcity">City / Town</label> <input type="text" name="city" class="form-control" id="locationcity" maxlength="50" value="<?php echo isset($city) ? $city : ''; ?> " required> </div> <div class="form-group pull-left" style="width: 47%;"> <label for="locationcountystate">County/Region, State</label> <select class="form-control" id="locationcountystate" name="countyid"> <option></option> <?php $counties = County::getAll(); foreach ($counties as $countyrow) { $countyrowid = $countyrow['id']; $countyrowname = $countyrow['name']; $countyrowstatecd = $countyrow['statecd']; ?> <option value="<?php echo $countyrowid; ?> " <?php echo !empty($countyid) && $countyrowid == $countyid ? 'selected' : ''; ?> ><?php echo $countyrowname . ', ' . $countyrowstatecd; ?> </option>
public static function recommendedJob($user_id = 0, $cvjob_title = null, $cvjob_title2 = null, $cvjob_city = null, $cvjob_county = null, $cvjob_state = null, $cvjob_country = null) { global $database, $db; $select = " SELECT job_title, city, county, state_province, country, fk_employer_id,var_name, created_at "; $select .= ", match( job.job_title, job.job_description ) against ('" . $cvjob_title . "' '+" . $cvjob_title2 . "' IN BOOLEAN MODE) as relevance "; $from = " FROM " . self::$table_name . " AS job "; $where = " WHERE job.id NOT IN ( SELECT job_h.fk_job_id from " . TBL_HISTORY . " as job_h WHERE job_h.fk_employee_id={$user_id}) "; $where .= " AND job.is_active='Y' AND job.job_status='approved' AND job.id > 0 "; //$where .= " AND var_name <> '".$old."' "; $where .= " AND match( job.job_title, job.job_description ) against ('" . $cvjob_title . "' '+" . $cvjob_title2 . "' IN BOOLEAN MODE)"; $where .= " AND DATE_ADD( job.created_at, INTERVAL " . JOBLASTFOR . " DAY ) > NOW() "; //$where .= " AND city='{$cvjob_city}' "; $where .= " AND county='{$cvjob_county}' "; $where .= " AND state_province='{$cvjob_state}'"; $where .= " AND country='{$cvjob_country}'"; $order = " ORDER BY relevance, created_at DESC "; $limit = " LIMIT 10 "; //SELECT job.job_title, job.city, job.county, job.state_province, job.country //FROM jobberland_job AS job //WHERE job.id NOT IN (SELECT job_h.fk_job_id from jobberland_job_history as job_h WHERE fk_employer_id = 1) $sql = $select . $from . $where . $order . $limit; //echo $sql; $result = $database->query($sql); $num_rows = $database->num_rows($result); if ($num_rows > 0) { $i = 1; $temp = array(); while ($row = $database->fetch_object($result)) { $temp[$i]['job_title'] = $row->job_title; $temp[$i]['var_name'] = $row->var_name; $temp[$i]['created_at'] = strftime(DATE_FORMAT, strtotime($row->created_at)); //country $country_arry = Country::find_by_code($row->country); $country_name = $country_arry->name; //states $state = StateProvince::find_by_code($row->country, $row->state_province); $state_name = empty($state) ? $row->state_province : $state->name; //county $county = County::find_by_code($row->country, $row->state_province, $row->county); $county_name = empty($county) ? $row->county : $county->name; //city $city = City::find_by_code($row->country, $row->state_province, $row->county, $row->city); $city_name = empty($city) ? $row->city : $city->name; $temp[$i]['location'] = $city_name . ", " . $county_name . ", " . $state_name . ", " . $country_name; $employer = Employer::find_by_id($row->fk_employer_id); $company_name = $employer->company_name; $temp[$i]['company_name'] = $company_name; //$temp[$i]['job_title'] = $row->job_title; //$temp[$i]['job_title'] = $row->job_title; $i++; } return $temp; } return false; }
public static function getCountie() { $counties = DB::table('counties')->get(); foreach (County::all() as $county) { $counties = $county->name; } return $counties; }
//IT Manager at IT Lab in London EC1A 9PT if ($jobs) { $job_s = array(); $i = 1; $job_suggestions = Job::apply_suggestion($jobs->job_title, $var_name); foreach ($job_suggestions as $job_suggestion) { $employer = Employer::find_by_id($job_suggestion->fk_employer_id); //locations //country $country_arry = Country::find_by_code($job_suggestion->country); $country_name = $country_arry->name; //states $state = StateProvince::find_by_code($job_suggestion->country, $job_suggestion->state_province); $state_name = empty($state) ? $job_suggestion->state_province : $state->name; //county $county = County::find_by_code($job_suggestion->country, $job_suggestion->state_province, $job_suggestion->county); $county_name = empty($county) ? $job_suggestion->county : $county->name; //city $city = City::find_by_code($job_suggestion->country, $job_suggestion->state_province, $job_suggestion->county, $job_suggestion->city); $city_name = empty($city) ? $job_suggestion->city : $city->name; //end $job_s[$i]['id'] = $job_suggestion->id; $job_s[$i]['var_name'] = $job_suggestion->var_name; $job_s[$i]['job_title'] = $job_suggestion->job_title; $job_s[$i]['company_name'] = $employer->company_name; $job_s[$i]['created_at'] = strftime(DATE_FORMAT, strtotime($job_suggestion->created_at)); $job_s[$i]['location'] = $city_name . ", " . $county_name . ", " . $state_name . ", " . $country_name; $i++; } $smarty->assign('job_suggestion', $job_s); }
//location/// $default_county = empty($_SESSION['loc']['country']) ? DEFAULT_COUNTRY : $_SESSION['loc']['country']; $_SESSION['loc']['country'] = $countrycode = $default_county = $default_county; $country = Country::find_all_order_by_name(); if (is_array($country) && !empty($country)) { $country_t = array(); $country_t['AA'] = 'All Countries'; foreach ($country as $co) { if ($val['code'] != 'AA') { $country_t[$co->code] = $co->name; } } $smarty->assign('country', $country_t); } $state = new StateProvince(); $county = new County(); $city = new City(); $lang['states'] = $state->get_stateOptions($countrycode, 'Y'); if (count($lang['states']) == 1) { foreach ($lang['states'] as $key => $val) { $_SESSION['add_job']['state'] = $key; } } //status $_SESSION['add_job']['state'] = $_SESSION['add_job']['state'] != '' ? $_SESSION['add_job']['state'] : ""; if ($_SESSION['add_job']['state'] != '') { $lang['counties'] = $county->get_countyOptions($countrycode, $_SESSION['add_job']['state'], 'N'); if (count($lang['counties']) == 1) { foreach ($lang['counties'] as $key => $val) { $_SESSION['add_job']['county'] = $key; }
/** * Get product price * * @param integer $id_product Product id * @param boolean $usetax With taxes or not (optional) * @param integer $id_product_attribute Product attribute id (optional). If set to false, do not apply the combination price impact. NULL does apply the default combination price impact. * @param integer $decimals Number of decimals (optional) * @param integer $divisor Useful when paying many time without fees (optional) * @param boolean $only_reduc Returns only the reduction amount * @param boolean $usereduc Set if the returned amount will include reduction * @param integer $quantity Required for quantity discount application (default value: 1) * @param boolean $forceAssociatedTax DEPRECATED - NOT USED Force to apply the associated tax. Only works when the parameter $usetax is true * @param integer $id_customer Customer ID (for customer group reduction) * @param integer $id_cart Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...) * @param integer $id_address Customer address ID. Required for price (tax included) calculation regarding the guest localization * @param variable_reference $specificPriceOutput. If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object * @param boolean $with_ecotax insert ecotax in price output. * @return float Product price */ public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = false, $id_customer = null, $id_cart = null, $id_address = null, &$specificPriceOutput = null, $with_ecotax = true, $use_groupReduction = true) { global $cookie, $cart; $cur_cart = $cart; if (isset($divisor)) { Tools::displayParameterAsDeprecated('divisor'); } if ((int) $id_product <= 0) { die(Tools::displayError()); } // Initializations if (!$id_customer) { $id_customer = Validate::isCookie($cookie) && isset($cookie->id_customer) && $cookie->id_customer ? (int) $cookie->id_customer : null; } $id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; if (!is_object($cur_cart) && !$id_cart && !Validate::isCookie($cookie)) { die(Tools::displayError()); } /* * When a user (e.g., guest, customer, Google...) is on PrestaShop, he has already its cart as the global (see /init.php) * When a non-user calls directly this method (e.g., payment module...) is on PrestaShop, he does not have already it BUT knows the cart ID */ if (!is_object($cur_cart) && ((int) $id_cart > 0 || Validate::isCookie($cookie) && $cookie->id_cart)) { $cur_cart = $id_cart ? new Cart((int) $id_cart) : new Cart((int) $cookie->id_cart); } $cart_quantity = 0; if ((int) $id_cart) { $calc_qty_discounts_with_combinations = (int) Configuration::get('PS_QTY_DISCOUNT_ON_COMBINATION'); $cache_name = (int) $id_cart . '_' . (int) $id_product . ($calc_qty_discounts_with_combinations ? '_' . (int) $id_product_attribute : ''); if (!isset(self::$_cart_quantity) || !count(self::$_cart_quantity) || !isset(self::$_cart_quantity[$cache_name])) { $quantities = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT id_product, ' . ($calc_qty_discounts_with_combinations ? 'id_product_attribute, quantity' : 'SUM(`quantity`) quantity') . ' FROM `' . _DB_PREFIX_ . 'cart_product` WHERE `id_cart` = ' . (int) $id_cart . ' ' . ($calc_qty_discounts_with_combinations ? ', id_product_attribute' : ' GROUP BY id_product'), false); while ($row = DB::getInstance()->nextRow($quantities)) { self::$_cart_quantity[(int) $id_cart . '_' . (int) $row['id_product'] . ($calc_qty_discounts_with_combinations ? '_' . (int) $row['id_product_attribute'] : '')] = $row['quantity']; } } $cart_quantity = self::$_cart_quantity[$cache_name]; } $quantity = $id_cart && $cart_quantity ? $cart_quantity : $quantity; $id_currency = (int) (Validate::isLoadedObject($cur_cart) ? $cur_cart->id_currency : (isset($cookie->id_currency) && (int) $cookie->id_currency ? $cookie->id_currency : _PS_CURRENCY_DEFAULT_)); // retrieve address informations $id_state = 0; $id_county = 0; if (!$id_address && Validate::isLoadedObject($cur_cart)) { $id_address = $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; } if ($id_address) { $address_infos = Address::getCountryAndState((int) $id_address); if ($address_infos['id_country']) { $id_country = (int) $address_infos['id_country']; $id_state = (int) $address_infos['id_state']; $postcode = (int) $address_infos['postcode']; $id_county = (int) County::getIdCountyByZipCode((int) $id_state, $postcode); } } elseif (isset($cookie->id_country)) { // fetch address from cookie $id_country = (int) $cookie->id_country; $id_state = (int) $cookie->id_state; $postcode = (int) $cookie->postcode; $id_county = (int) County::getIdCountyByZipCode((int) $id_state, $postcode); } if (!isset($id_country)) { $id_country = (int) Country::getDefaultCountryId(); } if (!_PS_TAX_ || $usetax != false && !empty($address_infos['vat_number']) && $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') && Configuration::get('VATNUMBER_MANAGEMENT')) { $usetax = false; } return Product::priceCalculation(0, $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $usetax, $decimals, $only_reduc, $usereduc, $with_ecotax, $specificPriceOutput, $use_groupReduction); }
$county->countrycode = $countrycode; $county->code = trim($data[0]); $county->var_name = $county->mod_write_check(trim($data[1])); $county->name = trim($data[1]); $county->statecode = trim($data[2]); $save = $county->save(); } fclose($file); $message = "<div class='success'>County codes loaded from " . $filename . " </div>"; $session->message($message); redirect_to($_SERVER['PHP_SELF']); } //delete all the countys from list if (isset($_POST['deletecounty'])) { global $db, $database; $county = new County(); $county->delete_by_country($countrycode); /* We should remove the county definition from counties, cities and zips tables also for this country */ //$db->query("update ".TBL_COUNTIES." set statecode='' where countrycode='$countrycode' "); $db->query("update " . TBL_CITY . " set countycode='' where countrycode='{$countrycode}' "); $message = "<div class='success'>County codes for #COUNTRY# are deleted </div>"; $message = str_replace('#COUNTRY#', $countrycode, $message); /* Analyze the table to adjust index values */ //$db->optimize_table( TBL_COUNTRY ); $db->optimize_table(TBL_STATES); $db->optimize_table(TBL_COUNTIES); $db->optimize_table(TBL_CITY); $session->message($message); redirect_to($_SERVER['PHP_SELF']); } //get the states files
$default_county = $_SESSION['loc']['country']; $countrycode = $default_county = !empty($default_county) ? $default_county : "GB"; $_SESSION['loc']['country'] = $countrycode = $default_county = !empty($default_county) ? $default_county : "GB"; $country = Country::find_all_order_by_name(); if (is_array($country) && !empty($country)) { $country_t = array(); $country_t['AA'] = 'All Countries'; foreach ($country as $co) { if ($val['code'] != 'AA') { $country_t[$co->code] = $co->name; } } $smarty->assign('country', $country_t); } $state = new StateProvince(); $county = new County(); $city = new City(); $lang['states'] = $state->get_stateOptions($countrycode, 'N'); if (count($lang['states']) == 1) { foreach ($lang['states'] as $key => $val) { $_SESSION['loc']['stateprovince'] = $key; } } //status $_SESSION['loc']['stateprovince'] = $_SESSION['loc']['stateprovince'] != '' ? $_SESSION['loc']['stateprovince'] : ""; if ($_SESSION['loc']['stateprovince'] != '') { $lang['counties'] = $county->get_countyOptions($countrycode, $_SESSION['loc']['stateprovince'], 'N'); if (count($lang['counties']) == 1) { foreach ($lang['counties'] as $key => $val) { $_SESSION['loc']['countycode'] = $key; }
public static function getCarrierTaxRate($id_carrier, $id_address = NULL) { $id_country = (int) Country::getDefaultCountryId(); $id_state = 0; $id_county = 0; if (!empty($id_address)) { $address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) { $id_country = (int) $address_infos['id_country']; $id_state = (int) $address_infos['id_state']; $id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']); } if (!empty($address_infos['vat_number']) and $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') and Configuration::get('VATNUMBER_MANAGEMENT')) { return 0; } } return TaxRulesGroup::getTaxesRate((int) Carrier::getIdTaxRulesGroupByIdCarrier((int) $id_carrier), (int) $id_country, (int) $id_state, (int) $id_county); }
/** * Get product price * * @param integer $id_product Product id * @param boolean $usetax With taxes or not (optional) * @param integer $id_product_attribute Product attribute id (optional). If set to false, do not apply the combination price impact. NULL does apply the default combination price impact. * @param integer $decimals Number of decimals (optional) * @param integer $divisor Useful when paying many time without fees (optional) * @param boolean $only_reduc Returns only the reduction amount * @param boolean $usereduc Set if the returned amount will include reduction * @param integer $quantity Required for quantity discount application (default value: 1) * @param boolean $forceAssociatedTax DEPRECATED - NOT USED Force to apply the associated tax. Only works when the parameter $usetax is true * @param integer $id_customer Customer ID (for customer group reduction) * @param integer $id_cart Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...) * @param integer $id_address Customer address ID. Required for price (tax included) calculation regarding the guest localization * @param variable_reference $specificPriceOutput. If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object * @param boolean $with_ecotax insert ecotax in price output. * @return float Product price */ public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = NULL, $decimals = 6, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = false, $id_customer = NULL, $id_cart = NULL, $id_address = NULL, &$specificPriceOutput = NULL, $with_ecotax = true, $use_groupReduction = true) { global $cookie, $cart; $cur_cart = $cart; if (isset($divisor)) { Tools::displayParameterAsDeprecated('divisor'); } if (!Validate::isBool($usetax) or !Validate::isUnsignedId($id_product)) { die(Tools::displayError()); } // Initializations if (!$id_customer) { $id_customer = (Validate::isCookie($cookie) and isset($cookie->id_customer) and $cookie->id_customer) ? (int) $cookie->id_customer : NULL; } $id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; if (!is_object($cur_cart) or Validate::isUnsignedInt($id_cart) and $id_cart) { /* * When a user (e.g., guest, customer, Google...) is on PrestaShop, he has already its cart as the global (see /init.php) * When a non-user calls directly this method (e.g., payment module...) is on PrestaShop, he does not have already it BUT knows the cart ID */ if (!$id_cart and !Validate::isCookie($cookie)) { die(Tools::displayError()); } $cur_cart = $id_cart ? new Cart((int) $id_cart) : new Cart((int) $cookie->id_cart); } $cart_quantity = 0; if ((int) $id_cart) { $condition = ''; $cache_name = (int) $id_cart . '_' . (int) $id_product; if (Configuration::get('PS_QTY_DISCOUNT_ON_COMBINATION')) { $cache_name = (int) $id_cart . '_' . (int) $id_product . '_' . (int) $id_product_attribute; $condition = ' AND `id_product_attribute` = ' . (int) $id_product_attribute; } if (!isset(self::$_cart_quantity[$cache_name]) or self::$_cart_quantity[$cache_name] != (int) $quantity) { self::$_cart_quantity[$cache_name] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT SUM(`quantity`) FROM `' . _DB_PREFIX_ . 'cart_product` WHERE `id_product` = ' . (int) $id_product . ' AND `id_cart` = ' . (int) $id_cart . ' ' . $condition); $cart_quantity = self::$_cart_quantity[$cache_name]; } } $quantity = ($id_cart and $cart_quantity) ? $cart_quantity : $quantity; $id_currency = (int) (Validate::isLoadedObject($cur_cart) ? $cur_cart->id_currency : ((isset($cookie->id_currency) and (int) $cookie->id_currency) ? $cookie->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))); // retrieve address informations $id_country = (int) Country::getDefaultCountryId(); $id_state = 0; $id_county = 0; if (!$id_address) { $id_address = $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; } if ($id_address) { $address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) { $id_country = (int) $address_infos['id_country']; $id_state = (int) $address_infos['id_state']; $postcode = (int) $address_infos['postcode']; $id_county = (int) County::getIdCountyByZipCode($id_state, $postcode); } } elseif (isset($cookie->id_country)) { // fetch address from cookie $id_country = (int) $cookie->id_country; $id_state = (int) $cookie->id_state; $postcode = (int) $cookie->postcode; $id_county = (int) County::getIdCountyByZipCode($id_state, $postcode); } if (Tax::excludeTaxeOption()) { $usetax = false; } if ($usetax != false and !empty($address_infos['vat_number']) and $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') and Configuration::get('VATNUMBER_MANAGEMENT')) { $usetax = false; } $id_shop = (int) Shop::getCurrentShop(); return Product::priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $usetax, $decimals, $only_reduc, $usereduc, $with_ecotax, $specificPriceOutput, $use_groupReduction); }
/** * Validate an order in database * Function called from a payment module * * @param integer $id_cart Value * @param integer $id_order_state Value * @param float $amountPaid Amount really paid by customer (in the default currency) * @param string $paymentMethod Payment method (eg. 'Credit card') * @param string $message Message to attach to order */ public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $secure_key = false) { global $cart; $cart = new Cart((int) $id_cart); // Does order already exists ? if (!$this->active) { die(Tools::displayError()); } if (Validate::isLoadedObject($cart) && $cart->OrderExists() == false) { if ($secure_key !== false && $secure_key != $cart->secure_key) { die(Tools::displayError()); } // Copying data from cart $order = new Order(); $order->id_carrier = (int) $cart->id_carrier; $order->id_customer = (int) $cart->id_customer; $order->id_address_invoice = (int) $cart->id_address_invoice; $order->id_address_delivery = (int) $cart->id_address_delivery; $vat_address = new Address((int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $order->id_currency = $currency_special ? (int) $currency_special : (int) $cart->id_currency; $order->id_lang = (int) $cart->id_lang; $order->id_cart = (int) $cart->id; $customer = new Customer((int) $order->id_customer); $order->secure_key = $secure_key ? pSQL($secure_key) : pSQL($customer->secure_key); $order->payment = $paymentMethod; if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $cart->recyclable; $order->gift = (int) $cart->gift; $order->gift_message = $cart->gift_message; $currency = new Currency($order->id_currency); $order->conversion_rate = $currency->conversion_rate; $amountPaid = !$dont_touch_amount ? Tools::ps_round((double) $amountPaid, 2) : $amountPaid; $order->total_paid_real = $amountPaid; $order->total_products = (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS); $order->total_products_wt = (double) $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $order->total_discounts = (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS)); $order->total_shipping = (double) $cart->getOrderShippingCost(); $order->carrier_tax_rate = (double) Tax::getCarrierTaxRate($cart->id_carrier, (int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $order->total_wrapping = (double) abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING)); $order->total_paid = (double) Tools::ps_round((double) $cart->getOrderTotal(true, Cart::BOTH), 2); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; // Amount paid by customer is not the right one -> Status = payment error // We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php // if ($order->total_paid != $order->total_paid_real) // We use number_format in order to compare two string if (number_format($order->total_paid, 2) != number_format($order->total_paid_real, 2)) { $id_order_state = Configuration::get('PS_OS_ERROR'); } // Creating order if ($cart->OrderExists() == false) { $result = $order->add(); } else { $errorMessage = Tools::displayError('An order has already been placed using this cart.'); Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($order->id_cart)); die($errorMessage); } // Next ! if ($result and isset($order->id)) { if (!$secure_key) { $message .= $this->l('Warning : the secure key is empty, check your payment account before validation'); } // Optional message to attach to this order if (isset($message) and !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (Validate::isCleanHtml($message)) { $msg->message = $message; $msg->id_order = intval($order->id); $msg->private = 1; $msg->add(); } } // Insert products from cart into order_detail table $products = $cart->getProducts(); $productsList = ''; $db = Db::getInstance(); $query = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail` (`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `reduction_percent`, `reduction_amount`, `group_reduction`, `product_quantity_discount`, `product_ean13`, `product_upc`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `ecotax_tax_rate`, `discount_quantity_applied`, `download_deadline`, `download_hash`) VALUES '; $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $outOfStock = false; $store_all_taxes = array(); foreach ($products as $key => $product) { $productQuantity = (int) Product::getQuantity((int) $product['id_product'], $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL); $quantityInStock = $productQuantity - (int) $product['cart_quantity'] < 0 ? $productQuantity : (int) $product['cart_quantity']; if ($id_order_state != Configuration::get('PS_OS_CANCELED') and $id_order_state != Configuration::get('PS_OS_ERROR')) { if (Product::updateQuantity($product, (int) $order->id)) { $product['stock_quantity'] -= $product['cart_quantity']; } if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) { $outOfStock = true; } Product::updateDefaultAttribute($product['id_product']); } $price = Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 6, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $price_wt = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 2, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); /* Store tax info */ $id_country = (int) Country::getDefaultCountryId(); $id_state = 0; $id_county = 0; $rate = 0; $id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) { $id_country = (int) $address_infos['id_country']; $id_state = (int) $address_infos['id_state']; $id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']); } $allTaxes = TaxRulesGroup::getTaxes((int) Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product']), $id_country, $id_state, $id_county); // If its a freeOrder, there will be no calculation if ($order->total_products > 0) { // remove order discount quotepart on product price in order to obtain the real tax $ratio = $price / $order->total_products; $order_reduction_amount = (double) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS)) * $ratio; $tmp_price = $price - $order_reduction_amount; foreach ($allTaxes as $res) { if (!isset($store_all_taxes[$res->id])) { $store_all_taxes[$res->id] = array(); $store_all_taxes[$res->id]['amount'] = 0; } $store_all_taxes[$res->id]['name'] = $res->name[(int) $order->id_lang]; $store_all_taxes[$res->id]['rate'] = $res->rate; $unit_tax_amount = $tmp_price * ($res->rate * 0.01); $tmp_price = $tmp_price + $unit_tax_amount; $store_all_taxes[$res->id]['amount'] += $unit_tax_amount * $product['cart_quantity']; } } /* End */ // Add some informations for virtual products $deadline = '0000-00-00 00:00:00'; $download_hash = null; if ($id_product_download = ProductDownload::getIdFromIdProduct((int) $product['id_product'])) { $productDownload = new ProductDownload((int) $id_product_download); $deadline = $productDownload->getDeadLine(); $download_hash = $productDownload->getHash(); } // Exclude VAT if (!_PS_TAX_) { $product['tax'] = 0; $product['rate'] = 0; $tax_rate = 0; } else { $tax_rate = Tax::getProductTaxRate((int) $product['id_product'], $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } $ecotaxTaxRate = 0; if (!empty($product['ecotax'])) { $ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } $product_price = (double) Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specificPrice, false, false); $group_reduction = (double) GroupReduction::getValueForProduct((int) $product['id_product'], $customer->id_default_group) * 100; if (!$group_reduction) { $group_reduction = (double) Group::getReduction((int) $order->id_customer); } $quantityDiscount = SpecificPrice::getQuantityDiscount((int) $product['id_product'], Shop::getCurrentShop(), (int) $cart->id_currency, (int) $vat_address->id_country, (int) $customer->id_default_group, (int) $product['cart_quantity']); $unitPrice = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, 1, false, (int) $order->id_customer, NULL, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $quantityDiscountValue = $quantityDiscount ? (Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100) : 0.0; $query .= '(' . (int) $order->id . ', ' . (int) $product['id_product'] . ', ' . (isset($product['id_product_attribute']) ? (int) $product['id_product_attribute'] : 'NULL') . ', \'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\', ' . (int) $product['cart_quantity'] . ', ' . $quantityInStock . ', ' . $product_price . ', ' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.0) . ', ' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'amount') ? !$specificPrice['id_currency'] ? Tools::convertPrice($specificPrice['reduction'], $order->id_currency) : $specificPrice['reduction'] : 0.0) . ', ' . $group_reduction . ', ' . $quantityDiscountValue . ', ' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ', ' . (empty($product['upc']) ? 'NULL' : '\'' . pSQL($product['upc']) . '\'') . ', ' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ', ' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ', ' . (double) ($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ', \'' . (empty($tax_rate) ? '' : pSQL($product['tax'])) . '\', ' . (double) $tax_rate . ', ' . (double) Tools::convertPrice(floatval($product['ecotax']), intval($order->id_currency)) . ', ' . (double) $ecotaxTaxRate . ', ' . (($specificPrice and $specificPrice['from_quantity'] > 1) ? 1 : 0) . ', \'' . pSQL($deadline) . '\', \'' . pSQL($download_hash) . '\'),'; $customizationQuantity = 0; if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) { $customizationText = ''; foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] as $customization) { if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) { foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) { $customizationText .= $text['name'] . ':' . ' ' . $text['value'] . '<br />'; } } if (isset($customization['datas'][_CUSTOMIZE_FILE_])) { $customizationText .= count($customization['datas'][_CUSTOMIZE_FILE_]) . ' ' . Tools::displayError('image(s)') . '<br />'; } $customizationText .= '---<br />'; } $customizationText = rtrim($customizationText, '---<br />'); $customizationQuantity = (int) $product['customizationQuantityTotal']; $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding: 0.6em 0.4em;">' . (isset($product['reference']) && !empty($product['reference']) ? $product['reference'] : ' ') . '</td> <td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : '') . ' - ' . $this->l('Customized') . (!empty($customizationText) ? ' - ' . $customizationText : '') . '</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt, $currency, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . $customizationQuantity . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt), $currency, false) . '</td> </tr>'; } if (!$customizationQuantity or (int) $product['cart_quantity'] > $customizationQuantity) { $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding: 0.6em 0.4em;">' . (isset($product['reference']) && !empty($product['reference']) ? $product['reference'] : ' ') . '</td> <td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : '') . '</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt, $currency, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . ((int) $product['cart_quantity'] - $customizationQuantity) . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(((int) $product['cart_quantity'] - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt), $currency, false) . '</td> </tr>'; } } // end foreach ($products) $query = rtrim($query, ','); $result = $db->Execute($query); /* Add carrier tax */ $shippingCostTaxExcl = $cart->getOrderShippingCost((int) $order->id_carrier, false); $allTaxes = TaxRulesGroup::getTaxes((int) Carrier::getIdTaxRulesGroupByIdCarrier((int) $order->id_carrier), $id_country, $id_state, $id_county); $nTax = 0; foreach ($allTaxes as $tax) { if (!isset($tax->id)) { continue; } if (!isset($store_all_taxes[$tax->id])) { $store_all_taxes[$tax->id] = array(); } if (!isset($store_all_taxes[$tax->id]['amount'])) { $store_all_taxes[$tax->id]['amount'] = 0; } $store_all_taxes[$tax->id]['name'] = $tax->name[(int) $order->id_lang]; $store_all_taxes[$tax->id]['rate'] = $tax->rate; if (!$nTax++) { $store_all_taxes[$tax->id]['amount'] += $shippingCostTaxExcl * (1 + $tax->rate * 0.01) - $shippingCostTaxExcl; } else { $store_all_taxes[$tax->id]['amount'] += $order->total_shipping - $order->total_shipping / (1 + $tax->rate * 0.01); } } /* Store taxes */ foreach ($store_all_taxes as $tax) { Db::getInstance()->Execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_tax` (`id_order`, `tax_name`, `tax_rate`, `amount`) VALUES (' . (int) $order->id . ', \'' . pSQL($tax['name']) . '\', ' . (double) $tax['rate'] . ', ' . (double) $tax['amount'] . ')'); } // Insert discounts from cart into order_discount table $discounts = $cart->getDiscounts(); $discountsList = ''; $total_discount_value = 0; $shrunk = false; foreach ($discounts as $discount) { $objDiscount = new Discount((int) $discount['id_discount']); $value = $objDiscount->getValue(count($discounts), $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $order->total_shipping, $cart->id); if ($objDiscount->id_discount_type == 2 and in_array($objDiscount->behavior_not_exhausted, array(1, 2))) { $shrunk = true; } if ($shrunk and $total_discount_value + $value > $order->total_products_wt + $order->total_shipping + $order->total_wrapping) { $amount_to_add = $order->total_products_wt + $order->total_shipping + $order->total_wrapping - $total_discount_value; if ($objDiscount->id_discount_type == 2 and $objDiscount->behavior_not_exhausted == 2) { $voucher = new Discount(); foreach ($objDiscount as $key => $discountValue) { $voucher->{$key} = $discountValue; } $voucher->name = 'VSRK' . (int) $order->id_customer . 'O' . (int) $order->id; $voucher->value = (double) $value - $amount_to_add; $voucher->add(); $params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false); $params['{voucher_num}'] = $voucher->name; $params['{firstname}'] = $customer->firstname; $params['{lastname}'] = $customer->lastname; $params['{id_order}'] = $order->id; $params['{order_name}'] = sprintf("#%06d", (int) $order->id); @Mail::Send((int) $order->id_lang, 'voucher', Mail::l('New voucher regarding your order #', (int) $order->id_lang) . sprintf("%06d", (int) $order->id), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname); } } else { $amount_to_add = $value; } $order->addDiscount($objDiscount->id, $objDiscount->name, $amount_to_add); $total_discount_value += $amount_to_add; if ($id_order_state != Configuration::get('PS_OS_ERROR') and $id_order_state != Configuration::get('PS_OS_CANCELED')) { $objDiscount->quantity = $objDiscount->quantity - 1; } $objDiscount->update(); $discountsList .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . ($value != 0.0 ? '-' : '') . Tools::displayPrice($value, $currency, false) . '</td> </tr>'; } // Specify order id for message $oldMessage = Message::getMessageByCartId((int) $cart->id); if ($oldMessage) { $message = new Message((int) $oldMessage['id_message']); $message->id_order = (int) $order->id; $message->update(); } // Hook new order $orderStatus = new OrderState((int) $id_order_state, (int) $order->id_lang); if (Validate::isLoadedObject($orderStatus)) { Hook::newOrder($cart, $order, $customer, $currency, $orderStatus); foreach ($cart->getProducts() as $product) { if ($orderStatus->logable) { ProductSale::addProductSale((int) $product['id_product'], (int) $product['cart_quantity']); } } } if (isset($outOfStock) && $outOfStock && Configuration::get('PS_STOCK_MANAGEMENT')) { $history = new OrderHistory(); $history->id_order = (int) $order->id; $history->changeIdOrderState(Configuration::get('PS_OS_OUTOFSTOCK'), (int) $order->id); $history->addWithemail(); } // Set order state in order history ONLY even if the "out of stock" status has not been yet reached // So you migth have two order states $new_history = new OrderHistory(); $new_history->id_order = (int) $order->id; $new_history->changeIdOrderState((int) $id_order_state, (int) $order->id); $new_history->addWithemail(true, $extraVars); // Order is reloaded because the status just changed $order = new Order($order->id); // Send an e-mail to customer if ($id_order_state != Configuration::get('PS_OS_ERROR') and $id_order_state != Configuration::get('PS_OS_CANCELED') and $customer->id) { $invoice = new Address((int) $order->id_address_invoice); $delivery = new Address((int) $order->id_address_delivery); $carrier = new Carrier((int) $order->id_carrier, $order->id_lang); $delivery_state = $delivery->id_state ? new State((int) $delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State((int) $invoice->id_state) : false; $data = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => $this->_getFormatedAddress($delivery, "<br />", array('firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')), '{invoice_block_html}' => $this->_getFormatedAddress($invoice, "<br />", array('firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_vat_number}' => $invoice->vat_number, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => sprintf("#%06d", (int) $order->id), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), (int) $order->id_lang, 1), '{carrier}' => $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false)); if (is_array($extraVars)) { $data = array_merge($data, $extraVars); } // Join PDF invoice if ((int) Configuration::get('PS_INVOICE') and Validate::isLoadedObject($orderStatus) and $orderStatus->invoice and $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', (int) $order->id_lang) . sprintf('%06d', $order->invoice_number) . '.pdf'; $fileAttachment['mime'] = 'application/pdf'; } else { $fileAttachment = null; } if (Validate::isEmail($customer->email)) { Mail::Send((int) $order->id_lang, 'order_conf', Mail::l('Order confirmation', (int) $order->id_lang), $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, $fileAttachment); } } $this->currentOrder = (int) $order->id; return true; } else { $errorMessage = Tools::displayError('Order creation failed'); Logger::addLog($errorMessage, 4, '0000002', 'Cart', intval($order->id_cart)); die($errorMessage); } } else { $errorMessage = Tools::displayError('Cart cannot be loaded or an order has already been placed using this cart'); Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id)); die($errorMessage); } }
protected function _installTaxes($xml) { if (isset($xml->taxes->tax)) { $available_behavior = array(PS_PRODUCT_TAX, PS_STATE_TAX, PS_BOTH_TAX); $assoc_taxes = array(); foreach ($xml->taxes->tax as $taxData) { $attributes = $taxData->attributes(); if (Tax::getTaxIdByName($attributes['name'])) { continue; } $tax = new Tax(); $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = strval($attributes['name']); $tax->rate = (double) $attributes['rate']; $tax->active = 1; if (!$tax->validateFields()) { $this->_errors[] = Tools::displayError('Invalid tax properties.'); return false; } if (!$tax->add()) { $this->_errors[] = Tools::displayError('An error occurred while importing the tax: ') . strval($attributes['name']); return false; } $assoc_taxes[(int) $attributes['id']] = $tax->id; } foreach ($xml->taxes->taxRulesGroup as $group) { $group_attributes = $group->attributes(); if (!Validate::isGenericName($group_attributes['name'])) { continue; } if (TaxRulesGroup::getIdByName($group['name'])) { continue; } $trg = new TaxRulesGroup(); $trg->name = $group['name']; $trg->active = 1; if (!$trg->save()) { $this->_errors = Tools::displayError('This tax rule cannot be saved.'); return false; } foreach ($group->taxRule as $rule) { $rule_attributes = $rule->attributes(); // Validation if (!isset($rule_attributes['iso_code_country'])) { continue; } $id_country = Country::getByIso(strtoupper($rule_attributes['iso_code_country'])); if (!$id_country) { continue; } if (!isset($rule_attributes['id_tax']) || !array_key_exists(strval($rule_attributes['id_tax']), $assoc_taxes)) { continue; } // Default values $id_state = (int) isset($rule_attributes['iso_code_state']) ? State::getIdByIso(strtoupper($rule_attributes['iso_code_state'])) : 0; $id_county = 0; $state_behavior = 0; $county_behavior = 0; if ($id_state) { if (isset($rule_attributes['state_behavior']) && in_array($rule_attributes['state_behavior'], $available_behavior)) { $state_behavior = (int) $rule_attributes['state_behavior']; } if (isset($rule_attributes['county_name'])) { $id_county = County::getIdCountyByNameAndIdState($rule_attributes['county_name'], (int) $id_state); if (!$id_county) { continue; } } if (isset($rule_attributes['county_behavior']) && in_array($rule_attributes['state_behavior'], $available_behavior)) { $county_behavior = (int) $rule_attributes['county_behavior']; } } // Creation $tr = new TaxRule(); $tr->id_tax_rules_group = $trg->id; $tr->id_country = $id_country; $tr->id_state = $id_state; $tr->id_county = $id_county; $tr->state_behavior = $state_behavior; $tr->county_behavior = $county_behavior; $tr->id_tax = $assoc_taxes[strval($rule_attributes['id_tax'])]; $tr->save(); } } } return true; }
///jobs $job_by_locations = Job::list_job_by_location($country_code); if ($job_by_locations2) { $location = array(); $i = 1; foreach ($job_by_locations as $job_by_location) { //city $city_code = City::find_by_code($country_a, null, null, $job_by_location->city); $city_var_name = $city_code ? $city_code->var_name : $job_by_location->city; //states $state_code = $job_by_location->state_province; $state_ = StateProvince::find_by_code($country_a, $state_code); $state_var_name = $state_ ? $state_->var_name : $job_by_location->state_province; //county $county_code = $job_by_location->county; $county_ = County::find_by_code($country_a, $state_code, $county_code); $county_var_name = $county_ ? $county_->var_name : $job_by_location->county; if ($city_code) { /**check length of text */ $location_name = strlen($city_code->name) > 60 ? substr($city_code->name, 0, 30) . " ... " : $city_code->name; } else { /**check length of text */ $location_name = strlen($city_var_name) > 60 ? substr($city_var_name, 0, 30) . " ... " : $city_var_name; } $total_jobs = Job::get_total_job_by_location($country_a, null, null, $job_by_location->city); $location[$i]['total'] = $total_jobs; $location[$i]['name'] = $location_name; $location[$i]['location_id'] = $city->id; $location[$i]['var_name'] = $city_var_name; $location[$i]['url'] = $state_var_name . "/" . $county_var_name . "/"; $i++;