quickbooks online - 添加销售收据

时间:2016-11-07 10:08:31

标签: php quickbooks

我正在尝试创建一个将在线Quickbooks中添加销售收据的php页面。我使用的是Keith Palmer SDK,其中包含大量示例,但没有显示如何创建销售收据。我尝试过在网上找到的各种例子,但似乎都没有。

有人知道我可以用作起点的任何工作示例吗?

以下代码是我得到的最接近的代码,但它出现以下错误:业务验证错误:只能有一个详细类型未存入资金的帐户。

<?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>

非常感谢任何帮助或指示。

此外,使用KP SDK查找给定任务所需信息的最佳位置在哪里? (SDK下载似乎不提供任何帮助或参考文件)

1 个答案:

答案 0 :(得分:0)

错误消息几乎总结了这个问题:

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

听起来您需要为没有与之关联的税码的交易行分配税码。

转到Intuit的文档:

展开销售收据的对象属性,直到找到:

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.

更改您的代码,以便设置税码:

$SalesItemLineDetail->setTaxCodeRef('TAX');     // USA only
$SalesItemLineDetail->setTaxCodeRef('some Id value here');    // Non-USA