pixiCreateReplacementOrder
Creates a replacement order for one or more return case lines, logs the request in the return case history and returns the new order number.
Creates a replacement (Ersatzauftrag) for returned items, based on the return case lines passed in ReturnLines.
Input format: ReturnLines is a list of RET_LINE_ID values separated by , or ; (e.g. 1024,1025). Semicolons are converted to commas, the string is trimmed and a trailing comma is added if missing.
Steps
- VAT check: For the first return line only, the shipping country of the related Rechnung (
Invoices.ShipAdrRef→Addresses.Country) and the country flagForceCountryVATare determined. If no VAT rate valid today exists inVATsfor that country:- with
ForceCountryVAT = 1an error is raised and nothing is changed; - otherwise
Pixi_InsertDefaultVATRateForCountryis executed to derive a default VAT rate from the default country.
- with
- History and status: For every return line a row is inserted into
RET_CASES_HISTORY(ACTION_TYPE= 8, text from the translation keyReplacementRequestAPIin languageLanguage_Id, with%ItemName%replaced by the Artikel name). The line status inRET_CASE_LINESis set toRPL(processing replacement). The editor is stored asEmployee + ' (API)', orAPIifEmployeeis empty. - Replacement order:
Pixi_CreateReplacementForReturnLinesis called with all lines. Within its own transaction it- collects the original order lines (only order lines with status
AUS, only return lines with statusRPL) with the returned quantity, - sets the return lines to status
SHI(waiting for shipping), - creates addresses for the customer and shop and creates the replacement order via
Pixi_CreateReplacementOrder, - writes the
RET_LINE_IDintoOrderlines.BackorderRefof the new order lines with the same Artikel, so that the return case can be closed at ship-out.
- collects the original order lines (only order lines with status
- The new order number is returned as a single row (
NewOrderNr), in the output parameterNewOrderNrand as the procedure return value.
Notes
- No overall transaction: the history rows and the status change to
RPLare written before and outside the transaction ofPixi_CreateReplacementForReturnLines. If the replacement creation fails, these changes remain. - The VAT check uses only the first return line. Customer, shop and location of the new order are taken from the last processed line, so all lines should belong to the same customer/Rechnung.
- If the first return line does not exist, the country cannot be determined and the call fails with an error from
Pixi_InsertDefaultVATRateForCountry(unknown country code). - Return lines whose original order line is not in status
AUSare skipped; if no line qualifies, the inner procedure raisesWrong Data. Errors from the inner procedure are logged vialog.InsertErrorand re-raised viasp_Exception_ReRaise(not attached; exact message format unknown). - Pitfalls in list parsing: IDs are removed from the list by text replacement of
ID,. Pass plain IDs without spaces or leading zeros. An emptyReturnLinesvalue, or IDs that are suffixes of other IDs in the list (e.g.12,112), can lead to parsing errors or an endless loop. - Lookups use
NOLOCK. - The header comment of the procedure ("Checks pixi* user credentials") does not match its function.
- The VAT error message contains the literal placeholders
[Order/Invoice/...]and{shipping country}; they are not filled in.
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
ReturnLines
Required
|
varchar(max) string |
– |
List of return case line IDs ( Example: |
Employee
|
varchar(50) string |
NULL |
Name of the employee; stored as Example: |
NewOrderNr
OUTPUT
|
int | NULL |
Output: order number of the created replacement order. |
Language_Id
Required
|
int | – |
Language ID used to translate the history text (translation key Example: |
Result set 1 · On success, after the replacement order has been created
One row with the number of the new replacement order.
| Column | Type | Description |
|---|---|---|
NewOrderNr
Nullable |
int |
Order number of the created replacement order. |
Response example
<SqlRowSet1>
<row>
<NewOrderNr>584213</NewOrderNr>
</row>
</SqlRowSet1>
| Status | Message | Cause |
|---|---|---|
| RAISERROR | The VAT rate for selected shipping country was not entered in pixi* Control Center. Since setting "Force Country VAT" is enabled for this country, creation of [Order/Invoice/...] is not possible. Please add VAT rates for country {shipping country} in pixi* Control Center and try again. | No VAT rate valid today exists for the shipping country of the first return line and the country has `ForceCountryVAT` enabled. Add a VAT rate for the country in pixi* Control Center. |
| RAISERROR | Error in [Pixi_InsertDefaultVATRateForCountry]: Unknown country code supplied on line {line} | The shipping country could not be determined, typically because the first ID in `ReturnLines` does not exist or is not linked to an invoice line with a shipping address. Pass valid return line IDs. |
| RAISERROR | Wrong Data | Raised by `Pixi_CreateReplacementForReturnLines` when no order lines could be collected (original order lines not in status `AUS`, return lines not in status `RPL`) or no shop could be determined. Re-raised via `sp_Exception_ReRaise`, so the final text may be wrapped. |
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:pixiCreateReplacementOrder>
<ReturnLines>1024,1025</ReturnLines>
<!-- <Employee>JSmith</Employee> -->
<!-- <NewOrderNr>?</NewOrderNr> -->
<Language_Id>1</Language_Id>
</ns1:pixiCreateReplacementOrder>
</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:pixiCreateReplacementOrder>
<ReturnLines>1024,1025</ReturnLines>
<!-- <Employee>JSmith</Employee> -->
<!-- <NewOrderNr>?</NewOrderNr> -->
<Language_Id>1</Language_Id>
</ns1:pixiCreateReplacementOrder>
</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 = [
'ReturnLines' => '1024,1025',
// 'Employee' => 'JSmith',
// 'NewOrderNr' => '?',
'Language_Id' => '1',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiCreateReplacementOrder', $soapArguments);
- SQL object:
- dbo.pipiCreateReplacementOrder