@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,491 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES = exports.isMaterializedPrepTimeDayScope = exports.mergeMaterializedPrepTimeEntrySections = void 0;
|
|
7
|
+
exports.updateMaterializedPrepTimeEntries = updateMaterializedPrepTimeEntries;
|
|
8
|
+
exports.needsMaterializedPrepTimeEntriesWrite = needsMaterializedPrepTimeEntriesWrite;
|
|
9
|
+
exports.foldMaterializedPrepTimePeriodCounters = foldMaterializedPrepTimePeriodCounters;
|
|
10
|
+
exports.foldMaterializedPrepTimePeriodRows = foldMaterializedPrepTimePeriodRows;
|
|
11
|
+
exports.needsMaterializedPrepTimeReportWrite = needsMaterializedPrepTimeReportWrite;
|
|
12
|
+
exports.buildTenantPrepTimeCloseDayPlan = buildTenantPrepTimeCloseDayPlan;
|
|
13
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
14
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
15
|
+
const materialized_prep_time_classification_helpers_1 = require("./materialized-prep-time-classification-helpers");
|
|
16
|
+
const materialized_prep_time_compile_helpers_1 = require("./materialized-prep-time-compile-helpers");
|
|
17
|
+
const materialized_tenant_reports_iterations_helpers_1 = require("./materialized-tenant-reports-iterations-helpers");
|
|
18
|
+
const scope_helpers_1 = require("./scope-helpers");
|
|
19
|
+
/**
|
|
20
|
+
* M2 close-day helpers.
|
|
21
|
+
*
|
|
22
|
+
* ## Why period counters are RECOMPUTED, not patched
|
|
23
|
+
*
|
|
24
|
+
* The other report ledgers keep period scopes up to date by SUBTRACTING the
|
|
25
|
+
* stored day delta and adding the fresh one. That cannot work here:
|
|
26
|
+
* `duration.min` / `duration.max` / `late_items.worst_delta` are AGGREGATES, and
|
|
27
|
+
* there is no way to "subtract" a minimum - removing the day that contributed the
|
|
28
|
+
* smallest value would leave a minimum that no longer exists in any day.
|
|
29
|
+
*
|
|
30
|
+
* So a period document's counters are FOLDED from the day documents that belong
|
|
31
|
+
* to it (the stored ones plus the day being closed). That is both correct for
|
|
32
|
+
* aggregates and IDEMPOTENT: re-closing the same day replaces that day's
|
|
33
|
+
* contribution and re-folds, so a re-close converges instead of drifting.
|
|
34
|
+
*/
|
|
35
|
+
/** Scopes written wholesale for the compiled day (no hour scope in v1). */
|
|
36
|
+
const PREP_TIME_DAY_SCOPES = [MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE];
|
|
37
|
+
/** Row identity inside a period document: an order holds many items. */
|
|
38
|
+
const prepEntryRowIdentity = (row) => String(row.order_id) + '|' + String(row.entry_key);
|
|
39
|
+
/**
|
|
40
|
+
* Merges a freshly compiled day of prep rows into a PERIOD document's stored
|
|
41
|
+
* rows.
|
|
42
|
+
*
|
|
43
|
+
* Idempotent by construction: the merge key is `(order_id, entry_key)`, which is
|
|
44
|
+
* globally unique per row (`entry_key` is the row's stable identity INSIDE its
|
|
45
|
+
* order, and an order belongs to exactly one day). Re-closing the SAME day
|
|
46
|
+
* therefore REPLACES its own rows rather than duplicating them, while a new day
|
|
47
|
+
* ADDS its rows.
|
|
48
|
+
*
|
|
49
|
+
* Without this a period document would hold only its final closed day - the
|
|
50
|
+
* measured M1 bug (a month entry document carrying 9 rows where the equivalent
|
|
51
|
+
* ledger month carried the whole month).
|
|
52
|
+
*/
|
|
53
|
+
const mergeMaterializedPrepTimeEntrySections = (stored, fresh) => {
|
|
54
|
+
const out = {};
|
|
55
|
+
const keys = new Set([...Object.keys(stored ?? {}), ...Object.keys(fresh ?? {})]);
|
|
56
|
+
for (const key of keys) {
|
|
57
|
+
const byIdentity = new Map();
|
|
58
|
+
for (const row of stored?.[key]?.rows ?? []) {
|
|
59
|
+
byIdentity.set(prepEntryRowIdentity(row), row);
|
|
60
|
+
}
|
|
61
|
+
// FRESH wins: a re-close of the same day overwrites its own rows.
|
|
62
|
+
for (const row of fresh?.[key]?.rows ?? []) {
|
|
63
|
+
byIdentity.set(prepEntryRowIdentity(row), row);
|
|
64
|
+
}
|
|
65
|
+
if (byIdentity.size > 0)
|
|
66
|
+
out[key] = { rows: [...byIdentity.values()] };
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
};
|
|
70
|
+
exports.mergeMaterializedPrepTimeEntrySections = mergeMaterializedPrepTimeEntrySections;
|
|
71
|
+
/** True when the document is one of the day scopes (replaced wholesale). */
|
|
72
|
+
const isMaterializedPrepTimeDayScope = (scopeContext) => PREP_TIME_DAY_SCOPES.includes(scopeContext);
|
|
73
|
+
exports.isMaterializedPrepTimeDayScope = isMaterializedPrepTimeDayScope;
|
|
74
|
+
/**
|
|
75
|
+
* Updates a stored prep ENTRY document.
|
|
76
|
+
*
|
|
77
|
+
* DAY scopes (`localDate`) are REPLACED wholesale - the day's rows are the whole
|
|
78
|
+
* truth. PERIOD scopes MERGE, because the compile produces only ONE day of rows.
|
|
79
|
+
* Returns null when the documents disagree on schema/scope (a data issue the
|
|
80
|
+
* caller must surface).
|
|
81
|
+
*/
|
|
82
|
+
function updateMaterializedPrepTimeEntries(existing, compiled, options = {}) {
|
|
83
|
+
if (existing == null || compiled == null)
|
|
84
|
+
return null;
|
|
85
|
+
if (existing.schema_version !== compiled.schema_version ||
|
|
86
|
+
existing.scope_context !== compiled.scope_context ||
|
|
87
|
+
existing.scope_field !== compiled.scope_field) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const computedAt = options.computedAt ?? new Date();
|
|
91
|
+
const existingTime = new Date(existing.source_watermark ?? 0).getTime();
|
|
92
|
+
const compiledTime = new Date(compiled.source_watermark ?? 0).getTime();
|
|
93
|
+
const mergePeriodRows = !(0, exports.isMaterializedPrepTimeDayScope)(String(compiled.scope_context));
|
|
94
|
+
return {
|
|
95
|
+
...existing,
|
|
96
|
+
prep_time_entries: mergePeriodRows
|
|
97
|
+
? (0, exports.mergeMaterializedPrepTimeEntrySections)(existing.prep_time_entries, compiled.prep_time_entries)
|
|
98
|
+
: compiled.prep_time_entries,
|
|
99
|
+
source_watermark: compiledTime > existingTime ? compiled.source_watermark : existing.source_watermark,
|
|
100
|
+
computed_at: computedAt,
|
|
101
|
+
updatedAt: computedAt,
|
|
102
|
+
iteration: (existing.iteration ?? 1) + 1,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** True when a stored prep entry document equals the compiled one (skip write). */
|
|
106
|
+
function needsMaterializedPrepTimeEntriesWrite(existing, incoming) {
|
|
107
|
+
if (existing == null || incoming == null)
|
|
108
|
+
return true;
|
|
109
|
+
if (existing.schema_version !== incoming.schema_version)
|
|
110
|
+
return true;
|
|
111
|
+
if ((existing.sale_type_key_filters ?? []).join(':') !== (incoming.sale_type_key_filters ?? []).join(':')) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
const existingTime = new Date(existing.source_watermark ?? 0).getTime();
|
|
115
|
+
const incomingTime = new Date(incoming.source_watermark ?? 0).getTime();
|
|
116
|
+
if (Number.isNaN(existingTime) || Number.isNaN(incomingTime))
|
|
117
|
+
return true;
|
|
118
|
+
return incomingTime > existingTime;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Folds the day documents of ONE period scope into that period's counters.
|
|
122
|
+
*
|
|
123
|
+
* `dayDocuments` must be the AUTHORITATIVE day set for the period: every stored
|
|
124
|
+
* `localDate` document that maps to this period, PLUS the day being closed (which
|
|
125
|
+
* supersedes any stored document for the same day). The caller supplies it, so a
|
|
126
|
+
* re-close naturally replaces its own contribution.
|
|
127
|
+
*
|
|
128
|
+
* Returns null when the period fields cannot be resolved for any supplied day -
|
|
129
|
+
* the caller surfaces that instead of writing a silently short period.
|
|
130
|
+
*/
|
|
131
|
+
function foldMaterializedPrepTimePeriodCounters({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }) {
|
|
132
|
+
const folded = {};
|
|
133
|
+
for (const dayDoc of dayDocuments) {
|
|
134
|
+
if (dayDoc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
135
|
+
continue;
|
|
136
|
+
const fields = periodFieldsOfDay(String(dayDoc.scope_field));
|
|
137
|
+
if (fields == null)
|
|
138
|
+
return null;
|
|
139
|
+
if (fields[periodScope] !== periodScopeField)
|
|
140
|
+
continue;
|
|
141
|
+
for (const [key, counters] of Object.entries(dayDoc.prep_time_counters ?? {})) {
|
|
142
|
+
const bucket = (folded[key] ?? (folded[key] = (0, materialized_prep_time_classification_helpers_1.freshMaterializedPrepTimeCounters)()));
|
|
143
|
+
(0, materialized_prep_time_compile_helpers_1.mergeMaterializedPrepTimeCounters)(bucket, counters);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return folded;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Folds the day documents of ONE period into that period's ENTRY rows, using the
|
|
150
|
+
* same authoritative day set as the counters. Rows are keyed by
|
|
151
|
+
* `(order_id, entry_key)` so a re-closed day replaces its own rows.
|
|
152
|
+
*/
|
|
153
|
+
function foldMaterializedPrepTimePeriodRows({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }) {
|
|
154
|
+
const sections = {};
|
|
155
|
+
for (const dayDoc of dayDocuments) {
|
|
156
|
+
if (dayDoc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
157
|
+
continue;
|
|
158
|
+
const fields = periodFieldsOfDay(String(dayDoc.scope_field));
|
|
159
|
+
if (fields == null)
|
|
160
|
+
continue;
|
|
161
|
+
if (fields[periodScope] !== periodScopeField)
|
|
162
|
+
continue;
|
|
163
|
+
const merged = (0, exports.mergeMaterializedPrepTimeEntrySections)(sections, dayDoc.prep_time_entries);
|
|
164
|
+
for (const key of Object.keys(merged))
|
|
165
|
+
sections[key] = merged[key];
|
|
166
|
+
}
|
|
167
|
+
return sections;
|
|
168
|
+
}
|
|
169
|
+
/** The period scope contexts (everything except the day scope). */
|
|
170
|
+
exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_REPORT_SCOPES.filter((scope) => !(0, exports.isMaterializedPrepTimeDayScope)(String(scope)));
|
|
171
|
+
/** True when a stored prep counter document equals the incoming one (skip write). */
|
|
172
|
+
function needsMaterializedPrepTimeReportWrite(existing, incoming) {
|
|
173
|
+
if (existing == null || incoming == null)
|
|
174
|
+
return true;
|
|
175
|
+
if (existing.schema_version !== incoming.schema_version)
|
|
176
|
+
return true;
|
|
177
|
+
if ((existing.sale_type_key_filters ?? []).join(':') !== (incoming.sale_type_key_filters ?? []).join(':')) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
const existingTime = new Date(existing.source_watermark ?? 0).getTime();
|
|
181
|
+
const incomingTime = new Date(incoming.source_watermark ?? 0).getTime();
|
|
182
|
+
if (Number.isNaN(existingTime) || Number.isNaN(incomingTime))
|
|
183
|
+
return true;
|
|
184
|
+
return incomingTime > existingTime;
|
|
185
|
+
}
|
|
186
|
+
const prepScopeKey = (doc) => doc.scope_context + '|' + doc.scope_field;
|
|
187
|
+
/**
|
|
188
|
+
* Builds the close-day plan for ONE tenant-day.
|
|
189
|
+
*
|
|
190
|
+
* The DAY scope is written from the compile. Every PERIOD scope the day touches
|
|
191
|
+
* is RE-FOLDED from its whole day set - including periods that contained a day
|
|
192
|
+
* that just became empty, which is why the touched set is the union of the closed
|
|
193
|
+
* day's periods and every removed day's periods. Without that, emptying a day
|
|
194
|
+
* would leave its contribution stranded in the period forever.
|
|
195
|
+
*
|
|
196
|
+
* Returns null on malformed input or a data issue the caller must surface.
|
|
197
|
+
*/
|
|
198
|
+
function buildTenantPrepTimeCloseDayPlan(input) {
|
|
199
|
+
if (input == null)
|
|
200
|
+
return null;
|
|
201
|
+
const { tenantId, reports, entries, reason } = input;
|
|
202
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
203
|
+
return null;
|
|
204
|
+
if (typeof reason !== 'string' || reason.length === 0)
|
|
205
|
+
return null;
|
|
206
|
+
if (!Array.isArray(reports) || !Array.isArray(entries))
|
|
207
|
+
return null;
|
|
208
|
+
if (reports.some((doc) => doc == null || doc.tenant_id !== tenantId))
|
|
209
|
+
return null;
|
|
210
|
+
const computedAt = input.computedAt ?? new Date();
|
|
211
|
+
const existing = input.existing ?? [];
|
|
212
|
+
const existingEntries = input.existingEntries ?? [];
|
|
213
|
+
const dateDoc = reports.find((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE) ?? null;
|
|
214
|
+
const localDate = dateDoc?.scope_field ?? input.localDate ?? null;
|
|
215
|
+
if (typeof localDate !== 'string' || localDate.length === 0)
|
|
216
|
+
return null;
|
|
217
|
+
const periodFieldsOfDay = (day) => (0, scope_helpers_1.getMaterializedPeriodScopeFields)(day);
|
|
218
|
+
const closedDayFields = periodFieldsOfDay(localDate);
|
|
219
|
+
if (closedDayFields == null)
|
|
220
|
+
return null;
|
|
221
|
+
const writes = [];
|
|
222
|
+
const entryWrites = [];
|
|
223
|
+
const staleDocuments = [];
|
|
224
|
+
const staleEntryDocuments = [];
|
|
225
|
+
const skippedDocuments = [];
|
|
226
|
+
const skippedEntryDocuments = [];
|
|
227
|
+
const addWrite = (report) => {
|
|
228
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
229
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
230
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_REPORTS,
|
|
231
|
+
reason,
|
|
232
|
+
computedAt,
|
|
233
|
+
});
|
|
234
|
+
if (iteration == null)
|
|
235
|
+
return false;
|
|
236
|
+
writes.push({ report: persisted, iteration: iteration });
|
|
237
|
+
return true;
|
|
238
|
+
};
|
|
239
|
+
const addEntryWrite = (report) => {
|
|
240
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
241
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
242
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES,
|
|
243
|
+
reason,
|
|
244
|
+
computedAt,
|
|
245
|
+
});
|
|
246
|
+
if (iteration == null)
|
|
247
|
+
return false;
|
|
248
|
+
entryWrites.push({ report: persisted, iteration: iteration });
|
|
249
|
+
return true;
|
|
250
|
+
};
|
|
251
|
+
const existingByScope = new Map();
|
|
252
|
+
for (const doc of existing)
|
|
253
|
+
existingByScope.set(prepScopeKey(doc), doc);
|
|
254
|
+
const existingEntriesByScope = new Map();
|
|
255
|
+
for (const doc of existingEntries)
|
|
256
|
+
existingEntriesByScope.set(prepScopeKey(doc), doc);
|
|
257
|
+
const compiledByScope = new Map();
|
|
258
|
+
for (const doc of reports) {
|
|
259
|
+
const key = prepScopeKey(doc);
|
|
260
|
+
if (compiledByScope.has(key))
|
|
261
|
+
return null; // duplicate - data issue
|
|
262
|
+
compiledByScope.set(key, doc);
|
|
263
|
+
}
|
|
264
|
+
// ---- the authoritative DAY set after this close --------------------------
|
|
265
|
+
// Stored day documents, minus the day being closed, plus the compiled day.
|
|
266
|
+
const removedDays = [];
|
|
267
|
+
const nextDayDocs = [];
|
|
268
|
+
for (const doc of existing) {
|
|
269
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
270
|
+
continue;
|
|
271
|
+
if (String(doc.scope_field) === localDate)
|
|
272
|
+
continue;
|
|
273
|
+
nextDayDocs.push(doc);
|
|
274
|
+
}
|
|
275
|
+
const compiledDateDocs = reports.filter((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE);
|
|
276
|
+
for (const doc of compiledDateDocs)
|
|
277
|
+
nextDayDocs.push(doc);
|
|
278
|
+
// ONLY THE DAY BEING CLOSED can become stale here. Every other day document is
|
|
279
|
+
// owned by ITS OWN close - treating them as stale would delete the whole history
|
|
280
|
+
// on the next close.
|
|
281
|
+
for (const doc of existing) {
|
|
282
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
283
|
+
continue;
|
|
284
|
+
if (String(doc.scope_field) !== localDate)
|
|
285
|
+
continue;
|
|
286
|
+
if (compiledByScope.has(prepScopeKey(doc)))
|
|
287
|
+
continue;
|
|
288
|
+
// The closed day compiled nothing: its stored document (and its contribution
|
|
289
|
+
// to every period) must go.
|
|
290
|
+
staleDocuments.push(doc);
|
|
291
|
+
removedDays.push(localDate);
|
|
292
|
+
}
|
|
293
|
+
// ---- PERIOD scopes: re-fold every period the closed/removed days touch ---
|
|
294
|
+
const touchedPeriods = new Map();
|
|
295
|
+
const noteDay = (day) => {
|
|
296
|
+
const fields = periodFieldsOfDay(day);
|
|
297
|
+
if (fields == null)
|
|
298
|
+
return false;
|
|
299
|
+
for (const scope of exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES) {
|
|
300
|
+
const periodScope = scope;
|
|
301
|
+
const field = fields[periodScope];
|
|
302
|
+
if (field == null)
|
|
303
|
+
continue;
|
|
304
|
+
touchedPeriods.set(String(scope) + '|' + field, { scope: periodScope, field });
|
|
305
|
+
}
|
|
306
|
+
return true;
|
|
307
|
+
};
|
|
308
|
+
if (!noteDay(localDate))
|
|
309
|
+
return null;
|
|
310
|
+
for (const removed of removedDays)
|
|
311
|
+
if (!noteDay(removed))
|
|
312
|
+
return null;
|
|
313
|
+
for (const { scope, field } of touchedPeriods.values()) {
|
|
314
|
+
const folded = foldMaterializedPrepTimePeriodCounters({
|
|
315
|
+
periodScope: scope,
|
|
316
|
+
periodScopeField: field,
|
|
317
|
+
dayDocuments: nextDayDocs,
|
|
318
|
+
periodFieldsOfDay,
|
|
319
|
+
});
|
|
320
|
+
if (folded == null)
|
|
321
|
+
return null;
|
|
322
|
+
const existingDoc = existingByScope.get(scope + '|' + field) ?? null;
|
|
323
|
+
const keys = Object.keys(folded);
|
|
324
|
+
if (keys.length === 0) {
|
|
325
|
+
// Nothing left in the period - an empty period document must not survive.
|
|
326
|
+
if (existingDoc != null)
|
|
327
|
+
staleDocuments.push(existingDoc);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const counters = {};
|
|
331
|
+
const counterRows = [];
|
|
332
|
+
let watermark = null;
|
|
333
|
+
for (const key of keys) {
|
|
334
|
+
counters[key] = folded[key];
|
|
335
|
+
counterRows.push({ key, counters: folded[key] });
|
|
336
|
+
}
|
|
337
|
+
for (const dayDoc of nextDayDocs) {
|
|
338
|
+
const fields = periodFieldsOfDay(String(dayDoc.scope_field));
|
|
339
|
+
if (fields == null)
|
|
340
|
+
continue;
|
|
341
|
+
if (fields[scope] !== field)
|
|
342
|
+
continue;
|
|
343
|
+
const time = new Date(dayDoc.source_watermark ?? 0).getTime();
|
|
344
|
+
if (Number.isNaN(time))
|
|
345
|
+
continue;
|
|
346
|
+
if (watermark == null || time > watermark.getTime())
|
|
347
|
+
watermark = new Date(time);
|
|
348
|
+
}
|
|
349
|
+
const report = {
|
|
350
|
+
// A period document created by the fold gets a fresh id; an existing one keeps
|
|
351
|
+
// its identity so the upsert targets the same row.
|
|
352
|
+
_id: existingDoc?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
353
|
+
tenant_id: tenantId,
|
|
354
|
+
brand_id: existingDoc?.brand_id ?? reports[0]?.brand_id ?? '',
|
|
355
|
+
scope_context: scope,
|
|
356
|
+
scope_field: field,
|
|
357
|
+
day_index: null,
|
|
358
|
+
sale_type_key_filters: existingDoc?.sale_type_key_filters ?? reports[0]?.sale_type_key_filters ?? [],
|
|
359
|
+
prep_time_counters: counters,
|
|
360
|
+
prep_time_counter_rows: counterRows,
|
|
361
|
+
iteration: existingDoc?.iteration,
|
|
362
|
+
schema_version: existingDoc?.schema_version ?? 1,
|
|
363
|
+
source_watermark: watermark ?? new Date(computedAt),
|
|
364
|
+
computed_at: computedAt,
|
|
365
|
+
createdAt: existingDoc?.createdAt ?? computedAt,
|
|
366
|
+
updatedAt: computedAt,
|
|
367
|
+
};
|
|
368
|
+
if (existingDoc != null && !needsMaterializedPrepTimeReportWrite(existingDoc, report)) {
|
|
369
|
+
skippedDocuments.push(existingDoc);
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (!addWrite(report))
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
// ---- the DAY scope: written straight from the compile --------------------
|
|
376
|
+
for (const doc of compiledDateDocs) {
|
|
377
|
+
const existingDoc = existingByScope.get(prepScopeKey(doc)) ?? null;
|
|
378
|
+
if (existingDoc != null && !needsMaterializedPrepTimeReportWrite(existingDoc, doc)) {
|
|
379
|
+
skippedDocuments.push(existingDoc);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (!addWrite(doc))
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
// ---- entry documents ------------------------------------------------------
|
|
386
|
+
const compiledEntriesByScope = new Map();
|
|
387
|
+
for (const doc of entries) {
|
|
388
|
+
if (doc == null || doc.tenant_id !== tenantId)
|
|
389
|
+
return null;
|
|
390
|
+
const key = prepScopeKey(doc);
|
|
391
|
+
if (compiledEntriesByScope.has(key))
|
|
392
|
+
return null;
|
|
393
|
+
compiledEntriesByScope.set(key, doc);
|
|
394
|
+
}
|
|
395
|
+
const nextDayEntries = [];
|
|
396
|
+
for (const doc of existingEntries) {
|
|
397
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
398
|
+
continue;
|
|
399
|
+
if (String(doc.scope_field) === localDate)
|
|
400
|
+
continue;
|
|
401
|
+
nextDayEntries.push(doc);
|
|
402
|
+
}
|
|
403
|
+
for (const doc of entries) {
|
|
404
|
+
if (doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
405
|
+
nextDayEntries.push(doc);
|
|
406
|
+
}
|
|
407
|
+
for (const doc of existingEntries) {
|
|
408
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
409
|
+
continue;
|
|
410
|
+
if (String(doc.scope_field) !== localDate)
|
|
411
|
+
continue;
|
|
412
|
+
if (compiledEntriesByScope.has(prepScopeKey(doc)))
|
|
413
|
+
continue;
|
|
414
|
+
staleEntryDocuments.push(doc);
|
|
415
|
+
}
|
|
416
|
+
for (const { scope, field } of touchedPeriods.values()) {
|
|
417
|
+
const sections = foldMaterializedPrepTimePeriodRows({
|
|
418
|
+
periodScope: scope,
|
|
419
|
+
periodScopeField: field,
|
|
420
|
+
dayDocuments: nextDayEntries,
|
|
421
|
+
periodFieldsOfDay,
|
|
422
|
+
});
|
|
423
|
+
const existingDoc = existingEntriesByScope.get(scope + '|' + field) ?? null;
|
|
424
|
+
const keys = Object.keys(sections);
|
|
425
|
+
if (keys.length === 0) {
|
|
426
|
+
if (existingDoc != null)
|
|
427
|
+
staleEntryDocuments.push(existingDoc);
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
// The watermark MUST advance with the folded days. Inheriting the STORED
|
|
431
|
+
// document watermark would make the folded document look unchanged, and
|
|
432
|
+
// needsMaterializedPrepTimeEntriesWrite would then SKIP the write forever -
|
|
433
|
+
// freezing the period at its first closed day (measured: a month document
|
|
434
|
+
// holding 94 rows where its 30 days totalled 1726).
|
|
435
|
+
let entryWatermark = existingDoc?.source_watermark ?? null;
|
|
436
|
+
for (const dayDoc of nextDayEntries) {
|
|
437
|
+
const fields = periodFieldsOfDay(String(dayDoc.scope_field));
|
|
438
|
+
if (fields == null)
|
|
439
|
+
continue;
|
|
440
|
+
if (fields[scope] !== field)
|
|
441
|
+
continue;
|
|
442
|
+
const time = new Date(dayDoc.source_watermark ?? 0).getTime();
|
|
443
|
+
if (Number.isNaN(time))
|
|
444
|
+
continue;
|
|
445
|
+
if (entryWatermark == null || time > entryWatermark.getTime()) {
|
|
446
|
+
entryWatermark = new Date(time);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const report = {
|
|
450
|
+
_id: existingDoc?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
451
|
+
tenant_id: tenantId,
|
|
452
|
+
brand_id: existingDoc?.brand_id ?? entries[0]?.brand_id ?? '',
|
|
453
|
+
scope_context: scope,
|
|
454
|
+
scope_field: field,
|
|
455
|
+
day_index: null,
|
|
456
|
+
sale_type_key_filters: existingDoc?.sale_type_key_filters ?? entries[0]?.sale_type_key_filters ?? [],
|
|
457
|
+
prep_time_entries: sections,
|
|
458
|
+
iteration: existingDoc?.iteration,
|
|
459
|
+
schema_version: existingDoc?.schema_version ?? 1,
|
|
460
|
+
source_watermark: entryWatermark ?? new Date(computedAt),
|
|
461
|
+
computed_at: computedAt,
|
|
462
|
+
createdAt: existingDoc?.createdAt ?? computedAt,
|
|
463
|
+
updatedAt: computedAt,
|
|
464
|
+
};
|
|
465
|
+
if (existingDoc != null && !needsMaterializedPrepTimeEntriesWrite(existingDoc, report)) {
|
|
466
|
+
skippedEntryDocuments.push(existingDoc);
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
if (!addEntryWrite(report))
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
for (const doc of entries) {
|
|
473
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
474
|
+
continue;
|
|
475
|
+
const existingDoc = existingEntriesByScope.get(prepScopeKey(doc)) ?? null;
|
|
476
|
+
if (existingDoc != null && !needsMaterializedPrepTimeEntriesWrite(existingDoc, doc)) {
|
|
477
|
+
skippedEntryDocuments.push(existingDoc);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (!addEntryWrite(doc))
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
return {
|
|
484
|
+
writes,
|
|
485
|
+
entryWrites,
|
|
486
|
+
staleDocuments,
|
|
487
|
+
staleEntryDocuments,
|
|
488
|
+
skippedDocuments,
|
|
489
|
+
skippedEntryDocuments,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IMaterializedTenantPrepTimeEntries } from '../../schemas/types/materialized_tenant_prep_time_entries';
|
|
2
|
+
import { IMaterializedPrepTimeCounters, IMaterializedTenantPrepTimeReport } from '../../schemas/types/materialized_tenant_prep_time_reports';
|
|
3
|
+
import { IPrepTimeOrderSource } from './materialized-prep-time-classification-helpers';
|
|
4
|
+
/**
|
|
5
|
+
* M2 compile - folds one tenant-day of orders into the prep time report + entries
|
|
6
|
+
* documents.
|
|
7
|
+
*
|
|
8
|
+
* Same shape as the discount compile: the day's orders are staged ONCE by the
|
|
9
|
+
* close-day orchestrator and every report compiles from that same staged set, so
|
|
10
|
+
* the reports can never disagree about what was closed.
|
|
11
|
+
*
|
|
12
|
+
* Scopes are the approved M2 set (day + periods, NO hour).
|
|
13
|
+
*/
|
|
14
|
+
export interface ICompileTenantPrepTimeReportsInput {
|
|
15
|
+
tenantId: string;
|
|
16
|
+
brandId: string;
|
|
17
|
+
localDate: string;
|
|
18
|
+
orders: IPrepTimeOrderSource[];
|
|
19
|
+
/**
|
|
20
|
+
* Tenant default prep target in MINUTES, when the tenant has one. Absent in the
|
|
21
|
+
* dev fixtures, so it is an explicit input rather than something the compile
|
|
22
|
+
* invents; items with neither a promise nor a default are counted as NONE.
|
|
23
|
+
*/
|
|
24
|
+
tenantDefaultMinutes?: number | null;
|
|
25
|
+
computedAt?: Date;
|
|
26
|
+
}
|
|
27
|
+
export interface ICompileTenantPrepTimeReportsResult {
|
|
28
|
+
reports: IMaterializedTenantPrepTimeReport[];
|
|
29
|
+
entries: IMaterializedTenantPrepTimeEntries[];
|
|
30
|
+
/** Orders that contributed to at least one document. */
|
|
31
|
+
contributingOrders: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Adds `source` into `target`.
|
|
35
|
+
*
|
|
36
|
+
* NOT the generic recursive numeric add the discount compile uses: `duration.min`
|
|
37
|
+
* and `duration.max` (and `late_items.worst_delta`) are AGGREGATES, not counters.
|
|
38
|
+
* Summing them would turn a 5-minute minimum into a 50-minute one across ten
|
|
39
|
+
* days. Everything additive is summed; the extremes fold with min()/max().
|
|
40
|
+
*/
|
|
41
|
+
export declare function mergeMaterializedPrepTimeCounters(target: IMaterializedPrepTimeCounters, source: IMaterializedPrepTimeCounters): void;
|
|
42
|
+
/**
|
|
43
|
+
* Compiles one tenant-day into the prep time report + entries documents.
|
|
44
|
+
* Returns `null` on malformed input (bad date / tenant / brand); returns EMPTY
|
|
45
|
+
* arrays when the day has nothing tracked at all.
|
|
46
|
+
*/
|
|
47
|
+
export declare function compileTenantPrepTimeReports(input: ICompileTenantPrepTimeReportsInput | null | undefined): ICompileTenantPrepTimeReportsResult | null;
|