@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,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared report API contract — the single response shape used by BOTH source
|
|
3
|
+
* modes:
|
|
4
|
+
*
|
|
5
|
+
* - `LIVE` — aggregated from the raw collections (orders / deliveries /
|
|
6
|
+
* cash ledger) for a range that may include the open day;
|
|
7
|
+
* - `HISTORICAL` — read from the materialized collections for a closed range.
|
|
8
|
+
*
|
|
9
|
+
* The mode changes the SOURCE and the freshness metadata only. The `current` /
|
|
10
|
+
* `comparison` / `rows` payloads are the SAME type in both modes, so the admin
|
|
11
|
+
* panel uses one slice and one formatter and only switches the URL.
|
|
12
|
+
*/
|
|
13
|
+
export const REPORT_API_VERSION = 1;
|
|
14
|
+
export var REPORT_MODE_ENUM;
|
|
15
|
+
(function (REPORT_MODE_ENUM) {
|
|
16
|
+
REPORT_MODE_ENUM["LIVE"] = "LIVE";
|
|
17
|
+
REPORT_MODE_ENUM["HISTORICAL"] = "HISTORICAL";
|
|
18
|
+
})(REPORT_MODE_ENUM || (REPORT_MODE_ENUM = {}));
|
|
19
|
+
export const ALL_REPORT_MODES = Object.values(REPORT_MODE_ENUM);
|
|
20
|
+
/**
|
|
21
|
+
* Every report the operations service can serve. The list is deliberately
|
|
22
|
+
* complete including reports that are still being built, so the capability
|
|
23
|
+
* matrix is the single place the frontend asks "does this report have a Live
|
|
24
|
+
* view?".
|
|
25
|
+
*/
|
|
26
|
+
export var REPORT_KEY_ENUM;
|
|
27
|
+
(function (REPORT_KEY_ENUM) {
|
|
28
|
+
REPORT_KEY_ENUM["OVERVIEW"] = "OVERVIEW";
|
|
29
|
+
REPORT_KEY_ENUM["DISCOUNTS"] = "DISCOUNTS";
|
|
30
|
+
REPORT_KEY_ENUM["PREP_TIME"] = "PREP_TIME";
|
|
31
|
+
REPORT_KEY_ENUM["CASH_IN_OUT"] = "CASH_IN_OUT";
|
|
32
|
+
REPORT_KEY_ENUM["DELIVERY"] = "DELIVERY";
|
|
33
|
+
REPORT_KEY_ENUM["SALES_COMPARISON"] = "SALES_COMPARISON";
|
|
34
|
+
REPORT_KEY_ENUM["HOURLY_COMPARISON"] = "HOURLY_COMPARISON";
|
|
35
|
+
REPORT_KEY_ENUM["PAYMENTS_COMPARISON"] = "PAYMENTS_COMPARISON";
|
|
36
|
+
REPORT_KEY_ENUM["CREDIT_BILLS"] = "CREDIT_BILLS";
|
|
37
|
+
REPORT_KEY_ENUM["ITERATIONS"] = "ITERATIONS";
|
|
38
|
+
REPORT_KEY_ENUM["SUMMARY"] = "SUMMARY";
|
|
39
|
+
REPORT_KEY_ENUM["X_REPORT"] = "X_REPORT";
|
|
40
|
+
REPORT_KEY_ENUM["Z_REPORT"] = "Z_REPORT";
|
|
41
|
+
REPORT_KEY_ENUM["ITEMS"] = "ITEMS";
|
|
42
|
+
REPORT_KEY_ENUM["ITEMS_COMPARISON"] = "ITEMS_COMPARISON";
|
|
43
|
+
REPORT_KEY_ENUM["VOID_ITEMS"] = "VOID_ITEMS";
|
|
44
|
+
REPORT_KEY_ENUM["REVIEWS_RATINGS"] = "REVIEWS_RATINGS";
|
|
45
|
+
})(REPORT_KEY_ENUM || (REPORT_KEY_ENUM = {}));
|
|
46
|
+
export const ALL_REPORT_KEYS = Object.values(REPORT_KEY_ENUM);
|
|
47
|
+
/** URL segment of each report under `/reports` (shared by ops + admin). */
|
|
48
|
+
export const REPORT_ROUTE_SEGMENTS = {
|
|
49
|
+
[REPORT_KEY_ENUM.OVERVIEW]: 'overview',
|
|
50
|
+
[REPORT_KEY_ENUM.DISCOUNTS]: 'discounts',
|
|
51
|
+
[REPORT_KEY_ENUM.PREP_TIME]: 'prep-time',
|
|
52
|
+
[REPORT_KEY_ENUM.CASH_IN_OUT]: 'cash-in-out',
|
|
53
|
+
[REPORT_KEY_ENUM.DELIVERY]: 'delivery',
|
|
54
|
+
[REPORT_KEY_ENUM.SALES_COMPARISON]: 'sales-comparison',
|
|
55
|
+
[REPORT_KEY_ENUM.HOURLY_COMPARISON]: 'hourly-comparison',
|
|
56
|
+
[REPORT_KEY_ENUM.PAYMENTS_COMPARISON]: 'payments-comparison',
|
|
57
|
+
[REPORT_KEY_ENUM.CREDIT_BILLS]: 'credit-bills',
|
|
58
|
+
[REPORT_KEY_ENUM.ITERATIONS]: 'iterations',
|
|
59
|
+
[REPORT_KEY_ENUM.SUMMARY]: 'summary',
|
|
60
|
+
[REPORT_KEY_ENUM.X_REPORT]: 'x-report',
|
|
61
|
+
[REPORT_KEY_ENUM.Z_REPORT]: 'z-report',
|
|
62
|
+
[REPORT_KEY_ENUM.ITEMS]: 'items',
|
|
63
|
+
[REPORT_KEY_ENUM.ITEMS_COMPARISON]: 'items-comparison',
|
|
64
|
+
[REPORT_KEY_ENUM.VOID_ITEMS]: 'void-items',
|
|
65
|
+
[REPORT_KEY_ENUM.REVIEWS_RATINGS]: 'reviews-ratings',
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The one capability matrix. `live: false` means the frontend MUST NOT render
|
|
69
|
+
* a Live switch for that report; the backend enforces the same flag.
|
|
70
|
+
*
|
|
71
|
+
* Reports that are not implemented yet are explicitly false. Do not advertise
|
|
72
|
+
* a mode before its routes exist.
|
|
73
|
+
*/
|
|
74
|
+
export const REPORT_CAPABILITIES = {
|
|
75
|
+
// Contract routes that are implemented today. Everything else keeps its
|
|
76
|
+
// legacy single-mode route until the live/historical pair lands; the UI must
|
|
77
|
+
// not offer a mode that is not in this matrix.
|
|
78
|
+
[REPORT_KEY_ENUM.OVERVIEW]: { live: true, historical: true, details: false },
|
|
79
|
+
[REPORT_KEY_ENUM.SALES_COMPARISON]: { live: true, historical: true, details: true },
|
|
80
|
+
[REPORT_KEY_ENUM.DISCOUNTS]: { live: true, historical: true, details: true },
|
|
81
|
+
[REPORT_KEY_ENUM.PREP_TIME]: { live: true, historical: true, details: true },
|
|
82
|
+
[REPORT_KEY_ENUM.CASH_IN_OUT]: { live: true, historical: true, details: true },
|
|
83
|
+
[REPORT_KEY_ENUM.DELIVERY]: { live: true, historical: true, details: true },
|
|
84
|
+
[REPORT_KEY_ENUM.HOURLY_COMPARISON]: { live: true, historical: true, details: true },
|
|
85
|
+
[REPORT_KEY_ENUM.PAYMENTS_COMPARISON]: { live: true, historical: true, details: true },
|
|
86
|
+
[REPORT_KEY_ENUM.CREDIT_BILLS]: { live: false, historical: true, details: true },
|
|
87
|
+
[REPORT_KEY_ENUM.ITERATIONS]: { live: false, historical: false, details: false },
|
|
88
|
+
[REPORT_KEY_ENUM.SUMMARY]: { live: false, historical: false, details: false },
|
|
89
|
+
[REPORT_KEY_ENUM.X_REPORT]: { live: false, historical: false, details: false },
|
|
90
|
+
[REPORT_KEY_ENUM.Z_REPORT]: { live: false, historical: false, details: false },
|
|
91
|
+
[REPORT_KEY_ENUM.ITEMS]: { live: false, historical: false, details: false },
|
|
92
|
+
[REPORT_KEY_ENUM.ITEMS_COMPARISON]: { live: false, historical: false, details: false },
|
|
93
|
+
[REPORT_KEY_ENUM.VOID_ITEMS]: { live: false, historical: false, details: false },
|
|
94
|
+
[REPORT_KEY_ENUM.REVIEWS_RATINGS]: { live: false, historical: false, details: false },
|
|
95
|
+
};
|
|
96
|
+
export var REPORT_ERROR_CODE_ENUM;
|
|
97
|
+
(function (REPORT_ERROR_CODE_ENUM) {
|
|
98
|
+
REPORT_ERROR_CODE_ENUM["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
99
|
+
REPORT_ERROR_CODE_ENUM["SELECTION_TOO_LARGE"] = "SELECTION_TOO_LARGE";
|
|
100
|
+
REPORT_ERROR_CODE_ENUM["TOO_MANY_TENANTS"] = "TOO_MANY_TENANTS";
|
|
101
|
+
REPORT_ERROR_CODE_ENUM["LIVE_NOT_SUPPORTED"] = "LIVE_NOT_SUPPORTED";
|
|
102
|
+
REPORT_ERROR_CODE_ENUM["HISTORICAL_THROUGH_LAST_CLOSE"] = "HISTORICAL_THROUGH_LAST_CLOSE";
|
|
103
|
+
REPORT_ERROR_CODE_ENUM["TIME_WINDOW_NOT_SUPPORTED_LIVE"] = "TIME_WINDOW_NOT_SUPPORTED_LIVE";
|
|
104
|
+
REPORT_ERROR_CODE_ENUM["INVALID_BASELINE"] = "INVALID_BASELINE";
|
|
105
|
+
REPORT_ERROR_CODE_ENUM["INVALID_CURSOR"] = "INVALID_CURSOR";
|
|
106
|
+
})(REPORT_ERROR_CODE_ENUM || (REPORT_ERROR_CODE_ENUM = {}));
|
|
107
|
+
const isNonEmptyString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
108
|
+
const toIsoString = (value) => {
|
|
109
|
+
if (value == null)
|
|
110
|
+
return null;
|
|
111
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
112
|
+
if (Number.isNaN(date.getTime()))
|
|
113
|
+
return null;
|
|
114
|
+
return date.toISOString();
|
|
115
|
+
};
|
|
116
|
+
const isReportKey = (value) => typeof value === 'string' && ALL_REPORT_KEYS.includes(value);
|
|
117
|
+
const isReportMode = (value) => typeof value === 'string' && ALL_REPORT_MODES.includes(value);
|
|
118
|
+
/** Pure builder for the shared meta block. Returns null on invalid input. */
|
|
119
|
+
export function buildReportMeta(input) {
|
|
120
|
+
if (input == null || !isReportMode(input.mode))
|
|
121
|
+
return null;
|
|
122
|
+
const asOf = toIsoString(input.asOf);
|
|
123
|
+
if (asOf == null)
|
|
124
|
+
return null;
|
|
125
|
+
if (typeof input.final !== 'boolean')
|
|
126
|
+
return null;
|
|
127
|
+
const isLive = input.mode === REPORT_MODE_ENUM.LIVE;
|
|
128
|
+
const schemaVersion = input.schemaVersion ?? null;
|
|
129
|
+
const watermark = toIsoString(input.sourceWatermark ?? null);
|
|
130
|
+
// Live data never carries a materialized schema version / watermark.
|
|
131
|
+
if (isLive && (schemaVersion != null || input.sourceWatermark != null))
|
|
132
|
+
return null;
|
|
133
|
+
return {
|
|
134
|
+
api_version: REPORT_API_VERSION,
|
|
135
|
+
mode: input.mode,
|
|
136
|
+
as_of: asOf,
|
|
137
|
+
business_date: input.businessDate ?? null,
|
|
138
|
+
last_closed_date: input.lastClosedDate ?? null,
|
|
139
|
+
final: input.final,
|
|
140
|
+
schema_version: isLive ? null : schemaVersion,
|
|
141
|
+
source_watermark: isLive ? null : watermark,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** Pure builder for the shared report envelope. Returns null on invalid input. */
|
|
145
|
+
export function buildReportResponse(input) {
|
|
146
|
+
if (input == null || !isReportKey(input.report))
|
|
147
|
+
return null;
|
|
148
|
+
if (input.meta == null || input.meta.api_version !== REPORT_API_VERSION)
|
|
149
|
+
return null;
|
|
150
|
+
if (!Array.isArray(input.tenants) || input.tenants.length === 0)
|
|
151
|
+
return null;
|
|
152
|
+
if (input.tenants.some((tenant) => !isNonEmptyString(tenant)))
|
|
153
|
+
return null;
|
|
154
|
+
if (!Array.isArray(input.current))
|
|
155
|
+
return null;
|
|
156
|
+
if (input.comparison !== null && !Array.isArray(input.comparison))
|
|
157
|
+
return null;
|
|
158
|
+
return {
|
|
159
|
+
report: input.report,
|
|
160
|
+
meta: input.meta,
|
|
161
|
+
tenants: input.tenants.map((tenant) => tenant.trim()),
|
|
162
|
+
current: input.current,
|
|
163
|
+
comparison: input.comparison,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export function buildReportDetailsResponse(input) {
|
|
167
|
+
if (input == null || !isReportKey(input.report))
|
|
168
|
+
return null;
|
|
169
|
+
if (input.meta == null || input.meta.api_version !== REPORT_API_VERSION)
|
|
170
|
+
return null;
|
|
171
|
+
if (!Array.isArray(input.rows))
|
|
172
|
+
return null;
|
|
173
|
+
return {
|
|
174
|
+
report: input.report,
|
|
175
|
+
meta: input.meta,
|
|
176
|
+
rows: input.rows,
|
|
177
|
+
next_cursor: input.nextCursor ?? null,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export function buildReportAnalyticsResponse(input) {
|
|
181
|
+
if (input == null || !isNonEmptyString(input.analytics))
|
|
182
|
+
return null;
|
|
183
|
+
if (input.meta == null || input.meta.api_version !== REPORT_API_VERSION)
|
|
184
|
+
return null;
|
|
185
|
+
if (!Array.isArray(input.tenants) || input.tenants.length === 0)
|
|
186
|
+
return null;
|
|
187
|
+
if (input.tenants.some((tenant) => !isNonEmptyString(tenant)))
|
|
188
|
+
return null;
|
|
189
|
+
if (input.data === undefined)
|
|
190
|
+
return null;
|
|
191
|
+
return {
|
|
192
|
+
analytics: input.analytics.trim(),
|
|
193
|
+
meta: input.meta,
|
|
194
|
+
tenants: input.tenants.map((tenant) => tenant.trim()),
|
|
195
|
+
data: input.data,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
export function getReportCapabilities(report) {
|
|
199
|
+
if (!isReportKey(report))
|
|
200
|
+
return null;
|
|
201
|
+
return { ...REPORT_CAPABILITIES[report] };
|
|
202
|
+
}
|
|
203
|
+
export function isReportModeSupported(report, mode) {
|
|
204
|
+
const capabilities = getReportCapabilities(report);
|
|
205
|
+
if (capabilities == null || !isReportMode(mode))
|
|
206
|
+
return false;
|
|
207
|
+
return mode === REPORT_MODE_ENUM.LIVE ? capabilities.live : capabilities.historical;
|
|
208
|
+
}
|
|
209
|
+
/** Shared URL builder — ops routes and admin fetchers use the same segments. */
|
|
210
|
+
export function buildReportPath(report, mode, options = {}) {
|
|
211
|
+
if (!isReportKey(report) || !isReportMode(mode))
|
|
212
|
+
return null;
|
|
213
|
+
if (!isReportModeSupported(report, mode))
|
|
214
|
+
return null;
|
|
215
|
+
if (options.details === true && !REPORT_CAPABILITIES[report].details)
|
|
216
|
+
return null;
|
|
217
|
+
const segment = REPORT_ROUTE_SEGMENTS[report];
|
|
218
|
+
return `/reports/${segment}${options.details === true ? '/details' : ''}/${mode.toLowerCase()}`;
|
|
219
|
+
}
|
|
220
|
+
export function buildReportError(code, message, details) {
|
|
221
|
+
return {
|
|
222
|
+
error: {
|
|
223
|
+
code,
|
|
224
|
+
message,
|
|
225
|
+
...(details === undefined ? {} : { details }),
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rider-earnings';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { RIDER_FEE_TYPE_ENUM } from '../../constants/enums/delivery';
|
|
2
|
+
const rawPerMeter = (value) => {
|
|
3
|
+
const numeric = Number(value);
|
|
4
|
+
return Number.isFinite(numeric) && numeric > 0 ? numeric : 0;
|
|
5
|
+
};
|
|
6
|
+
const nonNegative = (value) => {
|
|
7
|
+
const numeric = Number(value);
|
|
8
|
+
return Number.isFinite(numeric) && numeric > 0 ? numeric : 0;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Rounds the distance UP to the configured step. A step of 0/negative means
|
|
12
|
+
* "do not round", matching the delivery-cost branch that only rounds when the
|
|
13
|
+
* setting is truthy.
|
|
14
|
+
*/
|
|
15
|
+
export function roundRiderFeeDistance(distanceMeters, stepMeters) {
|
|
16
|
+
const distance = nonNegative(distanceMeters);
|
|
17
|
+
const step = nonNegative(stepMeters);
|
|
18
|
+
if (step <= 0 || distance <= 0)
|
|
19
|
+
return distance;
|
|
20
|
+
return Math.ceil(distance / step) * step;
|
|
21
|
+
}
|
|
22
|
+
export function calculateRiderFee(input) {
|
|
23
|
+
const rule = input?.rule;
|
|
24
|
+
const type = rule?.rider_revenue_type ?? RIDER_FEE_TYPE_ENUM.NONE;
|
|
25
|
+
const perMeter = rawPerMeter(rule?.rider_revenue_per_meter);
|
|
26
|
+
const distanceStep = nonNegative(rule?.static_rider_revenue_multiplier);
|
|
27
|
+
const deliveryCharge = nonNegative(input?.delivery_charge_cents);
|
|
28
|
+
const roundedDistance = roundRiderFeeDistance(nonNegative(input?.distance_meters), distanceStep);
|
|
29
|
+
let baseAmount = 0;
|
|
30
|
+
if (type === RIDER_FEE_TYPE_ENUM.DELIVERY_CHARGES_FULL) {
|
|
31
|
+
baseAmount = deliveryCharge;
|
|
32
|
+
}
|
|
33
|
+
else if (type === RIDER_FEE_TYPE_ENUM.DISTANCE_ONE_WAY) {
|
|
34
|
+
// raw per-metre value is scaled by 100000; /1000 turns
|
|
35
|
+
// (metres * raw) into cents.
|
|
36
|
+
baseAmount = Math.round((roundedDistance * perMeter) / 1000);
|
|
37
|
+
}
|
|
38
|
+
else if (type === RIDER_FEE_TYPE_ENUM.DISTANCE_RETURN) {
|
|
39
|
+
baseAmount = Math.round((roundedDistance * perMeter * 2) / 1000);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
baseAmount = 0;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
amount_cents: baseAmount,
|
|
46
|
+
base_amount_cents: baseAmount,
|
|
47
|
+
rounded_distance_meters: roundedDistance,
|
|
48
|
+
rule_type: type,
|
|
49
|
+
per_meter: perMeter,
|
|
50
|
+
distance_step: distanceStep,
|
|
51
|
+
delivery_charge_cents: deliveryCharge,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DELIVERY_STATUS_ENUM, RIDER_EARNINGS_STATUS_ENUM } from '../../constants/enums/delivery';
|
|
2
|
+
import { MATERIALIZED_RIDER_DAILY_REPORTS_SCHEMA_VERSION } from '../../schemas/models/materialized_rider_daily_reports';
|
|
3
|
+
const completedOrCancelled = (status) => status === DELIVERY_STATUS_ENUM.COMPLETED || status === DELIVERY_STATUS_ENUM.CANCELLED;
|
|
4
|
+
const finalEarnings = (delivery) => {
|
|
5
|
+
const earnings = delivery.rider_earnings;
|
|
6
|
+
if (earnings != null) {
|
|
7
|
+
return earnings.status === RIDER_EARNINGS_STATUS_ENUM.FINAL ? Number(earnings.amount) || 0 : 0;
|
|
8
|
+
}
|
|
9
|
+
return Number(delivery.rider_revenue) || 0;
|
|
10
|
+
};
|
|
11
|
+
export function buildRiderDailyReport({ rider_id, local_date, deliveries, computedAt = new Date(), }) {
|
|
12
|
+
if (rider_id.trim() === '' || local_date.trim() === '')
|
|
13
|
+
return null;
|
|
14
|
+
const rows = (deliveries ?? []).filter((delivery) => completedOrCancelled(delivery?.status));
|
|
15
|
+
if (rows.length === 0)
|
|
16
|
+
return null;
|
|
17
|
+
const tenants = {};
|
|
18
|
+
let deliveriesCount = 0;
|
|
19
|
+
let completed = 0;
|
|
20
|
+
let cancelled = 0;
|
|
21
|
+
let earnings = 0;
|
|
22
|
+
let distanceMeters = 0;
|
|
23
|
+
let onTime = 0;
|
|
24
|
+
let late = 0;
|
|
25
|
+
let firstDeliveryAt = null;
|
|
26
|
+
let lastDeliveryAt = null;
|
|
27
|
+
for (const delivery of rows) {
|
|
28
|
+
const tenantId = delivery.tenant_id == null ? '' : String(delivery.tenant_id);
|
|
29
|
+
if (tenantId === '')
|
|
30
|
+
continue;
|
|
31
|
+
const isCompleted = delivery.status === DELIVERY_STATUS_ENUM.COMPLETED;
|
|
32
|
+
const isCancelled = delivery.status === DELIVERY_STATUS_ENUM.CANCELLED;
|
|
33
|
+
const earning = finalEarnings(delivery);
|
|
34
|
+
const distance = Number(delivery.distance_in_meters_from_store) || 0;
|
|
35
|
+
const tenant = (tenants[tenantId] ?? (tenants[tenantId] = {
|
|
36
|
+
deliveries: 0,
|
|
37
|
+
completed: 0,
|
|
38
|
+
cancelled: 0,
|
|
39
|
+
earnings: 0,
|
|
40
|
+
distance_meters: 0,
|
|
41
|
+
}));
|
|
42
|
+
tenant.deliveries += 1;
|
|
43
|
+
tenant.completed += isCompleted ? 1 : 0;
|
|
44
|
+
tenant.cancelled += isCancelled ? 1 : 0;
|
|
45
|
+
tenant.earnings += earning;
|
|
46
|
+
tenant.distance_meters += distance;
|
|
47
|
+
deliveriesCount += 1;
|
|
48
|
+
completed += isCompleted ? 1 : 0;
|
|
49
|
+
cancelled += isCancelled ? 1 : 0;
|
|
50
|
+
earnings += earning;
|
|
51
|
+
distanceMeters += distance;
|
|
52
|
+
const expected = delivery.expected_delivery_at == null ? null : new Date(delivery.expected_delivery_at);
|
|
53
|
+
const delivered = delivery.delivered_at == null ? null : new Date(delivery.delivered_at);
|
|
54
|
+
if (expected != null &&
|
|
55
|
+
!Number.isNaN(expected.getTime()) &&
|
|
56
|
+
delivered != null &&
|
|
57
|
+
!Number.isNaN(delivered.getTime())) {
|
|
58
|
+
if (delivered <= expected)
|
|
59
|
+
onTime += 1;
|
|
60
|
+
else
|
|
61
|
+
late += 1;
|
|
62
|
+
}
|
|
63
|
+
const createdAt = delivery.createdAt == null ? null : new Date(delivery.createdAt);
|
|
64
|
+
if (createdAt != null && !Number.isNaN(createdAt.getTime())) {
|
|
65
|
+
if (firstDeliveryAt == null || createdAt < firstDeliveryAt)
|
|
66
|
+
firstDeliveryAt = createdAt;
|
|
67
|
+
if (lastDeliveryAt == null || createdAt > lastDeliveryAt)
|
|
68
|
+
lastDeliveryAt = createdAt;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (deliveriesCount === 0)
|
|
72
|
+
return null;
|
|
73
|
+
return {
|
|
74
|
+
rider_id,
|
|
75
|
+
local_date,
|
|
76
|
+
deliveries: deliveriesCount,
|
|
77
|
+
completed,
|
|
78
|
+
cancelled,
|
|
79
|
+
earnings,
|
|
80
|
+
distance_meters: distanceMeters,
|
|
81
|
+
on_time: onTime,
|
|
82
|
+
late,
|
|
83
|
+
tenants,
|
|
84
|
+
first_delivery_at: firstDeliveryAt,
|
|
85
|
+
last_delivery_at: lastDeliveryAt,
|
|
86
|
+
schema_version: MATERIALIZED_RIDER_DAILY_REPORTS_SCHEMA_VERSION,
|
|
87
|
+
source_watermark: computedAt,
|
|
88
|
+
computed_at: computedAt,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure mapping from materialized rider-day documents to the rider app report.
|
|
3
|
+
* The tenant-name lookup stays in the backend adapter.
|
|
4
|
+
*/
|
|
5
|
+
export function buildRiderReport({ rider_id, from, to, documents, tenantNames = {}, }) {
|
|
6
|
+
const days = [];
|
|
7
|
+
const tenants = new Map();
|
|
8
|
+
const totals = {
|
|
9
|
+
deliveries: 0,
|
|
10
|
+
completed: 0,
|
|
11
|
+
cancelled: 0,
|
|
12
|
+
earnings: 0,
|
|
13
|
+
distance_meters: 0,
|
|
14
|
+
on_time: 0,
|
|
15
|
+
late: 0,
|
|
16
|
+
active_days: 0,
|
|
17
|
+
};
|
|
18
|
+
for (const doc of documents ?? []) {
|
|
19
|
+
const localDate = String(doc.local_date ?? '');
|
|
20
|
+
if (localDate === '')
|
|
21
|
+
continue;
|
|
22
|
+
const day = {
|
|
23
|
+
local_date: localDate,
|
|
24
|
+
deliveries: Number(doc.deliveries) || 0,
|
|
25
|
+
completed: Number(doc.completed) || 0,
|
|
26
|
+
cancelled: Number(doc.cancelled) || 0,
|
|
27
|
+
earnings: Number(doc.earnings) || 0,
|
|
28
|
+
distance_meters: Number(doc.distance_meters) || 0,
|
|
29
|
+
on_time: Number(doc.on_time) || 0,
|
|
30
|
+
late: Number(doc.late) || 0,
|
|
31
|
+
};
|
|
32
|
+
days.push(day);
|
|
33
|
+
for (const [tenantId, row] of Object.entries(doc.tenants ?? {})) {
|
|
34
|
+
const tenant = tenants.get(tenantId) ?? {
|
|
35
|
+
tenant_id: tenantId,
|
|
36
|
+
tenant_name: tenantNames[tenantId] ?? null,
|
|
37
|
+
deliveries: 0,
|
|
38
|
+
completed: 0,
|
|
39
|
+
cancelled: 0,
|
|
40
|
+
earnings: 0,
|
|
41
|
+
distance_meters: 0,
|
|
42
|
+
};
|
|
43
|
+
tenant.deliveries += Number(row.deliveries) || 0;
|
|
44
|
+
tenant.completed += Number(row.completed) || 0;
|
|
45
|
+
tenant.cancelled += Number(row.cancelled) || 0;
|
|
46
|
+
tenant.earnings += Number(row.earnings) || 0;
|
|
47
|
+
tenant.distance_meters += Number(row.distance_meters) || 0;
|
|
48
|
+
tenants.set(tenantId, tenant);
|
|
49
|
+
}
|
|
50
|
+
totals.deliveries += day.deliveries;
|
|
51
|
+
totals.completed += day.completed;
|
|
52
|
+
totals.cancelled += day.cancelled;
|
|
53
|
+
totals.earnings += day.earnings;
|
|
54
|
+
totals.distance_meters += day.distance_meters;
|
|
55
|
+
totals.on_time += day.on_time;
|
|
56
|
+
totals.late += day.late;
|
|
57
|
+
}
|
|
58
|
+
totals.active_days = days.length;
|
|
59
|
+
return {
|
|
60
|
+
rider_id,
|
|
61
|
+
from,
|
|
62
|
+
to,
|
|
63
|
+
totals,
|
|
64
|
+
days,
|
|
65
|
+
tenants: [...tenants.values()].sort((a, b) => b.earnings - a.earnings),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -313,9 +313,10 @@ export function generateOrderIteration(order, partial = true, skipItemMetadata,
|
|
|
313
313
|
};
|
|
314
314
|
if (partial) {
|
|
315
315
|
// delete all undefined keys
|
|
316
|
+
const mutable = iteration;
|
|
316
317
|
Object.keys(iteration).forEach((key) => {
|
|
317
|
-
if (
|
|
318
|
-
delete
|
|
318
|
+
if (mutable[key] === undefined) {
|
|
319
|
+
delete mutable[key];
|
|
319
320
|
}
|
|
320
321
|
});
|
|
321
322
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
import { ALL_CURRENCY_SYMBOLS, ALL_DELIVERY_STATUS, CURRENCY_SYMBOL_ENUM, DELIVERY_STATUS_ENUM } from '../../constants';
|
|
2
|
+
import { ALL_CURRENCY_SYMBOLS, ALL_DELIVERY_STATUS, ALL_RIDER_EARNINGS_STATUS, ALL_RIDER_FEE_TYPES, CURRENCY_SYMBOL_ENUM, DELIVERY_STATUS_ENUM, RIDER_EARNINGS_STATUS_ENUM, RIDER_FEE_TYPE_ENUM, } from '../../constants';
|
|
3
3
|
export const DeliveriesSchema = new Schema({
|
|
4
4
|
_id: {
|
|
5
5
|
type: Schema.Types.ObjectId,
|
|
@@ -64,6 +64,12 @@ export const DeliveriesSchema = new Schema({
|
|
|
64
64
|
type: String,
|
|
65
65
|
required: false,
|
|
66
66
|
},
|
|
67
|
+
/** Tenant-local business date, copied from the order at creation. */
|
|
68
|
+
localDate: {
|
|
69
|
+
type: String,
|
|
70
|
+
required: false,
|
|
71
|
+
default: null,
|
|
72
|
+
},
|
|
67
73
|
polyline: {
|
|
68
74
|
type: [[Number, Number]],
|
|
69
75
|
required: true,
|
|
@@ -90,6 +96,81 @@ export const DeliveriesSchema = new Schema({
|
|
|
90
96
|
type: Boolean,
|
|
91
97
|
required: false,
|
|
92
98
|
},
|
|
99
|
+
// ---- Delivery metrics capture (M4, owner-approved) ----
|
|
100
|
+
//
|
|
101
|
+
// ALL SIX ARE OPTIONAL AND NULLABLE, which is what makes the addition safe:
|
|
102
|
+
// existing documents stay valid, a rider app that has not been updated simply
|
|
103
|
+
// leaves them null, and the report reads null as "not instrumented" rather than
|
|
104
|
+
// as zero - the same honesty rule as the prep time report's UNMEASURED bucket.
|
|
105
|
+
//
|
|
106
|
+
// Each timestamp is stamped ONCE on FIRST ENTRY to its state and never
|
|
107
|
+
// overwritten, mirroring how `closing.difference` is frozen at close in the cash
|
|
108
|
+
// drawer session. `updatedAt` moves on ANY mutation (a note edit, an image
|
|
109
|
+
// upload), which is exactly why these exact instants are needed.
|
|
110
|
+
assigned_at: {
|
|
111
|
+
type: Schema.Types.Date,
|
|
112
|
+
required: false,
|
|
113
|
+
default: null,
|
|
114
|
+
},
|
|
115
|
+
picked_up_at: {
|
|
116
|
+
type: Schema.Types.Date,
|
|
117
|
+
required: false,
|
|
118
|
+
default: null,
|
|
119
|
+
},
|
|
120
|
+
expected_delivery_at: {
|
|
121
|
+
type: Schema.Types.Date,
|
|
122
|
+
required: false,
|
|
123
|
+
default: null,
|
|
124
|
+
},
|
|
125
|
+
delivered_at: {
|
|
126
|
+
type: Schema.Types.Date,
|
|
127
|
+
required: false,
|
|
128
|
+
default: null,
|
|
129
|
+
},
|
|
130
|
+
cancelled_at: {
|
|
131
|
+
type: Schema.Types.Date,
|
|
132
|
+
required: false,
|
|
133
|
+
default: null,
|
|
134
|
+
},
|
|
135
|
+
/** Incremented on EVERY status write - detects churn no timestamp can express. */
|
|
136
|
+
status_updated_count: {
|
|
137
|
+
type: Number,
|
|
138
|
+
required: false,
|
|
139
|
+
min: 0,
|
|
140
|
+
default: 0,
|
|
141
|
+
},
|
|
142
|
+
/** Stored duration at COMPLETED, mirroring the proven `ready_minutes` precedent. */
|
|
143
|
+
delivery_minutes: {
|
|
144
|
+
type: Number,
|
|
145
|
+
required: false,
|
|
146
|
+
min: 0,
|
|
147
|
+
default: null,
|
|
148
|
+
},
|
|
149
|
+
rider_earnings: {
|
|
150
|
+
type: new Schema({
|
|
151
|
+
amount: { type: Number, required: true, min: 0, default: 0 },
|
|
152
|
+
status: {
|
|
153
|
+
type: String,
|
|
154
|
+
required: true,
|
|
155
|
+
enum: ALL_RIDER_EARNINGS_STATUS,
|
|
156
|
+
default: RIDER_EARNINGS_STATUS_ENUM.PENDING,
|
|
157
|
+
},
|
|
158
|
+
rule_type: {
|
|
159
|
+
type: String,
|
|
160
|
+
required: true,
|
|
161
|
+
enum: ALL_RIDER_FEE_TYPES,
|
|
162
|
+
default: RIDER_FEE_TYPE_ENUM.NONE,
|
|
163
|
+
},
|
|
164
|
+
per_meter: { type: Number, required: true, min: 0, default: 0 },
|
|
165
|
+
distance_step: { type: Number, required: true, min: 0, default: 0 },
|
|
166
|
+
distance_meters: { type: Number, required: true, min: 0, default: 0 },
|
|
167
|
+
delivery_charge: { type: Number, required: true, min: 0, default: 0 },
|
|
168
|
+
calculated_at: { type: Schema.Types.Date, default: null },
|
|
169
|
+
version: { type: Number, required: true, min: 1, default: 1 },
|
|
170
|
+
}, { _id: false }),
|
|
171
|
+
required: false,
|
|
172
|
+
default: null,
|
|
173
|
+
},
|
|
93
174
|
createdAt_mins: {
|
|
94
175
|
type: Number,
|
|
95
176
|
required: true,
|
|
@@ -28,7 +28,22 @@ export * from './item_transactions';
|
|
|
28
28
|
export * from './items';
|
|
29
29
|
export * from './marketing_fingerprints';
|
|
30
30
|
export * from './materialized_credit_bills';
|
|
31
|
+
export * from './materialized_tenant_discount_entries';
|
|
32
|
+
export * from './materialized_tenant_discount_reports';
|
|
33
|
+
export * from './materialized_tenant_cash_entries';
|
|
34
|
+
export * from './materialized_tenant_delivery_entries';
|
|
35
|
+
export * from './materialized_tenant_delivery_reports';
|
|
36
|
+
export * from './materialized_rider_daily_reports';
|
|
37
|
+
export * from './materialized_tenant_cash_reports';
|
|
38
|
+
export * from './materialized_tenant_prep_time_entries';
|
|
39
|
+
export * from './materialized_tenant_prep_time_reports';
|
|
31
40
|
export * from './materialized_tenant_reports_iterations';
|
|
41
|
+
export * from './materialized_tenant_sales_comparison_entries';
|
|
42
|
+
export * from './materialized_tenant_sales_comparison_reports';
|
|
43
|
+
export * from './materialized_tenant_hourly_comparison_entries';
|
|
44
|
+
export * from './materialized_tenant_hourly_comparison_reports';
|
|
45
|
+
export * from './materialized_tenant_payments_comparison_entries';
|
|
46
|
+
export * from './materialized_tenant_payments_comparison_reports';
|
|
32
47
|
export * from './materialized_tenant_sales_overview_reports';
|
|
33
48
|
export * from './menus';
|
|
34
49
|
export * from './messaging_devices';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
/**
|
|
3
|
+
* Mongoose schema for `materialized_rider_daily_reports`.
|
|
4
|
+
*
|
|
5
|
+
* The tenant breakdown is Mixed because its keys are tenant ids (data). The
|
|
6
|
+
* rider/day pair is the only unique identity.
|
|
7
|
+
*/
|
|
8
|
+
export const MATERIALIZED_RIDER_DAILY_REPORTS_SCHEMA_VERSION = 1;
|
|
9
|
+
export const MATERIALIZED_RIDER_DAILY_REPORTS_COLLECTION_NAME = 'materialized_rider_daily_reports';
|
|
10
|
+
export const MaterializedRiderDailyReportSchema = new Schema({
|
|
11
|
+
rider_id: { type: String, required: true },
|
|
12
|
+
local_date: { type: String, required: true },
|
|
13
|
+
deliveries: { type: Number, required: true, min: 0, default: 0 },
|
|
14
|
+
completed: { type: Number, required: true, min: 0, default: 0 },
|
|
15
|
+
cancelled: { type: Number, required: true, min: 0, default: 0 },
|
|
16
|
+
earnings: { type: Number, required: true, min: 0, default: 0 },
|
|
17
|
+
distance_meters: { type: Number, required: true, min: 0, default: 0 },
|
|
18
|
+
on_time: { type: Number, required: true, min: 0, default: 0 },
|
|
19
|
+
late: { type: Number, required: true, min: 0, default: 0 },
|
|
20
|
+
tenants: { type: Schema.Types.Mixed, required: true, default: {} },
|
|
21
|
+
first_delivery_at: { type: Schema.Types.Date, default: null },
|
|
22
|
+
last_delivery_at: { type: Schema.Types.Date, default: null },
|
|
23
|
+
schema_version: {
|
|
24
|
+
type: Number,
|
|
25
|
+
required: true,
|
|
26
|
+
immutable: true,
|
|
27
|
+
default: MATERIALIZED_RIDER_DAILY_REPORTS_SCHEMA_VERSION,
|
|
28
|
+
},
|
|
29
|
+
source_watermark: { type: Schema.Types.Date, required: true },
|
|
30
|
+
computed_at: { type: Schema.Types.Date, required: true },
|
|
31
|
+
}, { timestamps: true, versionKey: false, minimize: false });
|
|
32
|
+
MaterializedRiderDailyReportSchema.index({ rider_id: 1, local_date: 1 }, { unique: true, name: 'rider_id__local_date' });
|
|
33
|
+
export const MATERIALIZED_RIDER_DAILY_REPORTS_INDEX_OPTIONS = [
|
|
34
|
+
{
|
|
35
|
+
key: { rider_id: 1, local_date: 1 },
|
|
36
|
+
name: 'rider_id__local_date',
|
|
37
|
+
unique: true,
|
|
38
|
+
},
|
|
39
|
+
];
|