从QuickBooks导入客户(PHP WebKit)

时间:2013-01-18 10:48:09

标签: php quickbooks qwebkit qbxml

对于查询我使用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&lt;此方法返回错误然后在书中。

请帮我写一下来自Quickbooks的迭代器导入数据的正确查询。

1 个答案:

答案 0 :(得分: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 ...