@managesome/eposmatic-toolkit 0.4.9 → 0.4.10
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 +448 -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 +286 -0
- package/esm/helpers/materialized-reports/materialized-cash-close-day-helpers.js +396 -0
- package/esm/helpers/materialized-reports/materialized-cash-compile-helpers.js +244 -0
- package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +170 -0
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +426 -0
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +372 -0
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +214 -0
- package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +318 -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 +111 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +88 -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 +476 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +201 -0
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +7 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +189 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +157 -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 +156 -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 +237 -0
- package/esm/helpers/materialized-reports/tenant-payments-comparison-formatter.js +279 -0
- package/esm/helpers/materialized-reports/tenant-prep-time-formatter.js +228 -0
- package/esm/helpers/materialized-reports/tenant-sales-comparison-formatter.js +343 -0
- package/esm/helpers/reporting-contract/index.js +2 -0
- package/esm/helpers/reporting-contract/overview-contract.js +122 -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 +59 -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/schemas/models/deliveries.js +75 -0
- package/esm/schemas/models/index.js +15 -0
- 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/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 +339 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +450 -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 +90 -0
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.js +295 -0
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.d.ts +102 -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 +72 -0
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +251 -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 +84 -0
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +438 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +97 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +385 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +40 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +218 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +52 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +324 -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 +116 -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 +98 -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 +66 -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 +128 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +490 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.d.ts +46 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +208 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +8 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +8 -1
- 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 +161 -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 +159 -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 +243 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.d.ts +75 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.js +286 -0
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +97 -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 +349 -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 +126 -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 +58 -0
- package/lib/helpers/rider-earnings/rider-earnings.js +64 -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 +26 -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/types/materialized-reports-apis.d.ts +297 -1
- package/lib/schemas/models/deliveries.d.ts +54 -0
- package/lib/schemas/models/deliveries.js +75 -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_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/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/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 +196 -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 +152 -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 +241 -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 +141 -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 +270 -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-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 +206 -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,193 @@
|
|
|
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_DISCOUNT_COMPILED_SCOPES = void 0;
|
|
7
|
+
exports.compileTenantDiscountReports = compileTenantDiscountReports;
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
10
|
+
const materialized_discount_accumulator_helpers_1 = require("./materialized-discount-accumulator-helpers");
|
|
11
|
+
const materialized_discount_classification_helpers_1 = require("./materialized-discount-classification-helpers");
|
|
12
|
+
const key_helpers_1 = require("./key-helpers");
|
|
13
|
+
const scope_helpers_1 = require("./scope-helpers");
|
|
14
|
+
const materialized_credit_bills_helpers_1 = require("./materialized-credit-bills-helpers");
|
|
15
|
+
/** Adds every numeric field of `source` into `target`, recursively. */
|
|
16
|
+
function addCounters(target, source) {
|
|
17
|
+
for (const [key, value] of Object.entries(source)) {
|
|
18
|
+
if (typeof value === 'number') {
|
|
19
|
+
const current = target[key];
|
|
20
|
+
target[key] = (typeof current === 'number' ? current : 0) + value;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
|
24
|
+
const nested = (target[key] ?? (target[key] = {}));
|
|
25
|
+
addCounters(nested, value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** A zeroed counter block used as the merge seed (deep-cloned per key). */
|
|
30
|
+
const EMPTY_COUNTERS_SEED = (0, materialized_discount_classification_helpers_1.createEmptyDiscountOrderCounters)();
|
|
31
|
+
/** A fresh, deep-cloned zeroed counter block (each key accumulates into its own). */
|
|
32
|
+
const freshCounters = () => JSON.parse(JSON.stringify(EMPTY_COUNTERS_SEED));
|
|
33
|
+
const foldWatermark = (bucket, value) => {
|
|
34
|
+
if (value == null)
|
|
35
|
+
return;
|
|
36
|
+
const time = new Date(value).getTime();
|
|
37
|
+
if (Number.isNaN(time))
|
|
38
|
+
return;
|
|
39
|
+
if (bucket.watermark == null || time > bucket.watermark.getTime())
|
|
40
|
+
bucket.watermark = new Date(time);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Compiles one tenant-day into the discount report + entries documents.
|
|
44
|
+
* Returns `null` on malformed input (bad date / tenant / brand); returns
|
|
45
|
+
* EMPTY arrays when the day has no discounts at all.
|
|
46
|
+
*/
|
|
47
|
+
function compileTenantDiscountReports(input) {
|
|
48
|
+
if (input == null)
|
|
49
|
+
return null;
|
|
50
|
+
const { tenantId, brandId, localDate, orders, computedAt } = input;
|
|
51
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
52
|
+
return null;
|
|
53
|
+
if (typeof brandId !== 'string' || brandId.length === 0)
|
|
54
|
+
return null;
|
|
55
|
+
if (typeof localDate !== 'string' || localDate.length === 0)
|
|
56
|
+
return null;
|
|
57
|
+
if (!Array.isArray(orders))
|
|
58
|
+
return null;
|
|
59
|
+
const periodFields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
|
|
60
|
+
if (periodFields == null)
|
|
61
|
+
return null;
|
|
62
|
+
const dayIndex = (0, scope_helpers_1.getDayIndexFromLocalDate)(localDate);
|
|
63
|
+
// DERIVED from the report's scope list (as prep / cash / delivery do). This used to be a
|
|
64
|
+
// second, hand-maintained copy of the same four scopes - so widening the report's scopes
|
|
65
|
+
// compiled the new ones nowhere and the documents silently never appeared.
|
|
66
|
+
const periodScopes = MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_REPORT_SCOPES.filter((scope) => scope !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR);
|
|
67
|
+
// scope_field -> key -> bucket
|
|
68
|
+
const byScopeField = new Map();
|
|
69
|
+
const scopeContextOf = new Map();
|
|
70
|
+
const bucketFor = (scope, scopeField, key) => {
|
|
71
|
+
const identity = `${scope}|${scopeField}`;
|
|
72
|
+
let byKey = byScopeField.get(identity);
|
|
73
|
+
if (byKey == null) {
|
|
74
|
+
byKey = new Map();
|
|
75
|
+
byScopeField.set(identity, byKey);
|
|
76
|
+
scopeContextOf.set(identity, scope);
|
|
77
|
+
}
|
|
78
|
+
let bucket = byKey.get(key);
|
|
79
|
+
if (bucket == null) {
|
|
80
|
+
bucket = { counters: freshCounters(), rows: [], watermark: null };
|
|
81
|
+
byKey.set(key, bucket);
|
|
82
|
+
}
|
|
83
|
+
return bucket;
|
|
84
|
+
};
|
|
85
|
+
let contributingOrders = 0;
|
|
86
|
+
for (const order of orders) {
|
|
87
|
+
if (order == null)
|
|
88
|
+
continue;
|
|
89
|
+
// Only orders of this tenant compile into this tenant's documents.
|
|
90
|
+
if (order.tenant_id != null && String(order.tenant_id) !== tenantId)
|
|
91
|
+
continue;
|
|
92
|
+
const hour = (0, materialized_credit_bills_helpers_1.resolveOrderLocalHour)(order, localDate, input.gmtOffset);
|
|
93
|
+
const context = {
|
|
94
|
+
local_date: localDate,
|
|
95
|
+
local_hour: hour,
|
|
96
|
+
local_hour_label: (0, materialized_discount_accumulator_helpers_1.toDiscountHourLabel)(localDate, hour),
|
|
97
|
+
};
|
|
98
|
+
const result = (0, materialized_discount_accumulator_helpers_1.accumulateOrderDiscounts)(order, context);
|
|
99
|
+
if (!result.has_discount)
|
|
100
|
+
continue;
|
|
101
|
+
const key = (0, key_helpers_1.buildMaterializedReportKey)([String(order.order_status ?? ''), String(order.platform ?? '')]);
|
|
102
|
+
// A key with a reserved character (or a missing component) cannot be a Mongo
|
|
103
|
+
// field name — the order is skipped rather than silently mis-keyed.
|
|
104
|
+
if (key == null)
|
|
105
|
+
continue;
|
|
106
|
+
contributingOrders += 1;
|
|
107
|
+
const watermark = order.updatedAt != null ? new Date(order.updatedAt) : null;
|
|
108
|
+
const targets = periodScopes.map((scope) => [scope, periodFields[scope]]);
|
|
109
|
+
const hourField = hour == null ? null : (0, scope_helpers_1.getMaterializedHourScopeField)(localDate, hour);
|
|
110
|
+
if (hourField != null)
|
|
111
|
+
targets.push([MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, hourField]);
|
|
112
|
+
for (const [scope, scopeField] of targets) {
|
|
113
|
+
if (scopeField == null)
|
|
114
|
+
continue;
|
|
115
|
+
const bucket = bucketFor(scope, scopeField, key);
|
|
116
|
+
addCounters(bucket.counters, result.counters);
|
|
117
|
+
bucket.rows.push(...result.entries);
|
|
118
|
+
foldWatermark(bucket, watermark);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const sourceWatermark = new Date(computedAt);
|
|
122
|
+
const reports = [];
|
|
123
|
+
const entriesDocs = [];
|
|
124
|
+
for (const [identity, byKey] of byScopeField) {
|
|
125
|
+
const scope = scopeContextOf.get(identity);
|
|
126
|
+
const [scopeContextText, scopeField] = identity.split('|');
|
|
127
|
+
if (scopeContextText !== scope)
|
|
128
|
+
continue;
|
|
129
|
+
const counters = {};
|
|
130
|
+
const entrySections = {};
|
|
131
|
+
let watermark = null;
|
|
132
|
+
// The read-path rows: the SAME counters, as an array (see the type module —
|
|
133
|
+
// the map is right for the store/formatter, the array is what an aggregation
|
|
134
|
+
// can sum without dynamic-key gymnastics).
|
|
135
|
+
const counterRows = [];
|
|
136
|
+
for (const [key, bucket] of byKey) {
|
|
137
|
+
const bucketCounters = bucket.counters;
|
|
138
|
+
counters[key] = bucketCounters;
|
|
139
|
+
counterRows.push({ key, counters: bucketCounters });
|
|
140
|
+
if (bucket.rows.length > 0)
|
|
141
|
+
entrySections[key] = { rows: bucket.rows };
|
|
142
|
+
if (bucket.watermark != null && (watermark == null || bucket.watermark.getTime() > watermark.getTime())) {
|
|
143
|
+
watermark = bucket.watermark;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const docWatermark = watermark ?? sourceWatermark;
|
|
147
|
+
const isDateScoped = scope === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE || scope === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR;
|
|
148
|
+
reports.push({
|
|
149
|
+
_id: new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
150
|
+
tenant_id: tenantId,
|
|
151
|
+
brand_id: brandId,
|
|
152
|
+
scope_context: scope,
|
|
153
|
+
scope_field: scopeField,
|
|
154
|
+
day_index: isDateScoped ? dayIndex : null,
|
|
155
|
+
sale_type_key_filters: [
|
|
156
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS,
|
|
157
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM,
|
|
158
|
+
],
|
|
159
|
+
discount_counters: Object.keys(counters).length === 0 ? null : counters,
|
|
160
|
+
discount_counter_rows: counterRows.length === 0 ? null : counterRows,
|
|
161
|
+
top_sources: null,
|
|
162
|
+
schema_version: 1,
|
|
163
|
+
source_watermark: docWatermark,
|
|
164
|
+
computed_at: computedAt,
|
|
165
|
+
createdAt: computedAt,
|
|
166
|
+
updatedAt: computedAt,
|
|
167
|
+
});
|
|
168
|
+
// Entries documents exist only when there is at least one row.
|
|
169
|
+
if (Object.keys(entrySections).length > 0) {
|
|
170
|
+
entriesDocs.push({
|
|
171
|
+
_id: new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
172
|
+
tenant_id: tenantId,
|
|
173
|
+
brand_id: brandId,
|
|
174
|
+
scope_context: scope,
|
|
175
|
+
scope_field: scopeField,
|
|
176
|
+
day_index: isDateScoped ? dayIndex : null,
|
|
177
|
+
sale_type_key_filters: [
|
|
178
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS,
|
|
179
|
+
MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM,
|
|
180
|
+
],
|
|
181
|
+
discount_entries: entrySections,
|
|
182
|
+
schema_version: 1,
|
|
183
|
+
source_watermark: docWatermark,
|
|
184
|
+
computed_at: computedAt,
|
|
185
|
+
createdAt: computedAt,
|
|
186
|
+
updatedAt: computedAt,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { reports, entries: entriesDocs, contributingOrders };
|
|
191
|
+
}
|
|
192
|
+
/** Scopes this report materializes — exported for the close plan + tests. */
|
|
193
|
+
exports.MATERIALIZED_DISCOUNT_COMPILED_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_REPORT_SCOPES;
|
package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION, MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IMaterializedTenantHourlyComparisonEntries } from '../../schemas/types/materialized_tenant_hourly_comparison_entries';
|
|
3
|
+
import { IMaterializedTenantHourlyComparisonReport } from '../../schemas/types/materialized_tenant_hourly_comparison_reports';
|
|
4
|
+
/**
|
|
5
|
+
* Hourly Comparison close-day helpers.
|
|
6
|
+
*
|
|
7
|
+
* The report writes HOUR documents only. A close replaces the compiled day's
|
|
8
|
+
* active hours, retires the stored hours no longer backed by activity, and does
|
|
9
|
+
* NOT fold any period documents — the profile read only needs hour buckets, and
|
|
10
|
+
* the period comparison report already owns day/period materialization.
|
|
11
|
+
*
|
|
12
|
+
* The write guards are the Sales Comparison guards: the document shape is the
|
|
13
|
+
* same (same counters, same rows), so the same watermark + content comparison
|
|
14
|
+
* applies. An equal watermark with different content is a correction and must be
|
|
15
|
+
* written.
|
|
16
|
+
*
|
|
17
|
+
* Helpers never throw — invalid input returns `null`.
|
|
18
|
+
*/
|
|
19
|
+
/** One `(scope_context, scope_field)` pair. */
|
|
20
|
+
export interface IMaterializedHourlyComparisonScopeRef {
|
|
21
|
+
scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
22
|
+
scope_field: string;
|
|
23
|
+
}
|
|
24
|
+
/** Every stored hour ref one settled day's plan can touch (24, never 31). */
|
|
25
|
+
export declare function getMaterializedHourlyComparisonScopeRefsForDay(localDate: string): IMaterializedHourlyComparisonScopeRef[] | null;
|
|
26
|
+
/** One plan write: the document plus its iteration history row. */
|
|
27
|
+
export interface IMaterializedHourlyComparisonCloseDayWrite<T> {
|
|
28
|
+
report: T;
|
|
29
|
+
iteration: {
|
|
30
|
+
report_type: string;
|
|
31
|
+
report_id: string;
|
|
32
|
+
iteration: number;
|
|
33
|
+
schema_version: number;
|
|
34
|
+
reason: string;
|
|
35
|
+
snapshot: unknown;
|
|
36
|
+
createdAt: Date;
|
|
37
|
+
updatedAt: Date;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface ITenantHourlyComparisonCloseDayPlan {
|
|
41
|
+
writes: IMaterializedHourlyComparisonCloseDayWrite<IMaterializedTenantHourlyComparisonReport>[];
|
|
42
|
+
entryWrites: IMaterializedHourlyComparisonCloseDayWrite<IMaterializedTenantHourlyComparisonEntries>[];
|
|
43
|
+
/** Stored hour docs no longer backed by settled orders — delete by `_id`. */
|
|
44
|
+
staleDocuments: IMaterializedTenantHourlyComparisonReport[];
|
|
45
|
+
staleEntryDocuments: IMaterializedTenantHourlyComparisonEntries[];
|
|
46
|
+
skippedDocuments: IMaterializedTenantHourlyComparisonReport[];
|
|
47
|
+
skippedEntryDocuments: IMaterializedTenantHourlyComparisonEntries[];
|
|
48
|
+
}
|
|
49
|
+
export interface IBuildTenantHourlyComparisonCloseDayPlanInput {
|
|
50
|
+
tenantId: string;
|
|
51
|
+
/** Required when the day has no compiled document (an emptied day). */
|
|
52
|
+
localDate?: string | null;
|
|
53
|
+
reports: IMaterializedTenantHourlyComparisonReport[];
|
|
54
|
+
entries: IMaterializedTenantHourlyComparisonEntries[];
|
|
55
|
+
/** Stored hour docs of this day (any subset; the plan touches all 24 labels). */
|
|
56
|
+
existing?: IMaterializedTenantHourlyComparisonReport[];
|
|
57
|
+
existingEntries?: IMaterializedTenantHourlyComparisonEntries[];
|
|
58
|
+
reason: string;
|
|
59
|
+
force?: boolean;
|
|
60
|
+
computedAt?: Date;
|
|
61
|
+
}
|
|
62
|
+
export declare function buildTenantHourlyComparisonCloseDayPlan(input: IBuildTenantHourlyComparisonCloseDayPlanInput | null | undefined): ITenantHourlyComparisonCloseDayPlan | null;
|
|
63
|
+
/** Export the schema versions for the model contract test. */
|
|
64
|
+
export { MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION, MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION, };
|
|
@@ -0,0 +1,163 @@
|
|
|
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_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION = void 0;
|
|
7
|
+
exports.getMaterializedHourlyComparisonScopeRefsForDay = getMaterializedHourlyComparisonScopeRefsForDay;
|
|
8
|
+
exports.buildTenantHourlyComparisonCloseDayPlan = buildTenantHourlyComparisonCloseDayPlan;
|
|
9
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
11
|
+
Object.defineProperty(exports, "MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION", { enumerable: true, get: function () { return MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION; } });
|
|
12
|
+
Object.defineProperty(exports, "MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION", { enumerable: true, get: function () { return MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION; } });
|
|
13
|
+
const materialized_tenant_reports_iterations_helpers_1 = require("./materialized-tenant-reports-iterations-helpers");
|
|
14
|
+
const scope_helpers_1 = require("./scope-helpers");
|
|
15
|
+
const materialized_sales_comparison_close_day_helpers_1 = require("./materialized-sales-comparison-close-day-helpers");
|
|
16
|
+
/** Every stored hour ref one settled day's plan can touch (24, never 31). */
|
|
17
|
+
function getMaterializedHourlyComparisonScopeRefsForDay(localDate) {
|
|
18
|
+
if ((0, scope_helpers_1.getDayIndexFromLocalDate)(localDate) == null)
|
|
19
|
+
return null;
|
|
20
|
+
const refs = [];
|
|
21
|
+
for (let hour = 0; hour < 24; hour += 1) {
|
|
22
|
+
const scopeField = (0, scope_helpers_1.getMaterializedHourScopeField)(localDate, hour);
|
|
23
|
+
if (scopeField == null)
|
|
24
|
+
return null;
|
|
25
|
+
refs.push({
|
|
26
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
|
|
27
|
+
scope_field: scopeField,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return refs;
|
|
31
|
+
}
|
|
32
|
+
/** The `'YYYY-MM-DD'` prefix of an hour label, or null when malformed. */
|
|
33
|
+
const localDateOfHourLabel = (scopeField) => {
|
|
34
|
+
if (typeof scopeField !== 'string')
|
|
35
|
+
return null;
|
|
36
|
+
const match = /^(\d{4}-\d{2}-\d{2}) ([01]\d|2[0-3])$/.exec(scopeField);
|
|
37
|
+
return match == null ? null : match[1];
|
|
38
|
+
};
|
|
39
|
+
function buildTenantHourlyComparisonCloseDayPlan(input) {
|
|
40
|
+
if (input == null)
|
|
41
|
+
return null;
|
|
42
|
+
const { tenantId, reason } = input;
|
|
43
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
44
|
+
return null;
|
|
45
|
+
if (typeof reason !== 'string' || reason.length === 0)
|
|
46
|
+
return null;
|
|
47
|
+
const computedAt = input.computedAt ?? new Date();
|
|
48
|
+
if (Number.isNaN(computedAt.getTime()))
|
|
49
|
+
return null;
|
|
50
|
+
const compiledReports = (input.reports ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
51
|
+
const compiledEntries = (input.entries ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
52
|
+
const storedReports = (input.existing ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
53
|
+
const storedEntries = (input.existingEntries ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
54
|
+
const compiledDate = input.localDate ??
|
|
55
|
+
localDateOfHourLabel(compiledReports[0]?.scope_field) ??
|
|
56
|
+
localDateOfHourLabel(storedReports[0]?.scope_field);
|
|
57
|
+
if (compiledDate == null || getMaterializedHourlyComparisonScopeRefsForDay(compiledDate) == null) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const writes = [];
|
|
61
|
+
const entryWrites = [];
|
|
62
|
+
const staleDocuments = [];
|
|
63
|
+
const staleEntryDocuments = [];
|
|
64
|
+
const skippedDocuments = [];
|
|
65
|
+
const skippedEntryDocuments = [];
|
|
66
|
+
const compiledReportsByField = new Map();
|
|
67
|
+
for (const doc of compiledReports) {
|
|
68
|
+
if (localDateOfHourLabel(doc.scope_field) !== compiledDate)
|
|
69
|
+
continue;
|
|
70
|
+
compiledReportsByField.set(String(doc.scope_field), doc);
|
|
71
|
+
}
|
|
72
|
+
const compiledEntriesByField = new Map();
|
|
73
|
+
for (const doc of compiledEntries) {
|
|
74
|
+
if (localDateOfHourLabel(doc.scope_field) !== compiledDate)
|
|
75
|
+
continue;
|
|
76
|
+
compiledEntriesByField.set(String(doc.scope_field), doc);
|
|
77
|
+
}
|
|
78
|
+
const storedReportsByField = new Map();
|
|
79
|
+
for (const doc of storedReports) {
|
|
80
|
+
if (localDateOfHourLabel(doc.scope_field) !== compiledDate)
|
|
81
|
+
continue;
|
|
82
|
+
storedReportsByField.set(String(doc.scope_field), doc);
|
|
83
|
+
}
|
|
84
|
+
const storedEntriesByField = new Map();
|
|
85
|
+
for (const doc of storedEntries) {
|
|
86
|
+
if (localDateOfHourLabel(doc.scope_field) !== compiledDate)
|
|
87
|
+
continue;
|
|
88
|
+
storedEntriesByField.set(String(doc.scope_field), doc);
|
|
89
|
+
}
|
|
90
|
+
const addWrite = (report) => {
|
|
91
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
92
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
93
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_REPORTS,
|
|
94
|
+
reason,
|
|
95
|
+
computedAt,
|
|
96
|
+
});
|
|
97
|
+
if (iteration == null)
|
|
98
|
+
return false;
|
|
99
|
+
writes.push({ report: persisted, iteration: iteration });
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
const addEntryWrite = (report) => {
|
|
103
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
104
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
105
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES,
|
|
106
|
+
reason,
|
|
107
|
+
computedAt,
|
|
108
|
+
});
|
|
109
|
+
if (iteration == null)
|
|
110
|
+
return false;
|
|
111
|
+
entryWrites.push({ report: persisted, iteration: iteration });
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
114
|
+
for (let hour = 0; hour < 24; hour += 1) {
|
|
115
|
+
const scopeField = (0, scope_helpers_1.getMaterializedHourScopeField)(compiledDate, hour);
|
|
116
|
+
if (scopeField == null)
|
|
117
|
+
continue;
|
|
118
|
+
const compiled = compiledReportsByField.get(scopeField);
|
|
119
|
+
const stored = storedReportsByField.get(scopeField);
|
|
120
|
+
if (compiled != null) {
|
|
121
|
+
const next = {
|
|
122
|
+
...compiled,
|
|
123
|
+
_id: stored?._id ?? compiled._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
124
|
+
iteration: Number(stored?.iteration ?? 0) + 1,
|
|
125
|
+
};
|
|
126
|
+
if ((0, materialized_sales_comparison_close_day_helpers_1.needsMaterializedSalesComparisonReportWrite)(stored, next, input.force === true)) {
|
|
127
|
+
addWrite(next);
|
|
128
|
+
}
|
|
129
|
+
else if (stored != null) {
|
|
130
|
+
skippedDocuments.push(stored);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (stored != null) {
|
|
134
|
+
staleDocuments.push(stored);
|
|
135
|
+
}
|
|
136
|
+
const compiledEntry = compiledEntriesByField.get(scopeField);
|
|
137
|
+
const storedEntry = storedEntriesByField.get(scopeField);
|
|
138
|
+
if (compiledEntry != null) {
|
|
139
|
+
const next = {
|
|
140
|
+
...compiledEntry,
|
|
141
|
+
_id: storedEntry?._id ?? compiledEntry._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
142
|
+
iteration: Number(storedEntry?.iteration ?? 0) + 1,
|
|
143
|
+
};
|
|
144
|
+
if ((0, materialized_sales_comparison_close_day_helpers_1.needsMaterializedSalesComparisonEntriesWrite)(storedEntry, next, input.force === true)) {
|
|
145
|
+
addEntryWrite(next);
|
|
146
|
+
}
|
|
147
|
+
else if (storedEntry != null) {
|
|
148
|
+
skippedEntryDocuments.push(storedEntry);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else if (storedEntry != null) {
|
|
152
|
+
staleEntryDocuments.push(storedEntry);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
writes,
|
|
157
|
+
entryWrites,
|
|
158
|
+
staleDocuments,
|
|
159
|
+
staleEntryDocuments,
|
|
160
|
+
skippedDocuments,
|
|
161
|
+
skippedEntryDocuments,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IOrder } from '../../schemas/types/orders';
|
|
2
|
+
import { IMaterializedTenantHourlyComparisonEntries } from '../../schemas/types/materialized_tenant_hourly_comparison_entries';
|
|
3
|
+
import { IMaterializedTenantHourlyComparisonReport } from '../../schemas/types/materialized_tenant_hourly_comparison_reports';
|
|
4
|
+
/**
|
|
5
|
+
* Hourly Comparison compile — one settled tenant-day of orders into the day's
|
|
6
|
+
* 24 possible HOUR documents (`materialized_tenant_hourly_comparison_reports`)
|
|
7
|
+
* and their entries documents.
|
|
8
|
+
*
|
|
9
|
+
* This is the storage foundation for BOTH presentation options in the concept
|
|
10
|
+
* (§11): a one-profile pair and a per-day × hour matrix read the SAME hour
|
|
11
|
+
* documents. The read surface does not change what is stored.
|
|
12
|
+
*
|
|
13
|
+
* ## Anchor
|
|
14
|
+
*
|
|
15
|
+
* `order_settled_at` → the tenant-local settled DAY and HOUR. The punch day/hour
|
|
16
|
+
* is never used. Orders whose settled day is not the compiled day are skipped;
|
|
17
|
+
* orders that were never settled contribute nothing.
|
|
18
|
+
*
|
|
19
|
+
* ## Only ACTIVE hours are written
|
|
20
|
+
*
|
|
21
|
+
* An hour with no settled order produces no document; the close-day plan retires
|
|
22
|
+
* a stored hour document that is no longer backed by activity. This mirrors the
|
|
23
|
+
* overview's hour writes.
|
|
24
|
+
*
|
|
25
|
+
* Pure and total: `null` on malformed input, never a throw.
|
|
26
|
+
*/
|
|
27
|
+
export interface ICompileTenantHourlyComparisonReportsInput {
|
|
28
|
+
tenantId: string;
|
|
29
|
+
brandId: string;
|
|
30
|
+
/** The compiled settled day, tenant-local `'YYYY-MM-DD'`. */
|
|
31
|
+
localDate: string;
|
|
32
|
+
orders: IOrder[];
|
|
33
|
+
/** Tenant GST offset in hours (`+5`) used for the settled day AND hour. */
|
|
34
|
+
gmtOffset?: number;
|
|
35
|
+
computedAt: Date;
|
|
36
|
+
}
|
|
37
|
+
export interface ICompileTenantHourlyComparisonReportsResult {
|
|
38
|
+
reports: IMaterializedTenantHourlyComparisonReport[];
|
|
39
|
+
entries: IMaterializedTenantHourlyComparisonEntries[];
|
|
40
|
+
contributingOrders: number;
|
|
41
|
+
skippedUnsettledOrders: number;
|
|
42
|
+
skippedForeignOrders: number;
|
|
43
|
+
skippedUnkeyableOrders: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The tenant-local HOUR (0–23) of an order's settlement instant.
|
|
47
|
+
*
|
|
48
|
+
* Mirrors `getSalesComparisonSettledLocalDate` (same instant shift), so the day
|
|
49
|
+
* and the hour can never disagree.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getHourlyComparisonSettledLocalHour(order: Pick<IOrder, 'order_settled_at'> | null | undefined, gmtOffset?: number): number | null;
|
|
52
|
+
/** `'YYYY-MM-DD HH'` of the settled day + hour. */
|
|
53
|
+
export declare function getHourlyComparisonScopeField(localDate: string, hour: number): string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Compiles one settled tenant-day.
|
|
56
|
+
*
|
|
57
|
+
* Returns EMPTY arrays (never null) when the day has no settled orders: an
|
|
58
|
+
* emptied day produces no hour document, and the close-day plan retires the
|
|
59
|
+
* stored ones.
|
|
60
|
+
*/
|
|
61
|
+
export declare function compileTenantHourlyComparisonReports(input: ICompileTenantHourlyComparisonReportsInput | null | undefined): ICompileTenantHourlyComparisonReportsResult | null;
|