首页 > 解决方案 > 将 SalesOrders 数据从 REST API 调用保存到 Exact Online 的问题

问题描述

我一直在为 Exact Online 使用 PHP 客户端库很长时间了。

保存客户帐户、地址、联系人,然后根据 WooCommerce 订单过滤出 PaymentConditions 后,项目成功反映在 Exact Online 仪表板中。

但不幸的是调用了SalesOrders发布请求 API。我无法存储到 Exact Online 仪表板中,即使仅存储OrderedBy本身就足够了,官方文档中给出了

$ordersn = $order->save();

Picqer\Financials\Exact\ApiException:错误 403:禁止

$order = new SalesOrder($connection);
$lines = new SalesOrderLine($connection);


....

echo'<pre>'; print_r($order); 
$order->SalesOrderLines = $lines;
$ordersn = $order->save();
if ($ordersn->ID)
{
    $orderitem['sync_flag'] = true;
}

这是订单数组的详细信息

Picqer\Financials\Exact\SalesOrder Object
(
    ...
    [attributes:protected] => Array
            (
                [WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
                [OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
                [OrderedBy] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
                [DeliverTo] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
                [OrderDate] => 2019-02-17T19:29:53
                [YourRef] => 75591901YP220320G
                [OrderedByName] => Peter Kerner
                [Description] => 16031_PayPal/Lastschrift/Kreditkarte
                [Remarks] => Order is processing
                [PaymentReference] => 16031
                [PaymentCondition] => 
                [SalesOrderLines] => Picqer\Financials\Exact\SalesOrderLine Object
                    (
                        [attributes:protected] => Array
                            (
                                [OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
                                [VATAmount] => 5,58
                                [Description] => Goodies Box
                                [Quantity] => 1,00
                                [UnitPrice] => 29,37
                                [Item] => 418d43d6-55fe-410a-8df2-b05cbb72cea5
                            )
                            ...
                    )
            )
    ...
)

我们是否需要上传增值税代码,或者我是否遗漏了从上述订单数组中首先显示的其他数据,或者我们还需要调用什么适当的 API。因为为了反映在 Exact Online 仪表板上。我们应该遵循什么?

addItem()从代码片段下面的内置函数调用中:

$soLines = array(
                'OrderID' => $lines->OrderID,
                'Item' => $lines->Item,
                'Description' =>  $lines->Description,
                'Quantity' => $lines->Quantity,
                'UnitPrice' => $lines->UnitPrice,
                'VATAmount' => $lines->VATAmount,
                'VATCode' => $lines->VATCode
           );
$order->addItem($soLines);

生成LineNumber要包含在SalesOrderLines数组中的结果

[attributes:protected] => Array
(
    [WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
    [OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
    [DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
    [OrderDate] => 2019-02-17T20:45:34
    [YourRef] => 9Y9593859V795183K
    [OrderedByName] => Katrin Lenk
    [Description] => 16033_PayPal Express
    [Remarks] =>  Order is processing
    [PaymentReference] => 16033
    [PaymentCondition] => 
    [SalesOrderLines] => Array
        (
            [0] => Array
                (
                    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
                    [Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
                    [Description] => ABC Classic
                    [Quantity] => 2,00
                    [UnitPrice] => 15,08
                    [VATAmount] => 5,73
                    [VATCode] => 
                    [LineNumber] => 1
                )

        )

)

另请注意,我还没有创建 Journals、GLAccounts、Documents & DocumentAttachments API。这是否真的会影响 SalesOrders 的存储


编辑:

在更简单的

$salesOrder = new \Picqer\Financials\Exact\SalesOrder($connection);
$salesOrder->WarehouseID = '26ca2016-453f-499a-8a34-c986009bc78d';
$salesOrder->OrderID = '65F93F56-97A8-4D54-AE37-C0BDDE774E67';
$salesOrder->OrderedBy = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->DeliverTo = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->OrderDate = '2019-02-17T20:45:34';
$salesOrder->YourRef = '9Y9593859V795183K';
$salesOrder->OrderedByName = 'Katrin Lenk';
$salesOrder->Description = '16033_PayPal Express';
$salesOrder->Remarks = 'Order is processing';
$salesOrder->PaymentReference = '16033';
$salesOrder->PaymentCondition = 'PP';

$soLines = array(
    'Item' => '5c415369-615c-4953-b28c-c7688f61cfaa',
    'Description' => 'ABC Classic',
    'Quantity' => '1,00',
    'UnitPrice' => '29,37',
    'OrderID' => '65F93F56-97A8-4D54-AE37-C0BDDE774E67'
);

echo '<pre>'; print_r($soLines);
$salesOrder->addItem($soLines);
echo '<pre>'; print_r($salesOrder);
$salesOrder->save();

soLines从数组存储的结果值

[attributes:protected] => Array
(
    [WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
    [OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
    [DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
    [OrderDate] => 2019-02-17T20:45:34
    [YourRef] => 9Y9593859V795183K
    [OrderedByName] => Katrin Lenk
    [Description] => 16033_PayPal Express
    [Remarks] =>  Order is processing
    [PaymentReference] => 16033
    [PaymentCondition] => 
    [SalesOrderLines] => Array
        (
            [0] => Array
                (
                    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
                    [Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
                    [Description] => ABC Classic
                    [Quantity] => 2,00
                    [UnitPrice] => 15,08
                    [VATAmount] => 5,73
                    [VATCode] => 
                    [LineNumber] => 1
                )

        )

)

实际结果:

Picqer\Financials\Exact\ApiException:错误 403:禁止

标签: exact-onlinepicqer-exact-php-client

解决方案


原因是在两个 REST API 调用中以及在两个 REST API 调用OrderID中都包含了两次值,并且从完美工作中删除了条目并反映在 Exact Online Dashboard 中SalesOrderLineSalesOrderOrderIDSalesOrder

您不能$order->SalesOrderLines = $lines;直接分配导致集合到数组错误。addItem()做到这一点的唯一方法是通过称为将数组对象传递给它的内置函数来调用。


推荐阅读