Exemplo n.º 1
0
 /**
  * Find a record by ID number 
  * 
  * 
  */
 protected function _findById($Context, $realmID, $resource, $IDType, $xml_or_IDType = '', $query = null)
 {
     $IPP = $Context->IPP();
     $flavor = $IPP->flavor();
     if (!$xml_or_IDType) {
         if ($flavor == QuickBooks_IPP_IDS::FLAVOR_DESKTOP) {
             $parse = QuickBooks_IPP_IDS::parseIDType($IDType);
             $xml_or_IDType = '';
             $xml_or_IDType .= '<?xml version="1.0" encoding="UTF-8"?>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '<' . $resource . 'Query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.intuit.com/sb/cdm/' . $IPP->version() . '">' . QUICKBOOKS_CRLF;
             if ($resource == QuickBooks_IPP_IDS::RESOURCE_CUSTOMER) {
                 $xml_or_IDType .= '<CustomFieldEnable>true</CustomFieldEnable>';
             }
             if ($query) {
                 $xml_or_IDType .= $query;
             }
             $xml_or_IDType .= '	<' . QuickBooks_IPP_IDS::resourceToKeyType($resource) . 'Set>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '		<Id idDomain="' . $parse['domain'] . '">' . $parse['ID'] . '</Id>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '	</' . QuickBooks_IPP_IDS::resourceToKeyType($resource) . 'Set>' . QUICKBOOKS_CRLF;
             $xml_or_IDType .= '</' . $resource . 'Query>';
         } else {
             if ($flavor == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
                 $xml_or_IDType = $IDType;
             }
         }
     }
     $return = $IPP->IDS($Context, $realmID, $resource, QuickBooks_IPP_IDS::OPTYPE_FINDBYID, $xml_or_IDType);
     $this->_setLastRequestResponse($Context->lastRequest(), $Context->lastResponse());
     $this->_setLastDebug($Context->lastDebug());
     if (count($return)) {
         return $return[0];
     }
     return null;
 }
Exemplo n.º 2
0
 protected function _IDS_v2($Context, $realmID, $resource, $optype, $xml, $ID)
 {
     if (substr($resource, 0, 6) == 'Report') {
         $resource = substr($resource, 6);
     }
     // This is because IDS v2 with QuickBooks Online is retarded
     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_PAYMENTMETHOD) {
         $resource = 'payment-method';
     } else {
         if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_SALESRECEIPT) {
             $resource = 'sales-receipt';
         } else {
             if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_TIMEACTIVITY) {
                 $resource = 'time-activity';
             } else {
                 if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_JOURNALENTRY) {
                     $resource = 'journal-entries';
                 } else {
                     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $resource == QuickBooks_IPP_IDS::RESOURCE_BILLPAYMENT) {
                         $resource = 'bill-payment';
                     }
                 }
             }
         }
     }
     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE and $optype == QuickBooks_IPP_IDS::OPTYPE_QUERY) {
         // Make the resource plural... (unless it's the changedatadeleted) *sigh*
         if ($resource == QuickBooks_IPP_IDS::RESOURCE_TIMEACTIVITY) {
             $resource = 'time-activities';
         } else {
             if ($resource == QuickBooks_IPP_IDS::RESOURCE_CLASS) {
                 $resource .= 'es';
             } else {
                 if ($resource != QuickBooks_IPP_IDS::RESOURCE_CHANGEDATADELETED) {
                     $resource .= 's';
                 }
             }
         }
     }
     $post = true;
     if ($resource == QuickBooks_IPP_IDS::RESOURCE_COMPANY or $resource == QuickBooks_IPP_IDS::RESOURCE_COMPANYMETADATA) {
         $post = false;
         $xml = '';
     }
     //$url = 'https://services.intuit.com/sb/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID;
     if ($this->flavor() == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
         if ($optype == QuickBooks_IPP_IDS::OPTYPE_FINDBYID) {
             $parse = QuickBooks_IPP_IDS::parseIDType($xml);
             $url = $this->_baseurl . '/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID . '/' . $parse[1];
             $post = false;
             $xml = null;
         } else {
             if ($optype == QuickBooks_IPP_IDS::OPTYPE_MOD) {
                 $parse = QuickBooks_IPP_IDS::parseIDType($ID);
                 $url = $this->_baseurl . '/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID . '/' . $parse[1];
             } else {
                 $url = $this->_baseurl . '/' . strtolower($resource) . '/' . $this->_ids_version . '/' . $realmID;
             }
         }
     }
     if ($optype == QuickBooks_IPP_IDS::OPTYPE_SYNCSTATUS) {
         $url = $this->_baseurl . '/status/v2/' . $realmID;
     } else {
         // Case matters on "syncActivity" #fun (everything else is lower cased)
         if (strtolower($resource) == 'syncactivity') {
             $resource = 'syncActivity';
         } else {
             $resource = strtolower($resource);
             // everything else should be lowercase
         }
         $url = $this->_baseurl . '/' . $resource . '/' . $this->_ids_version . '/' . $realmID;
     }
     //print('hitting URL [' . $url . ']');
     //print($xml);
     $response = $this->_request($Context, QuickBooks_IPP::REQUEST_IDS, $url, $optype, $xml, $post);
     //print($response);
     // Check for generic IPP errors and HTTP errors
     if ($this->_hasErrors($response)) {
         return false;
     }
     $data = $this->_stripHTTPHeaders($response);
     if (!$this->_ids_parser) {
         // If they don't want the responses parsed into objects, then just return the raw XML data
         return $data;
     }
     $start = microtime(true);
     //$Parser = new QuickBooks_IPP_Parser();
     $Parser = $this->_parserInstance();
     $xml_errnum = null;
     $xml_errmsg = null;
     $err_code = null;
     $err_desc = null;
     $err_db = null;
     // Try to parse the responses into QuickBooks_IPP_Object_* classes
     $parsed = $Parser->parseIDS($data, $optype, $this->flavor(), QuickBooks_IPP_IDS::VERSION_2, $xml_errnum, $xml_errmsg, $err_code, $err_desc, $err_db);
     $this->_setLastDebug(__CLASS__, array('ids_parser_duration' => microtime(true) - $start));
     if ($xml_errnum != QuickBooks_XML::ERROR_OK) {
         // Error parsing the returned XML?
         $this->_setError(QuickBooks_IPP::ERROR_XML, 'XML parser said: ' . $xml_errnum . ': ' . $xml_errmsg);
         return false;
     } else {
         if ($err_code != QuickBooks_IPP::ERROR_OK) {
             // Some other IPP error
             $this->_setError($err_code, $err_desc, 'Database error code: ' . $err_db);
             return false;
         }
     }
     // Return the parsed response
     return $parsed;
 }
<?php 
$InvoiceService = new QuickBooks_IPP_Service_Invoice();
$ItemService = new QuickBooks_IPP_Service_Item();
$invoices = $InvoiceService->query($Context, $realm, "SELECT *, Line.* FROM Invoice STARTPOSITION 1 MAXRESULTS 5");
//print_r($customers);
foreach ($invoices as $Invoice) {
    $num_lines = $Invoice->countLine();
    // How many line items are there?
    for ($i = 0; $i < $num_lines; $i++) {
        $Line = $Invoice->getLine($i);
        // Let's find out what item this uses
        if ($Line->getDetailType() == 'SalesItemLineDetail') {
            $Detail = $Line->getSalesItemLineDetail();
            $item_id = $Detail->getItemRef();
            print 'Item id is: ' . $item_id . "\n";
            $items = $ItemService->query($Context, $realm, "SELECT * FROM Item WHERE Id = '" . QuickBooks_IPP_IDS::usableIDType($item_id) . "' ");
            print '   That item is named: ' . $items[0]->getName() . "\n";
        }
    }
    print "\n\n\n";
}
/*
print("\n\n\n\n");
print('Request [' . $IPP->lastRequest() . ']');
print("\n\n\n\n");
print('Response [' . $IPP->lastResponse() . ']');
print("\n\n\n\n");
*/
?>

</pre>
Exemplo n.º 4
0
 public function asIDSXML($indent = 0, $parent = null, $optype = null, $flavor = null)
 {
     // We're not going to actually change the data, just change a copy of it
     $data = $this->_data;
     if (!$parent) {
         $parent = $this->resource();
     }
     if ($optype == QuickBooks_IPP_IDS::OPTYPE_ADD or $optype == QuickBooks_IPP_IDS::OPTYPE_MOD) {
         if ($flavor == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
             $xml = str_repeat("\t", $indent) . '<' . $this->resource() . ' xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:ns2="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:ns3="http://www.intuit.com/sb/cdm/qbo">' . QUICKBOOKS_CRLF;
         } else {
             $xml = str_repeat("\t", $indent) . '<Object xsi:type="' . $this->resource() . '">' . QUICKBOOKS_CRLF;
         }
         // Merge in the defaults for this object type
         $data = array_merge($this->_defaults(), $data);
     } else {
         if ($parent == 'CustomField') {
             $xml = str_repeat("\t", $indent) . '<' . $parent . ' xsi:type="StringTypeCustomField">' . QUICKBOOKS_CRLF;
         } else {
             $xml = str_repeat("\t", $indent) . '<' . $parent . '>' . QUICKBOOKS_CRLF;
         }
     }
     // Re-order is correctly
     $data = $this->_reorder($data);
     // Go through the data, creating XML out of it
     foreach ($data as $key => $value) {
         if (is_object($value)) {
             // If this causes problems, it can be commented out. It handles only situations where you are ->set(...)ing full objects, which can also be done by ->add(...)ing full objects instead
             $xml .= $value->asIDSXML($indent + 1, null, null, $flavor);
         } else {
             if (is_array($value)) {
                 foreach ($value as $skey => $svalue) {
                     //print('converting array: [' . $key . ' >> ' . $skey . ']');
                     if (is_object($svalue)) {
                         $xml .= $svalue->asIDSXML($indent + 1, $key, null, $flavor);
                     } else {
                         if (substr($key, -2, 2) == 'Id') {
                             $for_qbxml = false;
                             $tmp = QuickBooks_IPP_IDS::parseIdType($svalue);
                             if ($tmp[0]) {
                                 $xml .= str_repeat("\t", $indent + 1) . '<' . $key . ' idDomain="' . $tmp[0] . '">';
                             } else {
                                 $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                             }
                             $xml .= QuickBooks_XML::encode($tmp[1], $for_qbxml);
                             $xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                         } else {
                             //$for_qbxml = false;
                             //
                             //$xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                             //$xml .= QuickBooks_XML::encode($value, $for_qbxml);
                             //$xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                             $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>' . QuickBooks_XML::encode($svalue, false) . '</' . $key . '>' . QUICKBOOKS_CRLF;
                         }
                     }
                 }
             } else {
                 if (substr($key, -2, 2) == 'Id') {
                     $for_qbxml = false;
                     $tmp = QuickBooks_IPP_IDS::parseIdType($value);
                     if ($tmp[0]) {
                         $xml .= str_repeat("\t", $indent + 1) . '<' . $key . ' idDomain="' . $tmp[0] . '">';
                     } else {
                         $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                     }
                     $xml .= QuickBooks_XML::encode($tmp[1], $for_qbxml);
                     $xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                 } else {
                     $for_qbxml = false;
                     $xml .= str_repeat("\t", $indent + 1) . '<' . $key . '>';
                     $xml .= QuickBooks_XML::encode($value, $for_qbxml);
                     $xml .= '</' . $key . '>' . QUICKBOOKS_CRLF;
                 }
             }
         }
     }
     if ($optype == QuickBooks_IPP_IDS::OPTYPE_ADD or $optype == QuickBooks_IPP_IDS::OPTYPE_MOD) {
         if ($flavor == QuickBooks_IPP_IDS::FLAVOR_ONLINE) {
             $xml .= str_repeat("\t", $indent) . '</' . $this->resource() . '>' . QUICKBOOKS_CRLF;
         } else {
             $xml .= str_repeat("\t", $indent) . '</Object>' . QUICKBOOKS_CRLF;
         }
     } else {
         $xml .= str_repeat("\t", $indent) . '</' . $parent . '>' . QUICKBOOKS_CRLF;
     }
     return $xml;
 }
Exemplo n.º 5
0
 protected function _push($Node, $Object)
 {
     $name = $Node->name();
     $data = $Node->data();
     if (substr($name, -2, 2) == 'Id' or $name == 'ExternalKey' or substr($name, -3, 3) == 'Ref') {
         $data = QuickBooks_IPP_IDS::buildIDType($Node->getAttribute('idDomain'), $data);
     }
     $adds = array();
     if ($Node->hasChildren()) {
         $class = 'QuickBooks_IPP_Object_' . $name;
         $Subobject = new $class();
         foreach ($Node->children() as $Subnode) {
             $this->_push($Subnode, $Subobject);
         }
         $Object->{'add' . $name}($Subobject);
     } else {
         if (true or isset($adds[$name])) {
             $Object->{'add' . $name}($data);
         }
         /*else
         		{
         			if ($data == 'false')
         			{
         				$Object->{'set' . $name}(false);
         			}
         			else if ($data == 'true')
         			{
         				$Object->{'set' . $name}(true);
         			}
         			else
         			{
         				$Object->{'set' . $name}($data);
         			}
         		}*/
     }
     if ($Node->hasAttributes()) {
         //Don't make a new object, just put it as a property of the same one
         foreach ($Node->attributes() as $attr_name => $attr_value) {
             $Object->{'add' . $name . '_' . $attr_name}($attr_value);
         }
     }
 }
// Print the credentials we're using
//print_r($creds);
// This is our current realm
$realm = $creds['qb_realm'];
// Load the OAuth information from the database
if ($Context = $IPP->context()) {
    // Set the IPP version to v3
    $IPP->version(QuickBooks_IPP_IDS::VERSION_3);
    $CustomerService = new QuickBooks_IPP_Service_Customer();
    $InvoiceService = new QuickBooks_IPP_Service_Invoice();
    $customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer WHERE FamilyName = 'Palmer' ");
    //print_r($customers);
    if (count($customers)) {
        foreach ($customers as $Customer) {
            print 'Customer Id=' . $Customer->getId() . ' is named: ' . $Customer->getFullyQualifiedName() . '<br>';
            $invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE CustomerRef = '" . QuickBooks_IPP_IDS::usableIDType($Customer->getId()) . "' ");
            /*
            print("\n\n\n\n");
            print('Request [' . $IPP->lastRequest() . ']');
            print("\n\n\n\n");
            print('Response [' . $IPP->lastResponse() . ']');
            print("\n\n\n\n");
            exit;
            */
            if (count($invoices)) {
                foreach ($invoices as $Invoice) {
                    print ' &nbsp; &nbsp; Invoice #' . $Invoice->getDocNumber() . ' on date ' . $Invoice->getTxnDate() . '<br>';
                }
            } else {
                print ' &nbsp; &nbsp; This customer has no invoices.<br>';
            }
Exemplo n.º 7
0
 public function setTxnId($Id)
 {
     return $this->set('TxnId', QuickBooks_IPP_IDS::usableIDType($Id));
 }