在QuickBooks Desktop中收到InvoiceAdd时收到错误

时间:2019-06-14 07:25:01

标签: php laravel quickbooks

我正在尝试在Laravel的QuickBooks Desktop中添加发票。 我正在使用QuickBooks.php中定义的常量,该常量名为 QUICKBOOKS_ADD_INVOICE ,它等效于 InvoiceAdd ,但它会在quickbooks_queue表中返回以下错误。 -2:没有注册的操作功能:InvoiceAdd。 我习惯于QuickBooks桌面,并添加了其他元素,例如客户和库存物品,但是在使用InvoiceAdd时却收到错误。 你能帮忙吗?

这是我的函数映射,文件是maps.php

<?php

return [
    // Map QuickBooks actions to handle functions
    'actions'   => [
        QUICKBOOKS_ADD_CUSTOMER => [
            [ Iresci23\LaravelQbd\Services\Customer\Customer::class, 'xmlRequest' ],
            [ Iresci23\LaravelQbd\Services\Customer\Customer::class, 'xmlResponse' ]
        ],
        QUICKBOOKS_MOD_CUSTOMER => [
            [ Iresci23\LaravelQbd\Services\Customer\EditCustomer::class, 'xmlRequest' ],
            [ Iresci23\LaravelQbd\Services\Customer\EditCustomer::class, 'xmlResponse' ]
        ],
        QUICKBOOKS_ADD_SALESORDER => [
            [ Iresci23\LaravelQbd\Services\Order\SaleOrder::class, 'xmlRequest' ],
            [ Iresci23\LaravelQbd\Services\Order\SaleOrder::class, 'xmlResponse' ],
            [ Iresci23\LaravelQbd\Services\Order\SaleOrder::class, 'handleError500' ]
        ],
        QUICKBOOKS_ADD_INVENTORYITEM => [
            [ Iresci23\LaravelQbd\Services\Item\InventoryItem::class, 'xmlRequest' ],
            [ Iresci23\LaravelQbd\Services\Item\InventoryItem::class, 'xmlResponse' ],
            [ Iresci23\LaravelQbd\Services\Item\InventoryItem::class, 'handleError500' ]
        ],
        QUICKBOOKS_MOD_INVENTORYITEM => [
            [ Iresci23\LaravelQbd\Services\Item\EditInventoryItem::class, 'xmlRequest' ],
            [ Iresci23\LaravelQbd\Services\Item\EditInventoryItem::class, 'xmlResponse' ],
            [ Iresci23\LaravelQbd\Services\Item\EditInventoryItem::class, 'handleError500' ]
        ],
        QUICKBOOKS_ADD_INVOICE => [
            [ Iresci23\LaravelQbd\Services\Invoice\AddInvoice::class, 'xmlRequest' ],
            [ Iresci23\LaravelQbd\Services\Invoice\AddInvoice::class, 'xmlResponse' ],
            [ Iresci23\LaravelQbd\Services\Invoice\AddInvoice::class, 'handleError500' ]
        ],
        QUICKBOOKS_MOD_INVOICE => [
            [ Iresci23\LaravelQbd\Services\Invoice\EditInvoice::class, 'xmlRequest' ],
            [ Iresci23\LaravelQbd\Services\Invoice\EditInvoice::class, 'xmlResponse' ],
            [ Iresci23\LaravelQbd\Services\Invoice\EditInvoice::class, 'handleError500' ]
        ],
    ]

];

以下是AddInvoice.php

<?php

namespace Iresci23\LaravelQbd\Services\Invoice;

use Illuminate\Support\Facades\Log;

class AddInvoice
{
    /**
     * Issue a request to QuickBooks to add a Sale Order
     */
    public static function xmlRequest($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 requestID="'.$requestID.'">
                <InvoiceAdd>
                    <CustomerRef>
                        <ListID>800020B5-1558602849</ListID>
                    </CustomerRef>
                    <TxnDate>2019-06-01</TxnDate>
                    <RefNumber>004658</RefNumber>
                    <BillAddress>
                        <Addr1>Test address 1</Addr1>
                        <Addr2>Test address 2</Addr2>
                        <City>norhport</City>
                        <State>new york</State>
                        <PostalCode>113458</PostalCode>
                        <Country>United States</Country>
                    </BillAddress>
                    <ShipAddress>
                        <Addr1>test address 1</Addr1>
                        <Addr2>test address 2</Addr2>
                        <City>northport</City>
                        <State>New York</State>
                        <PostalCode>11568</PostalCode>
                        <Country>United States</Country>
                        <Note>This is test Note</Note>
                    </ShipAddress>
                    <ShipDate>2019-06-06</ShipDate>
                    <Memo>Shipping to State Address</Memo>
                    <InvoiceLineAdd>
                        <ItemRef>
                            <ListID>800000DC-1639575384</ListID>
                        </ItemRef>
                        <Desc>test decription</Desc>
                        <Quantity>2</Quantity>
                        <Amount>25</Amount>
                    </InvoiceLineAdd>
                </InvoiceAdd>
            </InvoiceAddRq>
        </QBXMLMsgsRq>
    </QBXML>';
            Log::info(print_r('Invoice Add XML : ' . $xml , true));
            return $xml;
        }
    }

    /**
     * Handle a response from QuickBooks indicating a new Sale Order has been added
     */ 
    public static function xmlResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
    {   
        // Do something here to record that the data was added to QuickBooks successfully 
        if($idents['statusMessage'] == 'Status OK')
        {
            // $order = \App\Order::find($ID);
            // $order->quickbooks_listid = $idents['ListID'];
            // $order->quickbooks_txn_id = $idents['TxnID'];
            // $order->quickbooks_txn_line_id = $idents['TxnLineID'];
            // $order->quickbooks_editsequence = $idents['EditSequence'];
            // $order->save();
        }
        Log::info(print_r(array($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents), true));
        return true;  
    }

    public function handleError500($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
    {
        Log::error('Invoice handleError500');
        Log::error(print_r($errnum . ': ' . $errmsg , true));
        Log::info(print_r(array($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg), true));

        // return true;         // If you return TRUE, it will continue to process requests
        return false;           // If you return FALSE, it will stop processing requests
    }
}

以下是我正在发布的XML

<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
    <QBXMLMsgsRq onError="stopOnError">
        <InvoiceAddRq requestID="5">
            <InvoiceAdd>
                <CustomerRef>
                    <ListID>800020B5-1558602849</ListID>
                </CustomerRef>
                <TxnDate>2019-06-01</TxnDate>
                <RefNumber>004658</RefNumber>
                <BillAddress>
                    <Addr1>Test address 1</Addr1>
                    <Addr2>Test address 2</Addr2>
                    <City>norhport</City>
                    <State>new york</State>
                    <PostalCode>113458</PostalCode>
                    <Country>United States</Country>
                </BillAddress>
                <ShipAddress>
                    <Addr1>test address 1</Addr1>
                    <Addr2>test address 2</Addr2>
                    <City>northport</City>
                    <State>New York</State>
                    <PostalCode>11568</PostalCode>
                    <Country>United States</Country>
                    <Note>This is test Note</Note>
                </ShipAddress>
                <ShipDate>2019-06-06</ShipDate>
                <Memo>Shipping to State Address</Memo>
                <InvoiceLineAdd>
                    <ItemRef>
                        <ListID>800000DC-1639575384</ListID>
                    </ItemRef>
                    <Desc>test decription</Desc>
                    <Quantity>2</Quantity>
                    <Amount>25</Amount>
                </InvoiceLineAdd>
            </InvoiceAdd>
        </InvoiceAddRq>
    </QBXMLMsgsRq>
</QBXML>

要让我运行此代码,请使用

$Queue = new QuickBooks_WebConnector_Queue('mysql://root:@localhost/qbwc_database');
    $Queue->enqueue(QUICKBOOKS_ADD_INVOICE, 5); // here 5 is my order id in database.

将请求加入队列后,当Web连接器运行时,它将在数据库表中返回以下错误 -2:没有注册的操作功能:InvoiceAdd

0 个答案:

没有答案