@eristack/qups
Version:
Quantity / unit price / subtotal (QUPS) with 2-of-3 sources of truth, plus modifiers and tax — business line pricing on @eristack/money
89 lines • 2.46 kB
TypeScript
import { Money } from "@eristack/money";
export type ModifierKind = "discount" | "surcharge";
export type ModifierSpec = {
id?: string;
kind: ModifierKind;
type: "percent";
/** Percent points, e.g. `"10"` for 10%. */
percent: string;
} | {
id?: string;
kind: ModifierKind;
type: "nominal";
amount: Money;
};
export type ModifierStep = {
spec: ModifierSpec;
/** Absolute money effect (always ≥ 0). */
amount: Money;
/** Running total after this step. */
running: Money;
};
export type AdjustedInput = {
truth: "base+modifiers";
base: Money;
modifiers: readonly ModifierSpec[];
} | {
/** Derive a single nominal modifier so base ± mod = net. */
truth: "base+net";
base: Money;
net: Money;
kind?: ModifierKind;
id?: string;
} | {
/** Derive base from net by reversing modifiers (percent/nominal). */
truth: "modifiers+net";
net: Money;
modifiers: readonly ModifierSpec[];
};
/**
* Base amount ↔ modifiers ↔ net, with exactly two sources of truth.
* Supports multiple percent/nominal discounts and surcharges in order.
*/
export declare class AdjustedAmount {
readonly truth: "base+modifiers" | "base+net" | "modifiers+net";
readonly base: Money;
readonly net: Money;
readonly modifiers: readonly ModifierSpec[];
readonly steps: readonly ModifierStep[];
readonly discountTotal: Money;
readonly surchargeTotal: Money;
private constructor();
static of(input: AdjustedInput): AdjustedAmount;
toJSON(): {
truth: "base+modifiers" | "base+net" | "modifiers+net";
base: {
currency: string;
amount: string;
};
net: {
currency: string;
amount: string;
};
discountTotal: {
currency: string;
amount: string;
};
surchargeTotal: {
currency: string;
amount: string;
};
modifiers: ({
id: string | undefined;
kind: ModifierKind;
type: "percent";
percent: string;
amount?: undefined;
} | {
percent?: undefined;
id: string | undefined;
kind: ModifierKind;
type: "nominal";
amount: {
currency: string;
amount: string;
};
})[];
};
}
//# sourceMappingURL=modifier.d.ts.map