@managesome/eposmatic-toolkit 0.4.8 → 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/constants/enums/communications.js +1 -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/constants/enums/communications.d.ts +1 -0
- package/lib/constants/enums/communications.js +2 -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,431 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFormattedTenantDiscountsReporting = getFormattedTenantDiscountsReporting;
|
|
4
|
+
exports.getFormattedTenantDiscountsAggregatedReporting = getFormattedTenantDiscountsAggregatedReporting;
|
|
5
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
6
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
7
|
+
const materialized_tenant_discount_reports_1 = require("../../schemas/models/materialized_tenant_discount_reports");
|
|
8
|
+
const price_conversion_1 = require("../utils/price-conversion");
|
|
9
|
+
const key_helpers_1 = require("./key-helpers");
|
|
10
|
+
const materialized_reports_read_helpers_1 = require("./materialized-reports-read-helpers");
|
|
11
|
+
const emptySlot = () => ({ count: 0, amount: 0, resolved_amount: 0 });
|
|
12
|
+
const addSlot = (target, source) => {
|
|
13
|
+
if (source == null)
|
|
14
|
+
return;
|
|
15
|
+
target.count += source.count ?? 0;
|
|
16
|
+
target.amount += source.amount ?? 0;
|
|
17
|
+
target.resolved_amount += source.resolved_amount ?? 0;
|
|
18
|
+
};
|
|
19
|
+
/** Resolution of a slot's rate for display (`null` when no count/rate). */
|
|
20
|
+
function averageRate(slot) {
|
|
21
|
+
if (slot.count <= 0 || slot.amount <= 0)
|
|
22
|
+
return null;
|
|
23
|
+
return Math.round((slot.amount / slot.count) * 100) / 100;
|
|
24
|
+
}
|
|
25
|
+
const round2 = (value) => Math.round((value ?? 0) * 100) / 100;
|
|
26
|
+
const toDecimal = (cents) => (0, price_conversion_1.convertPriceFromCents)(cents ?? 0);
|
|
27
|
+
/** Human labels of the breakdown rows. */
|
|
28
|
+
const SUB_KIND_LABELS = {
|
|
29
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION]: 'Collection discount',
|
|
30
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.MANUAL]: 'Manual / quick discount',
|
|
31
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.PRICE_OVERRIDE]: 'Price override',
|
|
32
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM]: 'Item / catalog discount',
|
|
33
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER]: 'Offer',
|
|
34
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.GIFT_CARD]: 'Gift card',
|
|
35
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK]: 'Wallet cashback',
|
|
36
|
+
[MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED]: 'Other / unattributed',
|
|
37
|
+
};
|
|
38
|
+
/** Does a parsed key match the requested filter sets? (no filter = match) */
|
|
39
|
+
function keyMatchesFilters(key, keyFilters, filters) {
|
|
40
|
+
const components = (0, key_helpers_1.parseMaterializedReportKey)(key);
|
|
41
|
+
if (components == null || components.length !== keyFilters.length)
|
|
42
|
+
return null;
|
|
43
|
+
if (filters == null)
|
|
44
|
+
return { matched: true, components };
|
|
45
|
+
const wanted = {};
|
|
46
|
+
if (filters.platforms != null && filters.platforms.length > 0) {
|
|
47
|
+
wanted[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM] = filters.platforms;
|
|
48
|
+
}
|
|
49
|
+
if (filters.order_statuses != null && filters.order_statuses.length > 0) {
|
|
50
|
+
wanted[MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS] = filters.order_statuses;
|
|
51
|
+
}
|
|
52
|
+
for (let index = 0; index < keyFilters.length; index += 1) {
|
|
53
|
+
const filter = keyFilters[index];
|
|
54
|
+
const allowed = wanted[filter];
|
|
55
|
+
if (allowed == null)
|
|
56
|
+
continue;
|
|
57
|
+
if (!allowed.includes(components[index]))
|
|
58
|
+
return { matched: false, components };
|
|
59
|
+
}
|
|
60
|
+
return { matched: true, components };
|
|
61
|
+
}
|
|
62
|
+
const isCancelledKey = (components, keyFilters) => {
|
|
63
|
+
const statusIndex = keyFilters.indexOf(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS);
|
|
64
|
+
if (statusIndex === -1)
|
|
65
|
+
return false;
|
|
66
|
+
return components[statusIndex] === 'CANCELLED';
|
|
67
|
+
};
|
|
68
|
+
const emptyScopeAccumulator = () => ({
|
|
69
|
+
summary: {
|
|
70
|
+
total: 0,
|
|
71
|
+
orderLevel: 0,
|
|
72
|
+
itemLevel: 0,
|
|
73
|
+
discountCount: 0,
|
|
74
|
+
itemCount: 0,
|
|
75
|
+
unattributed: 0,
|
|
76
|
+
freeCount: 0,
|
|
77
|
+
freeValue: 0,
|
|
78
|
+
compCount: 0,
|
|
79
|
+
compAmount: 0,
|
|
80
|
+
},
|
|
81
|
+
orderSpecial: emptySlot(),
|
|
82
|
+
orderLoyalty: emptySlot(),
|
|
83
|
+
orderVoucher: emptySlot(),
|
|
84
|
+
rows: new Map(),
|
|
85
|
+
cancelled: { total: 0, count: 0 },
|
|
86
|
+
});
|
|
87
|
+
/** The row identity of a (sub-kind, slot, level) triple. */
|
|
88
|
+
const rowKey = (subKind, slot, level) => `${level}|${subKind}|${slot ?? '-'}`;
|
|
89
|
+
const rowFor = (accumulator, subKind, slot, level) => {
|
|
90
|
+
const key = rowKey(subKind, slot, level);
|
|
91
|
+
let row = accumulator.rows.get(key);
|
|
92
|
+
if (row == null) {
|
|
93
|
+
row = { subKind, slot, level, slotAcc: emptySlot() };
|
|
94
|
+
accumulator.rows.set(key, row);
|
|
95
|
+
}
|
|
96
|
+
return row.slotAcc;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Formats materialized discount documents into page-ready data — one entry per
|
|
100
|
+
* tenant (`separate_view_per_tenant`) or one combined entry. Returns `null` on
|
|
101
|
+
* unformattable input; an empty list yields a zero-filled page.
|
|
102
|
+
*/
|
|
103
|
+
function getFormattedTenantDiscountsReporting(reports, filters = null, separate_view_per_tenant = false) {
|
|
104
|
+
if (!Array.isArray(reports) || reports.some((report) => report == null))
|
|
105
|
+
return null;
|
|
106
|
+
if (filters != null && filters.day_indexes != null && Array.isArray(filters.day_indexes)) {
|
|
107
|
+
const invalid = filters.day_indexes.some((day) => !ENUMS_1.ALL_DAY_INDEX.includes(day));
|
|
108
|
+
if (invalid)
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
if (reports.length > 0) {
|
|
112
|
+
const signature = (reports[0].sale_type_key_filters ?? []).join(':');
|
|
113
|
+
const schemaVersion = reports[0].schema_version;
|
|
114
|
+
const seenScopes = new Set();
|
|
115
|
+
for (const report of reports) {
|
|
116
|
+
if ((report.sale_type_key_filters ?? []).join(':') !== signature)
|
|
117
|
+
return null;
|
|
118
|
+
if (report.schema_version !== schemaVersion)
|
|
119
|
+
return null;
|
|
120
|
+
// The read contract makes scope groups DISJOINT (the compiler never emits
|
|
121
|
+
// overlapping groups and the backend unions them) — so a repeated
|
|
122
|
+
// (scope_context, scope_field) WITHIN A TENANT would double-count every shared
|
|
123
|
+
// document. Reject rather than silently inflating the totals.
|
|
124
|
+
//
|
|
125
|
+
// The TENANT is part of the identity. Without it, two tenants of one brand that
|
|
126
|
+
// share a scope field — every brand-mode selection, since each store has its own
|
|
127
|
+
// document for the same date — looked like a duplicate and the whole formatter
|
|
128
|
+
// returned NULL, blanking the report for the exact multi-tenant read the page
|
|
129
|
+
// makes in production.
|
|
130
|
+
const identity = `${report.tenant_id}|${report.scope_context}|${report.scope_field}`;
|
|
131
|
+
if (seenScopes.has(identity))
|
|
132
|
+
return null;
|
|
133
|
+
seenScopes.add(identity);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const byTenant = new Map();
|
|
137
|
+
for (const report of reports) {
|
|
138
|
+
const tenant = String(report.tenant_id ?? '');
|
|
139
|
+
const list = byTenant.get(tenant) ?? [];
|
|
140
|
+
list.push(report);
|
|
141
|
+
byTenant.set(tenant, list);
|
|
142
|
+
}
|
|
143
|
+
if (byTenant.size === 0) {
|
|
144
|
+
return [[buildPageData([], emptyScopeAccumulator(), null, null)], null];
|
|
145
|
+
}
|
|
146
|
+
const pages = [];
|
|
147
|
+
const groups = separate_view_per_tenant ? [...byTenant.values()] : [[...byTenant.values()].flat()];
|
|
148
|
+
for (const group of groups) {
|
|
149
|
+
if (group.length === 0)
|
|
150
|
+
continue;
|
|
151
|
+
const keyFilters = group[0].sale_type_key_filters ?? [];
|
|
152
|
+
// Date/hour scopes feed the weekday + hourly views; period scopes feed the
|
|
153
|
+
// summary. A brand-level read returns BOTH, so accumulate per scope class.
|
|
154
|
+
const periodAccumulator = emptyScopeAccumulator();
|
|
155
|
+
const weekdayMap = new Map();
|
|
156
|
+
const hourMap = new Map();
|
|
157
|
+
let sawDateScoped = false;
|
|
158
|
+
let sawPeriodScoped = false;
|
|
159
|
+
for (const report of group) {
|
|
160
|
+
const scoped = MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX.includes(report.scope_context);
|
|
161
|
+
if (scoped)
|
|
162
|
+
sawDateScoped = true;
|
|
163
|
+
else
|
|
164
|
+
sawPeriodScoped = true;
|
|
165
|
+
// The weekday filter applies only to date/hour documents.
|
|
166
|
+
if (filters?.day_indexes != null && filters.day_indexes.length > 0) {
|
|
167
|
+
if (!scoped)
|
|
168
|
+
continue;
|
|
169
|
+
const dayIndex = report.day_index ?? null;
|
|
170
|
+
if (dayIndex == null || !filters.day_indexes.includes(dayIndex))
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
for (const [key, counters] of Object.entries(report.discount_counters ?? {})) {
|
|
174
|
+
const parsed = keyMatchesFilters(key, keyFilters, filters);
|
|
175
|
+
if (parsed == null)
|
|
176
|
+
continue;
|
|
177
|
+
if (!parsed.matched)
|
|
178
|
+
continue;
|
|
179
|
+
// Cancelled keys split out — they never feed the summary.
|
|
180
|
+
if (isCancelledKey(parsed.components, keyFilters)) {
|
|
181
|
+
periodAccumulator.cancelled.total += counters.amount ?? 0;
|
|
182
|
+
periodAccumulator.cancelled.count += counters.count ?? 0;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
accumulateCounters(periodAccumulator, counters);
|
|
186
|
+
if (scoped) {
|
|
187
|
+
const dayIndex = report.day_index ?? null;
|
|
188
|
+
if (dayIndex != null) {
|
|
189
|
+
const current = weekdayMap.get(dayIndex) ?? { total: 0, count: 0 };
|
|
190
|
+
current.total += counters.amount ?? 0;
|
|
191
|
+
current.count += counters.count ?? 0;
|
|
192
|
+
weekdayMap.set(dayIndex, current);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR) {
|
|
196
|
+
const parts = String(report.scope_field).split(' ');
|
|
197
|
+
const localDate = parts[0] ?? '';
|
|
198
|
+
const hour = Number.parseInt(parts[1] ?? '', 10);
|
|
199
|
+
if (localDate.length > 0 && Number.isInteger(hour) && hour >= 0 && hour <= 23) {
|
|
200
|
+
const current = hourMap.get(report.scope_field) ?? { total: 0, count: 0, localDate, hour };
|
|
201
|
+
current.total += counters.amount ?? 0;
|
|
202
|
+
current.count += counters.count ?? 0;
|
|
203
|
+
hourMap.set(report.scope_field, current);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// The summary sums every document: the read contract's scope groups are
|
|
209
|
+
// disjoint, so each order is represented exactly once. The weekday/hourly
|
|
210
|
+
// breakdowns can only come from DAY-scoped documents (period documents carry
|
|
211
|
+
// no `day_index` and no hour), so they are surfaced only when the selection
|
|
212
|
+
// actually contains them — a period-only read legitimately has neither.
|
|
213
|
+
const hasDayScoped = sawDateScoped;
|
|
214
|
+
const weekday = hasDayScoped
|
|
215
|
+
? [...weekdayMap.entries()]
|
|
216
|
+
.sort((a, b) => ENUMS_1.ALL_DAY_INDEX.indexOf(a[0]) - ENUMS_1.ALL_DAY_INDEX.indexOf(b[0]))
|
|
217
|
+
.map(([dayIndex, value]) => ({
|
|
218
|
+
day_index: dayIndex,
|
|
219
|
+
total_discount: toDecimal(value.total),
|
|
220
|
+
discount_count: value.count,
|
|
221
|
+
}))
|
|
222
|
+
: null;
|
|
223
|
+
const hourly = hasDayScoped
|
|
224
|
+
? [...hourMap.values()]
|
|
225
|
+
.sort((a, b) => a.localDate.localeCompare(b.localDate) ||
|
|
226
|
+
// Chronological business-hour order (06…23, 00…05) — never plain
|
|
227
|
+
// hour order, which would put the 00–05 tail before the evening.
|
|
228
|
+
((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(a.hour) ?? 0) - ((0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(b.hour) ?? 0))
|
|
229
|
+
.map((value) => ({
|
|
230
|
+
local_date: value.localDate,
|
|
231
|
+
hour: value.hour,
|
|
232
|
+
business_hour_index: (0, materialized_reports_read_helpers_1.getMaterializedBusinessHourIndex)(value.hour) ?? value.hour,
|
|
233
|
+
total_discount: toDecimal(value.total),
|
|
234
|
+
discount_count: value.count,
|
|
235
|
+
}))
|
|
236
|
+
: null;
|
|
237
|
+
pages.push(buildPageData(group.map((report) => String(report.tenant_id)), periodAccumulator, weekday, hourly));
|
|
238
|
+
}
|
|
239
|
+
return [pages, null];
|
|
240
|
+
}
|
|
241
|
+
/** Folds one key's counters into a scope accumulator. */
|
|
242
|
+
function accumulateCounters(accumulator, counters) {
|
|
243
|
+
const { summary } = accumulator;
|
|
244
|
+
summary.total += counters.amount ?? 0;
|
|
245
|
+
summary.orderLevel += counters.order_level_amount ?? 0;
|
|
246
|
+
summary.itemLevel += counters.item_level_amount ?? 0;
|
|
247
|
+
summary.discountCount += counters.count ?? 0;
|
|
248
|
+
summary.itemCount += counters.item_discount_count ?? 0;
|
|
249
|
+
summary.unattributed += counters.unattributed_amount ?? 0;
|
|
250
|
+
summary.freeCount += counters.free_items?.count ?? 0;
|
|
251
|
+
summary.freeValue += counters.free_items?.value ?? 0;
|
|
252
|
+
summary.compCount += counters.complimentary?.payment_count ?? 0;
|
|
253
|
+
summary.compAmount += counters.complimentary?.amount ?? 0;
|
|
254
|
+
addSlot(accumulator.orderSpecial, counters.order_special);
|
|
255
|
+
addSlot(accumulator.orderLoyalty, counters.order_loyalty);
|
|
256
|
+
addSlot(accumulator.orderVoucher, counters.order_voucher);
|
|
257
|
+
// Order-level sub-kind rows
|
|
258
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.special_collection);
|
|
259
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.MANUAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.special_manual);
|
|
260
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.PRICE_OVERRIDE, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.special_price_override);
|
|
261
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.special_catalog_item);
|
|
262
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.special_other);
|
|
263
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.loyalty_offer);
|
|
264
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.GIFT_CARD, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.loyalty_gift_card);
|
|
265
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.loyalty_wallet);
|
|
266
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.loyalty_other);
|
|
267
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.voucher_offer);
|
|
268
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER), counters.voucher_other);
|
|
269
|
+
// Item-level slot totals
|
|
270
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
271
|
+
count: counters.item_special?.collection_count ?? 0,
|
|
272
|
+
amount: counters.item_special?.collection_amount ?? 0,
|
|
273
|
+
resolved_amount: counters.item_special?.collection_resolved_amount ?? 0,
|
|
274
|
+
});
|
|
275
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.MANUAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
276
|
+
count: counters.item_special?.manual_count ?? 0,
|
|
277
|
+
amount: counters.item_special?.manual_amount ?? 0,
|
|
278
|
+
resolved_amount: counters.item_special?.manual_resolved_amount ?? 0,
|
|
279
|
+
});
|
|
280
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.PRICE_OVERRIDE, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
281
|
+
count: counters.item_special?.price_override_count ?? 0,
|
|
282
|
+
amount: counters.item_special?.price_override_amount ?? 0,
|
|
283
|
+
resolved_amount: counters.item_special?.price_override_resolved_amount ?? 0,
|
|
284
|
+
});
|
|
285
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
286
|
+
count: counters.item_special?.catalog_item_count ?? 0,
|
|
287
|
+
amount: counters.item_special?.catalog_item_amount ?? 0,
|
|
288
|
+
resolved_amount: counters.item_special?.catalog_item_resolved_amount ?? 0,
|
|
289
|
+
});
|
|
290
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
291
|
+
count: counters.item_special?.other_count ?? 0,
|
|
292
|
+
amount: counters.item_special?.other_amount ?? 0,
|
|
293
|
+
resolved_amount: counters.item_special?.other_resolved_amount ?? 0,
|
|
294
|
+
});
|
|
295
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
296
|
+
count: counters.item_loyalty?.offer_count ?? 0,
|
|
297
|
+
amount: counters.item_loyalty?.offer_amount ?? 0,
|
|
298
|
+
resolved_amount: counters.item_loyalty?.offer_resolved_amount ?? 0,
|
|
299
|
+
});
|
|
300
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.GIFT_CARD, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
301
|
+
count: counters.item_loyalty?.gift_card_count ?? 0,
|
|
302
|
+
amount: counters.item_loyalty?.gift_card_amount ?? 0,
|
|
303
|
+
resolved_amount: counters.item_loyalty?.gift_card_resolved_amount ?? 0,
|
|
304
|
+
});
|
|
305
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
306
|
+
count: counters.item_loyalty?.wallet_count ?? 0,
|
|
307
|
+
amount: counters.item_loyalty?.wallet_amount ?? 0,
|
|
308
|
+
resolved_amount: counters.item_loyalty?.wallet_resolved_amount ?? 0,
|
|
309
|
+
});
|
|
310
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
311
|
+
count: counters.item_loyalty?.other_count ?? 0,
|
|
312
|
+
amount: counters.item_loyalty?.other_amount ?? 0,
|
|
313
|
+
resolved_amount: counters.item_loyalty?.other_resolved_amount ?? 0,
|
|
314
|
+
});
|
|
315
|
+
addSlot(rowFor(accumulator, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER, MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM), {
|
|
316
|
+
count: counters.item_voucher?.offer_count ?? 0,
|
|
317
|
+
amount: counters.item_voucher?.offer_amount ?? 0,
|
|
318
|
+
resolved_amount: counters.item_voucher?.offer_resolved_amount ?? 0,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/** Builds one page from an accumulator. */
|
|
322
|
+
function buildPageData(tenantIds, accumulator, weekday, hourly) {
|
|
323
|
+
const totalCents = accumulator.summary.total;
|
|
324
|
+
const sections = [...accumulator.rows.values()]
|
|
325
|
+
.filter((row) => row.slotAcc.count > 0 || row.slotAcc.resolved_amount !== 0)
|
|
326
|
+
.map((row) => ({
|
|
327
|
+
sub_kind: row.subKind,
|
|
328
|
+
slot: row.slot,
|
|
329
|
+
level: row.level,
|
|
330
|
+
label: SUB_KIND_LABELS[row.subKind],
|
|
331
|
+
count: row.slotAcc.count,
|
|
332
|
+
amount: toDecimal(row.slotAcc.resolved_amount),
|
|
333
|
+
// The average RAW rate of the row's occurrences (a percent average for
|
|
334
|
+
// percentage-heavy rows) — display context only, NEVER money.
|
|
335
|
+
rate: averageRate(row.slotAcc),
|
|
336
|
+
share_percent: totalCents === 0 ? 0 : round2((row.slotAcc.resolved_amount / totalCents) * 100),
|
|
337
|
+
}))
|
|
338
|
+
.sort((a, b) => b.amount - a.amount);
|
|
339
|
+
return {
|
|
340
|
+
tenant_ids: [...new Set(tenantIds)],
|
|
341
|
+
summary: {
|
|
342
|
+
total_discount: toDecimal(accumulator.summary.total),
|
|
343
|
+
order_level_discount: toDecimal(accumulator.summary.orderLevel),
|
|
344
|
+
item_level_discount: toDecimal(accumulator.summary.itemLevel),
|
|
345
|
+
discount_count: accumulator.summary.discountCount,
|
|
346
|
+
item_discount_count: accumulator.summary.itemCount,
|
|
347
|
+
unattributed_discount: toDecimal(accumulator.summary.unattributed),
|
|
348
|
+
free_item_count: accumulator.summary.freeCount,
|
|
349
|
+
free_item_value: toDecimal(accumulator.summary.freeValue),
|
|
350
|
+
complimentary_count: accumulator.summary.compCount,
|
|
351
|
+
complimentary_amount: toDecimal(accumulator.summary.compAmount),
|
|
352
|
+
},
|
|
353
|
+
order_slots: [
|
|
354
|
+
{
|
|
355
|
+
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL,
|
|
356
|
+
count: accumulator.orderSpecial.count,
|
|
357
|
+
amount: toDecimal(accumulator.orderSpecial.resolved_amount),
|
|
358
|
+
rate: averageRate(accumulator.orderSpecial),
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY,
|
|
362
|
+
count: accumulator.orderLoyalty.count,
|
|
363
|
+
amount: toDecimal(accumulator.orderLoyalty.resolved_amount),
|
|
364
|
+
rate: averageRate(accumulator.orderLoyalty),
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER,
|
|
368
|
+
count: accumulator.orderVoucher.count,
|
|
369
|
+
amount: toDecimal(accumulator.orderVoucher.resolved_amount),
|
|
370
|
+
rate: averageRate(accumulator.orderVoucher),
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
sections,
|
|
374
|
+
cancelled: accumulator.cancelled.count > 0
|
|
375
|
+
? { total_discount: toDecimal(accumulator.cancelled.total), discount_count: accumulator.cancelled.count }
|
|
376
|
+
: null,
|
|
377
|
+
weekday,
|
|
378
|
+
hourly,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
/* ==================== Aggregated (pipeline) variant ==================== */
|
|
382
|
+
/**
|
|
383
|
+
* Frontend formatter for the AGGREGATED discounts read
|
|
384
|
+
* (`POST /reports/discounts` returns `IMaterializedTenantDiscountAggregatedReport[]`
|
|
385
|
+
* - one record per tenant, folded inside MongoDB).
|
|
386
|
+
*
|
|
387
|
+
* The aggregated record carries the SAME `discount_counters` map as a stored
|
|
388
|
+
* document, so this delegates to the stored-document formatter: one code path,
|
|
389
|
+
* no duplicated shaping. The envelope fields it reads are supplied here.
|
|
390
|
+
*
|
|
391
|
+
* `scope_field` carries the TENANT. The formatter's duplicate-identity guard
|
|
392
|
+
* (`scope_context|scope_field`) exists to catch the same stored scope document
|
|
393
|
+
* being fed twice; for folded records the meaningful identity IS the tenant, so
|
|
394
|
+
* one record per tenant keeps that guard useful instead of tripping on every
|
|
395
|
+
* record sharing an absent scope.
|
|
396
|
+
*
|
|
397
|
+
* LIMITATION - no `weekday` / `hourly` breakdowns. Those group on a stored
|
|
398
|
+
* document's `day_index` / `scope_field` hour, and a folded record spans many
|
|
399
|
+
* scope documents, so the fold has no single value to group on. A weekday or
|
|
400
|
+
* day-index filter is therefore REFUSED (`null`, the unformattable convention)
|
|
401
|
+
* rather than silently ignored; `weekday` and `hourly` come back `null`. The
|
|
402
|
+
* summary, order slots and sections are exact.
|
|
403
|
+
*/
|
|
404
|
+
function getFormattedTenantDiscountsAggregatedReporting(reports, filters = null, separate_view_per_tenant = false) {
|
|
405
|
+
if (!Array.isArray(reports) || reports.some((report) => report == null)) {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
// A folded record has no single day_index, so a weekday filter cannot be
|
|
409
|
+
// honoured - refuse rather than quietly return every weekday.
|
|
410
|
+
if (filters != null && Array.isArray(filters.day_indexes) && filters.day_indexes.length > 0) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
const asStored = reports.map((report) => ({
|
|
414
|
+
_id: `${report.tenant_id}|aggregated`,
|
|
415
|
+
tenant_id: report.tenant_id,
|
|
416
|
+
brand_id: report.brand_id,
|
|
417
|
+
// The fold spans scopes; LOCAL_MONTH is the report's widest scope and is
|
|
418
|
+
// only used for the (skipped) hour parse.
|
|
419
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
420
|
+
scope_field: report.tenant_id,
|
|
421
|
+
day_index: null,
|
|
422
|
+
sale_type_key_filters: report.sale_type_key_filters,
|
|
423
|
+
discount_counters: report.discount_counters,
|
|
424
|
+
schema_version: materialized_tenant_discount_reports_1.MATERIALIZED_TENANT_DISCOUNT_REPORTS_SCHEMA_VERSION,
|
|
425
|
+
source_watermark: report.max_updated_at ?? new Date(0),
|
|
426
|
+
computed_at: report.max_updated_at ?? new Date(0),
|
|
427
|
+
createdAt: report.max_updated_at ?? new Date(0),
|
|
428
|
+
updatedAt: report.max_updated_at ?? new Date(0),
|
|
429
|
+
}));
|
|
430
|
+
return getFormattedTenantDiscountsReporting(asStored, filters, separate_view_per_tenant);
|
|
431
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SALES_COMPARISON_METRIC_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IMaterializedTenantHourlyComparisonAggregatedReport } from '../types/materialized-reports-apis';
|
|
3
|
+
import { IMaterializedTenantHourlyComparisonReport } from '../../schemas/types/materialized_tenant_hourly_comparison_reports';
|
|
4
|
+
import { IFormattedSalesComparisonFilters, IFormattedSalesComparisonMetric, IFormattedSalesComparisonSeries } from './tenant-sales-comparison-formatter';
|
|
5
|
+
/**
|
|
6
|
+
* Hourly Comparison formatter — the page-ready hourly PROFILE.
|
|
7
|
+
*
|
|
8
|
+
* `current` and `comparison` are two ordinary reads of hour documents. This
|
|
9
|
+
* formatter aligns them by HOUR OF DAY, applies the client-side platform /
|
|
10
|
+
* status filters, splits cancelled revenue, and exposes every selectable metric
|
|
11
|
+
* for each hour plus the range totals.
|
|
12
|
+
*
|
|
13
|
+
* Ordering is BUSINESS-HOUR order (`06…23, 00…05`), never plain hour or string
|
|
14
|
+
* sort: 00–05 is the tail of the business evening.
|
|
15
|
+
*
|
|
16
|
+
* Ratios (`average_ticket`) are derived per hour, never stored.
|
|
17
|
+
*/
|
|
18
|
+
/** Formatted counters reuse the Sales Comparison shape. */
|
|
19
|
+
export interface IFormattedHourlyComparisonHour {
|
|
20
|
+
/** 0–23, the hour-of-day bucket. */
|
|
21
|
+
hour: number;
|
|
22
|
+
/** Display label `'18:00–19:00'`. */
|
|
23
|
+
label: string;
|
|
24
|
+
/** Position in the business-hour series (06 → 0 … 05 → 23). */
|
|
25
|
+
business_index: number;
|
|
26
|
+
current: IFormattedSalesComparisonSeries;
|
|
27
|
+
comparison: IFormattedSalesComparisonSeries | null;
|
|
28
|
+
metrics: Record<SALES_COMPARISON_METRIC_ENUM, IFormattedSalesComparisonMetric>;
|
|
29
|
+
}
|
|
30
|
+
export interface IFormattedHourlyComparisonPageData {
|
|
31
|
+
tenant_ids: string[];
|
|
32
|
+
filters: {
|
|
33
|
+
platforms: string[] | null;
|
|
34
|
+
order_statuses: string[] | null;
|
|
35
|
+
};
|
|
36
|
+
/** The whole selection's totals (cancelled split out). */
|
|
37
|
+
current: IFormattedSalesComparisonSeries;
|
|
38
|
+
comparison: IFormattedSalesComparisonSeries | null;
|
|
39
|
+
metrics: Record<SALES_COMPARISON_METRIC_ENUM, IFormattedSalesComparisonMetric>;
|
|
40
|
+
cancelled: IFormattedSalesComparisonSeries;
|
|
41
|
+
/** Always 24 entries, in business-hour order. */
|
|
42
|
+
hours: IFormattedHourlyComparisonHour[];
|
|
43
|
+
/** Hours with at least one current order (the profile's coverage). */
|
|
44
|
+
hours_with_data: number;
|
|
45
|
+
matched_documents: number;
|
|
46
|
+
max_updated_at: Date | null;
|
|
47
|
+
}
|
|
48
|
+
type THourlyDocument = IMaterializedTenantHourlyComparisonAggregatedReport | IMaterializedTenantHourlyComparisonReport;
|
|
49
|
+
/** `'HH:00–HH+1:00'` (end wraps at midnight). */
|
|
50
|
+
export declare const getHourlyComparisonHourLabel: (hour: number) => string;
|
|
51
|
+
/** Business-hour index: 06 → 0, …, 23 → 17, 00 → 18, …, 05 → 23. */
|
|
52
|
+
export declare const getHourlyComparisonBusinessIndex: (hour: number) => number;
|
|
53
|
+
/**
|
|
54
|
+
* Page-ready Hourly Comparison data.
|
|
55
|
+
*
|
|
56
|
+
* `comparisonDocs` is `null` for `baseline: NONE`; an empty array is a valid
|
|
57
|
+
* baseline window with no sales (a zero profile).
|
|
58
|
+
*/
|
|
59
|
+
export declare function getFormattedTenantHourlyComparisonReporting(currentDocs: THourlyDocument[] | null | undefined, comparisonDocs: THourlyDocument[] | null | undefined, filters?: IFormattedSalesComparisonFilters | null, separate_view_per_tenant?: boolean): [IFormattedHourlyComparisonPageData[], null] | null;
|
|
60
|
+
export {};
|