@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,207 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getHourlyComparisonSettledLocalHour = getHourlyComparisonSettledLocalHour;
7
+ exports.getHourlyComparisonScopeField = getHourlyComparisonScopeField;
8
+ exports.compileTenantHourlyComparisonReports = compileTenantHourlyComparisonReports;
9
+ const mongoose_1 = __importDefault(require("mongoose"));
10
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
11
+ const materialized_sales_comparison_accumulator_helpers_1 = require("./materialized-sales-comparison-accumulator-helpers");
12
+ const key_helpers_1 = require("./key-helpers");
13
+ const scope_helpers_1 = require("./scope-helpers");
14
+ /**
15
+ * The tenant-local HOUR (0–23) of an order's settlement instant.
16
+ *
17
+ * Mirrors `getSalesComparisonSettledLocalDate` (same instant shift), so the day
18
+ * and the hour can never disagree.
19
+ */
20
+ function getHourlyComparisonSettledLocalHour(order, gmtOffset = 0) {
21
+ const raw = order?.order_settled_at;
22
+ if (raw == null)
23
+ return null;
24
+ const time = new Date(raw).getTime();
25
+ if (Number.isNaN(time))
26
+ return null;
27
+ const offset = Number.isFinite(gmtOffset) ? gmtOffset : 0;
28
+ return new Date(time + offset * 60 * 60 * 1000).getUTCHours();
29
+ }
30
+ /** `'YYYY-MM-DD HH'` of the settled day + hour. */
31
+ function getHourlyComparisonScopeField(localDate, hour) {
32
+ return (0, scope_helpers_1.getMaterializedHourScopeField)(localDate, hour);
33
+ }
34
+ const compareEntryDescending = (a, b) => {
35
+ const byTime = new Date(b.time).getTime() - new Date(a.time).getTime();
36
+ if (byTime !== 0)
37
+ return byTime;
38
+ // Same instant: `order_id` ASC, matching the page cursor.
39
+ return a.order_id < b.order_id ? -1 : a.order_id > b.order_id ? 1 : 0;
40
+ };
41
+ const watermarkOf = (order, fallback) => {
42
+ const raw = order?.updatedAt;
43
+ const time = raw == null ? NaN : new Date(raw).getTime();
44
+ return Number.isNaN(time) ? fallback : new Date(time);
45
+ };
46
+ /**
47
+ * Compiles one settled tenant-day.
48
+ *
49
+ * Returns EMPTY arrays (never null) when the day has no settled orders: an
50
+ * emptied day produces no hour document, and the close-day plan retires the
51
+ * stored ones.
52
+ */
53
+ function compileTenantHourlyComparisonReports(input) {
54
+ if (input == null)
55
+ return null;
56
+ const { tenantId, brandId, localDate, orders, computedAt } = input;
57
+ if (typeof tenantId !== 'string' || tenantId.length === 0)
58
+ return null;
59
+ if (typeof brandId !== 'string' || brandId.length === 0)
60
+ return null;
61
+ if (typeof localDate !== 'string' || localDate.length === 0)
62
+ return null;
63
+ if (!Array.isArray(orders))
64
+ return null;
65
+ if (!(computedAt instanceof Date) || Number.isNaN(computedAt.getTime()))
66
+ return null;
67
+ const dayIndex = (0, scope_helpers_1.getDayIndexFromLocalDate)(localDate);
68
+ if (dayIndex == null)
69
+ return null;
70
+ const buckets = new Map();
71
+ let contributingOrders = 0;
72
+ let skippedUnsettledOrders = 0;
73
+ let skippedForeignOrders = 0;
74
+ let skippedUnkeyableOrders = 0;
75
+ for (const order of orders) {
76
+ if (order == null)
77
+ continue;
78
+ if (order.is_deleted === true)
79
+ continue;
80
+ if (order.tenant_id != null && String(order.tenant_id) !== tenantId)
81
+ continue;
82
+ const settledDay = (0, materialized_sales_comparison_accumulator_helpers_1.getSalesComparisonSettledLocalDate)(order, input.gmtOffset);
83
+ if (settledDay == null) {
84
+ skippedUnsettledOrders += 1;
85
+ continue;
86
+ }
87
+ if (settledDay !== localDate) {
88
+ skippedForeignOrders += 1;
89
+ continue;
90
+ }
91
+ const hour = getHourlyComparisonSettledLocalHour(order, input.gmtOffset);
92
+ if (hour == null || hour < 0 || hour > 23) {
93
+ skippedUnsettledOrders += 1;
94
+ continue;
95
+ }
96
+ const key = (0, key_helpers_1.buildMaterializedReportKey)([String(order.order_status ?? ''), String(order.platform ?? '')]);
97
+ if (key == null) {
98
+ skippedUnkeyableOrders += 1;
99
+ continue;
100
+ }
101
+ let bucket = buckets.get(hour);
102
+ if (bucket == null) {
103
+ bucket = { counters: new Map(), rows: new Map(), watermark: null };
104
+ buckets.set(hour, bucket);
105
+ }
106
+ let counters = bucket.counters.get(key);
107
+ if (counters == null) {
108
+ counters = (0, materialized_sales_comparison_accumulator_helpers_1.createEmptySalesComparisonCounters)();
109
+ bucket.counters.set(key, counters);
110
+ }
111
+ (0, materialized_sales_comparison_accumulator_helpers_1.addOrderToSalesComparisonCounters)(counters, order);
112
+ const settledAt = new Date(order.order_settled_at);
113
+ const gross = (0, materialized_sales_comparison_accumulator_helpers_1.getOrderGrossAmountCents)(order);
114
+ const discount = (0, materialized_sales_comparison_accumulator_helpers_1.getOrderDiscountAmountCents)(order);
115
+ const row = {
116
+ order_id: String(order._id ?? ''),
117
+ order_number: order.order_number == null ? null : Number(order.order_number),
118
+ time: settledAt.toISOString(),
119
+ order_status: String(order.order_status ?? ''),
120
+ platform: String(order.platform ?? ''),
121
+ net_amount: gross - discount,
122
+ discount_amount: discount,
123
+ item_count: (0, materialized_sales_comparison_accumulator_helpers_1.getOrderItemCount)(order),
124
+ };
125
+ const rows = bucket.rows.get(key);
126
+ if (rows == null)
127
+ bucket.rows.set(key, [row]);
128
+ else
129
+ rows.push(row);
130
+ const orderWatermark = watermarkOf(order, computedAt);
131
+ if (bucket.watermark == null || orderWatermark.getTime() > bucket.watermark.getTime()) {
132
+ bucket.watermark = orderWatermark;
133
+ }
134
+ contributingOrders += 1;
135
+ }
136
+ if (buckets.size === 0) {
137
+ return {
138
+ reports: [],
139
+ entries: [],
140
+ contributingOrders,
141
+ skippedUnsettledOrders,
142
+ skippedForeignOrders,
143
+ skippedUnkeyableOrders,
144
+ };
145
+ }
146
+ const reports = [];
147
+ const entries = [];
148
+ for (const hour of [...buckets.keys()].sort((a, b) => a - b)) {
149
+ const bucket = buckets.get(hour);
150
+ const scopeField = (0, scope_helpers_1.getMaterializedHourScopeField)(localDate, hour);
151
+ if (scopeField == null)
152
+ continue;
153
+ const salesCounters = {};
154
+ const counterRows = [];
155
+ const entrySections = {};
156
+ for (const key of [...bucket.counters.keys()].sort()) {
157
+ const counters = bucket.counters.get(key);
158
+ salesCounters[key] = counters;
159
+ counterRows.push({ key, counters });
160
+ const rows = (bucket.rows.get(key) ?? []).slice().sort(compareEntryDescending);
161
+ if (rows.length > 0)
162
+ entrySections[key] = { rows };
163
+ }
164
+ const sourceWatermark = bucket.watermark ?? computedAt;
165
+ reports.push({
166
+ _id: new mongoose_1.default.Types.ObjectId().toHexString(),
167
+ tenant_id: tenantId,
168
+ brand_id: brandId,
169
+ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
170
+ scope_field: scopeField,
171
+ day_index: dayIndex,
172
+ sale_type_key_filters: [...MATERIALIZED_REPORTS_1.HOURLY_COMPARISON_KEY_FILTERS],
173
+ sales_counters: salesCounters,
174
+ sales_counter_rows: counterRows,
175
+ schema_version: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION,
176
+ source_watermark: sourceWatermark,
177
+ computed_at: computedAt,
178
+ createdAt: computedAt,
179
+ updatedAt: computedAt,
180
+ iteration: 1,
181
+ });
182
+ entries.push({
183
+ _id: new mongoose_1.default.Types.ObjectId().toHexString(),
184
+ tenant_id: tenantId,
185
+ brand_id: brandId,
186
+ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
187
+ scope_field: scopeField,
188
+ day_index: dayIndex,
189
+ sale_type_key_filters: [...MATERIALIZED_REPORTS_1.HOURLY_COMPARISON_KEY_FILTERS],
190
+ sales_entries: entrySections,
191
+ schema_version: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION,
192
+ source_watermark: sourceWatermark,
193
+ computed_at: computedAt,
194
+ createdAt: computedAt,
195
+ updatedAt: computedAt,
196
+ iteration: 1,
197
+ });
198
+ }
199
+ return {
200
+ reports,
201
+ entries,
202
+ contributingOrders,
203
+ skippedUnsettledOrders,
204
+ skippedForeignOrders,
205
+ skippedUnkeyableOrders,
206
+ };
207
+ }
@@ -0,0 +1,23 @@
1
+ import { SALES_COMPARISON_BASELINE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
+ import { IReportCalendarSelection } from '../types/report-calendar';
3
+ import { IGetMaterializedReportScopeGroup } from '../types/materialized-reports-apis';
4
+ /** The hours a selection's profile covers, in business order (06…23, 00…05). */
5
+ export declare function getHourlyComparisonProfileHours(selection: IReportCalendarSelection): number[];
6
+ export interface IHourlyComparisonScopeGroupsResult {
7
+ /** One `localHour` group with every exact label (empty for a zero window). */
8
+ groups: IGetMaterializedReportScopeGroup[];
9
+ /** The days the profile covers (for display/debug). */
10
+ days: string[];
11
+ /** The hour-of-day set the profile covers. */
12
+ hours: number[];
13
+ }
14
+ /**
15
+ * Current profile groups. LIVE is not served (concept §9): the close writes the
16
+ * hour documents, so a running day has none.
17
+ */
18
+ export declare function buildHourlyComparisonScopeGroups(selection: IReportCalendarSelection): IHourlyComparisonScopeGroupsResult | null;
19
+ /**
20
+ * Baseline profile groups. `NONE` (or an unservable selection) returns `null`;
21
+ * a valid window with no matching day returns an empty group list.
22
+ */
23
+ export declare function buildHourlyComparisonBaselineScopeGroups(selection: IReportCalendarSelection, baseline: SALES_COMPARISON_BASELINE_ENUM | string | null | undefined): IHourlyComparisonScopeGroupsResult | null;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHourlyComparisonProfileHours = getHourlyComparisonProfileHours;
4
+ exports.buildHourlyComparisonScopeGroups = buildHourlyComparisonScopeGroups;
5
+ exports.buildHourlyComparisonBaselineScopeGroups = buildHourlyComparisonBaselineScopeGroups;
6
+ const REPORT_CALENDAR_1 = require("../../constants/REPORT_CALENDAR");
7
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
8
+ const materialized_sales_comparison_baseline_helpers_1 = require("./materialized-sales-comparison-baseline-helpers");
9
+ const materialized_reports_selection_helpers_1 = require("./materialized-reports-selection-helpers");
10
+ const scope_helpers_1 = require("./scope-helpers");
11
+ /**
12
+ * Hourly Comparison scope groups.
13
+ *
14
+ * The report reads HOUR documents, so a calendar selection is decoded into the
15
+ * exact `localHour` labels of its EFFECTIVE days — not into day/period groups.
16
+ * The baseline window is the Sales Comparison derivation (equal-length previous
17
+ * period / same-length previous year), then the same hour labels.
18
+ *
19
+ * The time-of-day refinement NARROWS the profile (proposed decision, concept
20
+ * §11.2): `16:00 → 20:00` reads hours 16, 17, 18, 19 on every selected day,
21
+ * end-exclusive, with the same 06:00 business-morning wrap rule as every other
22
+ * hour read. An invalid/incomplete window is ignored (all 24 hours), matching
23
+ * the shared decoder's posture.
24
+ *
25
+ * Returns `null` for an unservable selection; an EMPTY array is a valid window
26
+ * with no matching day (a real zero, not an error).
27
+ */
28
+ const hourOf = (time) => {
29
+ if (time == null)
30
+ return null;
31
+ const match = /^(\d{2}):00$/.exec(time);
32
+ if (match == null)
33
+ return null;
34
+ const hour = Number(match[1]);
35
+ return hour >= 0 && hour <= 23 ? hour : null;
36
+ };
37
+ /** The hours a selection's profile covers, in business order (06…23, 00…05). */
38
+ function getHourlyComparisonProfileHours(selection) {
39
+ const fromHour = hourOf(selection.timeStart);
40
+ const toHour = hourOf(selection.timeEnd);
41
+ if (fromHour == null || toHour == null || !(0, materialized_reports_selection_helpers_1.isValidBusinessHourWindow)(fromHour, toHour)) {
42
+ return Array.from({ length: 24 }, (_, hour) => hour);
43
+ }
44
+ const hours = [];
45
+ let cursor = fromHour;
46
+ // `isValidBusinessHourWindow` guarantees a non-empty walk within one
47
+ // business day; the bound is a belt-and-braces guard.
48
+ for (let step = 0; step < 24; step += 1) {
49
+ if (cursor === toHour)
50
+ break;
51
+ hours.push(cursor);
52
+ cursor = (cursor + 1) % 24;
53
+ }
54
+ return hours;
55
+ }
56
+ /** Exact `'YYYY-MM-DD HH'` labels for a day set × the profile's hours. */
57
+ const hourLabelsForDays = (days, hours) => {
58
+ const labels = [];
59
+ for (const day of days) {
60
+ for (const hour of hours) {
61
+ const label = (0, scope_helpers_1.getMaterializedHourScopeField)(day, hour);
62
+ // A malformed day is a data issue: the caller gets null, never a
63
+ // silently smaller profile.
64
+ if (label == null)
65
+ return [];
66
+ labels.push(label);
67
+ }
68
+ }
69
+ return [...new Set(labels)].sort();
70
+ };
71
+ /**
72
+ * Current profile groups. LIVE is not served (concept §9): the close writes the
73
+ * hour documents, so a running day has none.
74
+ */
75
+ function buildHourlyComparisonScopeGroups(selection) {
76
+ if (selection == null || typeof selection !== 'object')
77
+ return null;
78
+ if (selection.mode === REPORT_CALENDAR_1.CALENDAR_MODE_ENUM.LIVE)
79
+ return null;
80
+ const days = (0, materialized_reports_selection_helpers_1.getDayKeysFromCalendarSelection)(selection);
81
+ if (days.length === 0)
82
+ return null;
83
+ const hours = getHourlyComparisonProfileHours(selection);
84
+ const labels = hourLabelsForDays(days, hours);
85
+ return {
86
+ days: [...new Set(days)].sort(),
87
+ hours,
88
+ groups: labels.length === 0 ? [] : [{ scope_context: 'localHour', scope_field: labels }],
89
+ };
90
+ }
91
+ /**
92
+ * Baseline profile groups. `NONE` (or an unservable selection) returns `null`;
93
+ * a valid window with no matching day returns an empty group list.
94
+ */
95
+ function buildHourlyComparisonBaselineScopeGroups(selection, baseline) {
96
+ if (selection == null || typeof selection !== 'object')
97
+ return null;
98
+ if (selection.mode === REPORT_CALENDAR_1.CALENDAR_MODE_ENUM.LIVE)
99
+ return null;
100
+ if (baseline === MATERIALIZED_REPORTS_1.SALES_COMPARISON_BASELINE_ENUM.NONE)
101
+ return null;
102
+ if (baseline !== MATERIALIZED_REPORTS_1.SALES_COMPARISON_BASELINE_ENUM.PREVIOUS_PERIOD &&
103
+ baseline !== MATERIALIZED_REPORTS_1.SALES_COMPARISON_BASELINE_ENUM.PREVIOUS_YEAR) {
104
+ return null;
105
+ }
106
+ const range = (0, materialized_sales_comparison_baseline_helpers_1.getSalesComparisonBaselineRange)(selection, baseline);
107
+ if (range == null)
108
+ return null;
109
+ const hours = getHourlyComparisonProfileHours(selection);
110
+ const labels = hourLabelsForDays(range.days, hours);
111
+ return {
112
+ days: [...new Set(range.days)].sort(),
113
+ hours,
114
+ groups: labels.length === 0 ? [] : [{ scope_context: 'localHour', scope_field: labels }],
115
+ };
116
+ }
@@ -0,0 +1,25 @@
1
+ import { IOrder, IOrderPayment } from '../../schemas/types/orders';
2
+ import { IMaterializedPaymentsComparisonCounters } from '../../schemas/types/materialized_tenant_payments_comparison_reports';
3
+ import { getMaterializedPaymentGross, normalizeMaterializedPaymentType } from './tenant-sales-overview-helpers';
4
+ export declare function createEmptyPaymentsComparisonCounters(): IMaterializedPaymentsComparisonCounters;
5
+ /** The normalized payment type stored in the key (`PAY_LATER` → `UNPAID`). */
6
+ export declare function getPaymentsComparisonMethod(payment: IOrderPayment): string;
7
+ /**
8
+ * The stable identity of a payment row: `payment_id` (fallback the payment
9
+ * subdocument `_id`). Returns null when the payment carries neither — the
10
+ * caller skips it rather than collapsing two rows.
11
+ */
12
+ export declare function getPaymentsComparisonPaymentId(payment: IOrderPayment): string | null;
13
+ /** `<METHOD>:<STATUS>` or null when a component cannot be a Mongo key. */
14
+ export declare function buildPaymentsComparisonKey(payment: IOrderPayment, orderStatus: string): string | null;
15
+ /** Adds one INCLUDED payment's counters (mutates `target`). */
16
+ export declare function addPaymentToPaymentsComparisonCounters(target: IMaterializedPaymentsComparisonCounters, payment: IOrderPayment): void;
17
+ /** Adds every counter of `source` into `target` (mutates `target`). */
18
+ export declare function addPaymentsComparisonCounters(target: IMaterializedPaymentsComparisonCounters, source: IMaterializedPaymentsComparisonCounters | null | undefined): void;
19
+ export declare const ALL_PAYMENTS_COMPARISON_COUNTER_FIELDS: readonly ["payment_count", "payment_amount", "amount_due", "amount_paid", "amount_refunded", "card_charges", "refund_count", "unpaid_count"];
20
+ /** True when the payment must appear in this report (the overview facet rule). */
21
+ export declare function isPaymentIncluded(payment: IOrderPayment): boolean;
22
+ /** Convenience re-export for the compile + tests. */
23
+ export { getMaterializedPaymentGross, normalizeMaterializedPaymentType };
24
+ /** The order's key component; open-string status, so only the raw string matters. */
25
+ export type TPaymentsComparisonOrder = Pick<IOrder, 'order_status'>;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMaterializedPaymentType = exports.getMaterializedPaymentGross = exports.ALL_PAYMENTS_COMPARISON_COUNTER_FIELDS = void 0;
4
+ exports.createEmptyPaymentsComparisonCounters = createEmptyPaymentsComparisonCounters;
5
+ exports.getPaymentsComparisonMethod = getPaymentsComparisonMethod;
6
+ exports.getPaymentsComparisonPaymentId = getPaymentsComparisonPaymentId;
7
+ exports.buildPaymentsComparisonKey = buildPaymentsComparisonKey;
8
+ exports.addPaymentToPaymentsComparisonCounters = addPaymentToPaymentsComparisonCounters;
9
+ exports.addPaymentsComparisonCounters = addPaymentsComparisonCounters;
10
+ exports.isPaymentIncluded = isPaymentIncluded;
11
+ const key_helpers_1 = require("./key-helpers");
12
+ const tenant_sales_overview_helpers_1 = require("./tenant-sales-overview-helpers");
13
+ Object.defineProperty(exports, "getMaterializedPaymentGross", { enumerable: true, get: function () { return tenant_sales_overview_helpers_1.getMaterializedPaymentGross; } });
14
+ Object.defineProperty(exports, "normalizeMaterializedPaymentType", { enumerable: true, get: function () { return tenant_sales_overview_helpers_1.normalizeMaterializedPaymentType; } });
15
+ /**
16
+ * Payments Comparison counter accumulation.
17
+ *
18
+ * A payment row is included by the SAME rule as the overview's payment facet
19
+ * (`isPaymentIncludedInMaterializedSalesOverview`) and its money uses the SAME
20
+ * gross rule (`getMaterializedPaymentGross`, which handles refunds and card
21
+ * charges). `PAY_LATER` is reported as `UNPAID`, the existing one-place remap.
22
+ *
23
+ * The key is `<PAYMENT_METHOD>:<ORDER_STATUS>` (decision B). The method is an
24
+ * OPEN string; only reserved key characters make it un-keyable.
25
+ */
26
+ /** Coerces a source amount to a finite number (0 when absent/broken). */
27
+ const cents = (value) => {
28
+ const number = typeof value === 'number' ? value : Number(value);
29
+ return Number.isFinite(number) ? number : 0;
30
+ };
31
+ function createEmptyPaymentsComparisonCounters() {
32
+ return {
33
+ payment_count: 0,
34
+ payment_amount: 0,
35
+ amount_due: 0,
36
+ amount_paid: 0,
37
+ amount_refunded: 0,
38
+ card_charges: 0,
39
+ refund_count: 0,
40
+ unpaid_count: 0,
41
+ };
42
+ }
43
+ /** The normalized payment type stored in the key (`PAY_LATER` → `UNPAID`). */
44
+ function getPaymentsComparisonMethod(payment) {
45
+ return (0, tenant_sales_overview_helpers_1.normalizeMaterializedPaymentType)(String(payment.payment_type ?? ''));
46
+ }
47
+ /**
48
+ * The stable identity of a payment row: `payment_id` (fallback the payment
49
+ * subdocument `_id`). Returns null when the payment carries neither — the
50
+ * caller skips it rather than collapsing two rows.
51
+ */
52
+ function getPaymentsComparisonPaymentId(payment) {
53
+ const id = payment.payment_id ?? payment._id;
54
+ const text = id == null ? '' : String(id);
55
+ return text === '' ? null : text;
56
+ }
57
+ /** `<METHOD>:<STATUS>` or null when a component cannot be a Mongo key. */
58
+ function buildPaymentsComparisonKey(payment, orderStatus) {
59
+ return (0, key_helpers_1.buildMaterializedReportKey)([getPaymentsComparisonMethod(payment), orderStatus]);
60
+ }
61
+ /** Adds one INCLUDED payment's counters (mutates `target`). */
62
+ function addPaymentToPaymentsComparisonCounters(target, payment) {
63
+ if (target == null || payment == null)
64
+ return;
65
+ const amountRefunded = cents(payment.amount_refunded);
66
+ target.payment_count += 1;
67
+ target.payment_amount += (0, tenant_sales_overview_helpers_1.getMaterializedPaymentGross)(payment);
68
+ target.amount_due += cents(payment.amount_due);
69
+ target.amount_paid += cents(payment.amount_paid);
70
+ target.amount_refunded += amountRefunded;
71
+ target.card_charges += cents(payment.card_details?.card_charges);
72
+ if (amountRefunded > 0)
73
+ target.refund_count += 1;
74
+ if (getPaymentsComparisonMethod(payment) === 'UNPAID')
75
+ target.unpaid_count += 1;
76
+ }
77
+ /** Adds every counter of `source` into `target` (mutates `target`). */
78
+ function addPaymentsComparisonCounters(target, source) {
79
+ if (target == null || source == null)
80
+ return;
81
+ for (const field of exports.ALL_PAYMENTS_COMPARISON_COUNTER_FIELDS) {
82
+ target[field] += cents(source[field]);
83
+ }
84
+ }
85
+ exports.ALL_PAYMENTS_COMPARISON_COUNTER_FIELDS = [
86
+ 'payment_count',
87
+ 'payment_amount',
88
+ 'amount_due',
89
+ 'amount_paid',
90
+ 'amount_refunded',
91
+ 'card_charges',
92
+ 'refund_count',
93
+ 'unpaid_count',
94
+ ];
95
+ /** True when the payment must appear in this report (the overview facet rule). */
96
+ function isPaymentIncluded(payment) {
97
+ return (0, tenant_sales_overview_helpers_1.isPaymentIncludedInMaterializedSalesOverview)(payment);
98
+ }
@@ -0,0 +1,79 @@
1
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
+ import { IMaterializedPaymentsComparisonEntry, IMaterializedTenantPaymentsComparisonEntries } from '../../schemas/types/materialized_tenant_payments_comparison_entries';
3
+ import { IMaterializedPaymentsComparisonCounters, IMaterializedTenantPaymentsComparisonReport } from '../../schemas/types/materialized_tenant_payments_comparison_reports';
4
+ import { getMaterializedSalesComparisonPeriodDayKeys, getMaterializedSalesComparisonScopeRefsForDay } from './materialized-sales-comparison-close-day-helpers';
5
+ /**
6
+ * Payments Comparison close-day helpers.
7
+ *
8
+ * Mirrors Sales Comparison: the compile produces only the `localDate` pair, and
9
+ * every touched period is RE-FOLDED from its whole day set (never accumulated).
10
+ * Payment rows are de-duplicated by `(order_id, payment_id)` so a split bill is
11
+ * two rows but the same payment is never counted twice.
12
+ *
13
+ * The fetch contract is explicit (`getMaterializedPaymentsComparisonPeriodDayKeys`).
14
+ * The guard compares content when watermarks are equal, so a correction that
15
+ * removes a payment is written. Helpers never throw — invalid input returns null.
16
+ */
17
+ export declare const MATERIALIZED_PAYMENTS_COMPARISON_PERIOD_SCOPES: (MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR | MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK | MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK_OF_YEAR | MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH | MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_QUARTER | MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_SEMESTER | MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR)[];
18
+ export declare const isMaterializedPaymentsComparisonDayScope: (scopeContext: string) => boolean;
19
+ export declare const getMaterializedPaymentsComparisonScopeRefsForDay: typeof getMaterializedSalesComparisonScopeRefsForDay;
20
+ export declare const getMaterializedPaymentsComparisonPeriodDayKeys: typeof getMaterializedSalesComparisonPeriodDayKeys;
21
+ export declare function needsMaterializedPaymentsComparisonReportWrite(existing: IMaterializedTenantPaymentsComparisonReport | null | undefined, incoming: IMaterializedTenantPaymentsComparisonReport | null | undefined, force?: boolean): boolean;
22
+ export declare function needsMaterializedPaymentsComparisonEntriesWrite(existing: IMaterializedTenantPaymentsComparisonEntries | null | undefined, incoming: IMaterializedTenantPaymentsComparisonEntries | null | undefined, force?: boolean): boolean;
23
+ /** Folds the counters of every DAY document in one period. */
24
+ export declare function foldMaterializedPaymentsComparisonPeriodCounters(input: {
25
+ periodScope: MATERIALIZED_REPORT_SCOPE_ENUM | string;
26
+ periodScopeField: string;
27
+ dayDocuments: IMaterializedTenantPaymentsComparisonReport[];
28
+ }): Record<string, IMaterializedPaymentsComparisonCounters>;
29
+ export declare function mergeMaterializedPaymentsComparisonEntrySections(target: Record<string, {
30
+ rows: IMaterializedPaymentsComparisonEntry[];
31
+ }> | null, source: Record<string, {
32
+ rows: IMaterializedPaymentsComparisonEntry[];
33
+ }> | null): Record<string, {
34
+ rows: IMaterializedPaymentsComparisonEntry[];
35
+ }>;
36
+ export declare function foldMaterializedPaymentsComparisonPeriodEntries(input: {
37
+ periodScope: MATERIALIZED_REPORT_SCOPE_ENUM | string;
38
+ periodScopeField: string;
39
+ dayDocuments: IMaterializedTenantPaymentsComparisonEntries[];
40
+ }): Record<string, {
41
+ rows: IMaterializedPaymentsComparisonEntry[];
42
+ }>;
43
+ export interface IMaterializedPaymentsComparisonCloseDayWrite<T> {
44
+ report: T;
45
+ iteration: {
46
+ report_type: string;
47
+ report_id: string;
48
+ iteration: number;
49
+ schema_version: number;
50
+ reason: string;
51
+ snapshot: unknown;
52
+ createdAt: Date;
53
+ updatedAt: Date;
54
+ };
55
+ }
56
+ export interface ITenantPaymentsComparisonCloseDayPlan {
57
+ writes: IMaterializedPaymentsComparisonCloseDayWrite<IMaterializedTenantPaymentsComparisonReport>[];
58
+ entryWrites: IMaterializedPaymentsComparisonCloseDayWrite<IMaterializedTenantPaymentsComparisonEntries>[];
59
+ staleDocuments: IMaterializedTenantPaymentsComparisonReport[];
60
+ staleEntryDocuments: IMaterializedTenantPaymentsComparisonEntries[];
61
+ skippedDocuments: IMaterializedTenantPaymentsComparisonReport[];
62
+ skippedEntryDocuments: IMaterializedTenantPaymentsComparisonEntries[];
63
+ createdPeriodDocuments: {
64
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
65
+ scope_field: string;
66
+ }[];
67
+ }
68
+ export interface IBuildTenantPaymentsComparisonCloseDayPlanInput {
69
+ tenantId: string;
70
+ localDate?: string | null;
71
+ reports: IMaterializedTenantPaymentsComparisonReport[];
72
+ entries: IMaterializedTenantPaymentsComparisonEntries[];
73
+ existing?: IMaterializedTenantPaymentsComparisonReport[];
74
+ existingEntries?: IMaterializedTenantPaymentsComparisonEntries[];
75
+ reason: string;
76
+ force?: boolean;
77
+ computedAt?: Date;
78
+ }
79
+ export declare function buildTenantPaymentsComparisonCloseDayPlan(input: IBuildTenantPaymentsComparisonCloseDayPlanInput | null | undefined): ITenantPaymentsComparisonCloseDayPlan | null;