@managesome/eposmatic-toolkit 0.3.8 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (437) 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/types/api-types.d.ts +37 -0
  437. package/package.json +6 -3
@@ -0,0 +1,613 @@
1
+ import { GIFT_CARD_REWARD_TYPE_ENUM, OFFER_REWARD_TYPE_ENUM, PATHWAY_TO_UNLOCK_TYPE_ENUM, WALLET_CASHBACK_LOYALTY_DISCOUNT_ID, WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME, WALLET_CASHBACK_LOYALTY_REFERENCE, } from '../../constants';
2
+ import { calculateCartOrderInfoAndSyncData } from '../store/cart-actions';
3
+ import { calculateEligibleOfferDiscountDetails, getCappedOfferDiscountAmount, parseNum } from './common';
4
+ // ================================><================================= //
5
+ // === Shared order subtotal for discount logic === //
6
+ // ================================><================================= //
7
+ function getOrderSubtotalFromCategories(categories) {
8
+ if (!categories?.length)
9
+ return 0;
10
+ let subtotal = 0;
11
+ for (let i = 0; i < categories.length; i++) {
12
+ const items = categories[i].items;
13
+ for (let j = 0; j < items.length; j++) {
14
+ subtotal += items[j].subtotal ?? 0;
15
+ }
16
+ }
17
+ return subtotal;
18
+ }
19
+ function isWalletCashbackLoyaltyDiscount(orderDiscountDetails) {
20
+ return orderDiscountDetails?.loyalty_discount_id === WALLET_CASHBACK_LOYALTY_DISCOUNT_ID;
21
+ }
22
+ function getWalletCashbackAmountFromOrderData({ orderDiscountDetails, walletRedemptions, }) {
23
+ if (!isWalletCashbackLoyaltyDiscount(orderDiscountDetails)) {
24
+ return 0;
25
+ }
26
+ const loyaltyDiscountAmount = Number(orderDiscountDetails?.loyalty_discount ?? 0);
27
+ if (Number.isFinite(loyaltyDiscountAmount) && loyaltyDiscountAmount > 0) {
28
+ return parseNum(loyaltyDiscountAmount);
29
+ }
30
+ const walletCashbackAmount = Number(walletRedemptions?.cashback_amount ?? 0);
31
+ if (Number.isFinite(walletCashbackAmount) && walletCashbackAmount > 0) {
32
+ return parseNum(walletCashbackAmount);
33
+ }
34
+ return 0;
35
+ }
36
+ function getSyncedWalletCashbackOrderDiscountDetails({ orderDiscountDetails, walletCashbackAmount, }) {
37
+ if (orderDiscountDetails == null) {
38
+ return orderDiscountDetails;
39
+ }
40
+ if (walletCashbackAmount <= 0) {
41
+ return {
42
+ ...orderDiscountDetails,
43
+ loyalty_discount_id: undefined,
44
+ loyalty_discount_name: undefined,
45
+ loyalty_discount: undefined,
46
+ is_loyalty_discount_percentage: false,
47
+ loyalty_reference_number: undefined,
48
+ total_discount: 0,
49
+ };
50
+ }
51
+ return {
52
+ ...orderDiscountDetails,
53
+ loyalty_discount_id: WALLET_CASHBACK_LOYALTY_DISCOUNT_ID,
54
+ loyalty_discount_name: WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME,
55
+ loyalty_discount: parseNum(walletCashbackAmount),
56
+ is_loyalty_discount_percentage: false,
57
+ loyalty_reference_number: WALLET_CASHBACK_LOYALTY_REFERENCE,
58
+ };
59
+ }
60
+ // ================================><================================= //
61
+ // === buildOfferDiscountUpdate === //
62
+ // ================================><================================= //
63
+ export function buildOfferDiscountUpdate({ offer, orderDiscountDetails, categories, }) {
64
+ if (offer.reward_discount == null) {
65
+ return {
66
+ success: false,
67
+ discountDetails: null,
68
+ errorMessage: null,
69
+ redeemedOfferId: null,
70
+ };
71
+ }
72
+ const discountSlot = offer.pathway_to_unlock_type !== PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER ? 'loyalty' : 'voucher';
73
+ // Already-applied guard
74
+ if (orderDiscountDetails != null &&
75
+ (discountSlot === 'loyalty' ? orderDiscountDetails.loyalty_discount_id : orderDiscountDetails.voucher_discount_id)) {
76
+ return {
77
+ success: false,
78
+ discountDetails: null,
79
+ errorMessage: 'You already have an offer applied to your order.',
80
+ redeemedOfferId: null,
81
+ };
82
+ }
83
+ let { discount_value, is_discount_percentage } = offer.reward_discount;
84
+ const { max_discount_amount, max_discount_percentage, excluded_refs } = offer.reward_discount;
85
+ const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
86
+ // Handle excluded_refs
87
+ if (excluded_refs != null && excluded_refs.length > 0) {
88
+ const { subtotal: eligibleSubtotal, hasExcludedRefs } = calculateEligibleOfferDiscountDetails(categories, excluded_refs);
89
+ if (hasExcludedRefs) {
90
+ if (!is_discount_percentage) {
91
+ return { success: false, discountDetails: null, errorMessage: null };
92
+ }
93
+ if (eligibleSubtotal <= 0) {
94
+ return { success: false, discountDetails: null, errorMessage: null };
95
+ }
96
+ discount_value = parseNum(getCappedOfferDiscountAmount({
97
+ baseAmount: eligibleSubtotal,
98
+ discountValue: discount_value,
99
+ isDiscountPercentage: is_discount_percentage,
100
+ maxDiscountAmount: max_discount_amount,
101
+ maxDiscountPercentage: max_discount_percentage,
102
+ }));
103
+ is_discount_percentage = false;
104
+ }
105
+ }
106
+ // Cap handling for non-excluded cases
107
+ const hasRelevantCap = is_discount_percentage &&
108
+ max_discount_amount != null &&
109
+ Number.isFinite(max_discount_amount) &&
110
+ max_discount_amount >= 0;
111
+ const hasRelevantPercentageCap = !is_discount_percentage &&
112
+ max_discount_percentage != null &&
113
+ Number.isFinite(max_discount_percentage) &&
114
+ max_discount_percentage >= 0;
115
+ if (hasRelevantCap || hasRelevantPercentageCap) {
116
+ discount_value = parseNum(getCappedOfferDiscountAmount({
117
+ baseAmount: orderLevelDiscountBaseAmount,
118
+ discountValue: discount_value,
119
+ isDiscountPercentage: is_discount_percentage,
120
+ maxDiscountAmount: max_discount_amount,
121
+ maxDiscountPercentage: max_discount_percentage,
122
+ }));
123
+ is_discount_percentage = false;
124
+ }
125
+ const discountDetails = {
126
+ ...orderDiscountDetails,
127
+ ...(discountSlot === 'loyalty'
128
+ ? {
129
+ loyalty_discount_id: offer._id,
130
+ loyalty_discount_name: offer.name,
131
+ loyalty_discount: discount_value,
132
+ is_loyalty_discount_percentage: is_discount_percentage,
133
+ loyalty_reference_number: undefined,
134
+ }
135
+ : {
136
+ voucher_discount_id: offer._id,
137
+ voucher_discount_name: offer.name,
138
+ voucher_discount: discount_value,
139
+ is_voucher_discount_percentage: is_discount_percentage,
140
+ }),
141
+ total_discount: 0,
142
+ };
143
+ return {
144
+ success: true,
145
+ discountDetails,
146
+ errorMessage: null,
147
+ redeemedOfferId: null,
148
+ };
149
+ }
150
+ // ================================><================================= //
151
+ // === buildOfferPointsUpdate === //
152
+ // ================================><================================= //
153
+ export function buildOfferPointsUpdate({ offer, orderDiscountDetails, }) {
154
+ if (offer.reward_points == null) {
155
+ return {
156
+ success: false,
157
+ discountDetails: null,
158
+ errorMessage: null,
159
+ redeemedOfferId: null,
160
+ };
161
+ }
162
+ const discountDetails = orderDiscountDetails ?? null;
163
+ return {
164
+ success: true,
165
+ discountDetails,
166
+ errorMessage: null,
167
+ redeemedOfferId: offer._id,
168
+ };
169
+ }
170
+ // ================================><================================= //
171
+ // === buildOfferCashbackUpdate === //
172
+ // ================================><================================= //
173
+ export function buildOfferCashbackUpdate({ offer, orderDiscountDetails, categories, }) {
174
+ if (offer.reward_cashback == null) {
175
+ return {
176
+ success: false,
177
+ discountDetails: null,
178
+ errorMessage: null,
179
+ redeemedOfferId: null,
180
+ };
181
+ }
182
+ // Validate excluded_refs
183
+ const excluded_refs = offer.reward_cashback.excluded_refs ?? [];
184
+ if (excluded_refs.length > 0) {
185
+ const { subtotal: eligibleSubtotal } = calculateEligibleOfferDiscountDetails(categories, excluded_refs);
186
+ if (eligibleSubtotal <= 0) {
187
+ return {
188
+ success: false,
189
+ discountDetails: null,
190
+ errorMessage: null,
191
+ redeemedOfferId: null,
192
+ };
193
+ }
194
+ }
195
+ const discountDetails = orderDiscountDetails ?? null;
196
+ return {
197
+ success: true,
198
+ discountDetails,
199
+ errorMessage: null,
200
+ redeemedOfferId: offer._id,
201
+ };
202
+ }
203
+ // ================================><================================= //
204
+ // === buildOfferRewardUpdate === //
205
+ // === (for GIFT_CARDS and VOUCHER reward types — post-order) === //
206
+ // ================================><================================= //
207
+ export function buildOfferRewardUpdate({ offer, orderDiscountDetails, }) {
208
+ const isGiftCardReward = offer.reward_type === OFFER_REWARD_TYPE_ENUM.GIFT_CARDS;
209
+ const isVoucherReward = offer.reward_type === OFFER_REWARD_TYPE_ENUM.VOUCHER;
210
+ // This helper is intentionally for deferred rewards only.
211
+ // It records redeemed-offer intent while leaving active discount/wallet state unchanged.
212
+ if (!isGiftCardReward && !isVoucherReward) {
213
+ return {
214
+ success: false,
215
+ discountDetails: null,
216
+ errorMessage: 'Offer reward helper supports only GIFT_CARDS and VOUCHER rewards.',
217
+ redeemedOfferId: null,
218
+ };
219
+ }
220
+ if (isGiftCardReward && offer.reward_gift_cards == null) {
221
+ return {
222
+ success: false,
223
+ discountDetails: null,
224
+ errorMessage: 'Gift-card reward data is not available right now.',
225
+ redeemedOfferId: null,
226
+ };
227
+ }
228
+ if (isVoucherReward && offer.reward_voucher == null) {
229
+ return {
230
+ success: false,
231
+ discountDetails: null,
232
+ errorMessage: 'Voucher reward data is not available right now.',
233
+ redeemedOfferId: null,
234
+ };
235
+ }
236
+ const discountDetails = orderDiscountDetails ?? null;
237
+ return {
238
+ success: true,
239
+ discountDetails,
240
+ errorMessage: null,
241
+ redeemedOfferId: offer._id,
242
+ };
243
+ }
244
+ // ================================><================================= //
245
+ // === buildGiftCardDiscountUpdate === //
246
+ // ================================><================================= //
247
+ export function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categories, }) {
248
+ const rewardType = giftCard.reward_type;
249
+ if (rewardType === GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT) {
250
+ // Already-applied guard for loyalty-slot-based rewards.
251
+ if (orderDiscountDetails != null && orderDiscountDetails.loyalty_discount_id) {
252
+ return {
253
+ success: false,
254
+ discountDetails: null,
255
+ errorMessage: 'You already have a loyalty reward discount applied.',
256
+ };
257
+ }
258
+ const reward = giftCard.reward_discount;
259
+ if (!reward)
260
+ return { success: false, discountDetails: null, errorMessage: null };
261
+ const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage } = reward;
262
+ const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
263
+ const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
264
+ ? calculateEligibleOfferDiscountDetails(categories, excluded_refs)
265
+ : { subtotal: orderLevelDiscountBaseAmount, hasExcludedRefs: false };
266
+ const hasRelevantCap = is_discount_percentage &&
267
+ max_discount_amount != null &&
268
+ Number.isFinite(max_discount_amount) &&
269
+ max_discount_amount >= 0;
270
+ const hasRelevantPercentageCap = !is_discount_percentage &&
271
+ max_discount_percentage != null &&
272
+ Number.isFinite(max_discount_percentage) &&
273
+ max_discount_percentage >= 0;
274
+ const shouldNormalizeToStatic = hasExcludedRefs || hasRelevantCap || hasRelevantPercentageCap;
275
+ const discountBaseAmount = hasExcludedRefs ? eligibleSubtotal : orderLevelDiscountBaseAmount;
276
+ if (shouldNormalizeToStatic && discountBaseAmount <= 0) {
277
+ return {
278
+ success: false,
279
+ discountDetails: null,
280
+ errorMessage: 'Gift card is not applicable to current cart items.',
281
+ };
282
+ }
283
+ const resolvedDiscount = shouldNormalizeToStatic
284
+ ? parseNum(getCappedOfferDiscountAmount({
285
+ baseAmount: discountBaseAmount,
286
+ discountValue: discount_value,
287
+ isDiscountPercentage: is_discount_percentage,
288
+ maxDiscountAmount: max_discount_amount,
289
+ maxDiscountPercentage: max_discount_percentage,
290
+ }))
291
+ : discount_value;
292
+ const discountDetails = {
293
+ ...orderDiscountDetails,
294
+ loyalty_discount_id: giftCard._id,
295
+ loyalty_discount_name: giftCard.name,
296
+ loyalty_discount: resolvedDiscount,
297
+ is_loyalty_discount_percentage: shouldNormalizeToStatic ? false : is_discount_percentage,
298
+ loyalty_reference_number: giftCard.code.trim().toUpperCase(),
299
+ total_discount: 0,
300
+ };
301
+ return { success: true, discountDetails, errorMessage: null };
302
+ }
303
+ // Cashback rewards are post-order wallet credits and must not consume a discount slot.
304
+ if (rewardType === GIFT_CARD_REWARD_TYPE_ENUM.CASHBACK) {
305
+ if (giftCard.reward_cashback == null) {
306
+ return {
307
+ success: false,
308
+ discountDetails: null,
309
+ errorMessage: null,
310
+ };
311
+ }
312
+ const excluded_refs = giftCard.reward_cashback.excluded_refs ?? [];
313
+ if (excluded_refs.length > 0) {
314
+ const { subtotal: eligibleSubtotal } = calculateEligibleOfferDiscountDetails(categories, excluded_refs);
315
+ if (eligibleSubtotal <= 0) {
316
+ return {
317
+ success: false,
318
+ discountDetails: null,
319
+ errorMessage: 'Gift card is not applicable to current cart items.',
320
+ };
321
+ }
322
+ }
323
+ return {
324
+ success: true,
325
+ discountDetails: orderDiscountDetails ?? null,
326
+ errorMessage: null,
327
+ };
328
+ }
329
+ const hasValidRewardPayload = (rewardType === GIFT_CARD_REWARD_TYPE_ENUM.POINTS && giftCard.reward_points != null) ||
330
+ (rewardType === GIFT_CARD_REWARD_TYPE_ENUM.VOUCHER && giftCard.reward_voucher != null) ||
331
+ (rewardType === GIFT_CARD_REWARD_TYPE_ENUM.ITEMS && giftCard.reward_items != null) ||
332
+ (rewardType === GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT_ITEMS && giftCard.reward_discount_items != null) ||
333
+ (rewardType === GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT && giftCard.reward_mystery_gift != null);
334
+ if (!hasValidRewardPayload) {
335
+ return {
336
+ success: false,
337
+ discountDetails: null,
338
+ errorMessage: 'Gift card reward data is not available right now.',
339
+ };
340
+ }
341
+ // POINTS, VOUCHER, ITEMS, DISCOUNT_ITEMS, MYSTERY_GIFT are post-order rewards.
342
+ return {
343
+ success: true,
344
+ discountDetails: orderDiscountDetails ?? null,
345
+ errorMessage: null,
346
+ };
347
+ }
348
+ // ================================><================================= //
349
+ // === buildVoucherDiscountUpdate === //
350
+ // ================================><================================= //
351
+ export function buildVoucherDiscountUpdate({ code, orderDiscountDetails, }) {
352
+ return {
353
+ ...orderDiscountDetails,
354
+ voucher_reference_number: code.trim().toUpperCase(),
355
+ total_discount: 0,
356
+ };
357
+ }
358
+ // ===============================>Cart Actions<================================= //
359
+ function getNormalizedOfferId(offerId) {
360
+ if (offerId == null)
361
+ return null;
362
+ const normalizedOfferId = offerId.toString().trim();
363
+ return normalizedOfferId.length > 0 ? normalizedOfferId : null;
364
+ }
365
+ function toPositiveInteger(value, fallback = 0) {
366
+ const parsedValue = Number(value);
367
+ if (!Number.isFinite(parsedValue) || parsedValue <= 0) {
368
+ return fallback;
369
+ }
370
+ return Math.floor(parsedValue);
371
+ }
372
+ function getNormalizedRedeemedOffersMap(redeemedOffers) {
373
+ if (redeemedOffers == null)
374
+ return null;
375
+ const normalizedRedeemedOffers = {};
376
+ const offerIds = Object.keys(redeemedOffers);
377
+ for (let i = 0; i < offerIds.length; i++) {
378
+ const offerId = offerIds[i];
379
+ const normalizedOfferId = getNormalizedOfferId(offerId);
380
+ if (normalizedOfferId == null)
381
+ continue;
382
+ const safeCount = toPositiveInteger(redeemedOffers[offerId], 0);
383
+ if (safeCount <= 0)
384
+ continue;
385
+ normalizedRedeemedOffers[normalizedOfferId] = safeCount;
386
+ }
387
+ return Object.keys(normalizedRedeemedOffers).length > 0 ? normalizedRedeemedOffers : null;
388
+ }
389
+ function isRedeemedOffersMapNormalized(redeemedOffers) {
390
+ if (redeemedOffers == null) {
391
+ return true;
392
+ }
393
+ const normalizedRedeemedOffers = getNormalizedRedeemedOffersMap(redeemedOffers);
394
+ const rawOfferIds = Object.keys(redeemedOffers);
395
+ const normalizedOfferIds = Object.keys(normalizedRedeemedOffers ?? {});
396
+ if (rawOfferIds.length !== normalizedOfferIds.length) {
397
+ return false;
398
+ }
399
+ for (let i = 0; i < rawOfferIds.length; i++) {
400
+ const rawOfferId = rawOfferIds[i];
401
+ const normalizedOfferId = getNormalizedOfferId(rawOfferId);
402
+ const safeCount = toPositiveInteger(redeemedOffers[rawOfferId], 0);
403
+ if (normalizedOfferId == null || rawOfferId !== normalizedOfferId || safeCount <= 0) {
404
+ return false;
405
+ }
406
+ if ((normalizedRedeemedOffers?.[normalizedOfferId] ?? 0) !== safeCount) {
407
+ return false;
408
+ }
409
+ }
410
+ return true;
411
+ }
412
+ function areRedeemedOffersEqual(currentRedeemedOffers, nextRedeemedOffers) {
413
+ const normalizedCurrentRedeemedOffers = getNormalizedRedeemedOffersMap(currentRedeemedOffers);
414
+ const normalizedNextRedeemedOffers = getNormalizedRedeemedOffersMap(nextRedeemedOffers);
415
+ if (normalizedCurrentRedeemedOffers == null || normalizedNextRedeemedOffers == null) {
416
+ return normalizedCurrentRedeemedOffers == null && normalizedNextRedeemedOffers == null;
417
+ }
418
+ const currentOfferIds = Object.keys(normalizedCurrentRedeemedOffers);
419
+ const nextOfferIds = Object.keys(normalizedNextRedeemedOffers);
420
+ if (currentOfferIds.length !== nextOfferIds.length) {
421
+ return false;
422
+ }
423
+ for (let i = 0; i < currentOfferIds.length; i++) {
424
+ const offerId = currentOfferIds[i];
425
+ if (normalizedCurrentRedeemedOffers[offerId] !== normalizedNextRedeemedOffers[offerId]) {
426
+ return false;
427
+ }
428
+ }
429
+ return true;
430
+ }
431
+ function getItemRewardApplicableQuantity(offer) {
432
+ if (offer.reward_type === OFFER_REWARD_TYPE_ENUM.ITEMS) {
433
+ return toPositiveInteger(offer.reward_items?.num_of_items, 1);
434
+ }
435
+ if (offer.reward_type === OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
436
+ return toPositiveInteger(offer.reward_discount_items?.num_of_items, 1);
437
+ }
438
+ return null;
439
+ }
440
+ function getTotalSelectedOfferItemsAgainstOffer(categories, offerId) {
441
+ let totalSelectedOfferItems = 0;
442
+ for (let i = 0; i < categories.length; i++) {
443
+ const category = categories[i];
444
+ for (let j = 0; j < category.items.length; j++) {
445
+ const item = category.items[j];
446
+ const discountDetails = item.item_discount_details;
447
+ if (discountDetails == null)
448
+ continue;
449
+ const loyaltyDiscountId = getNormalizedOfferId(discountDetails.loyalty_discount_id);
450
+ const voucherDiscountId = getNormalizedOfferId(discountDetails.voucher_discount_id);
451
+ if (loyaltyDiscountId !== offerId && voucherDiscountId !== offerId)
452
+ continue;
453
+ totalSelectedOfferItems += toPositiveInteger(item.quantity, 0);
454
+ }
455
+ }
456
+ return totalSelectedOfferItems;
457
+ }
458
+ function getReconciledRedeemedOffersMap({ existingRedeemedOffers, categories, offers, removedOfferIds, unlockedOffersApplicableTimes, }) {
459
+ const nextRedeemedOffers = {
460
+ ...(getNormalizedRedeemedOffersMap(existingRedeemedOffers) ?? {}),
461
+ };
462
+ const removedIds = Array.from(removedOfferIds);
463
+ for (let i = 0; i < removedIds.length; i++) {
464
+ const normalizedOfferId = getNormalizedOfferId(removedIds[i]);
465
+ if (normalizedOfferId == null)
466
+ continue;
467
+ delete nextRedeemedOffers[normalizedOfferId];
468
+ }
469
+ for (let i = 0; i < offers.length; i++) {
470
+ const offer = offers[i];
471
+ const normalizedOfferId = getNormalizedOfferId(offer._id);
472
+ if (normalizedOfferId == null)
473
+ continue;
474
+ const applicableQuantity = getItemRewardApplicableQuantity(offer);
475
+ if (applicableQuantity != null) {
476
+ const selectedItemsCount = getTotalSelectedOfferItemsAgainstOffer(categories, normalizedOfferId);
477
+ // Percentage strategy: any partial usage of an item reward counts as a redeemed slot.
478
+ const redeemedTimes = selectedItemsCount > 0 ? Math.ceil(selectedItemsCount / applicableQuantity) : 0;
479
+ if (redeemedTimes > 0) {
480
+ nextRedeemedOffers[normalizedOfferId] = redeemedTimes;
481
+ }
482
+ else {
483
+ delete nextRedeemedOffers[normalizedOfferId];
484
+ }
485
+ continue;
486
+ }
487
+ const existingRedeemedTimes = toPositiveInteger(nextRedeemedOffers[normalizedOfferId], 0);
488
+ if (existingRedeemedTimes <= 0) {
489
+ delete nextRedeemedOffers[normalizedOfferId];
490
+ continue;
491
+ }
492
+ const hasUnlockContext = unlockedOffersApplicableTimes != null;
493
+ const maxApplicableTimes = toPositiveInteger(unlockedOffersApplicableTimes?.[offer._id], 0);
494
+ if (maxApplicableTimes <= 0) {
495
+ if (!hasUnlockContext) {
496
+ nextRedeemedOffers[normalizedOfferId] = existingRedeemedTimes;
497
+ continue;
498
+ }
499
+ delete nextRedeemedOffers[normalizedOfferId];
500
+ continue;
501
+ }
502
+ nextRedeemedOffers[normalizedOfferId] = Math.min(existingRedeemedTimes, maxApplicableTimes);
503
+ }
504
+ return getNormalizedRedeemedOffersMap(nextRedeemedOffers);
505
+ }
506
+ function getRedeemedOffersMap(existingRedeemedOffers) {
507
+ return getNormalizedRedeemedOffersMap(existingRedeemedOffers);
508
+ }
509
+ function getNormalizedWalletRedemptionsMap(walletRedemptions) {
510
+ if (walletRedemptions == null)
511
+ return null;
512
+ const normalized = {};
513
+ const cashbackAmount = Number(walletRedemptions.cashback_amount);
514
+ if (Number.isFinite(cashbackAmount) && cashbackAmount > 0) {
515
+ normalized.cashback_amount = cashbackAmount;
516
+ }
517
+ const rawGiftCardRedemptions = walletRedemptions.gift_cards;
518
+ const giftCardRedemptions = rawGiftCardRedemptions == null
519
+ ? []
520
+ : Array.isArray(rawGiftCardRedemptions)
521
+ ? rawGiftCardRedemptions
522
+ : [rawGiftCardRedemptions];
523
+ if (giftCardRedemptions.length > 0) {
524
+ const normalizedGiftCardRedemptionsMap = {};
525
+ for (let i = 0; i < giftCardRedemptions.length; i++) {
526
+ const giftCardRedemption = giftCardRedemptions[i];
527
+ const giftCardId = giftCardRedemption.gift_card_id?.toString().trim();
528
+ const legacyValueRedeemed = giftCardRedemption.value_redeemed;
529
+ const redeemedTimes = toPositiveInteger(giftCardRedemption.redeemed_times ?? legacyValueRedeemed, 0);
530
+ if (giftCardId == null || giftCardId.length === 0 || redeemedTimes <= 0) {
531
+ continue;
532
+ }
533
+ const existingRedemption = normalizedGiftCardRedemptionsMap[giftCardId];
534
+ normalizedGiftCardRedemptionsMap[giftCardId] = {
535
+ gift_card_id: giftCardId,
536
+ redeemed_times: (existingRedemption?.redeemed_times ?? 0) + redeemedTimes,
537
+ ...(giftCardRedemption.mystery_gift_type != null
538
+ ? { mystery_gift_type: giftCardRedemption.mystery_gift_type }
539
+ : existingRedemption?.mystery_gift_type != null
540
+ ? { mystery_gift_type: existingRedemption.mystery_gift_type }
541
+ : {}),
542
+ };
543
+ }
544
+ const normalizedGiftCardRedemptions = Object.values(normalizedGiftCardRedemptionsMap);
545
+ if (normalizedGiftCardRedemptions.length > 0) {
546
+ normalized.gift_cards = normalizedGiftCardRedemptions;
547
+ }
548
+ }
549
+ return Object.keys(normalized).length > 0 ? normalized : null;
550
+ }
551
+ function getWalletRedemptionsMap(existingWalletRedemptions) {
552
+ return getNormalizedWalletRedemptionsMap(existingWalletRedemptions);
553
+ }
554
+ export function getSyncOffersWithCartData(data, courses, listnerSettings, unlockedOffersApplicableTimes, // Record<offer_id, times can be applied>
555
+ offers) {
556
+ const syncedOrderData = calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, undefined, {
557
+ unlockedOffersApplicableTimes,
558
+ offers,
559
+ });
560
+ const removedOfferIds = new Set();
561
+ const currentOrderDiscountDetails = data.order_discount_details;
562
+ const syncedOrderDiscountDetails = syncedOrderData.order_discount_details;
563
+ const currentLoyaltyDiscountId = getNormalizedOfferId(currentOrderDiscountDetails?.loyalty_discount_id);
564
+ const syncedLoyaltyDiscountId = getNormalizedOfferId(syncedOrderDiscountDetails?.loyalty_discount_id);
565
+ if (currentLoyaltyDiscountId != null && currentLoyaltyDiscountId !== syncedLoyaltyDiscountId) {
566
+ removedOfferIds.add(currentLoyaltyDiscountId);
567
+ }
568
+ const currentVoucherDiscountId = getNormalizedOfferId(currentOrderDiscountDetails?.voucher_discount_id);
569
+ const syncedVoucherDiscountId = getNormalizedOfferId(syncedOrderDiscountDetails?.voucher_discount_id);
570
+ if (currentVoucherDiscountId != null && currentVoucherDiscountId !== syncedVoucherDiscountId) {
571
+ removedOfferIds.add(currentVoucherDiscountId);
572
+ }
573
+ const syncedCategories = syncedOrderData.categories ?? [];
574
+ const hasCartItems = syncedCategories.some((category) => category.items.length > 0);
575
+ const nextRedeemedOffers = hasCartItems
576
+ ? getReconciledRedeemedOffersMap({
577
+ existingRedeemedOffers: data.redeemed_offers,
578
+ categories: syncedCategories,
579
+ offers,
580
+ removedOfferIds,
581
+ unlockedOffersApplicableTimes,
582
+ })
583
+ : null;
584
+ const normalizedSyncedWalletRedemptions = getWalletRedemptionsMap(syncedOrderData.wallet_redemptions);
585
+ const normalizedCurrentWalletRedemptions = getWalletRedemptionsMap(data.wallet_redemptions);
586
+ const shouldSyncWalletCashbackDiscount = isWalletCashbackLoyaltyDiscount(syncedOrderDiscountDetails) ||
587
+ isWalletCashbackLoyaltyDiscount(currentOrderDiscountDetails);
588
+ const nextWalletRedemptions = getWalletRedemptionsMap({
589
+ ...(normalizedCurrentWalletRedemptions ?? {}),
590
+ ...(normalizedSyncedWalletRedemptions ?? {}),
591
+ cashback_amount: shouldSyncWalletCashbackDiscount
592
+ ? (normalizedSyncedWalletRedemptions?.cashback_amount ?? normalizedCurrentWalletRedemptions?.cashback_amount)
593
+ : undefined,
594
+ gift_cards: hasCartItems
595
+ ? (normalizedSyncedWalletRedemptions?.gift_cards ?? normalizedCurrentWalletRedemptions?.gift_cards)
596
+ : undefined,
597
+ });
598
+ const nextOrderDiscountDetails = shouldSyncWalletCashbackDiscount
599
+ ? getSyncedWalletCashbackOrderDiscountDetails({
600
+ orderDiscountDetails: syncedOrderDiscountDetails ?? currentOrderDiscountDetails,
601
+ walletCashbackAmount: getWalletCashbackAmountFromOrderData({
602
+ orderDiscountDetails: syncedOrderDiscountDetails ?? currentOrderDiscountDetails,
603
+ walletRedemptions: nextWalletRedemptions,
604
+ }),
605
+ })
606
+ : syncedOrderDiscountDetails;
607
+ return {
608
+ ...syncedOrderData,
609
+ order_discount_details: nextOrderDiscountDetails,
610
+ redeemed_offers: nextRedeemedOffers,
611
+ wallet_redemptions: nextWalletRedemptions,
612
+ };
613
+ }