2

对于查询,我使用 QB WebKit,所以我的查询如下所示:

$customer = new QuickBooks_Object_Customer();
$customer->set(...);
return QBXML_START . $customer->asQBXML('CustomerQueryRq') . QBXML_END;

但是对于迭代器方法它不起作用。所以我使用明文方法:

return '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="5.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<CustomerQueryRq requestID="' . $requestID . '" iterator="'. $iterator .'">
<MaxReturned>5</MaxReturned>
<OwnerID>0</OwnerID>
</CustomerQueryRq>
</QBXMLMsgsRq>
</QBXML>';

如果 MaxReturned < then 在 Book 中,此方法返回错误。

请帮我为 Quickbooks 中的迭代器导入数据编写正确的查询。

4

1 回答 1

3

你是对的 - QuickBooks_Object_Customer 类不适用于迭代器。您必须构建自己的 qbXML 请求。

话虽如此,这一切都在 DevKit 附带的示例之一中为您完成。

去获取QuickBooks PHP DevKit的每晚版本。

看看这个文件:docs/example_web_connector_import.php

代码应如下所示:

/**
 * Build a request to import customers already in QuickBooks into our application
 */
function _quickbooks_customer_import_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    // Iterator support (break the result set into small chunks)
    $attr_iteratorID = '';
    $attr_iterator = ' iterator="Start" ';
    if (empty($extra['iteratorID']))
    {
        // This is the first request in a new batch
        $last = _quickbooks_get_last_run($user, $action);
        _quickbooks_set_last_run($user, $action);           // Update the last run time to NOW()

        // Set the current run to $last
        _quickbooks_set_current_run($user, $action, $last);
    }
    else
    {
        // This is a continuation of a batch
        $attr_iteratorID = ' iteratorID="' . $extra['iteratorID'] . '" ';
        $attr_iterator = ' iterator="Continue" ';

        $last = _quickbooks_get_current_run($user, $action);
    }

    // Build the request
    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="' . $version . '"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <CustomerQueryRq ' . $attr_iterator . ' ' . $attr_iteratorID . ' requestID="' . $requestID . '">
                    <MaxReturned>25</MaxReturned>
                    <FromModifiedDate>' . $last . '</FromModifiedDate>
                    <OwnerID>0</OwnerID>
                </CustomerQueryRq>  
            </QBXMLMsgsRq>
        </QBXML>';

    return $xml;
}

/** 
 * 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
        $priority = 10;
        $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
        $Queue->enqueue(QUICKBOOKS_IMPORT_CUSTOMER, null, $priority, array( 'iteratorID' => $idents['iteratorID'] ));
    }
    ... do stuff with the data you got back here ...
于 2013-01-18T12:30:25.687 回答