2016-11-10 96 views
1

我使用Consolibyte QB SDK found here,並且在大多數情況下是工作得很好。Consolibyte的Quickbooks PHP SDK(網絡接口) - 重複的任務

不過,我有一個情況我需要檢查是否已創建或更新的Quickbooks每次QB報告到我的服務器上的任何客戶,估計和銷售訂單。如果是這樣,上載新/更新的那些服務器。

我記得看到一些有關計劃任務(或重複任務或這種性質的東西)的文檔,但現在我不能找到它。

我不認爲我想Quickbooks的SQL鏡像打擾......似乎有點小題大做。有人能指引我朝着正確的方向嗎?

回答

2

下面是如何做你描述一個例子:

總結:

註冊登錄成功掛鉤 - 這是得到一個功能每次Web連接器啓動一個新的同步會話時都會調用它。

// An array of callback hooks 
$hooks = array(
    QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess',  // call this whenever a successful login occurs 
    ); 

https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector_import.php#L126

使用功能要排隊查詢任何新的請求。

function _quickbooks_hook_loginsuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config) 
{ 
    // For new users, we need to set up a few things 
    // Fetch the queue instance 
    $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance(); 
    $date = '1983-01-02 12:01:01'; 

    // Do the same for customers 
    if (!_quickbooks_get_last_run($user, QUICKBOOKS_IMPORT_CUSTOMER)) 
    { 
     _quickbooks_set_last_run($user, QUICKBOOKS_IMPORT_CUSTOMER, $date); 
    } 

    $Queue->enqueue(QUICKBOOKS_IMPORT_CUSTOMER, 1, QB_PRIORITY_CUSTOMER); 
} 

https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector_import.php#L219

寫您的請求/響應處理程序創建一個qbXML查詢請求修改的對象:

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>20</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 

     $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance(); 
     $Queue->enqueue(QUICKBOOKS_IMPORT_CUSTOMER, null, QB_PRIORITY_CUSTOMER, array('iteratorID' => $idents['iteratorID'])); 
    } 

    ... handle the XML blob from QuickBooks here ... 

    return true; 
} 

https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector_import.php#L472

+0

感謝詳細的解答基思。到底是什麼我以後。 –

+0

沒問題,我很高興我可以幫助! –