pixiReport_GrossProfit
Returns the gross profit report per item for an invoice date range, with sales and returns figures, optionally filtered by shop, category, supplier, payment type and tags.
Exposes the Pixi report Gross Profit (Report_GrossProfit) as an API call. Only the detail view is returned; the sums-only mode of the report is hard-coded off.
Steps
- Parameters are normalised:
FromDateis set to the start of its day,ToDateto the end of its day (23:59:59.997). Empty strings are treated asNULL; aTagKeyof0also counts as not set. - Parameters are validated. If
FromDateis later thanToDate, or a given shop, category (TontrArten), supplier, payment type, excluded payment type or tag does not exist, a single status row withStatus=Erroris returned and the call ends. - The report reads invoice lines whose invoice date lies between
FromDateandToDateand applies the optional filters:ShopID: only lines of this shop.Category: item configuration type equals the category.SupplNr: only items of this supplier.PaymentType: only lines with this payment type;ExcludePaymentType: lines with this payment type are excluded.TagKey1–TagKey3: only items carrying all given tags (AND combination).
- Lines are grouped per item, separately for sold and returned quantities, and combined into one row per item.
Currency
- Without
ShopID, all amounts are converted into the database currency (if multi-currency is enabled) andCurrencyis the database currency code. - With
ShopID, amounts are returned in the shop's base currency when multi-currency is enabled; otherwise the database currency code is reported.
Figures per row
Sales_*are quantity-weighted average unit values of the sold lines (gross selling price, VAT, supplier price).Returns_*are the corresponding values of the returned lines.SingleGrossProfit= average gross selling price − average VAT − average supplier price of the sold lines.TotalGrossProfit= per-unit profit of sales × sold quantity − per-unit profit of returns × returned quantity.
Special invoice lines such as shipping costs or vouchers (negative internal item keys) can appear as their own rows.
Notes
- The error rows contain two columns:
Statusand an error text. Only for theExcludePaymentTypecheck is the text column namedMessage; in all other checks the column has no alias, so the SOAP client may receive it under a generated name (e.g.Column1). - The date error text says
"DateTo" is greater than "DateFrom", but it is returned whenFromDateis later thanToDate. FromDateandToDatehave no default. IfNULLis passed, no invoice lines match and the result is empty.- Tag filtering only takes effect if
TagKey1is set.TagKey2is only used together withTagKey1, andTagKey3only ifTagKey1andTagKey2are set; e.g.TagKey2alone is validated but ignored as a filter. - The underlying report sorts by item name, but the rows pass through a temporary table and the final
SELECThas noORDER BY, so the order is not guaranteed. - Each call first runs
Report_SaveSupplierPrices, which according to a comment fills a cache table of supplier prices; its definition is not attached. The multi-currency behaviour depends on the settingMultiCurrencyEnabled. - All reads use
NOLOCK, so uncommitted data may be included. Large date ranges can be slow. - Averages are divided by the sum of absolute quantities; groups with a total quantity of zero could cause a division-by-zero error.
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
FromDate
Required
|
datetime dateTime |
– |
Start of the invoice date range. The time part is ignored; the range starts at the beginning of this day. Example: |
ToDate
Required
|
datetime dateTime |
– |
End of the invoice date range. The time part is ignored; the whole day is included. Example: |
ShopID
|
varchar(3) string |
NULL |
Optional shop filter. Must exist in Example: |
Category
|
varchar(10) string |
NULL |
Optional item category (configuration type, Example: |
SupplNr
|
varchar(10) string |
NULL |
Optional supplier number. Must exist in Example: |
PaymentType
|
char(1) string |
NULL |
Optional payment type code; only invoice lines with this payment type are included. Must exist in Example: |
ExcludePaymentType
|
char(1) string |
NULL |
Optional payment type code to exclude. Must exist in Example: |
TagKey1
|
int | NULL |
Optional item tag ID. Only items with this tag are included. Example: |
TagKey2
|
int | NULL |
Optional second item tag ID; items must carry it in addition to Example: |
TagKey3
|
int | NULL |
Optional third item tag ID; only used as a filter if |
Result set 1 · If a parameter check fails (date range or unknown shop, category, supplier, payment type or tag)
Single status row describing the validation error. The call ends afterwards.
| Column | Type | Description |
|---|---|---|
Status
|
varchar(5) string |
Always |
Message
|
varchar string |
Error text. Only named |
Result set 2 · On success
One row per item (including special lines such as shipping costs or vouchers) with sales, returns and gross profit figures.
| Column | Type | Description |
|---|---|---|
ItemNrSupplier
Nullable |
varchar(50) string |
Supplier item number. |
Barcode
Nullable |
varchar(50) string |
EAN/UPC barcode of the item. |
ItemName
Nullable |
varchar(120) string |
Item name. |
Supplier
Nullable |
varchar(60) string |
Supplier name. |
Sales_Quantity
|
int |
Quantity sold in the period. |
Sales_SellingPrice
|
money decimal |
Average gross selling price per unit of the sold lines. |
Sales_VAT
|
money decimal |
Average VAT amount per unit of the sold lines, rounded to 2 decimals. |
Sales_SupplierPrice
|
money decimal |
Average supplier price (purchase price) per unit of the sold lines. |
Returns_SellingPrice
Nullable |
money decimal |
Average gross selling price per unit of the returned lines (sign inverted). |
Returns_Quantity
|
int |
Quantity returned in the period. |
Returns_VAT
Nullable |
money decimal |
Average VAT amount per unit of the returned lines (sign inverted), rounded to 2 decimals. |
Returns_SupplierPrice
Nullable |
money decimal |
Average supplier price per unit of the returned lines (sign inverted). |
SingleGrossProfit
|
money decimal |
Gross profit per sold unit: selling price − VAT − supplier price, rounded to 2 decimals. |
TotalGrossProfit
Nullable |
money decimal |
Total gross profit: per-unit profit of sales × sold quantity minus per-unit profit of returns × returned quantity, rounded to 2 decimals. |
Currency
Nullable |
varchar(3) string |
Currency code of the amounts (database currency, or shop base currency when |
Response example
<SqlRowSet1>
<row>
<ItemNrSupplier>HX-4410</ItemNrSupplier>
<Barcode>4012345678901</Barcode>
<ItemName>Trinkflasche Edelstahl 750 ml</ItemName>
<Supplier>Hydro Supplies GmbH</Supplier>
<Sales_Quantity>42</Sales_Quantity>
<Sales_SellingPrice>19.9900</Sales_SellingPrice>
<Sales_VAT>3.1900</Sales_VAT>
<Sales_SupplierPrice>7.5000</Sales_SupplierPrice>
<Returns_SellingPrice>19.9900</Returns_SellingPrice>
<Returns_Quantity>2</Returns_Quantity>
<Returns_VAT>3.1900</Returns_VAT>
<Returns_SupplierPrice>7.5000</Returns_SupplierPrice>
<SingleGrossProfit>9.3000</SingleGrossProfit>
<TotalGrossProfit>372.0000</TotalGrossProfit>
<Currency>EUR</Currency>
</row>
</SqlRowSet1>
| Status | Message | Cause |
|---|---|---|
| Error | Parameter "DateTo" is greater than parameter "DateFrom" | `FromDate` is later than `ToDate`. Pass a start date that is not after the end date. |
| Error | Shop "{ShopID}" does not exist | The given `ShopID` is not found in `Shops`. |
| Error | Category "{Category}" does not exist | The given `Category` is not found in `TontrArten`. |
| Error | Supplier number "{SupplNr}" does not exist | The given `SupplNr` is not found in `Suppliers`. |
| Error | Payment with payment type/code "{PaymentType}" does not exist | The given `PaymentType` is not a code in `Payments`. |
| Error | Payment with payment type/code "{ExcludePaymentType}" does not exist | The given `ExcludePaymentType` is not a code in `Payments`. In this case the text column is named `Message`. |
| Error | Tag with tag ID "{TagKey}" does not exist | One of `TagKey1`, `TagKey2` or `TagKey3` is not an existing item tag (`ItemTag`). |
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:pixiReport_GrossProfit>
<FromDate>2024-01-01T00:00:00</FromDate>
<ToDate>2024-01-31T00:00:00</ToDate>
<!-- <ShopID>SHP</ShopID> -->
<!-- <Category>STANDARD</Category> -->
<!-- <SupplNr>L1001</SupplNr> -->
<!-- <PaymentType>R</PaymentType> -->
<!-- <ExcludePaymentType>V</ExcludePaymentType> -->
<!-- <TagKey1>12</TagKey1> -->
<!-- <TagKey2>15</TagKey2> -->
<!-- <TagKey3>?</TagKey3> -->
</ns1:pixiReport_GrossProfit>
</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:pixiReport_GrossProfit>
<FromDate>2024-01-01T00:00:00</FromDate>
<ToDate>2024-01-31T00:00:00</ToDate>
<!-- <ShopID>SHP</ShopID> -->
<!-- <Category>STANDARD</Category> -->
<!-- <SupplNr>L1001</SupplNr> -->
<!-- <PaymentType>R</PaymentType> -->
<!-- <ExcludePaymentType>V</ExcludePaymentType> -->
<!-- <TagKey1>12</TagKey1> -->
<!-- <TagKey2>15</TagKey2> -->
<!-- <TagKey3>?</TagKey3> -->
</ns1:pixiReport_GrossProfit>
</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 = [
'FromDate' => '2024-01-01T00:00:00',
'ToDate' => '2024-01-31T00:00:00',
// 'ShopID' => 'SHP',
// 'Category' => 'STANDARD',
// 'SupplNr' => 'L1001',
// 'PaymentType' => 'R',
// 'ExcludePaymentType' => 'V',
// 'TagKey1' => '12',
// 'TagKey2' => '15',
// 'TagKey3' => '?',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiReport_GrossProfit', $soapArguments);
- SQL object:
- dbo.pipiReport_GrossProfit