@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,603 @@
|
|
|
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.isMaterializedSalesComparisonDayScope = exports.MATERIALIZED_SALES_COMPARISON_PERIOD_SCOPES = void 0;
|
|
7
|
+
exports.getMaterializedSalesComparisonScopeRefsForDay = getMaterializedSalesComparisonScopeRefsForDay;
|
|
8
|
+
exports.getMaterializedSalesComparisonPeriodDayKeys = getMaterializedSalesComparisonPeriodDayKeys;
|
|
9
|
+
exports.foldMaterializedSalesComparisonPeriodCounters = foldMaterializedSalesComparisonPeriodCounters;
|
|
10
|
+
exports.mergeMaterializedSalesComparisonEntrySections = mergeMaterializedSalesComparisonEntrySections;
|
|
11
|
+
exports.foldMaterializedSalesComparisonPeriodEntries = foldMaterializedSalesComparisonPeriodEntries;
|
|
12
|
+
exports.needsMaterializedSalesComparisonReportWrite = needsMaterializedSalesComparisonReportWrite;
|
|
13
|
+
exports.needsMaterializedSalesComparisonEntriesWrite = needsMaterializedSalesComparisonEntriesWrite;
|
|
14
|
+
exports.buildTenantSalesComparisonCloseDayPlan = buildTenantSalesComparisonCloseDayPlan;
|
|
15
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
16
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
17
|
+
const materialized_tenant_reports_iterations_helpers_1 = require("./materialized-tenant-reports-iterations-helpers");
|
|
18
|
+
const scope_helpers_1 = require("./scope-helpers");
|
|
19
|
+
const materialized_sales_comparison_accumulator_helpers_1 = require("./materialized-sales-comparison-accumulator-helpers");
|
|
20
|
+
/**
|
|
21
|
+
* Sales Comparison close-day helpers.
|
|
22
|
+
*
|
|
23
|
+
* ## Period counters are RE-FOLDED, never patched
|
|
24
|
+
*
|
|
25
|
+
* The discount report accumulates period deltas forward and subtracts a day
|
|
26
|
+
* delta on re-close. That design produced defects 4–6 in the handoff (emptied
|
|
27
|
+
* days, corrections that REMOVE rows, and a missing period document rebuilt
|
|
28
|
+
* from one day). This report mirrors CASH instead: every touched period is
|
|
29
|
+
* rebuilt from its whole day set, so a correction cannot leave residue and a
|
|
30
|
+
* missing period document is rebuilt from the days still on hand.
|
|
31
|
+
*
|
|
32
|
+
* ## The watermark comes from the FOLDED DAYS
|
|
33
|
+
*
|
|
34
|
+
* A folded document that inherited the STORED document watermark would look
|
|
35
|
+
* unchanged to the write guard, so the write would be skipped forever and the
|
|
36
|
+
* period would freeze at its first closed day. This bug shipped once in the
|
|
37
|
+
* prep time report; it is designed out here from the start.
|
|
38
|
+
*
|
|
39
|
+
* ## Close-day fetch contract — UNDER-FETCHING IS SILENT
|
|
40
|
+
*
|
|
41
|
+
* `existing` / `existingEntries` must contain:
|
|
42
|
+
* 1. the closing day's own range document (and the period documents it rolls
|
|
43
|
+
* into), and
|
|
44
|
+
* 2. **every stored `localDate` document inside those periods** — the sibling
|
|
45
|
+
* days are the fold's input. `getMaterializedSalesComparisonPeriodDayKeys`
|
|
46
|
+
* returns exactly the day keys a caller must fetch (`scope_field: { $in }`).
|
|
47
|
+
*
|
|
48
|
+
* Passing only (1) still handles emptied days and corrections on the closing
|
|
49
|
+
* day, but a period document is then rebuilt from the closing day alone and
|
|
50
|
+
* every sibling day silently disappears. That is why (2) is part of the
|
|
51
|
+
* contract, exactly like the discount entries contract.
|
|
52
|
+
*
|
|
53
|
+
* Helpers never throw — invalid input returns `null`.
|
|
54
|
+
*/
|
|
55
|
+
/** Period scopes this report materializes (everything except the day scope). */
|
|
56
|
+
exports.MATERIALIZED_SALES_COMPARISON_PERIOD_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_SALES_COMPARISON_REPORT_SCOPES.filter((scope) => scope !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE);
|
|
57
|
+
/** True when the scope is the plain day scope. */
|
|
58
|
+
const isMaterializedSalesComparisonDayScope = (scopeContext) => String(scopeContext) === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
59
|
+
exports.isMaterializedSalesComparisonDayScope = isMaterializedSalesComparisonDayScope;
|
|
60
|
+
const scopeKey = (doc) => String(doc.scope_context) + '|' + String(doc.scope_field);
|
|
61
|
+
/**
|
|
62
|
+
* The stored scope references one settled day's plan needs: its `localDate`
|
|
63
|
+
* document plus the five period documents it rolls into. NO hour scope — this
|
|
64
|
+
* report has none.
|
|
65
|
+
*/
|
|
66
|
+
function getMaterializedSalesComparisonScopeRefsForDay(localDate) {
|
|
67
|
+
const periodFields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
|
|
68
|
+
if (periodFields == null)
|
|
69
|
+
return null;
|
|
70
|
+
const refs = [
|
|
71
|
+
{
|
|
72
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
73
|
+
scope_field: localDate,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
for (const scope of exports.MATERIALIZED_SALES_COMPARISON_PERIOD_SCOPES) {
|
|
77
|
+
const field = periodFields[scope];
|
|
78
|
+
if (field == null || field === '')
|
|
79
|
+
return null;
|
|
80
|
+
refs.push({ scope_context: scope, scope_field: field });
|
|
81
|
+
}
|
|
82
|
+
return refs;
|
|
83
|
+
}
|
|
84
|
+
/* ------------------------------------------------------------------------ */
|
|
85
|
+
/* Period day-key ranges */
|
|
86
|
+
/* ------------------------------------------------------------------------ */
|
|
87
|
+
const KEY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
88
|
+
const keyToUtcDate = (key) => {
|
|
89
|
+
if (typeof key !== 'string' || !KEY_PATTERN.test(key))
|
|
90
|
+
return null;
|
|
91
|
+
const [year, month, day] = key.split('-').map(Number);
|
|
92
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
93
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return date;
|
|
97
|
+
};
|
|
98
|
+
const utcDateToKey = (date) => date.toISOString().slice(0, 10);
|
|
99
|
+
const addUtcDays = (date, amount) => new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + amount));
|
|
100
|
+
/** Inclusive [start, end] day keys of one period scope value. */
|
|
101
|
+
function periodDayRange(periodScope, periodField) {
|
|
102
|
+
switch (periodScope) {
|
|
103
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK: {
|
|
104
|
+
const startDate = keyToUtcDate(periodField);
|
|
105
|
+
if (startDate == null)
|
|
106
|
+
return null;
|
|
107
|
+
return { start: periodField, end: utcDateToKey(addUtcDays(startDate, 6)) };
|
|
108
|
+
}
|
|
109
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH: {
|
|
110
|
+
const match = /^(\d{4})-(\d{2})$/.exec(periodField);
|
|
111
|
+
if (match == null)
|
|
112
|
+
return null;
|
|
113
|
+
const year = Number(match[1]);
|
|
114
|
+
const month = Number(match[2]);
|
|
115
|
+
if (month < 1 || month > 12)
|
|
116
|
+
return null;
|
|
117
|
+
const first = new Date(Date.UTC(year, month - 1, 1));
|
|
118
|
+
const last = new Date(Date.UTC(year, month, 0));
|
|
119
|
+
return { start: utcDateToKey(first), end: utcDateToKey(last) };
|
|
120
|
+
}
|
|
121
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_QUARTER: {
|
|
122
|
+
const match = /^(\d{4})-Q([1-4])$/.exec(periodField);
|
|
123
|
+
if (match == null)
|
|
124
|
+
return null;
|
|
125
|
+
const year = Number(match[1]);
|
|
126
|
+
const quarter = Number(match[2]);
|
|
127
|
+
const first = new Date(Date.UTC(year, (quarter - 1) * 3, 1));
|
|
128
|
+
const last = new Date(Date.UTC(year, quarter * 3, 0));
|
|
129
|
+
return { start: utcDateToKey(first), end: utcDateToKey(last) };
|
|
130
|
+
}
|
|
131
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_SEMESTER: {
|
|
132
|
+
const match = /^(\d{4})-S([12])$/.exec(periodField);
|
|
133
|
+
if (match == null)
|
|
134
|
+
return null;
|
|
135
|
+
const year = Number(match[1]);
|
|
136
|
+
const semester = Number(match[2]);
|
|
137
|
+
const first = new Date(Date.UTC(year, semester === 1 ? 0 : 6, 1));
|
|
138
|
+
const last = new Date(Date.UTC(year, semester === 1 ? 6 : 12, 0));
|
|
139
|
+
return { start: utcDateToKey(first), end: utcDateToKey(last) };
|
|
140
|
+
}
|
|
141
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR: {
|
|
142
|
+
const match = /^(\d{4})$/.exec(periodField);
|
|
143
|
+
if (match == null)
|
|
144
|
+
return null;
|
|
145
|
+
const year = Number(match[1]);
|
|
146
|
+
return { start: `${year}-01-01`, end: `${year}-12-31` };
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Every `localDate` scope value a caller must fetch to re-fold the periods one
|
|
154
|
+
* settled day touches — the union of the day's week/month/quarter/semester/year
|
|
155
|
+
* ranges (≤ 366 keys). Sorted, deduped.
|
|
156
|
+
*/
|
|
157
|
+
function getMaterializedSalesComparisonPeriodDayKeys(localDate) {
|
|
158
|
+
const periodFields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
|
|
159
|
+
if (periodFields == null)
|
|
160
|
+
return null;
|
|
161
|
+
const keys = new Set();
|
|
162
|
+
for (const scope of exports.MATERIALIZED_SALES_COMPARISON_PERIOD_SCOPES) {
|
|
163
|
+
const field = periodFields[scope];
|
|
164
|
+
if (field == null || field === '')
|
|
165
|
+
return null;
|
|
166
|
+
const range = periodDayRange(scope, field);
|
|
167
|
+
if (range == null)
|
|
168
|
+
return null;
|
|
169
|
+
const start = keyToUtcDate(range.start);
|
|
170
|
+
const end = keyToUtcDate(range.end);
|
|
171
|
+
if (start == null || end == null)
|
|
172
|
+
return null;
|
|
173
|
+
for (let cursor = start; cursor.getTime() <= end.getTime(); cursor = addUtcDays(cursor, 1)) {
|
|
174
|
+
keys.add(utcDateToKey(cursor));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return [...keys].sort();
|
|
178
|
+
}
|
|
179
|
+
/* ------------------------------------------------------------------------ */
|
|
180
|
+
/* Folds */
|
|
181
|
+
/* ------------------------------------------------------------------------ */
|
|
182
|
+
/** Highest `source_watermark` across the day documents a fold actually used. */
|
|
183
|
+
function watermarkOfFoldedDays(dayDocuments, fallback) {
|
|
184
|
+
let latest = fallback.getTime();
|
|
185
|
+
for (const doc of dayDocuments ?? []) {
|
|
186
|
+
const time = new Date(doc?.source_watermark ?? 0).getTime();
|
|
187
|
+
if (!Number.isNaN(time) && time > latest)
|
|
188
|
+
latest = time;
|
|
189
|
+
}
|
|
190
|
+
return new Date(latest);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Folds the counters of every DAY document that belongs to one period scope.
|
|
194
|
+
* Pure; the caller supplies the whole day set.
|
|
195
|
+
*/
|
|
196
|
+
function foldMaterializedSalesComparisonPeriodCounters(input) {
|
|
197
|
+
const folded = {};
|
|
198
|
+
for (const dayDocument of input?.dayDocuments ?? []) {
|
|
199
|
+
if (!(0, exports.isMaterializedSalesComparisonDayScope)(String(dayDocument?.scope_context)))
|
|
200
|
+
continue;
|
|
201
|
+
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(String(dayDocument.scope_field));
|
|
202
|
+
if (fields == null)
|
|
203
|
+
continue;
|
|
204
|
+
if (fields[String(input.periodScope)] !== input.periodScopeField)
|
|
205
|
+
continue;
|
|
206
|
+
for (const [key, block] of Object.entries(dayDocument.sales_counters ?? {})) {
|
|
207
|
+
const target = folded[key] ?? (0, materialized_sales_comparison_accumulator_helpers_1.createEmptySalesComparisonCounters)();
|
|
208
|
+
(0, materialized_sales_comparison_accumulator_helpers_1.addSalesComparisonCounters)(target, block);
|
|
209
|
+
folded[key] = target;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return folded;
|
|
213
|
+
}
|
|
214
|
+
/** Newest-first row order, then stable id order. */
|
|
215
|
+
function compareRowsDescending(a, b) {
|
|
216
|
+
const byTime = new Date(b.time).getTime() - new Date(a.time).getTime();
|
|
217
|
+
if (byTime !== 0)
|
|
218
|
+
return byTime;
|
|
219
|
+
// Same instant: `order_id` ASC, matching the page cursor.
|
|
220
|
+
return a.order_id < b.order_id ? -1 : a.order_id > b.order_id ? 1 : 0;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Merges two entry sections, de-duplicating rows by `order_id`.
|
|
224
|
+
*
|
|
225
|
+
* A row belongs to exactly one settled day, so the same order id twice means
|
|
226
|
+
* the fold saw it twice; money and rows must never double-count.
|
|
227
|
+
*/
|
|
228
|
+
function mergeMaterializedSalesComparisonEntrySections(target, source) {
|
|
229
|
+
const rowsByKey = new Map();
|
|
230
|
+
const seenByKey = new Map();
|
|
231
|
+
const absorb = (input) => {
|
|
232
|
+
if (input == null)
|
|
233
|
+
return;
|
|
234
|
+
for (const [key, section] of Object.entries(input)) {
|
|
235
|
+
const rows = rowsByKey.get(key) ?? [];
|
|
236
|
+
const seen = seenByKey.get(key) ?? new Set();
|
|
237
|
+
for (const row of section?.rows ?? []) {
|
|
238
|
+
const identity = String(row.order_id ?? '');
|
|
239
|
+
if (identity !== '') {
|
|
240
|
+
if (seen.has(identity))
|
|
241
|
+
continue;
|
|
242
|
+
seen.add(identity);
|
|
243
|
+
}
|
|
244
|
+
rows.push(row);
|
|
245
|
+
}
|
|
246
|
+
rowsByKey.set(key, rows);
|
|
247
|
+
seenByKey.set(key, seen);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
absorb(target);
|
|
251
|
+
absorb(source);
|
|
252
|
+
const out = {};
|
|
253
|
+
for (const [key, rows] of rowsByKey) {
|
|
254
|
+
rows.sort(compareRowsDescending);
|
|
255
|
+
out[key] = { rows };
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Folds the itemized rows of every DAY entry document that belongs to one
|
|
261
|
+
* period scope, de-duplicated by `order_id`.
|
|
262
|
+
*/
|
|
263
|
+
function foldMaterializedSalesComparisonPeriodEntries(input) {
|
|
264
|
+
let merged = {};
|
|
265
|
+
for (const dayDocument of input?.dayDocuments ?? []) {
|
|
266
|
+
if (!(0, exports.isMaterializedSalesComparisonDayScope)(String(dayDocument?.scope_context)))
|
|
267
|
+
continue;
|
|
268
|
+
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(String(dayDocument.scope_field));
|
|
269
|
+
if (fields == null)
|
|
270
|
+
continue;
|
|
271
|
+
if (fields[String(input.periodScope)] !== input.periodScopeField)
|
|
272
|
+
continue;
|
|
273
|
+
merged = mergeMaterializedSalesComparisonEntrySections(merged, dayDocument.sales_entries ?? null);
|
|
274
|
+
}
|
|
275
|
+
return merged;
|
|
276
|
+
}
|
|
277
|
+
/* ------------------------------------------------------------------------ */
|
|
278
|
+
/* Write guards */
|
|
279
|
+
/* ------------------------------------------------------------------------ */
|
|
280
|
+
/**
|
|
281
|
+
* Canonical JSON of a counter/row tree (object keys sorted) so a content
|
|
282
|
+
* comparison cannot be fooled by insertion order — e.g. a document reloaded
|
|
283
|
+
* from Mongo with its map keys in a different order.
|
|
284
|
+
*/
|
|
285
|
+
function stableJson(value) {
|
|
286
|
+
const canonicalize = (input) => {
|
|
287
|
+
if (Array.isArray(input))
|
|
288
|
+
return input.map(canonicalize);
|
|
289
|
+
if (input != null && typeof input === 'object') {
|
|
290
|
+
const out = {};
|
|
291
|
+
for (const key of Object.keys(input).sort()) {
|
|
292
|
+
out[key] = canonicalize(input[key]);
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
return input;
|
|
297
|
+
};
|
|
298
|
+
return JSON.stringify(canonicalize(value ?? null));
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Write guard: does the stored document need a structural write?
|
|
302
|
+
*
|
|
303
|
+
* - `force` bypasses the guard (repairs / schema rollouts);
|
|
304
|
+
* - a schema-version or key-grammar change forces the write;
|
|
305
|
+
* - a NEWER watermark forces the write;
|
|
306
|
+
* - an OLDER watermark is a stale replay and is skipped;
|
|
307
|
+
* - an EQUAL watermark still writes when the CONTENT differs. This is the
|
|
308
|
+
* correction case: removing an order can leave the day's max `updatedAt`
|
|
309
|
+
* unchanged, and a watermark-only guard would then leave the period at its
|
|
310
|
+
* pre-correction figures forever.
|
|
311
|
+
*/
|
|
312
|
+
function needsMaterializedSalesComparisonReportWrite(existing, incoming, force = false) {
|
|
313
|
+
if (existing == null || incoming == null)
|
|
314
|
+
return true;
|
|
315
|
+
if (force)
|
|
316
|
+
return true;
|
|
317
|
+
if (Number(existing.schema_version) !== Number(incoming.schema_version) ||
|
|
318
|
+
Number.isNaN(Number(incoming.schema_version))) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
if ((existing.sale_type_key_filters ?? []).join(':') !== (incoming.sale_type_key_filters ?? []).join(':')) {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
const stored = new Date(existing.source_watermark ?? 0).getTime();
|
|
325
|
+
const next = new Date(incoming.source_watermark ?? 0).getTime();
|
|
326
|
+
if (Number.isNaN(stored) || Number.isNaN(next))
|
|
327
|
+
return true;
|
|
328
|
+
if (next > stored)
|
|
329
|
+
return true;
|
|
330
|
+
if (next < stored)
|
|
331
|
+
return false;
|
|
332
|
+
return stableJson(existing.sales_counters) !== stableJson(incoming.sales_counters);
|
|
333
|
+
}
|
|
334
|
+
/** True when the stored entry document already carries these exact rows. */
|
|
335
|
+
function needsMaterializedSalesComparisonEntriesWrite(existing, incoming, force = false) {
|
|
336
|
+
if (existing == null || incoming == null)
|
|
337
|
+
return true;
|
|
338
|
+
if (force)
|
|
339
|
+
return true;
|
|
340
|
+
if (Number(existing.schema_version) !== Number(incoming.schema_version) ||
|
|
341
|
+
Number.isNaN(Number(incoming.schema_version))) {
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
if ((existing.sale_type_key_filters ?? []).join(':') !== (incoming.sale_type_key_filters ?? []).join(':')) {
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
const stored = new Date(existing.source_watermark ?? 0).getTime();
|
|
348
|
+
const next = new Date(incoming.source_watermark ?? 0).getTime();
|
|
349
|
+
if (Number.isNaN(stored) || Number.isNaN(next))
|
|
350
|
+
return true;
|
|
351
|
+
if (next > stored)
|
|
352
|
+
return true;
|
|
353
|
+
if (next < stored)
|
|
354
|
+
return false;
|
|
355
|
+
return stableJson(existing.sales_entries) !== stableJson(incoming.sales_entries);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Builds the close-day plan for ONE settled tenant-day.
|
|
359
|
+
*
|
|
360
|
+
* The DAY scope is written from the compile. Every touched PERIOD scope is
|
|
361
|
+
* re-folded from its whole day set (stored siblings + the freshly compiled
|
|
362
|
+
* day). Returns `null` on malformed input.
|
|
363
|
+
*/
|
|
364
|
+
function buildTenantSalesComparisonCloseDayPlan(input) {
|
|
365
|
+
if (input == null)
|
|
366
|
+
return null;
|
|
367
|
+
const { tenantId, reason } = input;
|
|
368
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
369
|
+
return null;
|
|
370
|
+
if (typeof reason !== 'string' || reason.length === 0)
|
|
371
|
+
return null;
|
|
372
|
+
const computedAt = input.computedAt ?? new Date();
|
|
373
|
+
if (Number.isNaN(computedAt.getTime()))
|
|
374
|
+
return null;
|
|
375
|
+
const compiledReports = (input.reports ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
376
|
+
const compiledEntries = (input.entries ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
377
|
+
const storedReports = (input.existing ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
378
|
+
const storedEntries = (input.existingEntries ?? []).filter((doc) => doc != null && String(doc.tenant_id) === tenantId);
|
|
379
|
+
const compiledDateDoc = compiledReports.find((doc) => (0, exports.isMaterializedSalesComparisonDayScope)(String(doc.scope_context)));
|
|
380
|
+
const compiledDateEntries = compiledEntries.find((doc) => (0, exports.isMaterializedSalesComparisonDayScope)(String(doc.scope_context)));
|
|
381
|
+
const localDate = input.localDate ?? compiledDateDoc?.scope_field ?? null;
|
|
382
|
+
if (localDate == null || localDate === '' || getMaterializedSalesComparisonScopeRefsForDay(localDate) == null) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
const writes = [];
|
|
386
|
+
const entryWrites = [];
|
|
387
|
+
const staleDocuments = [];
|
|
388
|
+
const staleEntryDocuments = [];
|
|
389
|
+
const skippedDocuments = [];
|
|
390
|
+
const skippedEntryDocuments = [];
|
|
391
|
+
const createdPeriodDocuments = [];
|
|
392
|
+
const storedReportsByScope = new Map();
|
|
393
|
+
for (const doc of storedReports)
|
|
394
|
+
storedReportsByScope.set(scopeKey(doc), doc);
|
|
395
|
+
const storedEntriesByScope = new Map();
|
|
396
|
+
for (const doc of storedEntries)
|
|
397
|
+
storedEntriesByScope.set(scopeKey(doc), doc);
|
|
398
|
+
const addWrite = (report) => {
|
|
399
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
400
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
401
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_REPORTS,
|
|
402
|
+
reason,
|
|
403
|
+
computedAt,
|
|
404
|
+
});
|
|
405
|
+
if (iteration == null)
|
|
406
|
+
return false;
|
|
407
|
+
writes.push({ report: persisted, iteration: iteration });
|
|
408
|
+
return true;
|
|
409
|
+
};
|
|
410
|
+
const addEntryWrite = (report) => {
|
|
411
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
412
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
413
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES,
|
|
414
|
+
reason,
|
|
415
|
+
computedAt,
|
|
416
|
+
});
|
|
417
|
+
if (iteration == null)
|
|
418
|
+
return false;
|
|
419
|
+
entryWrites.push({ report: persisted, iteration: iteration });
|
|
420
|
+
return true;
|
|
421
|
+
};
|
|
422
|
+
const storedDateDoc = storedReportsByScope.get(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE + '|' + localDate);
|
|
423
|
+
const storedDateEntries = storedEntriesByScope.get(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE + '|' + localDate);
|
|
424
|
+
// ---- the DAY scope, straight from the compile ----
|
|
425
|
+
let effectiveDayDoc = null;
|
|
426
|
+
if (compiledDateDoc != null) {
|
|
427
|
+
const next = {
|
|
428
|
+
...compiledDateDoc,
|
|
429
|
+
_id: storedDateDoc?._id ?? compiledDateDoc._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
430
|
+
iteration: Number(storedDateDoc?.iteration ?? 0) + 1,
|
|
431
|
+
};
|
|
432
|
+
if (needsMaterializedSalesComparisonReportWrite(storedDateDoc, next, input.force === true)) {
|
|
433
|
+
if (addWrite(next))
|
|
434
|
+
effectiveDayDoc = next;
|
|
435
|
+
}
|
|
436
|
+
else if (storedDateDoc != null) {
|
|
437
|
+
skippedDocuments.push(storedDateDoc);
|
|
438
|
+
effectiveDayDoc = storedDateDoc;
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
effectiveDayDoc = next;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
else if (storedDateDoc != null) {
|
|
445
|
+
// A day that no longer has settled orders is retired; the period re-fold
|
|
446
|
+
// below removes its contribution.
|
|
447
|
+
staleDocuments.push(storedDateDoc);
|
|
448
|
+
}
|
|
449
|
+
let effectiveDayEntries = null;
|
|
450
|
+
if (compiledDateEntries != null) {
|
|
451
|
+
const next = {
|
|
452
|
+
...compiledDateEntries,
|
|
453
|
+
_id: storedDateEntries?._id ?? compiledDateEntries._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
454
|
+
iteration: Number(storedDateEntries?.iteration ?? 0) + 1,
|
|
455
|
+
};
|
|
456
|
+
if (needsMaterializedSalesComparisonEntriesWrite(storedDateEntries, next, input.force === true)) {
|
|
457
|
+
if (addEntryWrite(next))
|
|
458
|
+
effectiveDayEntries = next;
|
|
459
|
+
}
|
|
460
|
+
else if (storedDateEntries != null) {
|
|
461
|
+
skippedEntryDocuments.push(storedDateEntries);
|
|
462
|
+
effectiveDayEntries = storedDateEntries;
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
effectiveDayEntries = next;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else if (storedDateEntries != null) {
|
|
469
|
+
staleEntryDocuments.push(storedDateEntries);
|
|
470
|
+
}
|
|
471
|
+
// ---- the fold's day set: every OTHER stored day + this compiled day ----
|
|
472
|
+
const nextDayDocs = storedReports.filter((doc) => (0, exports.isMaterializedSalesComparisonDayScope)(String(doc.scope_context)) && String(doc.scope_field) !== localDate);
|
|
473
|
+
if (effectiveDayDoc != null)
|
|
474
|
+
nextDayDocs.push(effectiveDayDoc);
|
|
475
|
+
const nextDayEntryDocs = storedEntries.filter((doc) => (0, exports.isMaterializedSalesComparisonDayScope)(String(doc.scope_context)) && String(doc.scope_field) !== localDate);
|
|
476
|
+
if (effectiveDayEntries != null)
|
|
477
|
+
nextDayEntryDocs.push(effectiveDayEntries);
|
|
478
|
+
// ---- touched periods (the closing day's; one day cannot touch others) ----
|
|
479
|
+
const periodFields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
|
|
480
|
+
if (periodFields == null)
|
|
481
|
+
return null;
|
|
482
|
+
const touchedPeriods = [];
|
|
483
|
+
for (const scope of exports.MATERIALIZED_SALES_COMPARISON_PERIOD_SCOPES) {
|
|
484
|
+
const field = periodFields[scope];
|
|
485
|
+
if (field == null || field === '')
|
|
486
|
+
return null;
|
|
487
|
+
touchedPeriods.push({ scope_context: scope, scope_field: field });
|
|
488
|
+
}
|
|
489
|
+
for (const period of touchedPeriods) {
|
|
490
|
+
const key = scopeKey(period);
|
|
491
|
+
const existing = storedReportsByScope.get(key);
|
|
492
|
+
const folded = foldMaterializedSalesComparisonPeriodCounters({
|
|
493
|
+
periodScope: period.scope_context,
|
|
494
|
+
periodScopeField: period.scope_field,
|
|
495
|
+
dayDocuments: nextDayDocs,
|
|
496
|
+
});
|
|
497
|
+
const keys = Object.keys(folded).sort();
|
|
498
|
+
if (keys.length === 0) {
|
|
499
|
+
if (existing != null && !staleDocuments.includes(existing)) {
|
|
500
|
+
staleDocuments.push(existing);
|
|
501
|
+
}
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
const salesCounters = {};
|
|
505
|
+
const counterRows = [];
|
|
506
|
+
for (const counterKey of keys) {
|
|
507
|
+
salesCounters[counterKey] = folded[counterKey];
|
|
508
|
+
counterRows.push({ key: counterKey, counters: folded[counterKey] });
|
|
509
|
+
}
|
|
510
|
+
const contributingDays = nextDayDocs.filter((doc) => {
|
|
511
|
+
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(String(doc.scope_field));
|
|
512
|
+
return fields != null && fields[period.scope_context] === period.scope_field;
|
|
513
|
+
});
|
|
514
|
+
const report = {
|
|
515
|
+
_id: existing?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
516
|
+
tenant_id: tenantId,
|
|
517
|
+
brand_id: existing?.brand_id ?? effectiveDayDoc?.brand_id ?? compiledDateDoc?.brand_id ?? '',
|
|
518
|
+
scope_context: period.scope_context,
|
|
519
|
+
scope_field: period.scope_field,
|
|
520
|
+
day_index: null,
|
|
521
|
+
sale_type_key_filters: existing?.sale_type_key_filters ?? [...MATERIALIZED_REPORTS_1.SALES_COMPARISON_KEY_FILTERS],
|
|
522
|
+
sales_counters: salesCounters,
|
|
523
|
+
sales_counter_rows: counterRows,
|
|
524
|
+
iteration: existing?.iteration,
|
|
525
|
+
schema_version: existing?.schema_version ?? MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_SCHEMA_VERSION,
|
|
526
|
+
// FROM THE FOLDED DAYS - never the stored watermark, or the write would
|
|
527
|
+
// be skipped forever and the period would freeze at its first closed day.
|
|
528
|
+
source_watermark: watermarkOfFoldedDays(contributingDays, existing?.source_watermark ?? computedAt),
|
|
529
|
+
computed_at: computedAt,
|
|
530
|
+
createdAt: existing?.createdAt ?? computedAt,
|
|
531
|
+
updatedAt: computedAt,
|
|
532
|
+
};
|
|
533
|
+
const next = {
|
|
534
|
+
...report,
|
|
535
|
+
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
536
|
+
};
|
|
537
|
+
if (needsMaterializedSalesComparisonReportWrite(existing, next, input.force === true)) {
|
|
538
|
+
if (addWrite(next) && existing == null) {
|
|
539
|
+
createdPeriodDocuments.push({
|
|
540
|
+
scope_context: period.scope_context,
|
|
541
|
+
scope_field: period.scope_field,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
else if (existing != null) {
|
|
546
|
+
skippedDocuments.push(existing);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
for (const period of touchedPeriods) {
|
|
550
|
+
const key = scopeKey(period);
|
|
551
|
+
const existing = storedEntriesByScope.get(key);
|
|
552
|
+
const sections = foldMaterializedSalesComparisonPeriodEntries({
|
|
553
|
+
periodScope: period.scope_context,
|
|
554
|
+
periodScopeField: period.scope_field,
|
|
555
|
+
dayDocuments: nextDayEntryDocs,
|
|
556
|
+
});
|
|
557
|
+
const keys = Object.keys(sections);
|
|
558
|
+
if (keys.length === 0) {
|
|
559
|
+
if (existing != null)
|
|
560
|
+
staleEntryDocuments.push(existing);
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
const contributingDays = nextDayEntryDocs.filter((doc) => {
|
|
564
|
+
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(String(doc.scope_field));
|
|
565
|
+
return fields != null && fields[period.scope_context] === period.scope_field;
|
|
566
|
+
});
|
|
567
|
+
const report = {
|
|
568
|
+
_id: existing?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
569
|
+
tenant_id: tenantId,
|
|
570
|
+
brand_id: existing?.brand_id ?? effectiveDayEntries?.brand_id ?? compiledDateEntries?.brand_id ?? '',
|
|
571
|
+
scope_context: period.scope_context,
|
|
572
|
+
scope_field: period.scope_field,
|
|
573
|
+
day_index: null,
|
|
574
|
+
sale_type_key_filters: existing?.sale_type_key_filters ?? [...MATERIALIZED_REPORTS_1.SALES_COMPARISON_KEY_FILTERS],
|
|
575
|
+
sales_entries: sections,
|
|
576
|
+
iteration: existing?.iteration,
|
|
577
|
+
schema_version: existing?.schema_version ?? MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_SCHEMA_VERSION,
|
|
578
|
+
source_watermark: watermarkOfFoldedDays(contributingDays, existing?.source_watermark ?? computedAt),
|
|
579
|
+
computed_at: computedAt,
|
|
580
|
+
createdAt: existing?.createdAt ?? computedAt,
|
|
581
|
+
updatedAt: computedAt,
|
|
582
|
+
};
|
|
583
|
+
const next = {
|
|
584
|
+
...report,
|
|
585
|
+
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
586
|
+
};
|
|
587
|
+
if (needsMaterializedSalesComparisonEntriesWrite(existing, next, input.force === true)) {
|
|
588
|
+
addEntryWrite(next);
|
|
589
|
+
}
|
|
590
|
+
else if (existing != null) {
|
|
591
|
+
skippedEntryDocuments.push(existing);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return {
|
|
595
|
+
writes,
|
|
596
|
+
entryWrites,
|
|
597
|
+
staleDocuments,
|
|
598
|
+
staleEntryDocuments,
|
|
599
|
+
skippedDocuments,
|
|
600
|
+
skippedEntryDocuments,
|
|
601
|
+
createdPeriodDocuments,
|
|
602
|
+
};
|
|
603
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IOrder } from '../../schemas/types/orders';
|
|
3
|
+
import { IMaterializedTenantSalesComparisonEntries } from '../../schemas/types/materialized_tenant_sales_comparison_entries';
|
|
4
|
+
import { IMaterializedTenantSalesComparisonReport } from '../../schemas/types/materialized_tenant_sales_comparison_reports';
|
|
5
|
+
/**
|
|
6
|
+
* Sales Comparison compile — one tenant-day of orders into the day's
|
|
7
|
+
* `materialized_tenant_sales_comparison_reports` document and its
|
|
8
|
+
* `materialized_tenant_sales_comparison_entries` row document.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors the CASH compile, not the discount one: this report RE-FOLDS its
|
|
11
|
+
* period documents from day documents in the close-day plan, so the compile
|
|
12
|
+
* only ever produces the `localDate` pair. (The discount report accumulates
|
|
13
|
+
* period deltas and therefore compiles periods itself; that difference is the
|
|
14
|
+
* defect class behind discount defects 4–6 and must not be copied here.)
|
|
15
|
+
*
|
|
16
|
+
* ## Anchor — the SETTLED day, never the punch day
|
|
17
|
+
*
|
|
18
|
+
* An order belongs to the tenant-local calendar date of `order_settled_at`
|
|
19
|
+
* (concept §3). Orders whose settled day is not the day being compiled are
|
|
20
|
+
* skipped (the caller stages the right day), and orders that were never
|
|
21
|
+
* settled contribute nothing.
|
|
22
|
+
*
|
|
23
|
+
* ## Two rules this function exists to enforce
|
|
24
|
+
*
|
|
25
|
+
* 1. **The comparison is never stored.** These documents hold ONE period's
|
|
26
|
+
* truth; `current` and `comparison` are ordinary reads subtracted later.
|
|
27
|
+
* 2. **Counters and rows come from ONE pass**, so a document's map and its
|
|
28
|
+
* read-path row array can never disagree, and the entries can never list a
|
|
29
|
+
* different order set than the counters.
|
|
30
|
+
*
|
|
31
|
+
* Pure and total: `null` on malformed input, never a throw.
|
|
32
|
+
*/
|
|
33
|
+
export interface ICompileTenantSalesComparisonReportsInput {
|
|
34
|
+
tenantId: string;
|
|
35
|
+
brandId: string;
|
|
36
|
+
/** The compiled settled day, tenant-local `'YYYY-MM-DD'`. */
|
|
37
|
+
localDate: string;
|
|
38
|
+
/** Orders staged for this day (the close's fetch window). */
|
|
39
|
+
orders: IOrder[];
|
|
40
|
+
/**
|
|
41
|
+
* Tenant GST offset in hours (`+5`) used to derive the SETTLED local date.
|
|
42
|
+
* Defaults to 0 (UTC) only for synthetic callers; a real close MUST pass it.
|
|
43
|
+
*/
|
|
44
|
+
gmtOffset?: number;
|
|
45
|
+
computedAt: Date;
|
|
46
|
+
}
|
|
47
|
+
export interface ICompileTenantSalesComparisonReportsResult {
|
|
48
|
+
reports: IMaterializedTenantSalesComparisonReport[];
|
|
49
|
+
entries: IMaterializedTenantSalesComparisonEntries[];
|
|
50
|
+
/** Orders that produced a counter row. */
|
|
51
|
+
contributingOrders: number;
|
|
52
|
+
/** Orders skipped because they were never settled. */
|
|
53
|
+
skippedUnsettledOrders: number;
|
|
54
|
+
/** Orders skipped because their settled day is not `localDate`. */
|
|
55
|
+
skippedForeignOrders: number;
|
|
56
|
+
/** Orders skipped because their tenant/status/platform could not be keyed. */
|
|
57
|
+
skippedUnkeyableOrders: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Compiles one settled tenant-day.
|
|
61
|
+
*
|
|
62
|
+
* Returns EMPTY arrays (never null) when the day has no settled orders: an
|
|
63
|
+
* emptied day must produce no day document, and the close-day plan deletes the
|
|
64
|
+
* stored one.
|
|
65
|
+
*/
|
|
66
|
+
export declare function compileTenantSalesComparisonReports(input: ICompileTenantSalesComparisonReportsInput | null | undefined): ICompileTenantSalesComparisonReportsResult | null;
|
|
67
|
+
/** The scopes this report materializes — exported for the close plan + tests. */
|
|
68
|
+
export declare const MATERIALIZED_SALES_COMPARISON_COMPILED_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|