Postman collection
Stock Write

pixiSetStock

Sets the stock quantity of an item on a bin to an absolute value by booking the difference as a scan-in or take-out stock movement.

Sets the quantity of one item on one bin to NewStockQty. The call does not overwrite the quantity directly. It calculates the difference to the current quantity and books that difference as a stock movement.

Steps:

  1. Checks the setting API_Stock_Movements. If it is not enabled, the call returns a status row with Status = ERROR and stops.
  2. Checks that SMORef is a stock movement operation (StockMovementOperations.SMOKey) whose Application is API. If not, an error is raised.
  3. Looks up the item by EANUPC = EanUpc.
  4. Reads whether the item requires batch numbers or best-before dates (item tags -6 and -7). If the item does not require them, BatchNumber and BestBeforeDate are ignored. If it requires them, they must be filled; otherwise nothing is booked.
  5. Looks up the bin by BinName. If LocId is given, only bins of that location are considered; otherwise the first bin with that name in any location is used, and its location is used for the booking.
  6. Calculates the difference: NewStockQty minus the sum of BinItemQTY of the item on that bin (all rows, regardless of batch or best-before date).
    • Difference > 0: books a scan-in (Pixi_InvBinScanIn) of the difference.
    • Difference < 0: books a take-out (Pixi_InvBinTakeOut) of the absolute difference.
    • Difference = 0: no booking.
  7. Before booking, the combination of SMORef and SMTref must exist in StockMovementMatching; otherwise an error is logged and raised.
    • If SMTref is not given, the call replaces both values: for a scan-in it uses the API operation PutToStock and movement type 0201, for a take-out the API operation TakeOut and movement type 0301.
    • If SMTref is given, the passed SMORef and SMTref are used.
  8. Finally the item is queued for stock recalculation and shop export (Pixi_ExportItemChangesToShop), also when nothing was booked.

The procedure has a return code: 0 = processed, 1 = item not found or required batch number / best-before date missing, 2 = bin not found. On success no result set is returned.

Notes

  • SMORef has the default NULL, but the call always fails with SMO is not assigned to API if it is left out. Pass the key of an API stock movement operation.
  • The return codes 1 and 2 are only the procedure's return value; no status row is returned. Depending on the client, a missing item or bin may therefore look like a success.
  • If SMTref is omitted, the passed SMORef is only used for the initial check and then replaced by the PutToStock/TakeOut operation.
  • The difference is calculated over all batches and best-before dates on the bin, but booked with the given BatchNumber/BestBeforeDate. For items with batches the result per batch may differ from what is expected.
  • BestBeforeDate defaults to '', which SQL Server converts to 1900-01-01. This value is treated as empty, so items with a best-before date tag need a real date.
  • Without LocId, TOP 1 without ORDER BY is used to pick the bin; if the bin name exists in several locations the choice is not deterministic.
  • Lookups use NOLOCK.
  • The called procedures Pixi_InvBinScanIn/Pixi_InvBinTakeOut reject quantities above the setting MaxStockOperationLimit and run in their own transaction; their base procedures are not attached. Errors inside the base procedures are logged via log.InsertError and may not reach the caller.
  • Errors raised by the called procedures end in the CATCH block of this call, which writes an entry to LogTable and raises an error with the content of the internal error variable. For errors not produced by this procedure itself, that message is empty, so the original error text is lost.
  • For the SMT is not matched error, LogTable receives two entries (one before raising, one in the CATCH block).
  • Every call that passes the initial checks inserts a row into pixi.ItemRecalculateStockQueue, even if no booking was made or the item was not found.

Tables used

Settings · Read StockMovementOperations · Read StockMovementMatching · Read StockMovementTypes · Read Items · Read TagMatch · Read InvBin · Read InvBinItem · Read LogTable · Write ItemRecalculateStockQueue · Write
SQL object:
dbo.pipiSetStock
Updated at 2026-10-30