<?php require_once '../../QuickBooks.php'; $value = 'KeithPalmerJrFirstNameHere'; print QuickBooks_Cast::cast(QUICKBOOKS_OBJECT_CUSTOMER, 'Name', $value);
/** * Set a value within the object * * @param string $key * @param string $value * @return boolean */ public function set($key, $value, $cast = true) { if (is_array($value)) { $this->_object[$key] = $value; } else { //print('set(' . $key . ', ' . $value . ', ' . $cast . ')' . "\n"); if ($cast and $value != '__EMPTY__') { $value = QuickBooks_Cast::cast($this->object(), $key, $value, true, false); } //print(' setting [' . $key . '] to value {' . $value . '}' . "\n"); $this->_object[$key] = $value; } return true; }
public static function ReceivePaymentQueryRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale, $config = array()) { $xml = ''; //$iterator = QuickBooks_Callbacks_SQL_Callbacks::_buildIterator($extra); if (!QuickBooks_Callbacks_SQL_Callbacks::_requiredVersion(1.1, $version)) { return QUICKBOOKS_SKIP; } $tag1 = ''; $tag2 = ''; if (!empty($extra['TxnID'])) { $tag1 = ''; $tag1 .= '<TxnID>' . $extra['TxnID'] . '</TxnID>'; } else { if (!empty($extra['RefNumber'])) { $tag1 = ''; $tag1 .= '<RefNumber>' . $extra['RefNumber'] . '</RefNumber>'; } else { if (!empty($extra['Entity_FullName'])) { $tag2 = ''; $tag2 .= '<MaxReturned>' . QUICKBOOKS_SERVER_SQL_ITERATOR_MAXRETURNED . '</MaxReturned>'; $tag2 .= '<EntityFilter>' . QUICKBOOKS_CRLF; $tag2 .= "\t" . '<FullName>' . QuickBooks_Cast::cast(QUICKBOOKS_OBJECT_INVOICE, 'EntityFilter FullName', $extra['Entity_FullName']) . '</FullName>' . QUICKBOOKS_CRLF; $tag2 .= '</EntityFilter>' . QUICKBOOKS_CRLF; } else { if (!empty($extra['Entity_ListID'])) { $tag2 = ''; $tag2 .= '<MaxReturned>' . QUICKBOOKS_SERVER_SQL_ITERATOR_MAXRETURNED . '</MaxReturned>'; $tag2 .= '<EntityFilter>' . QUICKBOOKS_CRLF; $tag2 .= "\t" . '<ListID>' . $extra['Entity_ListID'] . '</ListID>' . QUICKBOOKS_CRLF; $tag2 .= '</EntityFilter>' . QUICKBOOKS_CRLF; } else { if (!empty($extra['FromModifiedDate']) and !empty($extra['ToModifiedDate'])) { $tag2 = ''; $tag2 .= '<MaxReturned>' . QUICKBOOKS_SERVER_SQL_ITERATOR_MAXRETURNED . '</MaxReturned>'; $tag2 .= '<ModifiedDateRangeFilter>' . QUICKBOOKS_CRLF; $tag2 .= "\t" . '<FromModifiedDate>' . QuickBooks_Utilities::datetime($extra['FromModifiedDate']) . '</FromModifiedDate>' . QUICKBOOKS_CRLF; $tag2 .= "\t" . '<ToModifiedDate>' . QuickBooks_Utilities::datetime($extra['ToModifiedDate']) . '</ToModifiedDate>' . QUICKBOOKS_CRLF; $tag2 .= '</ModifiedDateRangeFilter>' . QUICKBOOKS_CRLF; } else { return QUICKBOOKS_NOOP; } } } } } $xml .= '<?xml version="1.0" encoding="utf-8"?> <?qbxml version="' . $version . '"?> <QBXML> <QBXMLMsgsRq onError="' . QUICKBOOKS_SERVER_SQL_ON_ERROR . '"> <ReceivePaymentQueryRq> ' . $tag1 . ' ' . $tag2 . ' <IncludeLineItems>true</IncludeLineItems> ' . QuickBooks_Callbacks_SQL_Callbacks::_requiredVersionForElement(2.0, $version, '<OwnerID>0</OwnerID>') . ' </ReceivePaymentQueryRq> </QBXMLMsgsRq> </QBXML>'; return $xml; }
/** * * * * WARNING * * This function should *NOT* return an object! That behavior is *deprecated*! * * @param array $arr * @param array $map * @param QuickBooks_Object * @param string $type * @return null */ protected function _applyAddressMap($arr, $map, &$obj, $type) { if (!count($arr)) { return null; } // "ShipAddress" => "setShipAddress" foreach ($map as $addrtype => $method) { // Some integrators pass things like "ShipAddress_Address1" instead of "ShipAddress_Addr1" so we fix this here for ($i = 1; $i <= 5; $i++) { if (!empty($arr[$addrtype . '_Address' . $i]) and empty($arr[$addrtype . '_Addr' . $i])) { $arr[$addrtype . '_Addr' . $i] = $arr[$addrtype . '_Address' . $i]; } } // Compress empty address lines for ($i = 2; $i <= 5; $i++) { if (empty($arr[$addrtype . '_Addr' . ($i - 1)]) and !empty($arr[$addrtype . '_Addr' . $i])) { $arr[$addrtype . '_Addr' . ($i - 1)] = $arr[$addrtype . '_Addr' . $i]; $arr[$addrtype . '_Addr' . $i] = ''; } } // Default values $defaults = array('Addr1' => '', 'Addr2' => '', 'Addr3' => '', 'Addr4' => '', 'Addr5' => '', 'City' => '', 'State' => '', 'Province' => '', 'PostalCode' => '', 'Country' => '', 'Notes' => ''); foreach ($defaults as $key => $default) { // "ShipAddress_Addr1" if (!empty($arr[$addrtype . '_' . $key])) { // QUICKBOOKS_OBJECT_INVOICE, "ShipAddress Addr1", "56 Cowles Road" $casted = QuickBooks_Cast::cast($type, $addrtype . ' ' . $key, $arr[$addrtype . '_' . $key]); $defaults[$key] = $casted; } } $obj->{$method}($defaults['Addr1'], $defaults['Addr2'], $defaults['Addr3'], $defaults['Addr4'], $defaults['Addr5'], $defaults['City'], $defaults['State'], $defaults['Province'], $defaults['PostalCode'], $defaults['Country'], $defaults['Notes']); } return $obj; }
/** * Map a qbXML XML field type to it's SQL type definition * * @param string $object_type * @param string $field * @param string $qb_type * @return array * @TODO We case the input to lowercase, and so the array has to be in lowercase. Is there a better way to do this? */ public static function mapFieldToSQLDefinition($object_type, $field, $qb_type) { static $overrides = array('customer' => array('creditcardinfo_expirationmonth' => array(null, null, 'null'), 'creditcardinfo_expirationyear' => array(null, null, 'null')), 'estimate_estimateline' => array('quantity' => array(null, null, 'null')), 'salesorder_salesorderline' => array('quantity' => array(null, null, 'null')), 'purchaseorder_purchaseorderline' => array('quantity' => array(null, null, 'null')), 'invoice_invoiceline' => array('quantity' => array(null, null, 'null')), 'itemnoninventory' => array('salesorpurchase_price' => array(null, null, 'null'), 'salesorpurchase_pricepercent' => array(null, null, 'null'), 'salesorpurchase_salesprice' => array(null, null, 'null'), 'salesorpurchase_purchasecost' => array(null, null, 'null')), 'itemdiscount' => array('discountrate' => array(null, null, 'null'), 'discountratepercent' => array(null, null, 'null'))); $object_type = strtolower($object_type); $field = strtolower($field); $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 32; $default = null; // Default mappings for types switch ($qb_type) { case 'AMTTYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '10,2'; $default = 'null'; break; case 'PRICETYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '13,5'; $default = 'null'; break; case 'PERCENTTYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '12,5'; $default = 'null'; break; case 'DATETYPE': $type = QUICKBOOKS_DRIVER_SQL_DATE; $length = null; $default = 'null'; break; case 'DATETIMETYPE': $type = QUICKBOOKS_DRIVER_SQL_DATETIME; $length = null; $default = 'null'; break; case 'BOOLTYPE': $type = QUICKBOOKS_DRIVER_SQL_BOOLEAN; $length = null; $default = false; break; case 'INTTYPE': $type = QUICKBOOKS_DRIVER_SQL_INTEGER; $length = null; $default = 0; break; case 'QUANTYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '12,5'; $default = 0; break; case 'IDTYPE': $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 40; $default = 'null'; break; case 'ENUMTYPE': $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 40; $default = 'null'; break; case 'STRTYPE': default: //print('casting: ' . $object_type . "\n"); //print('field: ' . $field . "\n"); $x = str_repeat('x', 10000); $length = strlen(QuickBooks_Cast::cast($object_type, $field, $x)); // All FullName and *_FullName fields should be VARCHAR(255) so we can add INDEXes to them if ($length > 255 and strtolower(substr($field, -8)) == 'fullname') { $length = 255; } // If the length is really long, put it in a TEXT field instead of a VARCHAR if ($length > 255) { $type = QUICKBOOKS_DRIVER_SQL_TEXT; } else { $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; } $default = 'null'; if ($field == 'EditSequence') { $length = 16; } else { if (isset($overrides[$object_type][$field])) { // if (!is_null($overrides[$object_type][$field][2])) { $default = $overrides[$object_type][$field][2]; } } } break; } // Overrides for mappings that couldn't be done automatically /*switch ($object_type) { case 'invoice': switch ($field) { default: break; } default: switch ($field) { case 'isactive': $default = true; break; default: break; } break; }*/ //@TODO -- Keith, is this a good way to accomplish converting all txnid/listid fields to varchar? ~Garrett if (stripos($field, "listid") !== false || stripos($field, "txnid") !== false) { $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 40; $default = 'null'; } if (isset($overrides[$object_type][$field])) { if (!is_null($overrides[$object_type][$field][0])) { $type = $overrides[$object_type][$field][0]; } if (!is_null($overrides[$object_type][$field][1])) { $length = $overrides[$object_type][$field][1]; } if (!is_null($overrides[$object_type][$field][2])) { $default = $overrides[$object_type][$field][2]; } } return array($type, $length, $default); }
/** * Alias of {QuickBooks_Cast::cast()} * * @deprecated Use the QuickBooks_Cast class instead! */ public static function castToField($object_type, $field_name, $value, $use_abbrevs = true, $htmlspecialchars = true) { return QuickBooks_Cast::cast($object_type, $field_name, $value, $use_abbrevs, $htmlspecialchars); }
/** * * * @param array $arr * @param array $map * @param QuickBooks_Object * @param string $type * @param string $type * @return QuickBooks_Object */ protected function _applyBaseMap($arr, $map, $obj, $type, $path = '') { if ($path) { $path = trim($path) . ' '; } foreach ($map as $field => $tmp) { if (!empty($arr[$field])) { $set = true; $method = $tmp[0]; $qbfield = $tmp[1]; $resolve = false; if (!empty($tmp[2])) { $resolve = $tmp[2]; } $value = $arr[$field]; if ($qbfield and !strlen($resolve)) { // Cast $value $value = QuickBooks_Cast::cast($type, $path . $qbfield, $value); } else { if ($qbfield and strlen($resolve)) { // Try to resolve a value to a ListID or TxnID $obj->{$method}($value); $encode = $obj->get($qbfield); $obj->remove($qbfield); $reftype = null; $reftag = null; $refid = null; $obj->decodeApplicationID($encode, $reftype, $reftag, $refid); $API = QuickBooks_API_Singleton::getInstance(); if ($ListID_or_TxnID = $API->fetchQuickBooksID($reftype, $value)) { $obj->{$resolve}($ListID_or_TxnID); $set = false; } } } if ($set) { $obj->{$method}($value); } } } return $obj; }
/** * Cast a value to ensure that it will fit in a particular field within QuickBooks * * QuickBooks has some strange length limits on some fields (the max. * length of the CompanyName field for Customers is only 41 characters, * etc.) so this method provides an easy way to cast the data type and data * length of a value to the correct type and length for a specific field. * * @param string $object_type The QuickBooks object type (Customer, Invoice, etc.) * @param string $field_name The QuickBooks field name (these correspond to the qbXML field names: Addr1, Name, CompanyName, etc.) * @param mixed $value The value you want to cast * @param boolean $use_abbrevs There are a lot of strings which can be abbreviated to shorten lengths, this is whether or not you want to use those abbrevaitions ("University" to "Univ.", "Incorporated" to "Inc.", etc.) * @param boolean $htmlspecialchars * @return string */ public static function cast($type_or_action, $field, $value, $use_abbrevs = true, $htmlspecialchars = true) { $type_or_action = strtolower($type_or_action); if ($htmlspecialchars) { $entities = array('&' => '&', '<' => '<', '>' => '>', '\'' => ''', '"' => '"'); // First, *unreplace* things so that we don't double escape them $value = str_replace(array_values($entities), array_keys($entities), $value); // Then, replace XML entities $value = str_replace(array_keys($entities), array_values($entities), $value); //$value = htmlspecialchars($value, ENT_QUOTES, null, false); } $types = array(); $types3 = array(); $types5 = array(); $files = array(); // @TODO Optimize this so that it doesn't have to read this directory on *every* cast (singleton pattern) $dh = opendir(dirname(__FILE__) . '/QBXML/Schema/Object'); while (false !== ($file = readdir($dh))) { if ($file[0] == '.' or substr($file, -6, 6) != 'Rq.php') { continue; } $files[] = $file; } sort($files); foreach ($files as $file) { $substr = substr($file, 0, -4); $substrlower = strtolower($substr); $types[$substrlower] = $substr; $substr3 = substr($file, 0, -3 + -3); $substr3lower = strtolower($substr3); $substr5 = substr($file, 0, -3 + -6); $substr5lower = strtolower($substr5); if (!isset($types3[$substr3lower])) { $types3[$substr3lower] = $substr; } if (!isset($types5[$substr5lower])) { $types5[$substr5lower] = $substr; } } /* print(' looking for schema: ' . $type_or_action . "\n"); print_r($types); print_r($types3); print_r($types5); */ if (isset($types[$type_or_action])) { require_once 'QuickBooks/QBXML/Schema/Object/' . $types[$type_or_action] . '.php'; $class = 'QuickBooks_QBXML_Schema_Object_' . $types[$type_or_action]; $schema = new $class(); } else { if (isset($types3[$type_or_action])) { require_once 'QuickBooks/QBXML/Schema/Object/' . $types3[$type_or_action] . '.php'; $class = 'QuickBooks_QBXML_Schema_Object_' . $types3[$type_or_action]; $schema = new $class(); } else { if (isset($types5[$type_or_action])) { require_once 'QuickBooks/QBXML/Schema/Object/' . $types5[$type_or_action] . '.php'; $class = 'QuickBooks_QBXML_Schema_Object_' . $types5[$type_or_action]; $schema = new $class(); } else { return $value; } } } //print(' casting using schema: ' . get_class($schema) . "\n"); if (!$schema->exists($field) and false !== strpos($field, '_')) { $field = str_replace('_', ' ', $field); } if ($schema->exists($field)) { switch ($schema->dataType($field)) { case QUICKBOOKS_DATATYPE_STRING: $maxlength = $schema->maxLength($field); // Use only ASCII characters $value = QuickBooks_Cast::_castCharset($value); // Make sure it'll fit in the allocated field length if (is_int($maxlength) and $maxlength > 0) { $value = QuickBooks_Cast::_castTruncate($value, $maxlength, $use_abbrevs); } break; case QUICKBOOKS_DATATYPE_DATE: $value = date('Y-m-d', strtotime($value)); break; case QUICKBOOKS_DATATYPE_DATETIME: $value = date('Y-m-d', strtotime($value)) . 'T' . date('H:i:s', strtotime($value)); break; case QUICKBOOKS_DATATYPE_ENUM: // do nothing break; case QUICKBOOKS_DATATYPE_ID: // do nothing break; case QUICKBOOKS_DATATYPE_FLOAT: $value = (double) $value; break; case QUICKBOOKS_DATATYPE_BOOLEAN: if ($value) { $value = 'true'; } else { $value = 'false'; } break; case QUICKBOOKS_DATATYPE_INTEGER: $value = (int) $value; break; } } /* if ($htmlspecialchars) { $entities = array( '&' => '&', '<' => '<', '>' => '>', '\'' => ''', '"' => '"', ); // First, *unreplace* things so that we don't double escape them $value = str_replace(array_values($entities), array_keys($entities), $value); // Then, replace XML entities $value = str_replace(array_keys($entities), array_values($entities), $value); //$value = htmlspecialchars($value, ENT_QUOTES, null, false); } */ return $value; }
<?php require_once '../QuickBooks.php'; header('Content-Type: text/html; charset=utf-8'); print 'null date: ' . QuickBooks_Cast::cast(QUICKBOOKS_ADD_SALESORDER, 'ShipDate', null); print "\n"; print 'empty date: ' . QuickBooks_Cast::cast(QUICKBOOKS_ADD_SALESORDER, 'ShipDate', ''); print "\n"; print 'real date: ' . QuickBooks_Cast::cast(QUICKBOOKS_ADD_SALESORDER, 'ShipDate', 'Jan 5 2012'); print "\n"; print "\n\n\n"; $arr = array('Keith Palmer, Shannon Daniels, Kurtis & Karli', 'Test of some UTF8 chars- Á, Æ, Ë, ¾, Õ, ä, ß, ú, ñ', 'Test & Then Some', 'Test of already encoded & data.', 'Tapio Törmänen', 'Here is the £ pound sign for you British gents...'); $fields = array('Name', 'CompanyName', 'FirstName', 'LastName', 'BillAddress_Addr1', 'BillAddress_Addr2', 'BillAddress_Addr3', 'BillAddress_City', 'BillAddress_State', 'BillAddress_Country', 'BillAddress_PostalCode', 'ShipAddress_Addr1', 'ShipAddress_Addr2', 'ShipAddress_Addr3', 'ShipAddress_City', 'ShipAddress_State', 'ShipAddress_Country', 'ShipAddress_PostalCode', 'Phone', 'AltPhone', 'Fax', 'Email', 'Contact', 'AltContact'); print "\n"; foreach ($fields as $field) { foreach ($arr as $key => $value) { $cast = QuickBooks_Cast::cast(QUICKBOOKS_ADD_CUSTOMER, str_replace('_', ' ', $field), ucfirst($value)); print "\t" . $field . ': {' . $cast . '} (length: ' . strlen($cast) . ')' . "\n"; } print "\n"; } print "\n"; exit; $invoice = array('IsPaid' => true, 'IsToBePrinted' => false, 'IsToBeEmailed' => true, 'IsFinanceCharge' => false, 'IsPending' => true); foreach ($invoice as $key => $value) { print $key . ' => ' . QuickBooks_Cast::cast(QUICKBOOKS_ADD_INVOICE, $field, $value) . "\n"; }
<?php require_once '../QuickBooks.php'; $arr = array('Cable Raceway/Wire Chase, 1.25" x 6\', White', ' à â ', 'desempeños artísticos', 'Zugängliche', 'investigación', 'desempeños artísticos', 'desempeños artísticos', 'Zugängliche investigación'); foreach ($arr as $str) { print "\n\n" . '{' . QuickBooks_Cast::cast(QUICKBOOKS_ADD_INVOICE, 'InvoiceLineAdd Desc', html_entity_decode($str)) . '}' . "\n\n"; }
/** * Map a qbXML XML field type to it's SQL type definition * * @param string $object_type * @param string $field * @param string $qb_type * @return array * @TODO We case the input to lowercase, and so the array has to be in lowercase. Is there a better way to do this? */ public static function mapFieldToSQLDefinition($object_type, $field, $qb_type) { // array( type, length, default ) static $overrides = array('billpaymentcheck' => array('istobeprinted' => array(null, null, 'null')), 'check' => array('istobeprinted' => array(null, null, 'null')), 'creditmemo' => array('ispending' => array(null, null, 'null')), 'creditmemo_creditmemoline' => array('creditcardtxninputinfo_expirationmonth' => array(null, null, 'null'), 'creditcardtxninputinfo_expirationyear' => array(null, null, 'null'), 'creditcardtxnresultinfo_resultcode' => array(null, null, 'null'), 'creditcardtxnresultinfo_paymentgroupingcode' => array(null, null, 'null'), 'creditcardtxnresultinfo_txnauthorizationstamp' => array(null, null, 'null')), 'creditmemo_creditmemolinegroup_creditmemoline' => array('creditcardtxninfo_creditcardtxninputinfo_expirationmonth' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxninputinfo_expirationyear' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_resultcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_paymentgroupingcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_txnauthorizationstamp' => array(null, null, 'null')), 'customer' => array('creditcardinfo_expirationmonth' => array(null, null, 'null'), 'creditcardinfo_expirationyear' => array(null, null, 'null')), 'employee' => array('employeepayrollinfo_clearearnings' => array(null, null, 'null'), 'employeepayrollinfo_isusingtimedatatocreatepaychecks' => array(null, null, 'null'), 'employeepayrollinfo_sickhours_isresettinghourseachnewyear' => array(null, null, 'null'), 'employeepayrollinfo_vacationhours_isresettinghourseachnewyear' => array(null, null, 'null')), 'estimate' => array('istobeemailed' => array(null, null, 'null')), 'estimate_estimateline' => array('quantity' => array(null, null, 'null')), 'itemnoninventory' => array('salesorpurchase_price' => array(null, null, 'null'), 'salesorpurchase_pricepercent' => array(null, null, 'null'), 'salesorpurchase_salesprice' => array(null, null, 'null'), 'salesorpurchase_purchasecost' => array(null, null, 'null')), 'itemdiscount' => array('discountrate' => array(null, null, 'null'), 'discountratepercent' => array(null, null, 'null')), 'inventoryadjustment_inventoryadjustmentline' => array('quantityadjustment_newquantity' => array(null, null, 'null'), 'quantityadjustment_quantitydifference' => array(null, null, 'null'), 'valueadjustment_newquantity' => array(null, null, 'null'), 'valueadjustment_quantitydifference' => array(null, null, 'null'), 'valueadjustment_newvalue' => array(null, null, 'null'), 'valueadjustment_valuedifference' => array(null, null, 'null')), 'invoice' => array('ispending' => array(null, null, 'null'), 'isfinancecharge' => array(null, null, 'null'), 'ispaid' => array(null, null, 'null'), 'istobeprinted' => array(null, null, 'null'), 'istobeemailed' => array(null, null, 'null')), 'invoice_invoiceline' => array('quantity' => array(null, null, 'null')), 'purchaseorder' => array('ismanuallyclosed' => array(null, null, 'null'), 'isfullyreceived' => array(null, null, 'null'), 'istobeprinted' => array(null, null, 'null'), 'istobeemailed' => array(null, null, 'null')), 'purchaseorder_purchaseorderline' => array('ismanuallyclosed' => array(null, null, 'null'), 'receivedquantity' => array(null, null, 'null'), 'quantity' => array(null, null, 'null')), 'receivepayment' => array('creditcardtxninfo_creditcardtxninputinfo_expirationmonth' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxninputinfo_expirationyear' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_resultcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_paymentgroupingcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_txnauthorizationstamp' => array(null, null, 'null')), 'salesorder' => array('ismanuallyclosed' => array(null, null, 'null'), 'isfullyinvoiced' => array(null, null, 'null'), 'istobeprinted' => array(null, null, 'null'), 'istobeemailed' => array(null, null, 'null')), 'salesorder_salesorderline' => array('quantity' => array(null, null, 'null'), 'invoiced' => array(null, null, 'null'), 'ismanuallyclosed' => array(null, null, 'null')), 'salesreceipt' => array('ispending' => array(null, null, 'null'), 'istobeprinted' => array(null, null, 'null'), 'istobeemailed' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxninputinfo_expirationmonth' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxninputinfo_expirationyear' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_resultcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_paymentgroupingcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_txnauthorizationstamp' => array(null, null, 'null')), 'salesreceipt_salesreceiptline' => array('quantity' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxninputinfo_expirationmonth' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxninputinfo_expirationyear' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_resultcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_paymentgroupingcode' => array(null, null, 'null'), 'creditcardtxninfo_creditcardtxnresultinfo_txnauthorizationstamp' => array(null, null, 'null'))); $object_type = strtolower($object_type); $field = strtolower($field); $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 32; $default = null; // Default mappings for types switch ($qb_type) { case 'AMTTYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '10,2'; $default = 'null'; break; case 'PRICETYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '13,5'; $default = 'null'; break; case 'PERCENTTYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '12,5'; $default = 'null'; break; case 'DATETYPE': $type = QUICKBOOKS_DRIVER_SQL_DATE; $length = null; $default = 'null'; break; case 'DATETIMETYPE': $type = QUICKBOOKS_DRIVER_SQL_DATETIME; $length = null; $default = 'null'; break; case 'BOOLTYPE': $type = QUICKBOOKS_DRIVER_SQL_BOOLEAN; $length = null; $default = false; break; case 'INTTYPE': $type = QUICKBOOKS_DRIVER_SQL_INTEGER; $length = null; $default = 0; break; case 'QUANTYPE': $type = QUICKBOOKS_DRIVER_SQL_DECIMAL; $length = '12,5'; $default = 0; break; case 'IDTYPE': $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 40; $default = 'null'; break; case 'ENUMTYPE': $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 40; $default = 'null'; break; case 'STRTYPE': default: //print('casting: ' . $object_type . "\n"); //print('field: ' . $field . "\n"); $x = str_repeat('x', 10000); $length = strlen(QuickBooks_Cast::cast($object_type, $field, $x)); // All FullName and *_FullName fields should be VARCHAR(255) so we can add INDEXes to them if ($length > 255 and strtolower(substr($field, -8)) == 'fullname') { $length = 255; } // If the length is really long, put it in a TEXT field instead of a VARCHAR if ($length > 255) { $type = QUICKBOOKS_DRIVER_SQL_TEXT; } else { $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; } $default = 'null'; if ($field == 'EditSequence') { $length = 16; } else { if (isset($overrides[$object_type][$field])) { // if (!is_null($overrides[$object_type][$field][2])) { $default = $overrides[$object_type][$field][2]; } } } break; } // Overrides for mappings that couldn't be done automatically /*switch ($object_type) { case 'invoice': switch ($field) { default: break; } default: switch ($field) { case 'isactive': $default = true; break; default: break; } break; }*/ // @TODO -- Keith, is this a good way to accomplish converting all txnid/listid fields to varchar? ~Garrett if (stripos($field, 'listid') !== false or stripos($field, 'txnid') !== false) { $type = QUICKBOOKS_DRIVER_SQL_VARCHAR; $length = 40; $default = 'null'; } else { if (strtolower($field) == 'sortorder') { $type = QUICKBOOKS_DRIVER_SQL_INTEGER; $length = null; $default = 0; } } if (isset($overrides[$object_type][$field])) { if (!is_null($overrides[$object_type][$field][0])) { $type = $overrides[$object_type][$field][0]; } if (!is_null($overrides[$object_type][$field][1])) { $length = $overrides[$object_type][$field][1]; } if (!is_null($overrides[$object_type][$field][2])) { $default = $overrides[$object_type][$field][2]; } } return array($type, $length, $default); }
/** * Decode a UTF-8 string to an entity encoded string * * @param string $string Encoded string * @return string Decoded string */ protected static function _decodeUTF8($string) { // don't do decoding when there are no 8bit symbols if (!QuickBooks_Cast::_is8Bit($string, 'utf-8')) { return $string; } // decode four byte unicode characters $string = preg_replace_callback("/([ð-÷])([€-¿])([€-¿])([€-¿])/", function ($arr) { $val = (ord($arr[1]) - 240) * 262144 + (ord($arr[2]) - 128) * 4096 + (ord($arr[3]) - 128) * 64 + (ord($arr[4]) - 128); return "&#" . $val . ";"; }, $string); // decode three byte unicode characters $string = preg_replace_callback("/([à-ï])([€-¿])([€-¿])/", function ($arr) { $val = (ord($arr[1]) - 224) * 4096 + (ord($arr[2]) - 128) * 64 + (ord($arr[3]) - 128); return "&#" . $val . ";"; }, $string); // decode two byte unicode characters $string = preg_replace_callback("/([À-ß])([€-¿])/", function ($arr) { $val = (ord($arr[1]) - 192) * 64 + (ord($arr[2]) - 128); return "&#" . $val . ";"; }, $string); // remove broken unicode $string = preg_replace("/[€-Ÿ]| |[¡-ÿ]/", '?', $string); return $string; }