@managesome/eposmatic-toolkit 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/constants/MATERIALIZED_REPORTS.js +448 -0
- package/esm/constants/enums/communications.js +1 -0
- package/esm/helpers/index.js +3 -0
- package/esm/helpers/materialized-reports/index.js +32 -0
- package/esm/helpers/materialized-reports/materialized-cash-accumulator-helpers.js +114 -0
- package/esm/helpers/materialized-reports/materialized-cash-classification-helpers.js +286 -0
- package/esm/helpers/materialized-reports/materialized-cash-close-day-helpers.js +396 -0
- package/esm/helpers/materialized-reports/materialized-cash-compile-helpers.js +244 -0
- package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +170 -0
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +426 -0
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +372 -0
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +214 -0
- package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +318 -0
- package/esm/helpers/materialized-reports/materialized-discount-classification-helpers.js +213 -0
- package/esm/helpers/materialized-reports/materialized-discount-close-day-helpers.js +604 -0
- package/esm/helpers/materialized-reports/materialized-discount-compile-helpers.js +186 -0
- package/esm/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.js +155 -0
- package/esm/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.js +199 -0
- package/esm/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +111 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +88 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.js +394 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.js +167 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +215 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +476 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +201 -0
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +7 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +189 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +157 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +588 -0
- package/esm/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +175 -0
- package/esm/helpers/materialized-reports/tenant-cash-in-out-formatter.js +156 -0
- package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +230 -0
- package/esm/helpers/materialized-reports/tenant-discount-formatter.js +427 -0
- package/esm/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +237 -0
- package/esm/helpers/materialized-reports/tenant-payments-comparison-formatter.js +279 -0
- package/esm/helpers/materialized-reports/tenant-prep-time-formatter.js +228 -0
- package/esm/helpers/materialized-reports/tenant-sales-comparison-formatter.js +343 -0
- package/esm/helpers/reporting-contract/index.js +2 -0
- package/esm/helpers/reporting-contract/overview-contract.js +122 -0
- package/esm/helpers/reporting-contract/report-contract.js +228 -0
- package/esm/helpers/rider-earnings/index.js +1 -0
- package/esm/helpers/rider-earnings/rider-earnings.js +59 -0
- package/esm/helpers/rider-reports/index.js +2 -0
- package/esm/helpers/rider-reports/rider-daily-report.js +90 -0
- package/esm/helpers/rider-reports/rider-report.js +67 -0
- package/esm/schemas/models/deliveries.js +75 -0
- package/esm/schemas/models/index.js +15 -0
- package/esm/schemas/models/materialized_rider_daily_reports.js +39 -0
- package/esm/schemas/models/materialized_tenant_cash_entries.js +95 -0
- package/esm/schemas/models/materialized_tenant_cash_reports.js +77 -0
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +63 -0
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +63 -0
- package/esm/schemas/models/materialized_tenant_discount_entries.js +156 -0
- package/esm/schemas/models/materialized_tenant_discount_reports.js +333 -0
- package/esm/schemas/models/materialized_tenant_hourly_comparison_entries.js +87 -0
- package/esm/schemas/models/materialized_tenant_hourly_comparison_reports.js +99 -0
- package/esm/schemas/models/materialized_tenant_payments_comparison_entries.js +71 -0
- package/esm/schemas/models/materialized_tenant_payments_comparison_reports.js +76 -0
- package/esm/schemas/models/materialized_tenant_prep_time_entries.js +130 -0
- package/esm/schemas/models/materialized_tenant_prep_time_reports.js +109 -0
- package/esm/schemas/models/materialized_tenant_sales_comparison_entries.js +130 -0
- package/esm/schemas/models/materialized_tenant_sales_comparison_reports.js +154 -0
- package/esm/schemas/types/index.js +15 -0
- package/esm/schemas/types/materialized_rider_daily_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_cash_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_cash_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_delivery_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_delivery_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_discount_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_discount_reports.js +2 -0
- package/esm/schemas/types/materialized_tenant_hourly_comparison_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_hourly_comparison_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_payments_comparison_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_payments_comparison_reports.js +11 -0
- package/esm/schemas/types/materialized_tenant_prep_time_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_prep_time_reports.js +1 -0
- package/esm/schemas/types/materialized_tenant_sales_comparison_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_sales_comparison_reports.js +14 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +339 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +450 -1
- package/lib/constants/enums/communications.d.ts +1 -0
- package/lib/constants/enums/communications.js +2 -1
- package/lib/helpers/index.d.ts +3 -0
- package/lib/helpers/index.js +3 -0
- package/lib/helpers/materialized-reports/index.d.ts +32 -0
- package/lib/helpers/materialized-reports/index.js +32 -0
- package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.d.ts +18 -0
- package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.js +118 -0
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.d.ts +90 -0
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.js +295 -0
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.d.ts +102 -0
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.js +409 -0
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.d.ts +72 -0
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +251 -0
- package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.d.ts +7 -0
- package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +173 -0
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +84 -0
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +438 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +97 -0
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +385 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +40 -0
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +218 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +52 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +324 -0
- package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.d.ts +50 -0
- package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.js +222 -0
- package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.d.ts +182 -0
- package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.js +615 -0
- package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.d.ts +47 -0
- package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +193 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.d.ts +64 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.js +163 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.d.ts +61 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.js +207 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.d.ts +23 -0
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +116 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.d.ts +25 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +98 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.d.ts +79 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.js +407 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.d.ts +35 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.js +173 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.d.ts +66 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +224 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +128 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +490 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.d.ts +46 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +208 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +8 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +8 -1
- package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.d.ts +48 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +204 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.d.ts +22 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +161 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.d.ts +163 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +603 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.d.ts +68 -0
- package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +182 -0
- package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.d.ts +98 -0
- package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.js +159 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +133 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +233 -0
- package/lib/helpers/materialized-reports/tenant-discount-formatter.d.ts +114 -0
- package/lib/helpers/materialized-reports/tenant-discount-formatter.js +431 -0
- package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.d.ts +60 -0
- package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +243 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.d.ts +75 -0
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.js +286 -0
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +97 -0
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.js +232 -0
- package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.d.ts +105 -0
- package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.js +349 -0
- package/lib/helpers/reporting-contract/index.d.ts +2 -0
- package/lib/helpers/reporting-contract/index.js +18 -0
- package/lib/helpers/reporting-contract/overview-contract.d.ts +55 -0
- package/lib/helpers/reporting-contract/overview-contract.js +126 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +159 -0
- package/lib/helpers/reporting-contract/report-contract.js +239 -0
- package/lib/helpers/rider-earnings/index.d.ts +1 -0
- package/lib/helpers/rider-earnings/index.js +17 -0
- package/lib/helpers/rider-earnings/rider-earnings.d.ts +58 -0
- package/lib/helpers/rider-earnings/rider-earnings.js +64 -0
- package/lib/helpers/rider-reports/index.d.ts +2 -0
- package/lib/helpers/rider-reports/index.js +18 -0
- package/lib/helpers/rider-reports/rider-daily-report.d.ts +26 -0
- package/lib/helpers/rider-reports/rider-daily-report.js +93 -0
- package/lib/helpers/rider-reports/rider-report.d.ts +49 -0
- package/lib/helpers/rider-reports/rider-report.js +70 -0
- package/lib/helpers/types/materialized-reports-apis.d.ts +297 -1
- package/lib/schemas/models/deliveries.d.ts +54 -0
- package/lib/schemas/models/deliveries.js +75 -0
- package/lib/schemas/models/expense_details.d.ts +3 -3
- package/lib/schemas/models/index.d.ts +15 -0
- package/lib/schemas/models/index.js +15 -0
- package/lib/schemas/models/materialized_rider_daily_reports.d.ts +27 -0
- package/lib/schemas/models/materialized_rider_daily_reports.js +42 -0
- package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +181 -0
- package/lib/schemas/models/materialized_tenant_cash_entries.js +98 -0
- package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +111 -0
- package/lib/schemas/models/materialized_tenant_cash_reports.js +80 -0
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +98 -0
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +66 -0
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +98 -0
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +66 -0
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +199 -0
- package/lib/schemas/models/materialized_tenant_discount_entries.js +159 -0
- package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +216 -0
- package/lib/schemas/models/materialized_tenant_discount_reports.js +336 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +95 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.js +82 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +105 -0
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.js +91 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +91 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.js +70 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +98 -0
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.js +71 -0
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +181 -0
- package/lib/schemas/models/materialized_tenant_prep_time_entries.js +133 -0
- package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +118 -0
- package/lib/schemas/models/materialized_tenant_prep_time_reports.js +112 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +139 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.js +120 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +167 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.js +137 -0
- package/lib/schemas/models/tenant_purchase_order_vendor_returns.d.ts +3 -3
- package/lib/schemas/models/warehouse_internal_movements.d.ts +6 -6
- package/lib/schemas/models/warehouse_purchase_order_receipts.d.ts +3 -3
- package/lib/schemas/models/warehouse_purchase_order_vendor_returns.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_deliveries.d.ts +6 -6
- package/lib/schemas/models/warehouse_sale_invoices.d.ts +3 -3
- package/lib/schemas/types/deliveries.d.ts +40 -1
- package/lib/schemas/types/index.d.ts +15 -0
- package/lib/schemas/types/index.js +15 -0
- package/lib/schemas/types/materialized_rider_daily_reports.d.ts +37 -0
- package/lib/schemas/types/materialized_rider_daily_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_cash_entries.d.ts +87 -0
- package/lib/schemas/types/materialized_tenant_cash_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_cash_reports.d.ts +144 -0
- package/lib/schemas/types/materialized_tenant_cash_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +98 -0
- package/lib/schemas/types/materialized_tenant_delivery_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +179 -0
- package/lib/schemas/types/materialized_tenant_delivery_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_discount_entries.d.ts +81 -0
- package/lib/schemas/types/materialized_tenant_discount_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_discount_reports.d.ts +209 -0
- package/lib/schemas/types/materialized_tenant_discount_reports.js +3 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.d.ts +33 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.d.ts +40 -0
- package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_entries.d.ts +48 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_reports.d.ts +51 -0
- package/lib/schemas/types/materialized_tenant_payments_comparison_reports.js +14 -0
- package/lib/schemas/types/materialized_tenant_prep_time_entries.d.ts +88 -0
- package/lib/schemas/types/materialized_tenant_prep_time_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +132 -0
- package/lib/schemas/types/materialized_tenant_prep_time_reports.js +2 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_entries.d.ts +43 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_reports.d.ts +74 -0
- package/lib/schemas/types/materialized_tenant_sales_comparison_reports.js +17 -0
- package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/fixtures.d.ts +15 -1
- package/lib/tests/materialized-reports/fixtures.js +1 -0
- package/lib/tests/materialized-reports/materialized-cash-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-compile.test.js +196 -0
- package/lib/tests/materialized-reports/materialized-cash-fold.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-fold.test.js +116 -0
- package/lib/tests/materialized-reports/materialized-cash-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-formatter.test.js +152 -0
- package/lib/tests/materialized-reports/materialized-cash-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-plan.test.js +168 -0
- package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.js +267 -0
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +147 -0
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +241 -0
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +109 -0
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +141 -0
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +198 -0
- package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.js +173 -0
- package/lib/tests/materialized-reports/materialized-discount-classification.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-classification.test.js +339 -0
- package/lib/tests/materialized-reports/materialized-discount-close-day.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-close-day.test.js +506 -0
- package/lib/tests/materialized-reports/materialized-discount-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-compile.test.js +161 -0
- package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.js +107 -0
- package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.js +125 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.js +146 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.js +127 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.js +138 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.js +90 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.js +164 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.js +117 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.js +149 -0
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +273 -0
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +270 -0
- package/lib/tests/materialized-reports/materialized-prep-time-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-compile.test.js +217 -0
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +84 -0
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +176 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.js +126 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.js +206 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.js +179 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.js +196 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.js +241 -0
- package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.js +96 -0
- package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.js +112 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.js +142 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +8 -1
- package/lib/tests/materialized-reports/sales-comparison-reference.d.ts +55 -0
- package/lib/tests/materialized-reports/sales-comparison-reference.js +86 -0
- package/lib/tests/materialized-reports/tenant-discount-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-discount-formatter.test.js +289 -0
- package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.js +354 -0
- package/lib/tests/reporting-contract.test.d.ts +1 -0
- package/lib/tests/reporting-contract.test.js +267 -0
- package/lib/tests/rider-daily-report.test.d.ts +1 -0
- package/lib/tests/rider-daily-report.test.js +86 -0
- package/lib/tests/rider-earnings.test.d.ts +1 -0
- package/lib/tests/rider-earnings.test.js +65 -0
- package/lib/tests/rider-report.test.d.ts +1 -0
- package/lib/tests/rider-report.test.js +98 -0
- package/package.json +10 -1
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isMaterializedCashDayScope = exports.MATERIALIZED_CASH_PERIOD_SCOPES = void 0;
|
|
7
|
+
exports.mergeMaterializedCashEntrySections = mergeMaterializedCashEntrySections;
|
|
8
|
+
exports.needsMaterializedCashReportWrite = needsMaterializedCashReportWrite;
|
|
9
|
+
exports.needsMaterializedCashEntriesWrite = needsMaterializedCashEntriesWrite;
|
|
10
|
+
exports.foldMaterializedCashPeriodCounters = foldMaterializedCashPeriodCounters;
|
|
11
|
+
exports.foldMaterializedCashPeriodRows = foldMaterializedCashPeriodRows;
|
|
12
|
+
exports.buildTenantCashCloseDayPlan = buildTenantCashCloseDayPlan;
|
|
13
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
14
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
15
|
+
const materialized_tenant_reports_iterations_helpers_1 = require("./materialized-tenant-reports-iterations-helpers");
|
|
16
|
+
const scope_helpers_1 = require("./scope-helpers");
|
|
17
|
+
const materialized_cash_classification_helpers_1 = require("./materialized-cash-classification-helpers");
|
|
18
|
+
const materialized_cash_accumulator_helpers_1 = require("./materialized-cash-accumulator-helpers");
|
|
19
|
+
/**
|
|
20
|
+
* M3 close-day helpers.
|
|
21
|
+
*
|
|
22
|
+
* ## Period counters are RE-FOLDED, never patched
|
|
23
|
+
*
|
|
24
|
+
* The discounted ledgers keep periods current by subtracting a day delta and adding
|
|
25
|
+
* the fresh one. That CANNOT work here, for the same reason it cannot work in the prep
|
|
26
|
+
* time report: cash has a NON-ADDITIVE counter. `staff_count` counts DISTINCT staff,
|
|
27
|
+
* and there is no way to subtract a distinct count - removing the day where a given
|
|
28
|
+
* staff member first appeared would leave a count that no longer corresponds to any
|
|
29
|
+
* set of days. So every touched period is rebuilt from its whole day set.
|
|
30
|
+
*
|
|
31
|
+
* ## The watermark comes from the FOLDED DAYS
|
|
32
|
+
*
|
|
33
|
+
* A folded document that inherited the STORED document watermark would look
|
|
34
|
+
* unchanged to `needsMaterializedCashReportWrite`, and the write would be skipped
|
|
35
|
+
* forever - freezing the period at its first closed day. That bug shipped once in the
|
|
36
|
+
* prep time report and is designed out here from the start.
|
|
37
|
+
*/
|
|
38
|
+
/** Period scopes this report materializes (everything but the day scope). */
|
|
39
|
+
exports.MATERIALIZED_CASH_PERIOD_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_CASH_REPORT_SCOPES.filter((scope) => String(scope) !== 'localDate');
|
|
40
|
+
/** True when the scope is the plain day scope. */
|
|
41
|
+
const isMaterializedCashDayScope = (scopeContext) => String(scopeContext) === 'localDate';
|
|
42
|
+
exports.isMaterializedCashDayScope = isMaterializedCashDayScope;
|
|
43
|
+
const cashScopeKey = (doc) => String(doc.scope_context) + '|' + String(doc.scope_field);
|
|
44
|
+
/**
|
|
45
|
+
* Merges TWO period entry sections, keyed on `entry_key`.
|
|
46
|
+
*
|
|
47
|
+
* Rows are deduplicated by identity rather than concatenated: a source row belongs to
|
|
48
|
+
* exactly one day, so the same `entry_key` appearing twice means the fold saw it
|
|
49
|
+
* twice, and money must never be counted twice.
|
|
50
|
+
*/
|
|
51
|
+
function mergeMaterializedCashEntrySections(target, source) {
|
|
52
|
+
const rowsByKey = new Map();
|
|
53
|
+
const seenByKey = new Map();
|
|
54
|
+
const absorb = (input) => {
|
|
55
|
+
if (input == null)
|
|
56
|
+
return;
|
|
57
|
+
for (const [key, section] of Object.entries(input)) {
|
|
58
|
+
const rows = rowsByKey.get(key) ?? [];
|
|
59
|
+
const seen = seenByKey.get(key) ?? new Set();
|
|
60
|
+
for (const row of section?.rows ?? []) {
|
|
61
|
+
const identity = String(row.entry_key ?? row.cash_in_out_id ?? '');
|
|
62
|
+
if (identity !== '') {
|
|
63
|
+
if (seen.has(identity))
|
|
64
|
+
continue;
|
|
65
|
+
seen.add(identity);
|
|
66
|
+
}
|
|
67
|
+
rows.push(row);
|
|
68
|
+
}
|
|
69
|
+
rowsByKey.set(key, rows);
|
|
70
|
+
seenByKey.set(key, seen);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
absorb(target);
|
|
74
|
+
absorb(source);
|
|
75
|
+
const out = {};
|
|
76
|
+
for (const [key, rows] of rowsByKey) {
|
|
77
|
+
rows.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime() ||
|
|
78
|
+
(String(a.cash_in_out_id) < String(b.cash_in_out_id) ? 1 : -1));
|
|
79
|
+
out[key] = { rows };
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/** True when the stored document already carries this exact content. */
|
|
84
|
+
function needsMaterializedCashReportWrite(existing, next) {
|
|
85
|
+
if (existing == null)
|
|
86
|
+
return true;
|
|
87
|
+
const stored = new Date(existing.source_watermark ?? 0).getTime();
|
|
88
|
+
const incoming = new Date(next.source_watermark ?? 0).getTime();
|
|
89
|
+
if (Number.isNaN(stored) || Number.isNaN(incoming))
|
|
90
|
+
return true;
|
|
91
|
+
return incoming > stored;
|
|
92
|
+
}
|
|
93
|
+
/** True when the stored entry document already carries these exact rows. */
|
|
94
|
+
function needsMaterializedCashEntriesWrite(existing, next) {
|
|
95
|
+
if (existing == null)
|
|
96
|
+
return true;
|
|
97
|
+
const stored = new Date(existing.source_watermark ?? 0).getTime();
|
|
98
|
+
const incoming = new Date(next.source_watermark ?? 0).getTime();
|
|
99
|
+
if (Number.isNaN(stored) || Number.isNaN(incoming))
|
|
100
|
+
return true;
|
|
101
|
+
return incoming > stored;
|
|
102
|
+
}
|
|
103
|
+
/** Max watermark across the day documents that feed a fold. */
|
|
104
|
+
function watermarkOfDays(dayDocs, fallback) {
|
|
105
|
+
let latest = fallback.getTime();
|
|
106
|
+
for (const doc of dayDocs) {
|
|
107
|
+
const time = new Date(doc?.source_watermark ?? 0).getTime();
|
|
108
|
+
if (!Number.isNaN(time) && time > latest)
|
|
109
|
+
latest = time;
|
|
110
|
+
}
|
|
111
|
+
return new Date(latest);
|
|
112
|
+
}
|
|
113
|
+
/** Folds the counters of every day document that belongs to one period scope. */
|
|
114
|
+
function foldMaterializedCashPeriodCounters(input) {
|
|
115
|
+
const { periodScope, periodScopeField, dayDocuments } = input;
|
|
116
|
+
const folded = {};
|
|
117
|
+
for (const dayDocument of dayDocuments ?? []) {
|
|
118
|
+
if (!(0, exports.isMaterializedCashDayScope)(String(dayDocument?.scope_context)))
|
|
119
|
+
continue;
|
|
120
|
+
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(String(dayDocument.scope_field));
|
|
121
|
+
if (fields == null)
|
|
122
|
+
continue;
|
|
123
|
+
if (fields[periodScope] !== periodScopeField)
|
|
124
|
+
continue;
|
|
125
|
+
const counters = dayDocument.cash_counters ?? {};
|
|
126
|
+
for (const [key, block] of Object.entries(counters)) {
|
|
127
|
+
folded[key] = (0, materialized_cash_accumulator_helpers_1.mergeMaterializedCashCounters)(folded[key] ?? (0, materialized_cash_classification_helpers_1.freshCashCounters)(), block);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return folded;
|
|
131
|
+
}
|
|
132
|
+
/** Folds the statement rows of every day document that belongs to one period scope. */
|
|
133
|
+
function foldMaterializedCashPeriodRows(input) {
|
|
134
|
+
const { periodScope, periodScopeField, dayDocuments } = input;
|
|
135
|
+
let merged = {};
|
|
136
|
+
for (const dayDocument of dayDocuments ?? []) {
|
|
137
|
+
if (!(0, exports.isMaterializedCashDayScope)(String(dayDocument?.scope_context)))
|
|
138
|
+
continue;
|
|
139
|
+
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(String(dayDocument.scope_field));
|
|
140
|
+
if (fields == null)
|
|
141
|
+
continue;
|
|
142
|
+
if (fields[periodScope] !== periodScopeField)
|
|
143
|
+
continue;
|
|
144
|
+
merged = mergeMaterializedCashEntrySections(merged, dayDocument.cash_entries ?? null);
|
|
145
|
+
}
|
|
146
|
+
return merged;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Builds the close-day plan for ONE tenant-day.
|
|
150
|
+
*
|
|
151
|
+
* The DAY scope is written from the compile. Every PERIOD scope the day touches is
|
|
152
|
+
* RE-FOLDED from its whole day set - and the touched set is the union of the closed
|
|
153
|
+
* day's periods AND every removed day's periods, because emptying a day has to clear
|
|
154
|
+
* its contribution from the periods it used to be part of.
|
|
155
|
+
*
|
|
156
|
+
* Returns null on malformed input.
|
|
157
|
+
*/
|
|
158
|
+
function buildTenantCashCloseDayPlan(input) {
|
|
159
|
+
if (input == null)
|
|
160
|
+
return null;
|
|
161
|
+
const { tenantId, reports, entries, reason } = input;
|
|
162
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
163
|
+
return null;
|
|
164
|
+
if (typeof reason !== 'string' || reason.length === 0)
|
|
165
|
+
return null;
|
|
166
|
+
const computedAt = input.computedAt ?? new Date();
|
|
167
|
+
const compiledReports = (reports ?? []).filter((doc) => String(doc?.tenant_id) === tenantId);
|
|
168
|
+
const compiledEntries = (entries ?? []).filter((doc) => String(doc?.tenant_id) === tenantId);
|
|
169
|
+
const storedReports = (input.existing ?? []).filter((doc) => String(doc?.tenant_id) === tenantId);
|
|
170
|
+
const storedEntries = (input.existingEntries ?? []).filter((doc) => String(doc?.tenant_id) === tenantId);
|
|
171
|
+
const compiledDateDoc = compiledReports.find((doc) => (0, exports.isMaterializedCashDayScope)(String(doc.scope_context)));
|
|
172
|
+
const localDate = input.localDate ?? (compiledDateDoc == null ? null : String(compiledDateDoc.scope_field));
|
|
173
|
+
if (localDate == null || localDate === '')
|
|
174
|
+
return null;
|
|
175
|
+
const writes = [];
|
|
176
|
+
const entryWrites = [];
|
|
177
|
+
const staleDocuments = [];
|
|
178
|
+
const staleEntryDocuments = [];
|
|
179
|
+
const skippedDocuments = [];
|
|
180
|
+
const skippedEntryDocuments = [];
|
|
181
|
+
const storedReportsByScope = new Map();
|
|
182
|
+
for (const doc of storedReports)
|
|
183
|
+
storedReportsByScope.set(cashScopeKey(doc), doc);
|
|
184
|
+
const storedEntriesByScope = new Map();
|
|
185
|
+
for (const doc of storedEntries)
|
|
186
|
+
storedEntriesByScope.set(cashScopeKey(doc), doc);
|
|
187
|
+
const addWrite = (report) => {
|
|
188
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
189
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
190
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_REPORTS,
|
|
191
|
+
reason,
|
|
192
|
+
computedAt,
|
|
193
|
+
});
|
|
194
|
+
if (iteration == null)
|
|
195
|
+
return false;
|
|
196
|
+
writes.push({ report: persisted, iteration: iteration });
|
|
197
|
+
return true;
|
|
198
|
+
};
|
|
199
|
+
const addEntryWrite = (report) => {
|
|
200
|
+
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
201
|
+
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
202
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES,
|
|
203
|
+
reason,
|
|
204
|
+
computedAt,
|
|
205
|
+
});
|
|
206
|
+
if (iteration == null)
|
|
207
|
+
return false;
|
|
208
|
+
entryWrites.push({ report: persisted, iteration: iteration });
|
|
209
|
+
return true;
|
|
210
|
+
};
|
|
211
|
+
// ---- the DAY scope, straight from the compile ----
|
|
212
|
+
if (compiledDateDoc != null) {
|
|
213
|
+
const scopeKey = cashScopeKey(compiledDateDoc);
|
|
214
|
+
const existing = storedReportsByScope.get(scopeKey);
|
|
215
|
+
const next = {
|
|
216
|
+
...compiledDateDoc,
|
|
217
|
+
_id: existing?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
218
|
+
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
219
|
+
};
|
|
220
|
+
if (needsMaterializedCashReportWrite(existing, next))
|
|
221
|
+
addWrite(next);
|
|
222
|
+
else
|
|
223
|
+
skippedDocuments.push(existing);
|
|
224
|
+
}
|
|
225
|
+
const compiledDateEntries = compiledEntries.find((doc) => (0, exports.isMaterializedCashDayScope)(String(doc.scope_context)));
|
|
226
|
+
if (compiledDateEntries != null) {
|
|
227
|
+
const scopeKey = cashScopeKey(compiledDateEntries);
|
|
228
|
+
const existing = storedEntriesByScope.get(scopeKey);
|
|
229
|
+
const next = {
|
|
230
|
+
...compiledDateEntries,
|
|
231
|
+
_id: existing?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
232
|
+
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
233
|
+
};
|
|
234
|
+
if (needsMaterializedCashEntriesWrite(existing, next)) {
|
|
235
|
+
addEntryWrite(next);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
skippedEntryDocuments.push(existing);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// ---- DAY deletion: a stored day doc that no longer compiled ----
|
|
242
|
+
const compiledDateKeys = new Set(compiledReports
|
|
243
|
+
.filter((doc) => (0, exports.isMaterializedCashDayScope)(String(doc.scope_context)))
|
|
244
|
+
.map((doc) => cashScopeKey(doc)));
|
|
245
|
+
const removedDates = [];
|
|
246
|
+
for (const doc of storedReports) {
|
|
247
|
+
if (!(0, exports.isMaterializedCashDayScope)(String(doc.scope_context)))
|
|
248
|
+
continue;
|
|
249
|
+
if (String(doc.scope_field) !== localDate)
|
|
250
|
+
continue;
|
|
251
|
+
if (compiledDateKeys.has(cashScopeKey(doc)))
|
|
252
|
+
continue;
|
|
253
|
+
staleDocuments.push(doc);
|
|
254
|
+
removedDates.push(String(doc.scope_field));
|
|
255
|
+
}
|
|
256
|
+
const compiledDateEntryKeys = new Set(compiledEntries
|
|
257
|
+
.filter((doc) => (0, exports.isMaterializedCashDayScope)(String(doc.scope_context)))
|
|
258
|
+
.map((doc) => cashScopeKey(doc)));
|
|
259
|
+
for (const doc of storedEntries) {
|
|
260
|
+
if (!(0, exports.isMaterializedCashDayScope)(String(doc.scope_context)))
|
|
261
|
+
continue;
|
|
262
|
+
if (String(doc.scope_field) !== localDate)
|
|
263
|
+
continue;
|
|
264
|
+
if (compiledDateEntryKeys.has(cashScopeKey(doc)))
|
|
265
|
+
continue;
|
|
266
|
+
staleEntryDocuments.push(doc);
|
|
267
|
+
}
|
|
268
|
+
// ---- PERIOD re-fold ----
|
|
269
|
+
const nextDayDocs = storedReports.filter((doc) => {
|
|
270
|
+
if (!(0, exports.isMaterializedCashDayScope)(String(doc.scope_context)))
|
|
271
|
+
return false;
|
|
272
|
+
if (String(doc.scope_field) === localDate)
|
|
273
|
+
return false;
|
|
274
|
+
return true;
|
|
275
|
+
});
|
|
276
|
+
const willHaveDay = compiledDateDoc != null;
|
|
277
|
+
if (willHaveDay) {
|
|
278
|
+
nextDayDocs.push(writes.find((w) => (0, exports.isMaterializedCashDayScope)(String(w.report.scope_context)))?.report ??
|
|
279
|
+
compiledDateDoc);
|
|
280
|
+
}
|
|
281
|
+
const nextDayEntryDocs = storedEntries.filter((doc) => {
|
|
282
|
+
if (!(0, exports.isMaterializedCashDayScope)(String(doc.scope_context)))
|
|
283
|
+
return false;
|
|
284
|
+
return String(doc.scope_field) !== localDate;
|
|
285
|
+
});
|
|
286
|
+
const compiledDateEntryDoc = entryWrites.find((w) => (0, exports.isMaterializedCashDayScope)(String(w.report.scope_context)))?.report;
|
|
287
|
+
if (compiledDateEntryDoc != null)
|
|
288
|
+
nextDayEntryDocs.push(compiledDateEntryDoc);
|
|
289
|
+
const touchedPeriods = new Map();
|
|
290
|
+
const noteDay = (day) => {
|
|
291
|
+
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(day);
|
|
292
|
+
if (fields == null)
|
|
293
|
+
return;
|
|
294
|
+
for (const scope of exports.MATERIALIZED_CASH_PERIOD_SCOPES) {
|
|
295
|
+
const field = fields[String(scope)];
|
|
296
|
+
if (field == null || field === '')
|
|
297
|
+
continue;
|
|
298
|
+
touchedPeriods.set(String(scope) + '|' + field, { scope: String(scope), field });
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
noteDay(localDate);
|
|
302
|
+
for (const day of removedDates)
|
|
303
|
+
noteDay(day);
|
|
304
|
+
const periodFieldsOfDay = (day) => (0, scope_helpers_1.getMaterializedPeriodScopeFields)(day);
|
|
305
|
+
for (const { scope, field } of touchedPeriods.values()) {
|
|
306
|
+
const folded = foldMaterializedCashPeriodCounters({
|
|
307
|
+
periodScope: scope,
|
|
308
|
+
periodScopeField: field,
|
|
309
|
+
dayDocuments: nextDayDocs,
|
|
310
|
+
});
|
|
311
|
+
const existing = storedReportsByScope.get(scope + '|' + field);
|
|
312
|
+
const keys = Object.keys(folded).sort();
|
|
313
|
+
if (keys.length === 0) {
|
|
314
|
+
if (existing != null)
|
|
315
|
+
staleDocuments.push(existing);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const counters = {};
|
|
319
|
+
const counterRows = [];
|
|
320
|
+
for (const key of keys) {
|
|
321
|
+
counters[key] = folded[key];
|
|
322
|
+
counterRows.push({ key, counters: folded[key] });
|
|
323
|
+
}
|
|
324
|
+
const report = {
|
|
325
|
+
_id: existing?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
326
|
+
tenant_id: tenantId,
|
|
327
|
+
brand_id: existing?.brand_id ?? compiledDateDoc?.brand_id ?? '',
|
|
328
|
+
scope_context: scope,
|
|
329
|
+
scope_field: field,
|
|
330
|
+
day_index: null,
|
|
331
|
+
sale_type_key_filters: existing?.sale_type_key_filters ?? [...MATERIALIZED_REPORTS_1.CASH_KEY_FILTERS],
|
|
332
|
+
cash_counters: counters,
|
|
333
|
+
cash_counter_rows: counterRows,
|
|
334
|
+
iteration: existing?.iteration,
|
|
335
|
+
schema_version: existing?.schema_version ?? 1,
|
|
336
|
+
// FROM THE FOLDED DAYS - never the stored watermark, or the write would be
|
|
337
|
+
// skipped forever and the period would freeze at its first closed day.
|
|
338
|
+
source_watermark: watermarkOfDays(nextDayDocs, existing?.source_watermark ?? computedAt),
|
|
339
|
+
computed_at: computedAt,
|
|
340
|
+
createdAt: existing?.createdAt ?? computedAt,
|
|
341
|
+
updatedAt: computedAt,
|
|
342
|
+
};
|
|
343
|
+
const next = { ...report, iteration: Number(existing?.iteration ?? 0) + 1 };
|
|
344
|
+
if (needsMaterializedCashReportWrite(existing, next)) {
|
|
345
|
+
addWrite(next);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
skippedDocuments.push(existing);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
for (const { scope, field } of touchedPeriods.values()) {
|
|
352
|
+
const sections = foldMaterializedCashPeriodRows({
|
|
353
|
+
periodScope: scope,
|
|
354
|
+
periodScopeField: field,
|
|
355
|
+
dayDocuments: nextDayEntryDocs,
|
|
356
|
+
});
|
|
357
|
+
const existing = storedEntriesByScope.get(scope + '|' + field);
|
|
358
|
+
const keys = Object.keys(sections);
|
|
359
|
+
if (keys.length === 0) {
|
|
360
|
+
if (existing != null)
|
|
361
|
+
staleEntryDocuments.push(existing);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
let watermark = existing?.source_watermark ?? null;
|
|
365
|
+
for (const dayDoc of nextDayEntryDocs) {
|
|
366
|
+
const fields = periodFieldsOfDay(String(dayDoc.scope_field));
|
|
367
|
+
if (fields == null)
|
|
368
|
+
continue;
|
|
369
|
+
if (fields[scope] !== field)
|
|
370
|
+
continue;
|
|
371
|
+
const time = new Date(dayDoc.source_watermark ?? 0).getTime();
|
|
372
|
+
if (Number.isNaN(time))
|
|
373
|
+
continue;
|
|
374
|
+
if (watermark == null || time > new Date(watermark).getTime())
|
|
375
|
+
watermark = new Date(time);
|
|
376
|
+
}
|
|
377
|
+
const report = {
|
|
378
|
+
_id: existing?._id ?? new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
379
|
+
tenant_id: tenantId,
|
|
380
|
+
brand_id: existing?.brand_id ?? compiledDateEntries?.brand_id ?? '',
|
|
381
|
+
scope_context: scope,
|
|
382
|
+
scope_field: field,
|
|
383
|
+
day_index: null,
|
|
384
|
+
sale_type_key_filters: existing?.sale_type_key_filters ?? [...MATERIALIZED_REPORTS_1.CASH_KEY_FILTERS],
|
|
385
|
+
cash_entries: sections,
|
|
386
|
+
iteration: existing?.iteration,
|
|
387
|
+
schema_version: existing?.schema_version ?? 1,
|
|
388
|
+
source_watermark: watermark ?? computedAt,
|
|
389
|
+
computed_at: computedAt,
|
|
390
|
+
createdAt: existing?.createdAt ?? computedAt,
|
|
391
|
+
updatedAt: computedAt,
|
|
392
|
+
};
|
|
393
|
+
const next = { ...report, iteration: Number(existing?.iteration ?? 0) + 1 };
|
|
394
|
+
if (needsMaterializedCashEntriesWrite(existing, next)) {
|
|
395
|
+
addEntryWrite(next);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
skippedEntryDocuments.push(existing);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
writes,
|
|
403
|
+
entryWrites,
|
|
404
|
+
staleDocuments,
|
|
405
|
+
staleEntryDocuments,
|
|
406
|
+
skippedDocuments,
|
|
407
|
+
skippedEntryDocuments,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { IMaterializedTenantCashEntries } from '../../schemas/types/materialized_tenant_cash_entries';
|
|
2
|
+
import { IMaterializedTenantCashReport } from '../../schemas/types/materialized_tenant_cash_reports';
|
|
3
|
+
/**
|
|
4
|
+
* M3 cash - key grammar and the day compile.
|
|
5
|
+
*
|
|
6
|
+
* ## The key, and the ONE place this spec needed a decision
|
|
7
|
+
*
|
|
8
|
+
* The key is `<DRAWER_ID>:<REF_TYPE>` (decision (b3)). But a counter block holds BOTH
|
|
9
|
+
* `movements` and `sessions`, and a SESSION document has no `ref_type` at all - so the
|
|
10
|
+
* concept doc does not say which key a session belongs to. Resolved here as:
|
|
11
|
+
*
|
|
12
|
+
* session counters attach to the `<drawer_id>:DRAWER` key.
|
|
13
|
+
*
|
|
14
|
+
* That is the one key it can belong to without inventing a fake ref type: `DRAWER` is
|
|
15
|
+
* a real ledger ref type, and the rows carrying it ARE the session lifecycle (the
|
|
16
|
+
* opening float, every reopen, the count-out). So "drawer lifecycle movements + the
|
|
17
|
+
* session facts behind them" is exactly what that key means, and no read-side special
|
|
18
|
+
* casing or reserved token is needed. Flagged to the owner as a spec gap filled.
|
|
19
|
+
*
|
|
20
|
+
* ## The day compile
|
|
21
|
+
*
|
|
22
|
+
* Cash is NOT order-derived: the scope comes from the movement rows and the session
|
|
23
|
+
* documents directly. One key produces one counter block, and the block is stored
|
|
24
|
+
* TWICE - as a key-addressed map and as an array of rows - so the read is the
|
|
25
|
+
* canonical unwind/group/direct-sum pattern.
|
|
26
|
+
*/
|
|
27
|
+
/** The separator between the drawer id and the ref type inside a key. */
|
|
28
|
+
export declare const MATERIALIZED_CASH_KEY_SEPARATOR = ":";
|
|
29
|
+
/**
|
|
30
|
+
* Builds a key. The separator cannot appear in either component: a drawer id or ref
|
|
31
|
+
* type containing it would make the key unparseable, so such a row is SKIPPED by the
|
|
32
|
+
* caller rather than silently mis-keyed.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildMaterializedCashKey(drawerId: unknown, refType: unknown): string | null;
|
|
35
|
+
/** Splits a key back into its parts, or null when it is malformed. */
|
|
36
|
+
export declare function parseMaterializedCashKey(key: unknown): {
|
|
37
|
+
drawerId: string;
|
|
38
|
+
refType: string;
|
|
39
|
+
} | null;
|
|
40
|
+
/** The key that carries a drawer session counters. */
|
|
41
|
+
export declare function cashSessionKeyForDrawer(drawerId: unknown): string | null;
|
|
42
|
+
/** Input to one day compile. */
|
|
43
|
+
export interface ICashDayCompileInput {
|
|
44
|
+
tenantId: string;
|
|
45
|
+
brandId: string;
|
|
46
|
+
/** The business day being compiled - the DATE document's scope field. */
|
|
47
|
+
localDate: string;
|
|
48
|
+
/**
|
|
49
|
+
* `tenant_cash_in_out` rows whose `localDate` is this day. OPTIONAL: a day can
|
|
50
|
+
* legitimately have sessions but no movements (a drawer opened and closed with
|
|
51
|
+
* nothing in between), and pre-materialization history predates either.
|
|
52
|
+
*/
|
|
53
|
+
movements?: any[];
|
|
54
|
+
/**
|
|
55
|
+
* `tenant_cash_drawer_sessions` for this day, any drawer. OPTIONAL for the same
|
|
56
|
+
* reason - a movement without its session document is still a real ledger row and
|
|
57
|
+
* must not be dropped.
|
|
58
|
+
*/
|
|
59
|
+
sessions?: any[];
|
|
60
|
+
/** Optional `drawer_id -> display name`, for the statement rows. */
|
|
61
|
+
drawerNames?: Record<string, string | null>;
|
|
62
|
+
computedAt: Date;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Compiles one business day into the DATE report document plus the DATE entries
|
|
66
|
+
* document. Returns null when the day has NEITHER a movement NOR a session - an
|
|
67
|
+
* empted day writes nothing, and the close-day planner deletes what is left over.
|
|
68
|
+
*/
|
|
69
|
+
export declare function compileTenantCashReports(input: ICashDayCompileInput): {
|
|
70
|
+
reports: IMaterializedTenantCashReport[];
|
|
71
|
+
entries: IMaterializedTenantCashEntries[];
|
|
72
|
+
} | null;
|