@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,201 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { MATERIALIZED_PREP_TIME_REPORT_SCOPES, MATERIALIZED_REPORT_SCOPE_ENUM, PREP_TIME_KEY_FILTERS, } from '../../constants/MATERIALIZED_REPORTS';
|
|
3
|
+
import { accumulateOrderPrepTime, freshMaterializedPrepTimeCounters, } from './materialized-prep-time-classification-helpers';
|
|
4
|
+
import { getDayIndexFromLocalDate, getMaterializedPeriodScopeFields } from './scope-helpers';
|
|
5
|
+
/**
|
|
6
|
+
* Adds `source` into `target`.
|
|
7
|
+
*
|
|
8
|
+
* NOT the generic recursive numeric add the discount compile uses: `duration.min`
|
|
9
|
+
* and `duration.max` (and `late_items.worst_delta`) are AGGREGATES, not counters.
|
|
10
|
+
* Summing them would turn a 5-minute minimum into a 50-minute one across ten
|
|
11
|
+
* days. Everything additive is summed; the extremes fold with min()/max().
|
|
12
|
+
*/
|
|
13
|
+
export function mergeMaterializedPrepTimeCounters(target, source) {
|
|
14
|
+
// ---- coverage (all additive) ----
|
|
15
|
+
target.coverage.item_count += source.coverage.item_count;
|
|
16
|
+
target.coverage.ready_item_count += source.coverage.ready_item_count;
|
|
17
|
+
target.coverage.tracked_count += source.coverage.tracked_count;
|
|
18
|
+
target.coverage.own_anchor_count += source.coverage.own_anchor_count;
|
|
19
|
+
target.coverage.fallback_anchor_count += source.coverage.fallback_anchor_count;
|
|
20
|
+
target.coverage.order_count += source.coverage.order_count;
|
|
21
|
+
// ---- duration ----
|
|
22
|
+
target.duration.count += source.duration.count;
|
|
23
|
+
target.duration.sum += source.duration.sum;
|
|
24
|
+
target.duration.instant_count += source.duration.instant_count;
|
|
25
|
+
for (const [label, count] of Object.entries(source.duration.buckets)) {
|
|
26
|
+
target.duration.buckets[label] = (target.duration.buckets[label] ?? 0) + count;
|
|
27
|
+
}
|
|
28
|
+
// Extremes fold, never sum. A zero minimum means "no measured row yet", so it
|
|
29
|
+
// is replaced rather than kept.
|
|
30
|
+
if (source.duration.count > 0) {
|
|
31
|
+
target.duration.min =
|
|
32
|
+
target.duration.count - source.duration.count <= 0
|
|
33
|
+
? source.duration.min
|
|
34
|
+
: Math.min(target.duration.min, source.duration.min);
|
|
35
|
+
target.duration.max = Math.max(target.duration.max, source.duration.max);
|
|
36
|
+
}
|
|
37
|
+
// ---- promise (all additive; delta_sum is SIGNED) ----
|
|
38
|
+
target.promise.promise_set_count += source.promise.promise_set_count;
|
|
39
|
+
target.promise.default_baseline_count += source.promise.default_baseline_count;
|
|
40
|
+
target.promise.on_time_count += source.promise.on_time_count;
|
|
41
|
+
target.promise.late_count += source.promise.late_count;
|
|
42
|
+
target.promise.delta_sum += source.promise.delta_sum;
|
|
43
|
+
target.promise.no_target_count += source.promise.no_target_count;
|
|
44
|
+
// ---- late items ----
|
|
45
|
+
target.late_items.count += source.late_items.count;
|
|
46
|
+
target.late_items.worst_delta = Math.max(target.late_items.worst_delta, source.late_items.worst_delta);
|
|
47
|
+
}
|
|
48
|
+
const foldWatermark = (bucket, value) => {
|
|
49
|
+
if (value == null)
|
|
50
|
+
return;
|
|
51
|
+
const time = new Date(value).getTime();
|
|
52
|
+
if (Number.isNaN(time))
|
|
53
|
+
return;
|
|
54
|
+
if (bucket.watermark == null || time > bucket.watermark.getTime()) {
|
|
55
|
+
bucket.watermark = new Date(time);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const scopeKey = (doc) => doc.scope_context + '|' + doc.scope_field;
|
|
59
|
+
/** Hour label of one order (`YYYY-MM-DD HH`) from its local fields, or null. */
|
|
60
|
+
const resolveLocalHourLabel = (order, localDate) => {
|
|
61
|
+
const hour = order?.localHour;
|
|
62
|
+
if (typeof hour !== 'number' || !Number.isFinite(hour) || hour < 0 || hour > 23) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return localDate + ' ' + String(hour).padStart(2, '0');
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Compiles one tenant-day into the prep time report + entries documents.
|
|
69
|
+
* Returns `null` on malformed input (bad date / tenant / brand); returns EMPTY
|
|
70
|
+
* arrays when the day has nothing tracked at all.
|
|
71
|
+
*/
|
|
72
|
+
export function compileTenantPrepTimeReports(input) {
|
|
73
|
+
if (input == null)
|
|
74
|
+
return null;
|
|
75
|
+
const { tenantId, brandId, localDate, orders, computedAt } = input;
|
|
76
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
77
|
+
return null;
|
|
78
|
+
if (typeof brandId !== 'string' || brandId.length === 0)
|
|
79
|
+
return null;
|
|
80
|
+
if (typeof localDate !== 'string' || localDate.length === 0)
|
|
81
|
+
return null;
|
|
82
|
+
if (!Array.isArray(orders))
|
|
83
|
+
return null;
|
|
84
|
+
const periodFields = getMaterializedPeriodScopeFields(localDate);
|
|
85
|
+
if (periodFields == null)
|
|
86
|
+
return null;
|
|
87
|
+
const dayIndex = getDayIndexFromLocalDate(localDate);
|
|
88
|
+
const at = computedAt ?? new Date();
|
|
89
|
+
const byScope = new Map();
|
|
90
|
+
const scopeContextOf = new Map();
|
|
91
|
+
const bucketFor = (scope, scopeField, key) => {
|
|
92
|
+
const identity = scope + '|' + scopeField;
|
|
93
|
+
let byKey = byScope.get(identity);
|
|
94
|
+
if (byKey == null) {
|
|
95
|
+
byKey = new Map();
|
|
96
|
+
byScope.set(identity, byKey);
|
|
97
|
+
scopeContextOf.set(identity, scope);
|
|
98
|
+
}
|
|
99
|
+
let bucket = byKey.get(key);
|
|
100
|
+
if (bucket == null) {
|
|
101
|
+
bucket = { counters: freshMaterializedPrepTimeCounters(), rows: [], watermark: null };
|
|
102
|
+
byKey.set(key, bucket);
|
|
103
|
+
}
|
|
104
|
+
return bucket;
|
|
105
|
+
};
|
|
106
|
+
let contributingOrders = 0;
|
|
107
|
+
for (const order of orders) {
|
|
108
|
+
if (order == null)
|
|
109
|
+
continue;
|
|
110
|
+
// Only orders of this tenant compile into this tenant's documents.
|
|
111
|
+
if (order.tenant_id != null && String(order.tenant_id) !== tenantId)
|
|
112
|
+
continue;
|
|
113
|
+
const context = {
|
|
114
|
+
local_date: localDate,
|
|
115
|
+
local_hour_label: resolveLocalHourLabel(order, localDate),
|
|
116
|
+
};
|
|
117
|
+
const result = accumulateOrderPrepTime({
|
|
118
|
+
order,
|
|
119
|
+
context,
|
|
120
|
+
tenantDefaultMinutes: input.tenantDefaultMinutes ?? null,
|
|
121
|
+
});
|
|
122
|
+
// COVERAGE IS THE HEADLINE, so an order that served items but was never
|
|
123
|
+
// observed MUST still contribute its denominator. Skipping it would let the
|
|
124
|
+
// report claim "100% observed" by ignoring everything it failed to observe -
|
|
125
|
+
// exactly the reading this report exists to prevent (one measured store is
|
|
126
|
+
// 2.9% covered).
|
|
127
|
+
if (result.counters.coverage.item_count === 0)
|
|
128
|
+
continue;
|
|
129
|
+
// `contributingOrders` is the narrower documented numerator: orders with at
|
|
130
|
+
// least one TRACKED item.
|
|
131
|
+
if (result.has_tracked)
|
|
132
|
+
contributingOrders += 1;
|
|
133
|
+
const key = String(order.order_status ?? '') + ':' + String(order.platform ?? order.order_from ?? '');
|
|
134
|
+
const watermark = order.updatedAt != null ? new Date(order.updatedAt) : null;
|
|
135
|
+
for (const scope of MATERIALIZED_PREP_TIME_REPORT_SCOPES) {
|
|
136
|
+
const scopeField = periodFields[scope];
|
|
137
|
+
if (scopeField == null)
|
|
138
|
+
continue;
|
|
139
|
+
const bucket = bucketFor(scope, scopeField, key);
|
|
140
|
+
mergeMaterializedPrepTimeCounters(bucket.counters, result.counters);
|
|
141
|
+
bucket.rows.push(...result.entries);
|
|
142
|
+
foldWatermark(bucket, watermark);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const sourceWatermark = new Date(at);
|
|
146
|
+
const reports = [];
|
|
147
|
+
const entries = [];
|
|
148
|
+
for (const [identity, byKey] of byScope) {
|
|
149
|
+
const [scopeContext, scopeField] = identity.split('|');
|
|
150
|
+
const counters = {};
|
|
151
|
+
const counterRows = [];
|
|
152
|
+
const entrySections = {};
|
|
153
|
+
let watermark = null;
|
|
154
|
+
for (const [key, bucket] of byKey) {
|
|
155
|
+
counters[key] = bucket.counters;
|
|
156
|
+
counterRows.push({ key, counters: bucket.counters });
|
|
157
|
+
if (bucket.rows.length > 0)
|
|
158
|
+
entrySections[key] = { rows: bucket.rows };
|
|
159
|
+
if (bucket.watermark != null && (watermark == null || bucket.watermark.getTime() > watermark.getTime())) {
|
|
160
|
+
watermark = bucket.watermark;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const docWatermark = watermark ?? sourceWatermark;
|
|
164
|
+
const isDateScoped = scopeContext === MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
165
|
+
reports.push({
|
|
166
|
+
_id: new mongoose.Types.ObjectId().toHexString(),
|
|
167
|
+
tenant_id: tenantId,
|
|
168
|
+
brand_id: brandId,
|
|
169
|
+
scope_context: scopeContext,
|
|
170
|
+
scope_field: scopeField,
|
|
171
|
+
day_index: isDateScoped ? dayIndex : null,
|
|
172
|
+
sale_type_key_filters: [...PREP_TIME_KEY_FILTERS],
|
|
173
|
+
prep_time_counters: Object.keys(counters).length === 0 ? null : counters,
|
|
174
|
+
// The read-path shape, written from the SAME pass so the two cannot disagree.
|
|
175
|
+
prep_time_counter_rows: counterRows.length === 0 ? null : counterRows,
|
|
176
|
+
schema_version: 1,
|
|
177
|
+
source_watermark: docWatermark,
|
|
178
|
+
computed_at: at,
|
|
179
|
+
createdAt: at,
|
|
180
|
+
updatedAt: at,
|
|
181
|
+
});
|
|
182
|
+
if (Object.keys(entrySections).length > 0) {
|
|
183
|
+
entries.push({
|
|
184
|
+
_id: new mongoose.Types.ObjectId().toHexString(),
|
|
185
|
+
tenant_id: tenantId,
|
|
186
|
+
brand_id: brandId,
|
|
187
|
+
scope_context: scopeContext,
|
|
188
|
+
scope_field: scopeField,
|
|
189
|
+
day_index: isDateScoped ? dayIndex : null,
|
|
190
|
+
sale_type_key_filters: [...PREP_TIME_KEY_FILTERS],
|
|
191
|
+
prep_time_entries: entrySections,
|
|
192
|
+
schema_version: 1,
|
|
193
|
+
source_watermark: docWatermark,
|
|
194
|
+
computed_at: at,
|
|
195
|
+
createdAt: at,
|
|
196
|
+
updatedAt: at,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { reports, entries, contributingOrders };
|
|
201
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_WINDOW_KIND_ENUM, } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
2
|
import { getMaterializedHourWindowScopeFields } from './materialized-reports-read-helpers';
|
|
3
3
|
/**
|
|
4
4
|
* Smart scope-group compiler for materialized-report reads — turns a
|
|
@@ -24,10 +24,13 @@ import { getMaterializedHourWindowScopeFields } from './materialized-reports-rea
|
|
|
24
24
|
* Returns `null` (never throws) for malformed input — `null` means the
|
|
25
25
|
* caller passed invalid data.
|
|
26
26
|
*/
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Window refinement kinds (see the module docblock).
|
|
29
|
+
* @deprecated use MATERIALIZED_REPORT_WINDOW_KIND_ENUM from constants.
|
|
30
|
+
*/
|
|
28
31
|
export const MATERIALIZED_REPORT_WINDOW_KIND = {
|
|
29
|
-
RECURRING:
|
|
30
|
-
SPAN:
|
|
32
|
+
RECURRING: MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
33
|
+
SPAN: MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN,
|
|
31
34
|
};
|
|
32
35
|
/* ------------------------------------------------------------------------ */
|
|
33
36
|
/* Date-key math (UTC — keys are timezone-less) */
|
|
@@ -202,7 +205,7 @@ export function buildMaterializedReportScopeGroups(spec) {
|
|
|
202
205
|
const uniqueDates = dayKeys.map((key) => keyToDate(key));
|
|
203
206
|
// A SPAN window reads the CONTINUOUS interval first-day → last-day — a day
|
|
204
207
|
// set with gaps would silently pull the gap days in as full middle days.
|
|
205
|
-
if (window != null && window.kind ===
|
|
208
|
+
if (window != null && window.kind === MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN) {
|
|
206
209
|
for (let index = 1; index < uniqueDates.length; index += 1) {
|
|
207
210
|
if (daysBetween(uniqueDates[index - 1], uniqueDates[index]) !== 1) {
|
|
208
211
|
return null;
|
|
@@ -217,7 +220,7 @@ export function buildMaterializedReportScopeGroups(spec) {
|
|
|
217
220
|
if (!isValidHour(fromHour, 23) || !isValidHour(toHour, 23))
|
|
218
221
|
return null;
|
|
219
222
|
// Recurring: the same hours on every selected day.
|
|
220
|
-
if (kind ===
|
|
223
|
+
if (kind === MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING) {
|
|
221
224
|
const labels = getMaterializedHourWindowScopeFields(dayKeys, fromHour, toHour);
|
|
222
225
|
return labels == null ? null : [{ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, scope_field: labels }];
|
|
223
226
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ALL_DAY_INDEX } from '../../constants/ENUMS';
|
|
2
|
-
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_WINDOW_KIND_ENUM, } from '../../constants/MATERIALIZED_REPORTS';
|
|
3
3
|
import { CALENDAR_MODE_ENUM, CALENDAR_VIEW_MODE_ENUM } from '../../constants/REPORT_CALENDAR';
|
|
4
|
-
import {
|
|
4
|
+
import { buildMaterializedReportScopeGroups } from './materialized-reports-scope-group-helpers';
|
|
5
5
|
import { getDayIndexFromLocalDate, getMaterializedHourScopeField, getMaterializedPeriodScopeFields, parseMaterializedLocalDate, } from './scope-helpers';
|
|
6
6
|
/**
|
|
7
7
|
* Calendar-selection DECODER for the materialized report READ APIs — the
|
|
@@ -59,6 +59,13 @@ const RANGE_LIKE_VIEWS = new Set([
|
|
|
59
59
|
CALENDAR_VIEW_MODE_ENUM.QUARTER,
|
|
60
60
|
CALENDAR_VIEW_MODE_ENUM.SEMESTER,
|
|
61
61
|
]);
|
|
62
|
+
/**
|
|
63
|
+
* The SPAN-window views, exported for consumers that must mirror a selection's
|
|
64
|
+
* window semantics (the Sales Comparison baseline derivation): a range-like
|
|
65
|
+
* selection's toggle window is a CONTINUOUS span, while a discrete / weekday
|
|
66
|
+
* selection repeats the same hours on each day.
|
|
67
|
+
*/
|
|
68
|
+
export const MATERIALIZED_REPORT_SPAN_VIEW_MODES = SPAN_VIEWS;
|
|
62
69
|
/**
|
|
63
70
|
* Upper bound on the raw day span one selection may cover (~10 years).
|
|
64
71
|
* Bounds every date-walk expansion in the decoder; read services surface an
|
|
@@ -653,8 +660,8 @@ const decodeMaterializedReportScopeGroups = (selection) => {
|
|
|
653
660
|
// never compile it. Weekday + window therefore always compiles
|
|
654
661
|
// RECURRING (the same hours on each matching weekday).
|
|
655
662
|
kind: SPAN_VIEWS.has(view) && weekdayFilter == null
|
|
656
|
-
?
|
|
657
|
-
:
|
|
663
|
+
? MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN
|
|
664
|
+
: MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
658
665
|
},
|
|
659
666
|
}
|
|
660
667
|
: {}),
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { ORDER_STATUS_ENUM } from '../../constants/ENUMS';
|
|
2
|
+
/**
|
|
3
|
+
* Sales Comparison counter accumulation (see
|
|
4
|
+
* `console/admin-panel/docs/report-sales-comparison-concept.md` §6).
|
|
5
|
+
*
|
|
6
|
+
* ## Money mapping — deliberately grounded in the fields live orders carry
|
|
7
|
+
*
|
|
8
|
+
* The live order document has no single "net sales" field, and its fields do
|
|
9
|
+
* not nest the way their names suggest:
|
|
10
|
+
*
|
|
11
|
+
* | counter | source (all CENTS) | why |
|
|
12
|
+
* | --- | --- | --- |
|
|
13
|
+
* | `gross_amount` | `order.price` (fallback Σ item `_gross_amount`, then `subtotal`) | `price` is documented as the total item price WITHOUT discounts |
|
|
14
|
+
* | `discount_amount` | `order.total_discount_applied` → `order_discount_details.total_discount` | the same pair the overview materializer uses; `0` is a real value, so it must not fall through |
|
|
15
|
+
* | `net_amount` | `gross_amount − discount_amount` | standard net sales; equals Σ item `_net_amount` on live data |
|
|
16
|
+
* | `tax_amount` | `order.gst_amount + order.tax_amount` | live stores carry the collected tax in `gst_amount`; `tax_amount` is 0 there. The report has ONE tax counter, so both sum into it |
|
|
17
|
+
* | `service_charge_amount` | `order.service_fee_amount + order.surcharge_amount` | the report has ONE service-charge counter; surcharge is the other service-shaped charge. Both are absent on today's data (0), not guessed |
|
|
18
|
+
* | `tip_amount` | `order.tip_amount` | |
|
|
19
|
+
* | `refund_amount` | Σ `payments[].amount_refunded` | order-level refund money is only represented by its payment rows |
|
|
20
|
+
* | `void_amount` | `order.amount_earned` for a `CANCELLED` order, else 0 | voided order value. Item-level voids live in the SEPARATE `void_order_items` ledger, which a settled-sales report must not fold in without its own drill-down; the `CANCELLED` key is the order-derived void signal |
|
|
21
|
+
* | `item_count` | Σ `categories[].items[].quantity` | items sold, not line count |
|
|
22
|
+
* | `guest_count` | `dinein_details.num_of_guests` | 0 for non-dine-in |
|
|
23
|
+
*
|
|
24
|
+
* **Order count** counts every settled order, including `CANCELLED` — cancelled
|
|
25
|
+
* orders are keyed `CANCELLED:*` and are split out by the formatter, exactly
|
|
26
|
+
* like the overview.
|
|
27
|
+
*
|
|
28
|
+
* Every value is added AS-IS: the source amounts may carry fractional cents and
|
|
29
|
+
* the report must be decimal-exact, so no rounding happens here.
|
|
30
|
+
*/
|
|
31
|
+
/** Coerces a source amount to a finite number (0 when absent/broken). */
|
|
32
|
+
const cents = (value) => {
|
|
33
|
+
const number = typeof value === 'number' ? value : Number(value);
|
|
34
|
+
return Number.isFinite(number) ? number : 0;
|
|
35
|
+
};
|
|
36
|
+
const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
37
|
+
/** A zeroed counter block. */
|
|
38
|
+
export function createEmptySalesComparisonCounters() {
|
|
39
|
+
return {
|
|
40
|
+
order_count: 0,
|
|
41
|
+
gross_amount: 0,
|
|
42
|
+
discount_amount: 0,
|
|
43
|
+
net_amount: 0,
|
|
44
|
+
tax_amount: 0,
|
|
45
|
+
service_charge_amount: 0,
|
|
46
|
+
tip_amount: 0,
|
|
47
|
+
refund_amount: 0,
|
|
48
|
+
void_amount: 0,
|
|
49
|
+
item_count: 0,
|
|
50
|
+
guest_count: 0,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Σ item `_gross_amount` (fallback `subtotal`) — only read when `order.price` is absent. */
|
|
54
|
+
const itemsGrossAmount = (order) => {
|
|
55
|
+
let total = 0;
|
|
56
|
+
for (const category of order?.categories ?? []) {
|
|
57
|
+
for (const item of category?.items ?? []) {
|
|
58
|
+
total += isFiniteNumber(item?._gross_amount) ? item._gross_amount : cents(item?.subtotal);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return total;
|
|
62
|
+
};
|
|
63
|
+
/** Gross sales in CENTS — BEFORE discounts. */
|
|
64
|
+
export function getOrderGrossAmountCents(order) {
|
|
65
|
+
if (order == null)
|
|
66
|
+
return 0;
|
|
67
|
+
if (isFiniteNumber(order.price))
|
|
68
|
+
return order.price;
|
|
69
|
+
return itemsGrossAmount(order);
|
|
70
|
+
}
|
|
71
|
+
/** Discounts applied to the order, in CENTS. */
|
|
72
|
+
export function getOrderDiscountAmountCents(order) {
|
|
73
|
+
if (order == null)
|
|
74
|
+
return 0;
|
|
75
|
+
if (isFiniteNumber(order.total_discount_applied))
|
|
76
|
+
return order.total_discount_applied;
|
|
77
|
+
return cents(order.order_discount_details?.total_discount);
|
|
78
|
+
}
|
|
79
|
+
/** Total tax collected, in CENTS (GST + the unused `tax_amount` bucket). */
|
|
80
|
+
export function getOrderTaxAmountCents(order) {
|
|
81
|
+
if (order == null)
|
|
82
|
+
return 0;
|
|
83
|
+
return cents(order.gst_amount) + cents(order.tax_amount);
|
|
84
|
+
}
|
|
85
|
+
/** Service-shaped charges (service fee + surcharge), in CENTS. */
|
|
86
|
+
export function getOrderServiceChargeAmountCents(order) {
|
|
87
|
+
if (order == null)
|
|
88
|
+
return 0;
|
|
89
|
+
return cents(order.service_fee_amount) + cents(order.surcharge_amount);
|
|
90
|
+
}
|
|
91
|
+
/** Refunded money across the order's payments, in CENTS. */
|
|
92
|
+
export function getOrderRefundAmountCents(order) {
|
|
93
|
+
let total = 0;
|
|
94
|
+
for (const payment of order?.payments ?? []) {
|
|
95
|
+
total += cents(payment?.amount_refunded);
|
|
96
|
+
}
|
|
97
|
+
return total;
|
|
98
|
+
}
|
|
99
|
+
/** Voided (cancelled) order value, in CENTS. */
|
|
100
|
+
export function getOrderVoidAmountCents(order) {
|
|
101
|
+
if (order == null)
|
|
102
|
+
return 0;
|
|
103
|
+
return order.order_status === ORDER_STATUS_ENUM.CANCELLED ? cents(order.amount_earned) : 0;
|
|
104
|
+
}
|
|
105
|
+
/** Items sold (Σ quantity), NOT line count. */
|
|
106
|
+
export function getOrderItemCount(order) {
|
|
107
|
+
let total = 0;
|
|
108
|
+
for (const category of order?.categories ?? []) {
|
|
109
|
+
for (const item of category?.items ?? []) {
|
|
110
|
+
total += cents(item?.quantity);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return total;
|
|
114
|
+
}
|
|
115
|
+
/** Dine-in guest count (0 elsewhere). */
|
|
116
|
+
export function getOrderGuestCount(order) {
|
|
117
|
+
return cents(order?.dinein_details?.num_of_guests);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The tenant-local calendar date of an order's SETTLEMENT instant.
|
|
121
|
+
*
|
|
122
|
+
* The anchor is `order_settled_at` — NEVER `order.localDate`, which is the
|
|
123
|
+
* PUNCH day. A deferred bill punched Monday and collected Wednesday belongs to
|
|
124
|
+
* Wednesday's comparison row (concept §3: no time bias, one fixed anchor).
|
|
125
|
+
*
|
|
126
|
+
* `gmtOffset` is the tenant GST offset in hours (`+5`). The local calendar date
|
|
127
|
+
* of an instant is the UTC date after shifting by that offset.
|
|
128
|
+
*
|
|
129
|
+
* Returns `null` for an order that was never settled (no `order_settled_at` or
|
|
130
|
+
* an unparseable one) — such an order has no settled day and is NOT counted.
|
|
131
|
+
*/
|
|
132
|
+
export function getSalesComparisonSettledLocalDate(order, gmtOffset = 0) {
|
|
133
|
+
const raw = order?.order_settled_at;
|
|
134
|
+
if (raw == null)
|
|
135
|
+
return null;
|
|
136
|
+
const time = new Date(raw).getTime();
|
|
137
|
+
if (Number.isNaN(time))
|
|
138
|
+
return null;
|
|
139
|
+
const offset = Number.isFinite(gmtOffset) ? gmtOffset : 0;
|
|
140
|
+
return new Date(time + offset * 60 * 60 * 1000).toISOString().slice(0, 10);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Adds one order's counters into `target` (mutates `target`).
|
|
144
|
+
*
|
|
145
|
+
* The order's `net_amount` is derived from ITS OWN gross/discount pair so the
|
|
146
|
+
* three counters always satisfy `net = gross − discount` leaf by leaf.
|
|
147
|
+
*/
|
|
148
|
+
export function addOrderToSalesComparisonCounters(target, order) {
|
|
149
|
+
if (target == null || order == null)
|
|
150
|
+
return;
|
|
151
|
+
const gross = getOrderGrossAmountCents(order);
|
|
152
|
+
const discount = getOrderDiscountAmountCents(order);
|
|
153
|
+
target.order_count += 1;
|
|
154
|
+
target.gross_amount += gross;
|
|
155
|
+
target.discount_amount += discount;
|
|
156
|
+
target.net_amount += gross - discount;
|
|
157
|
+
target.tax_amount += getOrderTaxAmountCents(order);
|
|
158
|
+
target.service_charge_amount += getOrderServiceChargeAmountCents(order);
|
|
159
|
+
target.tip_amount += cents(order.tip_amount);
|
|
160
|
+
target.refund_amount += getOrderRefundAmountCents(order);
|
|
161
|
+
target.void_amount += getOrderVoidAmountCents(order);
|
|
162
|
+
target.item_count += getOrderItemCount(order);
|
|
163
|
+
target.guest_count += getOrderGuestCount(order);
|
|
164
|
+
}
|
|
165
|
+
/** Adds every counter of `source` into `target` (mutates `target`). */
|
|
166
|
+
export function addSalesComparisonCounters(target, source) {
|
|
167
|
+
if (target == null || source == null)
|
|
168
|
+
return;
|
|
169
|
+
for (const field of ALL_SALES_COMPARISON_COUNTER_FIELDS) {
|
|
170
|
+
target[field] += cents(source[field]);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Stable list of every additive counter, in display order. Kept in sync with
|
|
175
|
+
* the type module by the schema contract test.
|
|
176
|
+
*/
|
|
177
|
+
export const ALL_SALES_COMPARISON_COUNTER_FIELDS = [
|
|
178
|
+
'order_count',
|
|
179
|
+
'gross_amount',
|
|
180
|
+
'discount_amount',
|
|
181
|
+
'net_amount',
|
|
182
|
+
'tax_amount',
|
|
183
|
+
'service_charge_amount',
|
|
184
|
+
'tip_amount',
|
|
185
|
+
'refund_amount',
|
|
186
|
+
'void_amount',
|
|
187
|
+
'item_count',
|
|
188
|
+
'guest_count',
|
|
189
|
+
];
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ALL_DAY_INDEX } from '../../constants/ENUMS';
|
|
2
|
+
import { MATERIALIZED_REPORT_WINDOW_KIND_ENUM, SALES_COMPARISON_BASELINE_ENUM, } from '../../constants/MATERIALIZED_REPORTS';
|
|
3
|
+
import { buildMaterializedReportScopeGroups, } from './materialized-reports-scope-group-helpers';
|
|
4
|
+
import { MATERIALIZED_REPORT_SPAN_VIEW_MODES, getDayKeysFromCalendarSelection, isValidBusinessHourWindow, } from './materialized-reports-selection-helpers';
|
|
5
|
+
/**
|
|
6
|
+
* Sales Comparison baseline derivation (concept §7).
|
|
7
|
+
*
|
|
8
|
+
* The user picks ONE range (`selection`); the comparison range is DERIVED:
|
|
9
|
+
*
|
|
10
|
+
* - `PREVIOUS_PERIOD` — the EQUAL-LENGTH window immediately preceding the
|
|
11
|
+
* primary range. A 30-day month compares against the preceding 30 days,
|
|
12
|
+
* never against "the previous calendar month" (the classic off-by-one-day
|
|
13
|
+
* bug). Formally: `[min − span, min − 1]` where `span = max − min + 1`.
|
|
14
|
+
* - `PREVIOUS_YEAR` — the primary window shifted back 12 months, SAME length.
|
|
15
|
+
* The start is shifted one calendar year (Feb 29 clamps to Feb 28) and the
|
|
16
|
+
* end is `start + span − 1`, so a leap-year primary still compares against an
|
|
17
|
+
* equally long window.
|
|
18
|
+
*
|
|
19
|
+
* The selection's REFINEMENTS are re-applied to the derived window:
|
|
20
|
+
* - the weekday filter, so "every Monday in September" compares against
|
|
21
|
+
* Mondays inside the preceding equal-length window;
|
|
22
|
+
* - the time-of-day window, with the SAME window kind the primary decode uses
|
|
23
|
+
* (a range-like selection's toggle is a CONTINUOUS SPAN; discrete / weekday
|
|
24
|
+
* selections repeat the same hours each day).
|
|
25
|
+
*
|
|
26
|
+
* This lives in the toolkit because the server derives the pairing and both
|
|
27
|
+
* sides must agree on it — the CLIENT never builds the comparison selection.
|
|
28
|
+
*
|
|
29
|
+
* Returns `null` when the baseline is `NONE` or the selection cannot be
|
|
30
|
+
* decoded, and an EMPTY group list when the derived window legitimately
|
|
31
|
+
* contains no day matching the refinements (a real "zero" comparison, not an
|
|
32
|
+
* error).
|
|
33
|
+
*/
|
|
34
|
+
/** `'YYYY-MM-DD'` → UTC date (timezone-less key math). */
|
|
35
|
+
const keyToUtcDate = (key) => {
|
|
36
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(key);
|
|
37
|
+
if (match == null)
|
|
38
|
+
return null;
|
|
39
|
+
const year = Number(match[1]);
|
|
40
|
+
const month = Number(match[2]);
|
|
41
|
+
const day = Number(match[3]);
|
|
42
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
43
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return date;
|
|
47
|
+
};
|
|
48
|
+
const utcDateToKey = (date) => date.toISOString().slice(0, 10);
|
|
49
|
+
const addUtcDays = (date, amount) => new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + amount));
|
|
50
|
+
/** Shifts a key back one calendar year; Feb 29 clamps to Feb 28. */
|
|
51
|
+
const shiftKeyOneYearBack = (key) => {
|
|
52
|
+
const date = keyToUtcDate(key);
|
|
53
|
+
if (date == null)
|
|
54
|
+
return null;
|
|
55
|
+
const year = date.getUTCFullYear() - 1;
|
|
56
|
+
const month = date.getUTCMonth();
|
|
57
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
|
58
|
+
const day = Math.min(date.getUTCDate(), lastDayOfMonth);
|
|
59
|
+
return utcDateToKey(new Date(Date.UTC(year, month, day)));
|
|
60
|
+
};
|
|
61
|
+
const dayIndexKeyOf = (key) => {
|
|
62
|
+
const date = keyToUtcDate(key);
|
|
63
|
+
return date == null ? null : (ALL_DAY_INDEX[date.getUTCDay()] ?? null);
|
|
64
|
+
};
|
|
65
|
+
/** `'HH:mm'` → whole hour, or null (mirrors the decoder's whole-hour rule). */
|
|
66
|
+
const hourOf = (time) => {
|
|
67
|
+
if (time == null)
|
|
68
|
+
return null;
|
|
69
|
+
const match = /^(\d{2}):00$/.exec(time);
|
|
70
|
+
if (match == null)
|
|
71
|
+
return null;
|
|
72
|
+
const hour = Number(match[1]);
|
|
73
|
+
return hour >= 0 && hour <= 23 ? hour : null;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Derives the comparison window from a decoded selection.
|
|
77
|
+
*
|
|
78
|
+
* Returns `null` for `NONE` / an unservable selection; an entry with an empty
|
|
79
|
+
* `days` array means the window is valid but no day matches the refinement.
|
|
80
|
+
*/
|
|
81
|
+
export function getSalesComparisonBaselineRange(selection, baseline) {
|
|
82
|
+
if (selection == null || typeof selection !== 'object')
|
|
83
|
+
return null;
|
|
84
|
+
if (baseline === SALES_COMPARISON_BASELINE_ENUM.NONE)
|
|
85
|
+
return null;
|
|
86
|
+
if (baseline !== SALES_COMPARISON_BASELINE_ENUM.PREVIOUS_PERIOD &&
|
|
87
|
+
baseline !== SALES_COMPARISON_BASELINE_ENUM.PREVIOUS_YEAR) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// The window's LENGTH comes from the SELECTION's own range, not from the
|
|
91
|
+
// days that survive the weekday refinement: "every Monday in September" is a
|
|
92
|
+
// 30-day selection whose baseline is the preceding 30 days (then the same
|
|
93
|
+
// weekday filter applies), not the 22 days between its first and last Monday.
|
|
94
|
+
const rawSelection = { ...selection, weekdays: [] };
|
|
95
|
+
const primaryDays = getDayKeysFromCalendarSelection(rawSelection);
|
|
96
|
+
if (primaryDays.length === 0)
|
|
97
|
+
return null;
|
|
98
|
+
const sorted = [...primaryDays].sort();
|
|
99
|
+
const firstKey = sorted[0];
|
|
100
|
+
const lastKey = sorted[sorted.length - 1];
|
|
101
|
+
const first = keyToUtcDate(firstKey);
|
|
102
|
+
const last = keyToUtcDate(lastKey);
|
|
103
|
+
if (first == null || last == null)
|
|
104
|
+
return null;
|
|
105
|
+
const span = Math.round((last.getTime() - first.getTime()) / 86400000) + 1;
|
|
106
|
+
if (span < 1)
|
|
107
|
+
return null;
|
|
108
|
+
const startKey = baseline === SALES_COMPARISON_BASELINE_ENUM.PREVIOUS_YEAR
|
|
109
|
+
? shiftKeyOneYearBack(firstKey)
|
|
110
|
+
: utcDateToKey(addUtcDays(first, -span));
|
|
111
|
+
if (startKey == null)
|
|
112
|
+
return null;
|
|
113
|
+
const start = keyToUtcDate(startKey);
|
|
114
|
+
if (start == null)
|
|
115
|
+
return null;
|
|
116
|
+
const endKey = utcDateToKey(addUtcDays(start, span - 1));
|
|
117
|
+
const weekdayFilter = new Set(selection.weekdays ?? []);
|
|
118
|
+
const days = [];
|
|
119
|
+
for (let cursor = start; utcDateToKey(cursor) <= endKey; cursor = addUtcDays(cursor, 1)) {
|
|
120
|
+
const key = utcDateToKey(cursor);
|
|
121
|
+
if (weekdayFilter.size > 0) {
|
|
122
|
+
const weekday = dayIndexKeyOf(key);
|
|
123
|
+
if (weekday == null || !weekdayFilter.has(weekday))
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
days.push(key);
|
|
127
|
+
}
|
|
128
|
+
return { start: startKey, end: endKey, days };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Builds the comparison read's scope groups. Empty array = a valid baseline
|
|
132
|
+
* whose window contains no matching day (the read then folds to zero).
|
|
133
|
+
*/
|
|
134
|
+
export function buildSalesComparisonBaselineScopeGroups(selection, baseline) {
|
|
135
|
+
const range = getSalesComparisonBaselineRange(selection, baseline);
|
|
136
|
+
if (range == null)
|
|
137
|
+
return null;
|
|
138
|
+
if (range.days.length === 0)
|
|
139
|
+
return [];
|
|
140
|
+
const fromHour = hourOf(selection.timeStart);
|
|
141
|
+
const toHour = hourOf(selection.timeEnd);
|
|
142
|
+
const hasWindow = fromHour != null && toHour != null && isValidBusinessHourWindow(fromHour, toHour);
|
|
143
|
+
const spec = { days: range.days };
|
|
144
|
+
if (hasWindow) {
|
|
145
|
+
// Mirror the primary decoder's window kind: a range-like selection's
|
|
146
|
+
// toggle is CONTINUOUS, everything else repeats the same hours per day.
|
|
147
|
+
const weekdayRefined = (selection.weekdays ?? []).length > 0;
|
|
148
|
+
const span = !weekdayRefined && MATERIALIZED_REPORT_SPAN_VIEW_MODES.has(selection.view);
|
|
149
|
+
spec.window = {
|
|
150
|
+
fromHour: fromHour,
|
|
151
|
+
toHour: toHour,
|
|
152
|
+
kind: span ? MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN : MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return buildMaterializedReportScopeGroups(spec);
|
|
156
|
+
}
|