@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.
Files changed (336) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +448 -0
  2. package/esm/constants/enums/communications.js +1 -0
  3. package/esm/helpers/index.js +3 -0
  4. package/esm/helpers/materialized-reports/index.js +32 -0
  5. package/esm/helpers/materialized-reports/materialized-cash-accumulator-helpers.js +114 -0
  6. package/esm/helpers/materialized-reports/materialized-cash-classification-helpers.js +286 -0
  7. package/esm/helpers/materialized-reports/materialized-cash-close-day-helpers.js +396 -0
  8. package/esm/helpers/materialized-reports/materialized-cash-compile-helpers.js +244 -0
  9. package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +170 -0
  10. package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +426 -0
  11. package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +372 -0
  12. package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +214 -0
  13. package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +318 -0
  14. package/esm/helpers/materialized-reports/materialized-discount-classification-helpers.js +213 -0
  15. package/esm/helpers/materialized-reports/materialized-discount-close-day-helpers.js +604 -0
  16. package/esm/helpers/materialized-reports/materialized-discount-compile-helpers.js +186 -0
  17. package/esm/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.js +155 -0
  18. package/esm/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.js +199 -0
  19. package/esm/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +111 -0
  20. package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +88 -0
  21. package/esm/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.js +394 -0
  22. package/esm/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.js +167 -0
  23. package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +215 -0
  24. package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +476 -0
  25. package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +201 -0
  26. package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +7 -0
  27. package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +189 -0
  28. package/esm/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +157 -0
  29. package/esm/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +588 -0
  30. package/esm/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +175 -0
  31. package/esm/helpers/materialized-reports/tenant-cash-in-out-formatter.js +156 -0
  32. package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +230 -0
  33. package/esm/helpers/materialized-reports/tenant-discount-formatter.js +427 -0
  34. package/esm/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +237 -0
  35. package/esm/helpers/materialized-reports/tenant-payments-comparison-formatter.js +279 -0
  36. package/esm/helpers/materialized-reports/tenant-prep-time-formatter.js +228 -0
  37. package/esm/helpers/materialized-reports/tenant-sales-comparison-formatter.js +343 -0
  38. package/esm/helpers/reporting-contract/index.js +2 -0
  39. package/esm/helpers/reporting-contract/overview-contract.js +122 -0
  40. package/esm/helpers/reporting-contract/report-contract.js +228 -0
  41. package/esm/helpers/rider-earnings/index.js +1 -0
  42. package/esm/helpers/rider-earnings/rider-earnings.js +59 -0
  43. package/esm/helpers/rider-reports/index.js +2 -0
  44. package/esm/helpers/rider-reports/rider-daily-report.js +90 -0
  45. package/esm/helpers/rider-reports/rider-report.js +67 -0
  46. package/esm/schemas/models/deliveries.js +75 -0
  47. package/esm/schemas/models/index.js +15 -0
  48. package/esm/schemas/models/materialized_rider_daily_reports.js +39 -0
  49. package/esm/schemas/models/materialized_tenant_cash_entries.js +95 -0
  50. package/esm/schemas/models/materialized_tenant_cash_reports.js +77 -0
  51. package/esm/schemas/models/materialized_tenant_delivery_entries.js +63 -0
  52. package/esm/schemas/models/materialized_tenant_delivery_reports.js +63 -0
  53. package/esm/schemas/models/materialized_tenant_discount_entries.js +156 -0
  54. package/esm/schemas/models/materialized_tenant_discount_reports.js +333 -0
  55. package/esm/schemas/models/materialized_tenant_hourly_comparison_entries.js +87 -0
  56. package/esm/schemas/models/materialized_tenant_hourly_comparison_reports.js +99 -0
  57. package/esm/schemas/models/materialized_tenant_payments_comparison_entries.js +71 -0
  58. package/esm/schemas/models/materialized_tenant_payments_comparison_reports.js +76 -0
  59. package/esm/schemas/models/materialized_tenant_prep_time_entries.js +130 -0
  60. package/esm/schemas/models/materialized_tenant_prep_time_reports.js +109 -0
  61. package/esm/schemas/models/materialized_tenant_sales_comparison_entries.js +130 -0
  62. package/esm/schemas/models/materialized_tenant_sales_comparison_reports.js +154 -0
  63. package/esm/schemas/types/index.js +15 -0
  64. package/esm/schemas/types/materialized_rider_daily_reports.js +1 -0
  65. package/esm/schemas/types/materialized_tenant_cash_entries.js +1 -0
  66. package/esm/schemas/types/materialized_tenant_cash_reports.js +1 -0
  67. package/esm/schemas/types/materialized_tenant_delivery_entries.js +1 -0
  68. package/esm/schemas/types/materialized_tenant_delivery_reports.js +1 -0
  69. package/esm/schemas/types/materialized_tenant_discount_entries.js +1 -0
  70. package/esm/schemas/types/materialized_tenant_discount_reports.js +2 -0
  71. package/esm/schemas/types/materialized_tenant_hourly_comparison_entries.js +1 -0
  72. package/esm/schemas/types/materialized_tenant_hourly_comparison_reports.js +1 -0
  73. package/esm/schemas/types/materialized_tenant_payments_comparison_entries.js +1 -0
  74. package/esm/schemas/types/materialized_tenant_payments_comparison_reports.js +11 -0
  75. package/esm/schemas/types/materialized_tenant_prep_time_entries.js +1 -0
  76. package/esm/schemas/types/materialized_tenant_prep_time_reports.js +1 -0
  77. package/esm/schemas/types/materialized_tenant_sales_comparison_entries.js +1 -0
  78. package/esm/schemas/types/materialized_tenant_sales_comparison_reports.js +14 -0
  79. package/lib/constants/MATERIALIZED_REPORTS.d.ts +339 -2
  80. package/lib/constants/MATERIALIZED_REPORTS.js +450 -1
  81. package/lib/constants/enums/communications.d.ts +1 -0
  82. package/lib/constants/enums/communications.js +2 -1
  83. package/lib/helpers/index.d.ts +3 -0
  84. package/lib/helpers/index.js +3 -0
  85. package/lib/helpers/materialized-reports/index.d.ts +32 -0
  86. package/lib/helpers/materialized-reports/index.js +32 -0
  87. package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.d.ts +18 -0
  88. package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.js +118 -0
  89. package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.d.ts +90 -0
  90. package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.js +295 -0
  91. package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.d.ts +102 -0
  92. package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.js +409 -0
  93. package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.d.ts +72 -0
  94. package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +251 -0
  95. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.d.ts +7 -0
  96. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +173 -0
  97. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +84 -0
  98. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +438 -0
  99. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +97 -0
  100. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +385 -0
  101. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +40 -0
  102. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +218 -0
  103. package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +52 -0
  104. package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +324 -0
  105. package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.d.ts +50 -0
  106. package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.js +222 -0
  107. package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.d.ts +182 -0
  108. package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.js +615 -0
  109. package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.d.ts +47 -0
  110. package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +193 -0
  111. package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.d.ts +64 -0
  112. package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.js +163 -0
  113. package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.d.ts +61 -0
  114. package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.js +207 -0
  115. package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.d.ts +23 -0
  116. package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +116 -0
  117. package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.d.ts +25 -0
  118. package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +98 -0
  119. package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.d.ts +79 -0
  120. package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.js +407 -0
  121. package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.d.ts +35 -0
  122. package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.js +173 -0
  123. package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.d.ts +66 -0
  124. package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +224 -0
  125. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +128 -0
  126. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +490 -0
  127. package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.d.ts +46 -0
  128. package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +208 -0
  129. package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +8 -0
  130. package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +8 -1
  131. package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.d.ts +48 -0
  132. package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +204 -0
  133. package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.d.ts +22 -0
  134. package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +161 -0
  135. package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.d.ts +163 -0
  136. package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +603 -0
  137. package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.d.ts +68 -0
  138. package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +182 -0
  139. package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.d.ts +98 -0
  140. package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.js +159 -0
  141. package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +133 -0
  142. package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +233 -0
  143. package/lib/helpers/materialized-reports/tenant-discount-formatter.d.ts +114 -0
  144. package/lib/helpers/materialized-reports/tenant-discount-formatter.js +431 -0
  145. package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.d.ts +60 -0
  146. package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +243 -0
  147. package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.d.ts +75 -0
  148. package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.js +286 -0
  149. package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +97 -0
  150. package/lib/helpers/materialized-reports/tenant-prep-time-formatter.js +232 -0
  151. package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.d.ts +105 -0
  152. package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.js +349 -0
  153. package/lib/helpers/reporting-contract/index.d.ts +2 -0
  154. package/lib/helpers/reporting-contract/index.js +18 -0
  155. package/lib/helpers/reporting-contract/overview-contract.d.ts +55 -0
  156. package/lib/helpers/reporting-contract/overview-contract.js +126 -0
  157. package/lib/helpers/reporting-contract/report-contract.d.ts +159 -0
  158. package/lib/helpers/reporting-contract/report-contract.js +239 -0
  159. package/lib/helpers/rider-earnings/index.d.ts +1 -0
  160. package/lib/helpers/rider-earnings/index.js +17 -0
  161. package/lib/helpers/rider-earnings/rider-earnings.d.ts +58 -0
  162. package/lib/helpers/rider-earnings/rider-earnings.js +64 -0
  163. package/lib/helpers/rider-reports/index.d.ts +2 -0
  164. package/lib/helpers/rider-reports/index.js +18 -0
  165. package/lib/helpers/rider-reports/rider-daily-report.d.ts +26 -0
  166. package/lib/helpers/rider-reports/rider-daily-report.js +93 -0
  167. package/lib/helpers/rider-reports/rider-report.d.ts +49 -0
  168. package/lib/helpers/rider-reports/rider-report.js +70 -0
  169. package/lib/helpers/types/materialized-reports-apis.d.ts +297 -1
  170. package/lib/schemas/models/deliveries.d.ts +54 -0
  171. package/lib/schemas/models/deliveries.js +75 -0
  172. package/lib/schemas/models/expense_details.d.ts +3 -3
  173. package/lib/schemas/models/index.d.ts +15 -0
  174. package/lib/schemas/models/index.js +15 -0
  175. package/lib/schemas/models/materialized_rider_daily_reports.d.ts +27 -0
  176. package/lib/schemas/models/materialized_rider_daily_reports.js +42 -0
  177. package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +181 -0
  178. package/lib/schemas/models/materialized_tenant_cash_entries.js +98 -0
  179. package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +111 -0
  180. package/lib/schemas/models/materialized_tenant_cash_reports.js +80 -0
  181. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +98 -0
  182. package/lib/schemas/models/materialized_tenant_delivery_entries.js +66 -0
  183. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +98 -0
  184. package/lib/schemas/models/materialized_tenant_delivery_reports.js +66 -0
  185. package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +199 -0
  186. package/lib/schemas/models/materialized_tenant_discount_entries.js +159 -0
  187. package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +216 -0
  188. package/lib/schemas/models/materialized_tenant_discount_reports.js +336 -0
  189. package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +95 -0
  190. package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.js +82 -0
  191. package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +105 -0
  192. package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.js +91 -0
  193. package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +91 -0
  194. package/lib/schemas/models/materialized_tenant_payments_comparison_entries.js +70 -0
  195. package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +98 -0
  196. package/lib/schemas/models/materialized_tenant_payments_comparison_reports.js +71 -0
  197. package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +181 -0
  198. package/lib/schemas/models/materialized_tenant_prep_time_entries.js +133 -0
  199. package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +118 -0
  200. package/lib/schemas/models/materialized_tenant_prep_time_reports.js +112 -0
  201. package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +139 -0
  202. package/lib/schemas/models/materialized_tenant_sales_comparison_entries.js +120 -0
  203. package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +167 -0
  204. package/lib/schemas/models/materialized_tenant_sales_comparison_reports.js +137 -0
  205. package/lib/schemas/models/tenant_purchase_order_vendor_returns.d.ts +3 -3
  206. package/lib/schemas/models/warehouse_internal_movements.d.ts +6 -6
  207. package/lib/schemas/models/warehouse_purchase_order_receipts.d.ts +3 -3
  208. package/lib/schemas/models/warehouse_purchase_order_vendor_returns.d.ts +3 -3
  209. package/lib/schemas/models/warehouse_sale_deliveries.d.ts +6 -6
  210. package/lib/schemas/models/warehouse_sale_invoices.d.ts +3 -3
  211. package/lib/schemas/types/deliveries.d.ts +40 -1
  212. package/lib/schemas/types/index.d.ts +15 -0
  213. package/lib/schemas/types/index.js +15 -0
  214. package/lib/schemas/types/materialized_rider_daily_reports.d.ts +37 -0
  215. package/lib/schemas/types/materialized_rider_daily_reports.js +2 -0
  216. package/lib/schemas/types/materialized_tenant_cash_entries.d.ts +87 -0
  217. package/lib/schemas/types/materialized_tenant_cash_entries.js +2 -0
  218. package/lib/schemas/types/materialized_tenant_cash_reports.d.ts +144 -0
  219. package/lib/schemas/types/materialized_tenant_cash_reports.js +2 -0
  220. package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +98 -0
  221. package/lib/schemas/types/materialized_tenant_delivery_entries.js +2 -0
  222. package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +179 -0
  223. package/lib/schemas/types/materialized_tenant_delivery_reports.js +2 -0
  224. package/lib/schemas/types/materialized_tenant_discount_entries.d.ts +81 -0
  225. package/lib/schemas/types/materialized_tenant_discount_entries.js +2 -0
  226. package/lib/schemas/types/materialized_tenant_discount_reports.d.ts +209 -0
  227. package/lib/schemas/types/materialized_tenant_discount_reports.js +3 -0
  228. package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.d.ts +33 -0
  229. package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.js +2 -0
  230. package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.d.ts +40 -0
  231. package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.js +2 -0
  232. package/lib/schemas/types/materialized_tenant_payments_comparison_entries.d.ts +48 -0
  233. package/lib/schemas/types/materialized_tenant_payments_comparison_entries.js +2 -0
  234. package/lib/schemas/types/materialized_tenant_payments_comparison_reports.d.ts +51 -0
  235. package/lib/schemas/types/materialized_tenant_payments_comparison_reports.js +14 -0
  236. package/lib/schemas/types/materialized_tenant_prep_time_entries.d.ts +88 -0
  237. package/lib/schemas/types/materialized_tenant_prep_time_entries.js +2 -0
  238. package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +132 -0
  239. package/lib/schemas/types/materialized_tenant_prep_time_reports.js +2 -0
  240. package/lib/schemas/types/materialized_tenant_sales_comparison_entries.d.ts +43 -0
  241. package/lib/schemas/types/materialized_tenant_sales_comparison_entries.js +2 -0
  242. package/lib/schemas/types/materialized_tenant_sales_comparison_reports.d.ts +74 -0
  243. package/lib/schemas/types/materialized_tenant_sales_comparison_reports.js +17 -0
  244. package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
  245. package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
  246. package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
  247. package/lib/tests/materialized-reports/fixtures.d.ts +15 -1
  248. package/lib/tests/materialized-reports/fixtures.js +1 -0
  249. package/lib/tests/materialized-reports/materialized-cash-compile.test.d.ts +1 -0
  250. package/lib/tests/materialized-reports/materialized-cash-compile.test.js +196 -0
  251. package/lib/tests/materialized-reports/materialized-cash-fold.test.d.ts +1 -0
  252. package/lib/tests/materialized-reports/materialized-cash-fold.test.js +116 -0
  253. package/lib/tests/materialized-reports/materialized-cash-formatter.test.d.ts +1 -0
  254. package/lib/tests/materialized-reports/materialized-cash-formatter.test.js +152 -0
  255. package/lib/tests/materialized-reports/materialized-cash-plan.test.d.ts +1 -0
  256. package/lib/tests/materialized-reports/materialized-cash-plan.test.js +168 -0
  257. package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.d.ts +1 -0
  258. package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.js +267 -0
  259. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.d.ts +1 -0
  260. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +147 -0
  261. package/lib/tests/materialized-reports/materialized-delivery-compile.test.d.ts +1 -0
  262. package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +241 -0
  263. package/lib/tests/materialized-reports/materialized-delivery-fold.test.d.ts +1 -0
  264. package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +109 -0
  265. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.d.ts +1 -0
  266. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +141 -0
  267. package/lib/tests/materialized-reports/materialized-delivery-plan.test.d.ts +1 -0
  268. package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +198 -0
  269. package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.d.ts +1 -0
  270. package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.js +173 -0
  271. package/lib/tests/materialized-reports/materialized-discount-classification.test.d.ts +1 -0
  272. package/lib/tests/materialized-reports/materialized-discount-classification.test.js +339 -0
  273. package/lib/tests/materialized-reports/materialized-discount-close-day.test.d.ts +1 -0
  274. package/lib/tests/materialized-reports/materialized-discount-close-day.test.js +506 -0
  275. package/lib/tests/materialized-reports/materialized-discount-compile.test.d.ts +1 -0
  276. package/lib/tests/materialized-reports/materialized-discount-compile.test.js +161 -0
  277. package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.d.ts +1 -0
  278. package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.js +107 -0
  279. package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.d.ts +1 -0
  280. package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.js +125 -0
  281. package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.d.ts +1 -0
  282. package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.js +146 -0
  283. package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.d.ts +1 -0
  284. package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.js +127 -0
  285. package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.d.ts +1 -0
  286. package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.js +138 -0
  287. package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.d.ts +1 -0
  288. package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.js +90 -0
  289. package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.d.ts +1 -0
  290. package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.js +164 -0
  291. package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.d.ts +1 -0
  292. package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.js +117 -0
  293. package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.d.ts +1 -0
  294. package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.js +149 -0
  295. package/lib/tests/materialized-reports/materialized-prep-time-classification.test.d.ts +1 -0
  296. package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +273 -0
  297. package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.d.ts +1 -0
  298. package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +270 -0
  299. package/lib/tests/materialized-reports/materialized-prep-time-compile.test.d.ts +1 -0
  300. package/lib/tests/materialized-reports/materialized-prep-time-compile.test.js +217 -0
  301. package/lib/tests/materialized-reports/materialized-prep-time-constants.test.d.ts +1 -0
  302. package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +84 -0
  303. package/lib/tests/materialized-reports/materialized-prep-time-plan.test.d.ts +1 -0
  304. package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +176 -0
  305. package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.d.ts +1 -0
  306. package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.js +126 -0
  307. package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.d.ts +1 -0
  308. package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.js +206 -0
  309. package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.d.ts +1 -0
  310. package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.js +179 -0
  311. package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.d.ts +1 -0
  312. package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.js +196 -0
  313. package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.d.ts +1 -0
  314. package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.js +241 -0
  315. package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.d.ts +1 -0
  316. package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.js +96 -0
  317. package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.d.ts +1 -0
  318. package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.js +112 -0
  319. package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.d.ts +1 -0
  320. package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.js +142 -0
  321. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +8 -1
  322. package/lib/tests/materialized-reports/sales-comparison-reference.d.ts +55 -0
  323. package/lib/tests/materialized-reports/sales-comparison-reference.js +86 -0
  324. package/lib/tests/materialized-reports/tenant-discount-formatter.test.d.ts +1 -0
  325. package/lib/tests/materialized-reports/tenant-discount-formatter.test.js +289 -0
  326. package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.d.ts +1 -0
  327. package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.js +354 -0
  328. package/lib/tests/reporting-contract.test.d.ts +1 -0
  329. package/lib/tests/reporting-contract.test.js +267 -0
  330. package/lib/tests/rider-daily-report.test.d.ts +1 -0
  331. package/lib/tests/rider-daily-report.test.js +86 -0
  332. package/lib/tests/rider-earnings.test.d.ts +1 -0
  333. package/lib/tests/rider-earnings.test.js +65 -0
  334. package/lib/tests/rider-report.test.d.ts +1 -0
  335. package/lib/tests/rider-report.test.js +98 -0
  336. package/package.json +10 -1
@@ -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,90 @@
1
+ import { IMaterializedCashCounters } from '../../schemas/types/materialized_tenant_cash_reports';
2
+ /**
3
+ * M3 cash - lifecycle classifier + accumulators.
4
+ *
5
+ * ## The classification (decision (i3))
6
+ *
7
+ * Cash ledger rows carry NO explicit lifecycle flag, so provenance is derived from
8
+ * `ref_type` PLUS the note prefix written by the source, with the balance SHAPE as a
9
+ * secondary signal. The source notes are stable, source-verified strings:
10
+ *
11
+ * "Drawer opened - Day ..." -> the opening float
12
+ * "Drawer reopened - ... " -> a reopen re-baseline
13
+ * "Drawer closed - Day ..." -> the count-out
14
+ * "System adjustment - ..." -> an over/short sweep
15
+ *
16
+ * The classifier lives HERE and runs at COMPILE time; the entry rows store the
17
+ * resulting flags, so the read never re-derives them. When the durable
18
+ * `is_lifecycle` write-path stamp lands, only this function changes.
19
+ *
20
+ * ## The three nets, defined EXACTLY
21
+ *
22
+ * - `operator` - pure operator movement. Excludes the float, every reopen, the
23
+ * count-out AND the sweeps. This is the quantity the session
24
+ * document calls `net_movements`, so the two sources must AGREE.
25
+ * - `lifecycle` - float + reopen + count-out, broken out separately.
26
+ * - `system` - the over/short sweeps written at close.
27
+ *
28
+ * NOTE ON THE CONCEPT DOC: section 3.2.2 states the reconciliation as
29
+ * `ledger_net = operator_movement_net + reopen_amount + system_adjustment_net`.
30
+ * That is INCOMPLETE - it omits the float and the count-out, which are also ledger
31
+ * rows. Tracing the close routine shows why they matter: the count-out is written
32
+ * as `CASH_OUT amount = countedCash`, so a fully closed drawer-day nets to ZERO.
33
+ * The identity the harness must assert is therefore:
34
+ *
35
+ * ledger_net = operator.net + lifecycle.float_amount - lifecycle.countout_amount
36
+ * + lifecycle.reopen_amount + system.net
37
+ *
38
+ * which reduces to 0 for a closed day, while BOTH cross-collection checks
39
+ * (`operator.net == sessions.net_movements_amount` and
40
+ * `system.net == -sessions.variance_amount`) hold exactly.
41
+ */
42
+ /** Note prefixes written by the cash drawer repository. */
43
+ export declare const CASH_OPENING_NOTE_PREFIX = "Drawer opened";
44
+ export declare const CASH_REOPEN_NOTE_PREFIX = "Drawer reopened";
45
+ export declare const CASH_COUNT_OUT_NOTE_PREFIX = "Drawer closed";
46
+ export declare const CASH_SYSTEM_NOTE_PREFIX = "System adjustment";
47
+ /** Provenance of one ledger row. */
48
+ export interface ICashMovementProvenance {
49
+ is_opening_float: boolean;
50
+ is_reopen: boolean;
51
+ is_count_out: boolean;
52
+ is_system_adjustment: boolean;
53
+ /** True only for pure operator movement - the `net_movements` population. */
54
+ is_operator: boolean;
55
+ }
56
+ /**
57
+ * Classifies one ledger row.
58
+ *
59
+ * The note prefix is PRIMARY (it is what the source writes). The balance SHAPE is
60
+ * the fallback, because a lifecycle CASH_IN always opens from a zero balance while
61
+ * an operator cash-in never does - so a row whose note is missing or reworded is
62
+ * still classified correctly rather than silently counted as operator movement.
63
+ */
64
+ export declare function classifyCashMovement(row: any): ICashMovementProvenance;
65
+ /**
66
+ * A per-key accumulation buffer.
67
+ *
68
+ * `seen` de-duplicates ledger rows by source id: money must never be counted twice
69
+ * even if a source query returns a row across two overlapping reads.
70
+ */
71
+ export interface ICashAccumulator {
72
+ counters: IMaterializedCashCounters;
73
+ staff: Set<string>;
74
+ seen: Set<string>;
75
+ }
76
+ /** A zeroed counter block with every ref type present. */
77
+ export declare function freshCashCounters(): IMaterializedCashCounters;
78
+ /** A fresh buffer. */
79
+ export declare function freshCashAccumulator(): ICashAccumulator;
80
+ /** Adds one ledger row. Returns false when it was already counted. */
81
+ export declare function addCashMovement(acc: ICashAccumulator, row: any): boolean;
82
+ /** Adds one drawer session document. */
83
+ export declare function addCashSession(acc: ICashAccumulator, session: any): void;
84
+ /**
85
+ * Materializes the staff roster into the counter block (call before persisting).
86
+ *
87
+ * The IDS are kept alongside the count so a later period fold can take a UNION
88
+ * rather than a sum - a distinct count cannot be added.
89
+ */
90
+ export declare function finalizeCashAccumulator(acc: ICashAccumulator): IMaterializedCashCounters;
@@ -0,0 +1,295 @@
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
+ /**
12
+ * M3 cash - lifecycle classifier + accumulators.
13
+ *
14
+ * ## The classification (decision (i3))
15
+ *
16
+ * Cash ledger rows carry NO explicit lifecycle flag, so provenance is derived from
17
+ * `ref_type` PLUS the note prefix written by the source, with the balance SHAPE as a
18
+ * secondary signal. The source notes are stable, source-verified strings:
19
+ *
20
+ * "Drawer opened - Day ..." -> the opening float
21
+ * "Drawer reopened - ... " -> a reopen re-baseline
22
+ * "Drawer closed - Day ..." -> the count-out
23
+ * "System adjustment - ..." -> an over/short sweep
24
+ *
25
+ * The classifier lives HERE and runs at COMPILE time; the entry rows store the
26
+ * resulting flags, so the read never re-derives them. When the durable
27
+ * `is_lifecycle` write-path stamp lands, only this function changes.
28
+ *
29
+ * ## The three nets, defined EXACTLY
30
+ *
31
+ * - `operator` - pure operator movement. Excludes the float, every reopen, the
32
+ * count-out AND the sweeps. This is the quantity the session
33
+ * document calls `net_movements`, so the two sources must AGREE.
34
+ * - `lifecycle` - float + reopen + count-out, broken out separately.
35
+ * - `system` - the over/short sweeps written at close.
36
+ *
37
+ * NOTE ON THE CONCEPT DOC: section 3.2.2 states the reconciliation as
38
+ * `ledger_net = operator_movement_net + reopen_amount + system_adjustment_net`.
39
+ * That is INCOMPLETE - it omits the float and the count-out, which are also ledger
40
+ * rows. Tracing the close routine shows why they matter: the count-out is written
41
+ * as `CASH_OUT amount = countedCash`, so a fully closed drawer-day nets to ZERO.
42
+ * The identity the harness must assert is therefore:
43
+ *
44
+ * ledger_net = operator.net + lifecycle.float_amount - lifecycle.countout_amount
45
+ * + lifecycle.reopen_amount + system.net
46
+ *
47
+ * which reduces to 0 for a closed day, while BOTH cross-collection checks
48
+ * (`operator.net == sessions.net_movements_amount` and
49
+ * `system.net == -sessions.variance_amount`) hold exactly.
50
+ */
51
+ /** Note prefixes written by the cash drawer repository. */
52
+ exports.CASH_OPENING_NOTE_PREFIX = 'Drawer opened';
53
+ exports.CASH_REOPEN_NOTE_PREFIX = 'Drawer reopened';
54
+ exports.CASH_COUNT_OUT_NOTE_PREFIX = 'Drawer closed';
55
+ exports.CASH_SYSTEM_NOTE_PREFIX = 'System adjustment';
56
+ const noteOf = (row) => (typeof row?.note === 'string' ? row.note : '');
57
+ /**
58
+ * Classifies one ledger row.
59
+ *
60
+ * The note prefix is PRIMARY (it is what the source writes). The balance SHAPE is
61
+ * the fallback, because a lifecycle CASH_IN always opens from a zero balance while
62
+ * an operator cash-in never does - so a row whose note is missing or reworded is
63
+ * still classified correctly rather than silently counted as operator movement.
64
+ */
65
+ function classifyCashMovement(row) {
66
+ const refType = String(row?.ref_type ?? '');
67
+ const type = String(row?.type ?? '');
68
+ const note = noteOf(row);
69
+ const startsAtZero = Number(row?.drawer_balance_before ?? 0) === 0;
70
+ const isSystemAdjustment = refType === cash_1.CASH_IN_OUT_REF_ENUM.SYSTEM_ADJUSTMENT || note.startsWith(exports.CASH_SYSTEM_NOTE_PREFIX);
71
+ const isDrawerCashIn = refType === cash_1.CASH_IN_OUT_REF_ENUM.DRAWER && type === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_IN;
72
+ const isDrawerCashOut = refType === cash_1.CASH_IN_OUT_REF_ENUM.DRAWER && type === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_OUT;
73
+ // The NOTE is authoritative: the source always writes it, so an exact prefix
74
+ // match is trusted outright.
75
+ const isReopen = isDrawerCashIn && !isSystemAdjustment && note.startsWith(exports.CASH_REOPEN_NOTE_PREFIX);
76
+ // The SHAPE is only a fallback, and it cannot distinguish a float from a reopen -
77
+ // both open from a zero balance and both are CASH_IN / DRAWER. Given a note-less
78
+ // row the classifier therefore resolves to the FLOAT (the opening case), and the
79
+ // attribution is CROSS-CHECKED against the session documents instead of guessed:
80
+ // the harness asserts lifecycle.float_amount == sessions.opening_float_amount, so
81
+ // a note-less reopen shows up as a disagreement rather than silently mislabelling.
82
+ // (This is exactly the guessing decision (i3) accepts for v1 and the durable
83
+ // is_lifecycle stamp removes.)
84
+ const isOpeningFloat = isDrawerCashIn &&
85
+ !isSystemAdjustment &&
86
+ !isReopen &&
87
+ (note.startsWith(exports.CASH_OPENING_NOTE_PREFIX) || (note === '' && startsAtZero));
88
+ const isCountOut = isDrawerCashOut && !isSystemAdjustment && (note.startsWith(exports.CASH_COUNT_OUT_NOTE_PREFIX) || note === '');
89
+ const isLifecycle = isReopen || isOpeningFloat || isCountOut || isSystemAdjustment;
90
+ return {
91
+ is_opening_float: isOpeningFloat,
92
+ is_reopen: isReopen,
93
+ is_count_out: isCountOut,
94
+ is_system_adjustment: isSystemAdjustment,
95
+ is_operator: !isLifecycle,
96
+ };
97
+ }
98
+ const emptyFlow = () => ({
99
+ in_count: 0,
100
+ in_amount: 0,
101
+ out_count: 0,
102
+ out_amount: 0,
103
+ });
104
+ /** A zeroed counter block with every ref type present. */
105
+ function freshCashCounters() {
106
+ const byRef = {};
107
+ for (const refType of Object.values(cash_1.CASH_IN_OUT_REF_ENUM))
108
+ byRef[refType] = emptyFlow();
109
+ return {
110
+ movements: {
111
+ count: 0,
112
+ in_count: 0,
113
+ in_amount: 0,
114
+ out_count: 0,
115
+ out_amount: 0,
116
+ ledger_net: 0,
117
+ operator: { ...emptyFlow(), count: 0, net: 0 },
118
+ lifecycle: {
119
+ float_count: 0,
120
+ float_amount: 0,
121
+ reopen_count: 0,
122
+ reopen_amount: 0,
123
+ countout_count: 0,
124
+ countout_amount: 0,
125
+ },
126
+ system: { ...emptyFlow(), count: 0, net: 0 },
127
+ by_ref: byRef,
128
+ staff_count: 0,
129
+ staff_ids: [],
130
+ },
131
+ sessions: {
132
+ session_count: 0,
133
+ reopen_count: 0,
134
+ reopened_session_count: 0,
135
+ opening_float_amount: 0,
136
+ net_movements_amount: 0,
137
+ expected_close_amount: 0,
138
+ counted_close_amount: 0,
139
+ variance_amount: 0,
140
+ variance_positive_count: 0,
141
+ variance_negative_count: 0,
142
+ open_sessions_count: 0,
143
+ unmatched_close_count: 0,
144
+ },
145
+ };
146
+ }
147
+ /** A fresh buffer. */
148
+ function freshCashAccumulator() {
149
+ return { counters: freshCashCounters(), staff: new Set(), seen: new Set() };
150
+ }
151
+ /** Adds one ledger row. Returns false when it was already counted. */
152
+ function addCashMovement(acc, row) {
153
+ var _a;
154
+ if (acc == null || row == null)
155
+ return false;
156
+ const id = row.cash_in_out_id ?? row._id;
157
+ if (id != null) {
158
+ const key = String(id);
159
+ if (acc.seen.has(key))
160
+ return false;
161
+ acc.seen.add(key);
162
+ }
163
+ const provenance = classifyCashMovement(row);
164
+ const amount = Math.abs(Number(row.amount) || 0);
165
+ const isIn = String(row.type) === cash_1.CASH_IN_OUT_TYPE_ENUM.CASH_IN;
166
+ const movements = acc.counters.movements;
167
+ if (row.staff_id != null)
168
+ acc.staff.add(String(row.staff_id));
169
+ movements.count += 1;
170
+ if (isIn) {
171
+ movements.in_count += 1;
172
+ movements.in_amount += amount;
173
+ }
174
+ else {
175
+ movements.out_count += 1;
176
+ movements.out_amount += amount;
177
+ }
178
+ movements.ledger_net = movements.in_amount - movements.out_amount;
179
+ // by_ref is a BREAKDOWN of the same rows, so it uses the same classification.
180
+ const refKey = String(row.ref_type ?? cash_1.CASH_IN_OUT_REF_ENUM.NONE);
181
+ const refFlow = ((_a = movements.by_ref)[refKey] ?? (_a[refKey] = emptyFlow()));
182
+ if (isIn) {
183
+ refFlow.in_count += 1;
184
+ refFlow.in_amount += amount;
185
+ }
186
+ else {
187
+ refFlow.out_count += 1;
188
+ refFlow.out_amount += amount;
189
+ }
190
+ if (provenance.is_operator) {
191
+ const operator = movements.operator;
192
+ operator.count += 1;
193
+ if (isIn) {
194
+ operator.in_count += 1;
195
+ operator.in_amount += amount;
196
+ }
197
+ else {
198
+ operator.out_count += 1;
199
+ operator.out_amount += amount;
200
+ }
201
+ operator.net = operator.in_amount - operator.out_amount;
202
+ return true;
203
+ }
204
+ if (provenance.is_system_adjustment) {
205
+ const system = movements.system;
206
+ system.count += 1;
207
+ if (isIn) {
208
+ system.in_count += 1;
209
+ system.in_amount += amount;
210
+ }
211
+ else {
212
+ system.out_count += 1;
213
+ system.out_amount += amount;
214
+ }
215
+ system.net = system.in_amount - system.out_amount;
216
+ return true;
217
+ }
218
+ const lifecycle = movements.lifecycle;
219
+ if (provenance.is_opening_float) {
220
+ lifecycle.float_count += 1;
221
+ lifecycle.float_amount += amount;
222
+ }
223
+ else if (provenance.is_reopen) {
224
+ lifecycle.reopen_count += 1;
225
+ lifecycle.reopen_amount += amount;
226
+ }
227
+ else if (provenance.is_count_out) {
228
+ lifecycle.countout_count += 1;
229
+ lifecycle.countout_amount += amount;
230
+ }
231
+ return true;
232
+ }
233
+ /** Adds one drawer session document. */
234
+ function addCashSession(acc, session) {
235
+ if (acc == null || session == null)
236
+ return;
237
+ const sessions = acc.counters.sessions;
238
+ sessions.session_count += 1;
239
+ const reopenedTimes = Number(session.reopened_times) || 0;
240
+ sessions.reopen_count += reopenedTimes;
241
+ if (reopenedTimes > 0)
242
+ sessions.reopened_session_count += 1;
243
+ // The float is preserved across reopens, so it is counted ONCE per session.
244
+ sessions.opening_float_amount += Math.abs(Number(session.opening?.cash_amount) || 0);
245
+ sessions.net_movements_amount += Number(session.net_movements) || 0;
246
+ const closing = session.closing ?? null;
247
+ if (closing == null) {
248
+ // No closing record: a session still IN_USE is normal; anything else is a
249
+ // data-integrity tripwire.
250
+ if (String(session.status) === 'IN_USE')
251
+ sessions.open_sessions_count += 1;
252
+ else
253
+ sessions.unmatched_close_count += 1;
254
+ return;
255
+ }
256
+ // EVERY lifecycle counts, not just the last one.
257
+ //
258
+ // FOUND BY THE DEMO DATASET, not by reading the source: a REOPENED session has two
259
+ // (or more) lifecycles, and the ledger holds an over/short SWEEP for EACH of them -
260
+ // but `closing.difference` only describes the FINAL one. Summing just that made
261
+ // `variance_amount` undercount the day and broke the report's second cross-collection
262
+ // check (`system.net == -variance_amount`) on every reopened drawer-day: measured
263
+ // 120 vs -300 for one drawer, where lifecycle 1 was 420 OVER and lifecycle 2 was 300
264
+ // SHORT, netting to 120. The earlier lifecycle is snapshotted in
265
+ // `reopened_iterations`, so it is recoverable - and summing all of them makes the
266
+ // identity exact again.
267
+ const lifecycles = [closing];
268
+ for (const iteration of Array.isArray(session.reopened_iterations) ? session.reopened_iterations : []) {
269
+ if (iteration != null)
270
+ lifecycles.push(iteration);
271
+ }
272
+ for (const lifecycle of lifecycles) {
273
+ sessions.expected_close_amount += Number(lifecycle.expected_cash_amount) || 0;
274
+ sessions.counted_close_amount += Number(lifecycle.cash_amount) || 0;
275
+ const difference = Number(lifecycle.difference) || 0;
276
+ sessions.variance_amount += difference;
277
+ // SIGN: difference = expected - counted, so POSITIVE = SHORT.
278
+ if (difference > 0)
279
+ sessions.variance_positive_count += 1;
280
+ else if (difference < 0)
281
+ sessions.variance_negative_count += 1;
282
+ }
283
+ }
284
+ /**
285
+ * Materializes the staff roster into the counter block (call before persisting).
286
+ *
287
+ * The IDS are kept alongside the count so a later period fold can take a UNION
288
+ * rather than a sum - a distinct count cannot be added.
289
+ */
290
+ function finalizeCashAccumulator(acc) {
291
+ const ids = [...acc.staff].sort();
292
+ acc.counters.movements.staff_ids = ids;
293
+ acc.counters.movements.staff_count = ids.length;
294
+ return acc.counters;
295
+ }
@@ -0,0 +1,102 @@
1
+ import { IMaterializedCashEntry, IMaterializedTenantCashEntries } from '../../schemas/types/materialized_tenant_cash_entries';
2
+ import { IMaterializedCashCounters, IMaterializedTenantCashReport } from '../../schemas/types/materialized_tenant_cash_reports';
3
+ /**
4
+ * M3 close-day helpers.
5
+ *
6
+ * ## Period counters are RE-FOLDED, never patched
7
+ *
8
+ * The discounted ledgers keep periods current by subtracting a day delta and adding
9
+ * the fresh one. That CANNOT work here, for the same reason it cannot work in the prep
10
+ * time report: cash has a NON-ADDITIVE counter. `staff_count` counts DISTINCT staff,
11
+ * and there is no way to subtract a distinct count - removing the day where a given
12
+ * staff member first appeared would leave a count that no longer corresponds to any
13
+ * set of days. So every touched period is rebuilt from its whole day set.
14
+ *
15
+ * ## The watermark comes from the FOLDED DAYS
16
+ *
17
+ * A folded document that inherited the STORED document watermark would look
18
+ * unchanged to `needsMaterializedCashReportWrite`, and the write would be skipped
19
+ * forever - freezing the period at its first closed day. That bug shipped once in the
20
+ * prep time report and is designed out here from the start.
21
+ */
22
+ /** Period scopes this report materializes (everything but the day scope). */
23
+ export declare const MATERIALIZED_CASH_PERIOD_SCOPES: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM[];
24
+ /** True when the scope is the plain day scope. */
25
+ export declare const isMaterializedCashDayScope: (scopeContext: string) => boolean;
26
+ /**
27
+ * Merges TWO period entry sections, keyed on `entry_key`.
28
+ *
29
+ * Rows are deduplicated by identity rather than concatenated: a source row belongs to
30
+ * exactly one day, so the same `entry_key` appearing twice means the fold saw it
31
+ * twice, and money must never be counted twice.
32
+ */
33
+ export declare function mergeMaterializedCashEntrySections(target: Record<string, {
34
+ rows: IMaterializedCashEntry[];
35
+ }> | null, source: Record<string, {
36
+ rows: IMaterializedCashEntry[];
37
+ }> | null): Record<string, {
38
+ rows: IMaterializedCashEntry[];
39
+ }>;
40
+ /** True when the stored document already carries this exact content. */
41
+ export declare function needsMaterializedCashReportWrite(existing: IMaterializedTenantCashReport | null | undefined, next: IMaterializedTenantCashReport): boolean;
42
+ /** True when the stored entry document already carries these exact rows. */
43
+ export declare function needsMaterializedCashEntriesWrite(existing: IMaterializedTenantCashEntries | null | undefined, next: IMaterializedTenantCashEntries): boolean;
44
+ /** Folds the counters of every day document that belongs to one period scope. */
45
+ export declare function foldMaterializedCashPeriodCounters(input: {
46
+ periodScope: string;
47
+ periodScopeField: string;
48
+ dayDocuments: IMaterializedTenantCashReport[];
49
+ }): Record<string, IMaterializedCashCounters>;
50
+ /** Folds the statement rows of every day document that belongs to one period scope. */
51
+ export declare function foldMaterializedCashPeriodRows(input: {
52
+ periodScope: string;
53
+ periodScopeField: string;
54
+ dayDocuments: IMaterializedTenantCashEntries[];
55
+ }): Record<string, {
56
+ rows: IMaterializedCashEntry[];
57
+ }>;
58
+ /** One plan write: the document plus its iteration history row. */
59
+ export interface IMaterializedCashCloseDayWrite<T> {
60
+ report: T;
61
+ iteration: {
62
+ report_type: string;
63
+ report_id: string;
64
+ iteration: number;
65
+ schema_version: number;
66
+ reason: string;
67
+ snapshot: unknown;
68
+ createdAt: Date;
69
+ updatedAt: Date;
70
+ };
71
+ }
72
+ export interface ITenantCashCloseDayPlan {
73
+ writes: IMaterializedCashCloseDayWrite<IMaterializedTenantCashReport>[];
74
+ entryWrites: IMaterializedCashCloseDayWrite<IMaterializedTenantCashEntries>[];
75
+ /** DAY-scoped counter docs no longer backed by activity - delete by _id. */
76
+ staleDocuments: IMaterializedTenantCashReport[];
77
+ /** DAY-scoped entry docs no longer backed by rows - delete by _id. */
78
+ staleEntryDocuments: IMaterializedTenantCashEntries[];
79
+ skippedDocuments: IMaterializedTenantCashReport[];
80
+ skippedEntryDocuments: IMaterializedTenantCashEntries[];
81
+ }
82
+ export interface IBuildTenantCashCloseDayPlanInput {
83
+ tenantId: string;
84
+ reports: IMaterializedTenantCashReport[];
85
+ entries: IMaterializedTenantCashEntries[];
86
+ localDate?: string | null;
87
+ existing?: IMaterializedTenantCashReport[];
88
+ existingEntries?: IMaterializedTenantCashEntries[];
89
+ reason: string;
90
+ computedAt?: Date;
91
+ }
92
+ /**
93
+ * Builds the close-day plan for ONE tenant-day.
94
+ *
95
+ * The DAY scope is written from the compile. Every PERIOD scope the day touches is
96
+ * RE-FOLDED from its whole day set - and the touched set is the union of the closed
97
+ * day's periods AND every removed day's periods, because emptying a day has to clear
98
+ * its contribution from the periods it used to be part of.
99
+ *
100
+ * Returns null on malformed input.
101
+ */
102
+ export declare function buildTenantCashCloseDayPlan(input: IBuildTenantCashCloseDayPlanInput | null | undefined): ITenantCashCloseDayPlan | null;