【问题标题】:Create invoice with non-inventory item on Quick books desktop in PHP在 PHP 中的 Quickbooks 桌面上使用非库存项目创建发票
【发布时间】:2020-01-16 13:24:53
【问题描述】:

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

请帮帮我,我如何使用非库存物品创建发票?

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

<?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)
{
}

【问题讨论】:

  • 您好,欢迎来到 StackOverflow!您需要更具体地说明您需要什么帮助。
  • 请发布您迄今为止尝试/编写的代码,以便我们提供帮助。
  • 得到三种不同类型的错误: A.errorMsg="3040:在“金额”字段中转换金额“1.5”时出错。“你能告诉我,究竟是什么代码错误? /////////////////// B. 3140:发票中对 QuickBooks Ship Method "Fedex" 的引用无效。 QuickBooks 错误消息:参数无效。列表中不存在指定的记录。创建发票前是否需要创建运输方式?
  • C. 3140:发票行中对 QuickBooks 项目“项目”的引用无效。 QuickBooks 错误消息:参数无效。列表中不存在指定的记录。想要使用发票创建非库存项目,但根据错误消息,我认为我需要在 QB 上添加项目以传递他们的参考。是这样吗?

标签: php quickbooks


【解决方案1】:

看来您在这里的方向是正确的。让我们谈谈您收到的具体错误消息:

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

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

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

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

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

如果您尝试插入内容并引用不存在的外键,则会收到错误消息。所以你要么需要:

  1. 进入 QuickBooks UI,并创建一个名为 Fedex 的发送方法(这可能是您的最佳选择,因为 Ship Methods 往往不会经常更改,而且通常不会太多。在 QuickBooks 中选择 @987654328 @)

  1. 调用ShipMethodAdd 来创建ship 方法(文档:https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/shipmethodadd

  1. 如果您根本不想设置 &lt;ShipMethodRef&gt;,可以完全省略它

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

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

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

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

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

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

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

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

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

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

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

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

其中每一个都是Item但是因为它们处于嵌套层次结构中(例如,T-Shirts 是@987654346 的子项/子项 @) FullName反映了层次结构

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) 

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多