@managesome/eposmatic-toolkit 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/constants/MATERIALIZED_REPORTS.js +448 -0
- package/esm/constants/enums/communications.js +1 -0
- package/esm/helpers/index.js +3 -0
- package/esm/helpers/materialized-reports/index.js +32 -0
- package/esm/helpers/materialized-reports/materialized-cash-accumulator-helpers.js +114 -0
- package/esm/helpers/materialized-reports/materialized-cash-classification-helpers.js +286 -0
- package/esm/helpers/materialized-reports/materialized-cash-close-day-helpers.js +396 -0
- package/esm/helpers/materialized-reports/materialized-cash-compile-helpers.js +244 -0
- package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +170 -0
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +426 -0
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +372 -0
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +214 -0
- package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +318 -0
- package/esm/helpers/materialized-reports/materialized-discount-classification-helpers.js +213 -0
- package/esm/helpers/materialized-reports/materialized-discount-close-day-helpers.js +604 -0
- package/esm/helpers/materialized-reports/materialized-discount-compile-helpers.js +186 -0
- package/esm/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.js +155 -0
- package/esm/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.js +199 -0
- package/esm/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +111 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +88 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.js +394 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.js +167 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +215 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +476 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +201 -0
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +7 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +189 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +157 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +588 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +175 -0
- package/esm/helpers/materialized-reports/tenant-cash-in-out-formatter.js +156 -0
- package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +230 -0
- package/esm/helpers/materialized-reports/tenant-discount-formatter.js +427 -0
- package/esm/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +237 -0
- package/esm/helpers/materialized-reports/tenant-payments-comparison-formatter.js +279 -0
- package/esm/helpers/materialized-reports/tenant-prep-time-formatter.js +228 -0
- package/esm/helpers/materialized-reports/tenant-sales-comparison-formatter.js +343 -0
- package/esm/helpers/reporting-contract/index.js +2 -0
- package/esm/helpers/reporting-contract/overview-contract.js +122 -0
- package/esm/helpers/reporting-contract/report-contract.js +228 -0
- package/esm/helpers/rider-earnings/index.js +1 -0
- package/esm/helpers/rider-earnings/rider-earnings.js +59 -0
- package/esm/helpers/rider-reports/index.js +2 -0
- package/esm/helpers/rider-reports/rider-daily-report.js +90 -0
- package/esm/helpers/rider-reports/rider-report.js +67 -0
- package/esm/schemas/models/deliveries.js +75 -0
- package/esm/schemas/models/index.js +15 -0
- package/esm/schemas/models/materialized_rider_daily_reports.js +39 -0
- package/esm/schemas/models/materialized_tenant_cash_entries.js +95 -0
- package/esm/schemas/models/materialized_tenant_cash_reports.js +77 -0
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +63 -0
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +63 -0
- package/esm/schemas/models/materialized_tenant_discount_entries.js +156 -0
- package/esm/schemas/models/materialized_tenant_discount_reports.js +333 -0
- package/esm/schemas/models/materialized_tenant_hourly_comparison_entries.js +87 -0
- package/esm/schemas/models/materialized_tenant_hourly_comparison_reports.js +99 -0
- package/esm/schemas/models/materialized_tenant_payments_comparison_entries.js +71 -0
- package/esm/schemas/models/materialized_tenant_payments_comparison_reports.js +76 -0
- package/esm/schemas/models/materialized_tenant_prep_time_entries.js +130 -0
- package/esm/schemas/models/materialized_tenant_prep_time_reports.js +109 -0
- package/esm/schemas/models/materialized_tenant_sales_comparison_entries.js +130 -0
- package/esm/schemas/models/materialized_tenant_sales_comparison_reports.js +154 -0
- package/esm/schemas/types/index.js +15 -0
- package/esm/schemas/types/materialized_rider_daily_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_cash_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_cash_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_delivery_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_delivery_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_discount_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_discount_reports.js +2 -0
- package/esm/schemas/types/materialized_tenant_hourly_comparison_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_hourly_comparison_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_payments_comparison_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_payments_comparison_reports.js +11 -0
- package/esm/schemas/types/materialized_tenant_prep_time_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_prep_time_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_sales_comparison_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_sales_comparison_reports.js +14 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +339 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +450 -1
- package/lib/constants/enums/communications.d.ts +1 -0
- package/lib/constants/enums/communications.js +2 -1
- package/lib/helpers/index.d.ts +3 -0
- package/lib/helpers/index.js +3 -0
- package/lib/helpers/materialized-reports/index.d.ts +32 -0
- package/lib/helpers/materialized-reports/index.js +32 -0
- package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.d.ts +18 -0
- package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.js +118 -0
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.d.ts +90 -0
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.js +295 -0
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.d.ts +102 -0
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.js +409 -0
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.d.ts +72 -0
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +251 -0
- package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.d.ts +7 -0
- package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +173 -0
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +84 -0
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +438 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +97 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +385 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +40 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +218 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +52 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +324 -0
- package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.d.ts +50 -0
- package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.js +222 -0
- package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.d.ts +182 -0
- package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.js +615 -0
- package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.d.ts +47 -0
- package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +193 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.d.ts +64 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.js +163 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.d.ts +61 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.js +207 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.d.ts +23 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +116 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.d.ts +25 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +98 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.d.ts +79 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.js +407 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.d.ts +35 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.js +173 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.d.ts +66 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +224 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +128 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +490 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.d.ts +46 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +208 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +8 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +8 -1
- package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.d.ts +48 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +204 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.d.ts +22 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +161 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.d.ts +163 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +603 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.d.ts +68 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +182 -0
- package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.d.ts +98 -0
- package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.js +159 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +133 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +233 -0
- package/lib/helpers/materialized-reports/tenant-discount-formatter.d.ts +114 -0
- package/lib/helpers/materialized-reports/tenant-discount-formatter.js +431 -0
- package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.d.ts +60 -0
- package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +243 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.d.ts +75 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.js +286 -0
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +97 -0
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.js +232 -0
- package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.d.ts +105 -0
- package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.js +349 -0
- package/lib/helpers/reporting-contract/index.d.ts +2 -0
- package/lib/helpers/reporting-contract/index.js +18 -0
- package/lib/helpers/reporting-contract/overview-contract.d.ts +55 -0
- package/lib/helpers/reporting-contract/overview-contract.js +126 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +159 -0
- package/lib/helpers/reporting-contract/report-contract.js +239 -0
- package/lib/helpers/rider-earnings/index.d.ts +1 -0
- package/lib/helpers/rider-earnings/index.js +17 -0
- package/lib/helpers/rider-earnings/rider-earnings.d.ts +58 -0
- package/lib/helpers/rider-earnings/rider-earnings.js +64 -0
- package/lib/helpers/rider-reports/index.d.ts +2 -0
- package/lib/helpers/rider-reports/index.js +18 -0
- package/lib/helpers/rider-reports/rider-daily-report.d.ts +26 -0
- package/lib/helpers/rider-reports/rider-daily-report.js +93 -0
- package/lib/helpers/rider-reports/rider-report.d.ts +49 -0
- package/lib/helpers/rider-reports/rider-report.js +70 -0
- package/lib/helpers/types/materialized-reports-apis.d.ts +297 -1
- package/lib/schemas/models/deliveries.d.ts +54 -0
- package/lib/schemas/models/deliveries.js +75 -0
- package/lib/schemas/models/expense_details.d.ts +3 -3
- package/lib/schemas/models/index.d.ts +15 -0
- package/lib/schemas/models/index.js +15 -0
- package/lib/schemas/models/materialized_rider_daily_reports.d.ts +27 -0
- package/lib/schemas/models/materialized_rider_daily_reports.js +42 -0
- package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +181 -0
- package/lib/schemas/models/materialized_tenant_cash_entries.js +98 -0
- package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +111 -0
- package/lib/schemas/models/materialized_tenant_cash_reports.js +80 -0
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +98 -0
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +66 -0
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +98 -0
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +66 -0
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +199 -0
- package/lib/schemas/models/materialized_tenant_discount_entries.js +159 -0
- package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +216 -0
- package/lib/schemas/models/materialized_tenant_discount_reports.js +336 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +95 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.js +82 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +105 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.js +91 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +91 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.js +70 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +98 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.js +71 -0
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +181 -0
- package/lib/schemas/models/materialized_tenant_prep_time_entries.js +133 -0
- package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +118 -0
- package/lib/schemas/models/materialized_tenant_prep_time_reports.js +112 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +139 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.js +120 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +167 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.js +137 -0
- package/lib/schemas/models/tenant_purchase_order_vendor_returns.d.ts +3 -3
- package/lib/schemas/models/warehouse_internal_movements.d.ts +6 -6
- package/lib/schemas/models/warehouse_purchase_order_receipts.d.ts +3 -3
- package/lib/schemas/models/warehouse_purchase_order_vendor_returns.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_deliveries.d.ts +6 -6
- package/lib/schemas/models/warehouse_sale_invoices.d.ts +3 -3
- package/lib/schemas/types/deliveries.d.ts +40 -1
- package/lib/schemas/types/index.d.ts +15 -0
- package/lib/schemas/types/index.js +15 -0
- package/lib/schemas/types/materialized_rider_daily_reports.d.ts +37 -0
- package/lib/schemas/types/materialized_rider_daily_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_cash_entries.d.ts +87 -0
- package/lib/schemas/types/materialized_tenant_cash_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_cash_reports.d.ts +144 -0
- package/lib/schemas/types/materialized_tenant_cash_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +98 -0
- package/lib/schemas/types/materialized_tenant_delivery_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +179 -0
- package/lib/schemas/types/materialized_tenant_delivery_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_discount_entries.d.ts +81 -0
- package/lib/schemas/types/materialized_tenant_discount_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_discount_reports.d.ts +209 -0
- package/lib/schemas/types/materialized_tenant_discount_reports.js +3 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.d.ts +33 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.d.ts +40 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_entries.d.ts +48 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_reports.d.ts +51 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_reports.js +14 -0
- package/lib/schemas/types/materialized_tenant_prep_time_entries.d.ts +88 -0
- package/lib/schemas/types/materialized_tenant_prep_time_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +132 -0
- package/lib/schemas/types/materialized_tenant_prep_time_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_entries.d.ts +43 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_reports.d.ts +74 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_reports.js +17 -0
- package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/fixtures.d.ts +15 -1
- package/lib/tests/materialized-reports/fixtures.js +1 -0
- package/lib/tests/materialized-reports/materialized-cash-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-compile.test.js +196 -0
- package/lib/tests/materialized-reports/materialized-cash-fold.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-fold.test.js +116 -0
- package/lib/tests/materialized-reports/materialized-cash-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-formatter.test.js +152 -0
- package/lib/tests/materialized-reports/materialized-cash-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-plan.test.js +168 -0
- package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.js +267 -0
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +147 -0
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +241 -0
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +109 -0
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +141 -0
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +198 -0
- package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.js +173 -0
- package/lib/tests/materialized-reports/materialized-discount-classification.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-classification.test.js +339 -0
- package/lib/tests/materialized-reports/materialized-discount-close-day.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-close-day.test.js +506 -0
- package/lib/tests/materialized-reports/materialized-discount-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-compile.test.js +161 -0
- package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.js +107 -0
- package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.js +125 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.js +146 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.js +127 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.js +138 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.js +90 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.js +164 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.js +117 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.js +149 -0
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +273 -0
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +270 -0
- package/lib/tests/materialized-reports/materialized-prep-time-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-compile.test.js +217 -0
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +84 -0
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +176 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.js +126 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.js +206 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.js +179 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.js +196 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.js +241 -0
- package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.js +96 -0
- package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.js +112 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.js +142 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +8 -1
- package/lib/tests/materialized-reports/sales-comparison-reference.d.ts +55 -0
- package/lib/tests/materialized-reports/sales-comparison-reference.js +86 -0
- package/lib/tests/materialized-reports/tenant-discount-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-discount-formatter.test.js +289 -0
- package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.js +354 -0
- package/lib/tests/reporting-contract.test.d.ts +1 -0
- package/lib/tests/reporting-contract.test.js +267 -0
- package/lib/tests/rider-daily-report.test.d.ts +1 -0
- package/lib/tests/rider-daily-report.test.js +86 -0
- package/lib/tests/rider-earnings.test.d.ts +1 -0
- package/lib/tests/rider-earnings.test.js +65 -0
- package/lib/tests/rider-report.test.d.ts +1 -0
- package/lib/tests/rider-report.test.js +98 -0
- package/package.json +10 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IOrder } from '../../schemas/types/orders';
|
|
2
|
+
import { IMaterializedDiscountEntry } from '../../schemas/types/materialized_tenant_discount_entries';
|
|
3
|
+
import { IMaterializedDiscountOrderCounters, IMaterializedDiscountSlotCounter } from '../../schemas/types/materialized_tenant_discount_reports';
|
|
4
|
+
import { createEmptyDiscountSlotCounter } from './materialized-discount-classification-helpers';
|
|
5
|
+
/**
|
|
6
|
+
* The discounts-report ACCUMULATOR (M1) — folds ONE order into:
|
|
7
|
+
*
|
|
8
|
+
* - the counter block of its key (`IMaterializedDiscountOrderCounters`), and
|
|
9
|
+
* - the itemized drill-down rows (`IMaterializedDiscountEntry[]`).
|
|
10
|
+
*
|
|
11
|
+
* Both outputs come from the SAME pass, so the counters and the rows the
|
|
12
|
+
* drill-down lists can never disagree (the same single-writer discipline the
|
|
13
|
+
* credit ledger uses).
|
|
14
|
+
*
|
|
15
|
+
* Money rules (see the classifier module and
|
|
16
|
+
* `docs/report-discounts-concept.md` §5):
|
|
17
|
+
* - `amount` — RAW slot values; PERCENT for percentage rows. This is
|
|
18
|
+
* the only value comparable to the sales overview's
|
|
19
|
+
* `discount_by_type`.
|
|
20
|
+
* - `resolved_amount` — the MONEY the row applied.
|
|
21
|
+
* - Order-level money the slots cannot explain lands in `unattributed_amount`
|
|
22
|
+
* (measured 0 in both dev stores — a tripwire, never silently dropped).
|
|
23
|
+
* - Negative discounts are surcharges (the POS drops them from
|
|
24
|
+
* `total_discount_applied`); they contribute nothing here.
|
|
25
|
+
*
|
|
26
|
+
* Pure and total: no throws, no clock, no I/O.
|
|
27
|
+
*/
|
|
28
|
+
/** Punch-hour label of an order's local day (`'YYYY-MM-DD HH'`), hour = 0..23. */
|
|
29
|
+
export interface IDiscountOrderContext {
|
|
30
|
+
/** `order.localDate` — the business day the order compiles into. */
|
|
31
|
+
local_date: string;
|
|
32
|
+
/** Punch hour 0..23 when resolvable, else null (hour docs are then skipped). */
|
|
33
|
+
local_hour: number | null;
|
|
34
|
+
/** `'YYYY-MM-DD HH'` label (null when the hour is unknown). */
|
|
35
|
+
local_hour_label: string | null;
|
|
36
|
+
}
|
|
37
|
+
export interface IAccumulateOrderDiscountsResult {
|
|
38
|
+
counters: IMaterializedDiscountOrderCounters;
|
|
39
|
+
entries: IMaterializedDiscountEntry[];
|
|
40
|
+
/** Orders the accumulator would count (has ANY discount or a comp payment). */
|
|
41
|
+
has_discount: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** The line label of a punch hour (null when the hour is unknown). */
|
|
44
|
+
export declare const toDiscountHourLabel: (localDate: string, hour: number | null) => string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Folds ONE order into counters + rows. Returns zeroed counters and no rows for
|
|
47
|
+
* an order with no discounts (the caller decides whether to keep the key).
|
|
48
|
+
*/
|
|
49
|
+
export declare function accumulateOrderDiscounts(order: IOrder | null | undefined, context: IDiscountOrderContext): IAccumulateOrderDiscountsResult;
|
|
50
|
+
/** Folds a slot counter map into a target (used by tests + the key fold). */
|
|
51
|
+
export declare function mergeDiscountSlotCounters(target: IMaterializedDiscountSlotCounter, source: IMaterializedDiscountSlotCounter | null | undefined): void;
|
|
52
|
+
export { createEmptyDiscountSlotCounter };
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmptyDiscountSlotCounter = exports.toDiscountHourLabel = void 0;
|
|
4
|
+
exports.accumulateOrderDiscounts = accumulateOrderDiscounts;
|
|
5
|
+
exports.mergeDiscountSlotCounters = mergeDiscountSlotCounters;
|
|
6
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
7
|
+
const materialized_discount_classification_helpers_1 = require("./materialized-discount-classification-helpers");
|
|
8
|
+
Object.defineProperty(exports, "createEmptyDiscountSlotCounter", { enumerable: true, get: function () { return materialized_discount_classification_helpers_1.createEmptyDiscountSlotCounter; } });
|
|
9
|
+
const isComplimentaryPayment = (payment) => payment?.payment_type === 'COMPLIMENTARY';
|
|
10
|
+
const nonNegative = (value) => (Number.isFinite(value) && value > 0 ? value : 0);
|
|
11
|
+
/** The line label of a punch hour (null when the hour is unknown). */
|
|
12
|
+
const toDiscountHourLabel = (localDate, hour) => hour == null || hour < 0 || hour > 23 ? null : `${localDate} ${String(hour).padStart(2, '0')}`;
|
|
13
|
+
exports.toDiscountHourLabel = toDiscountHourLabel;
|
|
14
|
+
/** Base row fields shared by every discount entry. */
|
|
15
|
+
function entryBase(order, context, kind) {
|
|
16
|
+
return {
|
|
17
|
+
kind,
|
|
18
|
+
order_id: String(order._id),
|
|
19
|
+
order_number: order.order_number ?? null,
|
|
20
|
+
item_id: null,
|
|
21
|
+
item_name: null,
|
|
22
|
+
payment_id: null,
|
|
23
|
+
rate: null,
|
|
24
|
+
is_percentage: null,
|
|
25
|
+
item_value: null,
|
|
26
|
+
discount_id: null,
|
|
27
|
+
name: null,
|
|
28
|
+
reference_number: null,
|
|
29
|
+
reason: null,
|
|
30
|
+
staff_id: order.staff_details?.staff_id ?? null,
|
|
31
|
+
staff_name: order.staff_details?.staff_name ?? null,
|
|
32
|
+
order_taker_id: order.order_taker_details?.staff_id ?? null,
|
|
33
|
+
order_taker_name: order.order_taker_details?.staff_name ?? null,
|
|
34
|
+
order_status: String(order.order_status ?? ''),
|
|
35
|
+
platform: String(order.platform ?? ''),
|
|
36
|
+
created_at: new Date(order.createdAt ?? context.local_date),
|
|
37
|
+
local_hour: context.local_hour_label,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Adds one ORDER-LEVEL slot reading into its counters + rows. */
|
|
41
|
+
function accumulateOrderSlot(counters, entries, order, context, reading, resolved) {
|
|
42
|
+
const raw = nonNegative(reading.rate);
|
|
43
|
+
const money = nonNegative(resolved);
|
|
44
|
+
const slotCounter = reading.slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL
|
|
45
|
+
? counters.order_special
|
|
46
|
+
: reading.slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY
|
|
47
|
+
? counters.order_loyalty
|
|
48
|
+
: counters.order_voucher;
|
|
49
|
+
slotCounter.count += 1;
|
|
50
|
+
slotCounter.amount += raw;
|
|
51
|
+
slotCounter.resolved_amount += money;
|
|
52
|
+
const subCounter = orderSubKindCounter(counters, reading.slot, reading.sub_kind);
|
|
53
|
+
subCounter.count += 1;
|
|
54
|
+
subCounter.amount += raw;
|
|
55
|
+
subCounter.resolved_amount += money;
|
|
56
|
+
entries.push({
|
|
57
|
+
...entryBase(order, context, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.DISCOUNT),
|
|
58
|
+
slot: reading.slot,
|
|
59
|
+
sub_kind: reading.sub_kind,
|
|
60
|
+
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER,
|
|
61
|
+
entry_key: `order:${reading.slot.toLowerCase()}`,
|
|
62
|
+
amount: money,
|
|
63
|
+
rate: raw,
|
|
64
|
+
is_percentage: reading.is_percentage,
|
|
65
|
+
discount_id: reading.discount_id,
|
|
66
|
+
name: reading.name,
|
|
67
|
+
reference_number: reading.reference_number,
|
|
68
|
+
reason: reading.reason,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Maps an order-level sub-kind to its dedicated counter. */
|
|
72
|
+
function orderSubKindCounter(counters, slot, subKind) {
|
|
73
|
+
if (slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL) {
|
|
74
|
+
switch (subKind) {
|
|
75
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION:
|
|
76
|
+
return counters.special_collection;
|
|
77
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.MANUAL:
|
|
78
|
+
return counters.special_manual;
|
|
79
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.PRICE_OVERRIDE:
|
|
80
|
+
return counters.special_price_override;
|
|
81
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM:
|
|
82
|
+
return counters.special_catalog_item;
|
|
83
|
+
default:
|
|
84
|
+
return counters.special_other;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY) {
|
|
88
|
+
switch (subKind) {
|
|
89
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER:
|
|
90
|
+
return counters.loyalty_offer;
|
|
91
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.GIFT_CARD:
|
|
92
|
+
return counters.loyalty_gift_card;
|
|
93
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK:
|
|
94
|
+
return counters.loyalty_wallet;
|
|
95
|
+
default:
|
|
96
|
+
return counters.loyalty_other;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return subKind === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER ? counters.voucher_offer : counters.voucher_other;
|
|
100
|
+
}
|
|
101
|
+
/** Adds one ITEM-LEVEL slot reading into its counters + rows. */
|
|
102
|
+
function accumulateItemSlot(counters, entries, order, context, itemId, itemName, itemValue, reading, resolved, itemTotal) {
|
|
103
|
+
const raw = nonNegative(reading.rate);
|
|
104
|
+
const money = nonNegative(resolved);
|
|
105
|
+
const isFree = reading.is_percentage && reading.rate >= 100;
|
|
106
|
+
if (reading.slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL) {
|
|
107
|
+
const counter = counters.item_special;
|
|
108
|
+
counter.count += 1;
|
|
109
|
+
counter.amount += raw;
|
|
110
|
+
counter.resolved_amount += money;
|
|
111
|
+
switch (reading.sub_kind) {
|
|
112
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION:
|
|
113
|
+
counter.collection_count += 1;
|
|
114
|
+
counter.collection_amount += raw;
|
|
115
|
+
counter.collection_resolved_amount += money;
|
|
116
|
+
break;
|
|
117
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.MANUAL:
|
|
118
|
+
counter.manual_count += 1;
|
|
119
|
+
counter.manual_amount += raw;
|
|
120
|
+
counter.manual_resolved_amount += money;
|
|
121
|
+
break;
|
|
122
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.PRICE_OVERRIDE:
|
|
123
|
+
counter.price_override_count += 1;
|
|
124
|
+
counter.price_override_amount += raw;
|
|
125
|
+
counter.price_override_resolved_amount += money;
|
|
126
|
+
break;
|
|
127
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM:
|
|
128
|
+
counter.catalog_item_count += 1;
|
|
129
|
+
counter.catalog_item_amount += raw;
|
|
130
|
+
counter.catalog_item_resolved_amount += money;
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
counter.other_count += 1;
|
|
134
|
+
counter.other_amount += raw;
|
|
135
|
+
counter.other_resolved_amount += money;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (reading.slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY) {
|
|
140
|
+
const counter = counters.item_loyalty;
|
|
141
|
+
counter.count += 1;
|
|
142
|
+
counter.amount += raw;
|
|
143
|
+
counter.resolved_amount += money;
|
|
144
|
+
switch (reading.sub_kind) {
|
|
145
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER:
|
|
146
|
+
counter.offer_count += 1;
|
|
147
|
+
counter.offer_amount += raw;
|
|
148
|
+
counter.offer_resolved_amount += money;
|
|
149
|
+
break;
|
|
150
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.GIFT_CARD:
|
|
151
|
+
counter.gift_card_count += 1;
|
|
152
|
+
counter.gift_card_amount += raw;
|
|
153
|
+
counter.gift_card_resolved_amount += money;
|
|
154
|
+
break;
|
|
155
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK:
|
|
156
|
+
counter.wallet_count += 1;
|
|
157
|
+
counter.wallet_amount += raw;
|
|
158
|
+
counter.wallet_resolved_amount += money;
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
counter.other_count += 1;
|
|
162
|
+
counter.other_amount += raw;
|
|
163
|
+
counter.other_resolved_amount += money;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const counter = counters.item_voucher;
|
|
169
|
+
counter.count += 1;
|
|
170
|
+
counter.amount += raw;
|
|
171
|
+
counter.resolved_amount += money;
|
|
172
|
+
if (reading.reference_number != null)
|
|
173
|
+
counter.ref_count += 1;
|
|
174
|
+
if (reading.sub_kind === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER) {
|
|
175
|
+
counter.offer_count += 1;
|
|
176
|
+
counter.offer_amount += raw;
|
|
177
|
+
counter.offer_resolved_amount += money;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (isFree) {
|
|
181
|
+
counters.free_items.count += 1;
|
|
182
|
+
counters.free_items.amount += raw;
|
|
183
|
+
counters.free_items.resolved_amount += money;
|
|
184
|
+
counters.free_items.value += nonNegative(itemValue);
|
|
185
|
+
}
|
|
186
|
+
entries.push({
|
|
187
|
+
...entryBase(order, context, isFree ? MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.FREE_ITEM : MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.DISCOUNT),
|
|
188
|
+
slot: reading.slot,
|
|
189
|
+
sub_kind: reading.sub_kind,
|
|
190
|
+
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
191
|
+
entry_key: `item:${itemId}:${reading.slot.toLowerCase()}`,
|
|
192
|
+
amount: money,
|
|
193
|
+
rate: raw,
|
|
194
|
+
is_percentage: reading.is_percentage,
|
|
195
|
+
item_id: itemId,
|
|
196
|
+
item_name: itemName,
|
|
197
|
+
item_value: isFree ? nonNegative(itemValue) : null,
|
|
198
|
+
discount_id: reading.discount_id,
|
|
199
|
+
name: reading.name,
|
|
200
|
+
reference_number: reading.reference_number,
|
|
201
|
+
reason: reading.reason,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Folds ONE order into counters + rows. Returns zeroed counters and no rows for
|
|
206
|
+
* an order with no discounts (the caller decides whether to keep the key).
|
|
207
|
+
*/
|
|
208
|
+
function accumulateOrderDiscounts(order, context) {
|
|
209
|
+
const counters = (0, materialized_discount_classification_helpers_1.createEmptyDiscountOrderCounters)();
|
|
210
|
+
const entries = [];
|
|
211
|
+
if (order == null)
|
|
212
|
+
return { counters, entries, has_discount: false };
|
|
213
|
+
const orderDetails = order.order_discount_details ?? null;
|
|
214
|
+
const applied = nonNegative(Number(order.total_discount_applied ?? 0));
|
|
215
|
+
const storedOrderTotal = nonNegative(orderDetails?.total_discount != null ? Number(orderDetails.total_discount) : 0);
|
|
216
|
+
// ---- order level -------------------------------------------------------
|
|
217
|
+
const orderMoney = (0, materialized_discount_classification_helpers_1.resolveRowMoney)(orderDetails, storedOrderTotal);
|
|
218
|
+
// Slot PRESENCE = a positive rate OR an id. Zero-rate slots that carry an id
|
|
219
|
+
// do occur live, and they are real (zero-money) facts the drill-down shows —
|
|
220
|
+
// but the COUNTERS only add money, so an empty slot can never inflate a count
|
|
221
|
+
// or an amount.
|
|
222
|
+
// A slot COUNTS only when it applied money. Live data holds zero-money slots
|
|
223
|
+
// that still carry an id (a discount that was attempted then cleared — the
|
|
224
|
+
// writer leaves `*_discount: 0` with the id behind), and counting those would
|
|
225
|
+
// inflate every occurrence counter while adding nothing to the money; it would
|
|
226
|
+
// also break the "resolved slots explain the row total" invariant. They are
|
|
227
|
+
// therefore excluded here (the row itself is not a discount row).
|
|
228
|
+
const orderReadings = materialized_discount_classification_helpers_1.MATERIALIZED_DISCOUNT_SLOTS.map((slot) => (0, materialized_discount_classification_helpers_1.readDiscountSlot)(orderDetails, slot))
|
|
229
|
+
.filter((reading) => reading != null && reading.rate >= 0)
|
|
230
|
+
.map((reading) => ({ reading, money: nonNegative(orderMoney.perSlot.get(reading.slot) ?? 0) }))
|
|
231
|
+
.filter((entry) => entry.money > 0);
|
|
232
|
+
for (const { reading, money } of orderReadings) {
|
|
233
|
+
accumulateOrderSlot(counters, entries, order, context, reading, money);
|
|
234
|
+
}
|
|
235
|
+
if (storedOrderTotal > 0) {
|
|
236
|
+
counters.order_level_amount += storedOrderTotal;
|
|
237
|
+
// Money the slots cannot explain (no slots at all, several active slots, or
|
|
238
|
+
// a slot value the row total contradicts) is a tripwire: counted, never
|
|
239
|
+
// silently dropped.
|
|
240
|
+
counters.unattributed_amount += nonNegative(orderMoney.unallocated);
|
|
241
|
+
}
|
|
242
|
+
// ---- item level --------------------------------------------------------
|
|
243
|
+
let itemLevelTotal = 0;
|
|
244
|
+
for (const category of order.categories ?? []) {
|
|
245
|
+
for (const item of category.items ?? []) {
|
|
246
|
+
const itemDetails = item.item_discount_details ?? null;
|
|
247
|
+
const itemTotal = nonNegative(Number(itemDetails?.total_discount ?? 0));
|
|
248
|
+
if (itemTotal <= 0)
|
|
249
|
+
continue;
|
|
250
|
+
itemLevelTotal += itemTotal;
|
|
251
|
+
counters.item_discount_count += 1;
|
|
252
|
+
// The item's own value for a FREE_ITEM row: the net (post-discount) amount
|
|
253
|
+
// when the writer computed item metadata, else the list price. Never used
|
|
254
|
+
// for any counter total — display context only.
|
|
255
|
+
// Prefer the net (post-discount) amount, then the gross, then the list
|
|
256
|
+
// price — a fully discounted item has net 0, so a plain ?? chain would
|
|
257
|
+
// report its value as 0.
|
|
258
|
+
const netValue = nonNegative(Number(item._net_amount ?? 0));
|
|
259
|
+
const itemValue = netValue > 0 ? netValue : nonNegative(Number(item._gross_amount ?? item.price ?? 0));
|
|
260
|
+
const itemMoney = (0, materialized_discount_classification_helpers_1.resolveRowMoney)(itemDetails, itemTotal);
|
|
261
|
+
const itemReadings = materialized_discount_classification_helpers_1.MATERIALIZED_DISCOUNT_SLOTS.map((slot) => (0, materialized_discount_classification_helpers_1.readDiscountSlot)(itemDetails, slot))
|
|
262
|
+
.filter((reading) => reading != null && reading.rate >= 0)
|
|
263
|
+
.map((reading) => ({ reading, money: nonNegative(itemMoney.perSlot.get(reading.slot) ?? 0) }))
|
|
264
|
+
.filter((entry) => entry.money > 0);
|
|
265
|
+
if (itemReadings.length === 0) {
|
|
266
|
+
// Item money with no usable slot: keep it in the item total (so the
|
|
267
|
+
// headline reconciles) and record one unattributed row for the
|
|
268
|
+
// drill-down to show.
|
|
269
|
+
entries.push({
|
|
270
|
+
...entryBase(order, context, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.DISCOUNT),
|
|
271
|
+
slot: null,
|
|
272
|
+
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED,
|
|
273
|
+
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
274
|
+
entry_key: `item:${String(item._id)}:unattributed`,
|
|
275
|
+
amount: itemTotal,
|
|
276
|
+
item_id: String(item._id),
|
|
277
|
+
item_name: item.name ?? null,
|
|
278
|
+
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
for (const { reading, money } of itemReadings) {
|
|
282
|
+
accumulateItemSlot(counters, entries, order, context, String(item._id), item.name ?? null, itemValue, reading, money, itemTotal);
|
|
283
|
+
}
|
|
284
|
+
// Multi-slot / fixed-slot leftovers stay visible on the order-level
|
|
285
|
+
// tripwire so anchors E/H keep holding.
|
|
286
|
+
counters.unattributed_amount += nonNegative(itemMoney.unallocated);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
counters.item_level_amount += itemLevelTotal;
|
|
290
|
+
// ---- headline + comp ---------------------------------------------------
|
|
291
|
+
counters.amount += applied;
|
|
292
|
+
let compAmount = 0;
|
|
293
|
+
for (const payment of order.payments ?? []) {
|
|
294
|
+
if (!isComplimentaryPayment(payment))
|
|
295
|
+
continue;
|
|
296
|
+
counters.complimentary.payment_count += 1;
|
|
297
|
+
if (payment.note)
|
|
298
|
+
counters.complimentary.note_count += 1;
|
|
299
|
+
entries.push({
|
|
300
|
+
...entryBase(order, context, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.COMPLIMENTARY),
|
|
301
|
+
slot: null,
|
|
302
|
+
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED,
|
|
303
|
+
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.PAYMENT,
|
|
304
|
+
entry_key: `payment:${String(payment._id)}`,
|
|
305
|
+
amount: 0,
|
|
306
|
+
payment_id: payment._id != null ? String(payment._id) : null,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (counters.complimentary.payment_count > 0) {
|
|
310
|
+
compAmount = nonNegative(Number(order.amount_earned ?? 0));
|
|
311
|
+
counters.complimentary.amount += compAmount;
|
|
312
|
+
}
|
|
313
|
+
// ONE count per order with any discount or comp payment — incremented exactly
|
|
314
|
+
// once, after every source has been folded (a double increment here would
|
|
315
|
+
// silently inflate the "orders with a discount" KPI).
|
|
316
|
+
const hasDiscount = counters.order_level_amount > 0 || counters.item_level_amount > 0 || counters.complimentary.payment_count > 0;
|
|
317
|
+
if (hasDiscount)
|
|
318
|
+
counters.count = 1;
|
|
319
|
+
return { counters, entries, has_discount: hasDiscount };
|
|
320
|
+
}
|
|
321
|
+
/** Folds a slot counter map into a target (used by tests + the key fold). */
|
|
322
|
+
function mergeDiscountSlotCounters(target, source) {
|
|
323
|
+
(0, materialized_discount_classification_helpers_1.mergeDiscountSlotCounter)(target, source);
|
|
324
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MATERIALIZED_DISCOUNT_SLOT_ENUM, MATERIALIZED_DISCOUNT_SUB_KIND_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IDiscountDetails } from '../../schemas/types/orders';
|
|
3
|
+
import { IMaterializedDiscountOrderCounters, IMaterializedDiscountSlotCounter } from '../../schemas/types/materialized_tenant_discount_reports';
|
|
4
|
+
/** `'SPECIAL_DISCOUNT'` — the catalog item-discount sentinel (pos-web). */
|
|
5
|
+
export declare const MATERIALIZED_DISCOUNT_CATALOG_ITEM_ID = "SPECIAL_DISCOUNT";
|
|
6
|
+
export declare const MATERIALIZED_DISCOUNT_SLOTS: MATERIALIZED_DISCOUNT_SLOT_ENUM[];
|
|
7
|
+
export interface IDiscountSlotReading {
|
|
8
|
+
slot: MATERIALIZED_DISCOUNT_SLOT_ENUM;
|
|
9
|
+
sub_kind: MATERIALIZED_DISCOUNT_SUB_KIND_ENUM;
|
|
10
|
+
/** Raw slot value as stored (PERCENT for percentage rows). */
|
|
11
|
+
rate: number;
|
|
12
|
+
is_percentage: boolean;
|
|
13
|
+
discount_id: string | null;
|
|
14
|
+
name: string | null;
|
|
15
|
+
reference_number: string | null;
|
|
16
|
+
reason: string | null;
|
|
17
|
+
}
|
|
18
|
+
/** Reads ONE slot of an `IDiscountDetails` — null when the slot is empty. */
|
|
19
|
+
export declare function readDiscountSlot(details: IDiscountDetails | null | undefined, slot: MATERIALIZED_DISCOUNT_SLOT_ENUM): IDiscountSlotReading | null;
|
|
20
|
+
/**
|
|
21
|
+
* Classifies a slot's sub-kind from its id shape (and, for the special slot,
|
|
22
|
+
* the id's namespace).
|
|
23
|
+
*/
|
|
24
|
+
export declare function classifyDiscountSubKind(slot: MATERIALIZED_DISCOUNT_SLOT_ENUM, discountId: string | null): MATERIALIZED_DISCOUNT_SUB_KIND_ENUM;
|
|
25
|
+
/**
|
|
26
|
+
* The MONEY a row's slots applied.
|
|
27
|
+
*
|
|
28
|
+
* - `rowTotal` is the row's `total_discount` (order or item) — the authoritative
|
|
29
|
+
* money for the row.
|
|
30
|
+
* - A slot's resolved money is its own raw value when the row is a FIXED amount;
|
|
31
|
+
* when the slot is the row's ONLY active slot AND it is a percentage, the
|
|
32
|
+
* resolved money is the row total (a percentage of a base the order does not
|
|
33
|
+
* expose).
|
|
34
|
+
* - With several active slots the money cannot be split from the data, so it is
|
|
35
|
+
* returned as `unallocated` and the caller books it as unattributed rather
|
|
36
|
+
* than inventing a split.
|
|
37
|
+
*/
|
|
38
|
+
export interface IResolvedRowMoney {
|
|
39
|
+
perSlot: Map<MATERIALIZED_DISCOUNT_SLOT_ENUM, number>;
|
|
40
|
+
row_total: number;
|
|
41
|
+
allocated: number;
|
|
42
|
+
unallocated: number;
|
|
43
|
+
}
|
|
44
|
+
export declare function resolveRowMoney(details: IDiscountDetails | null | undefined, rowTotal: number): IResolvedRowMoney;
|
|
45
|
+
/** Empty slot counter. */
|
|
46
|
+
export declare const createEmptyDiscountSlotCounter: () => IMaterializedDiscountSlotCounter;
|
|
47
|
+
/** Empty counter block for one key — every field present and zeroed. */
|
|
48
|
+
export declare const createEmptyDiscountOrderCounters: () => IMaterializedDiscountOrderCounters;
|
|
49
|
+
/** Adds `source` counts/amounts into `target` (used by the key fold + tests). */
|
|
50
|
+
export declare function mergeDiscountSlotCounter(target: IMaterializedDiscountSlotCounter, source: IMaterializedDiscountSlotCounter | null | undefined): void;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmptyDiscountOrderCounters = exports.createEmptyDiscountSlotCounter = exports.MATERIALIZED_DISCOUNT_SLOTS = exports.MATERIALIZED_DISCOUNT_CATALOG_ITEM_ID = void 0;
|
|
4
|
+
exports.readDiscountSlot = readDiscountSlot;
|
|
5
|
+
exports.classifyDiscountSubKind = classifyDiscountSubKind;
|
|
6
|
+
exports.resolveRowMoney = resolveRowMoney;
|
|
7
|
+
exports.mergeDiscountSlotCounter = mergeDiscountSlotCounter;
|
|
8
|
+
const COMMON_1 = require("../../constants/COMMON");
|
|
9
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
10
|
+
/**
|
|
11
|
+
* The discounts-report CLASSIFIER (M1) — pure functions that turn one order's
|
|
12
|
+
* discount slots into the counter contract of
|
|
13
|
+
* `materialized_tenant_discount_reports`.
|
|
14
|
+
*
|
|
15
|
+
* ## The two rules that define correctness
|
|
16
|
+
*
|
|
17
|
+
* 1. **Never sum raw slots as money.** A slot holds the ORIGINAL value: for a
|
|
18
|
+
* percentage discount it is the PERCENT (`special_discount: 25`), while the
|
|
19
|
+
* money actually applied sits in the row's `total_discount`. So every
|
|
20
|
+
* classified slot yields BOTH `amount` (raw — the only value comparable to
|
|
21
|
+
* the sales overview's `discount_by_type`) and `resolved_amount` (money).
|
|
22
|
+
* 2. **Classify by the ID SHAPE.** The write path stores no kind discriminator;
|
|
23
|
+
* the id is it: a 24-hex ObjectId is a `discounts` collection document,
|
|
24
|
+
* `MANUAL_SINGLE_` is a price override, `MANUAL_` is a quick/custom/
|
|
25
|
+
* payment-type discount, and the loyalty/voucher slots reference offers, gift
|
|
26
|
+
* cards or the wallet sentinel.
|
|
27
|
+
*
|
|
28
|
+
* Everything here is pure and total: no throws, no clock, no I/O. Invalid input
|
|
29
|
+
* degrades to `UNATTRIBUTED` / 0 so a report can never be broken by one odd
|
|
30
|
+
* order.
|
|
31
|
+
*/
|
|
32
|
+
const HEX24 = /^[0-9a-f]{24}$/i;
|
|
33
|
+
/** `'SPECIAL_DISCOUNT'` — the catalog item-discount sentinel (pos-web). */
|
|
34
|
+
exports.MATERIALIZED_DISCOUNT_CATALOG_ITEM_ID = 'SPECIAL_DISCOUNT';
|
|
35
|
+
exports.MATERIALIZED_DISCOUNT_SLOTS = [
|
|
36
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL,
|
|
37
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY,
|
|
38
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER,
|
|
39
|
+
];
|
|
40
|
+
/** Field-name prefix of a slot in `IDiscountDetails` (`special` → `special_discount`). */
|
|
41
|
+
const slotFieldKey = (slot) => slot.toLowerCase();
|
|
42
|
+
/** Reads ONE slot of an `IDiscountDetails` — null when the slot is empty. */
|
|
43
|
+
function readDiscountSlot(details, slot) {
|
|
44
|
+
if (details == null)
|
|
45
|
+
return null;
|
|
46
|
+
const key = slotFieldKey(slot);
|
|
47
|
+
const rate = Number(details[`${key}_discount`] ?? 0);
|
|
48
|
+
const idValue = details[`${key}_discount_id`];
|
|
49
|
+
const discount_id = typeof idValue === 'string' && idValue.length > 0 ? idValue : null;
|
|
50
|
+
// A slot counts as present when it carries money/percent OR an id. Zero-value
|
|
51
|
+
// slots with ids DO occur live (e.g. `is_loyalty_discount_percentage: true`
|
|
52
|
+
// with only `total_discount`) — they are read but contribute 0.
|
|
53
|
+
if (rate === 0 && discount_id == null)
|
|
54
|
+
return null;
|
|
55
|
+
return {
|
|
56
|
+
slot,
|
|
57
|
+
sub_kind: classifyDiscountSubKind(slot, discount_id),
|
|
58
|
+
rate: Number.isFinite(rate) ? rate : 0,
|
|
59
|
+
is_percentage: details[`is_${key}_discount_percentage`] === true,
|
|
60
|
+
discount_id,
|
|
61
|
+
name: details[`${key}_discount_name`] ?? null,
|
|
62
|
+
reference_number: details[`${key}_reference_number`] ?? null,
|
|
63
|
+
reason: details[`${key}_discount_reason`] ?? null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Classifies a slot's sub-kind from its id shape (and, for the special slot,
|
|
68
|
+
* the id's namespace).
|
|
69
|
+
*/
|
|
70
|
+
function classifyDiscountSubKind(slot, discountId) {
|
|
71
|
+
if (discountId == null)
|
|
72
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED;
|
|
73
|
+
if (slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER) {
|
|
74
|
+
return discountId === COMMON_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID
|
|
75
|
+
? MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK
|
|
76
|
+
: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER;
|
|
77
|
+
}
|
|
78
|
+
if (slot === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY) {
|
|
79
|
+
if (discountId === COMMON_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID) {
|
|
80
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK;
|
|
81
|
+
}
|
|
82
|
+
// Offers and gift cards both use ObjectIds; the reference number is what
|
|
83
|
+
// tells them apart (`buildGiftCardDiscountUpdate` writes the card code).
|
|
84
|
+
return HEX24.test(discountId)
|
|
85
|
+
? MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER
|
|
86
|
+
: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.GIFT_CARD;
|
|
87
|
+
}
|
|
88
|
+
// SPECIAL slot — the namespace prefix is the discriminator.
|
|
89
|
+
if (discountId === exports.MATERIALIZED_DISCOUNT_CATALOG_ITEM_ID) {
|
|
90
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM;
|
|
91
|
+
}
|
|
92
|
+
if (discountId.startsWith(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_PRICE_OVERRIDE_PREFIX)) {
|
|
93
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.PRICE_OVERRIDE;
|
|
94
|
+
}
|
|
95
|
+
if (discountId.startsWith(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_MANUAL_PREFIX)) {
|
|
96
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.MANUAL;
|
|
97
|
+
}
|
|
98
|
+
if (HEX24.test(discountId))
|
|
99
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION;
|
|
100
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM;
|
|
101
|
+
}
|
|
102
|
+
function resolveRowMoney(details, rowTotal) {
|
|
103
|
+
const perSlot = new Map();
|
|
104
|
+
const total = Number.isFinite(rowTotal) ? rowTotal : 0;
|
|
105
|
+
if (details == null || total <= 0) {
|
|
106
|
+
return { perSlot, row_total: Math.max(0, total), allocated: 0, unallocated: Math.max(0, total) };
|
|
107
|
+
}
|
|
108
|
+
const readings = exports.MATERIALIZED_DISCOUNT_SLOTS.map((slot) => readDiscountSlot(details, slot)).filter((reading) => reading != null && reading.rate > 0);
|
|
109
|
+
if (readings.length === 0) {
|
|
110
|
+
return { perSlot, row_total: total, allocated: 0, unallocated: total };
|
|
111
|
+
}
|
|
112
|
+
if (readings.length === 1) {
|
|
113
|
+
// Single active slot: percent rows resolve to the row total, fixed rows to
|
|
114
|
+
// their own value (clamped to the row total so a stale slot cannot
|
|
115
|
+
// over-report money the row never applied).
|
|
116
|
+
const [only] = readings;
|
|
117
|
+
const resolved = only.is_percentage ? total : Math.min(only.rate, total);
|
|
118
|
+
perSlot.set(only.slot, resolved);
|
|
119
|
+
return { perSlot, row_total: total, allocated: resolved, unallocated: Math.max(0, total - resolved) };
|
|
120
|
+
}
|
|
121
|
+
// Several active slots (allocated offers): every slot is a FIXED amount when
|
|
122
|
+
// more than one is active in practice, so assign each its own value and let
|
|
123
|
+
// the remainder be unattributed rather than guessing a split.
|
|
124
|
+
let allocated = 0;
|
|
125
|
+
for (const reading of readings) {
|
|
126
|
+
if (reading.is_percentage)
|
|
127
|
+
continue; // a % mixed with other slots is unsplittable
|
|
128
|
+
const value = Math.max(0, reading.rate);
|
|
129
|
+
perSlot.set(reading.slot, value);
|
|
130
|
+
allocated += value;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
perSlot,
|
|
134
|
+
row_total: total,
|
|
135
|
+
allocated,
|
|
136
|
+
unallocated: Math.max(0, total - allocated),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Empty slot counter. */
|
|
140
|
+
const createEmptyDiscountSlotCounter = () => ({
|
|
141
|
+
count: 0,
|
|
142
|
+
amount: 0,
|
|
143
|
+
resolved_amount: 0,
|
|
144
|
+
});
|
|
145
|
+
exports.createEmptyDiscountSlotCounter = createEmptyDiscountSlotCounter;
|
|
146
|
+
const createEmptyItemSpecial = () => ({
|
|
147
|
+
...(0, exports.createEmptyDiscountSlotCounter)(),
|
|
148
|
+
collection_count: 0,
|
|
149
|
+
collection_amount: 0,
|
|
150
|
+
collection_resolved_amount: 0,
|
|
151
|
+
manual_count: 0,
|
|
152
|
+
manual_amount: 0,
|
|
153
|
+
manual_resolved_amount: 0,
|
|
154
|
+
price_override_count: 0,
|
|
155
|
+
price_override_amount: 0,
|
|
156
|
+
price_override_resolved_amount: 0,
|
|
157
|
+
catalog_item_count: 0,
|
|
158
|
+
catalog_item_amount: 0,
|
|
159
|
+
catalog_item_resolved_amount: 0,
|
|
160
|
+
other_count: 0,
|
|
161
|
+
other_amount: 0,
|
|
162
|
+
other_resolved_amount: 0,
|
|
163
|
+
});
|
|
164
|
+
const createEmptyItemLoyalty = () => ({
|
|
165
|
+
...(0, exports.createEmptyDiscountSlotCounter)(),
|
|
166
|
+
offer_count: 0,
|
|
167
|
+
offer_amount: 0,
|
|
168
|
+
offer_resolved_amount: 0,
|
|
169
|
+
gift_card_count: 0,
|
|
170
|
+
gift_card_amount: 0,
|
|
171
|
+
gift_card_resolved_amount: 0,
|
|
172
|
+
wallet_count: 0,
|
|
173
|
+
wallet_amount: 0,
|
|
174
|
+
wallet_resolved_amount: 0,
|
|
175
|
+
other_count: 0,
|
|
176
|
+
other_amount: 0,
|
|
177
|
+
other_resolved_amount: 0,
|
|
178
|
+
});
|
|
179
|
+
const createEmptyItemVoucher = () => ({
|
|
180
|
+
...(0, exports.createEmptyDiscountSlotCounter)(),
|
|
181
|
+
ref_count: 0,
|
|
182
|
+
offer_count: 0,
|
|
183
|
+
offer_amount: 0,
|
|
184
|
+
offer_resolved_amount: 0,
|
|
185
|
+
});
|
|
186
|
+
/** Empty counter block for one key — every field present and zeroed. */
|
|
187
|
+
const createEmptyDiscountOrderCounters = () => ({
|
|
188
|
+
count: 0,
|
|
189
|
+
amount: 0,
|
|
190
|
+
order_level_amount: 0,
|
|
191
|
+
item_level_amount: 0,
|
|
192
|
+
item_discount_count: 0,
|
|
193
|
+
unattributed_amount: 0,
|
|
194
|
+
order_special: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
195
|
+
order_loyalty: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
196
|
+
order_voucher: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
197
|
+
special_collection: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
198
|
+
special_manual: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
199
|
+
special_price_override: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
200
|
+
special_catalog_item: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
201
|
+
special_other: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
202
|
+
loyalty_offer: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
203
|
+
loyalty_gift_card: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
204
|
+
loyalty_wallet: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
205
|
+
loyalty_other: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
206
|
+
voucher_offer: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
207
|
+
voucher_other: (0, exports.createEmptyDiscountSlotCounter)(),
|
|
208
|
+
item_special: createEmptyItemSpecial(),
|
|
209
|
+
item_loyalty: createEmptyItemLoyalty(),
|
|
210
|
+
item_voucher: createEmptyItemVoucher(),
|
|
211
|
+
free_items: { count: 0, amount: 0, resolved_amount: 0, value: 0 },
|
|
212
|
+
complimentary: { payment_count: 0, amount: 0, note_count: 0 },
|
|
213
|
+
});
|
|
214
|
+
exports.createEmptyDiscountOrderCounters = createEmptyDiscountOrderCounters;
|
|
215
|
+
/** Adds `source` counts/amounts into `target` (used by the key fold + tests). */
|
|
216
|
+
function mergeDiscountSlotCounter(target, source) {
|
|
217
|
+
if (source == null)
|
|
218
|
+
return;
|
|
219
|
+
target.count += source.count ?? 0;
|
|
220
|
+
target.amount += source.amount ?? 0;
|
|
221
|
+
target.resolved_amount += source.resolved_amount ?? 0;
|
|
222
|
+
}
|