当前位置: 动力学知识库 > 问答 > 编程问答 >

php - quickbooks online - Add Sales receipt

问题描述:

I'm trying to create a php page that will add a sales receipt into Quickbooks online. I am using the Keith Palmer SDK which comes with a lot of examples but nothing that shows how to create a sales receipt. I have tried various examples found online but none seem to work.

Does anybody know of any working example I could use as a start point?

The following code is the closest I got but it gives the following error: Business Validation Error: There can be only one account of detail type Undeposited Funds.

<?php

require_once dirname(__FILE__) . '/config.php';

require_once dirname(__FILE__) . '/views/header.tpl.php';

?>

<pre>

<?php

$SalesReceiptService = new QuickBooks_IPP_Service_SalesReceipt();

$SalesReceipt = new QuickBooks_IPP_Object_SalesReceipt();

$SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();

$Line = new QuickBooks_IPP_Object_Line();

$Line->setDetailType('SalesItemLineDetail');

$Line->setAmount(24);

$Line->setDescription("Testing");

/* Create new line detail object */

$SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();

$SalesItemLineDetail->setItemRef(19);

$SalesItemLineDetail->setUnitPrice(3);

$SalesItemLineDetail->setQty(8);

//Add Line Detail to the Sales Receipt Line

$Line->addSalesItemLineDetail($SalesItemLineDetail);

//Add Line to Sales Receipt

$SalesReceipt->addLine($Line);

$TxnTaxDetail = new QuickBooks_IPP_Object_TxnTaxDetail();

$TxnTaxDetail->setTxnTaxCodeRef(2);

$SalesReceipt->addTxnTaxDetail($TxnTaxDetail);

$SalesReceipt->setCustomerRef(72);

if ($resp = $SalesReceiptService->add($Context, $realm, $SalesReceipt))

{

print('Our new Sales Receipt ID is: [' . $resp . ']');

}

else

{

print('Error in posting invoice. '.$SalesReceiptService->lastError());

}

/*

print($IPP->lastError($Context));

print("\n\n\n\n");

print('Request [' . $IPP->lastRequest() . ']');

print("\n\n\n\n");

print('Response [' . $IPP->lastResponse() . ']');

print("\n\n\n\n");

*/

?>

</pre>

<?php

require_once dirname(__FILE__) . '/views/footer.tpl.php';

?>

//XML OUTPUT

REQUEST: POST https://sandbox-quickbooks.api.intuit.com/v3/company /123456789123456/salesreceipt?requestid=3505016a-a3ec-7794-a55f-c2422870442c& minorversion=6 HTTP/1.1

Content-Type: application/xml

Authorization: OAuth realm="", oauth_signature_method="HMAC-SHA1", oauth_signature="hss48**********lrqmh13MsaS0%3D", oauth_nonce="U65P0", oauth_timestamp="1478554059", oauth_token="qyprdI6U7kOfbZv**********t69nti4NrT4TgEOcOKpSX0C", oauth_consumer_key="qyprdT**********uMblouZakTiYrk", oauth_version="1.0"

Content-Length: 561

<SalesReceipt xmlns="http://schema.intuit.com/finance/v3">

<Line xmlns="http://schema.intuit.com/finance/v3">

<Amount>24</Amount>

<DetailType>SalesItemLineDetail</DetailType>

<Description>Testing</Description>

<SalesItemLineDetail xmlns="http://schema.intuit.com/finance/v3">

<ItemRef>19</ItemRef>

<UnitPrice>3</UnitPrice>

<Qty>8</Qty>

</SalesItemLineDetail>

</Line>

<TxnTaxDetail xmlns="http://schema.intuit.com/finance/v3">

<TxnTaxCodeRef>2</TxnTaxCodeRef>

</TxnTaxDetail>

<CustomerRef>72</CustomerRef>

</SalesReceipt>

RESPONSE: HTTP/1.1 400 Bad Request

Server: nginx

Date: Mon, 07 Nov 2016 21:27:33 GMT

Content-Type: application/xml

Content-Length: 492

Connection: keep-alive

Keep-Alive: timeout=5

Strict-Transport-Security: max-age=15552000

intuit_tid: gw-56191ae9-ecce-4713-b335-243cad4f7c2e

X-NewRelic-App-Data: PxQEVFFbAQoTVVlSDwEAUVYTGhE1AwE2QgNWEVlbQFtcC2VOfw5BDwVaXhsDB21BWThOVgcBa0lOE xoDTFZPUh5RAVAICgUGC0kMVwBNEVABV1ICBFNdAFUCA1oCVAZESFdXXxEDPg==

Vary: Accept-Encoding

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2016-11-07T13:27:39.703-08:00"><Fault type="ValidationFault"><Error code="6000" element=""><Message>A business validation error has occurred while processing your request</Message><Detail>Business Validation Error: One or more transaction lines do not have a tax code associated with it. Please assign a tax code for those lines.</Detail> </Error></Fault></IntuitResponse>

Any help or pointers here would be much appreciated.

Also, where is the best place to find the information required for a given task using the KP SDK? (The SDK download does not appear to provide any help or reference files)

网友答案:

The error message pretty much sums up the issue:

<Detail>Business Validation Error: One or more transaction lines do not have a tax code associated with it. Please assign a tax code for those lines.</Detail>

Sounds like you need to assign a tax code for the transaction lines that don't have a tax code associated with them.

Go to Intuit's documentation:

  • https://developer.intuit.com/docs/api/accounting/salesreceipt

Expand the object attributes for Sales Receipts until you find:

TaxCodeRef:
optional
ReferenceType 
Reference to the TaxCode for this item. Query the TaxCode name list resource to determine the appropriate TaxCode object to reference here. Use TaxCode.Id and TaxCode.Name from that object for TaxCodeRef.value and TaxCodeRef.name, respectively.

Change your code so that you set the tax code:

$SalesItemLineDetail->setTaxCodeRef('TAX');     // USA only
$SalesItemLineDetail->setTaxCodeRef('some Id value here');    // Non-USA
分享给朋友:
您可能感兴趣的文章:
随机阅读: