如何使用 'consolibyte/quickbooks-php' 从发票中删除行

How to remove lines from an Invoice using 'consolibyte/quickbooks-php'

有没有办法使用 Consolibyte quickbooks 工具包从发票中删除行?

我可以发送带有行的发票,但我也想更新发票,我认为最好的方法是删除每一行,然后按当前状态发送这些行。即:要更新发票,我首先会使用我在本地存储的 ref 从 quickbooks 获取发票,删除行,然后更新发票对象上的字段,然后添加新行,然后使用更新方法发送发票。

我看过这个例子:

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

但我不确定如何更新个别行,因为我没有对它们存储在本地的引用,因此尝试删除它们然后重新创建。

在这里找到答案:

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;
}