@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,208 @@
|
|
|
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.mergeMaterializedPrepTimeCounters = mergeMaterializedPrepTimeCounters;
|
|
7
|
+
exports.compileTenantPrepTimeReports = compileTenantPrepTimeReports;
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
10
|
+
const materialized_prep_time_classification_helpers_1 = require("./materialized-prep-time-classification-helpers");
|
|
11
|
+
const scope_helpers_1 = require("./scope-helpers");
|
|
12
|
+
/**
|
|
13
|
+
* Adds `source` into `target`.
|
|
14
|
+
*
|
|
15
|
+
* NOT the generic recursive numeric add the discount compile uses: `duration.min`
|
|
16
|
+
* and `duration.max` (and `late_items.worst_delta`) are AGGREGATES, not counters.
|
|
17
|
+
* Summing them would turn a 5-minute minimum into a 50-minute one across ten
|
|
18
|
+
* days. Everything additive is summed; the extremes fold with min()/max().
|
|
19
|
+
*/
|
|
20
|
+
function mergeMaterializedPrepTimeCounters(target, source) {
|
|
21
|
+
// ---- coverage (all additive) ----
|
|
22
|
+
target.coverage.item_count += source.coverage.item_count;
|
|
23
|
+
target.coverage.ready_item_count += source.coverage.ready_item_count;
|
|
24
|
+
target.coverage.tracked_count += source.coverage.tracked_count;
|
|
25
|
+
target.coverage.own_anchor_count += source.coverage.own_anchor_count;
|
|
26
|
+
target.coverage.fallback_anchor_count += source.coverage.fallback_anchor_count;
|
|
27
|
+
target.coverage.order_count += source.coverage.order_count;
|
|
28
|
+
// ---- duration ----
|
|
29
|
+
target.duration.count += source.duration.count;
|
|
30
|
+
target.duration.sum += source.duration.sum;
|
|
31
|
+
target.duration.instant_count += source.duration.instant_count;
|
|
32
|
+
for (const [label, count] of Object.entries(source.duration.buckets)) {
|
|
33
|
+
target.duration.buckets[label] = (target.duration.buckets[label] ?? 0) + count;
|
|
34
|
+
}
|
|
35
|
+
// Extremes fold, never sum. A zero minimum means "no measured row yet", so it
|
|
36
|
+
// is replaced rather than kept.
|
|
37
|
+
if (source.duration.count > 0) {
|
|
38
|
+
target.duration.min =
|
|
39
|
+
target.duration.count - source.duration.count <= 0
|
|
40
|
+
? source.duration.min
|
|
41
|
+
: Math.min(target.duration.min, source.duration.min);
|
|
42
|
+
target.duration.max = Math.max(target.duration.max, source.duration.max);
|
|
43
|
+
}
|
|
44
|
+
// ---- promise (all additive; delta_sum is SIGNED) ----
|
|
45
|
+
target.promise.promise_set_count += source.promise.promise_set_count;
|
|
46
|
+
target.promise.default_baseline_count += source.promise.default_baseline_count;
|
|
47
|
+
target.promise.on_time_count += source.promise.on_time_count;
|
|
48
|
+
target.promise.late_count += source.promise.late_count;
|
|
49
|
+
target.promise.delta_sum += source.promise.delta_sum;
|
|
50
|
+
target.promise.no_target_count += source.promise.no_target_count;
|
|
51
|
+
// ---- late items ----
|
|
52
|
+
target.late_items.count += source.late_items.count;
|
|
53
|
+
target.late_items.worst_delta = Math.max(target.late_items.worst_delta, source.late_items.worst_delta);
|
|
54
|
+
}
|
|
55
|
+
const foldWatermark = (bucket, value) => {
|
|
56
|
+
if (value == null)
|
|
57
|
+
return;
|
|
58
|
+
const time = new Date(value).getTime();
|
|
59
|
+
if (Number.isNaN(time))
|
|
60
|
+
return;
|
|
61
|
+
if (bucket.watermark == null || time > bucket.watermark.getTime()) {
|
|
62
|
+
bucket.watermark = new Date(time);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const scopeKey = (doc) => doc.scope_context + '|' + doc.scope_field;
|
|
66
|
+
/** Hour label of one order (`YYYY-MM-DD HH`) from its local fields, or null. */
|
|
67
|
+
const resolveLocalHourLabel = (order, localDate) => {
|
|
68
|
+
const hour = order?.localHour;
|
|
69
|
+
if (typeof hour !== 'number' || !Number.isFinite(hour) || hour < 0 || hour > 23) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return localDate + ' ' + String(hour).padStart(2, '0');
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Compiles one tenant-day into the prep time report + entries documents.
|
|
76
|
+
* Returns `null` on malformed input (bad date / tenant / brand); returns EMPTY
|
|
77
|
+
* arrays when the day has nothing tracked at all.
|
|
78
|
+
*/
|
|
79
|
+
function compileTenantPrepTimeReports(input) {
|
|
80
|
+
if (input == null)
|
|
81
|
+
return null;
|
|
82
|
+
const { tenantId, brandId, localDate, orders, computedAt } = input;
|
|
83
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
84
|
+
return null;
|
|
85
|
+
if (typeof brandId !== 'string' || brandId.length === 0)
|
|
86
|
+
return null;
|
|
87
|
+
if (typeof localDate !== 'string' || localDate.length === 0)
|
|
88
|
+
return null;
|
|
89
|
+
if (!Array.isArray(orders))
|
|
90
|
+
return null;
|
|
91
|
+
const periodFields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
|
|
92
|
+
if (periodFields == null)
|
|
93
|
+
return null;
|
|
94
|
+
const dayIndex = (0, scope_helpers_1.getDayIndexFromLocalDate)(localDate);
|
|
95
|
+
const at = computedAt ?? new Date();
|
|
96
|
+
const byScope = new Map();
|
|
97
|
+
const scopeContextOf = new Map();
|
|
98
|
+
const bucketFor = (scope, scopeField, key) => {
|
|
99
|
+
const identity = scope + '|' + scopeField;
|
|
100
|
+
let byKey = byScope.get(identity);
|
|
101
|
+
if (byKey == null) {
|
|
102
|
+
byKey = new Map();
|
|
103
|
+
byScope.set(identity, byKey);
|
|
104
|
+
scopeContextOf.set(identity, scope);
|
|
105
|
+
}
|
|
106
|
+
let bucket = byKey.get(key);
|
|
107
|
+
if (bucket == null) {
|
|
108
|
+
bucket = { counters: (0, materialized_prep_time_classification_helpers_1.freshMaterializedPrepTimeCounters)(), rows: [], watermark: null };
|
|
109
|
+
byKey.set(key, bucket);
|
|
110
|
+
}
|
|
111
|
+
return bucket;
|
|
112
|
+
};
|
|
113
|
+
let contributingOrders = 0;
|
|
114
|
+
for (const order of orders) {
|
|
115
|
+
if (order == null)
|
|
116
|
+
continue;
|
|
117
|
+
// Only orders of this tenant compile into this tenant's documents.
|
|
118
|
+
if (order.tenant_id != null && String(order.tenant_id) !== tenantId)
|
|
119
|
+
continue;
|
|
120
|
+
const context = {
|
|
121
|
+
local_date: localDate,
|
|
122
|
+
local_hour_label: resolveLocalHourLabel(order, localDate),
|
|
123
|
+
};
|
|
124
|
+
const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
|
|
125
|
+
order,
|
|
126
|
+
context,
|
|
127
|
+
tenantDefaultMinutes: input.tenantDefaultMinutes ?? null,
|
|
128
|
+
});
|
|
129
|
+
// COVERAGE IS THE HEADLINE, so an order that served items but was never
|
|
130
|
+
// observed MUST still contribute its denominator. Skipping it would let the
|
|
131
|
+
// report claim "100% observed" by ignoring everything it failed to observe -
|
|
132
|
+
// exactly the reading this report exists to prevent (one measured store is
|
|
133
|
+
// 2.9% covered).
|
|
134
|
+
if (result.counters.coverage.item_count === 0)
|
|
135
|
+
continue;
|
|
136
|
+
// `contributingOrders` is the narrower documented numerator: orders with at
|
|
137
|
+
// least one TRACKED item.
|
|
138
|
+
if (result.has_tracked)
|
|
139
|
+
contributingOrders += 1;
|
|
140
|
+
const key = String(order.order_status ?? '') + ':' + String(order.platform ?? order.order_from ?? '');
|
|
141
|
+
const watermark = order.updatedAt != null ? new Date(order.updatedAt) : null;
|
|
142
|
+
for (const scope of MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_REPORT_SCOPES) {
|
|
143
|
+
const scopeField = periodFields[scope];
|
|
144
|
+
if (scopeField == null)
|
|
145
|
+
continue;
|
|
146
|
+
const bucket = bucketFor(scope, scopeField, key);
|
|
147
|
+
mergeMaterializedPrepTimeCounters(bucket.counters, result.counters);
|
|
148
|
+
bucket.rows.push(...result.entries);
|
|
149
|
+
foldWatermark(bucket, watermark);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const sourceWatermark = new Date(at);
|
|
153
|
+
const reports = [];
|
|
154
|
+
const entries = [];
|
|
155
|
+
for (const [identity, byKey] of byScope) {
|
|
156
|
+
const [scopeContext, scopeField] = identity.split('|');
|
|
157
|
+
const counters = {};
|
|
158
|
+
const counterRows = [];
|
|
159
|
+
const entrySections = {};
|
|
160
|
+
let watermark = null;
|
|
161
|
+
for (const [key, bucket] of byKey) {
|
|
162
|
+
counters[key] = bucket.counters;
|
|
163
|
+
counterRows.push({ key, counters: bucket.counters });
|
|
164
|
+
if (bucket.rows.length > 0)
|
|
165
|
+
entrySections[key] = { rows: bucket.rows };
|
|
166
|
+
if (bucket.watermark != null && (watermark == null || bucket.watermark.getTime() > watermark.getTime())) {
|
|
167
|
+
watermark = bucket.watermark;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const docWatermark = watermark ?? sourceWatermark;
|
|
171
|
+
const isDateScoped = scopeContext === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
172
|
+
reports.push({
|
|
173
|
+
_id: new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
174
|
+
tenant_id: tenantId,
|
|
175
|
+
brand_id: brandId,
|
|
176
|
+
scope_context: scopeContext,
|
|
177
|
+
scope_field: scopeField,
|
|
178
|
+
day_index: isDateScoped ? dayIndex : null,
|
|
179
|
+
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.PREP_TIME_KEY_FILTERS],
|
|
180
|
+
prep_time_counters: Object.keys(counters).length === 0 ? null : counters,
|
|
181
|
+
// The read-path shape, written from the SAME pass so the two cannot disagree.
|
|
182
|
+
prep_time_counter_rows: counterRows.length === 0 ? null : counterRows,
|
|
183
|
+
schema_version: 1,
|
|
184
|
+
source_watermark: docWatermark,
|
|
185
|
+
computed_at: at,
|
|
186
|
+
createdAt: at,
|
|
187
|
+
updatedAt: at,
|
|
188
|
+
});
|
|
189
|
+
if (Object.keys(entrySections).length > 0) {
|
|
190
|
+
entries.push({
|
|
191
|
+
_id: new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
192
|
+
tenant_id: tenantId,
|
|
193
|
+
brand_id: brandId,
|
|
194
|
+
scope_context: scopeContext,
|
|
195
|
+
scope_field: scopeField,
|
|
196
|
+
day_index: isDateScoped ? dayIndex : null,
|
|
197
|
+
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.PREP_TIME_KEY_FILTERS],
|
|
198
|
+
prep_time_entries: entrySections,
|
|
199
|
+
schema_version: 1,
|
|
200
|
+
source_watermark: docWatermark,
|
|
201
|
+
computed_at: at,
|
|
202
|
+
createdAt: at,
|
|
203
|
+
updatedAt: at,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return { reports, entries, contributingOrders };
|
|
208
|
+
}
|
|
@@ -23,10 +23,13 @@ import { IGetMaterializedReportScopeGroup } from '../types/materialized-reports-
|
|
|
23
23
|
* Returns `null` (never throws) for malformed input — `null` means the
|
|
24
24
|
* caller passed invalid data.
|
|
25
25
|
*/
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Window refinement kinds (see the module docblock).
|
|
28
|
+
* @deprecated use MATERIALIZED_REPORT_WINDOW_KIND_ENUM from constants.
|
|
29
|
+
*/
|
|
27
30
|
export declare const MATERIALIZED_REPORT_WINDOW_KIND: {
|
|
28
|
-
readonly RECURRING:
|
|
29
|
-
readonly SPAN:
|
|
31
|
+
readonly RECURRING: 'RECURRING';
|
|
32
|
+
readonly SPAN: 'SPAN';
|
|
30
33
|
};
|
|
31
34
|
export type TMaterializedReportWindowKind = (typeof MATERIALIZED_REPORT_WINDOW_KIND)[keyof typeof MATERIALIZED_REPORT_WINDOW_KIND];
|
|
32
35
|
export interface IMaterializedReportScopeSelectionSpec {
|
|
@@ -29,10 +29,13 @@ const materialized_reports_read_helpers_1 = require("./materialized-reports-read
|
|
|
29
29
|
* Returns `null` (never throws) for malformed input — `null` means the
|
|
30
30
|
* caller passed invalid data.
|
|
31
31
|
*/
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Window refinement kinds (see the module docblock).
|
|
34
|
+
* @deprecated use MATERIALIZED_REPORT_WINDOW_KIND_ENUM from constants.
|
|
35
|
+
*/
|
|
33
36
|
exports.MATERIALIZED_REPORT_WINDOW_KIND = {
|
|
34
|
-
RECURRING:
|
|
35
|
-
SPAN:
|
|
37
|
+
RECURRING: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
38
|
+
SPAN: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN,
|
|
36
39
|
};
|
|
37
40
|
/* ------------------------------------------------------------------------ */
|
|
38
41
|
/* Date-key math (UTC — keys are timezone-less) */
|
|
@@ -207,7 +210,7 @@ function buildMaterializedReportScopeGroups(spec) {
|
|
|
207
210
|
const uniqueDates = dayKeys.map((key) => keyToDate(key));
|
|
208
211
|
// A SPAN window reads the CONTINUOUS interval first-day → last-day — a day
|
|
209
212
|
// set with gaps would silently pull the gap days in as full middle days.
|
|
210
|
-
if (window != null && window.kind ===
|
|
213
|
+
if (window != null && window.kind === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN) {
|
|
211
214
|
for (let index = 1; index < uniqueDates.length; index += 1) {
|
|
212
215
|
if (daysBetween(uniqueDates[index - 1], uniqueDates[index]) !== 1) {
|
|
213
216
|
return null;
|
|
@@ -222,7 +225,7 @@ function buildMaterializedReportScopeGroups(spec) {
|
|
|
222
225
|
if (!isValidHour(fromHour, 23) || !isValidHour(toHour, 23))
|
|
223
226
|
return null;
|
|
224
227
|
// Recurring: the same hours on every selected day.
|
|
225
|
-
if (kind ===
|
|
228
|
+
if (kind === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING) {
|
|
226
229
|
const labels = (0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(dayKeys, fromHour, toHour);
|
|
227
230
|
return labels == null ? null : [{ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, scope_field: labels }];
|
|
228
231
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { CALENDAR_VIEW_MODE_ENUM } from '../../constants/REPORT_CALENDAR';
|
|
1
2
|
import { IGetMaterializedReportScopeGroup } from '../types/materialized-reports-apis';
|
|
2
3
|
import { IReportCalendarSelection } from '../types/report-calendar';
|
|
4
|
+
/**
|
|
5
|
+
* The SPAN-window views, exported for consumers that must mirror a selection's
|
|
6
|
+
* window semantics (the Sales Comparison baseline derivation): a range-like
|
|
7
|
+
* selection's toggle window is a CONTINUOUS span, while a discrete / weekday
|
|
8
|
+
* selection repeats the same hours on each day.
|
|
9
|
+
*/
|
|
10
|
+
export declare const MATERIALIZED_REPORT_SPAN_VIEW_MODES: ReadonlySet<CALENDAR_VIEW_MODE_ENUM>;
|
|
3
11
|
/**
|
|
4
12
|
* Upper bound on the raw day span one selection may cover (~10 years).
|
|
5
13
|
* Bounds every date-walk expansion in the decoder; read services surface an
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildMaterializedReportScopeGroupsFromSelection = exports.validateMaterializedReportSelectionInput = exports.isValidBusinessHourWindow = exports.getDayKeysFromCalendarSelection = exports.MATERIALIZED_REPORT_MAX_SELECTION_DAY_SPAN = void 0;
|
|
3
|
+
exports.buildMaterializedReportScopeGroupsFromSelection = exports.validateMaterializedReportSelectionInput = exports.isValidBusinessHourWindow = exports.getDayKeysFromCalendarSelection = exports.MATERIALIZED_REPORT_MAX_SELECTION_DAY_SPAN = exports.MATERIALIZED_REPORT_SPAN_VIEW_MODES = void 0;
|
|
4
4
|
const ENUMS_1 = require("../../constants/ENUMS");
|
|
5
5
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
6
6
|
const REPORT_CALENDAR_1 = require("../../constants/REPORT_CALENDAR");
|
|
@@ -62,6 +62,13 @@ const RANGE_LIKE_VIEWS = new Set([
|
|
|
62
62
|
REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.QUARTER,
|
|
63
63
|
REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.SEMESTER,
|
|
64
64
|
]);
|
|
65
|
+
/**
|
|
66
|
+
* The SPAN-window views, exported for consumers that must mirror a selection's
|
|
67
|
+
* window semantics (the Sales Comparison baseline derivation): a range-like
|
|
68
|
+
* selection's toggle window is a CONTINUOUS span, while a discrete / weekday
|
|
69
|
+
* selection repeats the same hours on each day.
|
|
70
|
+
*/
|
|
71
|
+
exports.MATERIALIZED_REPORT_SPAN_VIEW_MODES = SPAN_VIEWS;
|
|
65
72
|
/**
|
|
66
73
|
* Upper bound on the raw day span one selection may cover (~10 years).
|
|
67
74
|
* Bounds every date-walk expansion in the decoder; read services surface an
|
|
@@ -660,8 +667,8 @@ const decodeMaterializedReportScopeGroups = (selection) => {
|
|
|
660
667
|
// never compile it. Weekday + window therefore always compiles
|
|
661
668
|
// RECURRING (the same hours on each matching weekday).
|
|
662
669
|
kind: SPAN_VIEWS.has(view) && weekdayFilter == null
|
|
663
|
-
?
|
|
664
|
-
:
|
|
670
|
+
? MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN
|
|
671
|
+
: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
665
672
|
},
|
|
666
673
|
}
|
|
667
674
|
: {}),
|
package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IOrder } from '../../schemas/types/orders';
|
|
2
|
+
import { IMaterializedSalesComparisonCounters } from '../../schemas/types/materialized_tenant_sales_comparison_reports';
|
|
3
|
+
/** A zeroed counter block. */
|
|
4
|
+
export declare function createEmptySalesComparisonCounters(): IMaterializedSalesComparisonCounters;
|
|
5
|
+
/** Gross sales in CENTS — BEFORE discounts. */
|
|
6
|
+
export declare function getOrderGrossAmountCents(order: IOrder): number;
|
|
7
|
+
/** Discounts applied to the order, in CENTS. */
|
|
8
|
+
export declare function getOrderDiscountAmountCents(order: IOrder): number;
|
|
9
|
+
/** Total tax collected, in CENTS (GST + the unused `tax_amount` bucket). */
|
|
10
|
+
export declare function getOrderTaxAmountCents(order: IOrder): number;
|
|
11
|
+
/** Service-shaped charges (service fee + surcharge), in CENTS. */
|
|
12
|
+
export declare function getOrderServiceChargeAmountCents(order: IOrder): number;
|
|
13
|
+
/** Refunded money across the order's payments, in CENTS. */
|
|
14
|
+
export declare function getOrderRefundAmountCents(order: IOrder): number;
|
|
15
|
+
/** Voided (cancelled) order value, in CENTS. */
|
|
16
|
+
export declare function getOrderVoidAmountCents(order: IOrder): number;
|
|
17
|
+
/** Items sold (Σ quantity), NOT line count. */
|
|
18
|
+
export declare function getOrderItemCount(order: IOrder): number;
|
|
19
|
+
/** Dine-in guest count (0 elsewhere). */
|
|
20
|
+
export declare function getOrderGuestCount(order: IOrder): number;
|
|
21
|
+
/**
|
|
22
|
+
* The tenant-local calendar date of an order's SETTLEMENT instant.
|
|
23
|
+
*
|
|
24
|
+
* The anchor is `order_settled_at` — NEVER `order.localDate`, which is the
|
|
25
|
+
* PUNCH day. A deferred bill punched Monday and collected Wednesday belongs to
|
|
26
|
+
* Wednesday's comparison row (concept §3: no time bias, one fixed anchor).
|
|
27
|
+
*
|
|
28
|
+
* `gmtOffset` is the tenant GST offset in hours (`+5`). The local calendar date
|
|
29
|
+
* of an instant is the UTC date after shifting by that offset.
|
|
30
|
+
*
|
|
31
|
+
* Returns `null` for an order that was never settled (no `order_settled_at` or
|
|
32
|
+
* an unparseable one) — such an order has no settled day and is NOT counted.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getSalesComparisonSettledLocalDate(order: Pick<IOrder, 'order_settled_at'> | null | undefined, gmtOffset?: number): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Adds one order's counters into `target` (mutates `target`).
|
|
37
|
+
*
|
|
38
|
+
* The order's `net_amount` is derived from ITS OWN gross/discount pair so the
|
|
39
|
+
* three counters always satisfy `net = gross − discount` leaf by leaf.
|
|
40
|
+
*/
|
|
41
|
+
export declare function addOrderToSalesComparisonCounters(target: IMaterializedSalesComparisonCounters, order: IOrder): void;
|
|
42
|
+
/** Adds every counter of `source` into `target` (mutates `target`). */
|
|
43
|
+
export declare function addSalesComparisonCounters(target: IMaterializedSalesComparisonCounters, source: IMaterializedSalesComparisonCounters | null | undefined): void;
|
|
44
|
+
/**
|
|
45
|
+
* Stable list of every additive counter, in display order. Kept in sync with
|
|
46
|
+
* the type module by the schema contract test.
|
|
47
|
+
*/
|
|
48
|
+
export declare const ALL_SALES_COMPARISON_COUNTER_FIELDS: readonly ["order_count", "gross_amount", "discount_amount", "net_amount", "tax_amount", "service_charge_amount", "tip_amount", "refund_amount", "void_amount", "item_count", "guest_count"];
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALL_SALES_COMPARISON_COUNTER_FIELDS = void 0;
|
|
4
|
+
exports.createEmptySalesComparisonCounters = createEmptySalesComparisonCounters;
|
|
5
|
+
exports.getOrderGrossAmountCents = getOrderGrossAmountCents;
|
|
6
|
+
exports.getOrderDiscountAmountCents = getOrderDiscountAmountCents;
|
|
7
|
+
exports.getOrderTaxAmountCents = getOrderTaxAmountCents;
|
|
8
|
+
exports.getOrderServiceChargeAmountCents = getOrderServiceChargeAmountCents;
|
|
9
|
+
exports.getOrderRefundAmountCents = getOrderRefundAmountCents;
|
|
10
|
+
exports.getOrderVoidAmountCents = getOrderVoidAmountCents;
|
|
11
|
+
exports.getOrderItemCount = getOrderItemCount;
|
|
12
|
+
exports.getOrderGuestCount = getOrderGuestCount;
|
|
13
|
+
exports.getSalesComparisonSettledLocalDate = getSalesComparisonSettledLocalDate;
|
|
14
|
+
exports.addOrderToSalesComparisonCounters = addOrderToSalesComparisonCounters;
|
|
15
|
+
exports.addSalesComparisonCounters = addSalesComparisonCounters;
|
|
16
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
17
|
+
/**
|
|
18
|
+
* Sales Comparison counter accumulation (see
|
|
19
|
+
* `console/admin-panel/docs/report-sales-comparison-concept.md` §6).
|
|
20
|
+
*
|
|
21
|
+
* ## Money mapping — deliberately grounded in the fields live orders carry
|
|
22
|
+
*
|
|
23
|
+
* The live order document has no single "net sales" field, and its fields do
|
|
24
|
+
* not nest the way their names suggest:
|
|
25
|
+
*
|
|
26
|
+
* | counter | source (all CENTS) | why |
|
|
27
|
+
* | --- | --- | --- |
|
|
28
|
+
* | `gross_amount` | `order.price` (fallback Σ item `_gross_amount`, then `subtotal`) | `price` is documented as the total item price WITHOUT discounts |
|
|
29
|
+
* | `discount_amount` | `order.total_discount_applied` → `order_discount_details.total_discount` | the same pair the overview materializer uses; `0` is a real value, so it must not fall through |
|
|
30
|
+
* | `net_amount` | `gross_amount − discount_amount` | standard net sales; equals Σ item `_net_amount` on live data |
|
|
31
|
+
* | `tax_amount` | `order.gst_amount + order.tax_amount` | live stores carry the collected tax in `gst_amount`; `tax_amount` is 0 there. The report has ONE tax counter, so both sum into it |
|
|
32
|
+
* | `service_charge_amount` | `order.service_fee_amount + order.surcharge_amount` | the report has ONE service-charge counter; surcharge is the other service-shaped charge. Both are absent on today's data (0), not guessed |
|
|
33
|
+
* | `tip_amount` | `order.tip_amount` | |
|
|
34
|
+
* | `refund_amount` | Σ `payments[].amount_refunded` | order-level refund money is only represented by its payment rows |
|
|
35
|
+
* | `void_amount` | `order.amount_earned` for a `CANCELLED` order, else 0 | voided order value. Item-level voids live in the SEPARATE `void_order_items` ledger, which a settled-sales report must not fold in without its own drill-down; the `CANCELLED` key is the order-derived void signal |
|
|
36
|
+
* | `item_count` | Σ `categories[].items[].quantity` | items sold, not line count |
|
|
37
|
+
* | `guest_count` | `dinein_details.num_of_guests` | 0 for non-dine-in |
|
|
38
|
+
*
|
|
39
|
+
* **Order count** counts every settled order, including `CANCELLED` — cancelled
|
|
40
|
+
* orders are keyed `CANCELLED:*` and are split out by the formatter, exactly
|
|
41
|
+
* like the overview.
|
|
42
|
+
*
|
|
43
|
+
* Every value is added AS-IS: the source amounts may carry fractional cents and
|
|
44
|
+
* the report must be decimal-exact, so no rounding happens here.
|
|
45
|
+
*/
|
|
46
|
+
/** Coerces a source amount to a finite number (0 when absent/broken). */
|
|
47
|
+
const cents = (value) => {
|
|
48
|
+
const number = typeof value === 'number' ? value : Number(value);
|
|
49
|
+
return Number.isFinite(number) ? number : 0;
|
|
50
|
+
};
|
|
51
|
+
const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
52
|
+
/** A zeroed counter block. */
|
|
53
|
+
function createEmptySalesComparisonCounters() {
|
|
54
|
+
return {
|
|
55
|
+
order_count: 0,
|
|
56
|
+
gross_amount: 0,
|
|
57
|
+
discount_amount: 0,
|
|
58
|
+
net_amount: 0,
|
|
59
|
+
tax_amount: 0,
|
|
60
|
+
service_charge_amount: 0,
|
|
61
|
+
tip_amount: 0,
|
|
62
|
+
refund_amount: 0,
|
|
63
|
+
void_amount: 0,
|
|
64
|
+
item_count: 0,
|
|
65
|
+
guest_count: 0,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Σ item `_gross_amount` (fallback `subtotal`) — only read when `order.price` is absent. */
|
|
69
|
+
const itemsGrossAmount = (order) => {
|
|
70
|
+
let total = 0;
|
|
71
|
+
for (const category of order?.categories ?? []) {
|
|
72
|
+
for (const item of category?.items ?? []) {
|
|
73
|
+
total += isFiniteNumber(item?._gross_amount) ? item._gross_amount : cents(item?.subtotal);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return total;
|
|
77
|
+
};
|
|
78
|
+
/** Gross sales in CENTS — BEFORE discounts. */
|
|
79
|
+
function getOrderGrossAmountCents(order) {
|
|
80
|
+
if (order == null)
|
|
81
|
+
return 0;
|
|
82
|
+
if (isFiniteNumber(order.price))
|
|
83
|
+
return order.price;
|
|
84
|
+
return itemsGrossAmount(order);
|
|
85
|
+
}
|
|
86
|
+
/** Discounts applied to the order, in CENTS. */
|
|
87
|
+
function getOrderDiscountAmountCents(order) {
|
|
88
|
+
if (order == null)
|
|
89
|
+
return 0;
|
|
90
|
+
if (isFiniteNumber(order.total_discount_applied))
|
|
91
|
+
return order.total_discount_applied;
|
|
92
|
+
return cents(order.order_discount_details?.total_discount);
|
|
93
|
+
}
|
|
94
|
+
/** Total tax collected, in CENTS (GST + the unused `tax_amount` bucket). */
|
|
95
|
+
function getOrderTaxAmountCents(order) {
|
|
96
|
+
if (order == null)
|
|
97
|
+
return 0;
|
|
98
|
+
return cents(order.gst_amount) + cents(order.tax_amount);
|
|
99
|
+
}
|
|
100
|
+
/** Service-shaped charges (service fee + surcharge), in CENTS. */
|
|
101
|
+
function getOrderServiceChargeAmountCents(order) {
|
|
102
|
+
if (order == null)
|
|
103
|
+
return 0;
|
|
104
|
+
return cents(order.service_fee_amount) + cents(order.surcharge_amount);
|
|
105
|
+
}
|
|
106
|
+
/** Refunded money across the order's payments, in CENTS. */
|
|
107
|
+
function getOrderRefundAmountCents(order) {
|
|
108
|
+
let total = 0;
|
|
109
|
+
for (const payment of order?.payments ?? []) {
|
|
110
|
+
total += cents(payment?.amount_refunded);
|
|
111
|
+
}
|
|
112
|
+
return total;
|
|
113
|
+
}
|
|
114
|
+
/** Voided (cancelled) order value, in CENTS. */
|
|
115
|
+
function getOrderVoidAmountCents(order) {
|
|
116
|
+
if (order == null)
|
|
117
|
+
return 0;
|
|
118
|
+
return order.order_status === ENUMS_1.ORDER_STATUS_ENUM.CANCELLED ? cents(order.amount_earned) : 0;
|
|
119
|
+
}
|
|
120
|
+
/** Items sold (Σ quantity), NOT line count. */
|
|
121
|
+
function getOrderItemCount(order) {
|
|
122
|
+
let total = 0;
|
|
123
|
+
for (const category of order?.categories ?? []) {
|
|
124
|
+
for (const item of category?.items ?? []) {
|
|
125
|
+
total += cents(item?.quantity);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return total;
|
|
129
|
+
}
|
|
130
|
+
/** Dine-in guest count (0 elsewhere). */
|
|
131
|
+
function getOrderGuestCount(order) {
|
|
132
|
+
return cents(order?.dinein_details?.num_of_guests);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The tenant-local calendar date of an order's SETTLEMENT instant.
|
|
136
|
+
*
|
|
137
|
+
* The anchor is `order_settled_at` — NEVER `order.localDate`, which is the
|
|
138
|
+
* PUNCH day. A deferred bill punched Monday and collected Wednesday belongs to
|
|
139
|
+
* Wednesday's comparison row (concept §3: no time bias, one fixed anchor).
|
|
140
|
+
*
|
|
141
|
+
* `gmtOffset` is the tenant GST offset in hours (`+5`). The local calendar date
|
|
142
|
+
* of an instant is the UTC date after shifting by that offset.
|
|
143
|
+
*
|
|
144
|
+
* Returns `null` for an order that was never settled (no `order_settled_at` or
|
|
145
|
+
* an unparseable one) — such an order has no settled day and is NOT counted.
|
|
146
|
+
*/
|
|
147
|
+
function getSalesComparisonSettledLocalDate(order, gmtOffset = 0) {
|
|
148
|
+
const raw = order?.order_settled_at;
|
|
149
|
+
if (raw == null)
|
|
150
|
+
return null;
|
|
151
|
+
const time = new Date(raw).getTime();
|
|
152
|
+
if (Number.isNaN(time))
|
|
153
|
+
return null;
|
|
154
|
+
const offset = Number.isFinite(gmtOffset) ? gmtOffset : 0;
|
|
155
|
+
return new Date(time + offset * 60 * 60 * 1000).toISOString().slice(0, 10);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Adds one order's counters into `target` (mutates `target`).
|
|
159
|
+
*
|
|
160
|
+
* The order's `net_amount` is derived from ITS OWN gross/discount pair so the
|
|
161
|
+
* three counters always satisfy `net = gross − discount` leaf by leaf.
|
|
162
|
+
*/
|
|
163
|
+
function addOrderToSalesComparisonCounters(target, order) {
|
|
164
|
+
if (target == null || order == null)
|
|
165
|
+
return;
|
|
166
|
+
const gross = getOrderGrossAmountCents(order);
|
|
167
|
+
const discount = getOrderDiscountAmountCents(order);
|
|
168
|
+
target.order_count += 1;
|
|
169
|
+
target.gross_amount += gross;
|
|
170
|
+
target.discount_amount += discount;
|
|
171
|
+
target.net_amount += gross - discount;
|
|
172
|
+
target.tax_amount += getOrderTaxAmountCents(order);
|
|
173
|
+
target.service_charge_amount += getOrderServiceChargeAmountCents(order);
|
|
174
|
+
target.tip_amount += cents(order.tip_amount);
|
|
175
|
+
target.refund_amount += getOrderRefundAmountCents(order);
|
|
176
|
+
target.void_amount += getOrderVoidAmountCents(order);
|
|
177
|
+
target.item_count += getOrderItemCount(order);
|
|
178
|
+
target.guest_count += getOrderGuestCount(order);
|
|
179
|
+
}
|
|
180
|
+
/** Adds every counter of `source` into `target` (mutates `target`). */
|
|
181
|
+
function addSalesComparisonCounters(target, source) {
|
|
182
|
+
if (target == null || source == null)
|
|
183
|
+
return;
|
|
184
|
+
for (const field of exports.ALL_SALES_COMPARISON_COUNTER_FIELDS) {
|
|
185
|
+
target[field] += cents(source[field]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Stable list of every additive counter, in display order. Kept in sync with
|
|
190
|
+
* the type module by the schema contract test.
|
|
191
|
+
*/
|
|
192
|
+
exports.ALL_SALES_COMPARISON_COUNTER_FIELDS = [
|
|
193
|
+
'order_count',
|
|
194
|
+
'gross_amount',
|
|
195
|
+
'discount_amount',
|
|
196
|
+
'net_amount',
|
|
197
|
+
'tax_amount',
|
|
198
|
+
'service_charge_amount',
|
|
199
|
+
'tip_amount',
|
|
200
|
+
'refund_amount',
|
|
201
|
+
'void_amount',
|
|
202
|
+
'item_count',
|
|
203
|
+
'guest_count',
|
|
204
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SALES_COMPARISON_BASELINE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IReportCalendarSelection } from '../types/report-calendar';
|
|
3
|
+
import { IGetMaterializedReportScopeGroup } from '../types/materialized-reports-apis';
|
|
4
|
+
/** The derived comparison window, as day keys. */
|
|
5
|
+
export interface ISalesComparisonBaselineRange {
|
|
6
|
+
start: string;
|
|
7
|
+
end: string;
|
|
8
|
+
/** Days inside the window AFTER the weekday refinement. */
|
|
9
|
+
days: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Derives the comparison window from a decoded selection.
|
|
13
|
+
*
|
|
14
|
+
* Returns `null` for `NONE` / an unservable selection; an entry with an empty
|
|
15
|
+
* `days` array means the window is valid but no day matches the refinement.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getSalesComparisonBaselineRange(selection: IReportCalendarSelection, baseline: SALES_COMPARISON_BASELINE_ENUM | string | null | undefined): ISalesComparisonBaselineRange | null;
|
|
18
|
+
/**
|
|
19
|
+
* Builds the comparison read's scope groups. Empty array = a valid baseline
|
|
20
|
+
* whose window contains no matching day (the read then folds to zero).
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildSalesComparisonBaselineScopeGroups(selection: IReportCalendarSelection, baseline: SALES_COMPARISON_BASELINE_ENUM | string | null | undefined): IGetMaterializedReportScopeGroup[] | null;
|