Postman collection
Customers Read

pixiGetCustomerAccountBalance

Returns the customer account balance (sum of all account entries up to an optional date) for a customer identified by internal key or external customer number.

Calculates the balance of the customer account (CustomerAccount) for one or more customers.

Customer lookup

  • CustKey is compared with the external customer number (CustomerNrExternal) and, if it can be converted to an integer, with the internal customer key (CustKey). A customer matches if either comparison is true.
  • If ShopId is given (not empty), only customers whose CustomerOf equals this shop are considered.

Date limit

  • If DateTo is given, it is extended to the end of that day (23:59:59.997). Only account entries with an EventDate up to this point, or without an EventDate, are summed.
  • Without DateTo, all entries are summed.

Currency handling

  • The setting MultiCurrencyEnabled is read at runtime.
  • If it is 1, each entry amount is divided by the exchange rate of the entry (ExchRateId) and the result is grouped by the base currency of that exchange rate (BaseCurrency).
  • Otherwise amounts are summed as stored and BaseCurrency is the database (home) currency from the setting HomeCurrency.

Result One row per matching customer (and per base currency in multi-currency mode) with the balance CAbalance (as money) and the date of the latest included account entry LastEventDate. Customers without any account entries are returned with balance 0 and LastEventDate = NULL. No row is returned if no customer matches.

Notes

  • All tables are read with NOLOCK; the balance may include uncommitted data.
  • Because CustKey is matched against both the external number and the internal key, more than one customer can be returned (e.g. one customer with internal key 123 and another with external number 123). Use ShopId or check CustomerId in the result.
  • Pitfall with DateTo: the date filter is applied after the outer join. A customer whose account entries all lie after DateTo is not returned at all (no row instead of a row with balance 0).
  • Multi-currency mode: entries without an exchange rate produce NULL in the division and are ignored in the sum; they also form their own group with BaseCurrency = NULL. Entries with different base currencies yield separate rows for the same customer.
  • An empty ShopId is treated like NULL (no shop filter).

Tables used

Customers · Read CustomerAccount · Read ExchRate · Read Currency · Read Settings · Read
SQL object:
dbo.pipiGetCustomerAccountBalance
Updated at 2026-10-30