2016-03-03 74 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

相关问题