pixiReportStockRange
Returns a paged stock range report per item: current stock, sales in a period, sales per day and the resulting stock range in days, sorted by stock range descending.
Calculates how many days the current stock of each item will last based on past sales, and returns the items whose stock range is at least MinStockRange days. It is typically used to find slow-moving or overstocked items.
Calculation
- For every item that has at least one stock record (
InvBinItemjoined toInvBin), the procedure computes:Stock: sum ofBinItemQtyover all bins of the item.Sales: sum ofItemQtyof the invoice lines (Invlines) of the item that were created within the lastSalesDaysBackdays (calendar days). By default only lines with a positive quantity are counted. WithDeductReturns= 1, all lines are counted, so negative lines such as credit notes reduce the sum.LastStockInc: number of days since the most recentUpdateDateof the item's stock records.
SalesPerDay=Sales/SalesDaysBack.StockRange=Stock/SalesPerDay, in days. IfSalesis 0 or less,StockRangeis set to9999.
Filters (all combined with AND)
SupplNr: only items of this supplier (items.SupplNR).PriceMin/PriceMax: limits on the item sales price (items.Price).LastStockIncDays: only items whoseLastStockIncis greater than this value.StockMin: only items withStock>= this value (default 0, so items with negative stock are excluded).MinStockRange: only items withStockRange>= this value.ExcludeInhouseEAN= 1: items whoseEANUPCstarts with2(in-house EAN numbers) are excluded.
Sorting and paging
The filtered rows are numbered in Row by StockRange descending, then ItemName. The call returns at most RowCount rows with Row > StartRow, in the same order. To fetch the next page, pass the last Row received as StartRow.
Notes
- All tables are read
WITH (NOLOCK), so the figures can include uncommitted data. - The calculation runs over all items with stock records and uses a correlated subquery on
Invlinesper item, so every call (also every page) recalculates the full report. On large databases this can be slow. SalesDaysBack= 0 causes a division-by-zero SQL error, returned asSqlMessage. WithSalesDaysBack= NULL no sales are counted,SalesPerDayis NULL and every item getsStockRange9999.PriceMinandPriceMaxare normalised withNULLIF(…, ''); the empty string converts to the money value 0, so a value of0means no filter. In particularPriceMax= 0 does not restrict the result.SupplNr= empty string is treated as NULL (no filter).StartRow,StockMinandMinStockRange= NULL are treated as 0.RowCountis applied withSET ROWCOUNT;RowCount= 0 returns all matching rows.- With
ExcludeInhouseEAN= 1, items without anEANUPC(NULL) are also excluded, because theNOT LIKEcomparison is not true for NULL. - Despite its name,
LastStockIncis based on the latestUpdateDateof the stock records, not specifically on the last stock increase.
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
RowCount
|
int | 100 |
Maximum number of rows returned (page size). 0 returns all rows. Example: |
StartRow
|
int | NULL |
Only rows with Example: |
MinStockRange
|
int | 100 |
Minimum stock range in days; only items with Example: |
SalesDaysBack
|
int | 360 |
Length of the sales period in days, counted back from now. Also the divisor for Example: |
LastStockIncDays
|
int | NULL |
If set, only items whose stock records were last updated more than this number of days ago ( Example: |
StockMin
|
int | NULL |
Minimum total stock; only items with Example: |
PriceMin
|
money decimal |
NULL |
Minimum item sales price ( Example: |
PriceMax
|
money decimal |
NULL |
Maximum item sales price ( Example: |
SupplNr
|
varchar(4) string |
NULL |
Supplier number; only items of this supplier ( Example: |
ExcludeInhouseEAN
|
bit boolean |
0 |
Whether items with in-house EAN numbers (starting with Allowed values
Example: |
DeductReturns
|
bit boolean |
0 |
Whether invoice lines with negative quantities (e.g. credit notes) are deducted from the sales quantity. Allowed values
Example: |
Result set 1 · Always (may be empty)
One row per item matching the filters, page limited by RowCount and StartRow, sorted by StockRange descending, then ItemName.
| Column | Type | Description |
|---|---|---|
Row
|
bigint long |
Row number within the filtered and sorted result; use for paging. |
ItemKey
|
int |
Internal key of the item. |
ItemName
Nullable |
varchar(120) string |
Item name. |
Price
|
money decimal |
Sales price of the item. |
SupplPrice
|
money decimal |
Purchase price from the supplier. |
EANUPC
Nullable |
varchar(13) string |
EAN/UPC of the item. |
ItemNrSuppl
Nullable |
varchar(50) string |
Supplier's item number. |
ItemNrInt
|
varchar(50) string |
Internal item number. |
Stock
Nullable |
int |
Total stock over all bins (sum of |
Sales
|
int |
Invoiced quantity within the last |
SalesPerDay
Nullable |
numeric(29,15) decimal |
Average sales per day ( |
LastStockInc
Nullable |
int |
Days since the latest |
StockRange
Nullable |
numeric(38,11) decimal |
Stock range in days ( |
Response example
<SqlRowSet1>
<row>
<Row>1</Row>
<ItemKey>4711</ItemKey>
<ItemName>Winterjacke Herren XL</ItemName>
<Price>129.9000</Price>
<SupplPrice>54.0000</SupplPrice>
<EANUPC>4006381333931</EANUPC>
<ItemNrSuppl>WJ-XL-01</ItemNrSuppl>
<ItemNrInt>100245</ItemNrInt>
<Stock>35</Stock>
<Sales>0</Sales>
<SalesPerDay>0.000000000000000</SalesPerDay>
<LastStockInc>210</LastStockInc>
<StockRange>9999.00000000000</StockRange>
</row>
<row>
<Row>2</Row>
<ItemKey>5120</ItemKey>
<ItemName>Regenschirm schwarz</ItemName>
<Price>19.9000</Price>
<SupplPrice>6.5000</SupplPrice>
<EANUPC>4012345678901</EANUPC>
<ItemNrSuppl>RS-100</ItemNrSuppl>
<ItemNrInt>100388</ItemNrInt>
<Stock>120</Stock>
<Sales>36</Sales>
<SalesPerDay>0.100000000000000</SalesPerDay>
<LastStockInc>45</LastStockInc>
<StockRange>1200.00000000000</StockRange>
</row>
</SqlRowSet1>
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:pixiReportStockRange>
<!-- <RowCount>100</RowCount> -->
<!-- <StartRow>0</StartRow> -->
<!-- <MinStockRange>180</MinStockRange> -->
<!-- <SalesDaysBack>360</SalesDaysBack> -->
<!-- <LastStockIncDays>90</LastStockIncDays> -->
<!-- <StockMin>1</StockMin> -->
<!-- <PriceMin>10.00</PriceMin> -->
<!-- <PriceMax>500.00</PriceMax> -->
<!-- <SupplNr>L001</SupplNr> -->
<!-- <ExcludeInhouseEAN>1</ExcludeInhouseEAN> -->
<!-- <DeductReturns>0</DeductReturns> -->
</ns1:pixiReportStockRange>
</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:pixiReportStockRange>
<!-- <RowCount>100</RowCount> -->
<!-- <StartRow>0</StartRow> -->
<!-- <MinStockRange>180</MinStockRange> -->
<!-- <SalesDaysBack>360</SalesDaysBack> -->
<!-- <LastStockIncDays>90</LastStockIncDays> -->
<!-- <StockMin>1</StockMin> -->
<!-- <PriceMin>10.00</PriceMin> -->
<!-- <PriceMax>500.00</PriceMax> -->
<!-- <SupplNr>L001</SupplNr> -->
<!-- <ExcludeInhouseEAN>1</ExcludeInhouseEAN> -->
<!-- <DeductReturns>0</DeductReturns> -->
</ns1:pixiReportStockRange>
</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 = [
// 'RowCount' => '100',
// 'StartRow' => '0',
// 'MinStockRange' => '180',
// 'SalesDaysBack' => '360',
// 'LastStockIncDays' => '90',
// 'StockMin' => '1',
// 'PriceMin' => '10.00',
// 'PriceMax' => '500.00',
// 'SupplNr' => 'L001',
// 'ExcludeInhouseEAN' => '1',
// 'DeductReturns' => '0',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiReportStockRange', $soapArguments);
- SQL object:
- dbo.pipiReportStockRange