function testLatLongValidation() { $address = new Address(); $address->setLine1("900 Winslow Way"); $address->setLine2("Ste 130"); $address->setCity("Bainbridge Island"); $address->setRegion("WA"); $address->setPostalCode("98110"); $address->setLongitude("-122.510359"); $address->setLatitude("47.624972"); $validateRequest = new ValidateRequest(); $validateRequest->setAddress($address); $validateRequest->setTextCase(TextCase::$Upper); //added for 4.13 changes $validateRequest->setCoordinates(true); //Sets Profile name from Configuration File to "Jaas" //this will force it to Jaas (PostLocate) $this->client = new AddressServiceSoap("JaasDevelopement"); //validate the Request $result = $this->client->validate($validateRequest); //Re-Assigning to the original Profile $this->client = new AddressServiceSoap("Development"); $this->assertEqual($result->getResultCode(), SeverityLevel::$Success); $validAddresses = $result->getValidAddresses(); $this->assertEqual(1, count($validAddresses)); $validAddresses = $result->getValidAddresses(); if (count($validAddresses) != 1) { echo "Unexpected number of addresses returned. Expected one address."; } else { $validAddress = $validAddresses[0]; $this->assertEqual(strtoupper($address->getLine1()) . " E " . strtoupper($address->getLine2()), $validAddress->getLine1()); $this->assertEqual("", $validAddress->getLine2()); $this->assertEqual(strtoupper($address->getCity()), $validAddress->getCity()); $this->assertEqual(strtoupper($address->getRegion()), $validAddress->getRegion()); $this->assertEqual($address->getPostalCode() . "-2450", $validAddress->getPostalCode()); $this->assertEqual("H", $validAddress->getAddressType()); $this->assertEqual("C051", $validAddress->getCarrierRoute()); //Ticket 21203: Modified Fips Code value for jaas enabled account. //$this->assertEqual("5303500000", $validAddress->getFipsCode()); $this->assertEqual("5303503736", $validAddress->getFipsCode()); $this->assertEqual("KITSAP", $validAddress->getCounty()); $this->assertEqual(strtoupper($address->getCity()) . " " . strtoupper($address->getRegion()) . " " . $address->getPostalCode() . "-2450", $validAddress->getLine4()); $this->assertEqual("981102450307", $validAddress->getPostNet()); // Added 4.13 changes for the Lat Long // Update to check for ZIP+4 precision // Zip+4 precision coordinates if (strlen($validAddress->getLatitude()) > 7) { echo "ZIP+4 precision coordinates received"; $this->assertEqual($address->getLatitude(), $validAddress->getLatitude()); $this->assertEqual($address->getLongitude(), $validAddress->getLongitude()); } else { echo "ZIP5 precision coordinates received"; $this->assertEqual(substr($validAddress->getLatitude(), 0, 4), substr($address->getLatitude(), 0, 4), "Expected Latitude to start with '47.64'"); $this->assertEqual(substr($validAddress->getLongitude(), 0, 6), substr($address->getLongitude(), 0, 6), "Expected Longitude to start with '-122.53'"); } } }
/** * Sets attributes from the Mage address on the AvaTax Request address. * * @return $this */ protected function _convertRequestAddress() { if (!$this->_requestAddress) { $this->_requestAddress = new Address(); } $this->_requestAddress->setLine1($this->_mageAddress->getStreet(1)); $this->_requestAddress->setLine2($this->_mageAddress->getStreet(2)); $this->_requestAddress->setCity($this->_mageAddress->getCity()); $this->_requestAddress->setRegion($this->_mageAddress->getRegionCode()); $this->_requestAddress->setCountry($this->_mageAddress->getCountry()); $this->_requestAddress->setPostalCode($this->_mageAddress->getPostcode()); return $this; }
/** * Generic address maker * * @param string $line1 * @param string $line2 * @param string $city * @param string $state * @param string $zip * @param string $country * @return Address */ protected function _newAddress($line1, $line2, $city, $state, $zip, $country = 'USA') { $address = new Address(); $address->setLine1($line1); $address->setLine2($line2); $address->setCity($city); $address->setRegion($state); $address->setPostalCode($zip); $address->setCountry($country); return $address; }
function createStandardRequest($calc, $products, $sign = 1) { if (!class_exists('TaxServiceSoap')) { require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php'; } if (!class_exists('DocumentType')) { require VMAVALARA_CLASS_PATH . DS . 'DocumentType.class.php'; } if (!class_exists('DetailLevel')) { require VMAVALARA_CLASS_PATH . DS . 'DetailLevel.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('ServiceMode')) { require VMAVALARA_CLASS_PATH . DS . 'ServiceMode.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('GetTaxRequest')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxRequest.class.php'; } if (!class_exists('GetTaxResult')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxResult.class.php'; } if (!class_exists('Address')) { require VMAVALARA_CLASS_PATH . DS . 'Address.class.php'; } if (is_object($calc)) { $calc = get_object_vars($calc); } $request = new GetTaxRequest(); $origin = new Address(); //In Virtuemart we have not differenct warehouses, but we have a shipment address //So when the vendor has a shipment address, we assume that it is his warehouse //Later we can combine products with shipment addresses for different warehouse (yehye, future music) //But for now we just use the BT address if (!class_exists('VirtueMartModelVendor')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'vendor.php'; } $userId = VirtueMartModelVendor::getUserIdByVendorId($calc['virtuemart_vendor_id']); $userModel = VmModel::getModel('user'); $virtuemart_userinfo_id = $userModel->getBTuserinfo_id($userId); // this is needed to set the correct user id for the vendor when the user is logged $userModel->getVendor($calc['virtuemart_vendor_id']); $vendorFieldsArray = $userModel->getUserInfoInUserFields('mail', 'BT', $virtuemart_userinfo_id, FALSE, TRUE); $vendorFields = $vendorFieldsArray[$virtuemart_userinfo_id]; $origin->setLine1($vendorFields['fields']['address_1']['value']); $origin->setLine2($vendorFields['fields']['address_2']['value']); $origin->setCity($vendorFields['fields']['city']['value']); $origin->setCountry($vendorFields['fields']['virtuemart_country_id']['country_2_code']); $origin->setRegion($vendorFields['fields']['virtuemart_state_id']['state_2_code']); $origin->setPostalCode($vendorFields['fields']['zip']['value']); $request->setOriginAddress($origin); //Address if (isset($this->addresses[0])) { $destination = $this->addresses[0]; } else { return FALSE; } if (!class_exists('calculationHelper')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php'; } $calculator = calculationHelper::getInstance(); $request->setCurrencyCode($calculator->_currencyDisplay->_vendorCurrency_code_3); //CurrencyCode $request->setDestinationAddress($destination); //Address $request->setCompanyCode($calc['company_code']); // Your Company Code From the Dashboard $request->setDocDate(date('Y-m-d')); //date, checked $request->setCustomerCode(self::$vmadd['customer_number']); //string Required if (isset(self::$vmadd['tax_usage_type'])) { $request->setCustomerUsageType(self::$vmadd['tax_usage_type']); //string Entity Usage } if (isset(self::$vmadd['tax_exemption_number'])) { $request->setExemptionNo(self::$vmadd['tax_exemption_number']); //string if not using ECMS which keys on customer code } if (isset(self::$vmadd['taxOverride'])) { $request->setTaxOverride(self::$vmadd['taxOverride']); avadebug('I set tax override ', self::$vmadd['taxOverride']); } $setAllDiscounted = false; if (isset($products['discountAmount'])) { if (!empty($products['discountAmount'])) { //$request->setDiscount($sign * $products['discountAmount'] * (-1)); //decimal $request->setDiscount($sign * $products['discountAmount']); //decimal vmdebug('We sent as discount ' . $request->getDiscount()); $setAllDiscounted = true; } unset($products['discountAmount']); } $request->setDetailLevel('Tax'); //Summary or Document or Line or Tax or Diagnostic $lines = array(); $n = 0; $this->_lineNumbersToCartProductId = array(); foreach ($products as $k => $product) { $n++; $this->_lineNumbersToCartProductId[$n] = $k; $line = new Line(); $line->setNo($n); //string // line Number of invoice $line->setItemCode($product['product_sku']); //string $line->setDescription($product['product_name']); //product description, like in cart, atm only the name, todo add customfields if (!empty($product['categories'])) { //avadebug('AvaTax setTaxCode Product has categories !',$catNames); if (!class_exists('TableCategories')) { require JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'categories.php'; } $db = JFactory::getDbo(); $catTable = new TableCategories($db); foreach ($product['categories'] as $cat) { $catTable->load($cat); $catslug = $catTable->slug; if (strpos($catslug, 'avatax-') !== FALSE) { $taxCode = substr($catslug, 7); if (!empty($taxCode)) { $line->setTaxCode($taxCode); } else { vmError('AvaTax setTaxCode, category could not be parsed ' . $catslug); } break; } } } //$line->setTaxCode(""); //string $line->setQty($product['amount']); //decimal $line->setAmount($sign * $product['price'] * $product['amount']); //decimal // TotalAmmount if ($setAllDiscounted or !empty($product['discount'])) { $line->setDiscounted(1); } else { $line->setDiscounted(0); } $line->setRevAcct(""); //string $line->setRef1(""); //string $line->setRef2(""); //string if (isset(self::$vmadd['tax_usage_type'])) { $line->setCustomerUsageType(self::$vmadd['tax_usage_type']); //string Entity Usage } if (isset(self::$vmadd['tax_exemption_number'])) { $line->setExemptionNo(self::$vmadd['tax_exemption_number']); //string if not using ECMS which keys on customer code } if (isset(self::$vmadd['taxOverride'])) { //create new TaxOverride Object set //$line->setTaxOverride(self::$vmadd['taxOverride']); } $lines[] = $line; } $this->newATConfig($calc); $request->setLines($lines); return $request; }
// Get The address from the user via keyboard input echo "Address Line 1: "; $input = rtrim(fgets($STDIN)); $address->setLine1($input); echo "Address Line 2: "; $input = rtrim(fgets($STDIN)); $address->setLine2($input); echo "Address Line 3: "; $input = rtrim(fgets($STDIN)); $address->setLine3($input); echo "City: "; $input = rtrim(fgets($STDIN)); $address->setCity($input); echo "State/Province: "; $input = rtrim(fgets($STDIN)); $address->setRegion($input); echo "Postal Code: "; $input = rtrim(fgets($STDIN)); $address->setPostalCode($input); $textCase = TextCase::$Mixed; $coordinates = 1; $request = new ValidateRequest($address, $textCase ? $textCase : TextCase::$Default, $coordinates); $result = $client->Validate($request); echo "\n" . 'Validate ResultCode is: ' . $result->getResultCode() . "\n"; if ($result->getResultCode() != SeverityLevel::$Success) { foreach ($result->getMessages() as $msg) { echo $msg->getName() . ": " . $msg->getSummary() . "\n"; } } else { echo "Normalized Address:\n"; foreach ($result->getvalidAddresses() as $valid) {
/** * Tests Address->setRegion() */ public function testSetRegion() { $this->Address->setRegion('religion'); $this->assertEquals('religion', $this->Address->region); }
public function getPeople($ids, $fields, $options, $token) { $first = $options->getStartIndex(); $max = $options->getCount(); $this->checkDb(); $ret = array(); $filterQuery = ''; $options->setFilterBy(null); //DateOfBirth $query = "\n\t\tSELECT * FROM `Profiles` WHERE `ID` IN (" . implode(',', $ids) . ") {$filterQuery} ORDER BY `ID`\n\t"; /* `ID` AS 'id', `NickName` AS 'first_name', `NickName` AS 'last_name', `DescriptionMe` AS 'about_me', 20 AS 'age', `DateOfBirth` AS 'date_of_birth', 1 AS 'children', '' AS 'ethnicity', '' AS 'fashion', '' AS 'happiest_when', '' AS 'humor', '' AS 'job_interests' */ $res = mysqli_query($this->db, $query); if ($res) { while ($row = @mysqli_fetch_array($res, MYSQLI_ASSOC)) { $person_id = $row['ID']; $sFirstName = isset($row['FirstName']) ? $row['FirstName'] : $row['NickName']; $sLastName = isset($row['LastName']) ? $row['LastName'] : ''; $name = new Name($sFirstName . ' ' . $sLastName); $name->setGivenName($sFirstName); $name->setFamilyName($sLastName); $person = new Person($person_id, $name); $person->setDisplayName($name->getFormatted()); $sAboutMe = isset($row['DescriptionMe']) ? $row['DescriptionMe'] : ''; $person->setAboutMe($sAboutMe); $sDateOfBirth = isset($row['DateOfBirth']) ? date('Y-m-d', $row['DateOfBirth']) : ''; $sAge = $sDateOfBirth != '' ? $this->bx_getAge($sDateOfBirth) : ''; $person->setAge($sAge); $sChildren = isset($row['Children']) ? $row['Children'] : ''; $person->setChildren($sChildren); $person->setBirthday($sDateOfBirth); $sEthnicity = isset($row['Ethnicity']) ? $row['Ethnicity'] : ''; $person->setEthnicity($sEthnicity); $sFashion = isset($row['Fashion']) ? $row['Fashion'] : ''; $person->setFashion($sFashion); $sHappiestWhen = isset($row['HappiestWhen']) ? $row['HappiestWhen'] : ''; $person->setHappiestWhen($sHappiestWhen); $sHumor = isset($row['Humor']) ? $row['Humor'] : ''; $person->setHumor($sHumor); $sJobInterests = isset($row['JobInterests']) ? $row['JobInterests'] : ''; $person->setJobInterests($sJobInterests); $sLivingArrangement = isset($row['LivingArrangement']) ? $row['LivingArrangement'] : ''; $person->setLivingArrangement($sLivingArrangement); $sLookingFor = isset($row['LookingFor']) ? $row['LookingFor'] : ''; $person->setLookingFor($sLookingFor); $sNickName = isset($row['NickName']) ? $row['NickName'] : ''; $person->setNickname($sNickName); $sPets = isset($row['Pets']) ? $row['Pets'] : ''; $person->setPets($sPets); $sPoliticalViews = isset($row['PoliticalViews']) ? $row['PoliticalViews'] : ''; $person->setPoliticalViews($sPoliticalViews); $sProfileSong = isset($row['ProfileSong']) ? $row['ProfileSong'] : ''; $person->setProfileSong($sProfileSong); $person->setProfileUrl($this->url_prefix . '/profile/' . $person_id); //'A' TODO $sProfileVideo = isset($row['ProfileVideo']) ? $row['ProfileVideo'] : ''; $person->setProfileVideo($sProfileVideo); $sRelationshipStatus = isset($row['RelationshipStatus']) ? $row['RelationshipStatus'] : ''; $person->setRelationshipStatus($sRelationshipStatus); $sReligion = isset($row['Religion']) ? $row['Religion'] : ''; $person->setReligion($sReligion); $sRomance = isset($row['Romance']) ? $row['Romance'] : ''; $person->setRomance($sRomance); $sScaredOf = isset($row['ScaredOf']) ? $row['ScaredOf'] : ''; $person->setScaredOf($sScaredOf); $sSexualOrientation = isset($row['SexualOrientation']) ? $row['SexualOrientation'] : ''; $person->setSexualOrientation($sSexualOrientation); $person->setStatus($row['UserStatus']); $person->setThumbnailUrl(!empty($row['thumbnail_url']) ? $this->url_prefix . $row['thumbnail_url'] : ''); //'A' TODO if (!empty($row['thumbnail_url'])) { // also report thumbnail_url in standard photos field (this is the only photo supported by partuza) $person->setPhotos(array(new Photo($this->url_prefix . $row['thumbnail_url'], 'thumbnail', true))); } $sUtcOffset = isset($row['TimeZone']) ? $row['TimeZone'] : "-00:00"; $person->setUtcOffset(sprintf('%+03d:00', $sUtcOffset)); // force "-00:00" utc-offset format if (!empty($row['Drinker'])) { $person->setDrinker($row['Drinker']); } if (!empty($row['Sex'])) { $person->setGender(strtolower($row['Sex'])); } if (!empty($row['Smoker'])) { $person->setSmoker($row['Smoker']); } /* the following fields require additional queries so are only executed if requested */ if (isset($fields['activities']) || in_array('@all', $fields)) { $activities = array(); //'A' we haven`t activities yet /*$res2 = mysqli_query($this->db, "select activity from person_activities where person_id = " . $person_id); while (list($activity) = @mysqli_fetch_row($res2)) { $activities[] = $activity; }*/ $person->setActivities($activities); } if (isset($fields['addresses']) || in_array('@all', $fields)) { $addresses = array(); $sCountry = isset($row['Country']) ? $row['Country'] : ''; $sRegion = isset($row['City']) ? $row['City'] : ''; //'A' region -> city $sZip = isset($row['zip']) ? $row['zip'] : ''; if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $sRegion . " " . $sCountry); } $addres = new Address($row['unstructured_address']); $addres->setCountry($sCountry); if (!empty($row['latitude'])) { $addres->setLatitude($row['latitude']); } if (!empty($row['longitude'])) { $addres->setLongitude($row['longitude']); } if (!empty($row['locality'])) { $addres->setLocality($row['locality']); } $addres->setPostalCode($sZip); $addres->setRegion($sRegion); if (!empty($row['street_address'])) { $addres->setStreetAddress($row['street_address']); } if (!empty($row['street_address'])) { $addres->setType($row['street_address']); } //FIXME quick and dirty hack to demo PC $addres->setPrimary(true); $addresses[] = $addres; $person->setAddresses($addresses); } if (isset($fields['bodyType']) || in_array('@all', $fields)) { //'A' we haven`t bodyType at all /*$res2 = mysqli_query($this->db, "select * from person_body_type where person_id = " . $person_id); if (@mysqli_num_rows($res2)) { $row = @mysql_fetch_array($res2, MYSQLI_ASSOC); $bodyType = new BodyType(); $bodyType->setBuild($row['build']); $bodyType->setEyeColor($row['eye_color']); $bodyType->setHairColor($row['hair_color']); $bodyType->setHeight($row['height']); $bodyType->setWeight($row['weight']); $person->setBodyType($bodyType); }*/ } if (isset($fields['books']) || in_array('@all', $fields)) { //'A' we haven`t books at all /*$books = array(); $res2 = mysqli_query($this->db, "select book from person_books where person_id = " . $person_id); while (list($book) = @mysqli_fetch_row($res2)) { $books[] = $book; } $person->setBooks($books);*/ } if (isset($fields['cars']) || in_array('@all', $fields)) { //'A' we haven`t cars at all /*$cars = array(); $res2 = mysqli_query($this->db, "select car from person_cars where person_id = " . $person_id); while (list($car) = @mysqli_fetch_row($res2)) { $cars[] = $car; } $person->setCars($cars);*/ } if (isset($fields['currentLocation']) || in_array('@all', $fields)) { //'A' we haven`t currentLocation at all /*$addresses = array(); $res2 = mysqli_query($this->db, "select addresses.* from person_current_location, person_addresses, addresses where addresses.id = person_current_location.address_id and person_addresses.person_id = " . $person_id); if (@mysqli_num_rows($res2)) { $row = mysqli_fetch_array($res2, MYSQLI_ASSOC); if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $row['region'] . " " . $row['country']); } $addres = new Address($row['unstructured_address']); $addres->setCountry($row['country']); $addres->setLatitude($row['latitude']); $addres->setLongitude($row['longitude']); $addres->setLocality($row['locality']); $addres->setPostalCode($row['postal_code']); $addres->setRegion($row['region']); $addres->setStreetAddress($row['street_address']); $addres->setType($row['address_type']); $person->setCurrentLocation($addres); }*/ } if (isset($fields['emails']) || in_array('@all', $fields)) { $emails = array(); //'A' we haven`t multi emails, only single /*$res2 = mysqli_query($this->db, "select address, email_type from person_emails where person_id = " . $person_id); while (list($address, $type) = @mysqli_fetch_row($res2)) { $emails[] = new Email(strtolower($address), $type); // TODO: better email canonicalization; remove dups } $person->setEmails($emails);*/ $sEmail = isset($row['Email']) ? $row['Email'] : ''; $emails[] = new Email(strtolower($sEmail), 'main'); $person->setEmails($emails); } if (isset($fields['food']) || in_array('@all', $fields)) { //'A' we haven`t food at all /*$foods = array(); $res2 = mysqli_query($this->db, "select food from person_foods where person_id = " . $person_id); while (list($food) = @mysqli_fetch_row($res2)) { $foods[] = $food; } $person->setFood($foods);*/ } if (isset($fields['heroes']) || in_array('@all', $fields)) { //'A' we haven`t heroes at all /*$strings = array(); $res2 = mysqli_query($this->db, "select hero from person_heroes where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setHeroes($strings);*/ } if (isset($fields['interests']) || in_array('@all', $fields)) { //'A' we haven`t interests at all /* $strings = array(); $res2 = mysqli_query($this->db, "select interest from person_interests where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setInterests($strings);*/ } $organizations = array(); $fetchedOrg = false; if (isset($fields['jobs']) || in_array('@all', $fields)) { //'A' we haven`t jobs at all /*$res2 = mysqli_query($this->db, "select organizations.* from person_jobs, organizations where organizations.id = person_jobs.organization_id and person_jobs.person_id = " . $person_id); while ($row = mysqli_fetch_array($res2, MYSQLI_ASSOC)) { $organization = new Organization(); $organization->setDescription($row['description']); $organization->setEndDate($row['end_date']); $organization->setField($row['field']); $organization->setName($row['name']); $organization->setSalary($row['salary']); $organization->setStartDate($row['start_date']); $organization->setSubField($row['sub_field']); $organization->setTitle($row['title']); $organization->setWebpage($row['webpage']); $organization->setType('job'); if ($row['address_id']) { $res3 = mysqli_query($this->db, "select * from addresses where id = " . $row['address_id']); if (mysqli_num_rows($res3)) { $row = mysqli_fetch_array($res3, MYSQLI_ASSOC); if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $row['region'] . " " . $row['country']); } $addres = new Address($row['unstructured_address']); $addres->setCountry($row['country']); $addres->setLatitude($row['latitude']); $addres->setLongitude($row['longitude']); $addres->setLocality($row['locality']); $addres->setPostalCode($row['postal_code']); $addres->setRegion($row['region']); $addres->setStreetAddress($row['street_address']); $addres->setType($row['address_type']); $organization->setAddress($address); } } $organizations[] = $organization; } $fetchedOrg = true;*/ } if (isset($fields['schools']) || in_array('@all', $fields)) { //'A' we haven`t schools at all /*$res2 = mysqli_query($this->db, "select organizations.* from person_schools, organizations where organizations.id = person_schools.organization_id and person_schools.person_id = " . $person_id); while ($row = mysqli_fetch_array($res2, MYSQLI_ASSOC)) { $organization = new Organization(); $organization->setDescription($row['description']); $organization->setEndDate($row['end_date']); $organization->setField($row['field']); $organization->setName($row['name']); $organization->setSalary($row['salary']); $organization->setStartDate($row['start_date']); $organization->setSubField($row['sub_field']); $organization->setTitle($row['title']); $organization->setWebpage($row['webpage']); $organization->setType($row['school']); if ($row['address_id']) { $res3 = mysqli_query($this->db, "select * from addresses where id = " . $row['address_id']); if (mysqli_num_rows($res3)) { $row = mysqli_fetch_array($res3, MYSQLI_ASSOC); if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $row['region'] . " " . $row['country']); } $addres = new Address($row['unstructured_address']); $addres->setCountry($row['country']); $addres->setLatitude($row['latitude']); $addres->setLongitude($row['longitude']); $addres->setLocality($row['locality']); $addres->setPostalCode($row['postal_code']); $addres->setRegion($row['region']); $addres->setStreetAddress($row['street_address']); $addres->setType($row['address_type']); $organization->setAddress($address); } } $organizations[] = $organization; } $fetchedOrg = true;*/ } if ($fetchedOrg) { $person->setOrganizations($organizations); } //TODO languagesSpoken, currently missing the languages / countries tables so can't do this yet if (isset($fields['movies']) || in_array('@all', $fields)) { //'A' possible after /*$strings = array(); $res2 = mysqli_query($this->db, "select movie from person_movies where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setMovies($strings);*/ } if (isset($fields['music']) || in_array('@all', $fields)) { //'A' possible after /*$strings = array(); $res2 = mysqli_query($this->db, "select music from person_music where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setMusic($strings);*/ } if (isset($fields['phoneNumbers']) || in_array('@all', $fields)) { //'A' we haven`t phoneNumbers at all /*$numbers = array(); $res2 = mysqli_query($this->db, "select number, number_type from person_phone_numbers where person_id = " . $person_id); while (list($number, $type) = @mysqli_fetch_row($res2)) { $numbers[] = new Phone($number, $type); } $person->setPhoneNumbers($numbers);*/ } if (isset($fields['ims']) || in_array('@all', $fields)) { //'A' we haven`t ims at all /*$ims = array(); $res2 = mysqli_query($this->db, "select value, value_type from person_ims where person_id = " . $person_id); while (list($value, $type) = @mysqli_fetch_row($res2)) { $ims[] = new Im($value, $type); } $person->setIms($ims);*/ } if (isset($fields['accounts']) || in_array('@all', $fields)) { //'A' we haven`t accounts at all /*$accounts = array(); $res2 = mysqli_query($this->db, "select domain, userid, username from person_accounts where person_id = " . $person_id); while (list($domain, $userid, $username) = @mysqli_fetch_row($res2)) { $accounts[] = new Account($domain, $userid, $username); } $person->setAccounts($accounts);*/ } if (isset($fields['quotes']) || in_array('@all', $fields)) { //'A' we haven`t quotes at all /*$strings = array(); $res2 = mysqli_query($this->db, "select quote from person_quotes where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setQuotes($strings);*/ } if (isset($fields['sports']) || in_array('@all', $fields)) { //'A' we haven`t sports at all /*$strings = array(); $res2 = mysqli_query($this->db, "select sport from person_sports where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setSports($strings);*/ } if (isset($fields['tags']) || in_array('@all', $fields)) { $strings = array(); if (!empty($row['latitude'])) { $aProfileTags = preg_split("/[;,\\s]/", $_REQUEST['tags']); foreach ($aProfileTags as $sTag) { $strings[] = $sTag; } /*$res2 = mysqli_query($this->db, "select tag from person_tags where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; }*/ $person->setTags($strings); } } if (isset($fields['turnOns']) || in_array('@all', $fields)) { //'A' we haven`t turnOns at all /*$strings = array(); $res2 = mysqli_query($this->db, "select turn_on from person_turn_ons where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setTurnOns($strings);*/ } if (isset($fields['turnOffs']) || in_array('@all', $fields)) { //'A' we haven`t turnOffs at all /*$strings = array(); $res2 = mysqli_query($this->db, "select turn_off from person_turn_offs where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setTurnOffs($strings);*/ } if (isset($fields['urls']) || in_array('@all', $fields)) { //'A' we haven`t urls at all /*$strings = array(); $res2 = mysqli_query($this->db, "select url from person_urls where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = new Url($data, null, null); } $strings[] = new Url($this->url_prefix . '/profile/' . $person_id, null, 'profile'); // always include profile URL $person->setUrls($strings);*/ } $ret[$person_id] = $person; } } try { $ret = $this->filterResults($ret, $options); $ret['totalSize'] = count($ret); } catch (Exception $e) { $ret['totalSize'] = count($ret) - 1; $ret['filtered'] = 'false'; } if ($first !== false && $max !== false && is_numeric($first) && is_numeric($max) && $first >= 0 && $max > 0) { $count = 0; $result = array(); foreach ($ret as $id => $person) { if ($id == 'totalSize' || $id == 'filtered') { $result[$id] = $person; continue; } if ($count >= $first && $count < $first + $max) { $result[$id] = $person; } ++$count; } return $result; } else { return $ret; } }
$request = new GetTaxRequest(); //Add Origin Address $origin = new Address(); $origin->setLine1("435 Ericksen Ave NE"); $origin->setLine2("Suite 200"); $origin->setCity("Bainbridge Island"); $origin->setRegion("WA"); $origin->setPostalCode("98110-1896"); $request->setOriginAddress($origin); //Address //Add Destination address $destination = new Address(); $destination->setLine1("900 Winslow Way"); $destination->setLine2("Suite 200"); $destination->setCity("Bainbridge Island"); $destination->setRegion("WA"); $destination->setPostalCode("98110"); $request->setDestinationAddress($destination); //Address $request->setCompanyCode('DEFAULT'); // Your Company Code From the Dashboard $request->setDocType(DocumentType::$SalesInvoice); // Only supported types are SalesInvoice or SalesOrder $dateTime = new DateTime(); $docCode = "PHPSample" . date_format($dateTime, "dmyGis"); $request->setDocCode($docCode); // invoice number $request->setDocDate(date_format($dateTime, "Y-m-d")); //date $request->setSalespersonCode(""); // string Optional
function wc_autoship_taxnow_add_tax_rates($tax_rates, $schedule_id) { include_once WP_PLUGIN_DIR . '/taxnow_woo/taxnow-woo.class.php'; include_once WP_PLUGIN_DIR . '/woocommerce-autoship/classes/wc-autoship-schedule.php'; if (class_exists('class_taxNOW_woo') && class_exists('WC_Autoship_Schedule')) { // Create TaxNOW instance $taxnow_woo = new class_taxNOW_woo(); // Get autoship schedule $schedule = new WC_Autoship_Schedule($schedule_id); // Get autoship customer $customer = $schedule->get_customer(); // Create service $service = $taxnow_woo->create_service('TaxServiceSoap', false); $request = new GetTaxRequest(); $request->setDocDate(date('Y-m-d', current_time('timestamp'))); $request->setDocCode(''); $request->setCustomerCode($customer->get_email()); $request->setCompanyCode(get_option('tnwoo_company_code')); $request->setDocType(DocumentType::$SalesOrder); $request->setDetailLevel(DetailLevel::$Tax); $request->setCurrencyCode(get_option('woocommerce_currency')); $request->setBusinessIdentificationNo(get_option('tnwoo_business_vat_id')); // Origin address $origin = new Address(); $origin->setLine1(get_option('tnwoo_origin_street')); $origin->setCity(get_option('tnwoo_origin_city')); $origin->setRegion(get_option('tnwoo_origin_state')); $origin->setPostalCode(get_option('tnwoo_origin_zip')); $origin->setCountry(get_option('tnwoo_origin_country')); $request->setOriginAddress($origin); // Destination address $destination = new Address(); $destination->setLine1($customer->get('shipping_address_1')); $destination->setCity($customer->get('shipping_city')); $destination->setRegion($customer->get('shipping_state')); $destination->setPostalCode($customer->get('shipping_postcode')); $destination->setCountry($customer->get('shipping_country')); $request->setDestinationAddress($destination); // Lines items $items = $schedule->get_items(); $lines = array(); $global_tax_code = get_option('tnwoo_default_tax_code'); foreach ($items as $i => $item) { // Get WooCommerce product ID $product_id = $item->get_product_id(); // Create line item $line = new Line(); $line->setItemCode($product_id); $line->setDescription($product_id); $tax_code = get_post_meta($product_id, '_taxnow_taxcode', true); $line->setTaxCode(!empty($tax_code) ? $tax_code : $global_tax_code); $line->setQty((int) $item->get_quantity()); $line->setAmount((double) $item->get_autoship_price()); $line->setNo($i + 1); $line->setDiscounted(0); $lines[] = $line; } $request->setLines($lines); // Pretax discount $discount_pretax = 0.0; // Send request $taxnow_woo->log_add_entry('calculate_tax', 'request', $request); try { $response = $service->getTax($request); $taxnow_woo->log_add_entry('calculate_tax', 'response', $response); if ($response->getResultCode() == SeverityLevel::$Success) { foreach ($response->GetTaxLines() as $l => $TaxLine) { foreach ($TaxLine->getTaxDetails() as $d => $TaxDetail) { // Create WooCommerce tax rate $tax_rate = array('rate' => 100.0 * $TaxDetail->getRate(), 'label' => $TaxDetail->getTaxName(), 'shipping' => 'no', 'compound' => 'no'); $tax_rates["wc_autoship_taxnow_{$l}_{$d}"] = $tax_rate; } } } } catch (Exception $e) { $taxnow_woo->log_add_entry('calculate_tax', 'exception', $e->getMessage()); } } // Return tax rates return $tax_rates; }
function getTax($calculationHelper, $calc, $price, $sale = false, $committ = false) { if ($calc->activated == 0) { return false; } $shopperData = $this->getShopperData(); if (!$shopperData) { return false; } //if(self::$stop) return self::$stop; if (!class_exists('TaxServiceSoap')) { require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php'; } if (!class_exists('DocumentType')) { require VMAVALARA_CLASS_PATH . DS . 'DocumentType.class.php'; } if (!class_exists('DetailLevel')) { require VMAVALARA_CLASS_PATH . DS . 'DetailLevel.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('ServiceMode')) { require VMAVALARA_CLASS_PATH . DS . 'ServiceMode.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('GetTaxRequest')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxRequest.class.php'; } if (!class_exists('GetTaxResult')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxResult.class.php'; } $client = new TaxServiceSoap('Development'); $request = new GetTaxRequest(); $origin = new Address(); //$destination = $this->fillValidateAvalaraAddress($calc); //In Virtuemart we have not differenct warehouses, but we have a shipment address //So when the vendor has a shipment address, we assume that it is his warehouse //Later we can combine products with shipment addresses for different warehouse (yehye, future music) //But for now we just use the BT address if (!class_exists('VirtueMartModelVendor')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'vendor.php'; } $userId = VirtueMartModelVendor::getUserIdByVendorId($calc->virtuemart_vendor_id); $userModel = VmModel::getModel('user'); $virtuemart_userinfo_id = $userModel->getBTuserinfo_id($userId); // this is needed to set the correct user id for the vendor when the user is logged $userModel->getVendor($calc->virtuemart_vendor_id); $vendorFieldsArray = $userModel->getUserInfoInUserFields('mail', 'BT', $virtuemart_userinfo_id, FALSE, TRUE); $vendorFields = $vendorFieldsArray[$virtuemart_userinfo_id]; //vmdebug('my vendor fields',$vendorFields); $origin->setLine1($vendorFields['fields']['address_1']['value']); $origin->setLine2($vendorFields['fields']['address_2']['value']); $origin->setCity($vendorFields['fields']['city']['value']); $origin->setCountry($vendorFields['fields']['virtuemart_country_id']['country_2_code']); $origin->setRegion($vendorFields['fields']['virtuemart_state_id']['state_2_code']); $origin->setPostalCode($vendorFields['fields']['zip']['value']); $request->setOriginAddress($origin); //Address if (isset($this->addresses[0])) { $destination = $this->addresses[0]; } else { return FALSE; } $request->setDestinationAddress($destination); //Address //vmdebug('The date',$origin,$destination); $request->setCompanyCode($calc->company_code); // Your Company Code From the Dashboard if ($calc->committ and $sale) { $request->setDocType(DocumentType::$SalesInvoice); // Only supported types are SalesInvoice or SalesOrder $request->setCommit(true); //invoice number, problem is that the invoice number is at this time not known, but the order_number may reachable $request->setDocCode($committ); vmdebug('Request as SalesInvoice with invoiceNumber ' . $committ); } else { $request->setDocType(DocumentType::$SalesOrder); $request->setCommit(false); //invoice number, problem is that the invoice number is at this time not known, neither the order_number $request->setDocCode('VM2.0.16_order_request'); vmdebug('Request as SalesOrder'); } $request->setDocDate(date('Y-m-d')); //date //$request->setSalespersonCode(""); // string Optional $request->setCustomerCode($shopperData['customer_id']); //string Required if (isset($shopperData['tax_usage_type'])) { $request->setCustomerUsageType($shopperData['tax_usage_type']); //string Entity Usage } $cartPrices = $calculationHelper->getCartPrices(); //vmdebug('$cartPrices',$cartPrices); $request->setDiscount($cartPrices['discountAmount']); //decimal //$request->setDiscount(0.0); // $request->setPurchaseOrderNo(""); //string Optional //If I understand correctly, we need to add for this an userfield, for example with the name //exemption_no, then user could enter their number. if (isset($shopperData['tax_exemption_number'])) { $request->setExemptionNo($shopperData['tax_exemption_number']); //string if not using ECMS which keys on customer code } $request->setDetailLevel('Tax'); //Summary or Document or Line or Tax or Diagnostic // $request->setReferenceCode1(""); //string Optional // $request->setReferenceCode2(""); //string Optional // $request->setLocationCode(""); //string Optional - aka outlet id for tax forms ///////////////////////////////////////// if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } $cart = VirtueMartCart::getCart(); $products = array(); if ($calculationHelper->inCart) { $products = $cart->products; $prices = $calculationHelper->getCartPrices(); foreach ($products as $k => $product) { if (!empty($prices[$k]['discountedPriceWithoutTax'])) { $price = $prices[$k]['discountedPriceWithoutTax']; } else { if (!empty($prices[$k]['basePriceVariant'])) { $price = $prices[$k]['basePriceVariant']; } else { vmdebug('There is no price in getTax for product ' . $k . ' ', $prices); $price = 0.0; } } $product->price = $price; if (!empty($price[$k]['discountAmount'])) { $product->discount = $price[$k]['discountAmount']; } else { $product->discount = FALSE; } } } else { $calculationHelper->_product->price = $price; $products[0] = $calculationHelper->_product; if (!isset($products[0]->amount)) { $products[0]->amount = 1; } if (isset($calculationHelper->productPrices['discountAmount'])) { $products[0]->discount = $calculationHelper->productPrices['discountAmount']; } else { $products[0]->discount = FALSE; } } $lines = array(); $n = 0; $lineNumbersToCartProductId = array(); foreach ($products as $k => $product) { $n++; $lineNumbersToCartProductId[$n] = $k; $line = new Line(); $line->setNo($n); //string // line Number of invoice $line->setItemCode($product->product_sku); //string $line->setDescription($product->product_name); //product description, like in cart, atm only the name, todo add customfields //$line->setTaxCode(""); //string $line->setQty($product->amount); //decimal $line->setAmount($product->price * $product->amount); //decimal // TotalAmmount $line->setDiscounted($product->discount * $product->amount); //boolean $line->setRevAcct(""); //string $line->setRef1(""); //string $line->setRef2(""); //string if (isset($shopperData['tax_exemption_number'])) { $line->setExemptionNo($shopperData['tax_exemption_number']); //string } if (isset($shopperData['tax_usage_type'])) { $line->setCustomerUsageType($shopperData['tax_usage_type']); //string } $lines[] = $line; } $line = new Line(); $line->setNo(++$n); //$lineNumbersToCartProductId[$n] = count($products)+1; $line->setItemCode($cart->virtuemart_shipmentmethod_id); $line->setDescription('Shipment'); $line->setQty(1); //$line->setTaxCode(); $cartPrices = $calculationHelper->getCartPrices(); //vmdebug('$calculationHelper $cartPrices',$cartPrices); $line->setAmount($cartPrices['shipmentValue']); if (isset($shopperData['tax_exemption_number'])) { $line->setExemptionNo($shopperData['tax_exemption_number']); //string } if (isset($shopperData['tax_usage_type'])) { $line->setCustomerUsageType($shopperData['tax_usage_type']); //string } $lines[] = $line; //vmdebug('avalaragetTax setLines',$lines); $request->setLines($lines); //vmdebug('My request',$request); $totalTax = 0.0; try { if (!class_exists('TaxLine')) { require VMAVALARA_CLASS_PATH . DS . 'TaxLine.class.php'; } if (!class_exists('TaxDetail')) { require VMAVALARA_CLASS_PATH . DS . 'TaxDetail.class.php'; } vmSetStartTime('avagetTax'); $getTaxResult = $client->getTax($request); vmTime('Avalara getTax', 'avagetTax'); /* * [0] => getDocCode [1] => getAdjustmentDescription [2] => getAdjustmentReason [3] => getDocDate [4] => getTaxDate [5] => getDocType [6] => getDocStatus [7] => getIsReconciled [8] => getLocked [9] => getTimestamp [10] => getTotalAmount [11] => getTotalDiscount [12] => getTotalExemption [13] => getTotalTaxable [14] => getTotalTax [15] => getHashCode [16] => getVersion [17] => getTaxLines [18] => getTotalTaxCalculated [19] => getTaxSummary [20] => getTaxLine [21] => getTransactionId [22] => getResultCode [23] => getMessages */ //vmdebug( 'GetTax is: '. $getTaxResult->getResultCode(),$getTaxResult); if ($getTaxResult->getResultCode() == SeverityLevel::$Success) { //vmdebug("DocCode: ".$request->getDocCode() ); //vmdebug("DocId: ".$getTaxResult->getDocId()."\n"); vmdebug("TotalAmount: " . $getTaxResult->getTotalAmount()); $totalTax = $getTaxResult->getTotalTax(); vmdebug("TotalTax: " . $totalTax); foreach ($getTaxResult->getTaxLines() as $ctl) { if ($calculationHelper->inCart) { $nr = $ctl->getNo(); if (isset($lineNumbersToCartProductId[$nr])) { $quantity = $products[$lineNumbersToCartProductId[$nr]]->amount; //on the long hand, the taxAmount must be replaced by taxAmountQuantity to avoid rounding errors $prices[$lineNumbersToCartProductId[$ctl->getNo()]]['taxAmount'] = $ctl->getTax() / $quantity; $prices[$lineNumbersToCartProductId[$ctl->getNo()]]['taxAmountQuantity'] = $ctl->getTax(); } else { //$this->_cartPrices['shipmentValue'] = 0; //could be automatically set to a default set in the globalconfig //$this->_cartPrices['shipmentTax'] = 0; //$this->_cartPrices['shipmentTotal'] = 0; //$prices = array('shipmentValue'=>$cartPrices['shipmentValue'],'shipmentTax'=> $ctl->getTax(), 'shipmentTotal' =>($cartPrices['shipmentValue'] +$ctl->getTax() )); //vmdebug('my $cartPrices',$cartPrices); $prices['shipmentTax'] = $ctl->getTax(); $prices['salesPriceShipment'] = $prices['shipmentValue'] + $ctl->getTax(); //$cartPrices = array_merge($prices,$cartPrices); //$calculationHelper->setCartPrices( $cartPrices ); $totalTax = $totalTax - $ctl->getTax(); //vmdebug('my $cartPrices danach',$cartPrices); } } //vmdebug('my lines ',$ctl); //vmdebug( " Line: ".$ctl->getNo()." Tax: ".$ctl->getTax()." TaxCode: ".$ctl->getTaxCode()); foreach ($ctl->getTaxDetails() as $ctd) { //vmdebug( " Juris Type: ".$ctd->getJurisType()."; Juris Name: ".$ctd->getJurisName()."; Rate: ".$ctd->getRate()."; Amt: ".$ctd->getTax() ); } } if ($calculationHelper->inCart) { $calculationHelper->setCartPrices($prices); } } else { foreach ($getTaxResult->getMessages() as $msg) { vmError($msg->getName() . ": " . $msg->getSummary()); } } } catch (SoapFault $exception) { $msg = "Exception: "; if ($exception) { $msg .= $exception->faultstring; } vmdebug($msg . '<br />' . $client->__getLastRequest() . '<br />' . $client->__getLastResponse()); } //self::$stop = $totalTax; return $totalTax; }
function CalcTax($taxSvcSoapClient, $companyCode) { $request = new GetTaxRequest(); $origin = new Address(); $destination = new Address(); $line1 = new Line(); $origin->setLine1("435 Ericksen Ave NE"); $origin->setLine2("Suite 200"); $origin->setCity("Bainbridge Island"); $origin->setRegion("WA"); $origin->setPostalCode("98110-1896"); $destination->setLine1("900 Winslow Way"); $destination->setLine2("Suite 200"); $destination->setCity("Bainbridge Island"); $destination->setRegion("WA"); $destination->setPostalCode("98110"); $request->setOriginAddress($origin); //Address $request->setDestinationAddress($destination); //Address $request->setCompanyCode($companyCode); // Your Company Code From the Dashboard $request->setDocType(DocumentType::$SalesInvoice); // Only supported types are SalesInvoice or SalesOrder $dateTime = new DateTime(); $docCode = "PHPSample" . date_format($dateTime, "dmyGis"); $request->setDocCode($docCode); // invoice number $request->setDocDate(date_format($dateTime, "Y-m-d")); //date $request->setSalespersonCode(""); // string Optional $request->setCustomerCode("Cust123"); //string Required $request->setCustomerUsageType(""); //string Entity Usage $request->setDiscount(0.0); //decimal $request->setPurchaseOrderNo(""); //string Optional $request->setExemptionNo(""); //string if not using ECMS which keys on customer code $request->setDetailLevel(DetailLevel::$Document); $request->setCommit("true"); // commit upon tax calc $request->setReferenceCode(""); //string Optional $request->setLocationCode(""); //string Optional - aka outlet id for tax forms $line1->setNo("1"); //string // line Number of invoice $line1->setItemCode("SKU123"); //string $line1->setDescription("Invoice Calculated From PHP SDK"); //string $line1->setTaxCode(""); //string $line1->setQty(1.0); //decimal $line1->setAmount(1000.0); //decimal // TotalAmmount $line1->setDiscounted(false); //boolean $line1->setRevAcct(""); //string $line1->setRef1(""); //string $line1->setRef2(""); //string $line1->setExemptionNo(""); //string $line1->setCustomerUsageType(""); //string $request->setLines(array($line1)); //array try { $getTaxResult = $taxSvcSoapClient->getTax($request); echo 'GetTax Result: ' . $getTaxResult->getResultCode() . "\n"; if ($getTaxResult->getResultCode() == SeverityLevel::$Success) { echo "DocCode: " . $request->getDocCode() . "\n"; echo "TotalAmount: " . $getTaxResult->getTotalAmount() . "\n"; echo "TotalTax: " . $getTaxResult->getTotalTax() . "\n"; } else { foreach ($getTaxResult->getMessages() as $msg) { echo $msg->getName() . ": " . $msg->getSummary() . "\n"; } } } catch (SoapFault $exception) { $msg = "Exception: "; if ($exception) { $msg .= $exception->faultstring; } echo $msg . "\n"; echo $taxSvcSoapClient->__getLastRequest() . "\n"; echo $taxSvcSoapClient->__getLastResponse() . "\n"; } return $request->getDocCode(); }
private function CreateTaxRequestForBINo($bino) { $request = new GetTaxRequest(); //Set origin Address $origin = new Address(); $origin->setLine1("Avalara"); $origin->setLine2("900 winslow way"); $origin->setLine3("Suite 100"); $origin->setCity("Bainbridge Island"); $origin->setRegion("WA"); $origin->setPostalCode("98110-1896"); $origin->setCountry("USA"); $request->setOriginAddress($origin); //Set destination address $destination = new Address(); $destination->setLine1("3130 Elliott"); $destination->setCity("Seattle"); $destination->setRegion("WA"); $destination->setPostalCode("98121"); $destination->setCountry("USA"); $request->setDestinationAddress($destination); //Set line $line = new Line(); $line->setNo("1"); //string // line Number of invoice $line->setBusinessIdentificationNo("LL123"); $line->setItemCode("Item123"); //string $line->setQty(1.0); //decimal $line->setAmount(1010.0); $request->setLines(array($line)); $request->setCompanyCode('DEFAULT'); // Your Company Code From the Dashboard $request->setDocCode("DocTypeTest"); $request->setBusinessIdentificationNo($bino); $request->setDocDate(date_format(new DateTime(), "Y-m-d")); $request->setCustomerCode("TaxSvcTest"); //string Required $request->setSalespersonCode(""); // string Optional $request->setDetailLevel(DetailLevel::$Tax); //Summary or Document or Line or Tax or Diagnostic return $request; }
/** * Generic address maker * * @param string $line1 * @param string $line2 * @param string $city * @param string $state * @param string $zip * @param string $country * @return Address */ protected function _newAddress($line1, $line2, $city, $state, $zip, $country = 'USA') { // force string type because hash key generation uses serialize() in Estimate.php $address = new Address(); $address->setLine1((string) $line1); $address->setLine2((string) $line2); $address->setCity((string) $city); $address->setRegion((string) $state); $address->setPostalCode((string) $zip); $address->setCountry((string) $country); return $address; }
/** * Converts the address fetched from the database to the Address object. */ private function convertAddress($row) { $formatted = $row['unstructured_address']; if (empty($formatted)) { $formatted = trim($row['street_address'] . " " . $row['region'] . " " . $row['country']); $formatted = empty($formatted) ? $formatted : null; } $address = new Address($formatted); $address->setCountry($row['country']); $address->setLatitude($row['latitude']); $address->setLongitude($row['longitude']); $address->setLocality($row['locality']); $address->setPostalCode($row['postal_code']); $address->setRegion($row['region']); $address->setStreetAddress($row['street_address']); $address->setType($row['address_type']); $address->setUnstructuredAddress($row['unstructured_address']); $address->setExtendedAddress($row['extended_address']); $address->setPoBox($row['po_box']); return $address; }
public function getPeople($ids, $fields, $options, $token) { $first = $options->getStartIndex(); $max = $options->getCount(); $this->checkDb(); $ret = array(); $filterQuery = ''; if ($options->getFilterBy() == 'hasApp') { // remove the filterBy field, it's taken care of in the query already, otherwise filterResults will disqualify all results $options->setFilterBy(null); $appId = $token->getAppId(); $filterQuery = " and id in (select member_id from " . TABLE_PREFIX . "social_applications where application_id = {$appId})"; } elseif ($options->getFilterBy() == 'all') { $options->setFilterBy(null); } $query = "SELECT member.*, info.interests, info.associations, info.awards FROM " . TABLE_PREFIX . "members member LEFT JOIN " . TABLE_PREFIX . "social_member_additional_information info ON member.member_id=info.member_id WHERE member.member_id IN (" . implode(',', $ids) . ") {$filterQuery} ORDER BY member.member_id "; $res = mysql_query($query, $this->db); if ($res) { while ($row = mysql_fetch_assoc($res)) { $member_id = intval($row['member_id']); $name = new Name($row['first_name'] . ' ' . $row['last_name']); $name->setGivenName($row['first_name']); $name->setFamilyName($row['last_name']); $person = new Person($row['member_id'], $name); $person->setDisplayName($name->getFormatted()); $person->setAboutMe($row['about_me']); $person->setAge($row['age']); $person->setChildren($row['children']); $person->setBirthday(date('Y-m-d', $row['date_of_birth'])); $person->setEthnicity($row['ethnicity']); $person->setFashion($row['fashion']); $person->setHappiestWhen($row['happiest_when']); $person->setHumor($row['humor']); $person->setJobInterests($row['job_interests']); $person->setLivingArrangement($row['living_arrangement']); $person->setLookingFor($row['looking_for']); $person->setNickname($row['nickname']); $person->setPets($row['pets']); $person->setPoliticalViews($row['political_views']); $person->setProfileSong($row['profile_song']); $person->setProfileUrl($this->url_prefix . '/profile/' . $row['member_id']); $person->setProfileVideo($row['profile_video']); $person->setRelationshipStatus($row['relationship_status']); $person->setReligion($row['religion']); $person->setRomance($row['romance']); $person->setScaredOf($row['scared_of']); $person->setSexualOrientation($row['sexual_orientation']); $person->setStatus($row['status']); $person->setThumbnailUrl(!empty($row['thumbnail_url']) ? $this->url_prefix . $row['thumbnail_url'] : ''); if (!empty($row['thumbnail_url'])) { // also report thumbnail_url in standard photos field (this is the only photo supported by ATutor) $person->setPhotos(array(new Photo($this->url_prefix . 'get_profile_img.php?id=' . $row['member_id'], 'thumbnail', true))); } $person->setUtcOffset(sprintf('%+03d:00', $row['time_zone'])); // force "-00:00" utc-offset format if (!empty($row['drinker'])) { $person->setDrinker($row['drinker']); } if (!empty($row['gender'])) { $person->setGender(strtolower($row['gender'])); } if (!empty($row['email'])) { //TODO: Assumed <static> object TYPE to be "home". Change it if ATutor starts accepting more than one email $email = new Email(strtolower($row['email']), 'home'); $person->setEmails($email); } if (!empty($row['interests'])) { $strings = explode(',', $row['interests']); $person->setInterests($strings); } //TODO: Not in ATutor yet, skeleton field if (!empty($row['smoker'])) { $person->setSmoker($row['smoker']); } /* the following fields require additional queries so are only executed if requested */ if (isset($fields['activities']) || isset($fields['@all'])) { $activities = array(); $sql = "select title from " . TABLE_PREFIX . "social_activities where member_id = " . $member_id; $res2 = mysql_query($sql, $this->db); while (list($activity) = mysql_fetch_row($res2)) { $activities[] = $activity; } $person->setActivities($activities); } if (isset($fields['addresses']) || isset($fields['@all'])) { $addresses = array(); $sql = "select address, postal, city, province, country from " . TABLE_PREFIX . "members m where m.member_id = " . $member_id; $res2 = mysql_query($sql, $this->db); while ($row = mysql_fetch_assoc($res2)) { if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $row['province'] . " " . $row['country']); } $addres = new Address($row['unstructured_address']); $addres->setCountry($row['country']); $addres->setLatitude($row['latitude']); $addres->setLongitude($row['longitude']); $addres->setLocality($row['locality']); $addres->setPostalCode($row['postal_code']); $addres->setRegion($row['province']); $addres->setStreetAddress($row['street_address']); $addres->setType($row['address_type']); //FIXME quick and dirty hack to demo PC $addres->setPrimary(true); $addresses[] = $addres; } $person->setAddresses($addresses); } //TODO: Not in ATutor yet, skeleton field /* if (isset($fields['bodyType']) || isset($fields['@all'])) { $res2 = mysql_query($db, "select * from ".TABLE_PREFIX."person_body_type where person_id = " . $person_id); if (@mysql_num_rows($res2)) { $row = @mysql_fetch_assic($res2); $bodyType = new BodyType(); $bodyType->setBuild($row['build']); $bodyType->setEyeColor($row['eye_color']); $bodyType->setHairColor($row['hair_color']); $bodyType->setHeight($row['height']); $bodyType->setWeight($row['weight']); $person->setBodyType($bodyType); } } */ //TODO: Not in ATutor yet, skeleton field /* if (isset($fields['books']) || isset($fields['@all'])) { $books = array(); $res2 = mysqli_query($db, "select book from ".TABLE_PREFIX."person_books where person_id = " . $person_id); while (list($book) = @mysqli_fetch_row($res2)) { $books[] = $book; } $person->setBooks($books); } */ //TODO: Not in ATutor yet, skeleton field /* if (isset($fields['cars']) || isset($fields['@all'])) { $cars = array(); $res2 = mysqli_query($db, "select car from ".TABLE_PREFIX."person_cars where person_id = " . $person_id); while (list($car) = @mysqli_fetch_row($res2)) { $cars[] = $car; } $person->setCars($cars); } */ //TODO: Not in ATutor yet, skeleton field /* if (isset($fields['currentLocation']) || isset($fields['@all'])) { $addresses = array(); $res2 = mysqli_query($db, "select a.* from ".TABLE_PREFIX."person_current_location pcl, ".TABLE_PREFIX."person_addresses pa, ".TABLE_PREFIX."addresses a where a.id = pcl.address_id and pa.person_id = " . $person_id); if (@mysqli_num_rows($res2)) { $row = mysqli_fetch_array($res2, MYSQLI_ASSOC); if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $row['region'] . " " . $row['country']); } $addres = new Address($row['unstructured_address']); $addres->setCountry($row['country']); $addres->setLatitude($row['latitude']); $addres->setLongitude($row['longitude']); $addres->setLocality($row['locality']); $addres->setPostalCode($row['postal_code']); $addres->setRegion($row['region']); $addres->setStreetAddress($row['street_address']); $addres->setType($row['address_type']); $person->setCurrentLocation($addres); } } */ //TODO: Email is a singleton in ATutor, expand it. A person may have 1+ emails nowadays. //added to the above with all the other member's properties /* if (isset($fields['emails']) || isset($fields['@all'])) { $emails = array(); $sql = "select address, email_type from ".TABLE_PREFIX."person_emails where person_id = " . $person_id; $res2 = mysql_query(); while (list($address, $type) = @mysqli_fetch_row($res2)) { $emails[] = new Email(strtolower($address), $type); // TODO: better email canonicalization; remove dups } $person->setEmails($emails); } */ //TODO: Not in ATutor yet, skeleton field /* if (isset($fields['food']) || isset($fields['@all'])) { $foods = array(); $res2 = mysqli_query($db, "select food from ".TABLE_PREFIX."person_foods where person_id = " . $person_id); while (list($food) = @mysqli_fetch_row($res2)) { $foods[] = $food; } $person->setFood($foods); } */ //TODO: Not in ATutor yet, skeleton field /* if (isset($fields['heroes']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select hero from ".TABLE_PREFIX."person_heroes where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setHeroes($strings); } */ //Added with the above profile, interests is in CSV /* if (isset($fields['interests']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select interest from ".TABLE_PREFIX."person_interests where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setInterests($strings); } */ $organizations = array(); $fetchedOrg = false; if (isset($fields['jobs']) || isset($fields['@all'])) { $sql = "SELECT * FROM " . TABLE_PREFIX . "social_member_position WHERE member_id = " . $member_id; $res2 = mysql_query($sql, $this->db); while ($row = mysql_fetch_assoc($res2)) { $organization = new Organization($row['company']); $organization->setDescription($row['description']); $organization->setEndDate($row['to']); $organization->setField($row['field']); $organization->setName($row['company']); $organization->setSalary($row['salary']); $organization->setStartDate($row['from']); $organization->setSubField($row['']); $organization->setTitle($row['title']); $organization->setWebpage($row['webpage']); $organization->setType('job'); //TODO: Address: To be implemented /* if ($row['address_id']) { $res3 = mysqli_query($db, "select * from ".TABLE_PREFIX."addresses where id = " . mysqli_real_escape_string($db, $row['address_id'])); if (mysqli_num_rows($res3)) { $row = mysqli_fetch_array($res3, MYSQLI_ASSOC); if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $row['region'] . " " . $row['country']); } $addres = new Address($row['unstructured_address']); $addres->setCountry($row['country']); $addres->setLatitude($row['latitude']); $addres->setLongitude($row['longitude']); $addres->setLocality($row['locality']); $addres->setPostalCode($row['postal_code']); $addres->setRegion($row['region']); $addres->setStreetAddress($row['street_address']); $addres->setType($row['address_type']); $organization->setAddress($address); } } */ $organizations[] = $organization; } $fetchedOrg = true; } if (isset($fields['schools']) || isset($fields['@all'])) { $res2 = mysql_query("SELECT * FROM " . TABLE_PREFIX . "social_member_education WHERE member_id = " . $member_id, $this->db); while ($row = mysql_fetch_assoc($res2)) { $organization = new Organization($row['university']); $organization->setDescription($row['description']); $organization->setEndDate($row['to']); $organization->setField($row['field']); $organization->setName($row['university']); $organization->setSalary(''); $organization->setStartDate($row['from']); $organization->setSubField(''); $organization->setTitle($row['degree']); $organization->setWebpage(''); $organization->setType('school'); //TODO: Address: To be implemented /* if ($row['address_id']) { $res3 = mysqli_query($db, "select * from ".TABLE_PREFIX."addresses where id = " . mysqli_real_escape_string($db, $row['address_id'])); if (mysqli_num_rows($res3)) { $row = mysqli_fetch_array($res3, MYSQLI_ASSOC); if (empty($row['unstructured_address'])) { $row['unstructured_address'] = trim($row['street_address'] . " " . $row['region'] . " " . $row['country']); } $addres = new Address($row['unstructured_address']); $addres->setCountry($row['country']); $addres->setLatitude($row['latitude']); $addres->setLongitude($row['longitude']); $addres->setLocality($row['locality']); $addres->setPostalCode($row['postal_code']); $addres->setRegion($row['region']); $addres->setStreetAddress($row['street_address']); $addres->setType($row['address_type']); $organization->setAddress($address); } } */ $organizations[] = $organization; } $fetchedOrg = true; } if ($fetchedOrg) { $person->setOrganizations($organizations); } //TODO languagesSpoken, currently missing the languages / countries tables so can't do this yet //TODO: Not in ATutor yet, skeleton field /* if (isset($fields['movies']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select movie from ".TABLE_PREFIX."person_movies where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setMovies($strings); } if (isset($fields['music']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select music from ".TABLE_PREFIX."person_music where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setMusic($strings); } */ if (isset($fields['phoneNumbers']) || isset($fields['@all'])) { $numbers = array(); $res2 = mysql_query("SELECT phone FROM " . TABLE_PREFIX . "members where member_id = " . $member_id, $this->db); if ($res2) { while ($number = mysql_fetch_assoc($res2)) { $numbers[] = new Phone($number, 'Home'); //default to 'Home' until ATutor supports Mobile, etc. } } $person->setPhoneNumbers($numbers); } /* if (isset($fields['ims']) || isset($fields['@all'])) { $ims = array(); $res2 = mysqli_query($db, "select value, value_type from ".TABLE_PREFIX."person_ims where person_id = " . $person_id); while (list($value, $type) = @mysqli_fetch_row($res2)) { $ims[] = new Im($value, $type); } $person->setIms($ims); } if (isset($fields['accounts']) || isset($fields['@all'])) { $accounts = array(); $res2 = mysqli_query($db, "select domain, userid, username from ".TABLE_PREFIX."person_accounts where person_id = " . $person_id); while (list($domain, $userid, $username) = @mysqli_fetch_row($res2)) { $accounts[] = new Account($domain, $userid, $username); } $person->setAccounts($accounts); } if (isset($fields['quotes']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select quote from ".TABLE_PREFIX."person_quotes where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setQuotes($strings); } if (isset($fields['sports']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select sport from ".TABLE_PREFIX."person_sports where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setSports($strings); } if (isset($fields['tags']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select tag from ".TABLE_PREFIX."person_tags where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setTags($strings); } if (isset($fields['turnOns']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select turn_on from ".TABLE_PREFIX."person_turn_ons where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setTurnOns($strings); } if (isset($fields['turnOffs']) || isset($fields['@all'])) { $strings = array(); $res2 = mysqli_query($db, "select turn_off from ".TABLE_PREFIX."person_turn_offs where person_id = " . $person_id); while (list($data) = @mysqli_fetch_row($res2)) { $strings[] = $data; } $person->setTurnOffs($strings); } */ if (isset($fields['urls']) || isset($fields['@all'])) { $strings = array(); $res2 = mysql_query("SELECT url, site_name FROM " . TABLE_PREFIX . "social_member_websites WHERE member_id = " . $member_id, $this->db); if ($res2) { while ($data = mysql_fetch_assoc($res2)) { /** * see * http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/opensocial-reference#opensocial.Url */ $strings[] = new Url($data['url'], null, $data['site_name']); } } $strings[] = new Url($this->url_prefix . '/profile/' . $member_id, null, 'profile'); // always include profile URL $person->setUrls($strings); } $ret[$member_id] = $person; } } try { $ret = $this->filterResults($ret, $options); $ret['totalSize'] = count($ret); } catch (Exception $e) { $ret['totalSize'] = count($ret) - 1; $ret['filtered'] = 'false'; } if ($first !== false && $max !== false && is_numeric($first) && is_numeric($max) && $first >= 0 && $max > 0) { $count = 0; $result = array(); foreach ($ret as $id => $person) { if ($id == 'totalSize' || $id == 'filtered') { $result[$id] = $person; continue; } if ($count >= $first && $count < $first + $max) { $result[$id] = $person; } ++$count; } return $result; } else { return $ret; } }
private static function enforceCurrentLocation(Person &$rawOSPerson) { $loc = $rawOSPerson->getCurrentLocation(); if (is_array($loc)) { $add = new Address($loc['city'] . ", " . $loc['state'] . " " . $loc['zip']); //$add->setgetUnstructuredAddress($loc['city'].", ".$loc['state']." ".$loc['zip']); $add->setExtendedAddress($loc['city'] . ", " . $loc['state'] . " " . $loc['zip'] . " " . $loc['country']); $add->setRegion($loc['state']); $add->setCountry($loc['country']); $add->setPostalCode($loc['zip']); $rawOSPerson->setCurrentLocation($add); } }