发票未插入快速簿中

时间:2018-12-03 11:21:17

标签: php quickbooks-online

我正在尝试使用此代码https://github.com/IntuitDeveloper/SampleApp-CRUD-PHP/blob/master/CRUD_Examples/Invoice/InvoiceCreate.php在Quickbook中创建具有多个产品/商品的发票,但是当数据需要forloop但传递时,变量 $ resultingObj 总是提供num值只有一个产品详细信息成功创建了发票。

我应用了此方法Inserting contents of array into object not working作为答案,但仍然为空。

发票:

   $num = 1;
        $Lines = [];

        foreach ($json as $rec) {



            foreach ($rec['products'] as $pro) {


                $productDetails = getItemObj($pro, $collection1);

                if ($productDetails == 'Error') {
                    continue;
                }

                $taxDetails = getTaxObj($dataService, $pro);

                if ($taxDetails == 'Error') {
                    continue;
                }

                $Lines[] =
                    [
                        "Id" => $num,
                        "Amount" => $pro['amount'],
                        "Description" => $pro['productDescription'],
                        "DetailType" => "SalesItemLineDetail",
                        "SalesItemLineDetail" => [
                            "ItemRef" => [
                                "value" => $productDetails->Id,
                            ],
                            "TaxCodeRef" => [
                                "value" => $taxDetails->Id
                            ],
                            "UnitPrice" => $pro['unitPrice'],
                            "Qty" => $pro['quantity'],
                        ]

                    ];

                $num++;


            }
            $Lines[] = [
                "Amount" => $rec['invoiceTotal'],
                "DetailType" => "SubTotalLineDetail",
                "SubTotalLineDetail" => []
            ];


            $customerRef = getCustomerObj($dataService, $rec['clientName']);


            $invoiceObj = Invoice::create([
                "Line" => $Lines,
                "CustomerRef" => [
                    "value" => $customerRef->Id
                ],

            ]);
            $resultingInvoiceObj = $dataService->Add($invoiceObj);

0 个答案:

没有答案