本文介绍了使用 PHP 在 Quick Books 桌面上使用非库存项目创建发票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一张包含从我的网站到 Quick book 桌面应用程序的非库存项目的发票.我正在使用以下 github 存储库:https://github.com/consolibyte/quickbooks-php

请帮帮我,如何为非库存项目创建发票?

我添加了示例代码来创建包含非库存项目的发票:

 array('_quickbooks_invoice_add_request', '_quickbooks_invoice_add_response'));$errmap = array(3070 =>'_quickbooks_error_stringtoolong');$hooks = array();$log_level = QUICKBOOKS_LOG_DEBUG;$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;$soap_options = array();$handler_options = array( 'deny_concurrent_logins' => false,'deny_reallyfast_logins' =>错误的,);$driver_options = array();$callback_options = array();$dsn = 'mysqli://root:password@localhost/quickbooks';$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);$response = $Server->handle(true, true);$Queue = new QuickBooks_WebConnector_Queue($dsn);$Queue->enqueue(QUICKBOOKS_ADD_INVOICE, $primary_key_of_your_customer);函数_quickbooks_invoice_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale){$xml = '<?xml version="1.0" encoding="utf-8"?><?qbxml version="13.0"?><QBXML><QBXMLMsgsRq onError="stopOnError"><InvoiceAddRq><InvoiceAdd defMacro="MACROTYPE"><客户参考><ListID >80000257-1578565322</ListID><全名>ConsoliBYTE, LLC (1001546518)</全名></CustomerRef><RefNumber >STRTYPE</RefNumber><账单地址><Addr1>Addr1</Addr1><Addr2>Addr2</Addr2><City >indore</City><状态>TX</状态><邮政编码>482201</邮政编码><国家>美国</国家><注意>注意</注意></账单地址><发货地址><Addr1>旧宫</Addr1><Addr2>stree 123</Addr2><City >Katni</City><状态>TX</状态><邮政编码 >48002</邮政编码><国家>美国</国家><注意>运输</注意></ShipAddress><IsPending >true</IsPending><PONumber>PONumber</PONumber><ShipMethodRef><ListID ></ListID><全名>联邦快递</全名></ShipMethodRef><其他>其他</其他><发票行添加><ItemRef><全名>项目</全名></ItemRef><item Desc><数量>1</数量><UnitOfMeasure>UnitOfMeasure</UnitOfMeasure><速率>1.5</速率><数量>1.5</数量><其他1>其他1</其他1><其他2>其他2</其他2></InvoiceLineAdd></发票添加></InvoiceAddRq></QBXMLMsgsRq></QBXML>';返回 $xml;}函数_quickbooks_invoice_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents){}function _quickbooks_error_stringtoolong($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg){}
解决方案

看起来您走对了这里.让我们谈谈您收到的具体错误消息:

3040:在金额"字段中转换金额1.5"时出错

QuickBooks 中的美元金额有 2 位小数.例如您需要发送:

<金额>1.50</金额>

3140:发票中对 QuickBooks 运送方法Fedex"的引用无效.QuickBooks 错误消息:无效参数.列表中不存在指定的记录.

QuickBooks 的核心是一个关系数据库.将 ShipMethodRef/FullName(和/或 ShipMethodRef/ListID)视为外键约束.

如果您尝试插入某些内容并引用不存在的外键,则会出现错误.所以你要么需要:

  1. 进入 QuickBooks UI,并创建一个名为 Fedex 的发货方法(这可能是您的最佳选择,因为 Ship Method 往往不会经常更改并且通常有不要太多.在 QuickBooks 中选择 Lists > Customer & Vendor Profile Lists > Item List )

  1. 进行 ShipMethodAdd 调用以创建 Ship 方法(文档:https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/shipmethodadd )

  1. 如果您根本不想设置 ,则可以完全省略它

您还应该决定是要发送ListID 还是FullName.不要同时发送,它只会使错误更加混乱.我建议您只发送 FullName.如果您想发送 ListID,您必须查询 QuickBooks 以获取 ListID 值(它们不会显示在 QuickBooks UI 中).

3140:发票行中对 QuickBooks 项目项目"的引用无效.QuickBooks 错误消息:无效参数.列表中不存在指定的记录.

这是一个与上述 ShipMethod 错误非常相似的错误.您引用了一个项目:

<全名>项目</全名></ItemRef>

QuickBooks 告诉您该项目不存在.与 Ship Method 类似,您必须:

  1. 通过 QuickBooks UI 创建(或使用现有项目)(在 QuickBooks 中选择 Lists > Item List )

  1. 通过 API 创建它(文档:https:///developer.intuit.com/app/developer/qbdesktop/docs/api-reference/itemnoninventoryadd )

此处没有选项 3.,因为它是发票的必填字段.

由于您刚刚开始使用 QuickBooks 开发,我强烈建议您使用上面的选项 1..

处理 2. 仅在您需要时,并且在您掌握了集成的基础之后(例如,一旦您看到一些发票实际上已成功创建).

另一件需要注意的事情——QuickBooks 有一个子项目"的概念.可以这样想:

衬衫>T恤>红色 T 恤>蓝色 T 恤>绿色 T 恤

每一个都是一个Item但是因为它们在一个嵌套的层次结构中(例如T-Shirts是一个Shirts 的 item/sub-item) FullName反映该层次结构:

衬衫(名称=衬衫,全名=衬衫)>T 恤(名称=T 恤,全名=衬衫:T 恤)>红色 T 恤(名称 = 红色 T 恤,全名 = 衬衫:T 恤:红色 T 恤)>蓝色 T 恤(名称 = 红色 T 恤,全名 = 衬衫:T 恤:蓝色 T 恤)>绿色 T 恤(名称 = 红色 T 恤,全名 = 衬衫:T 恤:绿色 T 恤)

因此,如果您在 QuickBooks 中看到该项目...但您仍然收到关于 FullName 的错误,请确保您确实使用了整个 FullName 而不是只是事物的Name.

I want to create an invoice with non-inventory items from my website to Quick books desktop application. I am using following github repository:https://github.com/consolibyte/quickbooks-php

Please help me, how I can create an invoice with non-inventory items?

I have added my sample code to create an invoice with non-inventory items:

<?php
$primary_key_of_your_customer = 5;
require_once '../../QuickBooks.php';
$user = 'user';
$pass = 'pass';
$map = array(QUICKBOOKS_ADD_INVOICE => array( '_quickbooks_invoice_add_request', '_quickbooks_invoice_add_response' ));
$errmap = array(3070 => '_quickbooks_error_stringtoolong');
$hooks = array();
$log_level = QUICKBOOKS_LOG_DEBUG;  
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
$soap_options = array();
$handler_options = array( 'deny_concurrent_logins' => false, 
        'deny_reallyfast_logins' => false, 
    );
$driver_options = array();
$callback_options = array();
$dsn = 'mysqli://root:password@localhost/quickbooks';
$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
$response = $Server->handle(true, true);
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_INVOICE, $primary_key_of_your_customer);

function _quickbooks_invoice_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{    
    $xml = '<?xml version="1.0" encoding="utf-8"?>
                <?qbxml version="13.0"?>
                <QBXML>
                    <QBXMLMsgsRq onError="stopOnError">
                        <InvoiceAddRq>
                            <InvoiceAdd defMacro="MACROTYPE">
                                <CustomerRef>
                                    <ListID >80000257-1578565322</ListID>
                                    <FullName >ConsoliBYTE, LLC (1001546518)</FullName>
                                </CustomerRef>
                                <RefNumber >STRTYPE</RefNumber>
                                <BillAddress>
                                    <Addr1 >Addr1</Addr1>
                                    <Addr2 >Addr2</Addr2>
                                    <City >indore</City>
                                    <State >TX</State>
                                    <PostalCode >482201</PostalCode>
                                    <Country >US</Country>
                                    <Note >Notes</Note>
                                </BillAddress>
                                <ShipAddress>
                                    <Addr1 >old palasia</Addr1>
                                    <Addr2 >stree 123</Addr2>
                                    <City >Katni</City>
                                    <State >TX</State>
                                    <PostalCode >48002</PostalCode>
                                    <Country >US</Country>
                                    <Note >Shipping</Note>
                                </ShipAddress>
                                <IsPending >true</IsPending>
                                <PONumber >PONumber</PONumber>
                                <ShipMethodRef>
                                    <ListID ></ListID>
                                    <FullName >Fedex</FullName>
                                </ShipMethodRef>
                                <Other >Other</Other>
                                <InvoiceLineAdd>
                                    <ItemRef>
                                        <FullName >item</FullName>
                                    </ItemRef>
                                    <Desc >item Desc</Desc>
                                    <Quantity >1</Quantity>
                                    <UnitOfMeasure >UnitOfMeasure</UnitOfMeasure>
                                    <Rate >1.5</Rate>
                                    <Amount >1.5</Amount>
                                    <Other1 >Other1</Other1>
                                    <Other2 >Other2</Other2>
                                </InvoiceLineAdd>
                            </InvoiceAdd>
                        </InvoiceAddRq>
                    </QBXMLMsgsRq>
                </QBXML>';
    return $xml;
}

function _quickbooks_invoice_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{

}

function _quickbooks_error_stringtoolong($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
}
解决方案

It looks like you're on the right track here. Let's talk about the specific error messages you're getting:

Dollar amounts in QuickBooks have 2 decimal places. e.g. you need to send:

<Rate>1.50</Rate>
<Amount>1.50</Amount>

QuickBooks is, at it's core, a relational database. Think of ShipMethodRef/FullName (and/or ShipMethodRef/ListID) as a foreign key constraint.

If you try to insert something and reference a foreign key that doesn't exist, you get an error. So you'll either need to:

  1. Go into the QuickBooks UI, and create a ship method named Fedex (This is probably your best choice, since Ship Methods tend to not change often and there's usually not too many of them. In QuickBooks choose Lists > Customer & Vendor Profile Lists > Item List )

or

  1. Make a ShipMethodAdd call to create the ship method (docs: https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/shipmethodadd )

or

  1. You could leave out the <ShipMethodRef> entirely if you don't want to set it at all

You should also decide whether you're going to send a ListID or a FullName. Don't send both, it just makes errors more confusing. I'd recommend you send the FullName only. If you want to send the ListID you'll have to query QuickBooks to get the ListID values back (they do not show in the QuickBooks UI).

This is a very similar error to the ShipMethod error above. You reference an item:

<ItemRef>
  <FullName >item</FullName>
</ItemRef>

And QuickBooks is telling you that that item does not exist. Similar to Ship Method, you have to either:

  1. Create it (or use an existing item) via the QuickBooks UI (in QuickBooks choose Lists > Item List )

or

  1. Create it via the API (docs: https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/itemnoninventoryadd )

You don't have option 3. here because it's a required field for invoices.

Since you're just getting started with QuickBooks development, I would HIGHLY RECOMMEND that you go with option 1. above.

Tackle 2. only if you need to, and after you have the basics of your integration down (e.g. once you've seen some invoices actually get created successfully).

One other thing to watch for -- QuickBooks has a concept of a "sub-item". Think of it like this:

Shirts
 > T-Shirts
  > Red T-Shirts
  > Blue T-Shirts
  > Green T-Shirts

Each of those is an Item, but because they are in a nested hierarchy (e.g. T-Shirts is a child item/sub-item of Shirts) the FullName values reflect that hierarchy:

Shirts              (name=Shirts, FullName=Shirts)
 > T-Shirts         (name=T-Shirts, FullName=Shirts:T-Shirts)
  > Red T-Shirts    (name=Red T-Shirts, FullName=Shirts:T-Shirts:Red T-Shirts)
  > Blue T-Shirts   (name=Red T-Shirts, FullName=Shirts:T-Shirts:Blue T-Shirts) 
  > Green T-Shirts  (name=Red T-Shirts, FullName=Shirts:T-Shirts:Green T-Shirts) 

So if you see the item in QuickBooks... but you're still getting errors about FullName, make sure you're really using the whole FullName instead of just the Name of the thing.

这篇关于使用 PHP 在 Quick Books 桌面上使用非库存项目创建发票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 23:56