pixiMergeOrders
Merges a source order into a target order by moving all orderlines and bundle orderlines, recalculating tax rates and shipping costs.
Moves the content of the order SourceOrderNr into the order TargetOrderNr.
- Reads the order headers of both orders (order type, currency, shipping cost).
- Raises an error and stops if the two orders have different order types or different currencies. This also happens if neither order exists.
- Runs
pipiCanMergeOrders, which checks the following conditions and returns its own result row (CanMerge,Reason):- both orders exist
- both belong to the same customer
- all orderlines have status
ANG - both use the same payment type, which must not be credit card
K - no orderline is on an active picklist
- both have the same currency and order type
- If the merge is allowed, the following steps run in one transaction:
- The shipping cost of the target order header is set to the higher shipping cost of the two orders.
- All existing orderlines and bundle orderlines of the target order get this shipping cost,
UpdateEmpandUpdateDate. - The orderlines of the source order are moved to the target order. They take over the billing and shipping address,
Order_Id,OrderNrExternalandVoucherIDof the target order's orderlines. - Their
TaxRateis recalculated withfPixi_GetVATRate. The calculation uses the source order type and the country and VAT liability of the target shipping address. - With setting
CalculateBundleVAT=0, bundle components take the tax rate of their bundle orderline. - The bundle orderlines of the source order are moved the same way. With
CalculateBundleVAT=1, their tax rate is the net-weighted average of their components; otherwise it comes from the VAT function. - Bank matches (
BankMatch) of the source order are reassigned to the target order. - The
Discountof the source order header is set to 0.
- Returns
ResultMessage:200 OKon success- the reason code from
pipiCanMergeOrders(401–407) if the merge is not allowed 500 Unexpected errorif the transaction failed
UpdateEmp is set to Employee plus (API), or to API if no employee is given.
Notes
- The call returns two result sets.
SqlRowSet1comes frompipiCanMergeOrders(CanMerge,Reason).SqlRowSet2holdsResultMessage. - The source order header itself is not deleted. It remains without orderlines, with
Discount= 0. - The shipping cost update on
OrderHeadersetsCONTEXT_INFO0x66666 to bypass the update trigger. - Values taken from the target orderlines (addresses,
Order_Id,OrderNrExternal,VoucherID) are read from an arbitrary orderline of the target order. If the target order has no orderlines, these values become NULL on the moved lines. - Source orderlines whose
ItemRefhas no matching row initemsare not moved. - Bundle orderlines without component lines are not moved either.
- With
CalculateBundleVAT=1, a net sum of 0 over the components of a bundle causes a division error. This rolls back the transaction and returns500 Unexpected error. - Error details are not returned in that case; any failure in the transaction only yields
500 Unexpected error. - Reads use
NOLOCK. fPixi_GetDefaultCountryCode, used insidefPixi_GetVATRate, is not attached, so the default-country logic cannot be fully described here.
Related calls
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
TargetOrderNr
Required
|
int | – |
Order number of the target order that receives the orderlines. Example: |
SourceOrderNr
Required
|
int | – |
Order number of the source order whose orderlines are moved into the target order. Example: |
Employee
|
varchar(50) string |
NULL |
Employee name written to Example: |
ResultMessage
OUTPUT
|
varchar(128) string |
NULL |
Output: result code with text, e.g. |
Result set 1 · Whenever the order type and currency checks pass (returned by pipiCanMergeOrders).
Result of the merge pre-check.
| Column | Type | Description |
|---|---|---|
CanMerge
|
int |
1 if the orders can be merged, 0 otherwise. |
Reason
|
varchar(128) string |
Reason code with text, e.g. |
Result set 2 · Whenever the order type and currency checks pass.
Final result of the merge.
| Column | Type | Description |
|---|---|---|
ResultMessage
Nullable |
varchar(128) string |
|
Response example
<SqlRowSet1>
<row>
<CanMerge>1</CanMerge>
<Reason>200 OK</Reason>
</row>
</SqlRowSet1>
| Status | Message | Cause |
|---|---|---|
| RAISERROR | Different order types can not be merged. | The two orders have different order types, or neither order exists. Merge only orders of the same order type. |
| RAISERROR | Orders with different currency can not be merged. | The two orders have different currencies. Merge only orders in the same currency. |
| 401 | 401 Both orders must exist | One of the order numbers does not exist. |
| 402 | 402 Orders must belong to the same customer | The orders have different customers (`CustRef`). |
| 403 | 403 All involved orderlines must have status ANG | At least one orderline of either order is not in status `ANG`. |
| 404 | 404 Payment types on both orders must match and not be a creditcard type | The payment types of the billing addresses differ, or the payment type is credit card `K`. |
| 405 | 405 None of the orderlines in either orders can be on picklists | An orderline is on a picklist that has not expired. Remove it from the picklist first. |
| 406 | 406 Orders must have same currency | Currencies differ. This is normally caught earlier by the RAISERROR check. |
| 407 | 407 Orders must have same order type | Order types differ. This is normally caught earlier by the RAISERROR check. |
| 500 | 500 Unexpected error | An error occurred during the merge transaction, e.g. a division by zero in the bundle VAT average. All changes are rolled back. |
POST https://apigateway.descartes.com/tms/pixi/
Content-Type: text/xml; charset=utf-8
Authorization: Basic BASE64(USERNAME:PASSWORD)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiMergeOrders>
<TargetOrderNr>100245</TargetOrderNr>
<SourceOrderNr>100251</SourceOrderNr>
<!-- <Employee>jdoe</Employee> -->
<!-- <ResultMessage>?</ResultMessage> -->
</ns1:pixiMergeOrders>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
curl -X POST 'https://apigateway.descartes.com/tms/pixi/' \
--user 'USERNAME:PASSWORD' \
--header 'Content-Type: text/xml; charset=utf-8' \
--data-binary @- <<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiMergeOrders>
<TargetOrderNr>100245</TargetOrderNr>
<SourceOrderNr>100251</SourceOrderNr>
<!-- <Employee>jdoe</Employee> -->
<!-- <ResultMessage>?</ResultMessage> -->
</ns1:pixiMergeOrders>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML
<?php
$soapClient = new SoapClient(null, [
'login' => 'USERNAME',
'password' => 'PASSWORD',
'location' => 'https://apigateway.descartes.com/tms/pixi/',
'uri' => 'https://apigateway.descartes.com/tms/pixi/',
]);
$arguments = [
'TargetOrderNr' => '100245',
'SourceOrderNr' => '100251',
// 'Employee' => 'jdoe',
// 'ResultMessage' => '?',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiMergeOrders', $soapArguments);
- SQL object:
- dbo.pipiMergeOrders