@managesome/eposmatic-toolkit 0.3.8 → 0.3.9

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 (436) hide show
  1. package/esm/constants/ANALYTICS.js +146 -0
  2. package/esm/constants/API_ERRORS.js +6 -0
  3. package/esm/constants/COMMON.js +369 -0
  4. package/esm/constants/DELIVERY.js +45 -0
  5. package/esm/constants/DIALER_ENUMS.js +11 -0
  6. package/esm/constants/ENUMS.js +1988 -0
  7. package/esm/constants/FBR_ENUMS.js +18 -0
  8. package/esm/constants/HUBRISE_ENUMS.js +179 -0
  9. package/esm/constants/INTERNAL_ENUMS.js +49 -0
  10. package/esm/constants/NOTIFICATIONS.js +6 -0
  11. package/esm/constants/ORDER.js +251 -0
  12. package/esm/constants/PRA_ENUMS.js +18 -0
  13. package/esm/constants/REPORT_WEBVIEW.js +28 -0
  14. package/esm/constants/RFQ_GO.js +83 -0
  15. package/esm/constants/SMARTPAY_ENUMS.js +55 -0
  16. package/esm/constants/SOCKET.js +149 -0
  17. package/esm/constants/SRB_ENUMS.js +13 -0
  18. package/esm/constants/SWITCHPAY.js +28 -0
  19. package/esm/constants/TENANT_ENUMS.js +90 -0
  20. package/esm/constants/TENANT_PURCHASE_ORDER.js +91 -0
  21. package/esm/constants/WALLET.js +51 -0
  22. package/esm/constants/WAREHOUSE_ANALYTICS.js +28 -0
  23. package/esm/constants/WAREHOUSE_ENUMS.js +420 -0
  24. package/esm/constants/WAREHOUSE_PURCHASE_ORDER.js +97 -0
  25. package/esm/constants/WEBVIEW.js +43 -0
  26. package/esm/constants/WORKER_ENDPOINTS.js +79 -0
  27. package/esm/constants/index.js +27 -0
  28. package/esm/constants/types.js +2 -0
  29. package/esm/helpers/fbr/generate-invoice.js +94 -0
  30. package/esm/helpers/fbr/index.js +1 -0
  31. package/esm/helpers/hubrise/hubrise-catalog.js +304 -0
  32. package/esm/helpers/hubrise/index.js +1 -0
  33. package/esm/helpers/index.js +9 -0
  34. package/esm/helpers/kpra/generate-invoice.js +26 -0
  35. package/esm/helpers/kpra/index.js +1 -0
  36. package/esm/helpers/order/generate-order.js +508 -0
  37. package/esm/helpers/order/generate-warehouse-internal-movement.js +71 -0
  38. package/esm/helpers/order/generate-warehouse-purchase-order-rfq.js +176 -0
  39. package/esm/helpers/order/generate-warehouse-purchase-order.js +187 -0
  40. package/esm/helpers/order/generate-warehouse-sale-order-rfq.js +176 -0
  41. package/esm/helpers/order/generate-warehouse-sale-order.js +149 -0
  42. package/esm/helpers/order/index.js +6 -0
  43. package/esm/helpers/pra/generate-invoice.js +94 -0
  44. package/esm/helpers/pra/index.js +1 -0
  45. package/esm/helpers/srb/generate-invoice.js +68 -0
  46. package/esm/helpers/srb/index.js +1 -0
  47. package/esm/helpers/store/all-orders-actions.js +17 -0
  48. package/esm/helpers/store/all-tenant-purchase-orders-actions.js +45 -0
  49. package/esm/helpers/store/all-warehouse-purchase-order-rfqs-actions.js +66 -0
  50. package/esm/helpers/store/all-warehouse-purchase-order-vendor-return-actions.js +50 -0
  51. package/esm/helpers/store/all-warehouse-purchase-orders-actions.js +49 -0
  52. package/esm/helpers/store/all-warehouse-sale-order-invoices-actions.js +132 -0
  53. package/esm/helpers/store/all-warehouse-sale-order-rfqs-actions.js +66 -0
  54. package/esm/helpers/store/all-warehouse-sale-orders-actions.js +72 -0
  55. package/esm/helpers/store/cart-actions.js +3563 -0
  56. package/esm/helpers/store/catalog-actions.js +379 -0
  57. package/esm/helpers/store/common-order-actions.js +937 -0
  58. package/esm/helpers/store/common-tenant-purchase-order-actions.js +440 -0
  59. package/esm/helpers/store/common-warehouse-internal-movement-actions.js +95 -0
  60. package/esm/helpers/store/common-warehouse-purchase-order-actions.js +530 -0
  61. package/esm/helpers/store/common-warehouse-purchase-order-receipt-actions.js +33 -0
  62. package/esm/helpers/store/common-warehouse-purchase-order-rfq-actions.js +523 -0
  63. package/esm/helpers/store/common-warehouse-purchase-order-vendor-return-actions.js +25 -0
  64. package/esm/helpers/store/common-warehouse-sale-order-actions.js +483 -0
  65. package/esm/helpers/store/common-warehouse-sale-order-invoice-actions.js +54 -0
  66. package/esm/helpers/store/common-warehouse-sale-order-rfq-actions.js +523 -0
  67. package/esm/helpers/store/index.js +26 -0
  68. package/esm/helpers/store/offline-ordering.js +251 -0
  69. package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +379 -0
  70. package/esm/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +360 -0
  71. package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +470 -0
  72. package/esm/helpers/store/warehouse-sale-order-rfq-cart-actions.js +359 -0
  73. package/esm/helpers/store/warehouse-sale-orders-cart-actions.js +456 -0
  74. package/esm/helpers/types/api-types.js +1 -0
  75. package/esm/helpers/types/cart-actions.js +1 -0
  76. package/esm/helpers/types/cart-helpers.js +1 -0
  77. package/esm/helpers/types/catalog.js +1 -0
  78. package/esm/helpers/types/common.js +1 -0
  79. package/esm/helpers/types/deliverect_menu.js +1 -0
  80. package/esm/helpers/types/email-templates.js +1 -0
  81. package/esm/helpers/types/fbr-generate-invoice.js +1 -0
  82. package/esm/helpers/types/halfhalf.js +1 -0
  83. package/esm/helpers/types/hubrise_catalog.js +1 -0
  84. package/esm/helpers/types/hubrise_customers.js +1 -0
  85. package/esm/helpers/types/hubrise_deliveries.js +1 -0
  86. package/esm/helpers/types/hubrise_location.js +1 -0
  87. package/esm/helpers/types/hubrise_orders.js +1 -0
  88. package/esm/helpers/types/index.js +33 -0
  89. package/esm/helpers/types/internal-leads.js +1 -0
  90. package/esm/helpers/types/inventory-catalog.js +1 -0
  91. package/esm/helpers/types/kpra-generate-invoice.js +1 -0
  92. package/esm/helpers/types/marketing.js +1 -0
  93. package/esm/helpers/types/order-engine.js +1 -0
  94. package/esm/helpers/types/pra-generate-invoice.js +1 -0
  95. package/esm/helpers/types/report-webview.js +1 -0
  96. package/esm/helpers/types/reports.js +1 -0
  97. package/esm/helpers/types/smartpay-apis.js +2 -0
  98. package/esm/helpers/types/specials.js +1 -0
  99. package/esm/helpers/types/split_bill.js +1 -0
  100. package/esm/helpers/types/srb-generate-invoice.js +1 -0
  101. package/esm/helpers/types/switchpay.js +1 -0
  102. package/esm/helpers/types/tenant-purchase-order-cart-actions.js +1 -0
  103. package/esm/helpers/types/warehouse-catalog.js +1 -0
  104. package/esm/helpers/types/warehouse-purchase-order-cart-actions.js +1 -0
  105. package/esm/helpers/types/warehouse-purchase-order-rfq-cart-actions.js +1 -0
  106. package/esm/helpers/types/warehouse-sale-order-cart-actions.js +1 -0
  107. package/esm/helpers/types/warehouse-sale-order-rfq-cart-actions.js +1 -0
  108. package/esm/helpers/types/workers.js +1 -0
  109. package/esm/helpers/utils/asaanbill-identifier-helpers.js +31 -0
  110. package/esm/helpers/utils/business-day-helpers.js +201 -0
  111. package/esm/helpers/utils/cart-helpers.js +156 -0
  112. package/esm/helpers/utils/catalog-conversion.js +129 -0
  113. package/esm/helpers/utils/code-redemption-helpers.js +452 -0
  114. package/esm/helpers/utils/color-helpers.js +31 -0
  115. package/esm/helpers/utils/common.js +368 -0
  116. package/esm/helpers/utils/crypt.js +40 -0
  117. package/esm/helpers/utils/customers-helpers.js +15 -0
  118. package/esm/helpers/utils/delivery-area-helpers.js +42 -0
  119. package/esm/helpers/utils/delivery-helpers.js +87 -0
  120. package/esm/helpers/utils/denominations-helpers.js +53 -0
  121. package/esm/helpers/utils/dinein.js +39 -0
  122. package/esm/helpers/utils/discount-helpers.js +55 -0
  123. package/esm/helpers/utils/email-helpers.js +111 -0
  124. package/esm/helpers/utils/error-helpers.js +14 -0
  125. package/esm/helpers/utils/expense.js +26 -0
  126. package/esm/helpers/utils/getFormFieldsDiff.js +15 -0
  127. package/esm/helpers/utils/gift-card-helpers.js +258 -0
  128. package/esm/helpers/utils/halfhalf-setup-helpers.js +779 -0
  129. package/esm/helpers/utils/hourly-comparison-report-helpers.js +851 -0
  130. package/esm/helpers/utils/hr-helpers.js +62 -0
  131. package/esm/helpers/utils/hubrise-utils.js +32 -0
  132. package/esm/helpers/utils/image-helpers.js +95 -0
  133. package/esm/helpers/utils/image-url-helpers.js +96 -0
  134. package/esm/helpers/utils/index.js +96 -0
  135. package/esm/helpers/utils/ingredients.js +26 -0
  136. package/esm/helpers/utils/internal-amount-helpers.js +49 -0
  137. package/esm/helpers/utils/inventory.js +123 -0
  138. package/esm/helpers/utils/inventory_entries.js +91 -0
  139. package/esm/helpers/utils/inventory_transactions.js +91 -0
  140. package/esm/helpers/utils/item-report-helpers.js +2603 -0
  141. package/esm/helpers/utils/items-comparison-report-helpers.js +1057 -0
  142. package/esm/helpers/utils/kds-helpers.js +43 -0
  143. package/esm/helpers/utils/location-helpers.js +13 -0
  144. package/esm/helpers/utils/menu-helpers.js +44 -0
  145. package/esm/helpers/utils/minified-catalog.js +428 -0
  146. package/esm/helpers/utils/offer-apply-helpers.js +613 -0
  147. package/esm/helpers/utils/offers-helpers.js +3351 -0
  148. package/esm/helpers/utils/operational-roles-helpers.js +33 -0
  149. package/esm/helpers/utils/order-engine.js +1409 -0
  150. package/esm/helpers/utils/order-history.js +208 -0
  151. package/esm/helpers/utils/payment-comparison-report-helpers.js +873 -0
  152. package/esm/helpers/utils/payment-helpers.js +302 -0
  153. package/esm/helpers/utils/pdf-generator.js +110 -0
  154. package/esm/helpers/utils/platform-catalog.js +306 -0
  155. package/esm/helpers/utils/platform-num.js +188 -0
  156. package/esm/helpers/utils/platform-specific-tenant-shifts.js +19 -0
  157. package/esm/helpers/utils/price-conversion.js +24 -0
  158. package/esm/helpers/utils/printer-helpers.js +319 -0
  159. package/esm/helpers/utils/public-holidays-helpers.js +8 -0
  160. package/esm/helpers/utils/ratings-comparison-report-helpers.js +1187 -0
  161. package/esm/helpers/utils/receipt-engine.js +1050 -0
  162. package/esm/helpers/utils/review-helpers.js +391 -0
  163. package/esm/helpers/utils/rider-tracking.js +12 -0
  164. package/esm/helpers/utils/riders-report-helpers.js +1590 -0
  165. package/esm/helpers/utils/sales-comparison-report-helpers.js +1259 -0
  166. package/esm/helpers/utils/sales-comparitive-report-helpers.js +939 -0
  167. package/esm/helpers/utils/sales-overview-report-helpers.js +1046 -0
  168. package/esm/helpers/utils/sales-summary-report-helpers.js +877 -0
  169. package/esm/helpers/utils/scan-code-helpers.js +31 -0
  170. package/esm/helpers/utils/selection-model.js +68 -0
  171. package/esm/helpers/utils/shift-window-helpers.js +148 -0
  172. package/esm/helpers/utils/simplified-catalog.js +107 -0
  173. package/esm/helpers/utils/simplified-halfhalf.js +101 -0
  174. package/esm/helpers/utils/simplified-specials.js +107 -0
  175. package/esm/helpers/utils/simplified-tenant.js +411 -0
  176. package/esm/helpers/utils/specials-helpers.js +727 -0
  177. package/esm/helpers/utils/tenant-calendar-helpers.js +67 -0
  178. package/esm/helpers/utils/tenant-cash-drawer-sessions-helpers.js +248 -0
  179. package/esm/helpers/utils/tenant-cash-drawers-helpers.js +31 -0
  180. package/esm/helpers/utils/tenant-cash-in-out-helpers.js +47 -0
  181. package/esm/helpers/utils/tenant-day-sessions-helpers.js +167 -0
  182. package/esm/helpers/utils/tenant-instore-shift-sessions-helpers.js +227 -0
  183. package/esm/helpers/utils/tenant-staff-helpers.js +19 -0
  184. package/esm/helpers/utils/tenant_cash_in_hand_transactions.js +31 -0
  185. package/esm/helpers/utils/time-helpers.js +142 -0
  186. package/esm/helpers/utils/void-items-report-helpers.js +529 -0
  187. package/esm/helpers/utils/void-order-items-helpers.js +32 -0
  188. package/esm/helpers/utils/voidations-summary-report-helpers.js +800 -0
  189. package/esm/helpers/utils/wallet-helpers.js +22 -0
  190. package/esm/helpers/utils/wallet-redemption-helpers.js +46 -0
  191. package/esm/helpers/utils/warehouse-catalog-conversion.js +117 -0
  192. package/esm/helpers/utils/warehouse-inventory.js +59 -0
  193. package/esm/helpers/utils/warehouse-purchase-order-engine.js +27 -0
  194. package/esm/helpers/utils/warehouse-purchase-order-receipt-engine.js +205 -0
  195. package/esm/helpers/utils/warehouse-purchase-order-x-report-helpers.js +1432 -0
  196. package/esm/helpers/utils/warehouse-sale-order-engine.js +27 -0
  197. package/esm/helpers/utils/warehouse-sale-order-receipt-engine.js +207 -0
  198. package/esm/helpers/utils/warehouse-sale-order-x-report-helpers.js +1 -0
  199. package/esm/helpers/utils/warehouse-sale-x-report-helpers.js +1434 -0
  200. package/esm/helpers/utils/warehouse-settings-helpers.js +37 -0
  201. package/esm/helpers/utils/warehouse-void-purchase-order-items-helpers.js +34 -0
  202. package/esm/helpers/utils/warehouse-void-purchase-order-items-report-helpers.js +18 -0
  203. package/esm/helpers/utils/warehouse-void-sale-order-items-helpers.js +34 -0
  204. package/esm/helpers/utils/warehouse-void-sale-order-items-report-helpers.js +18 -0
  205. package/esm/helpers/utils/warehouse_inventory_transactions.js +91 -0
  206. package/esm/helpers/utils/x-report-helpers.js +1850 -0
  207. package/esm/index.js +3 -0
  208. package/esm/schemas/index.js +2 -0
  209. package/esm/schemas/models/app_configs.js +36 -0
  210. package/esm/schemas/models/applied_order_discounts.js +103 -0
  211. package/esm/schemas/models/brands.js +56 -0
  212. package/esm/schemas/models/categories.js +74 -0
  213. package/esm/schemas/models/close_dates.js +63 -0
  214. package/esm/schemas/models/common-models.js +449 -0
  215. package/esm/schemas/models/courses.js +62 -0
  216. package/esm/schemas/models/customer_redemptions.js +82 -0
  217. package/esm/schemas/models/customers.js +269 -0
  218. package/esm/schemas/models/deliveries.js +137 -0
  219. package/esm/schemas/models/delivery_areas.js +97 -0
  220. package/esm/schemas/models/dinein_floors.js +55 -0
  221. package/esm/schemas/models/dinein_tables.js +97 -0
  222. package/esm/schemas/models/dinein_tables_fingerprints.js +96 -0
  223. package/esm/schemas/models/discounts.js +87 -0
  224. package/esm/schemas/models/expense_categories.js +61 -0
  225. package/esm/schemas/models/expense_details.js +130 -0
  226. package/esm/schemas/models/gift_cards.js +342 -0
  227. package/esm/schemas/models/halfhalf_setup.js +142 -0
  228. package/esm/schemas/models/index.js +111 -0
  229. package/esm/schemas/models/internal_customers.js +139 -0
  230. package/esm/schemas/models/internal_invoices.js +119 -0
  231. package/esm/schemas/models/internal_leads.js +78 -0
  232. package/esm/schemas/models/internal_operational_roles.js +85 -0
  233. package/esm/schemas/models/internal_staffs.js +65 -0
  234. package/esm/schemas/models/inventories.js +103 -0
  235. package/esm/schemas/models/inventory_categories.js +52 -0
  236. package/esm/schemas/models/inventory_transactions.js +143 -0
  237. package/esm/schemas/models/item_transactions.js +117 -0
  238. package/esm/schemas/models/items.js +341 -0
  239. package/esm/schemas/models/marketing_fingerprints.js +92 -0
  240. package/esm/schemas/models/menus.js +66 -0
  241. package/esm/schemas/models/messaging_devices.js +99 -0
  242. package/esm/schemas/models/modifier_extras.js +120 -0
  243. package/esm/schemas/models/offers.js +470 -0
  244. package/esm/schemas/models/offers_fingerprints.js +61 -0
  245. package/esm/schemas/models/operational_roles.js +155 -0
  246. package/esm/schemas/models/orders.js +1051 -0
  247. package/esm/schemas/models/printer_settings.js +245 -0
  248. package/esm/schemas/models/public_holidays.js +58 -0
  249. package/esm/schemas/models/reservations.js +127 -0
  250. package/esm/schemas/models/reviews.js +145 -0
  251. package/esm/schemas/models/rewards_usage.js +61 -0
  252. package/esm/schemas/models/riders.js +75 -0
  253. package/esm/schemas/models/specials.js +169 -0
  254. package/esm/schemas/models/staff_shifts.js +66 -0
  255. package/esm/schemas/models/tenant-activity-logs.js +126 -0
  256. package/esm/schemas/models/tenant_active_jobs.js +77 -0
  257. package/esm/schemas/models/tenant_calendar.js +89 -0
  258. package/esm/schemas/models/tenant_cash_drawer_sessions.js +208 -0
  259. package/esm/schemas/models/tenant_cash_drawers.js +60 -0
  260. package/esm/schemas/models/tenant_cash_in_hand_transactions.js +69 -0
  261. package/esm/schemas/models/tenant_cash_in_out.js +104 -0
  262. package/esm/schemas/models/tenant_clients.js +66 -0
  263. package/esm/schemas/models/tenant_day_sessions.js +166 -0
  264. package/esm/schemas/models/tenant_hr_attendance_records.js +87 -0
  265. package/esm/schemas/models/tenant_hr_biometric_enrollments.js +69 -0
  266. package/esm/schemas/models/tenant_hr_departments.js +42 -0
  267. package/esm/schemas/models/tenant_hr_documents.js +71 -0
  268. package/esm/schemas/models/tenant_hr_employees.js +172 -0
  269. package/esm/schemas/models/tenant_hr_leave_requests.js +80 -0
  270. package/esm/schemas/models/tenant_hr_payrolls.js +131 -0
  271. package/esm/schemas/models/tenant_hr_performance_reviews.js +58 -0
  272. package/esm/schemas/models/tenant_hr_policies.js +57 -0
  273. package/esm/schemas/models/tenant_hr_positions.js +48 -0
  274. package/esm/schemas/models/tenant_hr_shift_schedules.js +84 -0
  275. package/esm/schemas/models/tenant_hr_shifts.js +64 -0
  276. package/esm/schemas/models/tenant_instore_shift_sessions.js +204 -0
  277. package/esm/schemas/models/tenant_instore_shifts.js +63 -0
  278. package/esm/schemas/models/tenant_inventory_department_transactions.js +116 -0
  279. package/esm/schemas/models/tenant_inventory_department_utilities.js +85 -0
  280. package/esm/schemas/models/tenant_inventory_departments.js +55 -0
  281. package/esm/schemas/models/tenant_inventory_entries.js +131 -0
  282. package/esm/schemas/models/tenant_metadata.js +88 -0
  283. package/esm/schemas/models/tenant_order_item_instructions.js +66 -0
  284. package/esm/schemas/models/tenant_purchase_order_vendor_returns.js +80 -0
  285. package/esm/schemas/models/tenant_purchase_orders.js +158 -0
  286. package/esm/schemas/models/tenant_shifts.js +57 -0
  287. package/esm/schemas/models/tenant_staffs.js +129 -0
  288. package/esm/schemas/models/tenant_vendors.js +99 -0
  289. package/esm/schemas/models/tenants.js +811 -0
  290. package/esm/schemas/models/terminal_devices.js +63 -0
  291. package/esm/schemas/models/tokens.js +73 -0
  292. package/esm/schemas/models/track_order_numbers.js +42 -0
  293. package/esm/schemas/models/void_order_items.js +210 -0
  294. package/esm/schemas/models/vouchers.js +101 -0
  295. package/esm/schemas/models/wallet_transactions.js +128 -0
  296. package/esm/schemas/models/wallets.js +44 -0
  297. package/esm/schemas/models/warehouse-activity-logs.js +144 -0
  298. package/esm/schemas/models/warehouse_categories.js +83 -0
  299. package/esm/schemas/models/warehouse_clients.js +81 -0
  300. package/esm/schemas/models/warehouse_communications.js +226 -0
  301. package/esm/schemas/models/warehouse_internal_movements.js +463 -0
  302. package/esm/schemas/models/warehouse_inventory_entries.js +125 -0
  303. package/esm/schemas/models/warehouse_inventory_lot_serial_numbers.js +188 -0
  304. package/esm/schemas/models/warehouse_inventory_transactions.js +133 -0
  305. package/esm/schemas/models/warehouse_item_transactions.js +97 -0
  306. package/esm/schemas/models/warehouse_items.js +173 -0
  307. package/esm/schemas/models/warehouse_operational_roles.js +87 -0
  308. package/esm/schemas/models/warehouse_purchase_order_receipts.js +163 -0
  309. package/esm/schemas/models/warehouse_purchase_order_rfqs.js +339 -0
  310. package/esm/schemas/models/warehouse_purchase_order_vendor_returns.js +199 -0
  311. package/esm/schemas/models/warehouse_purchase_orders.js +334 -0
  312. package/esm/schemas/models/warehouse_sale_deliveries.js +155 -0
  313. package/esm/schemas/models/warehouse_sale_invoices.js +229 -0
  314. package/esm/schemas/models/warehouse_sale_order_rfqs.js +340 -0
  315. package/esm/schemas/models/warehouse_sale_orders.js +322 -0
  316. package/esm/schemas/models/warehouse_staffs.js +104 -0
  317. package/esm/schemas/models/warehouse_track_order_numbers.js +73 -0
  318. package/esm/schemas/models/warehouse_vendors.js +99 -0
  319. package/esm/schemas/models/warehouse_void_purchase_order_items.js +174 -0
  320. package/esm/schemas/models/warehouse_void_sale_order_items.js +174 -0
  321. package/esm/schemas/models/warehouses.js +253 -0
  322. package/esm/schemas/types/app_configs.js +1 -0
  323. package/esm/schemas/types/applied_order_discounts.js +1 -0
  324. package/esm/schemas/types/brands.js +1 -0
  325. package/esm/schemas/types/categories.js +1 -0
  326. package/esm/schemas/types/close_dates.js +1 -0
  327. package/esm/schemas/types/common.js +1 -0
  328. package/esm/schemas/types/courses.js +1 -0
  329. package/esm/schemas/types/customer_redemptions.js +1 -0
  330. package/esm/schemas/types/customers.js +1 -0
  331. package/esm/schemas/types/deliveries.js +1 -0
  332. package/esm/schemas/types/delivery_areas.js +1 -0
  333. package/esm/schemas/types/dinein_floors.js +1 -0
  334. package/esm/schemas/types/dinein_tables.js +1 -0
  335. package/esm/schemas/types/dinein_tables_fingerprints.js +1 -0
  336. package/esm/schemas/types/discounts.js +1 -0
  337. package/esm/schemas/types/expense_categories.js +1 -0
  338. package/esm/schemas/types/expense_details.js +1 -0
  339. package/esm/schemas/types/gift_cards.js +1 -0
  340. package/esm/schemas/types/halfhalf_setup.js +1 -0
  341. package/esm/schemas/types/index.js +113 -0
  342. package/esm/schemas/types/internal_customers.js +1 -0
  343. package/esm/schemas/types/internal_invoices.js +1 -0
  344. package/esm/schemas/types/internal_leads.js +1 -0
  345. package/esm/schemas/types/internal_operational_roles.js +16 -0
  346. package/esm/schemas/types/internal_staffs.js +1 -0
  347. package/esm/schemas/types/inventories.js +1 -0
  348. package/esm/schemas/types/inventory_categories.js +1 -0
  349. package/esm/schemas/types/inventory_department_transactions.js +1 -0
  350. package/esm/schemas/types/inventory_department_utilities.js +1 -0
  351. package/esm/schemas/types/inventory_departments.js +1 -0
  352. package/esm/schemas/types/inventory_transactions.js +1 -0
  353. package/esm/schemas/types/item_transactions.js +1 -0
  354. package/esm/schemas/types/items.js +1 -0
  355. package/esm/schemas/types/marketing_fingerprints.js +1 -0
  356. package/esm/schemas/types/menus.js +1 -0
  357. package/esm/schemas/types/messaging_devices.js +1 -0
  358. package/esm/schemas/types/modifier_extras.js +1 -0
  359. package/esm/schemas/types/multi_tenants.js +1 -0
  360. package/esm/schemas/types/offers.js +1 -0
  361. package/esm/schemas/types/offers_fingerprints.js +1 -0
  362. package/esm/schemas/types/operational_roles.js +15 -0
  363. package/esm/schemas/types/orders.js +1 -0
  364. package/esm/schemas/types/printer_settings.js +1 -0
  365. package/esm/schemas/types/public_holidays.js +1 -0
  366. package/esm/schemas/types/reservations.js +1 -0
  367. package/esm/schemas/types/reviews.js +1 -0
  368. package/esm/schemas/types/rewards_usage.js +1 -0
  369. package/esm/schemas/types/riders.js +1 -0
  370. package/esm/schemas/types/specials.js +1 -0
  371. package/esm/schemas/types/staff_shifts.js +1 -0
  372. package/esm/schemas/types/tenant-activity-logs.js +1 -0
  373. package/esm/schemas/types/tenant_active_jobs.js +1 -0
  374. package/esm/schemas/types/tenant_calendar.js +1 -0
  375. package/esm/schemas/types/tenant_cash_drawer_sessions.js +1 -0
  376. package/esm/schemas/types/tenant_cash_drawers.js +1 -0
  377. package/esm/schemas/types/tenant_cash_in_hand_transactions.js +1 -0
  378. package/esm/schemas/types/tenant_cash_in_out.js +1 -0
  379. package/esm/schemas/types/tenant_clients.js +1 -0
  380. package/esm/schemas/types/tenant_day_sessions.js +1 -0
  381. package/esm/schemas/types/tenant_hr_attendance_records.js +1 -0
  382. package/esm/schemas/types/tenant_hr_biometric_enrollments.js +1 -0
  383. package/esm/schemas/types/tenant_hr_departments.js +1 -0
  384. package/esm/schemas/types/tenant_hr_documents.js +1 -0
  385. package/esm/schemas/types/tenant_hr_employees.js +1 -0
  386. package/esm/schemas/types/tenant_hr_leave_requests.js +1 -0
  387. package/esm/schemas/types/tenant_hr_payrolls.js +1 -0
  388. package/esm/schemas/types/tenant_hr_performance_reviews.js +1 -0
  389. package/esm/schemas/types/tenant_hr_policies.js +1 -0
  390. package/esm/schemas/types/tenant_hr_positions.js +1 -0
  391. package/esm/schemas/types/tenant_hr_shift_schedules.js +1 -0
  392. package/esm/schemas/types/tenant_hr_shifts.js +1 -0
  393. package/esm/schemas/types/tenant_instore_shift_sessions.js +1 -0
  394. package/esm/schemas/types/tenant_instore_shifts.js +1 -0
  395. package/esm/schemas/types/tenant_inventory_entries.js +1 -0
  396. package/esm/schemas/types/tenant_metadata.js +1 -0
  397. package/esm/schemas/types/tenant_order_item_instructions.js +1 -0
  398. package/esm/schemas/types/tenant_purchase_order_vendor_returns.js +1 -0
  399. package/esm/schemas/types/tenant_purchase_orders.js +1 -0
  400. package/esm/schemas/types/tenant_shifts.js +1 -0
  401. package/esm/schemas/types/tenant_staffs.js +1 -0
  402. package/esm/schemas/types/tenant_vendors.js +1 -0
  403. package/esm/schemas/types/tenants.js +1 -0
  404. package/esm/schemas/types/terminal_devices.js +1 -0
  405. package/esm/schemas/types/tokens.js +1 -0
  406. package/esm/schemas/types/track_order_numbers.js +1 -0
  407. package/esm/schemas/types/void_order_items.js +1 -0
  408. package/esm/schemas/types/vouchers.js +1 -0
  409. package/esm/schemas/types/wallet_transactions.js +1 -0
  410. package/esm/schemas/types/wallets.js +1 -0
  411. package/esm/schemas/types/warehouse-activity-logs.js +1 -0
  412. package/esm/schemas/types/warehouse_categories.js +1 -0
  413. package/esm/schemas/types/warehouse_clients.js +1 -0
  414. package/esm/schemas/types/warehouse_communications.js +1 -0
  415. package/esm/schemas/types/warehouse_internal_movements.js +1 -0
  416. package/esm/schemas/types/warehouse_inventory_entries.js +1 -0
  417. package/esm/schemas/types/warehouse_inventory_lot_serial_numbers.js +1 -0
  418. package/esm/schemas/types/warehouse_inventory_transactions.js +1 -0
  419. package/esm/schemas/types/warehouse_item_transactions.js +1 -0
  420. package/esm/schemas/types/warehouse_items.js +1 -0
  421. package/esm/schemas/types/warehouse_operational_roles.js +15 -0
  422. package/esm/schemas/types/warehouse_purchase_order_receipts.js +18 -0
  423. package/esm/schemas/types/warehouse_purchase_order_rfqs.js +1 -0
  424. package/esm/schemas/types/warehouse_purchase_order_vendor_returns.js +1 -0
  425. package/esm/schemas/types/warehouse_purchase_orders.js +1 -0
  426. package/esm/schemas/types/warehouse_sale_deliveries.js +1 -0
  427. package/esm/schemas/types/warehouse_sale_invoices.js +1 -0
  428. package/esm/schemas/types/warehouse_sale_order_rfqs.js +1 -0
  429. package/esm/schemas/types/warehouse_sale_orders.js +1 -0
  430. package/esm/schemas/types/warehouse_staffs.js +1 -0
  431. package/esm/schemas/types/warehouse_track_order_numbers.js +1 -0
  432. package/esm/schemas/types/warehouse_vendors.js +1 -0
  433. package/esm/schemas/types/warehouse_void_purchase_order_items.js +1 -0
  434. package/esm/schemas/types/warehouse_void_sale_order_items.js +1 -0
  435. package/esm/schemas/types/warehouses.js +1 -0
  436. package/package.json +6 -3
@@ -0,0 +1,779 @@
1
+ import ObjectID from 'bson-objectid';
2
+ import { MODIFIER_OPTION_REF_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM } from '../../constants';
3
+ import { calculateItemTotalWithTax } from '../store';
4
+ import { applyChooseExpensiveSegmentPrice, convertItemDiscountToOrderItemDiscount, syncOrderEngineItem, } from './order-engine';
5
+ import { convertItemToWorkableItem, findApplicableSchedule, getExcludedPlatformsFromIncludedPlatforms, getPriceEnum, } from './platform-catalog';
6
+ import { convertPriceObjFromCents, convertPriceObjToCents, convertPriceObjToSegmentPrice, convertSpecialHoursFromCents, convertSpecialHoursToCents, mergePriceObjs, } from './platform-num';
7
+ import { buildSelectionRefQueues, buildStoredFromSelection, consumeSelectionMatch, } from './selection-model';
8
+ import { applyModifierSpecialRefRules } from './specials-helpers';
9
+ export function getHalfHalfPostedData(data, payload) {
10
+ return data.some((half) => half._id === payload._id)
11
+ ? data
12
+ : data.concat(getHalfhalfSetupWithPrice(payload)).sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0));
13
+ }
14
+ export function renderBulkHalfHalfUpdate(data, payload) {
15
+ return data
16
+ .map((halfHalf) => {
17
+ const updatedHalfHalf = payload.find((c) => c._id === halfHalf._id);
18
+ return updatedHalfHalf
19
+ ? { ...halfHalf, ...(updatedHalfHalf != null ? getHalfhalfSetupWithPrice(updatedHalfHalf) : {}) }
20
+ : halfHalf;
21
+ })
22
+ .sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0));
23
+ }
24
+ export function getHalfHalfUpdatedData(data, payload) {
25
+ return data
26
+ .map((halfHalf) => halfHalf._id === payload._id
27
+ ? {
28
+ ...halfHalf,
29
+ ...getHalfhalfSetupWithPrice(payload),
30
+ }
31
+ : halfHalf)
32
+ .sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0));
33
+ }
34
+ export function getHalfHalfDeletedData(data, payload) {
35
+ return data.filter((halfHalf) => halfHalf._id !== payload).sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0));
36
+ }
37
+ // ====================================================================================================
38
+ export function getHalfhalfSetupWithPrice(halfhalfSetup, writeable) {
39
+ const convertToPrice = writeable ? convertPriceObjToCents : convertPriceObjFromCents;
40
+ const convertItemSpecialHours = writeable ? convertSpecialHoursToCents : convertSpecialHoursFromCents;
41
+ return {
42
+ ...halfhalfSetup,
43
+ ...(halfhalfSetup.upsell_price != null ? { upsell_price: convertToPrice(halfhalfSetup.upsell_price) } : {}),
44
+ ...(halfhalfSetup.discount_amount != null
45
+ ? { discount_amount: convertToPrice(halfhalfSetup.discount_amount) }
46
+ : {}),
47
+ ...(halfhalfSetup.item_special_hours != null
48
+ ? { item_special_hours: convertItemSpecialHours(halfhalfSetup.item_special_hours) }
49
+ : {}),
50
+ ...(halfhalfSetup.items != null
51
+ ? {
52
+ items: halfhalfSetup.items.map((item) => ({
53
+ ...item,
54
+ ...(item.upsell_price != null ? { upsell_price: convertToPrice(item.upsell_price) } : {}),
55
+ })),
56
+ }
57
+ : {}),
58
+ };
59
+ }
60
+ /**
61
+ * Divides a half-half segment item's price structure by the number of
62
+ * segments (2 halves / 4 quarters):
63
+ *
64
+ * - the item-level `price` is divided by `segments`,
65
+ * - EVERY modifier option price is divided too (recursively, at any depth):
66
+ * required groups because they define the item's price (e.g. "Pizza Size" →
67
+ * "Large 13\""), optional groups because they apply to the same segment
68
+ * (e.g. "Extra Cheese" on one half),
69
+ * - item-level upsell prices are never touched here; callers merge them on
70
+ * top.
71
+ *
72
+ * Returns the item unchanged when `segments` is missing/<= 1.
73
+ */
74
+ export function divideItemPriceBySegments(item, segments) {
75
+ const divisor = segments ?? 1;
76
+ if (divisor <= 1)
77
+ return item;
78
+ const divideModifierPrices = (modifiers) => {
79
+ if (modifiers == null || modifiers.length === 0)
80
+ return modifiers;
81
+ return modifiers.map((modifier) => ({
82
+ ...modifier,
83
+ options: (modifier.options ?? []).map((option) => ({
84
+ ...option,
85
+ price: convertPriceObjToSegmentPrice(option.price ?? null, divisor),
86
+ modifiers: divideModifierPrices(option.modifiers),
87
+ })),
88
+ }));
89
+ };
90
+ const result = {
91
+ ...item,
92
+ price: convertPriceObjToSegmentPrice(item.price, divisor),
93
+ modifiers: divideModifierPrices(item.modifiers),
94
+ };
95
+ return result;
96
+ }
97
+ const zeroModifierPrices = (modifiers) => {
98
+ if (modifiers == null || modifiers.length === 0)
99
+ return modifiers;
100
+ return modifiers.map((modifier) => ({
101
+ ...modifier,
102
+ options: (modifier.options ?? []).map((option) => ({
103
+ ...option,
104
+ price: null,
105
+ modifiers: zeroModifierPrices(option.modifiers),
106
+ })),
107
+ }));
108
+ };
109
+ /**
110
+ * A half-half nested in a special is priced ONLY by the special's item-level
111
+ * upsell (split per segment): every other price inside the segment item — its
112
+ * own price and the prices of its modifier options at any depth — is IGNORED
113
+ * (zeroed), so nothing else can leak into the deal. Options stay selectable;
114
+ * the special's own excluded/exclusive ref rules are applied downstream by
115
+ * `convertSpecialToItem` (`applyModifierSpecialRefRules`).
116
+ */
117
+ function zeroItemPrices(item) {
118
+ return { ...item, price: null, modifiers: zeroModifierPrices(item.modifiers) };
119
+ }
120
+ export function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, platform, tenant_id) {
121
+ if (!platform || !tenant_id)
122
+ return [];
123
+ const isSimple = typeof itemsMap[Object.keys(itemsMap)[0]]?.sold_out === 'boolean';
124
+ // Order the menu by the setup's sort_id (same as specials).
125
+ const sortedHalfhalfSetups = [...halfhalfSetups].sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0));
126
+ const halfhalfMenu = [];
127
+ for (let i = 0; i < sortedHalfhalfSetups.length; i++) {
128
+ const halfhalfSetup = sortedHalfhalfSetups[i];
129
+ if (!halfhalfSetup.active ||
130
+ !halfhalfSetup.tenants.includes(tenant_id) ||
131
+ !halfhalfSetup.included_platforms.includes(platform))
132
+ continue;
133
+ const applicableSchedule = findApplicableSchedule(halfhalfSetup.item_special_hours, platform);
134
+ // if there is no applicable schedule, we skip the halfhalfSetup
135
+ if (applicableSchedule === false)
136
+ continue;
137
+ // we get the price of the halfhalfSetup
138
+ let upsell_price = halfhalfSetup.upsell_price;
139
+ if (applicableSchedule !== true && applicableSchedule.price) {
140
+ // if there is an applicable schedule, we use the price from the schedule
141
+ upsell_price = applicableSchedule.price;
142
+ }
143
+ // we get the discount_amount of the halfhalfSetup
144
+ let discount_amount = halfhalfSetup.discount_amount;
145
+ let is_discount_percentage = halfhalfSetup.is_discount_percentage;
146
+ if (applicableSchedule !== true && applicableSchedule.discount_amount) {
147
+ // schedule discount takes preference over the half-half's own discount
148
+ // and the schedule also carries the percentage flag (same as IItem)
149
+ discount_amount = applicableSchedule.discount_amount;
150
+ is_discount_percentage = applicableSchedule.is_discount_percentage;
151
+ }
152
+ const halfhalfItems = [...halfhalfSetup.items]
153
+ // Respect excluded_refs: items whose item_id (ref) is listed are removed
154
+ // from the selectable list (same semantics as specials' excluded_refs).
155
+ .filter((setupItem) => !halfhalfSetup.excluded_refs.includes(setupItem.item_id))
156
+ .sort((a, b) => a.sort_id - b.sort_id);
157
+ // Workable segment entries: divided base price + own upsell. The
158
+ // expensive-segment rule is NOT baked in here: it depends on the current
159
+ // selection, so it runs on the engine working data (classic drawer and
160
+ // `convertHalfHalfToOrderEngineItem`) against the definition prices as
161
+ // the original references.
162
+ const entries = [];
163
+ // Items that exist for this platform but are outside their own schedule
164
+ // right now. Item schedules filter the SELECTABLE segment options — they
165
+ // must not invalidate the setup at menu level; the setup's own schedule is
166
+ // that gate.
167
+ let hasScheduledOutItem = false;
168
+ for (let j = 0; j < halfhalfItems.length; j++) {
169
+ const item = halfhalfItems[j];
170
+ const catalogItem = itemsMap[item.item_id];
171
+ if (!catalogItem)
172
+ continue;
173
+ const workableItem = convertItemToWorkableItem(catalogItem, platform, tenant_id);
174
+ if (!workableItem) {
175
+ // The item failed ONLY its own schedule: probe without the schedule
176
+ // check to tell "scheduled out right now" apart from "structurally
177
+ // unavailable" (inactive / platform / tenant filtered).
178
+ if (convertItemToWorkableItem(catalogItem, platform, tenant_id, true, true) != null) {
179
+ hasScheduledOutItem = true;
180
+ }
181
+ continue;
182
+ }
183
+ if (discount_amount != null) {
184
+ workableItem.discount_amount = null;
185
+ }
186
+ // Apply the half-half reference rules to the item's own modifiers:
187
+ // excluded_refs removes modifiers/options, exclusive_refs removes their price.
188
+ workableItem.modifiers = applyModifierSpecialRefRules(workableItem.modifiers, halfhalfSetup.exclusive_refs, halfhalfSetup.excluded_refs);
189
+ // Each half/quarter costs the item's price divided by the number of
190
+ // segments; every modifier option price is divided with it (e.g. Pizza
191
+ // Size 1150 -> 575, Extra Cheese 200 -> 100).
192
+ const segmentItem = divideItemPriceBySegments(workableItem, halfhalfSetup.segments.length);
193
+ entries.push({
194
+ workableItem: segmentItem,
195
+ itemUpsell: item.upsell_price,
196
+ });
197
+ }
198
+ const items = [];
199
+ for (const entry of entries) {
200
+ const { workableItem, itemUpsell } = entry;
201
+ // Each half keeps its own item-level upsell, added ON TOP of the divided
202
+ // price. The half-half upsell is a ONE-TIME addition on the order item,
203
+ // not merged per segment.
204
+ if (itemUpsell != null) {
205
+ workableItem.price = mergePriceObjs(workableItem.price, itemUpsell);
206
+ }
207
+ // exclusive_refs: this item is a segment option - make it free (price 0).
208
+ if (halfhalfSetup.exclusive_refs.includes(workableItem._id)) {
209
+ workableItem.price = null;
210
+ }
211
+ items.push(workableItem);
212
+ }
213
+ // A setup whose items are all outside their own schedule right now still
214
+ // belongs to the menu (the setup's own schedule is the menu-level gate);
215
+ // item schedules only filter the segment options.
216
+ if (items.length === 0 && !hasScheduledOutItem)
217
+ continue;
218
+ halfhalfMenu.push({
219
+ _id: halfhalfSetup._id,
220
+ name: halfhalfSetup.name,
221
+ description: halfhalfSetup.description,
222
+ sold_out: isSimple ? halfhalfSetup.sold_out.includes(tenant_id) : halfhalfSetup.sold_out,
223
+ image_url: halfhalfSetup.image_url,
224
+ choose_expensive_segment_price: halfhalfSetup.choose_expensive_segment_price,
225
+ segments: halfhalfSetup.segments,
226
+ category_id: halfhalfSetup.category_id,
227
+ excluded_refs: halfhalfSetup.excluded_refs,
228
+ exclusive_refs: halfhalfSetup.exclusive_refs,
229
+ discount_amount,
230
+ is_discount_percentage,
231
+ upsell_price,
232
+ items,
233
+ });
234
+ }
235
+ return halfhalfMenu;
236
+ }
237
+ /**
238
+ * Converts an IHalfHalfSetup into an IItem so it can flow through the standard
239
+ * catalog → drawer → cart pipeline just like a regular catalog item.
240
+ *
241
+ * Each segment becomes a single-select IModifier (one option per available
242
+ * item, priced as `(item price / segments) + own upsell`), so duplicates
243
+ * across segments are allowed and each segment must be filled exactly once.
244
+ * All modifier option prices are divided with the base (e.g. Pizza Size
245
+ * 1150 -> 575, Extra Cheese 200 -> 100).
246
+ *
247
+ * When the half-half is nested in a special (pass `specialItems`), the special
248
+ * is the authority instead: the segment options are the special's own items
249
+ * (priced from their special upsell split per segment), the half-half's own
250
+ * item list/ref rules/per-item upsells are ignored, and only
251
+ * `choose_expensive_segment_price` is taken from the setup.
252
+ *
253
+ * PURE CONVERSION ONLY — no availability filtering (active / tenants /
254
+ * included_platforms), no special-hours / platform-based price resolution,
255
+ * and NO `choose_expensive_segment_price` handling: that rule depends on
256
+ * which halves the user picks, so it is applied later at selection time
257
+ * (see `applyChooseExpensiveSegmentPrice`). Setup fields are copied through
258
+ * as-is:
259
+ * - item `price` stays the half-half upsell price (each platform resolves it
260
+ * via `getPriceEnum`),
261
+ * - item `discount_amount` stays the half-half discount,
262
+ * - `item_special_hours` is preserved on the output item,
263
+ * - each option's `excluded_platforms` is derived (complement) from its
264
+ * source item's `included_platforms`, so platform availability can be
265
+ * applied by the filter layer downstream.
266
+ *
267
+ * Returns null only when no option can be resolved from the items map.
268
+ */
269
+ export function convertHalfHalfToItem(halfhalfSetup, itemsMap, options) {
270
+ const specialItems = options?.specialItems;
271
+ const isSpecialContext = specialItems != null;
272
+ // Fields are carried through as-is (no schedule resolution here).
273
+ const upsell_price = halfhalfSetup.upsell_price;
274
+ const discount_amount = halfhalfSetup.discount_amount;
275
+ const is_discount_percentage = halfhalfSetup.is_discount_percentage;
276
+ // ── Build shared option list (segment-neutral ids) ─────────────
277
+ // In a special the segment options ARE the special's own items; the
278
+ // half-half's original item list is never used. Standalone uses the
279
+ // half-half's own list (respecting its excluded_refs).
280
+ const halfHalfItems = specialItems
281
+ ? [...specialItems].sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0))
282
+ : [...halfhalfSetup.items]
283
+ // Respect excluded_refs: items whose item_id (ref) is listed are
284
+ // removed from the selectable list (same semantics as specials').
285
+ .filter((setupItem) => !halfhalfSetup.excluded_refs.includes(setupItem.item_id))
286
+ .sort((a, b) => a.sort_id - b.sort_id);
287
+ // Aggregate the union of keywords/caveats/dietary_preferences across all
288
+ // constituent items so the half-half shows them too.
289
+ const allKeywords = [];
290
+ const allCaveats = [];
291
+ const allDietaryPreferences = [];
292
+ const optionEntries = [];
293
+ for (let i = 0; i < halfHalfItems.length; i++) {
294
+ const halfHalfItem = halfHalfItems[i];
295
+ const catalogItem = itemsMap[halfHalfItem.item_id];
296
+ if (!catalogItem)
297
+ continue;
298
+ allKeywords.push(...(catalogItem.keywords ?? []));
299
+ allCaveats.push(...(catalogItem.caveats ?? []));
300
+ allDietaryPreferences.push(...(catalogItem.dietary_preferences ?? []));
301
+ // Inside a special the segment item carries NO pricing of its own: its
302
+ // base price and its modifier option prices (at any depth) are zeroed so
303
+ // only the special's item-level upsell (applied below, split per segment)
304
+ // can charge. Standalone keeps the item's modifiers (own ref rules first,
305
+ // then the price structure divided by the number of segments).
306
+ const segmentItem = isSpecialContext
307
+ ? zeroItemPrices(catalogItem)
308
+ : divideItemPriceBySegments({
309
+ ...catalogItem,
310
+ modifiers: applyModifierSpecialRefRules(catalogItem.modifiers, halfhalfSetup.exclusive_refs, halfhalfSetup.excluded_refs),
311
+ }, halfhalfSetup.segments.length);
312
+ optionEntries.push({
313
+ catalogItem,
314
+ segmentItem,
315
+ itemUpsell: halfHalfItem.upsell_price,
316
+ sortId: halfHalfItem.sort_id ?? 0,
317
+ });
318
+ }
319
+ const baseOptions = [];
320
+ for (const entry of optionEntries) {
321
+ const { catalogItem, segmentItem, itemUpsell, sortId } = entry;
322
+ // In a special the special's item-level upsell is the only price source:
323
+ // segment option = special upsell / segments (no item price, no own
324
+ // per-item upsell; no special upsell => free). Standalone keeps the item
325
+ // price/segments + the half-half's own per-item upsell.
326
+ let optionPrice = isSpecialContext
327
+ ? convertPriceObjToSegmentPrice(itemUpsell ?? null, halfhalfSetup.segments.length)
328
+ : segmentItem.price;
329
+ if (!isSpecialContext && itemUpsell != null) {
330
+ optionPrice = mergePriceObjs(optionPrice, itemUpsell);
331
+ }
332
+ // exclusive_refs (own rules only): this option becomes free (price 0).
333
+ if (!isSpecialContext && halfhalfSetup.exclusive_refs.includes(catalogItem._id)) {
334
+ optionPrice = null;
335
+ }
336
+ baseOptions.push({
337
+ // `_id` is the real item `_id` (like a catalog option id); each segment
338
+ // creates its own occurrence below. `ref` points to the same item.
339
+ _id: catalogItem._id,
340
+ ref: catalogItem._id,
341
+ name: catalogItem.name,
342
+ active: catalogItem.active,
343
+ sold_out: catalogItem.sold_out,
344
+ sort_id: sortId,
345
+ // Each segment choice IS a menu item.
346
+ ref_type: MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
347
+ // Derived from the source item's included platforms (pure mapping),
348
+ // so platform availability can be applied by the filter layer downstream.
349
+ excluded_platforms: getExcludedPlatformsFromIncludedPlatforms(catalogItem.included_platforms),
350
+ // Carry the source item's special hours so the filter layer can apply
351
+ // schedule availability (pure mapping, no resolution here). Inside a
352
+ // special the segment item's schedule is fully ignored — the special
353
+ // owns availability/pricing.
354
+ item_modifier_option_special_hours: isSpecialContext ? null : catalogItem.item_special_hours,
355
+ price: optionPrice,
356
+ modifiers: segmentItem.modifiers,
357
+ });
358
+ }
359
+ if (baseOptions.length === 0)
360
+ return null;
361
+ // ── Build one single-select modifier per segment ───────────────
362
+ const modifiers = [];
363
+ for (let s = 0; s < halfhalfSetup.segments.length; s++) {
364
+ const segment = halfhalfSetup.segments[s];
365
+ modifiers.push({
366
+ // `_id` is the real segment `_id` (like a catalog modifier id); `ref`
367
+ // points to the same segment.
368
+ _id: segment._id,
369
+ ref: segment._id,
370
+ name: segment.name || `Segment ${s + 1}`,
371
+ description: '',
372
+ active: true,
373
+ sold_out: [],
374
+ sort_id: segment.sort_id ?? s,
375
+ min_num_options: 1,
376
+ max_num_options: 1,
377
+ num_free_options: null,
378
+ options: baseOptions.map((option) => ({
379
+ ...option,
380
+ // `_id` is the real item `_id` — same choice always yields the same
381
+ // id; `ref` stays the item `_id`.
382
+ _id: option.ref,
383
+ })),
384
+ });
385
+ }
386
+ // ── Assemble the IItem ─────────────────────────────────────────
387
+ const item = {
388
+ _id: halfhalfSetup._id,
389
+ brand_id: halfhalfSetup.brand_id,
390
+ tenants: halfhalfSetup.tenants,
391
+ category_id: halfhalfSetup.category_id,
392
+ included_platforms: halfhalfSetup.included_platforms,
393
+ name: halfhalfSetup.name,
394
+ hide_name: false,
395
+ description: halfhalfSetup.description,
396
+ active: halfhalfSetup.active,
397
+ sold_out: halfhalfSetup.sold_out,
398
+ sort_id: halfhalfSetup.sort_id,
399
+ // half-half-level upsell is added ONCE at item level; segment options
400
+ // carry the per-segment base (+ own item upsell) prices. Inside a special
401
+ // the half-half's own setup upsell is IGNORED — the item price is the
402
+ // special's upsell for the half-half option itself (null = free).
403
+ price: isSpecialContext ? (options?.specialHalfHalfUpsell ?? null) : upsell_price,
404
+ // Inside a special the half-half's own discount does NOT apply — the
405
+ // deal's pricing is the only authority (the special's upsell for the
406
+ // half-half is the item price; standalone keeps the setup discount).
407
+ discount_amount: isSpecialContext ? null : discount_amount,
408
+ is_discount_percentage: isSpecialContext ? false : is_discount_percentage,
409
+ caveats: Array.from(new Set(allCaveats)),
410
+ dietary_preferences: Array.from(new Set(allDietaryPreferences)),
411
+ tax_rate: null,
412
+ keywords: Array.from(new Set(allKeywords)),
413
+ image_url: halfhalfSetup.image_url,
414
+ ingredients: null,
415
+ // Inside a special the half-half's own schedule is ignored — the deal's
416
+ // schedule governs the half-half option (availability is checked at open
417
+ // via isSetupApplicable). Standalone keeps its schedule for the filter
418
+ // layer.
419
+ item_special_hours: isSpecialContext ? null : halfhalfSetup.item_special_hours,
420
+ modifiers: modifiers.length > 0 ? modifiers : null,
421
+ is_featured: false,
422
+ featured_sort_id: 0,
423
+ display_price: null,
424
+ show_starting_from: false,
425
+ createdAt: halfhalfSetup.createdAt,
426
+ updatedAt: halfhalfSetup.updatedAt,
427
+ };
428
+ return item;
429
+ }
430
+ /**
431
+ * Converts the legacy half-half selection (per-segment IOrderItems) into a
432
+ * single HALF_HALF IOrderItem. Each chosen segment becomes an IOrderModifier
433
+ * whose `_id` is a fresh BSON ObjectId (generated on create, like regular
434
+ * items) and whose `ref` is the segment's deterministic `_id` — so it is the
435
+ * same every time this half-half is punched. Each option's `ref` is the
436
+ * chosen item's `_id`, allowing the item to be de-structured back on edit.
437
+ */
438
+ export function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, }) {
439
+ const groups = [];
440
+ let menu_id;
441
+ for (let s = 0; s < selectedHalfHalfItems.length; s++) {
442
+ const selectedItem = selectedHalfHalfItems[s];
443
+ if (!selectedItem)
444
+ continue;
445
+ // The selected menu id (each selection item carries it) — the half-half
446
+ // belongs to the selected menu; only its constituent items (segments)
447
+ // bypass the menu filter.
448
+ if (selectedItem.menu_id != null && menu_id == null) {
449
+ menu_id = selectedItem.menu_id;
450
+ }
451
+ const segment = halfHalfItem.segments[s];
452
+ groups.push({
453
+ // Deterministic ref = the segment's real `_id` — unique per portion and
454
+ // the same every time this half-half is punched. Occurrence `_id` is
455
+ // fresh on create (selection model generates below); preserved on edit
456
+ // when the stored order item is threaded through.
457
+ ref: segment?._id ?? halfHalfItem._id,
458
+ _id: '',
459
+ name: segment?.name || `Segment ${s + 1}`,
460
+ min: 1,
461
+ max: 1,
462
+ freeN: 0,
463
+ options: [
464
+ {
465
+ // `_id` is the real catalog item `_id` (like an IItem option), so
466
+ // raw modifiers comparison works for merge and edits stay
467
+ // deterministic.
468
+ ref: selectedItem.item_id,
469
+ _id: selectedItem.item_id,
470
+ name: selectedItem.name,
471
+ price: selectedItem.price,
472
+ quantity: selectedItem.quantity,
473
+ is_free: false,
474
+ modifiers: selectedItem.modifiers ?? null,
475
+ },
476
+ ],
477
+ });
478
+ }
479
+ // Save direction of the selection model: `_id`s preserved when carried from
480
+ // the stored order item, fresh ObjectIds otherwise.
481
+ const modifiers = buildStoredFromSelection(groups);
482
+ const orderItem = {
483
+ // Half-half setup discount (schedule-resolved) is a special_discount on the
484
+ // order item — same as specials.
485
+ item_discount_details: convertItemDiscountToOrderItemDiscount(halfHalfItem.discount_amount, halfHalfItem.is_discount_percentage, platform, halfHalfItem._id),
486
+ special_instructions: '',
487
+ _net_amount: 0,
488
+ _gross_amount: 0,
489
+ _gst_amount: 0,
490
+ _discount_amount: 0,
491
+ ...existingOrderItem,
492
+ // Keep the original order-item id on edit (otherwise getCartItemsObj would
493
+ // treat it as removed + new); generate a fresh ObjectId on create, same as
494
+ // regular items.
495
+ _id: existingOrderItem?._id ?? orderItemId ?? ObjectID().toHexString(),
496
+ item_id: halfHalfItem._id,
497
+ // The half-half belongs to the selected menu; only its constituent items
498
+ // (segments) bypass the menu filter.
499
+ menu_id,
500
+ item_type: ORDER_ITEM_TYPE_ENUM.HALF_HALF,
501
+ name: halfHalfItem.name,
502
+ // half-half-level upsell is added ONCE here (segment options carry only
503
+ // their own base + item upsell prices).
504
+ price: getPriceEnum(halfHalfItem.upsell_price, platform),
505
+ subtotal: 0,
506
+ tax_rate: 0,
507
+ quantity,
508
+ modifiers,
509
+ };
510
+ const { itemSubtotal, item_discount_details } = calculateItemTotalWithTax(orderItem);
511
+ orderItem.subtotal = itemSubtotal;
512
+ orderItem.item_discount_details = item_discount_details;
513
+ return orderItem;
514
+ }
515
+ /**
516
+ * Converts the legacy half-half selection (per-segment IOrderItems) into a
517
+ * single HALF_HALF IOrderEngineItem — the SAME representation the classic
518
+ * item-options drawer builds — so callers can run it through
519
+ * `convertOrderEngineItemToOrderItem` and `setAddItemToCart`. This keeps a
520
+ * single pipeline for both classic and modern half-half flows, so the cart
521
+ * receives structurally identical order items (same fields, same modifier
522
+ * ids/refs) and merges/dedupes them consistently.
523
+ *
524
+ * Each chosen segment becomes a depth-0 engine modifier (segment `_id` as
525
+ * ref, min/max 1) with exactly one selected option (the chosen item, option
526
+ * `_id`/`ref` = the item id — consistent with the classic drawer). The item's
527
+ * own modifier tree is carried as nested selected engine modifiers; all
528
+ * options are kept selected (they were chosen), so sync/error checks pass.
529
+ */
530
+ export function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, chooseExpensiveSegmentPrice, }) {
531
+ let menu_id;
532
+ // Original (definition) prices for the assembled engine tree, keyed by the
533
+ // same option path the engine uses (`seg-1_milan`,
534
+ // `seg-1_milan_size-mod_large-13`). The selected per-segment items can carry
535
+ // prices raised by an earlier normalization (an edit de-structures them from
536
+ // the persisted line), so the baseline MUST come from the workable
537
+ // definition instead of the selected item price.
538
+ const originalPriceReferences = {};
539
+ const addDefinitionReferences = (modifiers, parentPath) => {
540
+ (modifiers ?? []).forEach((modifier) => {
541
+ const modifierPath = parentPath ? `${parentPath}_${modifier._id}` : modifier._id;
542
+ (modifier.options ?? []).forEach((option) => {
543
+ const optionPath = `${modifierPath}_${option._id}`;
544
+ originalPriceReferences[optionPath] = getPriceEnum(option.price, platform);
545
+ addDefinitionReferences(option.modifiers, optionPath);
546
+ });
547
+ });
548
+ };
549
+ // `exclusive_refs` items are FREE inside the half-half through PRICE ONLY
550
+ // (the workable conversion nulls their price). `is_free` is never set
551
+ // here: the "Free" tag belongs exclusively to `num_free_options` options.
552
+ const toEngineModifiers = (modifiers, depth, definitionModifiers) => (modifiers ?? []).map((modifier) => {
553
+ // Required/max flags come from the CATALOG definition: stored order-item
554
+ // modifiers don't carry them, and treating every group as required would
555
+ // let selected add-ons (e.g. toppings) inflate the choose_expensive
556
+ // comparison — they add on top of the segment instead.
557
+ const definitionModifier = (definitionModifiers ?? []).find((def) => def._id === modifier._id);
558
+ const options = modifier.options ?? [];
559
+ const engineOptions = options.map((option) => {
560
+ const definitionOption = (definitionModifier?.options ?? []).find((def) => def._id === option._id);
561
+ return {
562
+ _id: option._id,
563
+ ref: option.ref,
564
+ name: option.name,
565
+ price: option.price,
566
+ quantity: option.quantity || 1,
567
+ is_free: option.is_free ?? false,
568
+ default: true,
569
+ loyalty_applied: false,
570
+ voucher_applied: false,
571
+ active: true,
572
+ sold_out: [],
573
+ sort_id: 0,
574
+ excluded_platforms: [],
575
+ modifiers: toEngineModifiers(option.modifiers, depth + 1, definitionOption?.modifiers),
576
+ };
577
+ });
578
+ return {
579
+ _id: modifier._id,
580
+ ref: modifier.ref,
581
+ name: modifier.name,
582
+ description: '',
583
+ depth,
584
+ default: true,
585
+ active: true,
586
+ sold_out: [],
587
+ sort_id: 0,
588
+ // Mirror the catalog flags EXACTLY when the definition is known
589
+ // (undefined/null min = optional). Unknown groups keep the previous
590
+ // conservative default (required, max = selection count).
591
+ ...(definitionModifier != null
592
+ ? {
593
+ min_num_options: definitionModifier.min_num_options,
594
+ max_num_options: definitionModifier.max_num_options,
595
+ min_aggregate_options_quantity: definitionModifier.min_aggregate_options_quantity,
596
+ max_aggregate_options_quantity: definitionModifier.max_aggregate_options_quantity,
597
+ }
598
+ : {
599
+ min_num_options: 1,
600
+ max_num_options: options.length || 1,
601
+ }),
602
+ options: engineOptions,
603
+ };
604
+ });
605
+ const modifiers = [];
606
+ for (let s = 0; s < selectedHalfHalfItems.length; s++) {
607
+ const selectedItem = selectedHalfHalfItems[s];
608
+ if (!selectedItem)
609
+ continue;
610
+ if (selectedItem.menu_id != null && menu_id == null) {
611
+ menu_id = selectedItem.menu_id;
612
+ }
613
+ const segment = halfHalfItem.segments[s];
614
+ const definitionItem = halfHalfItem.items.find((item) => item._id === selectedItem.item_id);
615
+ const segmentPath = `${segment?._id ?? halfHalfItem._id}_${selectedItem.item_id}`;
616
+ if (definitionItem != null) {
617
+ originalPriceReferences[segmentPath] = getPriceEnum(definitionItem.price, platform);
618
+ addDefinitionReferences(definitionItem.modifiers, segmentPath);
619
+ }
620
+ const segmentOptions = [
621
+ {
622
+ _id: selectedItem.item_id,
623
+ ref: selectedItem.item_id,
624
+ name: selectedItem.name,
625
+ price: selectedItem.price,
626
+ quantity: selectedItem.quantity || 1,
627
+ is_free: false,
628
+ default: true,
629
+ loyalty_applied: false,
630
+ voucher_applied: false,
631
+ active: true,
632
+ sold_out: [],
633
+ sort_id: 0,
634
+ excluded_platforms: [],
635
+ modifiers: toEngineModifiers(selectedItem.modifiers, 1, definitionItem?.modifiers),
636
+ },
637
+ ];
638
+ const segmentModifier = {
639
+ _id: segment?._id ?? halfHalfItem._id,
640
+ ref: segment?._id ?? halfHalfItem._id,
641
+ name: segment?.name || `Segment ${s + 1}`,
642
+ description: '',
643
+ depth: 0,
644
+ default: true,
645
+ active: true,
646
+ sold_out: [],
647
+ sort_id: 0,
648
+ min_num_options: 1,
649
+ max_num_options: 1,
650
+ options: segmentOptions,
651
+ };
652
+ modifiers.push(segmentModifier);
653
+ }
654
+ const orderEngineItem = {
655
+ _id: existingOrderItem?._id ?? orderItemId ?? ObjectID().toHexString(),
656
+ category_id: halfHalfItem.category_id,
657
+ item_id: halfHalfItem._id,
658
+ menu_id: menu_id ?? null,
659
+ item_type: ORDER_ITEM_TYPE_ENUM.HALF_HALF,
660
+ is_ready: existingOrderItem?.is_ready ?? false,
661
+ // Match the classic engine conversion exactly: these fields are only
662
+ // carried when they already exist on the order item (undefined on create
663
+ // so they're omitted from the payload, same as convertCatalogItemTo-
664
+ // OrderEngineItem). Explicit null/false defaults here caused a shape
665
+ // mismatch (null vs undefined) between classic and modern lines.
666
+ is_split: existingOrderItem?.is_split,
667
+ moved_to_order_id: existingOrderItem?.moved_to_order_id,
668
+ moved_from_order_id: existingOrderItem?.moved_from_order_id,
669
+ ready_minutes: existingOrderItem?.ready_minutes,
670
+ prep_started_at: existingOrderItem?.prep_started_at,
671
+ name: halfHalfItem.name,
672
+ description: halfHalfItem.description,
673
+ loyalty_applied: false,
674
+ voucher_applied: false,
675
+ price: getPriceEnum(halfHalfItem.upsell_price, platform),
676
+ gross_total: 0,
677
+ subtotal: 0,
678
+ tax_rate: existingOrderItem?.tax_rate ?? 0,
679
+ quantity,
680
+ image_url: halfHalfItem.image_url,
681
+ special_instructions: existingOrderItem?.special_instructions ?? '',
682
+ item_discount_details: convertItemDiscountToOrderItemDiscount(halfHalfItem.discount_amount, halfHalfItem.is_discount_percentage, platform, halfHalfItem._id),
683
+ modifiers,
684
+ };
685
+ const syncedOrderEngineItem = syncOrderEngineItem(orderEngineItem);
686
+ if (chooseExpensiveSegmentPrice === true) {
687
+ return applyChooseExpensiveSegmentPrice(syncedOrderEngineItem, { originalPriceReferences });
688
+ }
689
+ return syncedOrderEngineItem;
690
+ }
691
+ // ====================================================================================================
692
+ /**
693
+ * De-structures a HALF_HALF IOrderItem back into the legacy per-segment
694
+ * selection format used by the HalfHalfScreen selection flow.
695
+ *
696
+ * Segment identity: the modifier's ref = the segment's real `_id`. Position
697
+ * and first-empty-slot are kept as fallbacks. Returns null if the order item
698
+ * doesn't belong to the provided halfhalf setup.
699
+ */
700
+ export function deStructureHalfHalfOrderItem(orderItem, halfHalfItem) {
701
+ if (orderItem.item_id !== halfHalfItem._id)
702
+ return null;
703
+ const selectedHalfHalfItems = new Array(halfHalfItem.segments.length).fill(null);
704
+ const orderModifiers = orderItem.modifiers ?? [];
705
+ // Ref-keyed FIFO queues: one stored modifier per segment (consumed once,
706
+ // duplicate-safe). Segment identity = modifier ref = the segment's real `_id`;
707
+ // exactId also covers legacy orders that stored `_id` = ref.
708
+ const orderModifierQueues = buildSelectionRefQueues(orderModifiers);
709
+ const consumedModifierIds = new Set();
710
+ for (let i = 0; i < halfHalfItem.segments.length; i++) {
711
+ const segment = halfHalfItem.segments[i];
712
+ if (segment == null)
713
+ continue;
714
+ let orderModifier = consumeSelectionMatch(orderModifierQueues, segment._id, segment._id);
715
+ if (orderModifier == null) {
716
+ // Legacy pre-punched lines: stored modifier may carry only `_id` = the
717
+ // segment `_id` (no ref) — match by exact `_id` as a fallback.
718
+ orderModifier = orderModifiers.find((storedModifier) => !consumedModifierIds.has(storedModifier._id) && storedModifier._id === segment._id);
719
+ }
720
+ if (orderModifier != null)
721
+ consumedModifierIds.add(orderModifier._id);
722
+ const option = orderModifier?.options[0];
723
+ if (option == null)
724
+ continue;
725
+ selectedHalfHalfItems[i] = {
726
+ _id: option._id,
727
+ item_id: option.ref,
728
+ menu_id: orderItem.menu_id ?? null,
729
+ item_type: ORDER_ITEM_TYPE_ENUM.HALF_HALF,
730
+ name: option.name,
731
+ price: option.price,
732
+ subtotal: option.price,
733
+ tax_rate: 0,
734
+ quantity: option.quantity,
735
+ special_instructions: '',
736
+ item_discount_details: null,
737
+ modifiers: option.modifiers ?? null,
738
+ // These values will be auto calculated
739
+ _discount_amount: 0,
740
+ _gross_amount: 0,
741
+ _gst_amount: 0,
742
+ _net_amount: 0,
743
+ };
744
+ }
745
+ // Fallback: leftover stored modifiers (segments renamed/removed, or legacy
746
+ // lines without refs) go to the first empty slot, oldest first — keeps the
747
+ // selection visible. Iterates the RAW stored modifiers so empty-ref legacy
748
+ // entries (skipped by the ref queues) are still recovered.
749
+ for (const orderModifier of orderModifiers) {
750
+ if (consumedModifierIds.has(orderModifier._id))
751
+ continue;
752
+ const slotIndex = selectedHalfHalfItems.findIndex((item) => item === null);
753
+ if (slotIndex === -1)
754
+ break;
755
+ const option = orderModifier.options[0];
756
+ if (option == null)
757
+ continue;
758
+ selectedHalfHalfItems[slotIndex] = {
759
+ _id: option._id,
760
+ item_id: option.ref,
761
+ menu_id: orderItem.menu_id ?? null,
762
+ item_type: ORDER_ITEM_TYPE_ENUM.HALF_HALF,
763
+ name: option.name,
764
+ price: option.price,
765
+ subtotal: option.price,
766
+ tax_rate: 0,
767
+ quantity: option.quantity,
768
+ special_instructions: '',
769
+ item_discount_details: null,
770
+ modifiers: option.modifiers ?? null,
771
+ // These values will be auto calculated
772
+ _discount_amount: 0,
773
+ _gross_amount: 0,
774
+ _gst_amount: 0,
775
+ _net_amount: 0,
776
+ };
777
+ }
778
+ return { selectedHalfHalfItems, quantity: orderItem.quantity };
779
+ }