@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
122 lines (120 loc) • 2.64 kB
JavaScript
import {
AdjustedAmount,
CurrencyMismatchError,
InvalidTruthError,
LineNotFoundError,
LineTax,
MissingDependencyError,
PricingLine,
ProfileNotFoundError,
QUPS_TRUTH_MODES,
Qups,
QupsError,
calculateLine,
createQups,
editableFieldKeys,
fieldsForTruth,
isBuiltinFieldKey,
isQupsTruthMode,
lineFieldMap,
modifiersToRecords,
moneyColumnPair,
patchLine,
pricingLineFromRecord,
pricingLineInputFromParts,
qupsRolesFor,
recordFromPricingLine,
recordsToModifiers,
syncFieldRoles,
withQupsColumns
} from "./chunk-UP24CFOV.js";
// src/core/cell-patch.ts
function applyCellPatch(line, field, value, options = {}) {
const patch = {
round: options.round ?? true,
prefer: options.prefer
};
switch (field) {
case "quantity":
patch.quantity = value;
break;
case "unitPrice":
patch.unitPrice = value;
break;
case "subtotal":
patch.subtotal = value;
break;
case "truth":
patch.truth = value;
break;
case "taxRatePercent":
patch.taxRatePercent = value;
break;
case "taxMode":
patch.taxMode = value;
break;
case "currency":
patch.currency = value;
break;
default: {
const _exhaustive = field;
throw new Error(`Unsupported QUPS cell field: ${String(_exhaustive)}`);
}
}
return patchLine(line, patch);
}
// src/core/qups-fields.ts
function withQupsFields(line) {
const c = line.columns;
return {
truth: c.truth,
quantity: c.quantity,
quantity_ratio_numerator: c.quantityRatioNumerator,
quantity_ratio_denominator: c.quantityRatioDenominator,
currency: c.currency,
unit_price_amount: c.unitPriceAmount,
subtotal_amount: c.subtotalAmount,
tax_rate_percent: c.taxRatePercent,
tax_mode: c.taxMode,
tax_amount: c.taxAmount,
net_amount: c.netAmount,
gross_amount: c.grossAmount
};
}
function withQupsFieldsRow(row, line) {
return { ...row, ...withQupsFields(line) };
}
export {
AdjustedAmount,
CurrencyMismatchError,
InvalidTruthError,
LineNotFoundError,
LineTax,
MissingDependencyError,
PricingLine,
ProfileNotFoundError,
QUPS_TRUTH_MODES,
Qups,
QupsError,
applyCellPatch,
calculateLine,
createQups,
editableFieldKeys,
fieldsForTruth,
isBuiltinFieldKey,
isQupsTruthMode,
lineFieldMap,
modifiersToRecords,
moneyColumnPair,
patchLine,
pricingLineFromRecord,
pricingLineInputFromParts,
qupsRolesFor,
recordFromPricingLine,
recordsToModifiers,
syncFieldRoles,
withQupsColumns,
withQupsFields,
withQupsFieldsRow
};
//# sourceMappingURL=index.js.map