@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,98 @@
|
|
|
1
|
+
import { MATERIALIZED_PREP_TIME_ANCHOR_ENUM, MATERIALIZED_PREP_TIME_TARGET_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IMaterializedPrepTimeEntry } from '../../schemas/types/materialized_tenant_prep_time_entries';
|
|
3
|
+
import { IMaterializedPrepTimeCounters } from '../../schemas/types/materialized_tenant_prep_time_reports';
|
|
4
|
+
/**
|
|
5
|
+
* M2 prep time - provenance classifier + accumulator.
|
|
6
|
+
*
|
|
7
|
+
* THE RULE (concept doc section 3.2.1, decision b2): `ready_minutes` is written
|
|
8
|
+
* from the chain `prep_started_at ?? order_status_updated_at ?? createdAt`, and
|
|
9
|
+
* the two populations behave completely differently. Only an item whose anchor is
|
|
10
|
+
* its OWN prep clock yields a real prep time; a fallback-anchored value is
|
|
11
|
+
* degenerate (measured: avg 0.0, 99.8% zeros in one store). Blending them
|
|
12
|
+
* under-reports the average by ~13x, so UNMEASURED items are counted in coverage
|
|
13
|
+
* and EXCLUDED from every duration statistic.
|
|
14
|
+
*
|
|
15
|
+
* The field shapes here are verified against the live fixtures: items live at
|
|
16
|
+
* `order.categories[].items[]` (NOT `order.items[]`), and the estimate fields are
|
|
17
|
+
* absolute ISO timestamps.
|
|
18
|
+
*/
|
|
19
|
+
/** Context of one order's local time (mirrors the other report accumulators). */
|
|
20
|
+
/** Raw order/item fields the prep classifier reads. */
|
|
21
|
+
export interface IPrepTimeOrderSource {
|
|
22
|
+
_id: string;
|
|
23
|
+
order_number?: number | null;
|
|
24
|
+
order_status?: string | null;
|
|
25
|
+
platform?: string | null;
|
|
26
|
+
order_from?: string | null;
|
|
27
|
+
createdAt?: Date | string | null;
|
|
28
|
+
updatedAt?: Date | string | null;
|
|
29
|
+
tenant_id?: string | null;
|
|
30
|
+
localHour?: number | null;
|
|
31
|
+
staff_details?: {
|
|
32
|
+
_id?: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
} | null;
|
|
35
|
+
categories?: {
|
|
36
|
+
name?: string | null;
|
|
37
|
+
items?: {
|
|
38
|
+
_id?: string;
|
|
39
|
+
name?: string | null;
|
|
40
|
+
is_ready?: boolean;
|
|
41
|
+
ready_minutes?: number | string | null;
|
|
42
|
+
prep_started_at?: Date | string | null;
|
|
43
|
+
}[];
|
|
44
|
+
}[];
|
|
45
|
+
delivery_details?: {
|
|
46
|
+
estimated_delivery_time?: Date | string | null;
|
|
47
|
+
} | null;
|
|
48
|
+
takeaway_details?: {
|
|
49
|
+
estimated_takeaway_time?: Date | string | null;
|
|
50
|
+
} | null;
|
|
51
|
+
}
|
|
52
|
+
export interface IPrepTimeOrderContext {
|
|
53
|
+
local_date: string;
|
|
54
|
+
local_hour_label: string | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Histogram bucket label of a duration. Total by construction: the top bucket is
|
|
58
|
+
* open-ended, so every finite duration lands in exactly one bucket.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveMaterializedPrepTimeBucket(minutes: number): string;
|
|
61
|
+
/**
|
|
62
|
+
* Provenance of ONE item (decision b2).
|
|
63
|
+
*
|
|
64
|
+
* MEASURED requires BOTH `prep_started_at` and `ready_minutes`: the item owns its
|
|
65
|
+
* prep clock, so the ready instant is reconstructible. Anything else - including
|
|
66
|
+
* `ready_minutes` with no `prep_started_at` - is UNMEASURED.
|
|
67
|
+
*/
|
|
68
|
+
export declare function classifyMaterializedPrepTimeAnchor(item: {
|
|
69
|
+
prep_started_at?: unknown;
|
|
70
|
+
ready_minutes?: unknown;
|
|
71
|
+
}): MATERIALIZED_PREP_TIME_ANCHOR_ENUM;
|
|
72
|
+
/** A zeroed counter block. */
|
|
73
|
+
export declare function freshMaterializedPrepTimeCounters(): IMaterializedPrepTimeCounters;
|
|
74
|
+
/** The on-time target of one order, and where it came from (decision e2). */
|
|
75
|
+
export declare function resolveMaterializedPrepTimeTarget(order: Pick<IPrepTimeOrderSource, 'createdAt' | 'delivery_details' | 'takeaway_details'>, tenantDefaultMinutes?: number | null): {
|
|
76
|
+
target_at: Date | null;
|
|
77
|
+
target_source: MATERIALIZED_PREP_TIME_TARGET_ENUM;
|
|
78
|
+
};
|
|
79
|
+
/** Stable identity of a row inside its order - part of the page cursor. */
|
|
80
|
+
export declare const buildMaterializedPrepTimeEntryKey: (itemId: string | null) => string;
|
|
81
|
+
export interface IAccumulateOrderPrepTimeResult {
|
|
82
|
+
counters: IMaterializedPrepTimeCounters;
|
|
83
|
+
entries: IMaterializedPrepTimeEntry[];
|
|
84
|
+
/** Orders with at least one TRACKED item - the coverage numerator. */
|
|
85
|
+
has_tracked: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Accumulates ONE order's items into the prep counters + drill-down rows.
|
|
89
|
+
*
|
|
90
|
+
* Items are read from `order.categories[].items[]` (the verified shape). Every
|
|
91
|
+
* item counts toward coverage; only MEASURED items reach the duration statistics,
|
|
92
|
+
* and only MEASURED items with a target are graded on time.
|
|
93
|
+
*/
|
|
94
|
+
export declare function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes, }: {
|
|
95
|
+
order: IPrepTimeOrderSource;
|
|
96
|
+
context: IPrepTimeOrderContext;
|
|
97
|
+
tenantDefaultMinutes?: number | null;
|
|
98
|
+
}): IAccumulateOrderPrepTimeResult;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildMaterializedPrepTimeEntryKey = void 0;
|
|
4
|
+
exports.resolveMaterializedPrepTimeBucket = resolveMaterializedPrepTimeBucket;
|
|
5
|
+
exports.classifyMaterializedPrepTimeAnchor = classifyMaterializedPrepTimeAnchor;
|
|
6
|
+
exports.freshMaterializedPrepTimeCounters = freshMaterializedPrepTimeCounters;
|
|
7
|
+
exports.resolveMaterializedPrepTimeTarget = resolveMaterializedPrepTimeTarget;
|
|
8
|
+
exports.accumulateOrderPrepTime = accumulateOrderPrepTime;
|
|
9
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
10
|
+
/**
|
|
11
|
+
* Numeric or null - never NaN. The stored field is a duration in whole minutes.
|
|
12
|
+
*/
|
|
13
|
+
const toMinutes = (value) => {
|
|
14
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
15
|
+
return value;
|
|
16
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
17
|
+
const parsed = Number(value);
|
|
18
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Histogram bucket label of a duration. Total by construction: the top bucket is
|
|
24
|
+
* open-ended, so every finite duration lands in exactly one bucket.
|
|
25
|
+
*/
|
|
26
|
+
function resolveMaterializedPrepTimeBucket(minutes) {
|
|
27
|
+
for (const bucket of MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_BUCKETS) {
|
|
28
|
+
if (minutes >= bucket.min && (bucket.max === null || minutes <= bucket.max)) {
|
|
29
|
+
return bucket.label;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Unreachable while the buckets tile the range (a unit test pins the tiling),
|
|
33
|
+
// but a NaN or negative duration must never silently vanish from the counts.
|
|
34
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TOP_BUCKET;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Provenance of ONE item (decision b2).
|
|
38
|
+
*
|
|
39
|
+
* MEASURED requires BOTH `prep_started_at` and `ready_minutes`: the item owns its
|
|
40
|
+
* prep clock, so the ready instant is reconstructible. Anything else - including
|
|
41
|
+
* `ready_minutes` with no `prep_started_at` - is UNMEASURED.
|
|
42
|
+
*/
|
|
43
|
+
function classifyMaterializedPrepTimeAnchor(item) {
|
|
44
|
+
const hasOwnAnchor = item?.prep_started_at != null;
|
|
45
|
+
const minutes = toMinutes(item?.ready_minutes);
|
|
46
|
+
return hasOwnAnchor && minutes != null
|
|
47
|
+
? MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.MEASURED
|
|
48
|
+
: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.UNMEASURED;
|
|
49
|
+
}
|
|
50
|
+
/** A zeroed counter block. */
|
|
51
|
+
function freshMaterializedPrepTimeCounters() {
|
|
52
|
+
const buckets = {};
|
|
53
|
+
for (const bucket of MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_BUCKETS)
|
|
54
|
+
buckets[bucket.label] = 0;
|
|
55
|
+
return {
|
|
56
|
+
coverage: {
|
|
57
|
+
item_count: 0,
|
|
58
|
+
ready_item_count: 0,
|
|
59
|
+
tracked_count: 0,
|
|
60
|
+
own_anchor_count: 0,
|
|
61
|
+
fallback_anchor_count: 0,
|
|
62
|
+
order_count: 0,
|
|
63
|
+
},
|
|
64
|
+
duration: { min: 0, max: 0, sum: 0, count: 0, instant_count: 0, buckets },
|
|
65
|
+
promise: {
|
|
66
|
+
promise_set_count: 0,
|
|
67
|
+
default_baseline_count: 0,
|
|
68
|
+
on_time_count: 0,
|
|
69
|
+
late_count: 0,
|
|
70
|
+
delta_sum: 0,
|
|
71
|
+
no_target_count: 0,
|
|
72
|
+
},
|
|
73
|
+
late_items: { count: 0, worst_delta: 0 },
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** The on-time target of one order, and where it came from (decision e2). */
|
|
77
|
+
function resolveMaterializedPrepTimeTarget(order, tenantDefaultMinutes) {
|
|
78
|
+
// An explicit estimate is an ABSOLUTE timestamp on the order's detail block.
|
|
79
|
+
const promised = order?.takeaway_details?.estimated_takeaway_time ?? order?.delivery_details?.estimated_delivery_time ?? null;
|
|
80
|
+
if (typeof promised === 'string' && promised.trim() !== '') {
|
|
81
|
+
const at = new Date(promised);
|
|
82
|
+
if (!Number.isNaN(at.getTime())) {
|
|
83
|
+
return { target_at: at, target_source: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.PROMISE };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Otherwise the tenant default, measured from the punch instant. Absent in the
|
|
87
|
+
// dev fixtures (0 orders carry one), so it arrives from tenant config and is
|
|
88
|
+
// usually null - those items are honestly counted as NONE, never graded against
|
|
89
|
+
// an invented baseline.
|
|
90
|
+
const fallbackMinutes = toMinutes(tenantDefaultMinutes);
|
|
91
|
+
const createdMs = order?.createdAt != null ? new Date(order.createdAt).getTime() : NaN;
|
|
92
|
+
if (fallbackMinutes != null && fallbackMinutes > 0 && !Number.isNaN(createdMs)) {
|
|
93
|
+
return {
|
|
94
|
+
target_at: new Date(createdMs + fallbackMinutes * 60000),
|
|
95
|
+
target_source: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.TENANT_DEFAULT,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return { target_at: null, target_source: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.NONE };
|
|
99
|
+
}
|
|
100
|
+
/** Stable identity of a row inside its order - part of the page cursor. */
|
|
101
|
+
const buildMaterializedPrepTimeEntryKey = (itemId) => 'item:' + String(itemId ?? 'unknown');
|
|
102
|
+
exports.buildMaterializedPrepTimeEntryKey = buildMaterializedPrepTimeEntryKey;
|
|
103
|
+
/**
|
|
104
|
+
* Accumulates ONE order's items into the prep counters + drill-down rows.
|
|
105
|
+
*
|
|
106
|
+
* Items are read from `order.categories[].items[]` (the verified shape). Every
|
|
107
|
+
* item counts toward coverage; only MEASURED items reach the duration statistics,
|
|
108
|
+
* and only MEASURED items with a target are graded on time.
|
|
109
|
+
*/
|
|
110
|
+
function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes = null, }) {
|
|
111
|
+
const counters = freshMaterializedPrepTimeCounters();
|
|
112
|
+
const entries = [];
|
|
113
|
+
if (order == null)
|
|
114
|
+
return { counters, entries, has_tracked: false };
|
|
115
|
+
const orderId = order._id != null ? String(order._id) : null;
|
|
116
|
+
if (orderId == null)
|
|
117
|
+
return { counters, entries, has_tracked: false };
|
|
118
|
+
const orderStatus = String(order.order_status ?? '');
|
|
119
|
+
const platform = String(order.platform ?? order.order_from ?? '');
|
|
120
|
+
const staffId = order.staff_details?._id != null ? String(order.staff_details._id) : null;
|
|
121
|
+
const staffName = order.staff_details?.name != null ? String(order.staff_details.name) : null;
|
|
122
|
+
const createdMs = order.createdAt != null ? new Date(order.createdAt).getTime() : NaN;
|
|
123
|
+
const createdAt = Number.isNaN(createdMs) ? new Date(0) : new Date(createdMs);
|
|
124
|
+
const { target_at, target_source } = resolveMaterializedPrepTimeTarget(order, tenantDefaultMinutes);
|
|
125
|
+
let tracked = 0;
|
|
126
|
+
for (const category of order.categories ?? []) {
|
|
127
|
+
for (const item of category?.items ?? []) {
|
|
128
|
+
counters.coverage.item_count += 1;
|
|
129
|
+
const isReady = item?.is_ready === true;
|
|
130
|
+
if (isReady)
|
|
131
|
+
counters.coverage.ready_item_count += 1;
|
|
132
|
+
const minutes = toMinutes(item?.ready_minutes);
|
|
133
|
+
const prepStartedAt = item?.prep_started_at != null ? new Date(item.prep_started_at) : null;
|
|
134
|
+
const prepStartedValid = prepStartedAt != null && !Number.isNaN(prepStartedAt.getTime());
|
|
135
|
+
const anchor = prepStartedValid && minutes != null
|
|
136
|
+
? MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.MEASURED
|
|
137
|
+
: MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.UNMEASURED;
|
|
138
|
+
let readyAt = null;
|
|
139
|
+
let deltaMinutes = null;
|
|
140
|
+
if (minutes != null) {
|
|
141
|
+
tracked += 1;
|
|
142
|
+
counters.coverage.tracked_count += 1;
|
|
143
|
+
if (anchor === MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ANCHOR_ENUM.MEASURED) {
|
|
144
|
+
counters.coverage.own_anchor_count += 1;
|
|
145
|
+
// RECONSTRUCTED ready instant - the source field ready_at does not exist.
|
|
146
|
+
readyAt = new Date(prepStartedAt.getTime() + minutes * 60000);
|
|
147
|
+
counters.duration.count += 1;
|
|
148
|
+
if (minutes === 0)
|
|
149
|
+
counters.duration.instant_count += 1;
|
|
150
|
+
const bucket = resolveMaterializedPrepTimeBucket(minutes);
|
|
151
|
+
counters.duration.buckets[bucket] = (counters.duration.buckets[bucket] ?? 0) + 1;
|
|
152
|
+
// Counts above stay complete; only the EXTREMES are guarded, so a single
|
|
153
|
+
// clock/backfill artefact cannot define min/max/sum.
|
|
154
|
+
if (minutes <= MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_MAX_MINUTES) {
|
|
155
|
+
counters.duration.sum += minutes;
|
|
156
|
+
if (counters.duration.count === 1 || minutes < counters.duration.min) {
|
|
157
|
+
counters.duration.min = minutes;
|
|
158
|
+
}
|
|
159
|
+
if (minutes > counters.duration.max)
|
|
160
|
+
counters.duration.max = minutes;
|
|
161
|
+
}
|
|
162
|
+
if (target_at != null) {
|
|
163
|
+
deltaMinutes = Math.round((readyAt.getTime() - target_at.getTime()) / 60000);
|
|
164
|
+
counters.promise.delta_sum += deltaMinutes;
|
|
165
|
+
if (deltaMinutes <= MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA) {
|
|
166
|
+
counters.promise.on_time_count += 1;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
counters.promise.late_count += 1;
|
|
170
|
+
counters.late_items.count += 1;
|
|
171
|
+
if (deltaMinutes > counters.late_items.worst_delta) {
|
|
172
|
+
counters.late_items.worst_delta = deltaMinutes;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
counters.coverage.fallback_anchor_count += 1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (target_at != null) {
|
|
182
|
+
if (target_source === MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_TARGET_ENUM.PROMISE) {
|
|
183
|
+
counters.promise.promise_set_count += 1;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
counters.promise.default_baseline_count += 1;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
counters.promise.no_target_count += 1;
|
|
191
|
+
}
|
|
192
|
+
const itemId = item?._id != null ? String(item._id) : null;
|
|
193
|
+
const row = {
|
|
194
|
+
entry_key: (0, exports.buildMaterializedPrepTimeEntryKey)(itemId),
|
|
195
|
+
order_id: orderId,
|
|
196
|
+
order_number: order.order_number ?? null,
|
|
197
|
+
item_id: itemId,
|
|
198
|
+
item_name: item?.name != null ? String(item.name) : null,
|
|
199
|
+
category_name: category?.name != null ? String(category.name) : null,
|
|
200
|
+
anchor,
|
|
201
|
+
duration_minutes: minutes,
|
|
202
|
+
prep_started_at: prepStartedValid ? prepStartedAt : null,
|
|
203
|
+
ready_at: readyAt,
|
|
204
|
+
is_ready: isReady,
|
|
205
|
+
target_at,
|
|
206
|
+
target_source: target_at != null ? target_source : null,
|
|
207
|
+
delta_minutes: deltaMinutes,
|
|
208
|
+
staff_id: staffId,
|
|
209
|
+
staff_name: staffName,
|
|
210
|
+
order_status: orderStatus,
|
|
211
|
+
platform,
|
|
212
|
+
created_at: createdAt,
|
|
213
|
+
local_hour: context.local_hour_label,
|
|
214
|
+
};
|
|
215
|
+
// Only items with a prep signal become rows: an untouched item has nothing
|
|
216
|
+
// to inspect, and the drill-down exists to explain the numbers.
|
|
217
|
+
if (minutes != null || prepStartedValid)
|
|
218
|
+
entries.push(row);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (tracked > 0)
|
|
222
|
+
counters.coverage.order_count = 1;
|
|
223
|
+
return { counters, entries, has_tracked: tracked > 0 };
|
|
224
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IMaterializedPrepTimeEntry, IMaterializedTenantPrepTimeEntries } from '../../schemas/types/materialized_tenant_prep_time_entries';
|
|
3
|
+
import { IMaterializedPrepTimeCounters, IMaterializedTenantPrepTimeReport } from '../../schemas/types/materialized_tenant_prep_time_reports';
|
|
4
|
+
import { IMaterializedPeriodScopeFields } from './scope-helpers';
|
|
5
|
+
/**
|
|
6
|
+
* Merges a freshly compiled day of prep rows into a PERIOD document's stored
|
|
7
|
+
* rows.
|
|
8
|
+
*
|
|
9
|
+
* Idempotent by construction: the merge key is `(order_id, entry_key)`, which is
|
|
10
|
+
* globally unique per row (`entry_key` is the row's stable identity INSIDE its
|
|
11
|
+
* order, and an order belongs to exactly one day). Re-closing the SAME day
|
|
12
|
+
* therefore REPLACES its own rows rather than duplicating them, while a new day
|
|
13
|
+
* ADDS its rows.
|
|
14
|
+
*
|
|
15
|
+
* Without this a period document would hold only its final closed day - the
|
|
16
|
+
* measured M1 bug (a month entry document carrying 9 rows where the equivalent
|
|
17
|
+
* ledger month carried the whole month).
|
|
18
|
+
*/
|
|
19
|
+
export declare const mergeMaterializedPrepTimeEntrySections: (stored: Record<string, {
|
|
20
|
+
rows: IMaterializedPrepTimeEntry[];
|
|
21
|
+
}> | null | undefined, fresh: Record<string, {
|
|
22
|
+
rows: IMaterializedPrepTimeEntry[];
|
|
23
|
+
}> | null | undefined) => Record<string, {
|
|
24
|
+
rows: IMaterializedPrepTimeEntry[];
|
|
25
|
+
}>;
|
|
26
|
+
/** True when the document is one of the day scopes (replaced wholesale). */
|
|
27
|
+
export declare const isMaterializedPrepTimeDayScope: (scopeContext: string) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Updates a stored prep ENTRY document.
|
|
30
|
+
*
|
|
31
|
+
* DAY scopes (`localDate`) are REPLACED wholesale - the day's rows are the whole
|
|
32
|
+
* truth. PERIOD scopes MERGE, because the compile produces only ONE day of rows.
|
|
33
|
+
* Returns null when the documents disagree on schema/scope (a data issue the
|
|
34
|
+
* caller must surface).
|
|
35
|
+
*/
|
|
36
|
+
export declare function updateMaterializedPrepTimeEntries(existing: IMaterializedTenantPrepTimeEntries | null | undefined, compiled: IMaterializedTenantPrepTimeEntries | null | undefined, options?: {
|
|
37
|
+
computedAt?: Date;
|
|
38
|
+
}): IMaterializedTenantPrepTimeEntries | null;
|
|
39
|
+
/** True when a stored prep entry document equals the compiled one (skip write). */
|
|
40
|
+
export declare function needsMaterializedPrepTimeEntriesWrite(existing: IMaterializedTenantPrepTimeEntries | null | undefined, incoming: IMaterializedTenantPrepTimeEntries | null | undefined): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Folds the day documents of ONE period scope into that period's counters.
|
|
43
|
+
*
|
|
44
|
+
* `dayDocuments` must be the AUTHORITATIVE day set for the period: every stored
|
|
45
|
+
* `localDate` document that maps to this period, PLUS the day being closed (which
|
|
46
|
+
* supersedes any stored document for the same day). The caller supplies it, so a
|
|
47
|
+
* re-close naturally replaces its own contribution.
|
|
48
|
+
*
|
|
49
|
+
* Returns null when the period fields cannot be resolved for any supplied day -
|
|
50
|
+
* the caller surfaces that instead of writing a silently short period.
|
|
51
|
+
*/
|
|
52
|
+
export declare function foldMaterializedPrepTimePeriodCounters({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }: {
|
|
53
|
+
periodScopeField: string;
|
|
54
|
+
periodScope: keyof IMaterializedPeriodScopeFields;
|
|
55
|
+
dayDocuments: IMaterializedTenantPrepTimeReport[];
|
|
56
|
+
periodFieldsOfDay: (localDate: string) => IMaterializedPeriodScopeFields | null;
|
|
57
|
+
}): Record<string, IMaterializedPrepTimeCounters> | null;
|
|
58
|
+
/**
|
|
59
|
+
* Folds the day documents of ONE period into that period's ENTRY rows, using the
|
|
60
|
+
* same authoritative day set as the counters. Rows are keyed by
|
|
61
|
+
* `(order_id, entry_key)` so a re-closed day replaces its own rows.
|
|
62
|
+
*/
|
|
63
|
+
export declare function foldMaterializedPrepTimePeriodRows({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }: {
|
|
64
|
+
periodScopeField: string;
|
|
65
|
+
periodScope: keyof IMaterializedPeriodScopeFields;
|
|
66
|
+
dayDocuments: IMaterializedTenantPrepTimeEntries[];
|
|
67
|
+
periodFieldsOfDay: (localDate: string) => IMaterializedPeriodScopeFields | null;
|
|
68
|
+
}): Record<string, {
|
|
69
|
+
rows: IMaterializedPrepTimeEntry[];
|
|
70
|
+
}>;
|
|
71
|
+
/** The period scope contexts (everything except the day scope). */
|
|
72
|
+
export declare const MATERIALIZED_PREP_TIME_PERIOD_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
73
|
+
/** True when a stored prep counter document equals the incoming one (skip write). */
|
|
74
|
+
export declare function needsMaterializedPrepTimeReportWrite(existing: IMaterializedTenantPrepTimeReport | null | undefined, incoming: IMaterializedTenantPrepTimeReport | null | undefined): boolean;
|
|
75
|
+
/** One planned write: the document plus its shared-history iteration row. */
|
|
76
|
+
export interface IMaterializedPrepTimeCloseDayWrite<T> {
|
|
77
|
+
report: T;
|
|
78
|
+
iteration: {
|
|
79
|
+
report_type: string;
|
|
80
|
+
report_id: string;
|
|
81
|
+
iteration: number;
|
|
82
|
+
schema_version: number;
|
|
83
|
+
reason: string;
|
|
84
|
+
snapshot: unknown;
|
|
85
|
+
createdAt: Date;
|
|
86
|
+
updatedAt: Date;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export interface ITenantPrepTimeCloseDayPlan {
|
|
90
|
+
/** Counter writes (report + history row) - persist in any order. */
|
|
91
|
+
writes: IMaterializedPrepTimeCloseDayWrite<IMaterializedTenantPrepTimeReport>[];
|
|
92
|
+
/** Entry writes (rows + history row) - persist after the counter writes. */
|
|
93
|
+
entryWrites: IMaterializedPrepTimeCloseDayWrite<IMaterializedTenantPrepTimeEntries>[];
|
|
94
|
+
/** Stored DAY-scoped counters no longer backed by activity - delete by _id. */
|
|
95
|
+
staleDocuments: IMaterializedTenantPrepTimeReport[];
|
|
96
|
+
/** Stored DAY-scoped entry docs no longer backed by rows - delete by _id. */
|
|
97
|
+
staleEntryDocuments: IMaterializedTenantPrepTimeEntries[];
|
|
98
|
+
/** Counter docs already up to date. */
|
|
99
|
+
skippedDocuments: IMaterializedTenantPrepTimeReport[];
|
|
100
|
+
/** Entry docs already up to date. */
|
|
101
|
+
skippedEntryDocuments: IMaterializedTenantPrepTimeEntries[];
|
|
102
|
+
}
|
|
103
|
+
export interface IBuildTenantPrepTimeCloseDayPlanInput {
|
|
104
|
+
tenantId: string;
|
|
105
|
+
/** The compiled day (report + entries documents for ONE local date). */
|
|
106
|
+
reports: IMaterializedTenantPrepTimeReport[];
|
|
107
|
+
entries: IMaterializedTenantPrepTimeEntries[];
|
|
108
|
+
/**
|
|
109
|
+
* The local date being closed. REQUIRED when the day compiled nothing at all -
|
|
110
|
+
* an emptied day has no date document to read it from, and the plan still has to
|
|
111
|
+
* know which day to clear.
|
|
112
|
+
*/
|
|
113
|
+
localDate?: string | null;
|
|
114
|
+
existing?: IMaterializedTenantPrepTimeReport[];
|
|
115
|
+
existingEntries?: IMaterializedTenantPrepTimeEntries[];
|
|
116
|
+
reason: string;
|
|
117
|
+
computedAt?: Date;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Builds the close-day plan for ONE tenant-day.
|
|
121
|
+
*
|
|
122
|
+
* The DAY scope is written from the compile. Every PERIOD scope the day touches
|
|
123
|
+
* is RE-FOLDED from its whole day set - including periods that contained a day
|
|
124
|
+
* that just became empty, which is why the touched set is the union of the closed
|
|
125
|
+
* day's periods and every removed day's periods. Without that, emptying a day
|
|
126
|
+
* would leave its contribution stranded in the period forever.
|
|
127
|
+
*
|
|
128
|
+
* Returns null on malformed input or a data issue the caller must surface.
|
|
129
|
+
*/
|
|
130
|
+
export declare function buildTenantPrepTimeCloseDayPlan(input: IBuildTenantPrepTimeCloseDayPlanInput | null | undefined): ITenantPrepTimeCloseDayPlan | null;
|