Create invoice with non-inventory item on Quick books desktop in PHP

二次信任 提交于 2020-01-25 06:51:42

问题


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

回答1:


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

3040: There was an error when converting the amount "1.5" in the field "Amount"

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

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

3140: There is an invalid reference to QuickBooks Ship Method "Fedex" in the Invoice. QuickBooks error message: Invalid argument. The specified record does not exist in the list.

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

3140: There is an invalid reference to QuickBooks Item "item" in the Invoice line. QuickBooks error message: Invalid argument. The specified record does not exist in the list.

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.



来源:https://stackoverflow.com/questions/59770646/create-invoice-with-non-inventory-item-on-quick-books-desktop-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!