Postman collection
Stock Read

pixiGetMinStockChanges

Returns items whose recommended minimum stock or minimum order quantity, based on recent sales, differs from the current setting by at least a given ratio.

Calculates disposition recommendations per item for one stock location and returns only items where the change is significant. The result is sorted and paged.

Input normalisation

  • 0 for HistoryDays, SecurityDays, ShowChangesAbovePercentage and Rows is replaced by the default value. ConfigtypeKey = 0 and empty strings for the text and XML parameters are treated as NULL.
  • If Location is empty, the first location with ShowLocation = 1 is used.
  • SortColumn and SortDirection are converted to lowercase.

Sales source (Pos / Shops)

  • Only Shops set: sales from order lines only.
  • Only Pos set: sales from closed POS receipts only.
  • Both or none set: order lines plus POS sales. The content of Pos is never read. Shops is parsed, but the shop list is not used to filter the data.

Item filters The filters are applied in this order and build a list of item keys:

  1. Categories (/CATS/CAT/CatId, mapped via TontrArten to items.ConfigType).
  2. Suppliers (/SUPPLIERS/SUP/SupplNr), intersected with the previous list.
  3. Tags (/TAGS/TAG with TAGKEY and TAGTYPE): a = item must have all these tags, o = item must have at least one, n = item must not have the tag. Matching items are added to the list.
  4. ConfigtypeKey (enabled items with this ConfigType), intersected with the list if it is not empty.
  5. SupplNR, intersected with the list if it is not empty.

Disabled items are then removed. If no filter is given, all enabled items are evaluated.

Calculation per item

  • MinStockQty / MinOrderQty: current values from ItemLocationSpecific for Location.
  • Quantity: sum of LocationQuantity over the locations in Locations (default: all locations with ShowLocation = 1).
  • DailyQty: quantity sold in the last HistoryDays days at Location (order lines with status AUS, POS receipts with status CLO) divided by HistoryDays. DailyQtyBefore: the same for the previous period of equal length. Trend is +, - or a blank.
  • RecommendedMinStockQty = FLOOR(DailyQty × (delivery days + SecurityDays)); delivery days default to 7 if the supplier has none.
  • RecommendedMinOrderQty = FLOOR(DailyQty × DesiredStockTurnOver); a result of 1 is set to 0. Negative recommendations are returned as 0.
  • ChangeMinStockQty / ChangeMinOrderQty: relative change (recommended − current) / current; if the current value is 0 and a recommendation exists, 1.
  • StockTurnover = FLOOR(Quantity / DailyQty), 0 without sales.
  • NumOfOrders: number of distinct orders / POS receipts in the period over the Locations list.

Selection, sorting and paging Only items with ABS(ChangeMinStockQty) or ABS(ChangeMinOrderQty) ≥ ShowChangesAbovePercentage are kept. They are numbered (RowNr) by SortColumn / SortDirection, then by ItemName ascending. Rows with RowNr > Start, RowNr ≤ Start + Rows and ItemKey > ItemKeyStart are returned, together with TotalRows (all matching items) and NrOfRecordsLeft (rows after Start with ItemKey > ItemKeyStart).

Notes

  • Read-only; all permanent tables are read WITH (NOLOCK), so uncommitted data can appear. The call computes several aggregates per item over Orderlines and POSitem2/POSheader2 and can be slow on large databases; use filters.
  • Bug: in the default mode (order lines plus POS) ChangeMinOrderQty is always NULL because the code checks the POS-only case twice. Then only ChangeMinStockQty decides whether an item is returned.
  • Items without an ItemLocationSpecific row for Location, or without any row in the Locations list, are not returned.
  • The previous period excludes the day exactly HistoryDays days ago.
  • Tags adds items to the list instead of intersecting it with Categories/Suppliers. A filter with only n tags returns no items as soon as any item carries one of these tags.
  • If Categories or Suppliers match no item and no Tags, ConfigtypeKey or SupplNR is given, the filter is ignored and all enabled items are evaluated.
  • SortColumn is lowercased and compared with mixed-case names; sorting works only with a case-insensitive database collation. Unknown values sort by ItemName.
  • DesiredStockTurnOver = 0 is not replaced by the default and leads to recommended order quantities of 0.
  • Invalid XML in the XML parameters causes a SQL error from sp_xml_preparedocument.
  • To apply a recommendation, use pixiSetItemBuyingInfo.

Tables used

Location · Read Shops · Read TontrArten · Read items · Read TagMatch · Read Suppliers · Read ItemLocationSpecific · Read Orderlines · Read POSitem2 · Read POSheader2 · Read
SQL object:
dbo.pipiGetMinStockChanges
Updated at 2026-10-30