@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,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MATERIALIZED_CASH_KEY_SEPARATOR = void 0;
|
|
4
|
+
exports.buildMaterializedCashKey = buildMaterializedCashKey;
|
|
5
|
+
exports.parseMaterializedCashKey = parseMaterializedCashKey;
|
|
6
|
+
exports.cashSessionKeyForDrawer = cashSessionKeyForDrawer;
|
|
7
|
+
exports.compileTenantCashReports = compileTenantCashReports;
|
|
8
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
9
|
+
const cash_1 = require("../../constants/enums/cash");
|
|
10
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
11
|
+
const materialized_tenant_cash_entries_1 = require("../../schemas/models/materialized_tenant_cash_entries");
|
|
12
|
+
const materialized_tenant_cash_reports_1 = require("../../schemas/models/materialized_tenant_cash_reports");
|
|
13
|
+
const materialized_cash_classification_helpers_1 = require("./materialized-cash-classification-helpers");
|
|
14
|
+
/**
|
|
15
|
+
* M3 cash - key grammar and the day compile.
|
|
16
|
+
*
|
|
17
|
+
* ## The key, and the ONE place this spec needed a decision
|
|
18
|
+
*
|
|
19
|
+
* The key is `<DRAWER_ID>:<REF_TYPE>` (decision (b3)). But a counter block holds BOTH
|
|
20
|
+
* `movements` and `sessions`, and a SESSION document has no `ref_type` at all - so the
|
|
21
|
+
* concept doc does not say which key a session belongs to. Resolved here as:
|
|
22
|
+
*
|
|
23
|
+
* session counters attach to the `<drawer_id>:DRAWER` key.
|
|
24
|
+
*
|
|
25
|
+
* That is the one key it can belong to without inventing a fake ref type: `DRAWER` is
|
|
26
|
+
* a real ledger ref type, and the rows carrying it ARE the session lifecycle (the
|
|
27
|
+
* opening float, every reopen, the count-out). So "drawer lifecycle movements + the
|
|
28
|
+
* session facts behind them" is exactly what that key means, and no read-side special
|
|
29
|
+
* casing or reserved token is needed. Flagged to the owner as a spec gap filled.
|
|
30
|
+
*
|
|
31
|
+
* ## The day compile
|
|
32
|
+
*
|
|
33
|
+
* Cash is NOT order-derived: the scope comes from the movement rows and the session
|
|
34
|
+
* documents directly. One key produces one counter block, and the block is stored
|
|
35
|
+
* TWICE - as a key-addressed map and as an array of rows - so the read is the
|
|
36
|
+
* canonical unwind/group/direct-sum pattern.
|
|
37
|
+
*/
|
|
38
|
+
/** The separator between the drawer id and the ref type inside a key. */
|
|
39
|
+
exports.MATERIALIZED_CASH_KEY_SEPARATOR = ':';
|
|
40
|
+
/**
|
|
41
|
+
* Builds a key. The separator cannot appear in either component: a drawer id or ref
|
|
42
|
+
* type containing it would make the key unparseable, so such a row is SKIPPED by the
|
|
43
|
+
* caller rather than silently mis-keyed.
|
|
44
|
+
*/
|
|
45
|
+
function buildMaterializedCashKey(drawerId, refType) {
|
|
46
|
+
const drawer = drawerId == null ? '' : String(drawerId).trim();
|
|
47
|
+
const ref = refType == null ? '' : String(refType).trim();
|
|
48
|
+
if (drawer === '' || ref === '')
|
|
49
|
+
return null;
|
|
50
|
+
if (drawer.includes(exports.MATERIALIZED_CASH_KEY_SEPARATOR) || ref.includes(exports.MATERIALIZED_CASH_KEY_SEPARATOR)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return drawer + exports.MATERIALIZED_CASH_KEY_SEPARATOR + ref;
|
|
54
|
+
}
|
|
55
|
+
/** Splits a key back into its parts, or null when it is malformed. */
|
|
56
|
+
function parseMaterializedCashKey(key) {
|
|
57
|
+
if (key == null)
|
|
58
|
+
return null;
|
|
59
|
+
const parts = String(key).split(exports.MATERIALIZED_CASH_KEY_SEPARATOR);
|
|
60
|
+
if (parts.length !== 2)
|
|
61
|
+
return null;
|
|
62
|
+
const [drawerId, refType] = parts;
|
|
63
|
+
if (drawerId === '' || refType === '')
|
|
64
|
+
return null;
|
|
65
|
+
return { drawerId, refType };
|
|
66
|
+
}
|
|
67
|
+
/** The key that carries a drawer session counters. */
|
|
68
|
+
function cashSessionKeyForDrawer(drawerId) {
|
|
69
|
+
return buildMaterializedCashKey(drawerId, cash_1.CASH_IN_OUT_REF_ENUM.DRAWER);
|
|
70
|
+
}
|
|
71
|
+
const watermarkOf = (row, fallback) => {
|
|
72
|
+
const raw = row?.updatedAt ?? row?.createdAt;
|
|
73
|
+
const time = raw == null ? NaN : new Date(raw).getTime();
|
|
74
|
+
return Number.isNaN(time) ? fallback : new Date(time);
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Compiles one business day into the DATE report document plus the DATE entries
|
|
78
|
+
* document. Returns null when the day has NEITHER a movement NOR a session - an
|
|
79
|
+
* empted day writes nothing, and the close-day planner deletes what is left over.
|
|
80
|
+
*/
|
|
81
|
+
function compileTenantCashReports(input) {
|
|
82
|
+
if (input == null)
|
|
83
|
+
return null;
|
|
84
|
+
const { tenantId, brandId, localDate } = input;
|
|
85
|
+
if (typeof tenantId !== 'string' ||
|
|
86
|
+
tenantId === '' ||
|
|
87
|
+
typeof brandId !== 'string' ||
|
|
88
|
+
brandId === '' ||
|
|
89
|
+
typeof localDate !== 'string' ||
|
|
90
|
+
localDate === '') {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const movements = Array.isArray(input.movements) ? input.movements : [];
|
|
94
|
+
const sessions = Array.isArray(input.sessions) ? input.sessions : [];
|
|
95
|
+
const computedAt = input.computedAt ?? new Date();
|
|
96
|
+
// Foreign tenants must never leak into this tenant's documents.
|
|
97
|
+
const ownMovements = movements.filter((row) => String(row?.tenant_id ?? tenantId) === tenantId);
|
|
98
|
+
const ownSessions = sessions.filter((row) => String(row?.tenant_id ?? tenantId) === tenantId);
|
|
99
|
+
if (ownMovements.length === 0 && ownSessions.length === 0)
|
|
100
|
+
return null;
|
|
101
|
+
const accumulators = new Map();
|
|
102
|
+
const entriesByKey = new Map();
|
|
103
|
+
const rowWatermarks = [];
|
|
104
|
+
const accumulatorFor = (key) => {
|
|
105
|
+
const existing = accumulators.get(key);
|
|
106
|
+
if (existing != null)
|
|
107
|
+
return existing;
|
|
108
|
+
const created = (0, materialized_cash_classification_helpers_1.freshCashAccumulator)();
|
|
109
|
+
accumulators.set(key, created);
|
|
110
|
+
return created;
|
|
111
|
+
};
|
|
112
|
+
for (const movement of ownMovements) {
|
|
113
|
+
const key = buildMaterializedCashKey(movement?.drawer_id, movement?.ref_type);
|
|
114
|
+
if (key == null) {
|
|
115
|
+
// An unparseable drawer id or ref type: SKIPPED, never mis-keyed.
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
(0, materialized_cash_classification_helpers_1.addCashMovement)(accumulatorFor(key), movement);
|
|
119
|
+
rowWatermarks.push(watermarkOf(movement, computedAt));
|
|
120
|
+
const drawerId = String(movement.drawer_id);
|
|
121
|
+
const type = String(movement.type) === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_IN
|
|
122
|
+
? cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_IN
|
|
123
|
+
: cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_OUT;
|
|
124
|
+
const amount = Math.abs(Number(movement.amount) || 0);
|
|
125
|
+
const isIn = type === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_IN;
|
|
126
|
+
const created = new Date(movement?.createdAt ?? computedAt);
|
|
127
|
+
const sourceId = String(movement?.cash_in_out_id ?? movement?._id ?? '');
|
|
128
|
+
const entry = {
|
|
129
|
+
cash_in_out_id: sourceId,
|
|
130
|
+
entry_key: localDate + '|' + sourceId,
|
|
131
|
+
drawer_id: drawerId,
|
|
132
|
+
drawer_name: input.drawerNames?.[drawerId] ?? null,
|
|
133
|
+
day_id: String(movement?.day_id ?? ''),
|
|
134
|
+
shift_id: movement?.shift_id == null ? null : String(movement.shift_id),
|
|
135
|
+
shift_number: movement?.shift_number == null ? null : Number(movement.shift_number) || 0,
|
|
136
|
+
type,
|
|
137
|
+
ref_type: String(movement?.ref_type ?? cash_1.CASH_IN_OUT_REF_ENUM.NONE),
|
|
138
|
+
ref_id: movement?.ref_id == null ? null : String(movement.ref_id),
|
|
139
|
+
amount,
|
|
140
|
+
signed_amount: isIn ? amount : -amount,
|
|
141
|
+
drawer_balance_before: Number(movement?.drawer_balance_before) || 0,
|
|
142
|
+
drawer_balance_after: Number(movement?.drawer_balance_after) || 0,
|
|
143
|
+
staff_id: movement?.staff_id == null ? null : String(movement.staff_id),
|
|
144
|
+
staff_name: movement?.staff_name == null ? null : String(movement.staff_name),
|
|
145
|
+
note: movement?.note == null ? null : String(movement.note),
|
|
146
|
+
...classifyForEntry(movement),
|
|
147
|
+
created_at: created,
|
|
148
|
+
local_hour: localHourOf(movement),
|
|
149
|
+
};
|
|
150
|
+
const bucket = entriesByKey.get(key);
|
|
151
|
+
if (bucket == null)
|
|
152
|
+
entriesByKey.set(key, [entry]);
|
|
153
|
+
else
|
|
154
|
+
bucket.push(entry);
|
|
155
|
+
}
|
|
156
|
+
for (const session of ownSessions) {
|
|
157
|
+
const key = cashSessionKeyForDrawer(session?.drawer_id);
|
|
158
|
+
if (key == null) {
|
|
159
|
+
// Same posture as the movements: a row we cannot key is skipped.
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
(0, materialized_cash_classification_helpers_1.addCashSession)(accumulatorFor(key), session);
|
|
163
|
+
rowWatermarks.push(watermarkOf(session, computedAt));
|
|
164
|
+
}
|
|
165
|
+
if (accumulators.size === 0)
|
|
166
|
+
return null;
|
|
167
|
+
const cashCounters = {};
|
|
168
|
+
const cashCounterRows = [];
|
|
169
|
+
for (const key of [...accumulators.keys()].sort()) {
|
|
170
|
+
const counters = (0, materialized_cash_classification_helpers_1.finalizeCashAccumulator)(accumulators.get(key));
|
|
171
|
+
cashCounters[key] = counters;
|
|
172
|
+
cashCounterRows.push({ key, counters });
|
|
173
|
+
}
|
|
174
|
+
// Rows are sorted newest-first WITHIN each key. Merging the keys into one global
|
|
175
|
+
// newest-first statement is the READER's job: the page cursor is
|
|
176
|
+
// {time, cash_in_out_id}, which implies a global order across the keys in scope.
|
|
177
|
+
const cashEntries = {};
|
|
178
|
+
for (const key of [...entriesByKey.keys()].sort()) {
|
|
179
|
+
const rows = entriesByKey.get(key);
|
|
180
|
+
rows.sort((a, b) => b.created_at.getTime() - a.created_at.getTime() || (a.cash_in_out_id < b.cash_in_out_id ? 1 : -1));
|
|
181
|
+
cashEntries[key] = { rows };
|
|
182
|
+
}
|
|
183
|
+
const watermark = rowWatermarks.reduce((latest, current) => (current.getTime() > latest.getTime() ? current : latest), computedAt);
|
|
184
|
+
const reports = [
|
|
185
|
+
{
|
|
186
|
+
_id: undefined,
|
|
187
|
+
tenant_id: tenantId,
|
|
188
|
+
brand_id: brandId,
|
|
189
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
190
|
+
scope_field: localDate,
|
|
191
|
+
day_index: dayIndexOf(localDate),
|
|
192
|
+
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.CASH_KEY_FILTERS],
|
|
193
|
+
cash_counters: cashCounters,
|
|
194
|
+
cash_counter_rows: cashCounterRows,
|
|
195
|
+
schema_version: materialized_tenant_cash_reports_1.MATERIALIZED_TENANT_CASH_REPORTS_SCHEMA_VERSION,
|
|
196
|
+
source_watermark: watermark,
|
|
197
|
+
computed_at: computedAt,
|
|
198
|
+
createdAt: computedAt,
|
|
199
|
+
updatedAt: computedAt,
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
const entries = [
|
|
203
|
+
{
|
|
204
|
+
_id: undefined,
|
|
205
|
+
tenant_id: tenantId,
|
|
206
|
+
brand_id: brandId,
|
|
207
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
208
|
+
scope_field: localDate,
|
|
209
|
+
day_index: dayIndexOf(localDate),
|
|
210
|
+
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.CASH_KEY_FILTERS],
|
|
211
|
+
cash_entries: Object.keys(cashEntries).length === 0 ? null : cashEntries,
|
|
212
|
+
schema_version: materialized_tenant_cash_entries_1.MATERIALIZED_TENANT_CASH_ENTRIES_SCHEMA_VERSION,
|
|
213
|
+
source_watermark: watermark,
|
|
214
|
+
computed_at: computedAt,
|
|
215
|
+
createdAt: computedAt,
|
|
216
|
+
updatedAt: computedAt,
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
return { reports, entries };
|
|
220
|
+
}
|
|
221
|
+
/** The four lifecycle flags, computed ONCE here so the read never re-derives them. */
|
|
222
|
+
function classifyForEntry(row) {
|
|
223
|
+
const p = (0, materialized_cash_classification_helpers_1.classifyCashMovement)(row);
|
|
224
|
+
return {
|
|
225
|
+
is_reopen: p.is_reopen,
|
|
226
|
+
is_opening_float: p.is_opening_float,
|
|
227
|
+
is_count_out: p.is_count_out,
|
|
228
|
+
is_system_adjustment: p.is_system_adjustment,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** `YYYY-MM-DD HH` from the local time fields, or null. */
|
|
232
|
+
function localHourOf(row) {
|
|
233
|
+
const explicit = row?.localHour;
|
|
234
|
+
if (typeof explicit === 'number' && Number.isFinite(explicit)) {
|
|
235
|
+
const day = String(row?.localDate ?? '');
|
|
236
|
+
return day === '' ? null : day + ' ' + String(explicit).padStart(2, '0');
|
|
237
|
+
}
|
|
238
|
+
const raw = row?.createdAt;
|
|
239
|
+
if (raw == null)
|
|
240
|
+
return null;
|
|
241
|
+
const date = new Date(raw);
|
|
242
|
+
if (Number.isNaN(date.getTime()))
|
|
243
|
+
return null;
|
|
244
|
+
return date.toISOString().slice(0, 13).replace('T', ' ');
|
|
245
|
+
}
|
|
246
|
+
/** Weekday denormalization for a date document. */
|
|
247
|
+
function dayIndexOf(localDate) {
|
|
248
|
+
const date = new Date(localDate + 'T00:00:00.000Z');
|
|
249
|
+
if (Number.isNaN(date.getTime()))
|
|
250
|
+
return null;
|
|
251
|
+
return ENUMS_1.ALL_DAY_INDEX[date.getUTCDay()] ?? null;
|
|
252
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IMaterializedDeliveryCounters } from '../../schemas/types/materialized_tenant_delivery_reports';
|
|
2
|
+
/**
|
|
3
|
+
* Merges `source` into `target`, IN PLACE. Null-safe: a source block missing a sub-object
|
|
4
|
+
* is treated as zeroes rather than throwing, so one malformed historical document cannot
|
|
5
|
+
* break a whole period fold.
|
|
6
|
+
*/
|
|
7
|
+
export declare function mergeMaterializedDeliveryCounters(target: IMaterializedDeliveryCounters, source: IMaterializedDeliveryCounters): IMaterializedDeliveryCounters;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeMaterializedDeliveryCounters = mergeMaterializedDeliveryCounters;
|
|
4
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
5
|
+
/**
|
|
6
|
+
* M4 delivery - folding counters across days into a PERIOD document.
|
|
7
|
+
*
|
|
8
|
+
* ## What is additive, and what is NOT
|
|
9
|
+
*
|
|
10
|
+
* Additive: every count, every money total, every distance total, every timing sum, and
|
|
11
|
+
* the whole ADOPTION block. Adoption folds safely because each order belongs to exactly
|
|
12
|
+
* one day, so summing `delivery_order_count` / `delivered_via_app_count` / `off_app_count`
|
|
13
|
+
* across days preserves the set relationship - there is no double counting to worry about,
|
|
14
|
+
* which is why this report does NOT need to carry id sets through the fold the way the
|
|
15
|
+
* cash report carries a staff roster.
|
|
16
|
+
*
|
|
17
|
+
* NOT additive, and this is the trap: the rider leaderboard's `first_delivery_at` and
|
|
18
|
+
* `last_delivery_at`. A rider who worked two days must keep the EARLIEST first and the
|
|
19
|
+
* LATEST last, so the fold takes a MINIMUM and a MAXIMUM rather than a sum. Summing them
|
|
20
|
+
* (or taking the last one seen) silently reports a rider's tenure as starting after it
|
|
21
|
+
* did - the same class of error as summing a minimum in the prep time report.
|
|
22
|
+
*
|
|
23
|
+
* The distance HISTOGRAM folds by sum, bucket by bucket, because each delivery lands in
|
|
24
|
+
* exactly one bucket per document.
|
|
25
|
+
*/
|
|
26
|
+
const num = (value) => Number(value) || 0;
|
|
27
|
+
const earlierOf = (current, candidate) => {
|
|
28
|
+
const time = candidate == null ? NaN : new Date(candidate).getTime();
|
|
29
|
+
if (Number.isNaN(time))
|
|
30
|
+
return current;
|
|
31
|
+
if (current == null || time < new Date(current).getTime())
|
|
32
|
+
return new Date(time);
|
|
33
|
+
return current;
|
|
34
|
+
};
|
|
35
|
+
const laterOf = (current, candidate) => {
|
|
36
|
+
const time = candidate == null ? NaN : new Date(candidate).getTime();
|
|
37
|
+
if (Number.isNaN(time))
|
|
38
|
+
return current;
|
|
39
|
+
if (current == null || time > new Date(current).getTime())
|
|
40
|
+
return new Date(time);
|
|
41
|
+
return current;
|
|
42
|
+
};
|
|
43
|
+
/** Merges one rider row into another, MIN/MAX on the tenure bounds. */
|
|
44
|
+
function mergeRiderRow(target, source) {
|
|
45
|
+
target.count += num(source?.count);
|
|
46
|
+
target.completed_count += num(source?.completed_count);
|
|
47
|
+
target.cancelled_count += num(source?.cancelled_count);
|
|
48
|
+
target.in_progress_count += num(source?.in_progress_count);
|
|
49
|
+
target.rider_revenue_amount += num(source?.rider_revenue_amount);
|
|
50
|
+
target.distance_sum_meters += num(source?.distance_sum_meters);
|
|
51
|
+
target.rider_name ?? (target.rider_name = source?.rider_name ?? null);
|
|
52
|
+
// MIN / MAX - never a sum, and never just the newest document value.
|
|
53
|
+
target.first_delivery_at = earlierOf(target.first_delivery_at, source?.first_delivery_at);
|
|
54
|
+
target.last_delivery_at = laterOf(target.last_delivery_at, source?.last_delivery_at);
|
|
55
|
+
}
|
|
56
|
+
/** Merges one area row into another, summing the hour heat map. */
|
|
57
|
+
function mergeAreaRow(target, source) {
|
|
58
|
+
target.count += num(source?.count);
|
|
59
|
+
target.completed_count += num(source?.completed_count);
|
|
60
|
+
target.cancelled_count += num(source?.cancelled_count);
|
|
61
|
+
target.rider_revenue_amount += num(source?.rider_revenue_amount);
|
|
62
|
+
target.distance_sum_meters += num(source?.distance_sum_meters);
|
|
63
|
+
target.by_hour ?? (target.by_hour = {});
|
|
64
|
+
for (const [hour, value] of Object.entries(source?.by_hour ?? {})) {
|
|
65
|
+
target.by_hour[hour] = num(target.by_hour[hour]) + num(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Merges `source` into `target`, IN PLACE. Null-safe: a source block missing a sub-object
|
|
70
|
+
* is treated as zeroes rather than throwing, so one malformed historical document cannot
|
|
71
|
+
* break a whole period fold.
|
|
72
|
+
*/
|
|
73
|
+
function mergeMaterializedDeliveryCounters(target, source) {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
if (target == null || source == null)
|
|
76
|
+
return target;
|
|
77
|
+
const ta = target.adoption;
|
|
78
|
+
const sa = source.adoption;
|
|
79
|
+
if (ta != null && sa != null) {
|
|
80
|
+
ta.delivery_order_count += num(sa.delivery_order_count);
|
|
81
|
+
ta.delivered_via_app_count += num(sa.delivered_via_app_count);
|
|
82
|
+
ta.off_app_count += num(sa.off_app_count);
|
|
83
|
+
ta.tracking_enabled_count += num(sa.tracking_enabled_count);
|
|
84
|
+
ta.proof_pickup_count += num(sa.proof_pickup_count);
|
|
85
|
+
ta.proof_dropoff_count += num(sa.proof_dropoff_count);
|
|
86
|
+
}
|
|
87
|
+
const td = target.deliveries;
|
|
88
|
+
const sd = source.deliveries;
|
|
89
|
+
if (td != null && sd != null) {
|
|
90
|
+
td.count += num(sd.count);
|
|
91
|
+
td.pending_count += num(sd.pending_count);
|
|
92
|
+
td.assigned_count += num(sd.assigned_count);
|
|
93
|
+
td.in_progress_count += num(sd.in_progress_count);
|
|
94
|
+
td.completed_count += num(sd.completed_count);
|
|
95
|
+
td.cancelled_count += num(sd.cancelled_count);
|
|
96
|
+
td.cancel_reason_count += num(sd.cancel_reason_count);
|
|
97
|
+
}
|
|
98
|
+
const tm = target.money;
|
|
99
|
+
const sm = source.money;
|
|
100
|
+
if (tm != null && sm != null) {
|
|
101
|
+
tm.rider_revenue_amount += num(sm.rider_revenue_amount);
|
|
102
|
+
tm.rider_revenue_count += num(sm.rider_revenue_count);
|
|
103
|
+
tm.net_sale_amount += num(sm.net_sale_amount);
|
|
104
|
+
tm.collected_amount += num(sm.collected_amount);
|
|
105
|
+
tm.delivery_charge_amount += num(sm.delivery_charge_amount);
|
|
106
|
+
tm.delivery_charge_count += num(sm.delivery_charge_count);
|
|
107
|
+
tm.tip_amount += num(sm.tip_amount);
|
|
108
|
+
tm.discount_amount += num(sm.discount_amount);
|
|
109
|
+
tm.refund_amount += num(sm.refund_amount);
|
|
110
|
+
tm.tax_amount += num(sm.tax_amount);
|
|
111
|
+
}
|
|
112
|
+
if (target.distance != null && source.distance != null) {
|
|
113
|
+
const tDist = target.distance;
|
|
114
|
+
const sDist = source.distance;
|
|
115
|
+
tDist.sum_meters = num(tDist.sum_meters) + num(sDist.sum_meters);
|
|
116
|
+
tDist.count = num(tDist.count) + num(sDist.count);
|
|
117
|
+
for (const bucket of MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_DISTANCE_BUCKETS) {
|
|
118
|
+
tDist[bucket.key] = num(tDist[bucket.key]) + num(sDist[bucket.key]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (target.timing != null && source.timing != null) {
|
|
122
|
+
const tt = target.timing;
|
|
123
|
+
const st = source.timing;
|
|
124
|
+
tt.graded_count += num(st.graded_count);
|
|
125
|
+
tt.dispatch_lag_sum_minutes += num(st.dispatch_lag_sum_minutes);
|
|
126
|
+
tt.complete_sum_minutes += num(st.complete_sum_minutes);
|
|
127
|
+
tt.total_sum_minutes += num(st.total_sum_minutes);
|
|
128
|
+
tt.exact_completion_count += num(st.exact_completion_count);
|
|
129
|
+
tt.assignment_sum_minutes += num(st.assignment_sum_minutes);
|
|
130
|
+
tt.assignment_count += num(st.assignment_count);
|
|
131
|
+
tt.pickup_wait_sum_minutes += num(st.pickup_wait_sum_minutes);
|
|
132
|
+
tt.pickup_wait_count += num(st.pickup_wait_count);
|
|
133
|
+
tt.transit_sum_minutes += num(st.transit_sum_minutes);
|
|
134
|
+
tt.transit_count += num(st.transit_count);
|
|
135
|
+
tt.cancel_sum_minutes += num(st.cancel_sum_minutes);
|
|
136
|
+
tt.cancel_count += num(st.cancel_count);
|
|
137
|
+
tt.cancelled_after_pickup_count += num(st.cancelled_after_pickup_count);
|
|
138
|
+
tt.status_updates_sum += num(st.status_updates_sum);
|
|
139
|
+
tt.status_updates_count += num(st.status_updates_count);
|
|
140
|
+
tt.promise_known_count += num(st.promise_known_count);
|
|
141
|
+
tt.on_time_count += num(st.on_time_count);
|
|
142
|
+
tt.late_count += num(st.late_count);
|
|
143
|
+
tt.late_minutes_sum += num(st.late_minutes_sum);
|
|
144
|
+
}
|
|
145
|
+
for (const [riderId, row] of Object.entries(source.riders ?? {})) {
|
|
146
|
+
target.riders ?? (target.riders = {});
|
|
147
|
+
(_a = target.riders)[riderId] ?? (_a[riderId] = {
|
|
148
|
+
rider_name: null,
|
|
149
|
+
count: 0,
|
|
150
|
+
completed_count: 0,
|
|
151
|
+
cancelled_count: 0,
|
|
152
|
+
in_progress_count: 0,
|
|
153
|
+
rider_revenue_amount: 0,
|
|
154
|
+
distance_sum_meters: 0,
|
|
155
|
+
first_delivery_at: null,
|
|
156
|
+
last_delivery_at: null,
|
|
157
|
+
});
|
|
158
|
+
mergeRiderRow(target.riders[riderId], row);
|
|
159
|
+
}
|
|
160
|
+
for (const [city, row] of Object.entries(source.areas ?? {})) {
|
|
161
|
+
target.areas ?? (target.areas = {});
|
|
162
|
+
(_b = target.areas)[city] ?? (_b[city] = {
|
|
163
|
+
count: 0,
|
|
164
|
+
completed_count: 0,
|
|
165
|
+
cancelled_count: 0,
|
|
166
|
+
rider_revenue_amount: 0,
|
|
167
|
+
distance_sum_meters: 0,
|
|
168
|
+
by_hour: {},
|
|
169
|
+
});
|
|
170
|
+
mergeAreaRow(target.areas[city], row);
|
|
171
|
+
}
|
|
172
|
+
return target;
|
|
173
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { DELIVERY_STATUS_ENUM } from '../../constants/enums/delivery';
|
|
2
|
+
import { IDelivery } from '../../schemas/types/deliveries';
|
|
3
|
+
import { IOrderDeliveryDetails } from '../../schemas/types/orders';
|
|
4
|
+
import { IMaterializedDeliveryCounters } from '../../schemas/types/materialized_tenant_delivery_reports';
|
|
5
|
+
/**
|
|
6
|
+
* M4 delivery - key grammar, the order join, and the accumulators.
|
|
7
|
+
*
|
|
8
|
+
* ## Adoption is the headline, and it needs BOTH populations
|
|
9
|
+
*
|
|
10
|
+
* The `deliveries` collection is written ONLY by the rider app, so for a tenant that does
|
|
11
|
+
* not use it the collection is EMPTY. An empty collection renders as "no deliveries"
|
|
12
|
+
* rather than "no visibility" - which is why the counters always carry
|
|
13
|
+
* `delivery_order_count` (from the ORDERS stage) beside `delivered_via_app_count` (from the
|
|
14
|
+
* DELIVERIES stage). Neither stage alone can compute `off_app_count`.
|
|
15
|
+
*
|
|
16
|
+
* `off_app_count` is NOT an error state: it is the pool the rider app can win.
|
|
17
|
+
*
|
|
18
|
+
* ## The join
|
|
19
|
+
*
|
|
20
|
+
* A delivery document carries neither the platform nor the city, so the key
|
|
21
|
+
* `<PLATFORM>:<CITY>` and every order-derived money figure come from joining by
|
|
22
|
+
* `order_id`. An order with no platform/city details falls into an explicit UNKNOWN
|
|
23
|
+
* bucket rather than being dropped silently - a missing dimension must still show up in
|
|
24
|
+
* the totals.
|
|
25
|
+
*
|
|
26
|
+
* ## One order, N attempts
|
|
27
|
+
*
|
|
28
|
+
* The unique `order_id + rider_id` index allows a re-assignment to create a SECOND
|
|
29
|
+
* delivery for the same order. `deliveries.count` therefore counts ATTEMPTS while
|
|
30
|
+
* `delivery_order_count` counts ORDERS, and the two are deliberately not expected to
|
|
31
|
+
* match. `off_app_count` is computed from a SET difference so a reassigned order is never
|
|
32
|
+
* counted as off-app.
|
|
33
|
+
*/
|
|
34
|
+
/** The key token used when a dimension is missing, so nothing is silently dropped. */
|
|
35
|
+
export declare const DELIVERY_UNKNOWN_TOKEN = "UNKNOWN";
|
|
36
|
+
export declare const MATERIALIZED_DELIVERY_KEY_SEPARATOR = ":";
|
|
37
|
+
/** Builds `<PLATFORM>:<CITY>`, substituting UNKNOWN for missing dimensions. */
|
|
38
|
+
export declare function buildMaterializedDeliveryKey(platform: unknown, city: unknown): string;
|
|
39
|
+
/** Splits a key back into its parts, or null when it is malformed. */
|
|
40
|
+
export declare function parseMaterializedDeliveryKey(key: unknown): {
|
|
41
|
+
platform: string;
|
|
42
|
+
city: string;
|
|
43
|
+
} | null;
|
|
44
|
+
/** A zeroed counter block. */
|
|
45
|
+
export declare function freshDeliveryCounters(): IMaterializedDeliveryCounters;
|
|
46
|
+
/** Which fixed distance bucket a metre value falls in. */
|
|
47
|
+
export declare function deliveryDistanceBucketKey(meters: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* A per-key accumulation buffer.
|
|
50
|
+
*
|
|
51
|
+
* The two ID SETS are what make adoption order-independent: `off_app_count` is the set
|
|
52
|
+
* difference between the orders that had a delivery and those that did not, so it does
|
|
53
|
+
* not matter whether the orders stage or the deliveries stage runs first.
|
|
54
|
+
*/
|
|
55
|
+
/** Raw order fields this classifier reads (source documents are often partial). */
|
|
56
|
+
export interface IDeliveryOrderSource {
|
|
57
|
+
_id: string;
|
|
58
|
+
tenant_id?: string | null;
|
|
59
|
+
updatedAt?: Date | string | null;
|
|
60
|
+
order_number?: number | null;
|
|
61
|
+
platform?: string | null;
|
|
62
|
+
createdAt?: Date | string | null;
|
|
63
|
+
net_sale_amount?: number | null;
|
|
64
|
+
amount_earned?: number | null;
|
|
65
|
+
amount_collected?: number | null;
|
|
66
|
+
amount_refunded?: number | null;
|
|
67
|
+
total_discount_applied?: number | null;
|
|
68
|
+
tip_amount?: number | null;
|
|
69
|
+
gst_amount?: number | null;
|
|
70
|
+
tax_amount?: number | null;
|
|
71
|
+
delivery_details?: (Partial<IOrderDeliveryDetails> & {
|
|
72
|
+
delivery_charge?: number | null;
|
|
73
|
+
delivery_charge_amount?: number | null;
|
|
74
|
+
}) | null;
|
|
75
|
+
}
|
|
76
|
+
/** Raw delivery fields this classifier reads (all optional at the boundary). */
|
|
77
|
+
export type TDeliverySource = Partial<Omit<IDelivery, 'status'>> & {
|
|
78
|
+
status?: DELIVERY_STATUS_ENUM | string;
|
|
79
|
+
localHour?: number | null;
|
|
80
|
+
};
|
|
81
|
+
export interface IDeliveryAccumulator {
|
|
82
|
+
counters: IMaterializedDeliveryCounters;
|
|
83
|
+
deliveryOrderIds: Set<string>;
|
|
84
|
+
deliveredOrderIds: Set<string>;
|
|
85
|
+
watermark: Date | null;
|
|
86
|
+
}
|
|
87
|
+
/** A fresh buffer. */
|
|
88
|
+
export declare function freshDeliveryAccumulator(): IDeliveryAccumulator;
|
|
89
|
+
/** True when an order is a DELIVERY order (it has delivery details). */
|
|
90
|
+
export declare function isDeliveryOrder(order: IDeliveryOrderSource): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Consumes ONE delivery ORDER - the ADOPTION half of the join.
|
|
93
|
+
*
|
|
94
|
+
* Order-side money is counted HERE rather than on the delivery, because a cancelled
|
|
95
|
+
* delivery must not lose the order figures the operator recognises.
|
|
96
|
+
*/
|
|
97
|
+
export declare function addDeliveryOrder(acc: IDeliveryAccumulator, order: IDeliveryOrderSource): void;
|
|
98
|
+
/**
|
|
99
|
+
* Consumes ONE delivery document - the APP-SIDE half of the join.
|
|
100
|
+
*
|
|
101
|
+
* `order` may be null (the order was not staged): the delivery still counts toward
|
|
102
|
+
* adoption and its own fields, but the order-derived money and the area cannot be
|
|
103
|
+
* attributed, so it lands in the UNKNOWN bucket.
|
|
104
|
+
*/
|
|
105
|
+
export declare function addDelivery(acc: IDeliveryAccumulator, delivery: TDeliverySource, order: IDeliveryOrderSource | null, key: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Computes the DERIVED adoption figures and prunes the bounded maps.
|
|
108
|
+
*
|
|
109
|
+
* Call ONCE per key, after both stages have been consumed. `off_app_count` is a set
|
|
110
|
+
* difference, so an order reassigned to a second rider is NOT counted as off-app even
|
|
111
|
+
* though there are more deliveries than orders.
|
|
112
|
+
*/
|
|
113
|
+
export declare function finalizeDeliveryAccumulator(acc: IDeliveryAccumulator): IMaterializedDeliveryCounters;
|