@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,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_MATERIALIZED_PAYMENTS_COMPARISON_COUNTERS = void 0;
4
+ /** Every additive counter, in display order. Ratios are derived, never listed. */
5
+ exports.ALL_MATERIALIZED_PAYMENTS_COMPARISON_COUNTERS = [
6
+ 'payment_count',
7
+ 'payment_amount',
8
+ 'amount_due',
9
+ 'amount_paid',
10
+ 'amount_refunded',
11
+ 'card_charges',
12
+ 'refund_count',
13
+ 'unpaid_count',
14
+ ];
@@ -0,0 +1,88 @@
1
+ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
+ import { MATERIALIZED_PREP_TIME_ANCHOR_ENUM, MATERIALIZED_PREP_TIME_TARGET_ENUM, MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Types for `materialized_tenant_prep_time_entries` (M2, decision a2).
5
+ *
6
+ * The per-ITEM rows behind the prep time report drill-down. They are the ONLY
7
+ * place a fallback-anchored item can be inspected, which is exactly what an
8
+ * operator debugging "why is this store prep time 0" needs: the row states its
9
+ * `anchor`, so a degenerate 0-minute fallback row is visibly different from a
10
+ * genuinely instant measured one.
11
+ *
12
+ * VOCABULARY NOTE: the concept doc section 6 sketches this row with
13
+ * `OWN | FALLBACK`. That sketch predates decision (b2), which settled on the
14
+ * two-bucket names MEASURED / UNMEASURED for the counters. One vocabulary is
15
+ * used throughout - the counters and the rows agree by construction.
16
+ */
17
+ /** One itemized prep row of the drill-down list. */
18
+ export interface IMaterializedPrepTimeEntry {
19
+ /**
20
+ * Stable identity of the row INSIDE its order - part of the
21
+ * `(time, order_id, entry_key)` page cursor.
22
+ */
23
+ entry_key: string;
24
+ order_id: string;
25
+ order_number?: number | null;
26
+ item_id: string | null;
27
+ item_name: string | null;
28
+ category_name: string | null;
29
+ /** Which population this row belongs to - the split that makes the report correct. */
30
+ anchor: MATERIALIZED_PREP_TIME_ANCHOR_ENUM;
31
+ /**
32
+ * Stored `ready_minutes` (null when never tracked). Whether the value is
33
+ * trustworthy is a property of `anchor`: only MEASURED rows carry a duration
34
+ * that may be read as a prep time.
35
+ */
36
+ duration_minutes: number | null;
37
+ prep_started_at: Date | null;
38
+ /**
39
+ * RECONSTRUCTED ready instant (`prep_started_at + ready_minutes`), never an
40
+ * invented timestamp. Null unless the row is MEASURED - the source field
41
+ * `ready_at` does not exist anywhere in the write path.
42
+ */
43
+ ready_at: Date | null;
44
+ is_ready: boolean;
45
+ /** The on-time target, and where it came from (decision e2). */
46
+ target_at: Date | null;
47
+ target_source: MATERIALIZED_PREP_TIME_TARGET_ENUM | null;
48
+ /** SIGNED minutes (ready_at - target_at); positive means late. MEASURED + target only. */
49
+ delta_minutes: number | null;
50
+ staff_id: string | null;
51
+ staff_name: string | null;
52
+ order_status: string;
53
+ platform: string;
54
+ /** Punch instant (`order.createdAt`) - the row ordering anchor. */
55
+ created_at: Date;
56
+ /** `YYYY-MM-DD HH` punch hour (null when unresolvable). */
57
+ local_hour: string | null;
58
+ }
59
+ /** Per-key row section of one document (rows may be empty, never absent-on-zero). */
60
+ export interface IMaterializedPrepTimeKeySection {
61
+ rows: IMaterializedPrepTimeEntry[];
62
+ }
63
+ /**
64
+ * One `materialized_tenant_prep_time_entries` document - tenant x scope context x
65
+ * scope value, capped at `LOCAL_MONTH`.
66
+ *
67
+ * Rows carry no `tenant_id`: the DOCUMENT carries it, and repeating it on every
68
+ * row would multiply the payload for no query benefit (the reads always address
69
+ * documents by tenant).
70
+ */
71
+ export interface IMaterializedTenantPrepTimeEntries {
72
+ _id: string;
73
+ tenant_id: string;
74
+ brand_id: string;
75
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
76
+ scope_field: string;
77
+ /** Denormalized weekday - set ONLY on `LOCAL_DATE` documents. */
78
+ day_index?: DAY_INDEX_ENUM | null;
79
+ sale_type_key_filters: MATERIALIZED_REPORT_KEY_FILTER_ENUM[];
80
+ /** One row section per observed filter-combination key; null when there are no rows. */
81
+ prep_time_entries: Record<string, IMaterializedPrepTimeKeySection> | null;
82
+ iteration?: number;
83
+ schema_version: number;
84
+ source_watermark: Date;
85
+ computed_at: Date;
86
+ createdAt: Date;
87
+ updatedAt: Date;
88
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,132 @@
1
+ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
+ import { MATERIALIZED_PREP_TIME_ANCHOR_ENUM, MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Types for `materialized_tenant_prep_time_reports` (M2).
5
+ *
6
+ * The report answers "how long does prep actually take, and how much of the
7
+ * operation do we actually observe?" - so COVERAGE is a first-class metric, not
8
+ * a footnote (concept doc section 3.2.1).
9
+ *
10
+ * The whole design follows from one rule: only items whose anchor is their OWN
11
+ * prep clock (`prep_started_at` AND `ready_minutes`) feed duration statistics.
12
+ * Everything else is counted in coverage only, because a fallback-anchored
13
+ * duration is degenerate (measured: avg 0.0, 99.8% zeros in one store) and
14
+ * blending the two under-reports the average by ~13x.
15
+ */
16
+ /** How much of the population is actually observed, per key. */
17
+ export interface IMaterializedPrepTimeCoverage {
18
+ /** Every item served in scope - ALWAYS the denominator of the report. */
19
+ item_count: number;
20
+ /** `is_ready === true` (NOT a proxy for measurement: 96.7-99.8% of items). */
21
+ ready_item_count: number;
22
+ /** `ready_minutes` present (measured + unmeasured). */
23
+ tracked_count: number;
24
+ /** `prep_started_at` present - the HONEST denominator for duration stats. */
25
+ own_anchor_count: number;
26
+ /** `ready_minutes` WITHOUT `prep_started_at` - the degenerate population. */
27
+ fallback_anchor_count: number;
28
+ /** Orders contributing at least one tracked item. */
29
+ order_count: number;
30
+ }
31
+ /**
32
+ * Duration statistics - MEASURED items ONLY.
33
+ *
34
+ * Durations are whole MINUTES. `min` / `max` / `sum` ignore values beyond
35
+ * `MATERIALIZED_PREP_TIME_MAX_MINUTES` (clock/backfill artefacts) while the
36
+ * `buckets` counts stay complete, so `count` is the trustworthy denominator and
37
+ * the extremes are never a single bad row.
38
+ */
39
+ export interface IMaterializedPrepTimeDuration {
40
+ min: number;
41
+ max: number;
42
+ sum: number;
43
+ count: number;
44
+ /** `ready_minutes === 0` - ~30% of measured rows, surfaced as its own bucket. */
45
+ instant_count: number;
46
+ /**
47
+ * Fixed histogram, bucket label -> count (see
48
+ * `MATERIALIZED_PREP_TIME_BUCKETS`). `median` / `p90` are derived from this and
49
+ * are therefore bucket-APPROXIMATE; the exact average is `sum / count`.
50
+ */
51
+ buckets: Record<string, number>;
52
+ }
53
+ /**
54
+ * Promise grading - measured items ONLY (the ready instant exists only there).
55
+ *
56
+ * `delta` is SIGNED minutes: positive means late, negative means early. The
57
+ * tolerance is `MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA` (0 for v1), kept as a
58
+ * constant so a grace window can be applied to the SAME materialized data later.
59
+ */
60
+ export interface IMaterializedPrepTimePromise {
61
+ /** Orders carrying an explicit estimate. */
62
+ promise_set_count: number;
63
+ /** Orders graded against the tenant default (ASAP). */
64
+ default_baseline_count: number;
65
+ on_time_count: number;
66
+ late_count: number;
67
+ /** Sum of the SIGNED deltas - the signed detail survives for a grace window. */
68
+ delta_sum: number;
69
+ /** No promise AND no tenant default - cannot be graded. */
70
+ no_target_count: number;
71
+ }
72
+ /** The per-key counter block. */
73
+ export interface IMaterializedPrepTimeCounters {
74
+ coverage: IMaterializedPrepTimeCoverage;
75
+ /** MEASURED items only. */
76
+ duration: IMaterializedPrepTimeDuration;
77
+ promise: IMaterializedPrepTimePromise;
78
+ /** Late rows (measured, delta > tolerance). Details live in the entries collection. */
79
+ late_items: {
80
+ count: number;
81
+ worst_delta: number;
82
+ };
83
+ }
84
+ /**
85
+ * The SAME counters as an ARRAY OF ROWS (`{ key, counters }`) - the read-path
86
+ * shape.
87
+ *
88
+ * Why beside the map: summing a dynamic-key map inside a MongoDB aggregation
89
+ * needs nested `$getField` calls (a dotted field name silently matches nothing),
90
+ * `$literal` around every computed field name and an `$arrayToObject` rebuild.
91
+ * With rows the read is the canonical pattern - `$unwind`, `$group` by
92
+ * `rows.key`, one direct `$sum` per counter field. Both copies are written from
93
+ * ONE accumulator pass, so they cannot disagree.
94
+ */
95
+ export interface IMaterializedPrepTimeCounterRow {
96
+ key: string;
97
+ counters: IMaterializedPrepTimeCounters;
98
+ }
99
+ /**
100
+ * One `materialized_tenant_prep_time_reports` document - tenant x scope context
101
+ * x scope value. Counters only; never rows.
102
+ */
103
+ export interface IMaterializedTenantPrepTimeReport {
104
+ _id: string;
105
+ tenant_id: string;
106
+ /** Required for brand-level reads (sum across the brand tenants). */
107
+ brand_id: string;
108
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
109
+ /** Format depends on `scope_context` (see `MATERIALIZED_REPORT_SCOPE_ENUM`). */
110
+ scope_field: string;
111
+ /** Denormalized weekday - set ONLY on `LOCAL_DATE` documents (no hour scope in v1). */
112
+ day_index?: DAY_INDEX_ENUM | null;
113
+ /** Ordered filter dimensions encoded into the key grammar (`ORDER_STATUS:PLATFORM`). */
114
+ sale_type_key_filters: MATERIALIZED_REPORT_KEY_FILTER_ENUM[];
115
+ /**
116
+ * One counter block per observed filter-combination key. Keys with no tracked
117
+ * items in the document scope are absent (pruned); an empty map is never
118
+ * written.
119
+ */
120
+ prep_time_counters: Record<string, IMaterializedPrepTimeCounters> | null;
121
+ /** The read-path shape of the SAME counters (see `IMaterializedPrepTimeCounterRow`). */
122
+ prep_time_counter_rows: IMaterializedPrepTimeCounterRow[] | null;
123
+ /** Bumped when the report is re-closed after a correction. */
124
+ iteration?: number;
125
+ schema_version: number;
126
+ source_watermark: Date;
127
+ computed_at: Date;
128
+ createdAt: Date;
129
+ updatedAt: Date;
130
+ }
131
+ /** Which anchor population a row belongs to (see the concept doc). */
132
+ export type TMaterializedPrepTimeAnchor = MATERIALIZED_PREP_TIME_ANCHOR_ENUM;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,43 @@
1
+ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
+ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Types for `materialized_tenant_sales_comparison_entries`.
5
+ *
6
+ * The itemized rows behind a counter, for the drill-down. Order rows ONLY: Sales
7
+ * Comparison and Payments Comparison are different reports, and a payment row here would
8
+ * double-count a split payment.
9
+ */
10
+ /** One order row behind a counter. */
11
+ export interface IMaterializedSalesComparisonEntry {
12
+ order_id: string;
13
+ order_number: number | null;
14
+ /** Tenant-local settled instant, ISO - the cursor key, newest-first. */
15
+ time: string;
16
+ order_status: string;
17
+ platform: string;
18
+ /** CENTS. */
19
+ net_amount: number;
20
+ discount_amount: number;
21
+ item_count: number;
22
+ }
23
+ /** The rows of one key. */
24
+ export interface IMaterializedSalesComparisonEntrySection {
25
+ rows: IMaterializedSalesComparisonEntry[];
26
+ }
27
+ /** A stored Sales Comparison entries document. */
28
+ export interface IMaterializedTenantSalesComparisonEntries {
29
+ _id: string;
30
+ tenant_id: string;
31
+ brand_id: string;
32
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
33
+ scope_field: string;
34
+ day_index: DAY_INDEX_ENUM | null;
35
+ sale_type_key_filters: MATERIALIZED_REPORT_KEY_FILTER_ENUM[];
36
+ sales_entries: Record<string, IMaterializedSalesComparisonEntrySection> | null;
37
+ schema_version: number;
38
+ source_watermark: Date;
39
+ computed_at: Date;
40
+ createdAt: Date;
41
+ updatedAt: Date;
42
+ iteration?: number;
43
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,74 @@
1
+ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
+ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Types for `materialized_tenant_sales_comparison_reports` (Sales Comparison).
5
+ *
6
+ * One metric, bucketed by a chosen grain, compared against a DERIVED baseline
7
+ * (`PREVIOUS_PERIOD` / `PREVIOUS_YEAR`). See
8
+ * `console/admin-panel/docs/report-sales-comparison-concept.md`.
9
+ *
10
+ * Two rules this shape exists to enforce:
11
+ *
12
+ * 1. **The comparison is NEVER stored.** A document is one period. `current` and
13
+ * `comparison` are both ordinary scope reads, subtracted in the formatter. A stored
14
+ * delta would need one document per (range x baseline) pair, which is unbounded.
15
+ * 2. **Additive primitives only.** `average_ticket` is not stored - it is
16
+ * `net_amount / order_count` in the formatter. A stored ratio cannot be summed across
17
+ * scopes and produces "average of averages" on any range read.
18
+ *
19
+ * Money is CENTS everywhere; the formatter converts to decimals.
20
+ */
21
+ /** Every counter this report carries, per `<ORDER_STATUS>:<PLATFORM>` key. */
22
+ export interface IMaterializedSalesComparisonCounters {
23
+ /** Orders in scope for this key. */
24
+ order_count: number;
25
+ /** Before discounts (CENTS). */
26
+ gross_amount: number;
27
+ discount_amount: number;
28
+ /** gross_amount - discount_amount. */
29
+ net_amount: number;
30
+ tax_amount: number;
31
+ service_charge_amount: number;
32
+ tip_amount: number;
33
+ refund_amount: number;
34
+ void_amount: number;
35
+ item_count: number;
36
+ guest_count: number;
37
+ }
38
+ /** One key of the read path shape (an UNWINDABLE row, not a map entry). */
39
+ export interface IMaterializedSalesComparisonCounterRow {
40
+ key: string;
41
+ counters: IMaterializedSalesComparisonCounters;
42
+ }
43
+ /**
44
+ * A stored Sales Comparison document.
45
+ *
46
+ * The counters exist TWICE on purpose: the key-addressed map is what the formatter and the
47
+ * close-day plan read, and the row array is what the read path `$unwind`s and `$sum`s (a
48
+ * `$facet` cannot walk a map). They must always agree - `verify:demo-data` asserts it.
49
+ */
50
+ export interface IMaterializedTenantSalesComparisonReport {
51
+ _id: string;
52
+ tenant_id: string;
53
+ brand_id: string;
54
+ /** The GRAIN: localDate | localWeek | localMonth | localQuarter | localSemester | localYear. */
55
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
56
+ scope_field: string;
57
+ /** The weekday - only day-scoped documents carry one. */
58
+ day_index: DAY_INDEX_ENUM | null;
59
+ /** Which dimensions the KEY encodes (`ORDER_STATUS`, `PLATFORM`). */
60
+ sale_type_key_filters: MATERIALIZED_REPORT_KEY_FILTER_ENUM[];
61
+ sales_counters: Record<string, IMaterializedSalesComparisonCounters> | null;
62
+ /** The read-path shape of the SAME counters. */
63
+ sales_counter_rows: IMaterializedSalesComparisonCounterRow[] | null;
64
+ schema_version: number;
65
+ /** Newest `order_settled_at` that contributed - the ANCHOR basis, with no time bias. */
66
+ source_watermark: Date;
67
+ computed_at: Date;
68
+ createdAt: Date;
69
+ updatedAt: Date;
70
+ /** Bumped when the report is re-closed after a correction. */
71
+ iteration?: number;
72
+ }
73
+ /** Every additive counter, in display order. Ratios are derived, never listed here. */
74
+ export declare const ALL_MATERIALIZED_SALES_COMPARISON_COUNTERS: readonly ["order_count", "gross_amount", "discount_amount", "net_amount", "tax_amount", "service_charge_amount", "tip_amount", "refund_amount", "void_amount", "item_count", "guest_count"];
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_MATERIALIZED_SALES_COMPARISON_COUNTERS = void 0;
4
+ /** Every additive counter, in display order. Ratios are derived, never listed here. */
5
+ exports.ALL_MATERIALIZED_SALES_COMPARISON_COUNTERS = [
6
+ 'order_count',
7
+ 'gross_amount',
8
+ 'discount_amount',
9
+ 'net_amount',
10
+ 'tax_amount',
11
+ 'service_charge_amount',
12
+ 'tip_amount',
13
+ 'refund_amount',
14
+ 'void_amount',
15
+ 'item_count',
16
+ 'guest_count',
17
+ ];
@@ -54,6 +54,13 @@ export interface RawFixtureOrder {
54
54
  platform: string;
55
55
  order_status: string;
56
56
  createdAt: string;
57
+ /**
58
+ * Present in every raw fixture document (verified against the JSON), and read by
59
+ * the demo generator for the close-day watermark. Declared here because
60
+ * `FixtureOrder` derives from this interface, so an undeclared field is a type
61
+ * error at the read site even though the data always carries it.
62
+ */
63
+ updatedAt?: string;
57
64
  order_settled_at: string | null;
58
65
  order_settled_at_mins?: number;
59
66
  amount_collected: number;
@@ -67,10 +74,17 @@ export interface RawFixtureOrder {
67
74
  day_index?: string;
68
75
  }
69
76
  /** Fixture order normalized for computation (dates parsed, payments always an array). */
70
- export interface FixtureOrder extends Omit<RawFixtureOrder, 'createdAt' | 'order_settled_at' | 'payments'> {
77
+ export interface FixtureOrder extends Omit<RawFixtureOrder, 'createdAt' | 'order_settled_at' | 'payments' | 'updatedAt'> {
71
78
  createdAt: Date;
72
79
  order_settled_at: Date | null;
73
80
  payments: FixturePayment[];
81
+ /**
82
+ * Normalized to a Date like the other instants, so a FixtureOrder stays
83
+ * assignable to `IOrder` (which types `updatedAt` as a Date) and the demo
84
+ * generator can read it as one. Falls back to `createdAt` when the raw document
85
+ * omits it, rather than leaving the field undefined at a Date-typed site.
86
+ */
87
+ updatedAt: Date;
74
88
  }
75
89
  /** Load a dataset with dates normalized to `Date` objects (cached per process). */
76
90
  export declare function loadOrdersDataset(name: OrdersDatasetName): FixtureOrder[];
@@ -74,6 +74,7 @@ function loadOrdersDataset(name) {
74
74
  createdAt: new Date(order.createdAt),
75
75
  order_settled_at: order.order_settled_at != null ? new Date(order.order_settled_at) : null,
76
76
  payments: order.payments ?? [],
77
+ updatedAt: order.updatedAt != null ? new Date(order.updatedAt) : new Date(order.createdAt),
77
78
  }));
78
79
  cache.set(name, orders);
79
80
  return orders;
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const materialized_cash_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-cash-compile-helpers");
4
+ /**
5
+ * M3 day compile.
6
+ *
7
+ * Two things are load-bearing here and worth stating: the key grammar must round-trip
8
+ * EXACTLY (a key that cannot be parsed back is a key that cannot be read), and a
9
+ * session must land on the drawer's DRAWER key, which is the spec gap this
10
+ * implementation had to close.
11
+ */
12
+ const TENANT = 'tenant-1';
13
+ const BRAND = 'brand-1';
14
+ const DAY = '2026-09-14';
15
+ const movement = (over = {}) => ({
16
+ _id: 'mov-' + Math.random().toString(36).slice(2),
17
+ tenant_id: TENANT,
18
+ drawer_id: 'drawer-A',
19
+ day_id: 'day-1',
20
+ shift_id: 'shift-1',
21
+ shift_number: 1,
22
+ ref_type: 'ORDER',
23
+ ref_id: 'order-1',
24
+ type: 'CASH_IN',
25
+ amount: 1000,
26
+ drawer_balance_before: 500,
27
+ drawer_balance_after: 1500,
28
+ staff_id: 'staff-1',
29
+ staff_name: 'Ali',
30
+ note: null,
31
+ createdAt: new Date('2026-09-14T10:00:00.000Z'),
32
+ localDate: DAY,
33
+ localHour: 10,
34
+ ...over,
35
+ });
36
+ describe('M3 key grammar', () => {
37
+ it('round-trips a drawer:ref key', () => {
38
+ const key = (0, materialized_cash_compile_helpers_1.buildMaterializedCashKey)('drawer-A', 'ORDER');
39
+ expect(key).toBe('drawer-A:ORDER');
40
+ expect((0, materialized_cash_compile_helpers_1.parseMaterializedCashKey)(key)).toEqual({ drawerId: 'drawer-A', refType: 'ORDER' });
41
+ });
42
+ it('REFUSES to build a key it could not parse back', () => {
43
+ // The separator must never appear inside a component, or the key is ambiguous.
44
+ expect((0, materialized_cash_compile_helpers_1.buildMaterializedCashKey)('drawer:A', 'ORDER')).toBeNull();
45
+ expect((0, materialized_cash_compile_helpers_1.buildMaterializedCashKey)('drawer-A', 'ORD:ER')).toBeNull();
46
+ expect((0, materialized_cash_compile_helpers_1.buildMaterializedCashKey)('', 'ORDER')).toBeNull();
47
+ expect((0, materialized_cash_compile_helpers_1.buildMaterializedCashKey)('drawer-A', null)).toBeNull();
48
+ expect((0, materialized_cash_compile_helpers_1.buildMaterializedCashKey)(undefined, 'ORDER')).toBeNull();
49
+ });
50
+ it('rejects malformed keys on parse', () => {
51
+ expect((0, materialized_cash_compile_helpers_1.parseMaterializedCashKey)('drawer-A')).toBeNull();
52
+ expect((0, materialized_cash_compile_helpers_1.parseMaterializedCashKey)('a:b:c')).toBeNull();
53
+ expect((0, materialized_cash_compile_helpers_1.parseMaterializedCashKey)(':ORDER')).toBeNull();
54
+ expect((0, materialized_cash_compile_helpers_1.parseMaterializedCashKey)(null)).toBeNull();
55
+ });
56
+ it('puts the session counters on the drawer DRAWER key', () => {
57
+ expect((0, materialized_cash_compile_helpers_1.cashSessionKeyForDrawer)('drawer-A')).toBe('drawer-A:DRAWER');
58
+ });
59
+ });
60
+ describe('M3 day compile', () => {
61
+ it('returns null for a day with nothing on it', () => {
62
+ expect((0, materialized_cash_compile_helpers_1.compileTenantCashReports)({
63
+ tenantId: TENANT,
64
+ brandId: BRAND,
65
+ localDate: DAY,
66
+ movements: [],
67
+ sessions: [],
68
+ computedAt: new Date(),
69
+ })).toBeNull();
70
+ });
71
+ it('rejects malformed input', () => {
72
+ const base = { tenantId: TENANT, brandId: BRAND, localDate: DAY, computedAt: new Date() };
73
+ expect((0, materialized_cash_compile_helpers_1.compileTenantCashReports)(null)).toBeNull();
74
+ expect((0, materialized_cash_compile_helpers_1.compileTenantCashReports)({ ...base, tenantId: '' })).toBeNull();
75
+ expect((0, materialized_cash_compile_helpers_1.compileTenantCashReports)({ ...base, localDate: '' })).toBeNull();
76
+ });
77
+ it('compiles one DATE report and one DATE entries document', () => {
78
+ const compiled = (0, materialized_cash_compile_helpers_1.compileTenantCashReports)({
79
+ tenantId: TENANT,
80
+ brandId: BRAND,
81
+ localDate: DAY,
82
+ movements: [
83
+ movement({
84
+ ref_type: 'DRAWER',
85
+ type: 'CASH_IN',
86
+ amount: 10000,
87
+ note: 'Drawer opened',
88
+ drawer_balance_before: 0,
89
+ }),
90
+ movement({ ref_type: 'ORDER', type: 'CASH_IN', amount: 5000 }),
91
+ movement({ ref_type: 'EXPENSE', type: 'CASH_OUT', amount: 2000 }),
92
+ ],
93
+ sessions: [
94
+ {
95
+ tenant_id: TENANT,
96
+ drawer_id: 'drawer-A',
97
+ status: 'CLOSED',
98
+ opening: { cash_amount: 10000 },
99
+ net_movements: 3000,
100
+ closing: { expected_cash_amount: 13000, cash_amount: 13000, difference: 0 },
101
+ },
102
+ ],
103
+ computedAt: new Date('2026-09-14T23:00:00.000Z'),
104
+ });
105
+ expect(compiled.reports).toHaveLength(1);
106
+ expect(compiled.entries).toHaveLength(1);
107
+ const report = compiled.reports[0];
108
+ expect(report.scope_context).toBe('localDate');
109
+ expect(report.scope_field).toBe(DAY);
110
+ expect(report.day_index).toBe('MONDAY');
111
+ expect(report.sale_type_key_filters).toEqual(['DRAWER_ID', 'REF_TYPE']);
112
+ // the map and the rows must describe the SAME counters.
113
+ const rows = report.cash_counter_rows;
114
+ expect(rows.length).toBe(Object.keys(report.cash_counters).length);
115
+ for (const r of rows) {
116
+ expect(report.cash_counters[r.key]).toEqual(r.counters);
117
+ }
118
+ // the session block lands on drawer-A:DRAWER, next to the lifecycle rows.
119
+ const drawerKey = report.cash_counters['drawer-A:DRAWER'];
120
+ expect(drawerKey.sessions.session_count).toBe(1);
121
+ expect(drawerKey.sessions.opening_float_amount).toBe(10000);
122
+ expect(drawerKey.movements.lifecycle.float_count).toBe(1);
123
+ // the operator movement lives on its own ref-type key.
124
+ expect(report.cash_counters['drawer-A:ORDER'].movements.operator.net).toBe(5000);
125
+ expect(report.cash_counters['drawer-A:EXPENSE'].movements.operator.net).toBe(-2000);
126
+ });
127
+ it('flags every statement row, newest first', () => {
128
+ const compiled = (0, materialized_cash_compile_helpers_1.compileTenantCashReports)({
129
+ tenantId: TENANT,
130
+ brandId: BRAND,
131
+ localDate: DAY,
132
+ movements: [
133
+ // localHour is the TENANT-LOCAL hour and takes precedence over createdAt
134
+ // (which is UTC) - set it so the assertion below is about precedence,
135
+ // not about a default leaking in from the factory.
136
+ movement({
137
+ ref_type: 'DRAWER',
138
+ type: 'CASH_IN',
139
+ amount: 10000,
140
+ note: 'Drawer opened',
141
+ drawer_balance_before: 0,
142
+ createdAt: new Date('2026-09-14T08:00:00.000Z'),
143
+ localHour: 8,
144
+ }),
145
+ movement({ ref_type: 'ORDER', type: 'CASH_IN', amount: 5000, createdAt: new Date('2026-09-14T12:00:00.000Z') }),
146
+ movement({
147
+ ref_type: 'SYSTEM_ADJUSTMENT',
148
+ type: 'CASH_OUT',
149
+ amount: 250,
150
+ note: 'System adjustment',
151
+ createdAt: new Date('2026-09-14T22:00:00.000Z'),
152
+ }),
153
+ ],
154
+ computedAt: new Date('2026-09-14T23:00:00.000Z'),
155
+ });
156
+ const sections = Object.values(compiled.entries[0].cash_entries);
157
+ const all = sections.flatMap((section) => section.rows);
158
+ expect(all).toHaveLength(3);
159
+ // Ordering is a PER-KEY invariant: each section is newest-first, and merging
160
+ // the sections into one global statement is the READER's job (the cursor is
161
+ // {time, cash_in_out_id}, i.e. a global time order). Asserting a global order
162
+ // here would be asserting something the storage does not promise.
163
+ for (const section of sections) {
164
+ for (let i = 1; i < section.rows.length; i += 1) {
165
+ expect(section.rows[i - 1].created_at.getTime()).toBeGreaterThanOrEqual(section.rows[i].created_at.getTime());
166
+ }
167
+ }
168
+ const systemRow = all.find((row) => row.is_system_adjustment);
169
+ expect(systemRow.signed_amount).toBe(-250);
170
+ expect(systemRow.amount).toBe(250);
171
+ const floatRow = all.find((row) => row.is_opening_float);
172
+ expect(floatRow.signed_amount).toBe(10000);
173
+ expect(floatRow.local_hour).toBe('2026-09-14 08');
174
+ });
175
+ it('never lets a FOREIGN tenant into the documents', () => {
176
+ const compiled = (0, materialized_cash_compile_helpers_1.compileTenantCashReports)({
177
+ tenantId: TENANT,
178
+ brandId: BRAND,
179
+ localDate: DAY,
180
+ movements: [movement(), movement({ tenant_id: 'someone-else', amount: 999999 })],
181
+ computedAt: new Date(),
182
+ });
183
+ expect(compiled.reports[0].cash_counters['drawer-A:ORDER'].movements.in_amount).toBe(1000);
184
+ });
185
+ it('skips a row it cannot key rather than mis-keying it', () => {
186
+ const compiled = (0, materialized_cash_compile_helpers_1.compileTenantCashReports)({
187
+ tenantId: TENANT,
188
+ brandId: BRAND,
189
+ localDate: DAY,
190
+ movements: [movement({ drawer_id: 'drawer:A' }), movement({ amount: 700 })],
191
+ computedAt: new Date(),
192
+ });
193
+ const total = Object.values(compiled.reports[0].cash_counters).reduce((sum, block) => sum + block.movements.in_amount, 0);
194
+ expect(total).toBe(700);
195
+ });
196
+ });