Postman collection
Reports Read

pixiReportReturnsCount

Returns the total quantity of returned items (negative invoice lines) for a reference day, the previous day, the current month to date and the previous month.

Calculates four return figures for a dashboard. A return is counted as an invoice line with a negative quantity (ItemQty < 0). The figure is the sum of the absolute quantities (SUM(ABS(ItemQty))), not the number of documents.

Steps:

  • The reference day is @EndDate. If it is NULL, the current date is used. The time is set to the end of that day (23:59:59.997).
  • From the reference day, four periods are derived and matched against the invoice date (InvDate):
    • Given day: start to end of the reference day.
    • Previous day: the full calendar day before the reference day.
    • Given month: from the first day of the reference month up to the end of the reference day (month to date).
    • Previous month: the full calendar month before the reference month.
  • Invoice lines are joined to their invoice and the invoice's customer. If @ShopID is filled, only customers whose CustomerOf equals @ShopID are counted. If it is empty or NULL, all shops are included.

The call returns one row with the four values.

Notes

  • @StartDate is declared but not used. All periods are derived only from @EndDate.
  • All reads use NOLOCK. The figures can include uncommitted data.
  • Returns are taken from invoice lines (credit lines with negative quantity), not from a separate returns table.
  • The values are stored in varchar(10) variables and are returned as strings. Depending on the data type of ItemQty, they can contain decimal places.
  • If a period has no matching lines, its value is NULL. In the SOAP response the element is then usually missing.
  • If an error occurs while calculating, the procedure ends with return code -1 and returns no result set. One possible cause is a sum that does not fit into varchar(10).

Tables used

Invlines · Read Invoices · Read Customers · Read
SQL object:
dbo.pipiReportReturnsCount
Updated at 2026-10-30