/**
 * Handle a 500 not found error from QuickBooks
 * 
 * Instead of returning empty result sets for queries that don't find any 
 * records, QuickBooks returns an error message. This handles those error 
 * messages, and acts on them by adding the missing item to QuickBooks. 
 */
function _quickbooks_error_e500_notfound($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
    $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
    if ($action == QUICKBOOKS_IMPORT_INVOICE) {
        return true;
    } else {
        if ($action == QUICKBOOKS_IMPORT_CUSTOMER) {
            return true;
        } else {
            if ($action == QUICKBOOKS_IMPORT_SALESORDER) {
                return true;
            } else {
                if ($action == QUICKBOOKS_IMPORT_ITEM) {
                    return true;
                } else {
                    if ($action == QUICKBOOKS_IMPORT_PURCHASEORDER) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
/** 
 * Handle a response from QuickBooks 
 */
function _quickbooks_customer_import_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
    if (!empty($idents['iteratorRemainingCount'])) {
        // Queue up another request
        $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
        $Queue->enqueue(QUICKBOOKS_IMPORT_CUSTOMER, null, 0, array('iteratorID' => $idents['iteratorID']));
    }
    // This piece of the response from QuickBooks is now stored in $xml. You
    //	can process the qbXML response in $xml in any way you like. Save it to
    //	a file, stuff it in a database, parse it and stuff the records in a
    //	database, etc. etc. etc.
    //
    // The following example shows how to use the built-in XML parser to parse
    //	the response and stuff it into a database.
    // Import all of the records
    $errnum = 0;
    $errmsg = '';
    $Parser = new QuickBooks_XML_Parser($xml);
    if ($Doc = $Parser->parse($errnum, $errmsg)) {
        $Root = $Doc->getRoot();
        $List = $Root->getChildAt('QBXML/QBXMLMsgsRs/CustomerQueryRs');
        foreach ($List->children() as $Customer) {
            $values = array('ListID' => $Customer->getChildDataAt('CustomerRet ListID'), 'FullName' => $Customer->getChildDataAt('CustomerRet FullName'), 'FirstName' => $Customer->getChildDataAt('CustomerRet FirstName'), 'LastName' => $Customer->getChildDataAt('CustomerRet LastName'));
            foreach ($Customer->children() as $Node) {
                // Be careful! Custom field names are case sensitive!
                if ($Node->name() === 'DataExtRet' and $Node->getChildDataAt('DataExtRet DataExtName') == 'Your Custom Field Name Goes Here') {
                    $values['Your Custom Field Names Goes Here'] = $Node->getChildDataAt('DataExtRet DataExtValue');
                }
            }
            // Do something with that data...
            // mysql_query("INSERT INTO ... ");
        }
    }
    return true;
}