@managesome/eposmatic-toolkit 0.3.7 → 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 (439) 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/lib/helpers/utils/order-engine.js +6 -1
  437. package/lib/tests/soldout-option-default-guard.test.d.ts +1 -0
  438. package/lib/tests/soldout-option-default-guard.test.js +126 -0
  439. package/package.json +6 -3
@@ -0,0 +1,937 @@
1
+ import ObjectID from 'bson-objectid';
2
+ import { ORDER_TYPE_ENUM, SPLIT_BILL_TYPE_ENUM } from '../../constants';
3
+ import { convertPriceFromCents, convertPriceToCents, parseNum } from '../utils';
4
+ import { calculateCartOrderInfoAndSyncData, getCartItemsObj } from './cart-actions';
5
+ /* ======================>Order Object<====================== */
6
+ export function getOrderDeliveryDetailsWithPrice(delivery, convertToPrice) {
7
+ if (!delivery)
8
+ return null;
9
+ return {
10
+ ...delivery,
11
+ ...(delivery.rider_revenue != null ? { rider_revenue: convertToPrice(delivery.rider_revenue) } : {}),
12
+ delivery_cost: convertToPrice(delivery.delivery_cost ?? 0),
13
+ };
14
+ }
15
+ export function getOrderPaymentsCardDetailsWithPrice(card_details, convertToPrice) {
16
+ if (!card_details)
17
+ return null;
18
+ return {
19
+ ...card_details,
20
+ card_charges: convertToPrice(card_details.card_charges),
21
+ };
22
+ }
23
+ export function getOrderPaymentsWithPrice(payments, convertToPrice) {
24
+ if (!payments)
25
+ return [];
26
+ return payments.map((payment) => ({
27
+ ...payment,
28
+ card_details: getOrderPaymentsCardDetailsWithPrice(payment.card_details, convertToPrice),
29
+ amount_paid: convertToPrice(payment.amount_paid),
30
+ amount_due: convertToPrice(payment.amount_due),
31
+ amount_refunded: convertToPrice(payment.amount_refunded),
32
+ }));
33
+ }
34
+ export function getOrderItemModifierOptionsWithPrice(options, convertToPrice) {
35
+ if (!options)
36
+ return [];
37
+ return options.map((option) => ({
38
+ ...option,
39
+ price: convertToPrice(option.price ?? 0),
40
+ modifiers: getOrderItemModifiersWithPrice(option.modifiers, convertToPrice),
41
+ }));
42
+ }
43
+ export function getOrderItemModifiersWithPrice(modifiers, convertToPrice) {
44
+ if (!modifiers)
45
+ return null;
46
+ return modifiers.map((modifier) => ({
47
+ ...modifier,
48
+ options: getOrderItemModifierOptionsWithPrice(modifier.options, convertToPrice),
49
+ }));
50
+ }
51
+ export function getOrderItemsWithPrice(items, convertToPrice) {
52
+ if (!items)
53
+ return [];
54
+ return items.map((item) => ({
55
+ ...item,
56
+ quantity: parseNum(item.quantity || 1, true),
57
+ price: convertToPrice(item.price ?? 0),
58
+ subtotal: convertToPrice(item.subtotal ?? 0),
59
+ tax_rate: convertToPrice(item.tax_rate ?? 0),
60
+ _gst_amount: convertToPrice(item._gst_amount ?? 0),
61
+ _net_amount: convertToPrice(item._net_amount ?? 0),
62
+ _gross_amount: convertToPrice(item._gross_amount ?? 0),
63
+ _discount_amount: convertToPrice(item._discount_amount ?? 0),
64
+ item_discount_details: getOrderDiscountDetailsWithPrice(item.item_discount_details, convertToPrice),
65
+ modifiers: getOrderItemModifiersWithPrice(item.modifiers, convertToPrice),
66
+ }));
67
+ }
68
+ export function getOrderCategoriesWithPrice(categories, convertToPrice) {
69
+ if (!categories)
70
+ return [];
71
+ return categories.map((category) => ({
72
+ ...category,
73
+ items: getOrderItemsWithPrice(category.items, convertToPrice),
74
+ }));
75
+ }
76
+ export function getOrderDiscountDetailsWithPrice(discount, convertToPrice) {
77
+ if (!discount)
78
+ return null;
79
+ const { voucher_discount, special_discount, loyalty_discount, total_discount } = discount;
80
+ return {
81
+ ...discount,
82
+ ...(typeof voucher_discount === 'number' ? { voucher_discount: convertToPrice(voucher_discount) } : {}),
83
+ ...(typeof special_discount === 'number' ? { special_discount: convertToPrice(special_discount) } : {}),
84
+ ...(typeof loyalty_discount === 'number' ? { loyalty_discount: convertToPrice(loyalty_discount) } : {}),
85
+ total_discount: convertToPrice(total_discount ?? 0),
86
+ };
87
+ }
88
+ export function getOrderWalletRedemptionsWithPrice(walletRedemptions, convertToPrice) {
89
+ if (walletRedemptions == null)
90
+ return null;
91
+ const normalizedGiftCardRedemptions = (() => {
92
+ const giftCardRedemptions = walletRedemptions.gift_cards;
93
+ if (!Array.isArray(giftCardRedemptions))
94
+ return null;
95
+ const normalizedGiftCardRedemptionsMap = {};
96
+ for (let i = 0; i < giftCardRedemptions.length; i++) {
97
+ const giftCardRedemption = giftCardRedemptions[i];
98
+ const giftCardId = giftCardRedemption.gift_card_id?.toString().trim();
99
+ const redeemedTimes = Number(giftCardRedemption.redeemed_times);
100
+ if (giftCardId == null || giftCardId.length === 0 || !Number.isFinite(redeemedTimes) || redeemedTimes <= 0) {
101
+ continue;
102
+ }
103
+ const existingRedemption = normalizedGiftCardRedemptionsMap[giftCardId];
104
+ normalizedGiftCardRedemptionsMap[giftCardId] = {
105
+ gift_card_id: giftCardId,
106
+ redeemed_times: (existingRedemption?.redeemed_times ?? 0) + Math.floor(redeemedTimes),
107
+ ...(giftCardRedemption.mystery_gift_type != null
108
+ ? { mystery_gift_type: giftCardRedemption.mystery_gift_type }
109
+ : existingRedemption?.mystery_gift_type != null
110
+ ? { mystery_gift_type: existingRedemption.mystery_gift_type }
111
+ : {}),
112
+ };
113
+ }
114
+ const dedupedGiftCardRedemptions = Object.values(normalizedGiftCardRedemptionsMap);
115
+ return dedupedGiftCardRedemptions.length > 0 ? dedupedGiftCardRedemptions : null;
116
+ })();
117
+ return {
118
+ ...walletRedemptions,
119
+ ...(walletRedemptions.cashback_amount != null
120
+ ? { cashback_amount: convertToPrice(walletRedemptions.cashback_amount) }
121
+ : {}),
122
+ ...(normalizedGiftCardRedemptions != null ? { gift_cards: normalizedGiftCardRedemptions } : {}),
123
+ };
124
+ }
125
+ export function sortByCreatedAt(a, b) {
126
+ return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
127
+ }
128
+ export function sortByIdTimestamp(a, b) {
129
+ return ObjectID(b._id).getTimestamp().getTime() - ObjectID(a._id).getTimestamp().getTime();
130
+ }
131
+ export function getOrderWithPrice(order, toCents) {
132
+ const convertToPrice = toCents ? convertPriceToCents : convertPriceFromCents;
133
+ const payload = {
134
+ ...order,
135
+ ...(order.iterations != null
136
+ ? {
137
+ iterations: getOrderIterationsWithPrice(order.iterations, toCents),
138
+ }
139
+ : {}),
140
+ ...(order.delivery_details != null
141
+ ? {
142
+ delivery_details: getOrderDeliveryDetailsWithPrice(order.delivery_details, convertToPrice),
143
+ }
144
+ : {}),
145
+ ...(order.categories != null
146
+ ? {
147
+ categories: getOrderCategoriesWithPrice(order.categories, convertToPrice),
148
+ }
149
+ : {}),
150
+ ...(order.order_discount_details != null
151
+ ? { order_discount_details: getOrderDiscountDetailsWithPrice(order.order_discount_details, convertToPrice) }
152
+ : {}),
153
+ ...(order.total_discount_applied != null
154
+ ? { total_discount_applied: convertToPrice(order.total_discount_applied) }
155
+ : {}),
156
+ ...(order.payments != null ? { payments: getOrderPaymentsWithPrice(order.payments, convertToPrice) } : {}),
157
+ ...(order.surcharge != null ? { surcharge: convertToPrice(order.surcharge) } : {}),
158
+ ...(order.surcharge_amount != null ? { surcharge_amount: convertToPrice(order.surcharge_amount) } : {}),
159
+ ...(order.tip_amount != null ? { tip_amount: convertToPrice(order.tip_amount) } : {}),
160
+ ...(order.service_fee != null ? { service_fee: convertToPrice(order.service_fee) } : {}),
161
+ ...(order.service_fee_amount != null ? { service_fee_amount: convertToPrice(order.service_fee_amount) } : {}),
162
+ ...(order.packaging_charges != null ? { packaging_charges: convertToPrice(order.packaging_charges) } : {}),
163
+ ...(order.adjustment_amount != null ? { adjustment_amount: convertToPrice(order.adjustment_amount) } : {}),
164
+ ...(order.tax_amount != null ? { tax_amount: convertToPrice(order.tax_amount) } : {}),
165
+ ...(order.gst != null ? { gst: convertToPrice(order.gst) } : {}),
166
+ ...(order.gst_amount != null ? { gst_amount: convertToPrice(order.gst_amount) } : {}),
167
+ ...(order.tax_invoice_provider_charges != null
168
+ ? { tax_invoice_provider_charges: convertToPrice(order.tax_invoice_provider_charges) }
169
+ : {}),
170
+ ...(order.amount_collected != null
171
+ ? { amount_collected: convertToPrice(order.amount_collected) }
172
+ : {}),
173
+ ...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
174
+ ...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
175
+ ...(order.price != null ? { price: convertToPrice(order.price) } : {}),
176
+ ...(order.dinein_details != null && toCents
177
+ ? {
178
+ dinein_details: {
179
+ ...order.dinein_details,
180
+ num_of_guests: order.dinein_details.num_of_guests || 1,
181
+ },
182
+ }
183
+ : {}),
184
+ ...(order.wallet_redemptions != null
185
+ ? { wallet_redemptions: getOrderWalletRedemptionsWithPrice(order.wallet_redemptions, convertToPrice) }
186
+ : {}),
187
+ };
188
+ if (toCents) {
189
+ if (payload.source_tenant_id != null) {
190
+ payload.source_tenant_id =
191
+ payload.tenant_id != null && payload.tenant_id === payload.source_tenant_id
192
+ ? null
193
+ : payload.source_tenant_id;
194
+ }
195
+ const orderType = order.platform != null ? order.platform.split('_')[1] : null;
196
+ if (orderType != null) {
197
+ if (orderType === ORDER_TYPE_ENUM.DINE_IN) {
198
+ payload.takeaway_details = null;
199
+ payload.delivery_details = null;
200
+ }
201
+ else if (orderType === ORDER_TYPE_ENUM.TAKE_AWAY) {
202
+ payload.dinein_details = null;
203
+ payload.delivery_details = null;
204
+ }
205
+ else if (orderType === ORDER_TYPE_ENUM.DELIVERY) {
206
+ payload.dinein_details = null;
207
+ payload.takeaway_details = null;
208
+ }
209
+ else {
210
+ payload.dinein_details = null;
211
+ payload.takeaway_details = null;
212
+ payload.delivery_details = null;
213
+ }
214
+ }
215
+ }
216
+ return payload;
217
+ }
218
+ export function getOrderIterationsWithPrice(iterations, toCents) {
219
+ if (!iterations)
220
+ return [];
221
+ return iterations.map((iteration) => getOrderWithPrice(iteration, toCents));
222
+ }
223
+ // ======================>Order Object<======================
224
+ function getCommonOptionalBoolFields(order, partial) {
225
+ const defaultValue = partial ? undefined : false;
226
+ return {
227
+ is_surcharge_percentage: order['is_surcharge_percentage'] || defaultValue,
228
+ is_surcharge_taxable: order['is_surcharge_taxable'] || defaultValue,
229
+ is_service_fee_percentage: order['is_service_fee_percentage'] || defaultValue,
230
+ is_service_fee_taxable: order['is_service_fee_taxable'] || defaultValue,
231
+ exclude_discount_from_gst: order['exclude_discount_from_gst'] || defaultValue,
232
+ apply_service_fee_on_original_price: order['apply_service_fee_on_original_price'] || defaultValue,
233
+ is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
234
+ };
235
+ }
236
+ function getCommonOptionalNullFields(order, partial) {
237
+ const defaultValue = partial ? undefined : null;
238
+ return {
239
+ delivery_details: order['delivery_details'] || defaultValue,
240
+ dinein_details: order['dinein_details'] || defaultValue,
241
+ takeaway_details: order['takeaway_details'] || defaultValue,
242
+ staff_details: order['staff_details'] || defaultValue,
243
+ order_taker_details: order['order_taker_details'] || defaultValue,
244
+ order_discount_details: order['order_discount_details'] || defaultValue,
245
+ adjustment_reason: order['adjustment_reason'] || defaultValue,
246
+ };
247
+ }
248
+ function getCommonOptionalNumFields(order, partial) {
249
+ const defaultValue = partial ? undefined : 0;
250
+ return {
251
+ surcharge: order['surcharge'] || defaultValue,
252
+ surcharge_amount: order['surcharge_amount'] || defaultValue,
253
+ service_fee: order['service_fee'] || defaultValue,
254
+ service_fee_amount: order['service_fee_amount'] || defaultValue,
255
+ gst: order['gst'] || defaultValue,
256
+ gst_amount: order['gst_amount'] || defaultValue,
257
+ packaging_charges: order['packaging_charges'] || defaultValue,
258
+ adjustment_amount: order['adjustment_amount'] || defaultValue,
259
+ tax_invoice_provider_charges: order['tax_invoice_provider_charges'] || defaultValue,
260
+ total_discount_applied: order['total_discount_applied'] || defaultValue,
261
+ };
262
+ }
263
+ export function skipItemMetadataFromOrderCategories(categories, previousCategories) {
264
+ return categories.map((category) => {
265
+ const previousCategory = previousCategories?.find((prevCategory) => prevCategory.category_id === category.category_id);
266
+ return {
267
+ ...category,
268
+ items: category.items.map((item) => {
269
+ const previousItem = previousCategory?.items.find((prevItem) => prevItem._id === item._id);
270
+ const void_reason = previousItem?.void_reason ?? item.void_reason;
271
+ const newItem = {
272
+ ...item,
273
+ ...(void_reason != null ? { void_reason } : {}),
274
+ _discount_amount: 0,
275
+ _gst_amount: 0,
276
+ _gross_amount: 0,
277
+ _net_amount: 0,
278
+ };
279
+ return newItem;
280
+ }),
281
+ };
282
+ });
283
+ }
284
+ export function generateOrderIteration(order, partial = true, skipItemMetadata, previousCategories) {
285
+ const iteration = {
286
+ // optional fields
287
+ ...getCommonOptionalBoolFields(order, partial),
288
+ ...getCommonOptionalNullFields(order, partial),
289
+ ...getCommonOptionalNumFields(order, partial),
290
+ ...(skipItemMetadata && order.categories != null
291
+ ? {
292
+ categories: skipItemMetadataFromOrderCategories(order.categories, previousCategories),
293
+ }
294
+ : {
295
+ categories: order['categories'],
296
+ }),
297
+ consumer: order['consumer'],
298
+ platform: order['platform'],
299
+ tip_amount: order['tip_amount'],
300
+ special_instructions: order['special_instructions'],
301
+ payments: order['payments'],
302
+ order_status: order['order_status'],
303
+ tax_number: order['tax_number'],
304
+ tax_amount: order['tax_amount'],
305
+ price: order['price'],
306
+ amount_earned: order['amount_earned'],
307
+ grand_total: order['grand_total'],
308
+ updatedAt: order['updatedAt'],
309
+ };
310
+ if (partial) {
311
+ // delete all undefined keys
312
+ Object.keys(iteration).forEach((key) => {
313
+ if (iteration[key] === undefined) {
314
+ delete iteration[key];
315
+ }
316
+ });
317
+ }
318
+ return iteration;
319
+ }
320
+ export function getOrderWithAllFields(order, skipItemMetadata) {
321
+ return {
322
+ ...order,
323
+ ...getCommonOptionalBoolFields(order, false),
324
+ ...getCommonOptionalNullFields(order, false),
325
+ ...getCommonOptionalNumFields(order, false),
326
+ ...(skipItemMetadata && order.categories != null
327
+ ? {
328
+ categories: skipItemMetadataFromOrderCategories(order.categories),
329
+ }
330
+ : {}),
331
+ source_tenant_id: order['source_tenant_id'] ?? null,
332
+ pos_id: order['pos_id'] ?? null,
333
+ delete_reason: order['delete_reason'] ?? null,
334
+ cancel_reason: order['cancel_reason'] ?? null,
335
+ tax_invoice_id: order['tax_invoice_id'] ?? null,
336
+ rating: order['rating'] ?? null,
337
+ review: order['review'] ?? null,
338
+ is_reopened: order['is_reopened'] ?? false,
339
+ synced_offline: order['synced_offline'] ?? false,
340
+ is_unpaid: order['is_unpaid'] ?? false,
341
+ deferred_settlement: order['deferred_settlement'] ?? false,
342
+ split_parent_id: order['split_parent_id'] ?? null,
343
+ split_child_ids: order['split_child_ids'] ?? null,
344
+ split_type: order['split_type'] ?? null,
345
+ redeemed_offers: order['redeemed_offers'] ?? null,
346
+ wallet_redemptions: order['wallet_redemptions'] ?? null,
347
+ };
348
+ }
349
+ // ======================>Order Object<======================
350
+ const removePriceFromModifiers = (modifiers) => {
351
+ if (modifiers == null)
352
+ return [null, 0];
353
+ const newModifiers = [];
354
+ let omittedPrice = 0;
355
+ for (let i = 0; i < modifiers.length; i++) {
356
+ const modifier = modifiers[i];
357
+ const options = [];
358
+ for (let j = 0; j < modifier.options.length; j++) {
359
+ const option = modifier.options[j];
360
+ const [optionModifiers, optionModifiersPrice] = removePriceFromModifiers(option.modifiers);
361
+ options.push({
362
+ ...option,
363
+ modifiers: optionModifiers,
364
+ price: 0,
365
+ });
366
+ if (!option.is_free) {
367
+ omittedPrice += option.price * option.quantity;
368
+ }
369
+ omittedPrice += optionModifiersPrice;
370
+ }
371
+ newModifiers.push({
372
+ ...modifier,
373
+ options,
374
+ });
375
+ }
376
+ return [newModifiers, omittedPrice];
377
+ };
378
+ // ======================>Offline Orders<======================
379
+ export function syncOrderData(order) {
380
+ const updatedOrder = {
381
+ ...order,
382
+ iterations: [],
383
+ };
384
+ const newOrder = getOrderWithPrice(calculateCartOrderInfoAndSyncData(getOrderWithPrice(updatedOrder), undefined, undefined, true), true);
385
+ newOrder.iterations = order.iterations;
386
+ return newOrder;
387
+ }
388
+ export function getVoidItemsWithReason({ currentCategories, iterationsFromFrontend, previousCategories, platform, }) {
389
+ const voidOrderItemReasonsMap = {};
390
+ const voidOrderItemIsReadyMap = {};
391
+ const latestIterationCategories = iterationsFromFrontend?.[0]?.categories;
392
+ if (latestIterationCategories != null && latestIterationCategories.length > 0) {
393
+ for (let i = 0; i < latestIterationCategories.length; i++) {
394
+ const category = latestIterationCategories[i];
395
+ for (let j = 0; j < category.items.length; j++) {
396
+ const item = category.items[j];
397
+ if (item.void_reason != null && item.void_reason.length > 0) {
398
+ voidOrderItemReasonsMap[item._id] = item.void_reason;
399
+ }
400
+ if (item.is_ready != null) {
401
+ voidOrderItemIsReadyMap[item._id] = item.is_ready;
402
+ }
403
+ }
404
+ }
405
+ }
406
+ const { newItems, removedItems } = getCartItemsObj({
407
+ currentDineinCourses: null,
408
+ previousDineinCourses: null,
409
+ currentIterationCategories: currentCategories,
410
+ previousIterationCategories: previousCategories,
411
+ mappedItems: {},
412
+ platform,
413
+ shouldSortItemsViaId: false,
414
+ isAnEdit: true,
415
+ });
416
+ const hasNewItems = newItems.length > 0;
417
+ const voidOrderItems = [];
418
+ const newVoidOrderItemReasonsMap = {};
419
+ // A removed item with no non-empty `void_reason` in the latest frontend
420
+ // iteration falls back to the '-' placeholder on voidOrderItems below.
421
+ // Surface it so callers can reject reasonless voids before persisting.
422
+ let hasMissingVoidReason = false;
423
+ for (let i = 0; i < removedItems.length; i++) {
424
+ const { orderItem } = removedItems[i];
425
+ const voidReason = voidOrderItemReasonsMap[orderItem._id];
426
+ const isReady = voidOrderItemIsReadyMap[orderItem._id];
427
+ if (voidReason == null) {
428
+ hasMissingVoidReason = true;
429
+ }
430
+ voidOrderItems.push({
431
+ ...orderItem,
432
+ ...(isReady != null ? { is_ready: isReady } : {}),
433
+ subtotal: Math.round(orderItem.subtotal),
434
+ void_reason: voidReason ?? '-',
435
+ });
436
+ if (voidReason != null) {
437
+ newVoidOrderItemReasonsMap[orderItem._id] = voidReason;
438
+ }
439
+ }
440
+ const newIterationCategories = [];
441
+ for (let i = 0; i < previousCategories.length; i++) {
442
+ const category = previousCategories[i];
443
+ const newCategoryItems = [];
444
+ for (let j = 0; j < category.items.length; j++) {
445
+ const prevItem = category.items[j];
446
+ const voidReason = newVoidOrderItemReasonsMap[prevItem._id];
447
+ const isReady = voidOrderItemIsReadyMap[prevItem._id];
448
+ const orderItem = {
449
+ ...prevItem,
450
+ subtotal: Math.round(prevItem.subtotal),
451
+ };
452
+ if (voidReason != null) {
453
+ orderItem.void_reason = voidReason;
454
+ }
455
+ if (isReady != null) {
456
+ orderItem.is_ready = isReady;
457
+ }
458
+ newCategoryItems.push(orderItem);
459
+ }
460
+ if (newCategoryItems.length === 0)
461
+ continue;
462
+ newIterationCategories.push({
463
+ ...category,
464
+ items: newCategoryItems,
465
+ });
466
+ }
467
+ return {
468
+ newIterationCategories,
469
+ voidOrderItems,
470
+ hasNewItems,
471
+ hasMissingVoidReason,
472
+ };
473
+ }
474
+ // ======================>Split Bill<======================
475
+ function syncDineinCoursesOnSplit(dinein_details, swapedItemIdsMap, totalChecks, isLastCheck) {
476
+ if (dinein_details == null) {
477
+ return dinein_details;
478
+ }
479
+ let newCourses = null;
480
+ if (dinein_details.courses != null && dinein_details.courses.length > 0) {
481
+ newCourses = [];
482
+ for (let i = 0; i < dinein_details.courses.length; i++) {
483
+ const course = dinein_details.courses[i];
484
+ const newItemIds = [];
485
+ for (let j = 0; j < course.item_ids.length; j++) {
486
+ const itemId = course.item_ids[j];
487
+ const newItemId = swapedItemIdsMap[itemId];
488
+ if (newItemId != null)
489
+ newItemIds.push(newItemId);
490
+ }
491
+ if (newItemIds.length > 0) {
492
+ newCourses.push({
493
+ ...course,
494
+ item_ids: newItemIds,
495
+ });
496
+ }
497
+ }
498
+ }
499
+ let num_of_guests = 1;
500
+ if (isLastCheck) {
501
+ // Eg: 5 guests, 3 checks
502
+ // Check 1: 1 Guest
503
+ // Check 2: 1 Guests
504
+ // Check 3: 3 Guests
505
+ num_of_guests = dinein_details.num_of_guests - totalChecks + 1;
506
+ if (num_of_guests < 1) {
507
+ num_of_guests = 1;
508
+ }
509
+ }
510
+ const result = {
511
+ ...dinein_details,
512
+ num_of_guests,
513
+ courses: newCourses,
514
+ };
515
+ return result;
516
+ }
517
+ function splitOrderEqually({ originalOrder, totalSplits, totalChecks, isLastCheck, check, }) {
518
+ const portions = check.portions ?? 1;
519
+ const convertAmount = (amount, divideBy = totalSplits, quantity = portions) => {
520
+ let newAmount = parseNum(amount / divideBy) * quantity;
521
+ if (isLastCheck) {
522
+ // Eg: 100.00 / 3 = 33.33 * 3 = 99.99
523
+ // 100.00 - 99.99 = 0.01
524
+ // 0.01 + 99.99 = 100.00
525
+ const singleAmount = parseNum(amount / divideBy);
526
+ const diff = amount - singleAmount * divideBy;
527
+ newAmount += diff;
528
+ newAmount = Number(newAmount.toFixed(2));
529
+ }
530
+ return newAmount;
531
+ };
532
+ const getDiscountDetails = (discount) => {
533
+ if (discount == null)
534
+ return null;
535
+ const discount_details = {
536
+ ...discount,
537
+ };
538
+ if (discount_details.voucher_discount != null && !discount_details.is_voucher_discount_percentage) {
539
+ discount_details.voucher_discount = convertAmount(discount_details.voucher_discount);
540
+ }
541
+ if (discount_details.special_discount != null && !discount_details.is_special_discount_percentage) {
542
+ discount_details.special_discount = convertAmount(discount_details.special_discount);
543
+ }
544
+ if (discount_details.loyalty_discount != null && !discount_details.is_loyalty_discount_percentage) {
545
+ discount_details.loyalty_discount = convertAmount(discount_details.loyalty_discount);
546
+ }
547
+ discount_details.total_discount = convertAmount(discount_details.total_discount);
548
+ return discount_details;
549
+ };
550
+ const categories = [];
551
+ const swapedItemIdsMap = {};
552
+ for (let i = 0; i < originalOrder.categories.length; i++) {
553
+ const category = originalOrder.categories[i];
554
+ const items = [];
555
+ for (let j = 0; j < category.items.length; j++) {
556
+ const item = category.items[j];
557
+ const [modifiers, ommitedPrice] = removePriceFromModifiers(item.modifiers);
558
+ let newQuantity = convertAmount(item.quantity);
559
+ newQuantity = parseNum(Math.abs(newQuantity));
560
+ const price = item.price + ommitedPrice;
561
+ const newItem = {
562
+ ...item,
563
+ _id: ObjectID().toHexString(), // NOTE: We need to keep the original item id
564
+ modifiers,
565
+ quantity: newQuantity,
566
+ price,
567
+ is_split: true,
568
+ item_discount_details: getDiscountDetails(item.item_discount_details),
569
+ };
570
+ items.push(newItem);
571
+ swapedItemIdsMap[item._id] = newItem._id;
572
+ }
573
+ categories.push({
574
+ ...category,
575
+ items,
576
+ });
577
+ }
578
+ let newOrder = {
579
+ ...originalOrder,
580
+ _id: ObjectID().toHexString(),
581
+ iterations: [],
582
+ payments: [],
583
+ ...(originalOrder.tax_amount ? { tax_amount: convertAmount(originalOrder.tax_amount) } : {}),
584
+ ...(originalOrder.surcharge != null && !originalOrder.is_surcharge_percentage
585
+ ? { surcharge: convertAmount(originalOrder.surcharge) }
586
+ : {}),
587
+ ...(originalOrder.service_fee != null && !originalOrder.is_service_fee_percentage
588
+ ? { service_fee: convertAmount(originalOrder.service_fee) }
589
+ : {}),
590
+ ...(originalOrder.tip_amount != null ? { tip_amount: convertAmount(originalOrder.tip_amount) } : {}),
591
+ order_discount_details: getDiscountDetails(originalOrder.order_discount_details),
592
+ categories,
593
+ };
594
+ newOrder.dinein_details = syncDineinCoursesOnSplit(newOrder.dinein_details, swapedItemIdsMap, totalChecks, isLastCheck);
595
+ newOrder = calculateCartOrderInfoAndSyncData(newOrder);
596
+ return newOrder;
597
+ }
598
+ function splitOrderByItem({ originalOrder, originalItemsMap, totalChecks, remainingSplitItemsMap, check, isLastCheck, }) {
599
+ const convertAmount = (amount, originalQuantity, newQuantity) => {
600
+ const newAmount = parseNum(amount / originalQuantity) * newQuantity;
601
+ return newAmount;
602
+ };
603
+ const getDiscountDetails = (discount, originalQuantity, newQuantity) => {
604
+ if (discount == null)
605
+ return null;
606
+ const discount_details = {
607
+ ...discount,
608
+ };
609
+ if (discount_details.voucher_discount != null && !discount_details.is_voucher_discount_percentage) {
610
+ discount_details.voucher_discount = convertAmount(discount_details.voucher_discount, originalQuantity, newQuantity);
611
+ }
612
+ if (discount_details.special_discount != null && !discount_details.is_special_discount_percentage) {
613
+ discount_details.special_discount = convertAmount(discount_details.special_discount, originalQuantity, newQuantity);
614
+ }
615
+ if (discount_details.loyalty_discount != null && !discount_details.is_loyalty_discount_percentage) {
616
+ discount_details.loyalty_discount = convertAmount(discount_details.loyalty_discount, originalQuantity, newQuantity);
617
+ }
618
+ discount_details.total_discount = convertAmount(discount_details.total_discount, originalQuantity, newQuantity);
619
+ return discount_details;
620
+ };
621
+ const splitItems = check.split_items ?? [];
622
+ const splitCategoriesMap = {};
623
+ const swapedItemIdsMap = {};
624
+ for (let i = 0; i < splitItems.length; i++) {
625
+ const splitItem = splitItems[i];
626
+ const item = originalItemsMap[splitItem._id];
627
+ if (item == null)
628
+ continue;
629
+ const category_id = item.category_id;
630
+ const category_name = item.category_name;
631
+ if (splitCategoriesMap[category_id] == null) {
632
+ splitCategoriesMap[category_id] = {
633
+ category_id,
634
+ name: category_name,
635
+ items: [],
636
+ };
637
+ }
638
+ const originalItem = item.item;
639
+ const [modifiers, ommitedPrice] = removePriceFromModifiers(originalItem.modifiers);
640
+ let newQuantity = splitItem.quantity;
641
+ const uniqueId = `${check._id}-${splitItem.split_id}`;
642
+ if (remainingSplitItemsMap[splitItem._id] != null) {
643
+ const pointer = remainingSplitItemsMap[splitItem._id];
644
+ pointer.quantity -= newQuantity;
645
+ pointer.unique_ids = pointer.unique_ids.filter((id) => id !== uniqueId);
646
+ if (pointer.unique_ids.length === 0 && pointer.quantity !== 0) {
647
+ // Add remaining quantity back to the original order
648
+ newQuantity += pointer.quantity;
649
+ newQuantity = Number(newQuantity.toFixed(2));
650
+ }
651
+ }
652
+ newQuantity = parseNum(Math.abs(newQuantity));
653
+ const price = originalItem.price + ommitedPrice;
654
+ const newItem = {
655
+ ...originalItem,
656
+ _id: ObjectID().toHexString(),
657
+ modifiers,
658
+ quantity: newQuantity,
659
+ price,
660
+ is_split: true,
661
+ item_discount_details: getDiscountDetails(originalItem.item_discount_details, originalItem.quantity, newQuantity),
662
+ };
663
+ splitCategoriesMap[category_id].items.push(newItem);
664
+ swapedItemIdsMap[originalItem._id] = newItem._id;
665
+ }
666
+ const categories = Object.values(splitCategoriesMap).filter((category) => category.items.length > 0);
667
+ if (categories.length === 0) {
668
+ return null;
669
+ }
670
+ let newOrder = {
671
+ ...originalOrder,
672
+ _id: ObjectID().toHexString(),
673
+ iterations: [],
674
+ payments: [],
675
+ ...(originalOrder.tax_amount ? { tax_amount: convertAmount(originalOrder.tax_amount, totalChecks, 1) } : {}),
676
+ ...(originalOrder.surcharge != null && !originalOrder.is_surcharge_percentage
677
+ ? { surcharge: convertAmount(originalOrder.surcharge, totalChecks, 1) }
678
+ : {}),
679
+ ...(originalOrder.service_fee != null && !originalOrder.is_service_fee_percentage
680
+ ? { service_fee: convertAmount(originalOrder.service_fee, totalChecks, 1) }
681
+ : {}),
682
+ ...(originalOrder.tip_amount != null
683
+ ? { tip_amount: convertAmount(originalOrder.tip_amount, totalChecks, 1) }
684
+ : {}),
685
+ order_discount_details: getDiscountDetails(originalOrder.order_discount_details, totalChecks, 1),
686
+ categories,
687
+ };
688
+ newOrder.dinein_details = syncDineinCoursesOnSplit(newOrder.dinein_details, swapedItemIdsMap, totalChecks, isLastCheck);
689
+ newOrder = calculateCartOrderInfoAndSyncData(newOrder);
690
+ return newOrder;
691
+ }
692
+ function splitOrderByTenant({ originalOrder, originalItemsMap, tenantItems, totalChecks, check, isLastCheck, }) {
693
+ const checkTenantId = check.tenant_id;
694
+ if (!checkTenantId)
695
+ return null;
696
+ const originalTenantId = originalOrder.tenant_id;
697
+ const convertAmount = (amount, divideBy, quantity = 1) => {
698
+ let newAmount = parseNum(amount / divideBy) * quantity;
699
+ if (isLastCheck) {
700
+ const singleAmount = parseNum(amount / divideBy);
701
+ const diff = amount - singleAmount * divideBy;
702
+ newAmount += diff;
703
+ newAmount = Number(newAmount.toFixed(2));
704
+ }
705
+ return newAmount;
706
+ };
707
+ const getDiscountDetails = (discount) => {
708
+ if (discount == null)
709
+ return null;
710
+ const discount_details = {
711
+ ...discount,
712
+ };
713
+ if (discount_details.voucher_discount != null && !discount_details.is_voucher_discount_percentage) {
714
+ discount_details.voucher_discount = convertAmount(discount_details.voucher_discount, totalChecks);
715
+ }
716
+ if (discount_details.special_discount != null && !discount_details.is_special_discount_percentage) {
717
+ discount_details.special_discount = convertAmount(discount_details.special_discount, totalChecks);
718
+ }
719
+ if (discount_details.loyalty_discount != null && !discount_details.is_loyalty_discount_percentage) {
720
+ discount_details.loyalty_discount = convertAmount(discount_details.loyalty_discount, totalChecks);
721
+ }
722
+ discount_details.total_discount = convertAmount(discount_details.total_discount, totalChecks);
723
+ return discount_details;
724
+ };
725
+ const splitCategoriesMap = {};
726
+ const includedItemIds = {};
727
+ // Iterate over all items and filter by tenant
728
+ for (const itemId in originalItemsMap) {
729
+ const itemData = originalItemsMap[itemId];
730
+ const originalItem = itemData.item;
731
+ // Determine which tenant this item belongs to
732
+ const itemTenantId = tenantItems?.[originalItem.item_id] ?? originalTenantId;
733
+ // Skip if item doesn't belong to this check's tenant
734
+ if (itemTenantId !== checkTenantId)
735
+ continue;
736
+ const category_id = itemData.category_id;
737
+ const category_name = itemData.category_name;
738
+ if (splitCategoriesMap[category_id] == null) {
739
+ splitCategoriesMap[category_id] = {
740
+ category_id,
741
+ name: category_name,
742
+ items: [],
743
+ };
744
+ }
745
+ const [modifiers, ommitedPrice] = removePriceFromModifiers(originalItem.modifiers);
746
+ const price = originalItem.price + ommitedPrice;
747
+ const newItem = {
748
+ ...originalItem,
749
+ modifiers,
750
+ price,
751
+ is_split: true,
752
+ };
753
+ splitCategoriesMap[category_id].items.push(newItem);
754
+ includedItemIds[originalItem._id] = originalItem._id;
755
+ }
756
+ const categories = Object.values(splitCategoriesMap).filter((category) => category.items.length > 0);
757
+ if (categories.length === 0) {
758
+ return null;
759
+ }
760
+ let newOrder = {
761
+ ...originalOrder,
762
+ _id: ObjectID().toHexString(),
763
+ tenant_id: checkTenantId,
764
+ iterations: [],
765
+ payments: [],
766
+ ...(originalOrder.tax_amount ? { tax_amount: convertAmount(originalOrder.tax_amount, totalChecks) } : {}),
767
+ ...(originalOrder.surcharge != null && !originalOrder.is_surcharge_percentage
768
+ ? { surcharge: convertAmount(originalOrder.surcharge, totalChecks) }
769
+ : {}),
770
+ ...(originalOrder.service_fee != null && !originalOrder.is_service_fee_percentage
771
+ ? { service_fee: convertAmount(originalOrder.service_fee, totalChecks) }
772
+ : {}),
773
+ ...(originalOrder.tip_amount != null ? { tip_amount: convertAmount(originalOrder.tip_amount, totalChecks) } : {}),
774
+ order_discount_details: getDiscountDetails(originalOrder.order_discount_details),
775
+ categories,
776
+ };
777
+ newOrder.dinein_details = syncDineinCoursesOnSplit(newOrder.dinein_details, includedItemIds, totalChecks, isLastCheck);
778
+ newOrder = calculateCartOrderInfoAndSyncData(newOrder);
779
+ return newOrder;
780
+ }
781
+ // ======================>Split Bill<======================
782
+ export function getSplitOrdersFromOrder(order, splitBill) {
783
+ let isSplitValid = true;
784
+ const splitType = splitBill.split_type;
785
+ let totalSplits = splitBill.checks.length;
786
+ if (splitType === SPLIT_BILL_TYPE_ENUM.EQUAL) {
787
+ totalSplits = 0;
788
+ for (let i = 0; i < splitBill.checks.length; i++) {
789
+ const check = splitBill.checks[i];
790
+ if (check.portions == null || check.portions < 1) {
791
+ isSplitValid = false;
792
+ break;
793
+ }
794
+ totalSplits += check.portions;
795
+ }
796
+ }
797
+ else if (splitType === SPLIT_BILL_TYPE_ENUM.ITEM) {
798
+ for (let i = 0; i < splitBill.checks.length; i++) {
799
+ const check = splitBill.checks[i];
800
+ if (check.split_items == null || check.split_items.length === 0) {
801
+ isSplitValid = false;
802
+ break;
803
+ }
804
+ }
805
+ }
806
+ else if (splitType === SPLIT_BILL_TYPE_ENUM.AMOUNT) {
807
+ for (let i = 0; i < splitBill.checks.length; i++) {
808
+ const check = splitBill.checks[i];
809
+ if (check.split_amount == null || check.split_amount <= 0) {
810
+ isSplitValid = false;
811
+ break;
812
+ }
813
+ }
814
+ }
815
+ else if (splitType === SPLIT_BILL_TYPE_ENUM.SEAT) {
816
+ for (let i = 0; i < splitBill.checks.length; i++) {
817
+ const check = splitBill.checks[i];
818
+ if (check.seat_number == null || check.seat_number <= 0) {
819
+ isSplitValid = false;
820
+ break;
821
+ }
822
+ }
823
+ }
824
+ else if (splitType === SPLIT_BILL_TYPE_ENUM.TENANT) {
825
+ for (let i = 0; i < splitBill.checks.length; i++) {
826
+ const check = splitBill.checks[i];
827
+ if (check.tenant_id == null || check.tenant_id.length === 0) {
828
+ isSplitValid = false;
829
+ break;
830
+ }
831
+ }
832
+ }
833
+ else {
834
+ isSplitValid = false;
835
+ }
836
+ if (!isSplitValid)
837
+ return [];
838
+ const originalOrder = { ...order, split_type: splitType };
839
+ const totalChecks = splitBill.checks.length;
840
+ const newOrders = [];
841
+ if (splitType === SPLIT_BILL_TYPE_ENUM.EQUAL) {
842
+ for (let i = 0; i < totalChecks; i++) {
843
+ const check = splitBill.checks[i];
844
+ const isLastCheck = i === totalChecks - 1;
845
+ const splitOrder = splitOrderEqually({
846
+ originalOrder,
847
+ totalSplits,
848
+ totalChecks,
849
+ isLastCheck,
850
+ check,
851
+ });
852
+ newOrders.push(splitOrder);
853
+ }
854
+ }
855
+ else if (splitType === SPLIT_BILL_TYPE_ENUM.ITEM) {
856
+ const originalItemsMap = {};
857
+ for (let i = 0; i < originalOrder.categories.length; i++) {
858
+ const category = originalOrder.categories[i];
859
+ for (let i = 0; i < category.items.length; i++) {
860
+ const item = category.items[i];
861
+ originalItemsMap[item._id] = {
862
+ category_id: category.category_id,
863
+ category_name: category.name,
864
+ item,
865
+ };
866
+ }
867
+ }
868
+ const remainingSplitItemsMap = {};
869
+ for (let i = 0; i < splitBill.checks.length; i++) {
870
+ const check = splitBill.checks[i];
871
+ const splitItems = check.split_items ?? [];
872
+ for (let j = 0; j < splitItems.length; j++) {
873
+ const splitItem = splitItems[j];
874
+ const originalItem = originalItemsMap[splitItem._id];
875
+ if (originalItem == null)
876
+ continue;
877
+ const uniqueId = `${check._id}-${splitItem.split_id}`;
878
+ if (remainingSplitItemsMap[splitItem._id] == null) {
879
+ remainingSplitItemsMap[splitItem._id] = {
880
+ unique_ids: [uniqueId],
881
+ quantity: originalItem.item.quantity,
882
+ };
883
+ }
884
+ else {
885
+ remainingSplitItemsMap[splitItem._id].unique_ids.push(uniqueId);
886
+ }
887
+ }
888
+ }
889
+ for (let i = 0; i < totalChecks; i++) {
890
+ const check = splitBill.checks[i];
891
+ const isLastCheck = i === totalChecks - 1;
892
+ const splitOrder = splitOrderByItem({
893
+ originalOrder,
894
+ originalItemsMap,
895
+ remainingSplitItemsMap,
896
+ totalChecks,
897
+ check,
898
+ isLastCheck,
899
+ });
900
+ if (splitOrder != null) {
901
+ newOrders.push(splitOrder);
902
+ }
903
+ }
904
+ }
905
+ else if (splitType === SPLIT_BILL_TYPE_ENUM.TENANT) {
906
+ // Build items map from original order
907
+ const originalItemsMap = {};
908
+ for (let i = 0; i < originalOrder.categories.length; i++) {
909
+ const category = originalOrder.categories[i];
910
+ for (let j = 0; j < category.items.length; j++) {
911
+ const item = category.items[j];
912
+ originalItemsMap[item._id] = {
913
+ category_id: category.category_id,
914
+ category_name: category.name,
915
+ item,
916
+ };
917
+ }
918
+ }
919
+ const tenantItems = splitBill.tenant_items;
920
+ for (let i = 0; i < totalChecks; i++) {
921
+ const check = splitBill.checks[i];
922
+ const isLastCheck = i === totalChecks - 1;
923
+ const splitOrder = splitOrderByTenant({
924
+ originalOrder,
925
+ originalItemsMap,
926
+ tenantItems,
927
+ totalChecks,
928
+ check,
929
+ isLastCheck,
930
+ });
931
+ if (splitOrder != null) {
932
+ newOrders.push(splitOrder);
933
+ }
934
+ }
935
+ }
936
+ return newOrders;
937
+ }