pixiCreateReplacement
Creates a replacement order with negative quantities for selected order lines, based on the customer and addresses of an existing order.
Creates a new replacement order and returns the key of the new order header. The work is done by the internal procedure Pixi_CreateReplacementOrder.
- Reads one order line of the order
OrderNr(TOP 1without sort order). Customer, invoice address, shipping address,LocationIDandLastOrdLocationIDare taken from it. The current date is used as creation date. - Copies the invoice address of that order line as a new record in
Addresses. TheUsernameis stored as creator and editor. All other fields are copied unchanged. - Reads the shipping country, the VAT liability (
AddrNoChargeVAT) and the shop of the customer (CustomerOf) from the shipping address. - Parses
Orderlines. Entries are separated by commas. Each entry has the formOrderlineKey;Quantity. The quantity is optional; without it the full quantity of the original line is used. - Reads the order type (default
B2C), shipping costs, tax rates, VAT settings for shipping costs, currency andAddress_Remarksfrom the order header of one of the listed order lines. It also looks up the invoice of that line inInvlines. - Determines an exchange rate for the currency and the current date and creates a new order header (
Pixi_OrderHeader_Insert). The order uses the default CCP merchant from settingDefaultCCPMerchantand a discount of 0. The external order number isP+ the new order number. - Inserts one order line per listed original line:
- quantity negated (
-Quantityor-Qty), statusMIN; - prices, article data, serial number, Charge and best-before date copied;
LocationIDtaken from the orderOrderNr;- tax rate recalculated from the order type, the VAT liability, the shipping country and the item's VAT class;
- line amounts negated and rounded: gross to 2 decimals for
B2C(else 4), net to 2 decimals forB2B(else 4); - amount differences negated.
- quantity negated (
- Links the new order to the original invoice with a
pixi.InvoiceAttributerecord (TypeId3, value = new order number). - Returns the new
OrderHeaderKeyand commits the transaction.
Notes
- All work runs in one transaction. If an error occurs, the
CATCHblock only rolls back. No error message and no result row reach the caller. An empty response means that no replacement order was created. - The result row is sent before the commit. If the internal error counter is not 0, the transaction is rolled back although a key has already been returned.
@Orderlinesis passed to avarchar(8000)parameter of the internal procedure. Longer lists are truncated.- The listed order lines are matched only by
OrderlineKey. The code does not check that they belong toOrderNr. Customer and addresses come fromOrderNr; order type, tax rates, currency and the linked invoice come from one of the listed lines. Pass only lines of the same order. - Which line of
OrderNris used for customer and addresses is not defined (TOP 1withoutORDER BY). - If a listed line has no invoice, the link record in
pixi.InvoiceAttributeis written with an emptyInvoiceId, or the insert fails depending on table constraints. A failure rolls back the whole call. - Order lines are only created for items that exist in
items. - Reads use
NOLOCK.CONTEXT_INFOis set to0x10136while the order lines are inserted, presumably to control triggers. Pixi_OrderHeader_Insert,pixi.GetExchRateID,fpixi_GetSetting,fPixi_GetCommaSplitandfPixi_GetVATRateare not attached. Their exact behaviour, including how the order header is written, is not documented here.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
OrderNr
Required
|
int | – |
Number of the existing order. Customer, invoice address, shipping address and Example: |
Orderlines
Required
|
varchar(max) string |
– |
Comma-separated list of original order lines in the form Example: |
Username
|
varchar(50) string |
API |
User name stored as creator and editor of the new address and order lines. Example: |
Response
Result set 1 · If no error occurs during processing. If an error occurs, nothing is returned.
Key of the newly created order header.
| Column | Type | Description |
|---|---|---|
OrderHeaderKey
|
int |
|
Response example
<SqlRowSet1>
<row>
<OrderHeaderKey>98765</OrderHeaderKey>
</row>
</SqlRowSet1>
Examples
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:pixiCreateReplacement>
<OrderNr>104512</OrderNr>
<Orderlines>556781;1,556782;2</Orderlines>
<!-- <Username>API</Username> -->
</ns1:pixiCreateReplacement>
</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:pixiCreateReplacement>
<OrderNr>104512</OrderNr>
<Orderlines>556781;1,556782;2</Orderlines>
<!-- <Username>API</Username> -->
</ns1:pixiCreateReplacement>
</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 = [
'OrderNr' => '104512',
'Orderlines' => '556781;1,556782;2',
// 'Username' => 'API',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiCreateReplacement', $soapArguments);
Tables used
- SQL object:
- dbo.pipiCreateReplacement