我正在使用QuickBook ONline PHP SDK(最新版本)在现有发票中添加新的行项目,但是为此,我使用了QUickBOOK文档中的示例脚本,但这总是返回以下错误:无法使用QuickBooksOnline类型的对象\ API \ Data \ IPPLine作为数组
这是我的代码:- `
require_once("vendor/autoload.php");
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Core\Http\Serialization\XmlObjectSerializer;
use QuickBooksOnline\API\Core\OAuth\OAuth2\OAuth2LoginHelper;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\Line;
// Here is my OAuth token code
$targetInvoiceArray = $dataService->Query("select * from Invoice where DocNumber='7001'");
if(!empty($targetInvoiceArray) && sizeof($targetInvoiceArray) == 1){
$theInvoice = current($targetInvoiceArray);
}
$LineObj = Line::create([
"Description" => "Discount for Alex",
"Amount" => -10.00,
"DetailType" => "SalesItemLineDetail",
"SalesItemLineDetail" => [
"ItemRef" => [
"value" => 21,
"name" => "Discount"
]
]
]);
//Remove last element of Line Item.
$lineArray = array_pop($theInvoice->Line);
$lineArray[] = $LineObj;
// $lineArray.push($LineObj);
$updatedInvoice = Invoice::update($theInvoice, [
"sparse" => true,
"Line" => $lineArray
]);
$updatedResult = $dataService->Update($updatedInvoice);
`
脚本在此行$lineArray[] = $LineObj;
处抛出错误
答案 0 :(得分:0)
经过大量调试,我发现QuickBooks PHP SDK示例代码中存在错误。我通过更改几行代码解决了该问题:
替换以下几行:
$lineArray[] = $LineObj;
$updatedInvoice = Invoice::update($theInvoice, [
"sparse" => true,
"Line" => $lineArray
]);
使用此代码
$theInvoice->Line[] = $LineObj;
$updatedInvoice = Invoice::update($theInvoice, [
"sparse" => true
]);