fn_itemizer_breakdown


Description

Splits a tax/service-INCLUSIVE amount into base (= BASE_PRICE) + service + tax + other using the itemizer codes given (normally department.itemizers).

base is the same number sp_post_transaction stores as the BASE_PRICE entry of transactions.itemizers, so callers reconcile with itemizer_summary exactly.

Two behaviours worth knowing: * sp_get_itemizer_amounts returns BASE_PRICE = NULL when the code array is empty or NULL (its residual is sum() over an empty set), so base coalesces back to p_amount. A department with no itemizers therefore yields base = gross, never NULL. * The arithmetic is NOT linear in p_amount: flat-amount itemizers (itemizer.rate IS NULL) are charged per unit, so base(2x) <> 2*base(x). Never precompute a per-department ratio and multiply – always call with the real amount.

Do not reimplement the arithmetic here; sp_calc_itemizers / fn_calc_itemizers / fn_itemizer use a naive per-itemizer model that ignores is_service/is_tax ordering and calc_on_baseprice and disagrees with what is stored on transactions.

Parameters

Name Type Mode
p_amount t_money IN
p_itemizer_codes text[] IN
base numeric OUT
service numeric OUT
tax numeric OUT
other numeric OUT

Definition