@managesome/eposmatic-toolkit 0.4.9 → 0.4.11
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 +455 -0
- package/esm/constants/enums/delivery.js +8 -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 +248 -0
- package/esm/helpers/materialized-reports/materialized-cash-close-day-helpers.js +396 -0
- package/esm/helpers/materialized-reports/materialized-cash-compile-helpers.js +245 -0
- package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +170 -0
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +430 -0
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +373 -0
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +216 -0
- package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +319 -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 +115 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +89 -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 +477 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +201 -0
- package/esm/helpers/materialized-reports/materialized-reports-scope-group-helpers.js +9 -6
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +11 -4
- package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +189 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +156 -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 +157 -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 +238 -0
- package/esm/helpers/materialized-reports/tenant-payments-comparison-formatter.js +282 -0
- package/esm/helpers/materialized-reports/tenant-prep-time-formatter.js +228 -0
- package/esm/helpers/materialized-reports/tenant-sales-comparison-formatter.js +346 -0
- package/esm/helpers/reporting-contract/index.js +2 -0
- package/esm/helpers/reporting-contract/overview-contract.js +123 -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 +53 -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/helpers/store/common-order-actions.js +3 -2
- package/esm/schemas/models/deliveries.js +82 -1
- package/esm/schemas/models/index.js +15 -0
- package/esm/schemas/models/materialized_credit_bills.js +1 -1
- 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/models/materialized_tenant_sales_overview_reports.js +1 -1
- 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 +345 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +457 -1
- package/lib/constants/enums/delivery.d.ts +7 -0
- package/lib/constants/enums/delivery.js +9 -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 +142 -0
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.js +257 -0
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.d.ts +103 -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 +73 -0
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +252 -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 +113 -0
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +442 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +98 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +386 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +41 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +220 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +52 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +325 -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 +120 -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 +99 -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 +98 -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 +130 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +491 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.d.ts +47 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +208 -0
- package/lib/helpers/materialized-reports/materialized-reports-scope-group-helpers.d.ts +6 -3
- package/lib/helpers/materialized-reports/materialized-reports-scope-group-helpers.js +8 -5
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +8 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +10 -3
- 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 +160 -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 +160 -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 +244 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.d.ts +75 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.js +289 -0
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +98 -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 +352 -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 +127 -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 +51 -0
- package/lib/helpers/rider-earnings/rider-earnings.js +57 -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 +28 -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/store/common-order-actions.js +3 -2
- package/lib/helpers/types/materialized-reports-apis.d.ts +300 -1
- package/lib/schemas/models/deliveries.d.ts +58 -1
- package/lib/schemas/models/deliveries.js +81 -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_credit_bills.d.ts +3 -3
- package/lib/schemas/models/materialized_credit_bills.js +1 -1
- 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/materialized_tenant_sales_overview_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +1 -1
- 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/schemas/types/materialized_tenant_sales_overview_reports.d.ts +7 -0
- package/lib/tests/deliveries-schema.test.d.ts +1 -0
- package/lib/tests/deliveries-schema.test.js +70 -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 +197 -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 +153 -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 +242 -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 +142 -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 +271 -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-reports-scope-group-helpers.test.js +13 -13
- 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 +207 -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,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
8
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
9
|
+
const materialized_tenant_sales_comparison_entries_1 = require("../../schemas/models/materialized_tenant_sales_comparison_entries");
|
|
10
|
+
const materialized_tenant_sales_comparison_reports_1 = require("../../schemas/models/materialized_tenant_sales_comparison_reports");
|
|
11
|
+
const materialized_tenant_sales_comparison_reports_2 = require("../../schemas/types/materialized_tenant_sales_comparison_reports");
|
|
12
|
+
const materialized_sales_comparison_accumulator_helpers_1 = require("../../helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers");
|
|
13
|
+
/**
|
|
14
|
+
* Sales Comparison schema contract.
|
|
15
|
+
*
|
|
16
|
+
* The collection name + the ONE unique identity index are what the read hint
|
|
17
|
+
* and the close-day upserts depend on; the counter shape is what the map/rows
|
|
18
|
+
* agreement depends on.
|
|
19
|
+
*/
|
|
20
|
+
const ReportModel = mongoose_1.default.models[MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_NAME] ??
|
|
21
|
+
mongoose_1.default.model(MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_NAME, materialized_tenant_sales_comparison_reports_1.MaterializedTenantSalesComparisonReportSchema, MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_NAME);
|
|
22
|
+
const EntriesModel = mongoose_1.default.models[MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_NAME] ??
|
|
23
|
+
mongoose_1.default.model(MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_NAME, materialized_tenant_sales_comparison_entries_1.MaterializedTenantSalesComparisonEntriesSchema, MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_NAME);
|
|
24
|
+
const counters = () => (0, materialized_sales_comparison_accumulator_helpers_1.createEmptySalesComparisonCounters)();
|
|
25
|
+
const reportDocument = (over = {}) => ({
|
|
26
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
27
|
+
tenant_id: 'tenant-1',
|
|
28
|
+
brand_id: 'brand-1',
|
|
29
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
30
|
+
scope_field: '2026-09-14',
|
|
31
|
+
day_index: ENUMS_1.DAY_INDEX_ENUM.MON,
|
|
32
|
+
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.SALES_COMPARISON_KEY_FILTERS],
|
|
33
|
+
sales_counters: { 'COMPLETED:POS_DINE-IN': counters() },
|
|
34
|
+
sales_counter_rows: [{ key: 'COMPLETED:POS_DINE-IN', counters: counters() }],
|
|
35
|
+
schema_version: materialized_tenant_sales_comparison_reports_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_SCHEMA_VERSION,
|
|
36
|
+
source_watermark: new Date('2026-09-14T12:00:00.000Z'),
|
|
37
|
+
computed_at: new Date('2026-09-14T23:00:00.000Z'),
|
|
38
|
+
createdAt: new Date('2026-09-14T23:00:00.000Z'),
|
|
39
|
+
updatedAt: new Date('2026-09-14T23:00:00.000Z'),
|
|
40
|
+
...over,
|
|
41
|
+
});
|
|
42
|
+
const entriesDocument = (over = {}) => ({
|
|
43
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
44
|
+
tenant_id: 'tenant-1',
|
|
45
|
+
brand_id: 'brand-1',
|
|
46
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
47
|
+
scope_field: '2026-09-14',
|
|
48
|
+
day_index: ENUMS_1.DAY_INDEX_ENUM.MON,
|
|
49
|
+
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.SALES_COMPARISON_KEY_FILTERS],
|
|
50
|
+
sales_entries: {
|
|
51
|
+
'COMPLETED:POS_DINE-IN': {
|
|
52
|
+
rows: [
|
|
53
|
+
{
|
|
54
|
+
order_id: 'o1',
|
|
55
|
+
order_number: 1,
|
|
56
|
+
time: '2026-09-14T12:00:00.000Z',
|
|
57
|
+
order_status: 'COMPLETED',
|
|
58
|
+
platform: 'POS_DINE-IN',
|
|
59
|
+
net_amount: 1000,
|
|
60
|
+
discount_amount: 100,
|
|
61
|
+
item_count: 2,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
schema_version: materialized_tenant_sales_comparison_entries_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_SCHEMA_VERSION,
|
|
67
|
+
source_watermark: new Date('2026-09-14T12:00:00.000Z'),
|
|
68
|
+
computed_at: new Date('2026-09-14T23:00:00.000Z'),
|
|
69
|
+
createdAt: new Date('2026-09-14T23:00:00.000Z'),
|
|
70
|
+
updatedAt: new Date('2026-09-14T23:00:00.000Z'),
|
|
71
|
+
...over,
|
|
72
|
+
});
|
|
73
|
+
describe('materialized_tenant_sales_comparison_reports schema', () => {
|
|
74
|
+
it('exposes the agreed collection names', () => {
|
|
75
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_NAME).toBe('materialized_tenant_sales_comparison_reports');
|
|
76
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_NAME).toBe('materialized_tenant_sales_comparison_entries');
|
|
77
|
+
});
|
|
78
|
+
it('declares the ONE unique identity/read index on both collections', () => {
|
|
79
|
+
expect(materialized_tenant_sales_comparison_reports_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_INDEXES).toEqual({
|
|
80
|
+
_id: { _id: 1 },
|
|
81
|
+
tenant_id__scope_context__scope_field__day_index: {
|
|
82
|
+
tenant_id: 1,
|
|
83
|
+
scope_context: 1,
|
|
84
|
+
scope_field: 1,
|
|
85
|
+
day_index: 1,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
expect(materialized_tenant_sales_comparison_reports_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_INDEX_OPTIONS).toEqual([
|
|
89
|
+
{
|
|
90
|
+
key: { tenant_id: 1, scope_context: 1, scope_field: 1, day_index: 1 },
|
|
91
|
+
name: 'tenant_id__scope_context__scope_field__day_index',
|
|
92
|
+
unique: true,
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
95
|
+
expect(materialized_tenant_sales_comparison_entries_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_INDEXES).toEqual(materialized_tenant_sales_comparison_reports_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_INDEXES);
|
|
96
|
+
expect(materialized_tenant_sales_comparison_entries_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_INDEX_OPTIONS).toEqual(materialized_tenant_sales_comparison_reports_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_INDEX_OPTIONS);
|
|
97
|
+
});
|
|
98
|
+
it('accepts a valid document (map + read-path rows) and a null day_index on periods', () => {
|
|
99
|
+
const doc = new ReportModel(reportDocument({
|
|
100
|
+
day_index: null,
|
|
101
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
102
|
+
scope_field: '2026-09',
|
|
103
|
+
}));
|
|
104
|
+
expect(doc.validateSync()).toBeUndefined();
|
|
105
|
+
});
|
|
106
|
+
it('has exactly the additive counter list, and no stored ratio', () => {
|
|
107
|
+
expect([...materialized_tenant_sales_comparison_reports_2.ALL_MATERIALIZED_SALES_COMPARISON_COUNTERS].sort()).toEqual(Object.keys((0, materialized_sales_comparison_accumulator_helpers_1.createEmptySalesComparisonCounters)()).sort());
|
|
108
|
+
expect(materialized_tenant_sales_comparison_reports_2.ALL_MATERIALIZED_SALES_COMPARISON_COUNTERS).not.toContain('average_ticket');
|
|
109
|
+
});
|
|
110
|
+
it('rejects an hour scope (this report has none) and an unknown key dimension', () => {
|
|
111
|
+
const hour = new ReportModel(reportDocument({ scope_context: 'localHour' }));
|
|
112
|
+
expect(hour.validateSync()).toBeDefined();
|
|
113
|
+
const badFilter = new ReportModel(reportDocument({ sale_type_key_filters: ['SALE_TYPE'] }));
|
|
114
|
+
expect(badFilter.validateSync()).toBeDefined();
|
|
115
|
+
const emptyFilters = new ReportModel(reportDocument({ sale_type_key_filters: [] }));
|
|
116
|
+
expect(emptyFilters.validateSync()).toBeDefined();
|
|
117
|
+
});
|
|
118
|
+
it('declares the six scopes and no ISO week', () => {
|
|
119
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_SALES_COMPARISON_REPORT_SCOPES).toEqual([
|
|
120
|
+
'localDate',
|
|
121
|
+
'localWeek',
|
|
122
|
+
'localMonth',
|
|
123
|
+
'localQuarter',
|
|
124
|
+
'localSemester',
|
|
125
|
+
'localYear',
|
|
126
|
+
]);
|
|
127
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_SALES_COMPARISON_REPORT_SCOPES).not.toContain('localWeekOfYear');
|
|
128
|
+
expect(MATERIALIZED_REPORTS_1.MATERIALIZED_SALES_COMPARISON_REPORT_SCOPES).not.toContain('localHour');
|
|
129
|
+
});
|
|
130
|
+
it('declares ORDER_STATUS:PLATFORM and no sale-type dimension', () => {
|
|
131
|
+
expect(MATERIALIZED_REPORTS_1.SALES_COMPARISON_KEY_FILTERS).toEqual(['ORDER_STATUS', 'PLATFORM']);
|
|
132
|
+
expect(MATERIALIZED_REPORTS_1.SALES_COMPARISON_KEY_FILTERS.length).toBeLessThanOrEqual(MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_KEY_FILTERS.length);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('materialized_tenant_sales_comparison_entries schema', () => {
|
|
136
|
+
it('accepts an order row document', () => {
|
|
137
|
+
expect(new EntriesModel(entriesDocument()).validateSync()).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
it('requires the entries map (a zero-row document is DELETED, never stored)', () => {
|
|
140
|
+
expect(new EntriesModel(entriesDocument({ sales_entries: null })).validateSync()).toBeDefined();
|
|
141
|
+
});
|
|
142
|
+
});
|
package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js
CHANGED
|
@@ -208,9 +208,16 @@ describe('materialized_tenant_sales_overview_reports schema', () => {
|
|
|
208
208
|
expect(badDayIndex?.errors).toHaveProperty('day_index');
|
|
209
209
|
});
|
|
210
210
|
it('rejects unsupported key-filter dimensions', () => {
|
|
211
|
+
// NOTE: this test previously used 'CITY' as its unsupported example. The delivery
|
|
212
|
+
// report (M4) legitimately ADDED CITY as a real dimension - a key is <PLATFORM>:<CITY>
|
|
213
|
+
// - so the fixture silently stopped testing rejection. The sentinel is now a value
|
|
214
|
+
// that is deliberately not a dimension, and the guard below makes the test fail
|
|
215
|
+
// LOUDLY if that ever changes, instead of quietly passing on a valid value.
|
|
216
|
+
const unsupported = 'NOT_A_DIMENSION';
|
|
217
|
+
expect(MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_KEY_FILTERS).not.toContain(unsupported);
|
|
211
218
|
const badFilters = new Model({
|
|
212
219
|
...validDocument(),
|
|
213
|
-
sale_type_key_filters: ['ORDER_STATUS',
|
|
220
|
+
sale_type_key_filters: ['ORDER_STATUS', unsupported],
|
|
214
221
|
}).validateSync();
|
|
215
222
|
expect(Object.keys(badFilters?.errors ?? {})).toContain('sale_type_key_filters.1');
|
|
216
223
|
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IOrder } from '../../schemas/types/orders';
|
|
2
|
+
/**
|
|
3
|
+
* Pure reference implementation of the LEGACY
|
|
4
|
+
* `/analytics/sales-comparison` aggregation (`items-service`
|
|
5
|
+
* `salesComparisonReport`, SETTLED bias) over raw orders.
|
|
6
|
+
*
|
|
7
|
+
* This is the parity oracle for the Sales Comparison materialization, exactly
|
|
8
|
+
* like `sales-overview-reference.ts` is for the overview. It is deliberately
|
|
9
|
+
* written from the order document directly (no materialization helpers) so a
|
|
10
|
+
* mistake in the compile cannot be mirrored here.
|
|
11
|
+
*
|
|
12
|
+
* The legacy report does NOT have every counter the new report has; the
|
|
13
|
+
* comparison test maps the overlapping leaves and derives the rest from the
|
|
14
|
+
* same raw inputs (documented per field). The legacy `time_bias` is pinned to
|
|
15
|
+
* SETTLED — comparing settled materialization against created live data is the
|
|
16
|
+
* documented false-mismatch trap.
|
|
17
|
+
*/
|
|
18
|
+
export interface ISalesComparisonReferenceTotals {
|
|
19
|
+
/** Non-cancelled orders. */
|
|
20
|
+
total_orders: number;
|
|
21
|
+
total_cancelled_orders: number;
|
|
22
|
+
/** Legacy `price` (pre-discount item total), non-cancelled. */
|
|
23
|
+
price: number;
|
|
24
|
+
/** Legacy `amount_earned`, non-cancelled. */
|
|
25
|
+
amount_earned: number;
|
|
26
|
+
/** Legacy `cancelled_orders_amount`. */
|
|
27
|
+
cancelled_orders_amount: number;
|
|
28
|
+
amount_collected: number;
|
|
29
|
+
service_fee_amount: number;
|
|
30
|
+
total_discount_amount: number;
|
|
31
|
+
order_discount_amount: number;
|
|
32
|
+
tip_amount: number;
|
|
33
|
+
tax_amount: number;
|
|
34
|
+
gst_amount: number;
|
|
35
|
+
surcharge_amount: number;
|
|
36
|
+
num_of_guests: number;
|
|
37
|
+
/** Not in the legacy report — derived from the same orders. */
|
|
38
|
+
items_quantity: number;
|
|
39
|
+
refund_amount: number;
|
|
40
|
+
}
|
|
41
|
+
export declare const emptySalesComparisonReferenceTotals: () => ISalesComparisonReferenceTotals;
|
|
42
|
+
/** Tenant-local calendar date of the SETTLED instant (legacy `dateId`, DAY). */
|
|
43
|
+
export declare function salesComparisonReferenceLocalDate(order: Pick<IOrder, 'order_settled_at'>, gmtOffset: number): string | null;
|
|
44
|
+
/** Adds one order to a legacy-shaped reference accumulator. */
|
|
45
|
+
export declare function addSalesComparisonReferenceOrder(totals: ISalesComparisonReferenceTotals, order: IOrder): void;
|
|
46
|
+
/**
|
|
47
|
+
* Legacy-shaped totals for every order whose SETTLED tenant-local day is in
|
|
48
|
+
* `[fromDay, toDay]` (inclusive, `'YYYY-MM-DD'`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildSalesComparisonReferenceTotals(input: {
|
|
51
|
+
orders: IOrder[];
|
|
52
|
+
gmtOffset: number;
|
|
53
|
+
fromDay: string;
|
|
54
|
+
toDay: string;
|
|
55
|
+
}): ISalesComparisonReferenceTotals;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emptySalesComparisonReferenceTotals = void 0;
|
|
4
|
+
exports.salesComparisonReferenceLocalDate = salesComparisonReferenceLocalDate;
|
|
5
|
+
exports.addSalesComparisonReferenceOrder = addSalesComparisonReferenceOrder;
|
|
6
|
+
exports.buildSalesComparisonReferenceTotals = buildSalesComparisonReferenceTotals;
|
|
7
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
8
|
+
const emptySalesComparisonReferenceTotals = () => ({
|
|
9
|
+
total_orders: 0,
|
|
10
|
+
total_cancelled_orders: 0,
|
|
11
|
+
price: 0,
|
|
12
|
+
amount_earned: 0,
|
|
13
|
+
cancelled_orders_amount: 0,
|
|
14
|
+
amount_collected: 0,
|
|
15
|
+
service_fee_amount: 0,
|
|
16
|
+
total_discount_amount: 0,
|
|
17
|
+
order_discount_amount: 0,
|
|
18
|
+
tip_amount: 0,
|
|
19
|
+
tax_amount: 0,
|
|
20
|
+
gst_amount: 0,
|
|
21
|
+
surcharge_amount: 0,
|
|
22
|
+
num_of_guests: 0,
|
|
23
|
+
items_quantity: 0,
|
|
24
|
+
refund_amount: 0,
|
|
25
|
+
});
|
|
26
|
+
exports.emptySalesComparisonReferenceTotals = emptySalesComparisonReferenceTotals;
|
|
27
|
+
const number = (value) => {
|
|
28
|
+
const parsed = typeof value === 'number' ? value : Number(value);
|
|
29
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
30
|
+
};
|
|
31
|
+
/** Tenant-local calendar date of the SETTLED instant (legacy `dateId`, DAY). */
|
|
32
|
+
function salesComparisonReferenceLocalDate(order, gmtOffset) {
|
|
33
|
+
const raw = order?.order_settled_at;
|
|
34
|
+
if (raw == null)
|
|
35
|
+
return null;
|
|
36
|
+
const time = new Date(raw).getTime();
|
|
37
|
+
if (Number.isNaN(time))
|
|
38
|
+
return null;
|
|
39
|
+
return new Date(time + number(gmtOffset) * 3600000).toISOString().slice(0, 10);
|
|
40
|
+
}
|
|
41
|
+
/** Adds one order to a legacy-shaped reference accumulator. */
|
|
42
|
+
function addSalesComparisonReferenceOrder(totals, order) {
|
|
43
|
+
const cancelled = order.order_status === ENUMS_1.ORDER_STATUS_ENUM.CANCELLED;
|
|
44
|
+
if (cancelled) {
|
|
45
|
+
totals.total_cancelled_orders += 1;
|
|
46
|
+
totals.cancelled_orders_amount += number(order.amount_earned);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
totals.total_orders += 1;
|
|
50
|
+
totals.price += number(order.price);
|
|
51
|
+
totals.amount_earned += number(order.amount_earned);
|
|
52
|
+
totals.amount_collected += number(order.amount_collected);
|
|
53
|
+
totals.service_fee_amount += number(order.service_fee_amount);
|
|
54
|
+
totals.total_discount_amount += number(order.total_discount_applied);
|
|
55
|
+
totals.order_discount_amount += number(order.order_discount_details?.total_discount);
|
|
56
|
+
totals.tip_amount += number(order.tip_amount);
|
|
57
|
+
totals.tax_amount += number(order.tax_amount);
|
|
58
|
+
totals.gst_amount += number(order.gst_amount);
|
|
59
|
+
totals.surcharge_amount += number(order.surcharge_amount);
|
|
60
|
+
totals.num_of_guests += number(order.dinein_details?.num_of_guests);
|
|
61
|
+
for (const category of order.categories ?? []) {
|
|
62
|
+
for (const item of category?.items ?? []) {
|
|
63
|
+
totals.items_quantity += number(item.quantity);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const payment of order.payments ?? []) {
|
|
68
|
+
totals.refund_amount += number(payment.amount_refunded);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Legacy-shaped totals for every order whose SETTLED tenant-local day is in
|
|
73
|
+
* `[fromDay, toDay]` (inclusive, `'YYYY-MM-DD'`).
|
|
74
|
+
*/
|
|
75
|
+
function buildSalesComparisonReferenceTotals(input) {
|
|
76
|
+
const totals = (0, exports.emptySalesComparisonReferenceTotals)();
|
|
77
|
+
for (const order of input.orders ?? []) {
|
|
78
|
+
if (order == null || order.is_deleted === true)
|
|
79
|
+
continue;
|
|
80
|
+
const day = salesComparisonReferenceLocalDate(order, input.gmtOffset);
|
|
81
|
+
if (day == null || day < input.fromDay || day > input.toDay)
|
|
82
|
+
continue;
|
|
83
|
+
addSalesComparisonReferenceOrder(totals, order);
|
|
84
|
+
}
|
|
85
|
+
return totals;
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
4
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
5
|
+
const tenant_discount_formatter_1 = require("../../helpers/materialized-reports/tenant-discount-formatter");
|
|
6
|
+
const materialized_discount_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-discount-compile-helpers");
|
|
7
|
+
const fixtures_1 = require("./fixtures");
|
|
8
|
+
/**
|
|
9
|
+
* Discounts-report FORMATTER audit (M1).
|
|
10
|
+
*
|
|
11
|
+
* Proves the page-shaping contract:
|
|
12
|
+
* - money converts CENTS → decimals and the amount shown is the RESOLVED money
|
|
13
|
+
* (a raw percent can never leak into an amount field);
|
|
14
|
+
* - client-side platform / status filters select keys WITHOUT a refetch;
|
|
15
|
+
* - cancelled keys split into their own facet;
|
|
16
|
+
* - hour series order by business-hour index (06…23, 00…05), never by hour;
|
|
17
|
+
* - duplicated (scope, field) documents are rejected instead of double-counted.
|
|
18
|
+
*/
|
|
19
|
+
const AT = new Date('2026-10-01T00:00:00.000Z');
|
|
20
|
+
const TENANT = 'basha-istanbul-f7';
|
|
21
|
+
const ordersForDay = (localDate) => (0, fixtures_1.loadOrdersDataset)('basha').filter((order) => order.localDate === localDate);
|
|
22
|
+
const compileDay = (localDate) => (0, materialized_discount_compile_helpers_1.compileTenantDiscountReports)({
|
|
23
|
+
tenantId: TENANT,
|
|
24
|
+
brandId: 'brand-basha',
|
|
25
|
+
localDate,
|
|
26
|
+
orders: ordersForDay(localDate),
|
|
27
|
+
gmtOffset: 5,
|
|
28
|
+
computedAt: AT,
|
|
29
|
+
});
|
|
30
|
+
/** A synthetic counters block — precise control for the filter/shape tests. */
|
|
31
|
+
const counters = (overrides = {}) => ({
|
|
32
|
+
count: 0,
|
|
33
|
+
amount: 0,
|
|
34
|
+
order_level_amount: 0,
|
|
35
|
+
item_level_amount: 0,
|
|
36
|
+
item_discount_count: 0,
|
|
37
|
+
unattributed_amount: 0,
|
|
38
|
+
order_special: { count: 0, amount: 0, resolved_amount: 0 },
|
|
39
|
+
order_loyalty: { count: 0, amount: 0, resolved_amount: 0 },
|
|
40
|
+
order_voucher: { count: 0, amount: 0, resolved_amount: 0 },
|
|
41
|
+
special_collection: { count: 0, amount: 0, resolved_amount: 0 },
|
|
42
|
+
special_manual: { count: 0, amount: 0, resolved_amount: 0 },
|
|
43
|
+
special_price_override: { count: 0, amount: 0, resolved_amount: 0 },
|
|
44
|
+
special_catalog_item: { count: 0, amount: 0, resolved_amount: 0 },
|
|
45
|
+
special_other: { count: 0, amount: 0, resolved_amount: 0 },
|
|
46
|
+
loyalty_offer: { count: 0, amount: 0, resolved_amount: 0 },
|
|
47
|
+
loyalty_gift_card: { count: 0, amount: 0, resolved_amount: 0 },
|
|
48
|
+
loyalty_wallet: { count: 0, amount: 0, resolved_amount: 0 },
|
|
49
|
+
loyalty_other: { count: 0, amount: 0, resolved_amount: 0 },
|
|
50
|
+
voucher_offer: { count: 0, amount: 0, resolved_amount: 0 },
|
|
51
|
+
voucher_other: { count: 0, amount: 0, resolved_amount: 0 },
|
|
52
|
+
item_special: {
|
|
53
|
+
count: 0,
|
|
54
|
+
amount: 0,
|
|
55
|
+
resolved_amount: 0,
|
|
56
|
+
collection_count: 0,
|
|
57
|
+
collection_amount: 0,
|
|
58
|
+
collection_resolved_amount: 0,
|
|
59
|
+
manual_count: 0,
|
|
60
|
+
manual_amount: 0,
|
|
61
|
+
manual_resolved_amount: 0,
|
|
62
|
+
price_override_count: 0,
|
|
63
|
+
price_override_amount: 0,
|
|
64
|
+
price_override_resolved_amount: 0,
|
|
65
|
+
catalog_item_count: 0,
|
|
66
|
+
catalog_item_amount: 0,
|
|
67
|
+
catalog_item_resolved_amount: 0,
|
|
68
|
+
other_count: 0,
|
|
69
|
+
other_amount: 0,
|
|
70
|
+
other_resolved_amount: 0,
|
|
71
|
+
},
|
|
72
|
+
item_loyalty: {
|
|
73
|
+
count: 0,
|
|
74
|
+
amount: 0,
|
|
75
|
+
resolved_amount: 0,
|
|
76
|
+
offer_count: 0,
|
|
77
|
+
offer_amount: 0,
|
|
78
|
+
offer_resolved_amount: 0,
|
|
79
|
+
gift_card_count: 0,
|
|
80
|
+
gift_card_amount: 0,
|
|
81
|
+
gift_card_resolved_amount: 0,
|
|
82
|
+
wallet_count: 0,
|
|
83
|
+
wallet_amount: 0,
|
|
84
|
+
wallet_resolved_amount: 0,
|
|
85
|
+
other_count: 0,
|
|
86
|
+
other_amount: 0,
|
|
87
|
+
other_resolved_amount: 0,
|
|
88
|
+
},
|
|
89
|
+
item_voucher: {
|
|
90
|
+
count: 0,
|
|
91
|
+
amount: 0,
|
|
92
|
+
resolved_amount: 0,
|
|
93
|
+
ref_count: 0,
|
|
94
|
+
offer_count: 0,
|
|
95
|
+
offer_amount: 0,
|
|
96
|
+
offer_resolved_amount: 0,
|
|
97
|
+
},
|
|
98
|
+
free_items: { count: 0, amount: 0, resolved_amount: 0, value: 0 },
|
|
99
|
+
complimentary: { payment_count: 0, amount: 0, note_count: 0 },
|
|
100
|
+
...overrides,
|
|
101
|
+
});
|
|
102
|
+
const doc = (scope, field, discount_counters, extra = {}) => ({
|
|
103
|
+
_id: `id-${scope}-${field}`,
|
|
104
|
+
tenant_id: TENANT,
|
|
105
|
+
brand_id: 'brand-basha',
|
|
106
|
+
scope_context: scope,
|
|
107
|
+
scope_field: field,
|
|
108
|
+
day_index: null,
|
|
109
|
+
sale_type_key_filters: [
|
|
110
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS,
|
|
111
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM,
|
|
112
|
+
],
|
|
113
|
+
discount_counters,
|
|
114
|
+
schema_version: 1,
|
|
115
|
+
source_watermark: AT,
|
|
116
|
+
computed_at: AT,
|
|
117
|
+
createdAt: AT,
|
|
118
|
+
updatedAt: AT,
|
|
119
|
+
...extra,
|
|
120
|
+
});
|
|
121
|
+
describe('materialized discounts — formatter', () => {
|
|
122
|
+
it('converts cents to decimals and exposes RESOLVED money, never the raw percent', () => {
|
|
123
|
+
const reports = [
|
|
124
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-13', {
|
|
125
|
+
'COMPLETED:POS_WALK-IN': counters({
|
|
126
|
+
count: 2,
|
|
127
|
+
amount: 8717.5,
|
|
128
|
+
order_level_amount: 8717.5,
|
|
129
|
+
order_special: { count: 1, amount: 25, resolved_amount: 8717.5 },
|
|
130
|
+
special_manual: { count: 1, amount: 25, resolved_amount: 8717.5 },
|
|
131
|
+
}),
|
|
132
|
+
}),
|
|
133
|
+
];
|
|
134
|
+
const result = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports);
|
|
135
|
+
const page = result[0][0];
|
|
136
|
+
// cents → decimals. NB the toolkit's converter is `parseFloat((c/100).toFixed(2))`,
|
|
137
|
+
// so 8717.5 cents is 87.17 (87.175 does not round up in binary float) — asserting
|
|
138
|
+
// the ACTUAL behaviour, not the intuitive rounding.
|
|
139
|
+
expect(page.summary.total_discount).toBe(87.17);
|
|
140
|
+
expect(page.summary.order_level_discount).toBe(87.17);
|
|
141
|
+
// The order-level slot shows the MONEY, not the 25 percent
|
|
142
|
+
const special = page.order_slots.find((slot) => slot.slot === 'SPECIAL');
|
|
143
|
+
expect(special.amount).toBe(87.17);
|
|
144
|
+
expect(special.rate).toBe(25); // the raw rate is exposed as \`rate\`, not as money
|
|
145
|
+
const section = page.sections.find((row) => row.sub_kind === 'MANUAL');
|
|
146
|
+
expect(section.amount).toBe(87.17);
|
|
147
|
+
expect(section.rate).toBe(25);
|
|
148
|
+
expect(section.share_percent).toBe(100);
|
|
149
|
+
});
|
|
150
|
+
it('applies platform and order-status filters to the key map (no refetch)', () => {
|
|
151
|
+
const reports = [
|
|
152
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-13', {
|
|
153
|
+
'COMPLETED:POS_WALK-IN': counters({ count: 1, amount: 1000, order_level_amount: 1000 }),
|
|
154
|
+
'COMPLETED:WEB_DELIVERY': counters({ count: 1, amount: 2000, order_level_amount: 2000 }),
|
|
155
|
+
'CANCELLED:POS_WALK-IN': counters({ count: 1, amount: 4000, order_level_amount: 4000 }),
|
|
156
|
+
}),
|
|
157
|
+
];
|
|
158
|
+
const all = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports)[0][0];
|
|
159
|
+
// cancelled keys are SPLIT OUT, never summed into the summary: 10 + 20 = 30
|
|
160
|
+
expect(all.cancelled).toEqual({ total_discount: 40, discount_count: 1 });
|
|
161
|
+
const platformFiltered = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports, { platforms: ['WEB_DELIVERY'] })[0][0];
|
|
162
|
+
expect(platformFiltered.summary.total_discount).toBe(20);
|
|
163
|
+
expect(platformFiltered.cancelled).toBeNull();
|
|
164
|
+
const statusFiltered = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports, { order_statuses: ['CANCELLED'] })[0][0];
|
|
165
|
+
expect(statusFiltered.summary.total_discount).toBe(0);
|
|
166
|
+
expect(statusFiltered.cancelled).toEqual({ total_discount: 40, discount_count: 1 });
|
|
167
|
+
});
|
|
168
|
+
it('orders the hour series by BUSINESS hour (06…23, 00…05), not by hour', () => {
|
|
169
|
+
const reports = [
|
|
170
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, '2026-09-13 00', { 'COMPLETED:POS_WALK-IN': counters({ count: 1, amount: 100 }) }, { day_index: ENUMS_1.DAY_INDEX_ENUM.SUN }),
|
|
171
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, '2026-09-13 08', { 'COMPLETED:POS_WALK-IN': counters({ count: 1, amount: 200 }) }, { day_index: ENUMS_1.DAY_INDEX_ENUM.SUN }),
|
|
172
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, '2026-09-13 22', { 'COMPLETED:POS_WALK-IN': counters({ count: 1, amount: 300 }) }, { day_index: ENUMS_1.DAY_INDEX_ENUM.SUN }),
|
|
173
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-13', { 'COMPLETED:POS_WALK-IN': counters({ count: 3, amount: 600 }) }, { day_index: ENUMS_1.DAY_INDEX_ENUM.SUN }),
|
|
174
|
+
];
|
|
175
|
+
const page = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports)[0][0];
|
|
176
|
+
expect(page.hourly).not.toBeNull();
|
|
177
|
+
const hours = page.hourly.map((entry) => entry.hour);
|
|
178
|
+
expect(hours).toEqual([8, 22, 0]); // 06…23 then the 00–05 tail
|
|
179
|
+
for (const entry of page.hourly) {
|
|
180
|
+
expect(entry.business_hour_index).toBe((entry.hour + 18) % 24);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
it('groups the weekday view on day_index and honours the weekday filter', () => {
|
|
184
|
+
const reports = [
|
|
185
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-13', { 'COMPLETED:POS_WALK-IN': counters({ count: 1, amount: 1000 }) }, { day_index: ENUMS_1.DAY_INDEX_ENUM.SUN }),
|
|
186
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-14', { 'COMPLETED:POS_WALK-IN': counters({ count: 2, amount: 2000 }) }, { day_index: ENUMS_1.DAY_INDEX_ENUM.MON }),
|
|
187
|
+
];
|
|
188
|
+
const page = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports)[0][0];
|
|
189
|
+
expect(page.weekday).toEqual([
|
|
190
|
+
{ day_index: ENUMS_1.DAY_INDEX_ENUM.SUN, total_discount: 10, discount_count: 1 },
|
|
191
|
+
{ day_index: ENUMS_1.DAY_INDEX_ENUM.MON, total_discount: 20, discount_count: 2 },
|
|
192
|
+
]);
|
|
193
|
+
const filtered = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports, { day_indexes: [ENUMS_1.DAY_INDEX_ENUM.MON] })[0][0];
|
|
194
|
+
expect(filtered.summary.total_discount).toBe(20);
|
|
195
|
+
expect(filtered.weekday).toEqual([{ day_index: ENUMS_1.DAY_INDEX_ENUM.MON, total_discount: 20, discount_count: 2 }]);
|
|
196
|
+
});
|
|
197
|
+
it('rejects duplicated (scope, field) documents instead of double-counting', () => {
|
|
198
|
+
const duplicated = [
|
|
199
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-13', {
|
|
200
|
+
'COMPLETED:POS_WALK-IN': counters({ amount: 1000 }),
|
|
201
|
+
}),
|
|
202
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-13', {
|
|
203
|
+
'COMPLETED:POS_WALK-IN': counters({ amount: 1000 }),
|
|
204
|
+
}),
|
|
205
|
+
];
|
|
206
|
+
expect((0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(duplicated)).toBeNull();
|
|
207
|
+
expect((0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)([
|
|
208
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, '2026-09-13', {}, { schema_version: 1 }),
|
|
209
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK, '2026-09-13', {}, { schema_version: 2 }),
|
|
210
|
+
])).toBeNull();
|
|
211
|
+
expect((0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(null)).toBeNull();
|
|
212
|
+
});
|
|
213
|
+
it('sums a period-only selection and still reports a zero-filled page for no data', () => {
|
|
214
|
+
const reports = [
|
|
215
|
+
doc(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH, '2026-09', {
|
|
216
|
+
'COMPLETED:POS_WALK-IN': counters({
|
|
217
|
+
count: 5,
|
|
218
|
+
amount: 12345,
|
|
219
|
+
item_level_amount: 2345,
|
|
220
|
+
item_discount_count: 2,
|
|
221
|
+
order_special: { count: 5, amount: 100, resolved_amount: 10000 },
|
|
222
|
+
}),
|
|
223
|
+
}),
|
|
224
|
+
];
|
|
225
|
+
const page = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(reports)[0][0];
|
|
226
|
+
expect(page.summary.total_discount).toBe(123.45);
|
|
227
|
+
expect(page.summary.item_level_discount).toBe(23.45);
|
|
228
|
+
expect(page.summary.item_discount_count).toBe(2);
|
|
229
|
+
expect(page.weekday).toBeNull(); // a period document carries no day_index
|
|
230
|
+
expect(page.hourly).toBeNull();
|
|
231
|
+
const empty = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)([])[0][0];
|
|
232
|
+
expect(empty.summary.total_discount).toBe(0);
|
|
233
|
+
expect(empty.sections).toEqual([]);
|
|
234
|
+
expect(empty.tenant_ids).toEqual([]);
|
|
235
|
+
});
|
|
236
|
+
it('formats a real compiled day end-to-end and keeps order+item == total', () => {
|
|
237
|
+
const compiled = compileDay('2026-09-13');
|
|
238
|
+
const page = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(compiled.reports)[0][0];
|
|
239
|
+
expect(page.summary.total_discount).toBeGreaterThan(0);
|
|
240
|
+
// The formatter must preserve the compile's money identity (cents → decimals)
|
|
241
|
+
const centsTotal = Math.round(page.summary.total_discount * 100);
|
|
242
|
+
const centsParts = Math.round((page.summary.order_level_discount + page.summary.item_level_discount + page.summary.unattributed_discount) * 100);
|
|
243
|
+
expect(centsParts).toBe(centsTotal);
|
|
244
|
+
expect(page.tenant_ids).toEqual([TENANT]);
|
|
245
|
+
});
|
|
246
|
+
it('MULTI-TENANT: two tenants sharing a scope field are NOT a duplicate', () => {
|
|
247
|
+
// Regression. The disjointness guard identified a document by
|
|
248
|
+
// `${scope_context}|${scope_field}` WITHOUT the tenant, so two tenants of one brand that
|
|
249
|
+
// both hold a document for the same date looked like a duplicated scope and the formatter
|
|
250
|
+
// returned NULL - blanking the report for the exact multi-tenant read the page makes in
|
|
251
|
+
// brand mode. Reproduced against two real demo tenants before the fix:
|
|
252
|
+
// discounts folded pages 0 (EXPECTED 1) | split pages 0 (EXPECTED 2)
|
|
253
|
+
// A day that ACTUALLY carries discounts - most fixture days carry none, and an empty
|
|
254
|
+
// compile would test the empty-page path instead of the guard.
|
|
255
|
+
const day = [...new Set((0, fixtures_1.loadOrdersDataset)('basha').map((o) => o.localDate))]
|
|
256
|
+
.filter((d) => typeof d === 'string')
|
|
257
|
+
.sort()
|
|
258
|
+
.find((d) => compileDay(d).reports.length > 0);
|
|
259
|
+
expect(day).toBeDefined();
|
|
260
|
+
const compiled = compileDay(day);
|
|
261
|
+
expect(compiled.reports.length).toBeGreaterThan(0);
|
|
262
|
+
// The SAME scope documents, relabelled to a second tenant - which is what brand mode
|
|
263
|
+
// hands the formatter.
|
|
264
|
+
const other = compiled.reports.map((report) => ({ ...report, tenant_id: 'other-tenant' }));
|
|
265
|
+
const both = [...compiled.reports, ...other];
|
|
266
|
+
const folded = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(both, null, false);
|
|
267
|
+
expect(folded).not.toBeNull();
|
|
268
|
+
expect(folded[0]).toHaveLength(1);
|
|
269
|
+
const split = (0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(both, null, true);
|
|
270
|
+
expect(split).not.toBeNull();
|
|
271
|
+
expect(split[0]).toHaveLength(2);
|
|
272
|
+
// one tenant per page, never blended
|
|
273
|
+
for (const page of split[0]) {
|
|
274
|
+
expect(page.tenant_ids).toHaveLength(1);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
it('MULTI-TENANT: a TRUE duplicate within ONE tenant is still rejected', () => {
|
|
278
|
+
// The guard must keep doing its original job: the same scope twice for the SAME tenant
|
|
279
|
+
// would double-count every shared document.
|
|
280
|
+
const day = [...new Set((0, fixtures_1.loadOrdersDataset)('basha').map((o) => o.localDate))]
|
|
281
|
+
.filter((d) => typeof d === 'string')
|
|
282
|
+
.sort()
|
|
283
|
+
.find((d) => compileDay(d).reports.length > 0);
|
|
284
|
+
const compiled = compileDay(day);
|
|
285
|
+
expect(compiled.reports.length).toBeGreaterThan(0);
|
|
286
|
+
const doubled = [...compiled.reports, ...compiled.reports];
|
|
287
|
+
expect((0, tenant_discount_formatter_1.getFormattedTenantDiscountsReporting)(doubled, null, false)).toBeNull();
|
|
288
|
+
});
|
|
289
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|