pixiGetCRMSales
Returns the cumulated net sales per customer from invoices, reduced by referencing credit notes, optionally filtered by shops and invoice date, with keyset paging.
Calculates a sales figure per customer (CustKey) from the invoice table and returns one row per customer and base currency.
Steps
- An empty
CustomerOfis treated asNULL. If given, it is parsed as XML (/SHOPS/SHOP, valueSHOPID, as element or attribute). Only shop IDs that exist inShopsare kept. - Invoices are selected if:
- the gross total
Totalis greater than 0 (credit notes with negative totals are not counted as primary invoices), - the invoice date
InvDatelies withinCalculationStart…CalculationEnd(each bound inclusive and optional), - when
CustomerOfis set, the customer'sCustomerOfshop is one of the given shops.
- the gross total
- For each invoice, the net total (
Total_Net) and the net total without shipping costs (Total_Net - Total_ShipCost_Net) are taken. The net totals of all invoices that reference it viaRefToInvoiceKey(typically credit notes) are added to these values. - Currency handling depends on the setting
MultiCurrencyEnabled:- not
1: amounts stay in the original invoice currency andBaseCurrencyisNULL; 1: every amount is divided by the exchange rate of the invoice (pixi.ExchRate) andBaseCurrencycontains the code of the base currency of that rate.
- not
- The results are grouped by
CustKeyandBaseCurrency.
Paging
Paging uses keys: only customers with CustKey greater than Offset are returned, sorted by CustKey ascending, limited to Rows rows. For the next page, pass the last returned CustKey as Offset. Offset is not a row count.
Notes
- All reads use
NOLOCK, so results may include uncommitted data. - If
CustomerOfis set but none of the shop IDs exist inShops, no rows are returned. Invalid XML causes an error raised bysp_xml_preparedocument. - Without multi-currency (
MultiCurrencyEnablednot1), amounts in different invoice currencies are summed together without conversion. - With multi-currency, invoices without an exchange rate (
ExchRateIdnot found inpixi.ExchRate) are excluded, and referencing credit notes without an exchange rate are ignored in the sums. Converted amounts are stored with 9 decimal places. - With multi-currency a customer can appear in several rows (one per base currency). Because
Rowslimits rows, not customers, a page can end in the middle of a customer's rows; using thatCustKeyas the nextOffsetskips the remaining rows of that customer. - The date filter is applied only to the primary invoice; referencing credit notes are included regardless of their date.
- A total-return flag is calculated internally but not returned.
- The database currency is read via
pixi.GetDatabaseCurrency(), but the values are not used in the result.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
CustomerOf
|
varchar(max) xml |
NULL |
XML list of pixi* shops ( Example:
|
CalculationStart
|
datetime dateTime |
NULL |
Earliest invoice date (inclusive). Example: |
CalculationEnd
|
datetime dateTime |
NULL |
Latest invoice date (inclusive). Example: |
Rows
|
int | 1000 |
Maximum number of rows returned. Example: |
Offset
|
int | 0 |
Only customers with Example: |
Response
Result set 1 · Always (may be empty).
Cumulated sales per customer and base currency, sorted by CustKey ascending.
| Column | Type | Description |
|---|---|---|
CustKey
Nullable |
int |
Customer key ( |
TotalCompound
Nullable |
decimal(38,9) decimal |
Sum of net invoice totals including the net totals of referencing credit notes; converted to the base currency if multi-currency is enabled. |
TotalWithoutShipcostsCompound
Nullable |
numeric(17,4) decimal |
Same as |
BaseCurrency
Nullable |
varchar(3) string |
Code of the base currency of the amounts if multi-currency is enabled; otherwise |
Response example
<SqlRowSet1>
<row>
<CustKey>1001</CustKey>
<TotalCompound>1523.450000000</TotalCompound>
<TotalWithoutShipcostsCompound>1488.4500</TotalWithoutShipcostsCompound>
<BaseCurrency>EUR</BaseCurrency>
</row>
<row>
<CustKey>1002</CustKey>
<TotalCompound>89.900000000</TotalCompound>
<TotalWithoutShipcostsCompound>84.9000</TotalWithoutShipcostsCompound>
<BaseCurrency>EUR</BaseCurrency>
</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:pixiGetCRMSales>
<!-- <CustomerOf><![CDATA[<SHOPS><SHOP><SHOPID>ABC</SHOPID></SHOP><SHOP><SHOPID>XYZ</SHOPID></SHOP></SHOPS>]]></CustomerOf> -->
<!-- <CalculationStart>2024-01-01T00:00:00</CalculationStart> -->
<!-- <CalculationEnd>2024-12-31T23:59:59</CalculationEnd> -->
<!-- <Rows>1000</Rows> -->
<!-- <Offset>0</Offset> -->
</ns1:pixiGetCRMSales>
</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:pixiGetCRMSales>
<!-- <CustomerOf><![CDATA[<SHOPS><SHOP><SHOPID>ABC</SHOPID></SHOP><SHOP><SHOPID>XYZ</SHOPID></SHOP></SHOPS>]]></CustomerOf> -->
<!-- <CalculationStart>2024-01-01T00:00:00</CalculationStart> -->
<!-- <CalculationEnd>2024-12-31T23:59:59</CalculationEnd> -->
<!-- <Rows>1000</Rows> -->
<!-- <Offset>0</Offset> -->
</ns1:pixiGetCRMSales>
</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 = [
// 'CustomerOf' => '<SHOPS><SHOP><SHOPID>ABC</SHOPID></SHOP><SHOP><SHOPID>XYZ</SHOPID></SHOP></SHOPS>',
// 'CalculationStart' => '2024-01-01T00:00:00',
// 'CalculationEnd' => '2024-12-31T23:59:59',
// 'Rows' => '1000',
// 'Offset' => '0',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiGetCRMSales', $soapArguments);
Tables used
- SQL object:
- dbo.pipiGetCRMSales