pixiDFCreateInvoices
Creates direct fulfilment (DF) invoices for order lines that are ready, optionally restricted to and enriched with ship vendor and tracking data from XML.
The call creates invoices for direct fulfilment orders. The actual work is done by the internal procedure Pixi_CreateFulfillmentIncoices, which runs with CreateEmp = 'API'.
Steps
-
An exclusive application lock
pipiDFCreateInvoicesis requested with a timeout of 5 seconds, so that parallel runs are serialised. -
If
OrderlinesXMLis given (an empty string counts as NULL), the elements/Orderlines/Orderlineare read with the child elementsOrderlineKey,ShipVendor,ShipmentTrackingIdandReturnTrackingId. -
If
ShowDetailedMessages = 1, the input is validated first:- The XML must be present and contain at least one
Orderline. - The ship vendor code (taken from the first line of each order) may be at most 3 characters long.
- All shipment tracking IDs of an order, joined with
;, may be at most 512 characters long. The same limit applies to the return tracking IDs. - Every
OrderlineKeymust exist inOrderlines.
If any check fails, all error rows are returned and no invoice is created.
- The XML must be present and contain at least one
-
Invoices are created. The behaviour depends on the settings
EnableFulfilmentTypeOneandEnableFulfilmentTypeTwo:- Type one: order lines from the XML that have status
FUTare first set toFUS. Then one invoice is created per order that hasFUSlines. With XML, only the listed lines are used; without XML, allFUSlines are used. - Type two: candidate orders are those whose lines are all
FUSor in a final state, and that have at least oneFUSline without an invoice. The XML does not restrict the candidate orders. It only restricts whichFUSlines are added to the invoice. Lines with statusMINare always added.
- Type one: order lines from the XML that have status
-
Each order is processed in its own transaction:
- The invoice is created, flagged with
Fulfillment = 1and given its invoice positions. - The ship vendor from the XML overrides the ship vendor of the order.
- Tracking IDs from the XML are stored on the invoice. Several IDs can be separated by
;, and each distinct ID becomes its own invoice package. - The order lines are set to
AUSwithInvRefandShipDate. - An invoice number is assigned, an entry is posted to the customer account and the invoice is scanned out.
- An
InvoiceCreatedevent is published.
- The invoice is created, flagged with
-
If
ShowDetailedMessages = 1, one status table is returned:- one
OKrow listing the invoice numbers linked to the given order lines; - an
ERRORrow listing orders whose given lines have no invoice position; - an
ERRORrow if neither of the two applies.
- one
With ShowDetailedMessages = 0, no result set is returned.
Notes
- Errors are swallowed. The whole body runs in
TRY/CATCH. TheCATCHblock only releases the application lock, so SQL errors never reach the caller. WithShowDetailedMessages = 0the caller gets no feedback at all. - Lock result is not checked. The return value of
sp_getapplockis ignored. If the lock cannot be obtained within 5 seconds, processing continues anyway. - Lock not released on validation errors. On the early returns after a validation error the lock is not released explicitly. It stays with the session until the session ends.
- Truncation risk.
ErrorMessageisvarchar(512)and the list of invoice numbers is held in avarchar(512)variable. Long lists of order numbers or invoice numbers can be truncated, or can raise a truncation error that is then silently caught. - Validation is optional. It only runs with
ShowDetailedMessages = 1. Without it, the internal procedure readsShipVendorasvarchar(3)and the tracking IDs asvarchar(512), so longer values may be cut. - Meaning of the
OKrow. It lists every invoice linked to the given order lines, which can include invoices created earlier. The code comment names a supplier withoutCanDoDirectFulfillmentor a line status other thanFUTas typical reasons for a missing invoice. - Settings.
- If neither
EnableFulfilmentTypeOnenorEnableFulfilmentTypeTwois1, no invoices are created. - With
DoNotSendAUSmailOnFulfillment=1/Y, the order lines are additionally markedCustomerEMailed = 'Y'.
- If neither
- Invoice numbers. An existing external invoice number on the order lines (
InvoiceNrExternal) is used when the invoice is created. The internal procedure then callsPixi_GetNextInvNrand writes its result toInvoiceNr. Whether that keeps the external number cannot be seen because that procedure is not attached. - Rollback per order. An invoice without positions is rolled back and deleted, as is an order that produced errors. Other orders are not affected.
- Further side effects. Several nested procedures are not attached:
GOS_Qi_InvoiceNOD,Pixi_CA_AddPixiInvoice,GOSScanOutInvoice,Pixi_PollCreateRecords,Pixi_MQ_EventPublishandPixi_AddDataForSEPAExportToInvoice. Their side effects are not documented here.
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
OrderlinesXML
|
varchar(max) xml |
NULL |
XML with the order lines to invoice, plus optional ship vendor and tracking data. Expected path: Example:
|
ShowDetailedMessages
|
bit boolean |
0 |
Controls input validation and the status result set. NULL is treated as 0. Allowed values
Example: |
Result set 1 · Only if ShowDetailedMessages = 1 and validation fails. Returned instead of the processing result; no invoices are created.
One row per validation error.
| Column | Type | Description |
|---|---|---|
ReturnCode
Nullable |
varchar(10) string |
Always |
ErrorMessage
Nullable |
varchar(512) string |
Error text including the affected order numbers or order line keys. |
Result set 2 · If ShowDetailedMessages = 1 and validation succeeded, after invoice creation.
Status rows. An ERROR row lists orders without invoice positions, an OK row lists the created or linked invoice numbers. Both can appear together.
| Column | Type | Description |
|---|---|---|
ReturnCode
Nullable |
varchar(10) string |
|
ErrorMessage
Nullable |
varchar(512) string |
Status text, e.g. the list of invoice numbers separated by |
Response example
<SqlRowSet1>
<row>
<ReturnCode>OK</ReturnCode>
<ErrorMessage>Direct fulfilment Invoice(s) created with invoice number(s): RE100234; RE100235</ErrorMessage>
</row>
</SqlRowSet1>
| Status | Message | Cause |
|---|---|---|
| ERROR | XML is empty or not proper. Please review and adapt. | `ShowDetailedMessages` = 1, and `OrderlinesXML` is empty or contains no `/Orderlines/Orderline` element. Send valid XML with at least one order line. |
| ERROR | Ship vendor code is too long, field size max. of 3 characters was reached. Please review and adapt OrderNr(s): {OrderNrs} | The `ShipVendor` value of the first line of an order is longer than 3 characters. Use the 3-character ship vendor code. |
| ERROR | TrackingId is too long, field size max. of 512 characters was reached. Please review and adapt OrderNr(s): {OrderNrs} | The shipment tracking IDs of all lines of an order, joined with `;`, exceed 512 characters. Send fewer or shorter IDs. |
| ERROR | ReturnTrackingId is too long, field size max. of 512 characters was reached. Please review and adapt OrderNr(s): {OrderNrs} | The return tracking IDs of all lines of an order, joined with `;`, exceed 512 characters. |
| ERROR | Orderline keys: {OrderlineKeys} do not exist in the database. Please check the input data. | At least one `OrderlineKey` from the XML does not exist in `Orderlines`. |
| ERROR | No direct fulfilment Invoice was created for order(s): {OrderNrs}. Please check the input data. | Given order lines of these orders have no invoice position after processing. A typical cause is a line status other than `FUT`/`FUS`, or a supplier that is not enabled for direct fulfilment. |
| ERROR | No direct fulfilment Invoice(s) created | No invoice is linked to the given order lines and no other status message was produced. |
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:pixiDFCreateInvoices>
<!-- <OrderlinesXML><![CDATA[<Orderlines><Orderline><OrderlineKey>123456</OrderlineKey><ShipVendor>DHL</ShipVendor><ShipmentTrackingId>00340434161234567890</ShipmentTrackingId><ReturnTrackingId>00340434169876543210</ReturnTrackingId></Orderline><Orderline><OrderlineKey>123457</OrderlineKey><ShipVendor>DHL</ShipVendor><ShipmentTrackingId>00340434161234567891</ShipmentTrackingId><ReturnTrackingId></ReturnTrackingId></Orderline></Orderlines>]]></OrderlinesXML> -->
<!-- <ShowDetailedMessages>1</ShowDetailedMessages> -->
</ns1:pixiDFCreateInvoices>
</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:pixiDFCreateInvoices>
<!-- <OrderlinesXML><![CDATA[<Orderlines><Orderline><OrderlineKey>123456</OrderlineKey><ShipVendor>DHL</ShipVendor><ShipmentTrackingId>00340434161234567890</ShipmentTrackingId><ReturnTrackingId>00340434169876543210</ReturnTrackingId></Orderline><Orderline><OrderlineKey>123457</OrderlineKey><ShipVendor>DHL</ShipVendor><ShipmentTrackingId>00340434161234567891</ShipmentTrackingId><ReturnTrackingId></ReturnTrackingId></Orderline></Orderlines>]]></OrderlinesXML> -->
<!-- <ShowDetailedMessages>1</ShowDetailedMessages> -->
</ns1:pixiDFCreateInvoices>
</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 = [
// 'OrderlinesXML' => '<Orderlines><Orderline><OrderlineKey>123456</OrderlineKey><ShipVendor>DHL</ShipVendor><ShipmentTrackingId>00340434161234567890</ShipmentTrackingId><ReturnTrackingId>00340434169876543210</ReturnTrackingId></Orderline><Orderline><OrderlineKey>123457</OrderlineKey><ShipVendor>DHL</ShipVendor><ShipmentTrackingId>00340434161234567891</ShipmentTrackingId><ReturnTrackingId></ReturnTrackingId></Orderline></Orderlines>',
// 'ShowDetailedMessages' => '1',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiDFCreateInvoices', $soapArguments);
- SQL object:
- dbo.pipiDFCreateInvoices