@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,18 @@
|
|
|
1
|
+
import { IMaterializedCashCounters } from '../../schemas/types/materialized_tenant_cash_reports';
|
|
2
|
+
import { freshCashCounters } from './materialized-cash-classification-helpers';
|
|
3
|
+
/**
|
|
4
|
+
* Merges `source` into `target`, IN PLACE. Used to fold day counters into a period.
|
|
5
|
+
*
|
|
6
|
+
* Null-safe: a source block missing a sub-object is treated as zeroes rather than
|
|
7
|
+
* throwing, so one malformed historical document cannot break a whole fold.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeMaterializedCashCounters(target: IMaterializedCashCounters, source: IMaterializedCashCounters): IMaterializedCashCounters;
|
|
10
|
+
/**
|
|
11
|
+
* Recomputes every DERIVED value from the summed components, in place.
|
|
12
|
+
*
|
|
13
|
+
* This is what makes a folded document self-consistent: the nets and the `by_ref`
|
|
14
|
+
* totals are always a function of the counts and amounts beside them.
|
|
15
|
+
*/
|
|
16
|
+
export declare function recalculateCashDerived(counters: IMaterializedCashCounters): void;
|
|
17
|
+
/** A fresh zeroed block - re-exported so callers fold from the same seed. */
|
|
18
|
+
export { freshCashCounters };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.freshCashCounters = void 0;
|
|
4
|
+
exports.mergeMaterializedCashCounters = mergeMaterializedCashCounters;
|
|
5
|
+
exports.recalculateCashDerived = recalculateCashDerived;
|
|
6
|
+
const cash_1 = require("../../constants/enums/cash");
|
|
7
|
+
const materialized_cash_classification_helpers_1 = require("./materialized-cash-classification-helpers");
|
|
8
|
+
Object.defineProperty(exports, "freshCashCounters", { enumerable: true, get: function () { return materialized_cash_classification_helpers_1.freshCashCounters; } });
|
|
9
|
+
/**
|
|
10
|
+
* M3 cash - folding counters across days into a PERIOD document.
|
|
11
|
+
*
|
|
12
|
+
* Two rules, and both exist because cash has non-additive quantities:
|
|
13
|
+
*
|
|
14
|
+
* 1. **Derived values are RECOMPUTED, never summed.** `ledger_net`, `operator.net`,
|
|
15
|
+
* `system.net` and every `by_ref` total are all `in - out`. They happen to be
|
|
16
|
+
* linear here, but recomputing from the summed parts means a future change to a
|
|
17
|
+
* definition cannot silently desynchronize a period total from its components.
|
|
18
|
+
* 2. **`staff_count` is a UNION, not a sum.** It counts DISTINCT staff, so adding two
|
|
19
|
+
* days double-counts anyone who worked both. The fold unions the stored id sets.
|
|
20
|
+
* A period document therefore cannot be produced by summing day documents alone -
|
|
21
|
+
* which is the same reason the prep time report stores its histogram rows.
|
|
22
|
+
*
|
|
23
|
+
* Period documents are always RE-FOLDED from the day documents rather than
|
|
24
|
+
* incremented in place: you cannot subtract a distinct count, so an incremental
|
|
25
|
+
* update could never undo a removed day.
|
|
26
|
+
*/
|
|
27
|
+
const addFlow = (target, source) => {
|
|
28
|
+
target.in_count += Number(source?.in_count) || 0;
|
|
29
|
+
target.in_amount += Number(source?.in_amount) || 0;
|
|
30
|
+
target.out_count += Number(source?.out_count) || 0;
|
|
31
|
+
target.out_amount += Number(source?.out_amount) || 0;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Merges `source` into `target`, IN PLACE. Used to fold day counters into a period.
|
|
35
|
+
*
|
|
36
|
+
* Null-safe: a source block missing a sub-object is treated as zeroes rather than
|
|
37
|
+
* throwing, so one malformed historical document cannot break a whole fold.
|
|
38
|
+
*/
|
|
39
|
+
function mergeMaterializedCashCounters(target, source) {
|
|
40
|
+
var _a;
|
|
41
|
+
if (target == null || source == null)
|
|
42
|
+
return target;
|
|
43
|
+
const t = target.movements;
|
|
44
|
+
const s = source.movements;
|
|
45
|
+
if (t != null && s != null) {
|
|
46
|
+
t.count += Number(s.count) || 0;
|
|
47
|
+
t.in_count += Number(s.in_count) || 0;
|
|
48
|
+
t.in_amount += Number(s.in_amount) || 0;
|
|
49
|
+
t.out_count += Number(s.out_count) || 0;
|
|
50
|
+
t.out_amount += Number(s.out_amount) || 0;
|
|
51
|
+
if (t.operator != null && s.operator != null) {
|
|
52
|
+
addFlow(t.operator, s.operator);
|
|
53
|
+
t.operator.count += Number(s.operator.count) || 0;
|
|
54
|
+
}
|
|
55
|
+
if (t.system != null && s.system != null) {
|
|
56
|
+
addFlow(t.system, s.system);
|
|
57
|
+
t.system.count += Number(s.system.count) || 0;
|
|
58
|
+
}
|
|
59
|
+
if (t.lifecycle != null && s.lifecycle != null) {
|
|
60
|
+
t.lifecycle.float_count += Number(s.lifecycle.float_count) || 0;
|
|
61
|
+
t.lifecycle.float_amount += Number(s.lifecycle.float_amount) || 0;
|
|
62
|
+
t.lifecycle.reopen_count += Number(s.lifecycle.reopen_count) || 0;
|
|
63
|
+
t.lifecycle.reopen_amount += Number(s.lifecycle.reopen_amount) || 0;
|
|
64
|
+
t.lifecycle.countout_count += Number(s.lifecycle.countout_count) || 0;
|
|
65
|
+
t.lifecycle.countout_amount += Number(s.lifecycle.countout_amount) || 0;
|
|
66
|
+
}
|
|
67
|
+
t.by_ref ?? (t.by_ref = {});
|
|
68
|
+
for (const refType of Object.values(cash_1.CASH_IN_OUT_REF_ENUM)) {
|
|
69
|
+
const sourceFlow = s.by_ref?.[refType];
|
|
70
|
+
if (sourceFlow == null)
|
|
71
|
+
continue;
|
|
72
|
+
(_a = t.by_ref)[refType] ?? (_a[refType] = { in_count: 0, in_amount: 0, out_count: 0, out_amount: 0 });
|
|
73
|
+
addFlow(t.by_ref[refType], sourceFlow);
|
|
74
|
+
}
|
|
75
|
+
// UNION the rosters - never add the counts.
|
|
76
|
+
const roster = new Set(t.staff_ids ?? []);
|
|
77
|
+
for (const id of s.staff_ids ?? [])
|
|
78
|
+
roster.add(String(id));
|
|
79
|
+
t.staff_ids = [...roster].sort();
|
|
80
|
+
t.staff_count = t.staff_ids.length;
|
|
81
|
+
}
|
|
82
|
+
const ts = target.sessions;
|
|
83
|
+
const ss = source.sessions;
|
|
84
|
+
if (ts != null && ss != null) {
|
|
85
|
+
ts.session_count += Number(ss.session_count) || 0;
|
|
86
|
+
ts.reopen_count += Number(ss.reopen_count) || 0;
|
|
87
|
+
ts.reopened_session_count += Number(ss.reopened_session_count) || 0;
|
|
88
|
+
ts.opening_float_amount += Number(ss.opening_float_amount) || 0;
|
|
89
|
+
ts.net_movements_amount += Number(ss.net_movements_amount) || 0;
|
|
90
|
+
ts.expected_close_amount += Number(ss.expected_close_amount) || 0;
|
|
91
|
+
ts.counted_close_amount += Number(ss.counted_close_amount) || 0;
|
|
92
|
+
ts.variance_amount += Number(ss.variance_amount) || 0;
|
|
93
|
+
ts.variance_positive_count += Number(ss.variance_positive_count) || 0;
|
|
94
|
+
ts.variance_negative_count += Number(ss.variance_negative_count) || 0;
|
|
95
|
+
ts.open_sessions_count += Number(ss.open_sessions_count) || 0;
|
|
96
|
+
ts.unmatched_close_count += Number(ss.unmatched_close_count) || 0;
|
|
97
|
+
}
|
|
98
|
+
recalculateCashDerived(target);
|
|
99
|
+
return target;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Recomputes every DERIVED value from the summed components, in place.
|
|
103
|
+
*
|
|
104
|
+
* This is what makes a folded document self-consistent: the nets and the `by_ref`
|
|
105
|
+
* totals are always a function of the counts and amounts beside them.
|
|
106
|
+
*/
|
|
107
|
+
function recalculateCashDerived(counters) {
|
|
108
|
+
const m = counters?.movements;
|
|
109
|
+
if (m == null)
|
|
110
|
+
return;
|
|
111
|
+
m.ledger_net = (Number(m.in_amount) || 0) - (Number(m.out_amount) || 0);
|
|
112
|
+
if (m.operator != null) {
|
|
113
|
+
m.operator.net = (Number(m.operator.in_amount) || 0) - (Number(m.operator.out_amount) || 0);
|
|
114
|
+
}
|
|
115
|
+
if (m.system != null) {
|
|
116
|
+
m.system.net = (Number(m.system.in_amount) || 0) - (Number(m.system.out_amount) || 0);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { CASH_DRAWER_STATUS_ENUM, CASH_IN_OUT_REF_ENUM, CASH_IN_OUT_TYPE_ENUM } from '../../constants/enums/cash';
|
|
2
|
+
import { IMaterializedCashCounters } from '../../schemas/types/materialized_tenant_cash_reports';
|
|
3
|
+
/**
|
|
4
|
+
* M3 cash - lifecycle classifier + accumulators.
|
|
5
|
+
*
|
|
6
|
+
* ## The classification (decision (i3))
|
|
7
|
+
*
|
|
8
|
+
* Cash ledger rows carry NO explicit lifecycle flag, so provenance is derived from
|
|
9
|
+
* `ref_type` PLUS the note prefix written by the source, with the balance SHAPE as a
|
|
10
|
+
* secondary signal. The source notes are stable, source-verified strings:
|
|
11
|
+
*
|
|
12
|
+
* "Drawer opened - Day ..." -> the opening float
|
|
13
|
+
* "Drawer reopened - ... " -> a reopen re-baseline
|
|
14
|
+
* "Drawer closed - Day ..." -> the count-out
|
|
15
|
+
* "System adjustment - ..." -> an over/short sweep
|
|
16
|
+
*
|
|
17
|
+
* The classifier lives HERE and runs at COMPILE time; the entry rows store the
|
|
18
|
+
* resulting flags, so the read never re-derives them. When the durable
|
|
19
|
+
* `is_lifecycle` write-path stamp lands, only this function changes.
|
|
20
|
+
*
|
|
21
|
+
* ## The three nets, defined EXACTLY
|
|
22
|
+
*
|
|
23
|
+
* - `operator` - pure operator movement. Excludes the float, every reopen, the
|
|
24
|
+
* count-out AND the sweeps. This is the quantity the session
|
|
25
|
+
* document calls `net_movements`, so the two sources must AGREE.
|
|
26
|
+
* - `lifecycle` - float + reopen + count-out, broken out separately.
|
|
27
|
+
* - `system` - the over/short sweeps written at close.
|
|
28
|
+
*
|
|
29
|
+
* NOTE ON THE CONCEPT DOC: section 3.2.2 states the reconciliation as
|
|
30
|
+
* `ledger_net = operator_movement_net + reopen_amount + system_adjustment_net`.
|
|
31
|
+
* That is INCOMPLETE - it omits the float and the count-out, which are also ledger
|
|
32
|
+
* rows. Tracing the close routine shows why they matter: the count-out is written
|
|
33
|
+
* as `CASH_OUT amount = countedCash`, so a fully closed drawer-day nets to ZERO.
|
|
34
|
+
* The identity the harness must assert is therefore:
|
|
35
|
+
*
|
|
36
|
+
* ledger_net = operator.net + lifecycle.float_amount - lifecycle.countout_amount
|
|
37
|
+
* + lifecycle.reopen_amount + system.net
|
|
38
|
+
*
|
|
39
|
+
* which reduces to 0 for a closed day, while BOTH cross-collection checks
|
|
40
|
+
* (`operator.net == sessions.net_movements_amount` and
|
|
41
|
+
* `system.net == -sessions.variance_amount`) hold exactly.
|
|
42
|
+
*/
|
|
43
|
+
export interface TCashMovementSource {
|
|
44
|
+
_id?: string;
|
|
45
|
+
cash_in_out_id?: string;
|
|
46
|
+
tenant_id?: string;
|
|
47
|
+
drawer_id?: string;
|
|
48
|
+
day_id?: string;
|
|
49
|
+
shift_id?: string | null;
|
|
50
|
+
shift_number?: number | null;
|
|
51
|
+
ref_type?: CASH_IN_OUT_REF_ENUM | string;
|
|
52
|
+
ref_id?: string | null;
|
|
53
|
+
type?: CASH_IN_OUT_TYPE_ENUM | string;
|
|
54
|
+
amount?: number | null;
|
|
55
|
+
drawer_balance_before?: number | null;
|
|
56
|
+
drawer_balance_after?: number | null;
|
|
57
|
+
staff_id?: string | null;
|
|
58
|
+
staff_name?: string | null;
|
|
59
|
+
note?: string | null;
|
|
60
|
+
createdAt?: Date | string | null;
|
|
61
|
+
updatedAt?: Date | string | null;
|
|
62
|
+
localDate?: string | null;
|
|
63
|
+
localHour?: number | null;
|
|
64
|
+
}
|
|
65
|
+
export interface TCashSessionSource {
|
|
66
|
+
_id?: string;
|
|
67
|
+
tenant_id?: string;
|
|
68
|
+
drawer_id?: string;
|
|
69
|
+
day_id?: string;
|
|
70
|
+
status?: CASH_DRAWER_STATUS_ENUM | string;
|
|
71
|
+
opening?: {
|
|
72
|
+
cash_amount?: number | null;
|
|
73
|
+
} | null;
|
|
74
|
+
closing?: {
|
|
75
|
+
expected_cash_amount?: number | null;
|
|
76
|
+
cash_amount?: number | null;
|
|
77
|
+
difference?: number | null;
|
|
78
|
+
} | null;
|
|
79
|
+
net_movements?: number | null;
|
|
80
|
+
reopened_times?: number | null;
|
|
81
|
+
reopened_iterations?: {
|
|
82
|
+
closing?: {
|
|
83
|
+
expected_cash_amount?: number | null;
|
|
84
|
+
cash_amount?: number | null;
|
|
85
|
+
difference?: number | null;
|
|
86
|
+
} | null;
|
|
87
|
+
expected_cash_amount?: number | null;
|
|
88
|
+
cash_amount?: number | null;
|
|
89
|
+
difference?: number | null;
|
|
90
|
+
}[];
|
|
91
|
+
createdAt?: Date | string | null;
|
|
92
|
+
updatedAt?: Date | string | null;
|
|
93
|
+
}
|
|
94
|
+
/** Note prefixes written by the cash drawer repository. */
|
|
95
|
+
export declare const CASH_OPENING_NOTE_PREFIX = "Drawer opened";
|
|
96
|
+
export declare const CASH_REOPEN_NOTE_PREFIX = "Drawer reopened";
|
|
97
|
+
export declare const CASH_COUNT_OUT_NOTE_PREFIX = "Drawer closed";
|
|
98
|
+
export declare const CASH_SYSTEM_NOTE_PREFIX = "System adjustment";
|
|
99
|
+
/** Provenance of one ledger row. */
|
|
100
|
+
export interface ICashMovementProvenance {
|
|
101
|
+
is_opening_float: boolean;
|
|
102
|
+
is_reopen: boolean;
|
|
103
|
+
is_count_out: boolean;
|
|
104
|
+
is_system_adjustment: boolean;
|
|
105
|
+
/** True only for pure operator movement - the `net_movements` population. */
|
|
106
|
+
is_operator: boolean;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Classifies one ledger row.
|
|
110
|
+
*
|
|
111
|
+
* The note prefix is PRIMARY (it is what the source writes). The balance SHAPE is
|
|
112
|
+
* the fallback, because a lifecycle CASH_IN always opens from a zero balance while
|
|
113
|
+
* an operator cash-in never does - so a row whose note is missing or reworded is
|
|
114
|
+
* still classified correctly rather than silently counted as operator movement.
|
|
115
|
+
*/
|
|
116
|
+
export declare function classifyCashMovement(row: TCashMovementSource): ICashMovementProvenance;
|
|
117
|
+
/**
|
|
118
|
+
* A per-key accumulation buffer.
|
|
119
|
+
*
|
|
120
|
+
* `seen` de-duplicates ledger rows by source id: money must never be counted twice
|
|
121
|
+
* even if a source query returns a row across two overlapping reads.
|
|
122
|
+
*/
|
|
123
|
+
export interface ICashAccumulator {
|
|
124
|
+
counters: IMaterializedCashCounters;
|
|
125
|
+
staff: Set<string>;
|
|
126
|
+
seen: Set<string>;
|
|
127
|
+
}
|
|
128
|
+
/** A zeroed counter block with every ref type present. */
|
|
129
|
+
export declare function freshCashCounters(): IMaterializedCashCounters;
|
|
130
|
+
/** A fresh buffer. */
|
|
131
|
+
export declare function freshCashAccumulator(): ICashAccumulator;
|
|
132
|
+
/** Adds one ledger row. Returns false when it was already counted. */
|
|
133
|
+
export declare function addCashMovement(acc: ICashAccumulator, row: TCashMovementSource): boolean;
|
|
134
|
+
/** Adds one drawer session document. */
|
|
135
|
+
export declare function addCashSession(acc: ICashAccumulator, session: TCashSessionSource): void;
|
|
136
|
+
/**
|
|
137
|
+
* Materializes the staff roster into the counter block (call before persisting).
|
|
138
|
+
*
|
|
139
|
+
* The IDS are kept alongside the count so a later period fold can take a UNION
|
|
140
|
+
* rather than a sum - a distinct count cannot be added.
|
|
141
|
+
*/
|
|
142
|
+
export declare function finalizeCashAccumulator(acc: ICashAccumulator): IMaterializedCashCounters;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CASH_SYSTEM_NOTE_PREFIX = exports.CASH_COUNT_OUT_NOTE_PREFIX = exports.CASH_REOPEN_NOTE_PREFIX = exports.CASH_OPENING_NOTE_PREFIX = void 0;
|
|
4
|
+
exports.classifyCashMovement = classifyCashMovement;
|
|
5
|
+
exports.freshCashCounters = freshCashCounters;
|
|
6
|
+
exports.freshCashAccumulator = freshCashAccumulator;
|
|
7
|
+
exports.addCashMovement = addCashMovement;
|
|
8
|
+
exports.addCashSession = addCashSession;
|
|
9
|
+
exports.finalizeCashAccumulator = finalizeCashAccumulator;
|
|
10
|
+
const cash_1 = require("../../constants/enums/cash");
|
|
11
|
+
/** Note prefixes written by the cash drawer repository. */
|
|
12
|
+
exports.CASH_OPENING_NOTE_PREFIX = 'Drawer opened';
|
|
13
|
+
exports.CASH_REOPEN_NOTE_PREFIX = 'Drawer reopened';
|
|
14
|
+
exports.CASH_COUNT_OUT_NOTE_PREFIX = 'Drawer closed';
|
|
15
|
+
exports.CASH_SYSTEM_NOTE_PREFIX = 'System adjustment';
|
|
16
|
+
const noteOf = (row) => (typeof row?.note === 'string' ? row.note : '');
|
|
17
|
+
/**
|
|
18
|
+
* Classifies one ledger row.
|
|
19
|
+
*
|
|
20
|
+
* The note prefix is PRIMARY (it is what the source writes). The balance SHAPE is
|
|
21
|
+
* the fallback, because a lifecycle CASH_IN always opens from a zero balance while
|
|
22
|
+
* an operator cash-in never does - so a row whose note is missing or reworded is
|
|
23
|
+
* still classified correctly rather than silently counted as operator movement.
|
|
24
|
+
*/
|
|
25
|
+
function classifyCashMovement(row) {
|
|
26
|
+
const refType = String(row?.ref_type ?? '');
|
|
27
|
+
const type = String(row?.type ?? '');
|
|
28
|
+
const note = noteOf(row);
|
|
29
|
+
const startsAtZero = Number(row?.drawer_balance_before ?? 0) === 0;
|
|
30
|
+
const isSystemAdjustment = refType === cash_1.CASH_IN_OUT_REF_ENUM.SYSTEM_ADJUSTMENT || note.startsWith(exports.CASH_SYSTEM_NOTE_PREFIX);
|
|
31
|
+
const isDrawerCashIn = refType === cash_1.CASH_IN_OUT_REF_ENUM.DRAWER && type === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_IN;
|
|
32
|
+
const isDrawerCashOut = refType === cash_1.CASH_IN_OUT_REF_ENUM.DRAWER && type === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_OUT;
|
|
33
|
+
// The NOTE is authoritative: the source always writes it, so an exact prefix
|
|
34
|
+
// match is trusted outright.
|
|
35
|
+
const isReopen = isDrawerCashIn && !isSystemAdjustment && note.startsWith(exports.CASH_REOPEN_NOTE_PREFIX);
|
|
36
|
+
// The SHAPE is only a fallback, and it cannot distinguish a float from a reopen -
|
|
37
|
+
// both open from a zero balance and both are CASH_IN / DRAWER. Given a note-less
|
|
38
|
+
// row the classifier therefore resolves to the FLOAT (the opening case), and the
|
|
39
|
+
// attribution is CROSS-CHECKED against the session documents instead of guessed:
|
|
40
|
+
// the harness asserts lifecycle.float_amount == sessions.opening_float_amount, so
|
|
41
|
+
// a note-less reopen shows up as a disagreement rather than silently mislabelling.
|
|
42
|
+
// (This is exactly the guessing decision (i3) accepts for v1 and the durable
|
|
43
|
+
// is_lifecycle stamp removes.)
|
|
44
|
+
const isOpeningFloat = isDrawerCashIn &&
|
|
45
|
+
!isSystemAdjustment &&
|
|
46
|
+
!isReopen &&
|
|
47
|
+
(note.startsWith(exports.CASH_OPENING_NOTE_PREFIX) || (note === '' && startsAtZero));
|
|
48
|
+
const isCountOut = isDrawerCashOut && !isSystemAdjustment && (note.startsWith(exports.CASH_COUNT_OUT_NOTE_PREFIX) || note === '');
|
|
49
|
+
const isLifecycle = isReopen || isOpeningFloat || isCountOut || isSystemAdjustment;
|
|
50
|
+
return {
|
|
51
|
+
is_opening_float: isOpeningFloat,
|
|
52
|
+
is_reopen: isReopen,
|
|
53
|
+
is_count_out: isCountOut,
|
|
54
|
+
is_system_adjustment: isSystemAdjustment,
|
|
55
|
+
is_operator: !isLifecycle,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const emptyFlow = () => ({
|
|
59
|
+
in_count: 0,
|
|
60
|
+
in_amount: 0,
|
|
61
|
+
out_count: 0,
|
|
62
|
+
out_amount: 0,
|
|
63
|
+
});
|
|
64
|
+
/** A zeroed counter block with every ref type present. */
|
|
65
|
+
function freshCashCounters() {
|
|
66
|
+
const byRef = {};
|
|
67
|
+
for (const refType of Object.values(cash_1.CASH_IN_OUT_REF_ENUM))
|
|
68
|
+
byRef[refType] = emptyFlow();
|
|
69
|
+
return {
|
|
70
|
+
movements: {
|
|
71
|
+
count: 0,
|
|
72
|
+
in_count: 0,
|
|
73
|
+
in_amount: 0,
|
|
74
|
+
out_count: 0,
|
|
75
|
+
out_amount: 0,
|
|
76
|
+
ledger_net: 0,
|
|
77
|
+
operator: { ...emptyFlow(), count: 0, net: 0 },
|
|
78
|
+
lifecycle: {
|
|
79
|
+
float_count: 0,
|
|
80
|
+
float_amount: 0,
|
|
81
|
+
reopen_count: 0,
|
|
82
|
+
reopen_amount: 0,
|
|
83
|
+
countout_count: 0,
|
|
84
|
+
countout_amount: 0,
|
|
85
|
+
},
|
|
86
|
+
system: { ...emptyFlow(), count: 0, net: 0 },
|
|
87
|
+
by_ref: byRef,
|
|
88
|
+
staff_count: 0,
|
|
89
|
+
staff_ids: [],
|
|
90
|
+
},
|
|
91
|
+
sessions: {
|
|
92
|
+
session_count: 0,
|
|
93
|
+
reopen_count: 0,
|
|
94
|
+
reopened_session_count: 0,
|
|
95
|
+
opening_float_amount: 0,
|
|
96
|
+
net_movements_amount: 0,
|
|
97
|
+
expected_close_amount: 0,
|
|
98
|
+
counted_close_amount: 0,
|
|
99
|
+
variance_amount: 0,
|
|
100
|
+
variance_positive_count: 0,
|
|
101
|
+
variance_negative_count: 0,
|
|
102
|
+
open_sessions_count: 0,
|
|
103
|
+
unmatched_close_count: 0,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** A fresh buffer. */
|
|
108
|
+
function freshCashAccumulator() {
|
|
109
|
+
return { counters: freshCashCounters(), staff: new Set(), seen: new Set() };
|
|
110
|
+
}
|
|
111
|
+
/** Adds one ledger row. Returns false when it was already counted. */
|
|
112
|
+
function addCashMovement(acc, row) {
|
|
113
|
+
var _a;
|
|
114
|
+
if (acc == null || row == null)
|
|
115
|
+
return false;
|
|
116
|
+
const id = row.cash_in_out_id ?? row._id;
|
|
117
|
+
if (id != null) {
|
|
118
|
+
const key = String(id);
|
|
119
|
+
if (acc.seen.has(key))
|
|
120
|
+
return false;
|
|
121
|
+
acc.seen.add(key);
|
|
122
|
+
}
|
|
123
|
+
const provenance = classifyCashMovement(row);
|
|
124
|
+
const amount = Math.abs(Number(row.amount) || 0);
|
|
125
|
+
const isIn = String(row.type) === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_IN;
|
|
126
|
+
const movements = acc.counters.movements;
|
|
127
|
+
if (row.staff_id != null)
|
|
128
|
+
acc.staff.add(String(row.staff_id));
|
|
129
|
+
movements.count += 1;
|
|
130
|
+
if (isIn) {
|
|
131
|
+
movements.in_count += 1;
|
|
132
|
+
movements.in_amount += amount;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
movements.out_count += 1;
|
|
136
|
+
movements.out_amount += amount;
|
|
137
|
+
}
|
|
138
|
+
movements.ledger_net = movements.in_amount - movements.out_amount;
|
|
139
|
+
// by_ref is a BREAKDOWN of the same rows, so it uses the same classification.
|
|
140
|
+
const refKey = String(row.ref_type ?? cash_1.CASH_IN_OUT_REF_ENUM.NONE);
|
|
141
|
+
const refFlow = ((_a = movements.by_ref)[refKey] ?? (_a[refKey] = emptyFlow()));
|
|
142
|
+
if (isIn) {
|
|
143
|
+
refFlow.in_count += 1;
|
|
144
|
+
refFlow.in_amount += amount;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
refFlow.out_count += 1;
|
|
148
|
+
refFlow.out_amount += amount;
|
|
149
|
+
}
|
|
150
|
+
if (provenance.is_operator) {
|
|
151
|
+
const operator = movements.operator;
|
|
152
|
+
operator.count += 1;
|
|
153
|
+
if (isIn) {
|
|
154
|
+
operator.in_count += 1;
|
|
155
|
+
operator.in_amount += amount;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
operator.out_count += 1;
|
|
159
|
+
operator.out_amount += amount;
|
|
160
|
+
}
|
|
161
|
+
operator.net = operator.in_amount - operator.out_amount;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
if (provenance.is_system_adjustment) {
|
|
165
|
+
const system = movements.system;
|
|
166
|
+
system.count += 1;
|
|
167
|
+
if (isIn) {
|
|
168
|
+
system.in_count += 1;
|
|
169
|
+
system.in_amount += amount;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
system.out_count += 1;
|
|
173
|
+
system.out_amount += amount;
|
|
174
|
+
}
|
|
175
|
+
system.net = system.in_amount - system.out_amount;
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
const lifecycle = movements.lifecycle;
|
|
179
|
+
if (provenance.is_opening_float) {
|
|
180
|
+
lifecycle.float_count += 1;
|
|
181
|
+
lifecycle.float_amount += amount;
|
|
182
|
+
}
|
|
183
|
+
else if (provenance.is_reopen) {
|
|
184
|
+
lifecycle.reopen_count += 1;
|
|
185
|
+
lifecycle.reopen_amount += amount;
|
|
186
|
+
}
|
|
187
|
+
else if (provenance.is_count_out) {
|
|
188
|
+
lifecycle.countout_count += 1;
|
|
189
|
+
lifecycle.countout_amount += amount;
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
/** Adds one drawer session document. */
|
|
194
|
+
function addCashSession(acc, session) {
|
|
195
|
+
if (acc == null || session == null)
|
|
196
|
+
return;
|
|
197
|
+
const sessions = acc.counters.sessions;
|
|
198
|
+
sessions.session_count += 1;
|
|
199
|
+
const reopenedTimes = Number(session.reopened_times) || 0;
|
|
200
|
+
sessions.reopen_count += reopenedTimes;
|
|
201
|
+
if (reopenedTimes > 0)
|
|
202
|
+
sessions.reopened_session_count += 1;
|
|
203
|
+
// The float is preserved across reopens, so it is counted ONCE per session.
|
|
204
|
+
sessions.opening_float_amount += Math.abs(Number(session.opening?.cash_amount) || 0);
|
|
205
|
+
sessions.net_movements_amount += Number(session.net_movements) || 0;
|
|
206
|
+
const closing = session.closing ?? null;
|
|
207
|
+
if (closing == null) {
|
|
208
|
+
// No closing record: a session still IN_USE is normal; anything else is a
|
|
209
|
+
// data-integrity tripwire.
|
|
210
|
+
if (String(session.status) === cash_1.CASH_DRAWER_STATUS_ENUM.IN_USE)
|
|
211
|
+
sessions.open_sessions_count += 1;
|
|
212
|
+
else
|
|
213
|
+
sessions.unmatched_close_count += 1;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// EVERY lifecycle counts, not just the last one.
|
|
217
|
+
//
|
|
218
|
+
// FOUND BY THE DEMO DATASET, not by reading the source: a REOPENED session has two
|
|
219
|
+
// (or more) lifecycles, and the ledger holds an over/short SWEEP for EACH of them -
|
|
220
|
+
// but `closing.difference` only describes the FINAL one. Summing just that made
|
|
221
|
+
// `variance_amount` undercount the day and broke the report's second cross-collection
|
|
222
|
+
// check (`system.net == -variance_amount`) on every reopened drawer-day: measured
|
|
223
|
+
// 120 vs -300 for one drawer, where lifecycle 1 was 420 OVER and lifecycle 2 was 300
|
|
224
|
+
// SHORT, netting to 120. The earlier lifecycle is snapshotted in
|
|
225
|
+
// `reopened_iterations`, so it is recoverable - and summing all of them makes the
|
|
226
|
+
// identity exact again.
|
|
227
|
+
const lifecycles = [closing];
|
|
228
|
+
for (const iteration of Array.isArray(session.reopened_iterations) ? session.reopened_iterations : []) {
|
|
229
|
+
if (iteration?.closing != null)
|
|
230
|
+
lifecycles.push(iteration.closing);
|
|
231
|
+
else if (iteration != null)
|
|
232
|
+
lifecycles.push(iteration);
|
|
233
|
+
}
|
|
234
|
+
for (const lifecycle of lifecycles) {
|
|
235
|
+
sessions.expected_close_amount += Number(lifecycle.expected_cash_amount) || 0;
|
|
236
|
+
sessions.counted_close_amount += Number(lifecycle.cash_amount) || 0;
|
|
237
|
+
const difference = Number(lifecycle.difference) || 0;
|
|
238
|
+
sessions.variance_amount += difference;
|
|
239
|
+
// SIGN: difference = expected - counted, so POSITIVE = SHORT.
|
|
240
|
+
if (difference > 0)
|
|
241
|
+
sessions.variance_positive_count += 1;
|
|
242
|
+
else if (difference < 0)
|
|
243
|
+
sessions.variance_negative_count += 1;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Materializes the staff roster into the counter block (call before persisting).
|
|
248
|
+
*
|
|
249
|
+
* The IDS are kept alongside the count so a later period fold can take a UNION
|
|
250
|
+
* rather than a sum - a distinct count cannot be added.
|
|
251
|
+
*/
|
|
252
|
+
function finalizeCashAccumulator(acc) {
|
|
253
|
+
const ids = [...acc.staff].sort();
|
|
254
|
+
acc.counters.movements.staff_ids = ids;
|
|
255
|
+
acc.counters.movements.staff_count = ids.length;
|
|
256
|
+
return acc.counters;
|
|
257
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { IMaterializedCashEntry, IMaterializedTenantCashEntries } from '../../schemas/types/materialized_tenant_cash_entries';
|
|
3
|
+
import { IMaterializedCashCounters, IMaterializedTenantCashReport } from '../../schemas/types/materialized_tenant_cash_reports';
|
|
4
|
+
/**
|
|
5
|
+
* M3 close-day helpers.
|
|
6
|
+
*
|
|
7
|
+
* ## Period counters are RE-FOLDED, never patched
|
|
8
|
+
*
|
|
9
|
+
* The discounted ledgers keep periods current by subtracting a day delta and adding
|
|
10
|
+
* the fresh one. That CANNOT work here, for the same reason it cannot work in the prep
|
|
11
|
+
* time report: cash has a NON-ADDITIVE counter. `staff_count` counts DISTINCT staff,
|
|
12
|
+
* and there is no way to subtract a distinct count - removing the day where a given
|
|
13
|
+
* staff member first appeared would leave a count that no longer corresponds to any
|
|
14
|
+
* set of days. So every touched period is rebuilt from its whole day set.
|
|
15
|
+
*
|
|
16
|
+
* ## The watermark comes from the FOLDED DAYS
|
|
17
|
+
*
|
|
18
|
+
* A folded document that inherited the STORED document watermark would look
|
|
19
|
+
* unchanged to `needsMaterializedCashReportWrite`, and the write would be skipped
|
|
20
|
+
* forever - freezing the period at its first closed day. That bug shipped once in the
|
|
21
|
+
* prep time report and is designed out here from the start.
|
|
22
|
+
*/
|
|
23
|
+
/** Period scopes this report materializes (everything but the day scope). */
|
|
24
|
+
export declare const MATERIALIZED_CASH_PERIOD_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
25
|
+
/** True when the scope is the plain day scope. */
|
|
26
|
+
export declare const isMaterializedCashDayScope: (scopeContext: string) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Merges TWO period entry sections, keyed on `entry_key`.
|
|
29
|
+
*
|
|
30
|
+
* Rows are deduplicated by identity rather than concatenated: a source row belongs to
|
|
31
|
+
* exactly one day, so the same `entry_key` appearing twice means the fold saw it
|
|
32
|
+
* twice, and money must never be counted twice.
|
|
33
|
+
*/
|
|
34
|
+
export declare function mergeMaterializedCashEntrySections(target: Record<string, {
|
|
35
|
+
rows: IMaterializedCashEntry[];
|
|
36
|
+
}> | null, source: Record<string, {
|
|
37
|
+
rows: IMaterializedCashEntry[];
|
|
38
|
+
}> | null): Record<string, {
|
|
39
|
+
rows: IMaterializedCashEntry[];
|
|
40
|
+
}>;
|
|
41
|
+
/** True when the stored document already carries this exact content. */
|
|
42
|
+
export declare function needsMaterializedCashReportWrite(existing: IMaterializedTenantCashReport | null | undefined, next: IMaterializedTenantCashReport): boolean;
|
|
43
|
+
/** True when the stored entry document already carries these exact rows. */
|
|
44
|
+
export declare function needsMaterializedCashEntriesWrite(existing: IMaterializedTenantCashEntries | null | undefined, next: IMaterializedTenantCashEntries): boolean;
|
|
45
|
+
/** Folds the counters of every day document that belongs to one period scope. */
|
|
46
|
+
export declare function foldMaterializedCashPeriodCounters(input: {
|
|
47
|
+
periodScope: string;
|
|
48
|
+
periodScopeField: string;
|
|
49
|
+
dayDocuments: IMaterializedTenantCashReport[];
|
|
50
|
+
}): Record<string, IMaterializedCashCounters>;
|
|
51
|
+
/** Folds the statement rows of every day document that belongs to one period scope. */
|
|
52
|
+
export declare function foldMaterializedCashPeriodRows(input: {
|
|
53
|
+
periodScope: string;
|
|
54
|
+
periodScopeField: string;
|
|
55
|
+
dayDocuments: IMaterializedTenantCashEntries[];
|
|
56
|
+
}): Record<string, {
|
|
57
|
+
rows: IMaterializedCashEntry[];
|
|
58
|
+
}>;
|
|
59
|
+
/** One plan write: the document plus its iteration history row. */
|
|
60
|
+
export interface IMaterializedCashCloseDayWrite<T> {
|
|
61
|
+
report: T;
|
|
62
|
+
iteration: {
|
|
63
|
+
report_type: string;
|
|
64
|
+
report_id: string;
|
|
65
|
+
iteration: number;
|
|
66
|
+
schema_version: number;
|
|
67
|
+
reason: string;
|
|
68
|
+
snapshot: unknown;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
updatedAt: Date;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface ITenantCashCloseDayPlan {
|
|
74
|
+
writes: IMaterializedCashCloseDayWrite<IMaterializedTenantCashReport>[];
|
|
75
|
+
entryWrites: IMaterializedCashCloseDayWrite<IMaterializedTenantCashEntries>[];
|
|
76
|
+
/** DAY-scoped counter docs no longer backed by activity - delete by _id. */
|
|
77
|
+
staleDocuments: IMaterializedTenantCashReport[];
|
|
78
|
+
/** DAY-scoped entry docs no longer backed by rows - delete by _id. */
|
|
79
|
+
staleEntryDocuments: IMaterializedTenantCashEntries[];
|
|
80
|
+
skippedDocuments: IMaterializedTenantCashReport[];
|
|
81
|
+
skippedEntryDocuments: IMaterializedTenantCashEntries[];
|
|
82
|
+
}
|
|
83
|
+
export interface IBuildTenantCashCloseDayPlanInput {
|
|
84
|
+
tenantId: string;
|
|
85
|
+
reports: IMaterializedTenantCashReport[];
|
|
86
|
+
entries: IMaterializedTenantCashEntries[];
|
|
87
|
+
localDate?: string | null;
|
|
88
|
+
existing?: IMaterializedTenantCashReport[];
|
|
89
|
+
existingEntries?: IMaterializedTenantCashEntries[];
|
|
90
|
+
reason: string;
|
|
91
|
+
computedAt?: Date;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Builds the close-day plan for ONE tenant-day.
|
|
95
|
+
*
|
|
96
|
+
* The DAY scope is written from the compile. Every PERIOD scope the day touches is
|
|
97
|
+
* RE-FOLDED from its whole day set - and the touched set is the union of the closed
|
|
98
|
+
* day's periods AND every removed day's periods, because emptying a day has to clear
|
|
99
|
+
* its contribution from the periods it used to be part of.
|
|
100
|
+
*
|
|
101
|
+
* Returns null on malformed input.
|
|
102
|
+
*/
|
|
103
|
+
export declare function buildTenantCashCloseDayPlan(input: IBuildTenantCashCloseDayPlanInput | null | undefined): ITenantCashCloseDayPlan | null;
|