从REST API调用保存Exact Online来保存SalesOrders数据的问题

时间:2019-05-03 06:45:23

标签: exact-online picqer-exact-php-client

我已经使用PHP Client library for Exact Online很长时间了。

保存客户的帐户,地址,联系人,然后根据WooCommerce订单过滤掉PaymentConditions之后,项目将成功反映在“精确在线”仪表板中。

但不幸的是调用了SalesOrders发布请求API。我无法存储到“确切的在线”信息中心中, 即使仅存储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
                            )
                            ...
                    )
            )
    ...
)

我们是否需要上传 VAT代码,还是我还缺少其他需要从上面的订单数组中首先显示的数据,或者我们还需要调用什么合适的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:禁止

1 个答案:

答案 0 :(得分:0)

原因是两个REST API调用在OrderIDSalesOrderLine中两次包含SalesOrder值,并从{{1 }}运作完美,并反映在“精确在线仪表板”中

您不能直接分配OrderID导致集合到数组错误。 唯一的方法是通过名为SalesOrder的内置函数调用,将数组对象传递给它。