@managesome/eposmatic-toolkit 0.4.9 → 0.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (351) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +455 -0
  2. package/esm/constants/enums/delivery.js +8 -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 +248 -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 +245 -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 +430 -0
  11. package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +373 -0
  12. package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +216 -0
  13. package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +319 -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 +115 -0
  20. package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +89 -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 +477 -0
  25. package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +201 -0
  26. package/esm/helpers/materialized-reports/materialized-reports-scope-group-helpers.js +9 -6
  27. package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +11 -4
  28. package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +189 -0
  29. package/esm/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +156 -0
  30. package/esm/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +588 -0
  31. package/esm/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +175 -0
  32. package/esm/helpers/materialized-reports/tenant-cash-in-out-formatter.js +157 -0
  33. package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +230 -0
  34. package/esm/helpers/materialized-reports/tenant-discount-formatter.js +427 -0
  35. package/esm/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +238 -0
  36. package/esm/helpers/materialized-reports/tenant-payments-comparison-formatter.js +282 -0
  37. package/esm/helpers/materialized-reports/tenant-prep-time-formatter.js +228 -0
  38. package/esm/helpers/materialized-reports/tenant-sales-comparison-formatter.js +346 -0
  39. package/esm/helpers/reporting-contract/index.js +2 -0
  40. package/esm/helpers/reporting-contract/overview-contract.js +123 -0
  41. package/esm/helpers/reporting-contract/report-contract.js +228 -0
  42. package/esm/helpers/rider-earnings/index.js +1 -0
  43. package/esm/helpers/rider-earnings/rider-earnings.js +53 -0
  44. package/esm/helpers/rider-reports/index.js +2 -0
  45. package/esm/helpers/rider-reports/rider-daily-report.js +90 -0
  46. package/esm/helpers/rider-reports/rider-report.js +67 -0
  47. package/esm/helpers/store/common-order-actions.js +3 -2
  48. package/esm/schemas/models/deliveries.js +82 -1
  49. package/esm/schemas/models/index.js +15 -0
  50. package/esm/schemas/models/materialized_credit_bills.js +1 -1
  51. package/esm/schemas/models/materialized_rider_daily_reports.js +39 -0
  52. package/esm/schemas/models/materialized_tenant_cash_entries.js +95 -0
  53. package/esm/schemas/models/materialized_tenant_cash_reports.js +77 -0
  54. package/esm/schemas/models/materialized_tenant_delivery_entries.js +63 -0
  55. package/esm/schemas/models/materialized_tenant_delivery_reports.js +63 -0
  56. package/esm/schemas/models/materialized_tenant_discount_entries.js +156 -0
  57. package/esm/schemas/models/materialized_tenant_discount_reports.js +333 -0
  58. package/esm/schemas/models/materialized_tenant_hourly_comparison_entries.js +87 -0
  59. package/esm/schemas/models/materialized_tenant_hourly_comparison_reports.js +99 -0
  60. package/esm/schemas/models/materialized_tenant_payments_comparison_entries.js +71 -0
  61. package/esm/schemas/models/materialized_tenant_payments_comparison_reports.js +76 -0
  62. package/esm/schemas/models/materialized_tenant_prep_time_entries.js +130 -0
  63. package/esm/schemas/models/materialized_tenant_prep_time_reports.js +109 -0
  64. package/esm/schemas/models/materialized_tenant_sales_comparison_entries.js +130 -0
  65. package/esm/schemas/models/materialized_tenant_sales_comparison_reports.js +154 -0
  66. package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +1 -1
  67. package/esm/schemas/types/index.js +15 -0
  68. package/esm/schemas/types/materialized_rider_daily_reports.js +1 -0
  69. package/esm/schemas/types/materialized_tenant_cash_entries.js +1 -0
  70. package/esm/schemas/types/materialized_tenant_cash_reports.js +1 -0
  71. package/esm/schemas/types/materialized_tenant_delivery_entries.js +1 -0
  72. package/esm/schemas/types/materialized_tenant_delivery_reports.js +1 -0
  73. package/esm/schemas/types/materialized_tenant_discount_entries.js +1 -0
  74. package/esm/schemas/types/materialized_tenant_discount_reports.js +2 -0
  75. package/esm/schemas/types/materialized_tenant_hourly_comparison_entries.js +1 -0
  76. package/esm/schemas/types/materialized_tenant_hourly_comparison_reports.js +1 -0
  77. package/esm/schemas/types/materialized_tenant_payments_comparison_entries.js +1 -0
  78. package/esm/schemas/types/materialized_tenant_payments_comparison_reports.js +11 -0
  79. package/esm/schemas/types/materialized_tenant_prep_time_entries.js +1 -0
  80. package/esm/schemas/types/materialized_tenant_prep_time_reports.js +1 -0
  81. package/esm/schemas/types/materialized_tenant_sales_comparison_entries.js +1 -0
  82. package/esm/schemas/types/materialized_tenant_sales_comparison_reports.js +14 -0
  83. package/lib/constants/MATERIALIZED_REPORTS.d.ts +345 -2
  84. package/lib/constants/MATERIALIZED_REPORTS.js +457 -1
  85. package/lib/constants/enums/delivery.d.ts +7 -0
  86. package/lib/constants/enums/delivery.js +9 -1
  87. package/lib/helpers/index.d.ts +3 -0
  88. package/lib/helpers/index.js +3 -0
  89. package/lib/helpers/materialized-reports/index.d.ts +32 -0
  90. package/lib/helpers/materialized-reports/index.js +32 -0
  91. package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.d.ts +18 -0
  92. package/lib/helpers/materialized-reports/materialized-cash-accumulator-helpers.js +118 -0
  93. package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.d.ts +142 -0
  94. package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.js +257 -0
  95. package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.d.ts +103 -0
  96. package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.js +409 -0
  97. package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.d.ts +73 -0
  98. package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +252 -0
  99. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.d.ts +7 -0
  100. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +173 -0
  101. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +113 -0
  102. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +442 -0
  103. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +98 -0
  104. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +386 -0
  105. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +41 -0
  106. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +220 -0
  107. package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +52 -0
  108. package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +325 -0
  109. package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.d.ts +50 -0
  110. package/lib/helpers/materialized-reports/materialized-discount-classification-helpers.js +222 -0
  111. package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.d.ts +182 -0
  112. package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.js +615 -0
  113. package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.d.ts +47 -0
  114. package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +193 -0
  115. package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.d.ts +64 -0
  116. package/lib/helpers/materialized-reports/materialized-hourly-comparison-close-day-helpers.js +163 -0
  117. package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.d.ts +61 -0
  118. package/lib/helpers/materialized-reports/materialized-hourly-comparison-compile-helpers.js +207 -0
  119. package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.d.ts +23 -0
  120. package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +120 -0
  121. package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.d.ts +25 -0
  122. package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +99 -0
  123. package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.d.ts +79 -0
  124. package/lib/helpers/materialized-reports/materialized-payments-comparison-close-day-helpers.js +407 -0
  125. package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.d.ts +35 -0
  126. package/lib/helpers/materialized-reports/materialized-payments-comparison-compile-helpers.js +173 -0
  127. package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.d.ts +98 -0
  128. package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +224 -0
  129. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +130 -0
  130. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +491 -0
  131. package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.d.ts +47 -0
  132. package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +208 -0
  133. package/lib/helpers/materialized-reports/materialized-reports-scope-group-helpers.d.ts +6 -3
  134. package/lib/helpers/materialized-reports/materialized-reports-scope-group-helpers.js +8 -5
  135. package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +8 -0
  136. package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +10 -3
  137. package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.d.ts +48 -0
  138. package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +204 -0
  139. package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.d.ts +22 -0
  140. package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +160 -0
  141. package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.d.ts +163 -0
  142. package/lib/helpers/materialized-reports/materialized-sales-comparison-close-day-helpers.js +603 -0
  143. package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.d.ts +68 -0
  144. package/lib/helpers/materialized-reports/materialized-sales-comparison-compile-helpers.js +182 -0
  145. package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.d.ts +98 -0
  146. package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.js +160 -0
  147. package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +133 -0
  148. package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +233 -0
  149. package/lib/helpers/materialized-reports/tenant-discount-formatter.d.ts +114 -0
  150. package/lib/helpers/materialized-reports/tenant-discount-formatter.js +431 -0
  151. package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.d.ts +60 -0
  152. package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +244 -0
  153. package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.d.ts +75 -0
  154. package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.js +289 -0
  155. package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +98 -0
  156. package/lib/helpers/materialized-reports/tenant-prep-time-formatter.js +232 -0
  157. package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.d.ts +105 -0
  158. package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.js +352 -0
  159. package/lib/helpers/reporting-contract/index.d.ts +2 -0
  160. package/lib/helpers/reporting-contract/index.js +18 -0
  161. package/lib/helpers/reporting-contract/overview-contract.d.ts +55 -0
  162. package/lib/helpers/reporting-contract/overview-contract.js +127 -0
  163. package/lib/helpers/reporting-contract/report-contract.d.ts +159 -0
  164. package/lib/helpers/reporting-contract/report-contract.js +239 -0
  165. package/lib/helpers/rider-earnings/index.d.ts +1 -0
  166. package/lib/helpers/rider-earnings/index.js +17 -0
  167. package/lib/helpers/rider-earnings/rider-earnings.d.ts +51 -0
  168. package/lib/helpers/rider-earnings/rider-earnings.js +57 -0
  169. package/lib/helpers/rider-reports/index.d.ts +2 -0
  170. package/lib/helpers/rider-reports/index.js +18 -0
  171. package/lib/helpers/rider-reports/rider-daily-report.d.ts +28 -0
  172. package/lib/helpers/rider-reports/rider-daily-report.js +93 -0
  173. package/lib/helpers/rider-reports/rider-report.d.ts +49 -0
  174. package/lib/helpers/rider-reports/rider-report.js +70 -0
  175. package/lib/helpers/store/common-order-actions.js +3 -2
  176. package/lib/helpers/types/materialized-reports-apis.d.ts +300 -1
  177. package/lib/schemas/models/deliveries.d.ts +58 -1
  178. package/lib/schemas/models/deliveries.js +81 -0
  179. package/lib/schemas/models/expense_details.d.ts +3 -3
  180. package/lib/schemas/models/index.d.ts +15 -0
  181. package/lib/schemas/models/index.js +15 -0
  182. package/lib/schemas/models/materialized_credit_bills.d.ts +3 -3
  183. package/lib/schemas/models/materialized_credit_bills.js +1 -1
  184. package/lib/schemas/models/materialized_rider_daily_reports.d.ts +27 -0
  185. package/lib/schemas/models/materialized_rider_daily_reports.js +42 -0
  186. package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +181 -0
  187. package/lib/schemas/models/materialized_tenant_cash_entries.js +98 -0
  188. package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +111 -0
  189. package/lib/schemas/models/materialized_tenant_cash_reports.js +80 -0
  190. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +98 -0
  191. package/lib/schemas/models/materialized_tenant_delivery_entries.js +66 -0
  192. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +98 -0
  193. package/lib/schemas/models/materialized_tenant_delivery_reports.js +66 -0
  194. package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +199 -0
  195. package/lib/schemas/models/materialized_tenant_discount_entries.js +159 -0
  196. package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +216 -0
  197. package/lib/schemas/models/materialized_tenant_discount_reports.js +336 -0
  198. package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +95 -0
  199. package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.js +82 -0
  200. package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +105 -0
  201. package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.js +91 -0
  202. package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +91 -0
  203. package/lib/schemas/models/materialized_tenant_payments_comparison_entries.js +70 -0
  204. package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +98 -0
  205. package/lib/schemas/models/materialized_tenant_payments_comparison_reports.js +71 -0
  206. package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +181 -0
  207. package/lib/schemas/models/materialized_tenant_prep_time_entries.js +133 -0
  208. package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +118 -0
  209. package/lib/schemas/models/materialized_tenant_prep_time_reports.js +112 -0
  210. package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +139 -0
  211. package/lib/schemas/models/materialized_tenant_sales_comparison_entries.js +120 -0
  212. package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +167 -0
  213. package/lib/schemas/models/materialized_tenant_sales_comparison_reports.js +137 -0
  214. package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +3 -3
  215. package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +1 -1
  216. package/lib/schemas/models/tenant_purchase_order_vendor_returns.d.ts +3 -3
  217. package/lib/schemas/models/warehouse_internal_movements.d.ts +6 -6
  218. package/lib/schemas/models/warehouse_purchase_order_receipts.d.ts +3 -3
  219. package/lib/schemas/models/warehouse_purchase_order_vendor_returns.d.ts +3 -3
  220. package/lib/schemas/models/warehouse_sale_deliveries.d.ts +6 -6
  221. package/lib/schemas/models/warehouse_sale_invoices.d.ts +3 -3
  222. package/lib/schemas/types/deliveries.d.ts +40 -1
  223. package/lib/schemas/types/index.d.ts +15 -0
  224. package/lib/schemas/types/index.js +15 -0
  225. package/lib/schemas/types/materialized_rider_daily_reports.d.ts +37 -0
  226. package/lib/schemas/types/materialized_rider_daily_reports.js +2 -0
  227. package/lib/schemas/types/materialized_tenant_cash_entries.d.ts +87 -0
  228. package/lib/schemas/types/materialized_tenant_cash_entries.js +2 -0
  229. package/lib/schemas/types/materialized_tenant_cash_reports.d.ts +144 -0
  230. package/lib/schemas/types/materialized_tenant_cash_reports.js +2 -0
  231. package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +98 -0
  232. package/lib/schemas/types/materialized_tenant_delivery_entries.js +2 -0
  233. package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +179 -0
  234. package/lib/schemas/types/materialized_tenant_delivery_reports.js +2 -0
  235. package/lib/schemas/types/materialized_tenant_discount_entries.d.ts +81 -0
  236. package/lib/schemas/types/materialized_tenant_discount_entries.js +2 -0
  237. package/lib/schemas/types/materialized_tenant_discount_reports.d.ts +209 -0
  238. package/lib/schemas/types/materialized_tenant_discount_reports.js +3 -0
  239. package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.d.ts +33 -0
  240. package/lib/schemas/types/materialized_tenant_hourly_comparison_entries.js +2 -0
  241. package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.d.ts +40 -0
  242. package/lib/schemas/types/materialized_tenant_hourly_comparison_reports.js +2 -0
  243. package/lib/schemas/types/materialized_tenant_payments_comparison_entries.d.ts +48 -0
  244. package/lib/schemas/types/materialized_tenant_payments_comparison_entries.js +2 -0
  245. package/lib/schemas/types/materialized_tenant_payments_comparison_reports.d.ts +51 -0
  246. package/lib/schemas/types/materialized_tenant_payments_comparison_reports.js +14 -0
  247. package/lib/schemas/types/materialized_tenant_prep_time_entries.d.ts +88 -0
  248. package/lib/schemas/types/materialized_tenant_prep_time_entries.js +2 -0
  249. package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +132 -0
  250. package/lib/schemas/types/materialized_tenant_prep_time_reports.js +2 -0
  251. package/lib/schemas/types/materialized_tenant_sales_comparison_entries.d.ts +43 -0
  252. package/lib/schemas/types/materialized_tenant_sales_comparison_entries.js +2 -0
  253. package/lib/schemas/types/materialized_tenant_sales_comparison_reports.d.ts +74 -0
  254. package/lib/schemas/types/materialized_tenant_sales_comparison_reports.js +17 -0
  255. package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +7 -0
  256. package/lib/tests/deliveries-schema.test.d.ts +1 -0
  257. package/lib/tests/deliveries-schema.test.js +70 -0
  258. package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
  259. package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
  260. package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
  261. package/lib/tests/materialized-reports/fixtures.d.ts +15 -1
  262. package/lib/tests/materialized-reports/fixtures.js +1 -0
  263. package/lib/tests/materialized-reports/materialized-cash-compile.test.d.ts +1 -0
  264. package/lib/tests/materialized-reports/materialized-cash-compile.test.js +197 -0
  265. package/lib/tests/materialized-reports/materialized-cash-fold.test.d.ts +1 -0
  266. package/lib/tests/materialized-reports/materialized-cash-fold.test.js +116 -0
  267. package/lib/tests/materialized-reports/materialized-cash-formatter.test.d.ts +1 -0
  268. package/lib/tests/materialized-reports/materialized-cash-formatter.test.js +153 -0
  269. package/lib/tests/materialized-reports/materialized-cash-plan.test.d.ts +1 -0
  270. package/lib/tests/materialized-reports/materialized-cash-plan.test.js +168 -0
  271. package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.d.ts +1 -0
  272. package/lib/tests/materialized-reports/materialized-cash-reconciliation.test.js +267 -0
  273. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.d.ts +1 -0
  274. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +147 -0
  275. package/lib/tests/materialized-reports/materialized-delivery-compile.test.d.ts +1 -0
  276. package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +242 -0
  277. package/lib/tests/materialized-reports/materialized-delivery-fold.test.d.ts +1 -0
  278. package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +109 -0
  279. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.d.ts +1 -0
  280. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +142 -0
  281. package/lib/tests/materialized-reports/materialized-delivery-plan.test.d.ts +1 -0
  282. package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +198 -0
  283. package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.d.ts +1 -0
  284. package/lib/tests/materialized-reports/materialized-discount-aggregated-formatter.test.js +173 -0
  285. package/lib/tests/materialized-reports/materialized-discount-classification.test.d.ts +1 -0
  286. package/lib/tests/materialized-reports/materialized-discount-classification.test.js +339 -0
  287. package/lib/tests/materialized-reports/materialized-discount-close-day.test.d.ts +1 -0
  288. package/lib/tests/materialized-reports/materialized-discount-close-day.test.js +506 -0
  289. package/lib/tests/materialized-reports/materialized-discount-compile.test.d.ts +1 -0
  290. package/lib/tests/materialized-reports/materialized-discount-compile.test.js +161 -0
  291. package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.d.ts +1 -0
  292. package/lib/tests/materialized-reports/materialized-discount-counter-rows.test.js +107 -0
  293. package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.d.ts +1 -0
  294. package/lib/tests/materialized-reports/materialized-discount-entries-accumulation.test.js +125 -0
  295. package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.d.ts +1 -0
  296. package/lib/tests/materialized-reports/materialized-hourly-comparison-compile.test.js +146 -0
  297. package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.d.ts +1 -0
  298. package/lib/tests/materialized-reports/materialized-hourly-comparison-formatter.test.js +127 -0
  299. package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.d.ts +1 -0
  300. package/lib/tests/materialized-reports/materialized-hourly-comparison-plan.test.js +138 -0
  301. package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.d.ts +1 -0
  302. package/lib/tests/materialized-reports/materialized-hourly-comparison-selection.test.js +90 -0
  303. package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.d.ts +1 -0
  304. package/lib/tests/materialized-reports/materialized-payments-comparison-compile.test.js +164 -0
  305. package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.d.ts +1 -0
  306. package/lib/tests/materialized-reports/materialized-payments-comparison-formatter.test.js +117 -0
  307. package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.d.ts +1 -0
  308. package/lib/tests/materialized-reports/materialized-payments-comparison-plan.test.js +149 -0
  309. package/lib/tests/materialized-reports/materialized-prep-time-classification.test.d.ts +1 -0
  310. package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +273 -0
  311. package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.d.ts +1 -0
  312. package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +271 -0
  313. package/lib/tests/materialized-reports/materialized-prep-time-compile.test.d.ts +1 -0
  314. package/lib/tests/materialized-reports/materialized-prep-time-compile.test.js +217 -0
  315. package/lib/tests/materialized-reports/materialized-prep-time-constants.test.d.ts +1 -0
  316. package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +84 -0
  317. package/lib/tests/materialized-reports/materialized-prep-time-plan.test.d.ts +1 -0
  318. package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +176 -0
  319. package/lib/tests/materialized-reports/materialized-reports-scope-group-helpers.test.js +13 -13
  320. package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.d.ts +1 -0
  321. package/lib/tests/materialized-reports/materialized-sales-comparison-baseline.test.js +126 -0
  322. package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.d.ts +1 -0
  323. package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.js +207 -0
  324. package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.d.ts +1 -0
  325. package/lib/tests/materialized-reports/materialized-sales-comparison-formatter.test.js +179 -0
  326. package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.d.ts +1 -0
  327. package/lib/tests/materialized-reports/materialized-sales-comparison-parity.test.js +196 -0
  328. package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.d.ts +1 -0
  329. package/lib/tests/materialized-reports/materialized-sales-comparison-plan.test.js +241 -0
  330. package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.d.ts +1 -0
  331. package/lib/tests/materialized-reports/materialized-tenant-hourly-comparison-schema.test.js +96 -0
  332. package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.d.ts +1 -0
  333. package/lib/tests/materialized-reports/materialized-tenant-payments-comparison-schema.test.js +112 -0
  334. package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.d.ts +1 -0
  335. package/lib/tests/materialized-reports/materialized-tenant-sales-comparison-schema.test.js +142 -0
  336. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +8 -1
  337. package/lib/tests/materialized-reports/sales-comparison-reference.d.ts +55 -0
  338. package/lib/tests/materialized-reports/sales-comparison-reference.js +86 -0
  339. package/lib/tests/materialized-reports/tenant-discount-formatter.test.d.ts +1 -0
  340. package/lib/tests/materialized-reports/tenant-discount-formatter.test.js +289 -0
  341. package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.d.ts +1 -0
  342. package/lib/tests/materialized-reports/tenant-prep-time-formatter.test.js +354 -0
  343. package/lib/tests/reporting-contract.test.d.ts +1 -0
  344. package/lib/tests/reporting-contract.test.js +267 -0
  345. package/lib/tests/rider-daily-report.test.d.ts +1 -0
  346. package/lib/tests/rider-daily-report.test.js +86 -0
  347. package/lib/tests/rider-earnings.test.d.ts +1 -0
  348. package/lib/tests/rider-earnings.test.js +65 -0
  349. package/lib/tests/rider-report.test.d.ts +1 -0
  350. package/lib/tests/rider-report.test.js +98 -0
  351. package/package.json +10 -1
@@ -0,0 +1,208 @@
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.mergeMaterializedPrepTimeCounters = mergeMaterializedPrepTimeCounters;
7
+ exports.compileTenantPrepTimeReports = compileTenantPrepTimeReports;
8
+ const mongoose_1 = __importDefault(require("mongoose"));
9
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
10
+ const materialized_prep_time_classification_helpers_1 = require("./materialized-prep-time-classification-helpers");
11
+ const scope_helpers_1 = require("./scope-helpers");
12
+ /**
13
+ * Adds `source` into `target`.
14
+ *
15
+ * NOT the generic recursive numeric add the discount compile uses: `duration.min`
16
+ * and `duration.max` (and `late_items.worst_delta`) are AGGREGATES, not counters.
17
+ * Summing them would turn a 5-minute minimum into a 50-minute one across ten
18
+ * days. Everything additive is summed; the extremes fold with min()/max().
19
+ */
20
+ function mergeMaterializedPrepTimeCounters(target, source) {
21
+ // ---- coverage (all additive) ----
22
+ target.coverage.item_count += source.coverage.item_count;
23
+ target.coverage.ready_item_count += source.coverage.ready_item_count;
24
+ target.coverage.tracked_count += source.coverage.tracked_count;
25
+ target.coverage.own_anchor_count += source.coverage.own_anchor_count;
26
+ target.coverage.fallback_anchor_count += source.coverage.fallback_anchor_count;
27
+ target.coverage.order_count += source.coverage.order_count;
28
+ // ---- duration ----
29
+ target.duration.count += source.duration.count;
30
+ target.duration.sum += source.duration.sum;
31
+ target.duration.instant_count += source.duration.instant_count;
32
+ for (const [label, count] of Object.entries(source.duration.buckets)) {
33
+ target.duration.buckets[label] = (target.duration.buckets[label] ?? 0) + count;
34
+ }
35
+ // Extremes fold, never sum. A zero minimum means "no measured row yet", so it
36
+ // is replaced rather than kept.
37
+ if (source.duration.count > 0) {
38
+ target.duration.min =
39
+ target.duration.count - source.duration.count <= 0
40
+ ? source.duration.min
41
+ : Math.min(target.duration.min, source.duration.min);
42
+ target.duration.max = Math.max(target.duration.max, source.duration.max);
43
+ }
44
+ // ---- promise (all additive; delta_sum is SIGNED) ----
45
+ target.promise.promise_set_count += source.promise.promise_set_count;
46
+ target.promise.default_baseline_count += source.promise.default_baseline_count;
47
+ target.promise.on_time_count += source.promise.on_time_count;
48
+ target.promise.late_count += source.promise.late_count;
49
+ target.promise.delta_sum += source.promise.delta_sum;
50
+ target.promise.no_target_count += source.promise.no_target_count;
51
+ // ---- late items ----
52
+ target.late_items.count += source.late_items.count;
53
+ target.late_items.worst_delta = Math.max(target.late_items.worst_delta, source.late_items.worst_delta);
54
+ }
55
+ const foldWatermark = (bucket, value) => {
56
+ if (value == null)
57
+ return;
58
+ const time = new Date(value).getTime();
59
+ if (Number.isNaN(time))
60
+ return;
61
+ if (bucket.watermark == null || time > bucket.watermark.getTime()) {
62
+ bucket.watermark = new Date(time);
63
+ }
64
+ };
65
+ const scopeKey = (doc) => doc.scope_context + '|' + doc.scope_field;
66
+ /** Hour label of one order (`YYYY-MM-DD HH`) from its local fields, or null. */
67
+ const resolveLocalHourLabel = (order, localDate) => {
68
+ const hour = order?.localHour;
69
+ if (typeof hour !== 'number' || !Number.isFinite(hour) || hour < 0 || hour > 23) {
70
+ return null;
71
+ }
72
+ return localDate + ' ' + String(hour).padStart(2, '0');
73
+ };
74
+ /**
75
+ * Compiles one tenant-day into the prep time report + entries documents.
76
+ * Returns `null` on malformed input (bad date / tenant / brand); returns EMPTY
77
+ * arrays when the day has nothing tracked at all.
78
+ */
79
+ function compileTenantPrepTimeReports(input) {
80
+ if (input == null)
81
+ return null;
82
+ const { tenantId, brandId, localDate, orders, computedAt } = input;
83
+ if (typeof tenantId !== 'string' || tenantId.length === 0)
84
+ return null;
85
+ if (typeof brandId !== 'string' || brandId.length === 0)
86
+ return null;
87
+ if (typeof localDate !== 'string' || localDate.length === 0)
88
+ return null;
89
+ if (!Array.isArray(orders))
90
+ return null;
91
+ const periodFields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
92
+ if (periodFields == null)
93
+ return null;
94
+ const dayIndex = (0, scope_helpers_1.getDayIndexFromLocalDate)(localDate);
95
+ const at = computedAt ?? new Date();
96
+ const byScope = new Map();
97
+ const scopeContextOf = new Map();
98
+ const bucketFor = (scope, scopeField, key) => {
99
+ const identity = scope + '|' + scopeField;
100
+ let byKey = byScope.get(identity);
101
+ if (byKey == null) {
102
+ byKey = new Map();
103
+ byScope.set(identity, byKey);
104
+ scopeContextOf.set(identity, scope);
105
+ }
106
+ let bucket = byKey.get(key);
107
+ if (bucket == null) {
108
+ bucket = { counters: (0, materialized_prep_time_classification_helpers_1.freshMaterializedPrepTimeCounters)(), rows: [], watermark: null };
109
+ byKey.set(key, bucket);
110
+ }
111
+ return bucket;
112
+ };
113
+ let contributingOrders = 0;
114
+ for (const order of orders) {
115
+ if (order == null)
116
+ continue;
117
+ // Only orders of this tenant compile into this tenant's documents.
118
+ if (order.tenant_id != null && String(order.tenant_id) !== tenantId)
119
+ continue;
120
+ const context = {
121
+ local_date: localDate,
122
+ local_hour_label: resolveLocalHourLabel(order, localDate),
123
+ };
124
+ const result = (0, materialized_prep_time_classification_helpers_1.accumulateOrderPrepTime)({
125
+ order,
126
+ context,
127
+ tenantDefaultMinutes: input.tenantDefaultMinutes ?? null,
128
+ });
129
+ // COVERAGE IS THE HEADLINE, so an order that served items but was never
130
+ // observed MUST still contribute its denominator. Skipping it would let the
131
+ // report claim "100% observed" by ignoring everything it failed to observe -
132
+ // exactly the reading this report exists to prevent (one measured store is
133
+ // 2.9% covered).
134
+ if (result.counters.coverage.item_count === 0)
135
+ continue;
136
+ // `contributingOrders` is the narrower documented numerator: orders with at
137
+ // least one TRACKED item.
138
+ if (result.has_tracked)
139
+ contributingOrders += 1;
140
+ const key = String(order.order_status ?? '') + ':' + String(order.platform ?? order.order_from ?? '');
141
+ const watermark = order.updatedAt != null ? new Date(order.updatedAt) : null;
142
+ for (const scope of MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_REPORT_SCOPES) {
143
+ const scopeField = periodFields[scope];
144
+ if (scopeField == null)
145
+ continue;
146
+ const bucket = bucketFor(scope, scopeField, key);
147
+ mergeMaterializedPrepTimeCounters(bucket.counters, result.counters);
148
+ bucket.rows.push(...result.entries);
149
+ foldWatermark(bucket, watermark);
150
+ }
151
+ }
152
+ const sourceWatermark = new Date(at);
153
+ const reports = [];
154
+ const entries = [];
155
+ for (const [identity, byKey] of byScope) {
156
+ const [scopeContext, scopeField] = identity.split('|');
157
+ const counters = {};
158
+ const counterRows = [];
159
+ const entrySections = {};
160
+ let watermark = null;
161
+ for (const [key, bucket] of byKey) {
162
+ counters[key] = bucket.counters;
163
+ counterRows.push({ key, counters: bucket.counters });
164
+ if (bucket.rows.length > 0)
165
+ entrySections[key] = { rows: bucket.rows };
166
+ if (bucket.watermark != null && (watermark == null || bucket.watermark.getTime() > watermark.getTime())) {
167
+ watermark = bucket.watermark;
168
+ }
169
+ }
170
+ const docWatermark = watermark ?? sourceWatermark;
171
+ const isDateScoped = scopeContext === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
172
+ reports.push({
173
+ _id: new mongoose_1.default.Types.ObjectId().toHexString(),
174
+ tenant_id: tenantId,
175
+ brand_id: brandId,
176
+ scope_context: scopeContext,
177
+ scope_field: scopeField,
178
+ day_index: isDateScoped ? dayIndex : null,
179
+ sale_type_key_filters: [...MATERIALIZED_REPORTS_1.PREP_TIME_KEY_FILTERS],
180
+ prep_time_counters: Object.keys(counters).length === 0 ? null : counters,
181
+ // The read-path shape, written from the SAME pass so the two cannot disagree.
182
+ prep_time_counter_rows: counterRows.length === 0 ? null : counterRows,
183
+ schema_version: 1,
184
+ source_watermark: docWatermark,
185
+ computed_at: at,
186
+ createdAt: at,
187
+ updatedAt: at,
188
+ });
189
+ if (Object.keys(entrySections).length > 0) {
190
+ entries.push({
191
+ _id: new mongoose_1.default.Types.ObjectId().toHexString(),
192
+ tenant_id: tenantId,
193
+ brand_id: brandId,
194
+ scope_context: scopeContext,
195
+ scope_field: scopeField,
196
+ day_index: isDateScoped ? dayIndex : null,
197
+ sale_type_key_filters: [...MATERIALIZED_REPORTS_1.PREP_TIME_KEY_FILTERS],
198
+ prep_time_entries: entrySections,
199
+ schema_version: 1,
200
+ source_watermark: docWatermark,
201
+ computed_at: at,
202
+ createdAt: at,
203
+ updatedAt: at,
204
+ });
205
+ }
206
+ }
207
+ return { reports, entries, contributingOrders };
208
+ }
@@ -23,10 +23,13 @@ import { IGetMaterializedReportScopeGroup } from '../types/materialized-reports-
23
23
  * Returns `null` (never throws) for malformed input — `null` means the
24
24
  * caller passed invalid data.
25
25
  */
26
- /** Window refinement kinds (see the module docblock). */
26
+ /**
27
+ * Window refinement kinds (see the module docblock).
28
+ * @deprecated use MATERIALIZED_REPORT_WINDOW_KIND_ENUM from constants.
29
+ */
27
30
  export declare const MATERIALIZED_REPORT_WINDOW_KIND: {
28
- readonly RECURRING: "RECURRING";
29
- readonly SPAN: "SPAN";
31
+ readonly RECURRING: 'RECURRING';
32
+ readonly SPAN: 'SPAN';
30
33
  };
31
34
  export type TMaterializedReportWindowKind = (typeof MATERIALIZED_REPORT_WINDOW_KIND)[keyof typeof MATERIALIZED_REPORT_WINDOW_KIND];
32
35
  export interface IMaterializedReportScopeSelectionSpec {
@@ -29,10 +29,13 @@ const materialized_reports_read_helpers_1 = require("./materialized-reports-read
29
29
  * Returns `null` (never throws) for malformed input — `null` means the
30
30
  * caller passed invalid data.
31
31
  */
32
- /** Window refinement kinds (see the module docblock). */
32
+ /**
33
+ * Window refinement kinds (see the module docblock).
34
+ * @deprecated use MATERIALIZED_REPORT_WINDOW_KIND_ENUM from constants.
35
+ */
33
36
  exports.MATERIALIZED_REPORT_WINDOW_KIND = {
34
- RECURRING: 'RECURRING',
35
- SPAN: 'SPAN',
37
+ RECURRING: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
38
+ SPAN: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN,
36
39
  };
37
40
  /* ------------------------------------------------------------------------ */
38
41
  /* Date-key math (UTC — keys are timezone-less) */
@@ -207,7 +210,7 @@ function buildMaterializedReportScopeGroups(spec) {
207
210
  const uniqueDates = dayKeys.map((key) => keyToDate(key));
208
211
  // A SPAN window reads the CONTINUOUS interval first-day → last-day — a day
209
212
  // set with gaps would silently pull the gap days in as full middle days.
210
- if (window != null && window.kind === exports.MATERIALIZED_REPORT_WINDOW_KIND.SPAN) {
213
+ if (window != null && window.kind === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN) {
211
214
  for (let index = 1; index < uniqueDates.length; index += 1) {
212
215
  if (daysBetween(uniqueDates[index - 1], uniqueDates[index]) !== 1) {
213
216
  return null;
@@ -222,7 +225,7 @@ function buildMaterializedReportScopeGroups(spec) {
222
225
  if (!isValidHour(fromHour, 23) || !isValidHour(toHour, 23))
223
226
  return null;
224
227
  // Recurring: the same hours on every selected day.
225
- if (kind === exports.MATERIALIZED_REPORT_WINDOW_KIND.RECURRING) {
228
+ if (kind === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING) {
226
229
  const labels = (0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(dayKeys, fromHour, toHour);
227
230
  return labels == null ? null : [{ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, scope_field: labels }];
228
231
  }
@@ -1,5 +1,13 @@
1
+ import { CALENDAR_VIEW_MODE_ENUM } from '../../constants/REPORT_CALENDAR';
1
2
  import { IGetMaterializedReportScopeGroup } from '../types/materialized-reports-apis';
2
3
  import { IReportCalendarSelection } from '../types/report-calendar';
4
+ /**
5
+ * The SPAN-window views, exported for consumers that must mirror a selection's
6
+ * window semantics (the Sales Comparison baseline derivation): a range-like
7
+ * selection's toggle window is a CONTINUOUS span, while a discrete / weekday
8
+ * selection repeats the same hours on each day.
9
+ */
10
+ export declare const MATERIALIZED_REPORT_SPAN_VIEW_MODES: ReadonlySet<CALENDAR_VIEW_MODE_ENUM>;
3
11
  /**
4
12
  * Upper bound on the raw day span one selection may cover (~10 years).
5
13
  * Bounds every date-walk expansion in the decoder; read services surface an
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildMaterializedReportScopeGroupsFromSelection = exports.validateMaterializedReportSelectionInput = exports.isValidBusinessHourWindow = exports.getDayKeysFromCalendarSelection = exports.MATERIALIZED_REPORT_MAX_SELECTION_DAY_SPAN = void 0;
3
+ exports.buildMaterializedReportScopeGroupsFromSelection = exports.validateMaterializedReportSelectionInput = exports.isValidBusinessHourWindow = exports.getDayKeysFromCalendarSelection = exports.MATERIALIZED_REPORT_MAX_SELECTION_DAY_SPAN = exports.MATERIALIZED_REPORT_SPAN_VIEW_MODES = void 0;
4
4
  const ENUMS_1 = require("../../constants/ENUMS");
5
5
  const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
6
6
  const REPORT_CALENDAR_1 = require("../../constants/REPORT_CALENDAR");
@@ -62,6 +62,13 @@ const RANGE_LIKE_VIEWS = new Set([
62
62
  REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.QUARTER,
63
63
  REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.SEMESTER,
64
64
  ]);
65
+ /**
66
+ * The SPAN-window views, exported for consumers that must mirror a selection's
67
+ * window semantics (the Sales Comparison baseline derivation): a range-like
68
+ * selection's toggle window is a CONTINUOUS span, while a discrete / weekday
69
+ * selection repeats the same hours on each day.
70
+ */
71
+ exports.MATERIALIZED_REPORT_SPAN_VIEW_MODES = SPAN_VIEWS;
65
72
  /**
66
73
  * Upper bound on the raw day span one selection may cover (~10 years).
67
74
  * Bounds every date-walk expansion in the decoder; read services surface an
@@ -660,8 +667,8 @@ const decodeMaterializedReportScopeGroups = (selection) => {
660
667
  // never compile it. Weekday + window therefore always compiles
661
668
  // RECURRING (the same hours on each matching weekday).
662
669
  kind: SPAN_VIEWS.has(view) && weekdayFilter == null
663
- ? materialized_reports_scope_group_helpers_1.MATERIALIZED_REPORT_WINDOW_KIND.SPAN
664
- : materialized_reports_scope_group_helpers_1.MATERIALIZED_REPORT_WINDOW_KIND.RECURRING,
670
+ ? MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN
671
+ : MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
665
672
  },
666
673
  }
667
674
  : {}),
@@ -0,0 +1,48 @@
1
+ import { IOrder } from '../../schemas/types/orders';
2
+ import { IMaterializedSalesComparisonCounters } from '../../schemas/types/materialized_tenant_sales_comparison_reports';
3
+ /** A zeroed counter block. */
4
+ export declare function createEmptySalesComparisonCounters(): IMaterializedSalesComparisonCounters;
5
+ /** Gross sales in CENTS — BEFORE discounts. */
6
+ export declare function getOrderGrossAmountCents(order: IOrder): number;
7
+ /** Discounts applied to the order, in CENTS. */
8
+ export declare function getOrderDiscountAmountCents(order: IOrder): number;
9
+ /** Total tax collected, in CENTS (GST + the unused `tax_amount` bucket). */
10
+ export declare function getOrderTaxAmountCents(order: IOrder): number;
11
+ /** Service-shaped charges (service fee + surcharge), in CENTS. */
12
+ export declare function getOrderServiceChargeAmountCents(order: IOrder): number;
13
+ /** Refunded money across the order's payments, in CENTS. */
14
+ export declare function getOrderRefundAmountCents(order: IOrder): number;
15
+ /** Voided (cancelled) order value, in CENTS. */
16
+ export declare function getOrderVoidAmountCents(order: IOrder): number;
17
+ /** Items sold (Σ quantity), NOT line count. */
18
+ export declare function getOrderItemCount(order: IOrder): number;
19
+ /** Dine-in guest count (0 elsewhere). */
20
+ export declare function getOrderGuestCount(order: IOrder): number;
21
+ /**
22
+ * The tenant-local calendar date of an order's SETTLEMENT instant.
23
+ *
24
+ * The anchor is `order_settled_at` — NEVER `order.localDate`, which is the
25
+ * PUNCH day. A deferred bill punched Monday and collected Wednesday belongs to
26
+ * Wednesday's comparison row (concept §3: no time bias, one fixed anchor).
27
+ *
28
+ * `gmtOffset` is the tenant GST offset in hours (`+5`). The local calendar date
29
+ * of an instant is the UTC date after shifting by that offset.
30
+ *
31
+ * Returns `null` for an order that was never settled (no `order_settled_at` or
32
+ * an unparseable one) — such an order has no settled day and is NOT counted.
33
+ */
34
+ export declare function getSalesComparisonSettledLocalDate(order: Pick<IOrder, 'order_settled_at'> | null | undefined, gmtOffset?: number): string | null;
35
+ /**
36
+ * Adds one order's counters into `target` (mutates `target`).
37
+ *
38
+ * The order's `net_amount` is derived from ITS OWN gross/discount pair so the
39
+ * three counters always satisfy `net = gross − discount` leaf by leaf.
40
+ */
41
+ export declare function addOrderToSalesComparisonCounters(target: IMaterializedSalesComparisonCounters, order: IOrder): void;
42
+ /** Adds every counter of `source` into `target` (mutates `target`). */
43
+ export declare function addSalesComparisonCounters(target: IMaterializedSalesComparisonCounters, source: IMaterializedSalesComparisonCounters | null | undefined): void;
44
+ /**
45
+ * Stable list of every additive counter, in display order. Kept in sync with
46
+ * the type module by the schema contract test.
47
+ */
48
+ export declare const ALL_SALES_COMPARISON_COUNTER_FIELDS: 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,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_SALES_COMPARISON_COUNTER_FIELDS = void 0;
4
+ exports.createEmptySalesComparisonCounters = createEmptySalesComparisonCounters;
5
+ exports.getOrderGrossAmountCents = getOrderGrossAmountCents;
6
+ exports.getOrderDiscountAmountCents = getOrderDiscountAmountCents;
7
+ exports.getOrderTaxAmountCents = getOrderTaxAmountCents;
8
+ exports.getOrderServiceChargeAmountCents = getOrderServiceChargeAmountCents;
9
+ exports.getOrderRefundAmountCents = getOrderRefundAmountCents;
10
+ exports.getOrderVoidAmountCents = getOrderVoidAmountCents;
11
+ exports.getOrderItemCount = getOrderItemCount;
12
+ exports.getOrderGuestCount = getOrderGuestCount;
13
+ exports.getSalesComparisonSettledLocalDate = getSalesComparisonSettledLocalDate;
14
+ exports.addOrderToSalesComparisonCounters = addOrderToSalesComparisonCounters;
15
+ exports.addSalesComparisonCounters = addSalesComparisonCounters;
16
+ const ENUMS_1 = require("../../constants/ENUMS");
17
+ /**
18
+ * Sales Comparison counter accumulation (see
19
+ * `console/admin-panel/docs/report-sales-comparison-concept.md` §6).
20
+ *
21
+ * ## Money mapping — deliberately grounded in the fields live orders carry
22
+ *
23
+ * The live order document has no single "net sales" field, and its fields do
24
+ * not nest the way their names suggest:
25
+ *
26
+ * | counter | source (all CENTS) | why |
27
+ * | --- | --- | --- |
28
+ * | `gross_amount` | `order.price` (fallback Σ item `_gross_amount`, then `subtotal`) | `price` is documented as the total item price WITHOUT discounts |
29
+ * | `discount_amount` | `order.total_discount_applied` → `order_discount_details.total_discount` | the same pair the overview materializer uses; `0` is a real value, so it must not fall through |
30
+ * | `net_amount` | `gross_amount − discount_amount` | standard net sales; equals Σ item `_net_amount` on live data |
31
+ * | `tax_amount` | `order.gst_amount + order.tax_amount` | live stores carry the collected tax in `gst_amount`; `tax_amount` is 0 there. The report has ONE tax counter, so both sum into it |
32
+ * | `service_charge_amount` | `order.service_fee_amount + order.surcharge_amount` | the report has ONE service-charge counter; surcharge is the other service-shaped charge. Both are absent on today's data (0), not guessed |
33
+ * | `tip_amount` | `order.tip_amount` | |
34
+ * | `refund_amount` | Σ `payments[].amount_refunded` | order-level refund money is only represented by its payment rows |
35
+ * | `void_amount` | `order.amount_earned` for a `CANCELLED` order, else 0 | voided order value. Item-level voids live in the SEPARATE `void_order_items` ledger, which a settled-sales report must not fold in without its own drill-down; the `CANCELLED` key is the order-derived void signal |
36
+ * | `item_count` | Σ `categories[].items[].quantity` | items sold, not line count |
37
+ * | `guest_count` | `dinein_details.num_of_guests` | 0 for non-dine-in |
38
+ *
39
+ * **Order count** counts every settled order, including `CANCELLED` — cancelled
40
+ * orders are keyed `CANCELLED:*` and are split out by the formatter, exactly
41
+ * like the overview.
42
+ *
43
+ * Every value is added AS-IS: the source amounts may carry fractional cents and
44
+ * the report must be decimal-exact, so no rounding happens here.
45
+ */
46
+ /** Coerces a source amount to a finite number (0 when absent/broken). */
47
+ const cents = (value) => {
48
+ const number = typeof value === 'number' ? value : Number(value);
49
+ return Number.isFinite(number) ? number : 0;
50
+ };
51
+ const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
52
+ /** A zeroed counter block. */
53
+ function createEmptySalesComparisonCounters() {
54
+ return {
55
+ order_count: 0,
56
+ gross_amount: 0,
57
+ discount_amount: 0,
58
+ net_amount: 0,
59
+ tax_amount: 0,
60
+ service_charge_amount: 0,
61
+ tip_amount: 0,
62
+ refund_amount: 0,
63
+ void_amount: 0,
64
+ item_count: 0,
65
+ guest_count: 0,
66
+ };
67
+ }
68
+ /** Σ item `_gross_amount` (fallback `subtotal`) — only read when `order.price` is absent. */
69
+ const itemsGrossAmount = (order) => {
70
+ let total = 0;
71
+ for (const category of order?.categories ?? []) {
72
+ for (const item of category?.items ?? []) {
73
+ total += isFiniteNumber(item?._gross_amount) ? item._gross_amount : cents(item?.subtotal);
74
+ }
75
+ }
76
+ return total;
77
+ };
78
+ /** Gross sales in CENTS — BEFORE discounts. */
79
+ function getOrderGrossAmountCents(order) {
80
+ if (order == null)
81
+ return 0;
82
+ if (isFiniteNumber(order.price))
83
+ return order.price;
84
+ return itemsGrossAmount(order);
85
+ }
86
+ /** Discounts applied to the order, in CENTS. */
87
+ function getOrderDiscountAmountCents(order) {
88
+ if (order == null)
89
+ return 0;
90
+ if (isFiniteNumber(order.total_discount_applied))
91
+ return order.total_discount_applied;
92
+ return cents(order.order_discount_details?.total_discount);
93
+ }
94
+ /** Total tax collected, in CENTS (GST + the unused `tax_amount` bucket). */
95
+ function getOrderTaxAmountCents(order) {
96
+ if (order == null)
97
+ return 0;
98
+ return cents(order.gst_amount) + cents(order.tax_amount);
99
+ }
100
+ /** Service-shaped charges (service fee + surcharge), in CENTS. */
101
+ function getOrderServiceChargeAmountCents(order) {
102
+ if (order == null)
103
+ return 0;
104
+ return cents(order.service_fee_amount) + cents(order.surcharge_amount);
105
+ }
106
+ /** Refunded money across the order's payments, in CENTS. */
107
+ function getOrderRefundAmountCents(order) {
108
+ let total = 0;
109
+ for (const payment of order?.payments ?? []) {
110
+ total += cents(payment?.amount_refunded);
111
+ }
112
+ return total;
113
+ }
114
+ /** Voided (cancelled) order value, in CENTS. */
115
+ function getOrderVoidAmountCents(order) {
116
+ if (order == null)
117
+ return 0;
118
+ return order.order_status === ENUMS_1.ORDER_STATUS_ENUM.CANCELLED ? cents(order.amount_earned) : 0;
119
+ }
120
+ /** Items sold (Σ quantity), NOT line count. */
121
+ function getOrderItemCount(order) {
122
+ let total = 0;
123
+ for (const category of order?.categories ?? []) {
124
+ for (const item of category?.items ?? []) {
125
+ total += cents(item?.quantity);
126
+ }
127
+ }
128
+ return total;
129
+ }
130
+ /** Dine-in guest count (0 elsewhere). */
131
+ function getOrderGuestCount(order) {
132
+ return cents(order?.dinein_details?.num_of_guests);
133
+ }
134
+ /**
135
+ * The tenant-local calendar date of an order's SETTLEMENT instant.
136
+ *
137
+ * The anchor is `order_settled_at` — NEVER `order.localDate`, which is the
138
+ * PUNCH day. A deferred bill punched Monday and collected Wednesday belongs to
139
+ * Wednesday's comparison row (concept §3: no time bias, one fixed anchor).
140
+ *
141
+ * `gmtOffset` is the tenant GST offset in hours (`+5`). The local calendar date
142
+ * of an instant is the UTC date after shifting by that offset.
143
+ *
144
+ * Returns `null` for an order that was never settled (no `order_settled_at` or
145
+ * an unparseable one) — such an order has no settled day and is NOT counted.
146
+ */
147
+ function getSalesComparisonSettledLocalDate(order, gmtOffset = 0) {
148
+ const raw = order?.order_settled_at;
149
+ if (raw == null)
150
+ return null;
151
+ const time = new Date(raw).getTime();
152
+ if (Number.isNaN(time))
153
+ return null;
154
+ const offset = Number.isFinite(gmtOffset) ? gmtOffset : 0;
155
+ return new Date(time + offset * 60 * 60 * 1000).toISOString().slice(0, 10);
156
+ }
157
+ /**
158
+ * Adds one order's counters into `target` (mutates `target`).
159
+ *
160
+ * The order's `net_amount` is derived from ITS OWN gross/discount pair so the
161
+ * three counters always satisfy `net = gross − discount` leaf by leaf.
162
+ */
163
+ function addOrderToSalesComparisonCounters(target, order) {
164
+ if (target == null || order == null)
165
+ return;
166
+ const gross = getOrderGrossAmountCents(order);
167
+ const discount = getOrderDiscountAmountCents(order);
168
+ target.order_count += 1;
169
+ target.gross_amount += gross;
170
+ target.discount_amount += discount;
171
+ target.net_amount += gross - discount;
172
+ target.tax_amount += getOrderTaxAmountCents(order);
173
+ target.service_charge_amount += getOrderServiceChargeAmountCents(order);
174
+ target.tip_amount += cents(order.tip_amount);
175
+ target.refund_amount += getOrderRefundAmountCents(order);
176
+ target.void_amount += getOrderVoidAmountCents(order);
177
+ target.item_count += getOrderItemCount(order);
178
+ target.guest_count += getOrderGuestCount(order);
179
+ }
180
+ /** Adds every counter of `source` into `target` (mutates `target`). */
181
+ function addSalesComparisonCounters(target, source) {
182
+ if (target == null || source == null)
183
+ return;
184
+ for (const field of exports.ALL_SALES_COMPARISON_COUNTER_FIELDS) {
185
+ target[field] += cents(source[field]);
186
+ }
187
+ }
188
+ /**
189
+ * Stable list of every additive counter, in display order. Kept in sync with
190
+ * the type module by the schema contract test.
191
+ */
192
+ exports.ALL_SALES_COMPARISON_COUNTER_FIELDS = [
193
+ 'order_count',
194
+ 'gross_amount',
195
+ 'discount_amount',
196
+ 'net_amount',
197
+ 'tax_amount',
198
+ 'service_charge_amount',
199
+ 'tip_amount',
200
+ 'refund_amount',
201
+ 'void_amount',
202
+ 'item_count',
203
+ 'guest_count',
204
+ ];
@@ -0,0 +1,22 @@
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 derived comparison window, as day keys. */
5
+ export interface ISalesComparisonBaselineRange {
6
+ start: string;
7
+ end: string;
8
+ /** Days inside the window AFTER the weekday refinement. */
9
+ days: string[];
10
+ }
11
+ /**
12
+ * Derives the comparison window from a decoded selection.
13
+ *
14
+ * Returns `null` for `NONE` / an unservable selection; an entry with an empty
15
+ * `days` array means the window is valid but no day matches the refinement.
16
+ */
17
+ export declare function getSalesComparisonBaselineRange(selection: IReportCalendarSelection, baseline: SALES_COMPARISON_BASELINE_ENUM | string | null | undefined): ISalesComparisonBaselineRange | null;
18
+ /**
19
+ * Builds the comparison read's scope groups. Empty array = a valid baseline
20
+ * whose window contains no matching day (the read then folds to zero).
21
+ */
22
+ export declare function buildSalesComparisonBaselineScopeGroups(selection: IReportCalendarSelection, baseline: SALES_COMPARISON_BASELINE_ENUM | string | null | undefined): IGetMaterializedReportScopeGroup[] | null;