2016-03-03 33 views
0

有沒有使用Consolibyte quickbooks工具包從發票中刪除行的方法?如何使用'consolibyte/quickbooks-php'刪除發票中的行

我可以用行發送發票,但我也想更新發票,我認爲最好的方法是刪除每一行,然後發送行,因爲它們是目前。即:要更新發票,我首先使用本地庫存ref從快速存摺獲取發票,刪除行,然後更新發票對象上的字段,然後添加新行,然後使用更新方法發送發票。

我看到這個例子:

https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_invoice_update.php

但我不確定我怎麼會更新各行,因爲我有沒有提及它們存儲在本地,因此試圖刪除它們,然後重新創建。

回答

2

在這裏找到了答案:

How to access Quickbooks Invoice Line Items using php api

我的解決辦法是這樣的,使用Laravel:

public function qbUpdateInvoice(Invoice $invoice) 
{ 
    if ($invoice->qb_ref == null) { 
     throw new \Exception('Invoice Quickbooks ref not available.'); 
    } 

    $qbInvoice = $this->findInvoiceByRef($invoice); 

    $count = $qbInvoice->countLine(); 

    for ($i = 0; $i < $count; $i++) { 
     $qbInvoice->unsetLine($i); 
    } 

    $qbInvoice = $this->setInvoiceDetails($invoice, $qbInvoice); 
    $qbInvoice = $this->setInvoiceLines($invoice, $qbInvoice); 

    $response = $this->qbInvoiceService->update($this->context, $this->realm, $qbInvoice->getId(), $qbInvoice); 

    if (!$response) { 
     throw new \Exception($this->qbInvoiceService->lastError()); 
    } 

    return $response; 
} 
+0

我要嘗試實現這個使用Consolibyte與Laravel爲好,做這個解決方案適合你嗎? unsetLine和findInvoiceByRef函數是您編寫的Consolibyte工具包或函數的一部分嗎? –

+0

說實話,我不會推薦Consolibyte工具箱,因爲它有錯誤,你必須破解工具包才能正常工作。它也使用不推薦使用的函數,如果升級到PHP7,它將停止工作。您也無法直接使用Laravel DB連接。您必須創建單獨的數據庫連接,因爲它只接受DSN,並且不支持PDO。我最終選擇了Quickbooks的官方工具包,這也不完美。設置起來有點困難,但更加靈活。 – Steven1978

相關問題