简体   繁体   English

在PHP中使用API​​在Quickbooks中创建发票时出错

[英]Error creating Invoice in Quickbooks using API with PHP

I am trying to create invoice object in Quickbooks online sandbox account. 我正在尝试在Quickbooks在线沙箱帐户中创建发票对象。 Here is the Invoice Object docs https://developer.intuit.com/docs/api/accounting/Invoice which defines the simplest structure of an invoice object and I am using accordingly but still getting error. 这是发票对象docs https://developer.intuit.com/docs/api/accounting/Invoice ,它定义了发票对象的最简单结构,我正在相应地使用它,但仍然出现错误。 What is missing?? 什么东西少了??

 $invoiceObj = new \IPPInvoice();
 $Line = new \IPPLine(); 
 $Line->Amount = 30; 
 $Line->Description = "Test invoice line item";
 $Line->DetailType = "SalesItemLineDetail";
 $Line->AmountSpecified = true;
 $saleItemLineDetail = new \IPPSalesItemLineDetail();
 $saleItemRefType = new \IPPNameValue(); 
 $saleItemRefType->name = "Services";
 $saleItemRefType->value = "1";
 $saleItemLineDetail->ItemRef = $saleItemRefType;
 $saleItemLineDetail->ServiceDate = '2016-06-28';
 $Line->SalesItemLineDetail = $saleItemLineDetail;
 $invoiceObj->Line = $Line;
//$invoiceObj->DocNumber = '23713';
//$invoiceObj->TxnDate = '2016-06-28';
 $invoiceObj->DueDate = date(strtotime('+5 days'));
 $invoiceObj->AutoDocNumber = true;

 $customerRefType = new \IPPNameValue();  
 $customerRefType->name = "DisplayName969745229";
 $customerRefType->value = 58;
 $invoiceObj->CustomerRef = $customerRefType;
 $resultingObj = $dataService->Add($invoiceObj);
 echo "Created Invoice Id={$resultingObj->Id}. Reconstructed response body:\n\n";
 $xmlBody = \XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingObj, $urlResource);
    echo $xmlBody . "\n";

` `

This code throws the below error: 此代码引发以下错误:

IdsException: [0]: Required parameter Line.SalesItemLineDetail is missing in the request

Any help will be greatly appreciated. 任何帮助将不胜感激。 Thanks 谢谢

I figured it out myself I was setting properties using a wrong class IPPNameValue but it was supposed to be IPPReferenceType . 我自己弄清楚,我使用错误的类IPPNameValue设置属性,但应该是IPPReferenceType

Here is my working code for any one else having same issue in future. 这是我的其他任何将来遇到相同问题的工作代码。

$invoiceObj = new \IPPInvoice();
$Line = new \IPPLine(); 
$Line->Amount = 30; 
$Line->Description = "Test invoice line item";
$Line->DetailType = "SalesItemLineDetail";
$Line->AmountSpecified = true;
$saleItemLineDetail = new \IPPSalesItemLineDetail();
$saleItemRefType = new \IPPReferenceType(); 
$saleItemRefType->type = "Service";
$saleItemRefType->name = "Concrete";
$saleItemRefType->value = "1";
$saleItemLineDetail->ItemRef = $saleItemRefType;
$saleItemLineDetail->ServiceDate = '2016-06-28';

$Line->SalesItemLineDetail = $saleItemLineDetail;
$invoiceObj->Line = $Line;

$invoiceObj->DueDate = date(strtotime('+5 days'));
$invoiceObj->AutoDocNumber = true;

$customerRefType = new \IPPReferenceType();  
$customerRefType->type = 'Customer';
$customerRefType->name = "DisplayName969745229";
$customerRefType->value = 58;

$invoiceObj->CustomerRef = $customerRefType;

$resultingObj = $dataService->Add($invoiceObj);
// Echo some formatted output
echo "Created Invoice Id={$resultingObj->Id}. Reconstructed response body:\n\n";
        $xmlBody = \XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingObj, $urlResource);
        echo $xmlBody . "\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM