@managesome/eposmatic-toolkit 0.3.8 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/esm/constants/ANALYTICS.js +146 -0
  2. package/esm/constants/API_ERRORS.js +6 -0
  3. package/esm/constants/COMMON.js +369 -0
  4. package/esm/constants/DELIVERY.js +45 -0
  5. package/esm/constants/DIALER_ENUMS.js +11 -0
  6. package/esm/constants/ENUMS.js +1988 -0
  7. package/esm/constants/FBR_ENUMS.js +18 -0
  8. package/esm/constants/HUBRISE_ENUMS.js +179 -0
  9. package/esm/constants/INTERNAL_ENUMS.js +49 -0
  10. package/esm/constants/NOTIFICATIONS.js +6 -0
  11. package/esm/constants/ORDER.js +251 -0
  12. package/esm/constants/PRA_ENUMS.js +18 -0
  13. package/esm/constants/REPORT_WEBVIEW.js +28 -0
  14. package/esm/constants/RFQ_GO.js +83 -0
  15. package/esm/constants/SMARTPAY_ENUMS.js +55 -0
  16. package/esm/constants/SOCKET.js +149 -0
  17. package/esm/constants/SRB_ENUMS.js +13 -0
  18. package/esm/constants/SWITCHPAY.js +28 -0
  19. package/esm/constants/TENANT_ENUMS.js +90 -0
  20. package/esm/constants/TENANT_PURCHASE_ORDER.js +91 -0
  21. package/esm/constants/WALLET.js +51 -0
  22. package/esm/constants/WAREHOUSE_ANALYTICS.js +28 -0
  23. package/esm/constants/WAREHOUSE_ENUMS.js +420 -0
  24. package/esm/constants/WAREHOUSE_PURCHASE_ORDER.js +97 -0
  25. package/esm/constants/WEBVIEW.js +43 -0
  26. package/esm/constants/WORKER_ENDPOINTS.js +79 -0
  27. package/esm/constants/index.js +27 -0
  28. package/esm/constants/types.js +2 -0
  29. package/esm/helpers/fbr/generate-invoice.js +94 -0
  30. package/esm/helpers/fbr/index.js +1 -0
  31. package/esm/helpers/hubrise/hubrise-catalog.js +304 -0
  32. package/esm/helpers/hubrise/index.js +1 -0
  33. package/esm/helpers/index.js +9 -0
  34. package/esm/helpers/kpra/generate-invoice.js +26 -0
  35. package/esm/helpers/kpra/index.js +1 -0
  36. package/esm/helpers/order/generate-order.js +508 -0
  37. package/esm/helpers/order/generate-warehouse-internal-movement.js +71 -0
  38. package/esm/helpers/order/generate-warehouse-purchase-order-rfq.js +176 -0
  39. package/esm/helpers/order/generate-warehouse-purchase-order.js +187 -0
  40. package/esm/helpers/order/generate-warehouse-sale-order-rfq.js +176 -0
  41. package/esm/helpers/order/generate-warehouse-sale-order.js +149 -0
  42. package/esm/helpers/order/index.js +6 -0
  43. package/esm/helpers/pra/generate-invoice.js +94 -0
  44. package/esm/helpers/pra/index.js +1 -0
  45. package/esm/helpers/srb/generate-invoice.js +68 -0
  46. package/esm/helpers/srb/index.js +1 -0
  47. package/esm/helpers/store/all-orders-actions.js +17 -0
  48. package/esm/helpers/store/all-tenant-purchase-orders-actions.js +45 -0
  49. package/esm/helpers/store/all-warehouse-purchase-order-rfqs-actions.js +66 -0
  50. package/esm/helpers/store/all-warehouse-purchase-order-vendor-return-actions.js +50 -0
  51. package/esm/helpers/store/all-warehouse-purchase-orders-actions.js +49 -0
  52. package/esm/helpers/store/all-warehouse-sale-order-invoices-actions.js +132 -0
  53. package/esm/helpers/store/all-warehouse-sale-order-rfqs-actions.js +66 -0
  54. package/esm/helpers/store/all-warehouse-sale-orders-actions.js +72 -0
  55. package/esm/helpers/store/cart-actions.js +3563 -0
  56. package/esm/helpers/store/catalog-actions.js +379 -0
  57. package/esm/helpers/store/common-order-actions.js +937 -0
  58. package/esm/helpers/store/common-tenant-purchase-order-actions.js +440 -0
  59. package/esm/helpers/store/common-warehouse-internal-movement-actions.js +95 -0
  60. package/esm/helpers/store/common-warehouse-purchase-order-actions.js +530 -0
  61. package/esm/helpers/store/common-warehouse-purchase-order-receipt-actions.js +33 -0
  62. package/esm/helpers/store/common-warehouse-purchase-order-rfq-actions.js +523 -0
  63. package/esm/helpers/store/common-warehouse-purchase-order-vendor-return-actions.js +25 -0
  64. package/esm/helpers/store/common-warehouse-sale-order-actions.js +483 -0
  65. package/esm/helpers/store/common-warehouse-sale-order-invoice-actions.js +54 -0
  66. package/esm/helpers/store/common-warehouse-sale-order-rfq-actions.js +523 -0
  67. package/esm/helpers/store/index.js +26 -0
  68. package/esm/helpers/store/offline-ordering.js +251 -0
  69. package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +379 -0
  70. package/esm/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +360 -0
  71. package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +470 -0
  72. package/esm/helpers/store/warehouse-sale-order-rfq-cart-actions.js +359 -0
  73. package/esm/helpers/store/warehouse-sale-orders-cart-actions.js +456 -0
  74. package/esm/helpers/types/api-types.js +1 -0
  75. package/esm/helpers/types/cart-actions.js +1 -0
  76. package/esm/helpers/types/cart-helpers.js +1 -0
  77. package/esm/helpers/types/catalog.js +1 -0
  78. package/esm/helpers/types/common.js +1 -0
  79. package/esm/helpers/types/deliverect_menu.js +1 -0
  80. package/esm/helpers/types/email-templates.js +1 -0
  81. package/esm/helpers/types/fbr-generate-invoice.js +1 -0
  82. package/esm/helpers/types/halfhalf.js +1 -0
  83. package/esm/helpers/types/hubrise_catalog.js +1 -0
  84. package/esm/helpers/types/hubrise_customers.js +1 -0
  85. package/esm/helpers/types/hubrise_deliveries.js +1 -0
  86. package/esm/helpers/types/hubrise_location.js +1 -0
  87. package/esm/helpers/types/hubrise_orders.js +1 -0
  88. package/esm/helpers/types/index.js +33 -0
  89. package/esm/helpers/types/internal-leads.js +1 -0
  90. package/esm/helpers/types/inventory-catalog.js +1 -0
  91. package/esm/helpers/types/kpra-generate-invoice.js +1 -0
  92. package/esm/helpers/types/marketing.js +1 -0
  93. package/esm/helpers/types/order-engine.js +1 -0
  94. package/esm/helpers/types/pra-generate-invoice.js +1 -0
  95. package/esm/helpers/types/report-webview.js +1 -0
  96. package/esm/helpers/types/reports.js +1 -0
  97. package/esm/helpers/types/smartpay-apis.js +2 -0
  98. package/esm/helpers/types/specials.js +1 -0
  99. package/esm/helpers/types/split_bill.js +1 -0
  100. package/esm/helpers/types/srb-generate-invoice.js +1 -0
  101. package/esm/helpers/types/switchpay.js +1 -0
  102. package/esm/helpers/types/tenant-purchase-order-cart-actions.js +1 -0
  103. package/esm/helpers/types/warehouse-catalog.js +1 -0
  104. package/esm/helpers/types/warehouse-purchase-order-cart-actions.js +1 -0
  105. package/esm/helpers/types/warehouse-purchase-order-rfq-cart-actions.js +1 -0
  106. package/esm/helpers/types/warehouse-sale-order-cart-actions.js +1 -0
  107. package/esm/helpers/types/warehouse-sale-order-rfq-cart-actions.js +1 -0
  108. package/esm/helpers/types/workers.js +1 -0
  109. package/esm/helpers/utils/asaanbill-identifier-helpers.js +31 -0
  110. package/esm/helpers/utils/business-day-helpers.js +201 -0
  111. package/esm/helpers/utils/cart-helpers.js +156 -0
  112. package/esm/helpers/utils/catalog-conversion.js +129 -0
  113. package/esm/helpers/utils/code-redemption-helpers.js +452 -0
  114. package/esm/helpers/utils/color-helpers.js +31 -0
  115. package/esm/helpers/utils/common.js +368 -0
  116. package/esm/helpers/utils/crypt.js +40 -0
  117. package/esm/helpers/utils/customers-helpers.js +15 -0
  118. package/esm/helpers/utils/delivery-area-helpers.js +42 -0
  119. package/esm/helpers/utils/delivery-helpers.js +87 -0
  120. package/esm/helpers/utils/denominations-helpers.js +53 -0
  121. package/esm/helpers/utils/dinein.js +39 -0
  122. package/esm/helpers/utils/discount-helpers.js +55 -0
  123. package/esm/helpers/utils/email-helpers.js +111 -0
  124. package/esm/helpers/utils/error-helpers.js +14 -0
  125. package/esm/helpers/utils/expense.js +26 -0
  126. package/esm/helpers/utils/getFormFieldsDiff.js +15 -0
  127. package/esm/helpers/utils/gift-card-helpers.js +258 -0
  128. package/esm/helpers/utils/halfhalf-setup-helpers.js +779 -0
  129. package/esm/helpers/utils/hourly-comparison-report-helpers.js +851 -0
  130. package/esm/helpers/utils/hr-helpers.js +62 -0
  131. package/esm/helpers/utils/hubrise-utils.js +32 -0
  132. package/esm/helpers/utils/image-helpers.js +95 -0
  133. package/esm/helpers/utils/image-url-helpers.js +96 -0
  134. package/esm/helpers/utils/index.js +96 -0
  135. package/esm/helpers/utils/ingredients.js +26 -0
  136. package/esm/helpers/utils/internal-amount-helpers.js +49 -0
  137. package/esm/helpers/utils/inventory.js +123 -0
  138. package/esm/helpers/utils/inventory_entries.js +91 -0
  139. package/esm/helpers/utils/inventory_transactions.js +91 -0
  140. package/esm/helpers/utils/item-report-helpers.js +2603 -0
  141. package/esm/helpers/utils/items-comparison-report-helpers.js +1057 -0
  142. package/esm/helpers/utils/kds-helpers.js +43 -0
  143. package/esm/helpers/utils/location-helpers.js +13 -0
  144. package/esm/helpers/utils/menu-helpers.js +44 -0
  145. package/esm/helpers/utils/minified-catalog.js +428 -0
  146. package/esm/helpers/utils/offer-apply-helpers.js +613 -0
  147. package/esm/helpers/utils/offers-helpers.js +3351 -0
  148. package/esm/helpers/utils/operational-roles-helpers.js +33 -0
  149. package/esm/helpers/utils/order-engine.js +1409 -0
  150. package/esm/helpers/utils/order-history.js +208 -0
  151. package/esm/helpers/utils/payment-comparison-report-helpers.js +873 -0
  152. package/esm/helpers/utils/payment-helpers.js +302 -0
  153. package/esm/helpers/utils/pdf-generator.js +110 -0
  154. package/esm/helpers/utils/platform-catalog.js +306 -0
  155. package/esm/helpers/utils/platform-num.js +188 -0
  156. package/esm/helpers/utils/platform-specific-tenant-shifts.js +19 -0
  157. package/esm/helpers/utils/price-conversion.js +24 -0
  158. package/esm/helpers/utils/printer-helpers.js +319 -0
  159. package/esm/helpers/utils/public-holidays-helpers.js +8 -0
  160. package/esm/helpers/utils/ratings-comparison-report-helpers.js +1187 -0
  161. package/esm/helpers/utils/receipt-engine.js +1050 -0
  162. package/esm/helpers/utils/review-helpers.js +391 -0
  163. package/esm/helpers/utils/rider-tracking.js +12 -0
  164. package/esm/helpers/utils/riders-report-helpers.js +1590 -0
  165. package/esm/helpers/utils/sales-comparison-report-helpers.js +1259 -0
  166. package/esm/helpers/utils/sales-comparitive-report-helpers.js +939 -0
  167. package/esm/helpers/utils/sales-overview-report-helpers.js +1046 -0
  168. package/esm/helpers/utils/sales-summary-report-helpers.js +877 -0
  169. package/esm/helpers/utils/scan-code-helpers.js +31 -0
  170. package/esm/helpers/utils/selection-model.js +68 -0
  171. package/esm/helpers/utils/shift-window-helpers.js +148 -0
  172. package/esm/helpers/utils/simplified-catalog.js +107 -0
  173. package/esm/helpers/utils/simplified-halfhalf.js +101 -0
  174. package/esm/helpers/utils/simplified-specials.js +107 -0
  175. package/esm/helpers/utils/simplified-tenant.js +411 -0
  176. package/esm/helpers/utils/specials-helpers.js +727 -0
  177. package/esm/helpers/utils/tenant-calendar-helpers.js +67 -0
  178. package/esm/helpers/utils/tenant-cash-drawer-sessions-helpers.js +248 -0
  179. package/esm/helpers/utils/tenant-cash-drawers-helpers.js +31 -0
  180. package/esm/helpers/utils/tenant-cash-in-out-helpers.js +47 -0
  181. package/esm/helpers/utils/tenant-day-sessions-helpers.js +167 -0
  182. package/esm/helpers/utils/tenant-instore-shift-sessions-helpers.js +227 -0
  183. package/esm/helpers/utils/tenant-staff-helpers.js +19 -0
  184. package/esm/helpers/utils/tenant_cash_in_hand_transactions.js +31 -0
  185. package/esm/helpers/utils/time-helpers.js +142 -0
  186. package/esm/helpers/utils/void-items-report-helpers.js +529 -0
  187. package/esm/helpers/utils/void-order-items-helpers.js +32 -0
  188. package/esm/helpers/utils/voidations-summary-report-helpers.js +800 -0
  189. package/esm/helpers/utils/wallet-helpers.js +22 -0
  190. package/esm/helpers/utils/wallet-redemption-helpers.js +46 -0
  191. package/esm/helpers/utils/warehouse-catalog-conversion.js +117 -0
  192. package/esm/helpers/utils/warehouse-inventory.js +59 -0
  193. package/esm/helpers/utils/warehouse-purchase-order-engine.js +27 -0
  194. package/esm/helpers/utils/warehouse-purchase-order-receipt-engine.js +205 -0
  195. package/esm/helpers/utils/warehouse-purchase-order-x-report-helpers.js +1432 -0
  196. package/esm/helpers/utils/warehouse-sale-order-engine.js +27 -0
  197. package/esm/helpers/utils/warehouse-sale-order-receipt-engine.js +207 -0
  198. package/esm/helpers/utils/warehouse-sale-order-x-report-helpers.js +1 -0
  199. package/esm/helpers/utils/warehouse-sale-x-report-helpers.js +1434 -0
  200. package/esm/helpers/utils/warehouse-settings-helpers.js +37 -0
  201. package/esm/helpers/utils/warehouse-void-purchase-order-items-helpers.js +34 -0
  202. package/esm/helpers/utils/warehouse-void-purchase-order-items-report-helpers.js +18 -0
  203. package/esm/helpers/utils/warehouse-void-sale-order-items-helpers.js +34 -0
  204. package/esm/helpers/utils/warehouse-void-sale-order-items-report-helpers.js +18 -0
  205. package/esm/helpers/utils/warehouse_inventory_transactions.js +91 -0
  206. package/esm/helpers/utils/x-report-helpers.js +1850 -0
  207. package/esm/index.js +3 -0
  208. package/esm/schemas/index.js +2 -0
  209. package/esm/schemas/models/app_configs.js +36 -0
  210. package/esm/schemas/models/applied_order_discounts.js +103 -0
  211. package/esm/schemas/models/brands.js +56 -0
  212. package/esm/schemas/models/categories.js +74 -0
  213. package/esm/schemas/models/close_dates.js +63 -0
  214. package/esm/schemas/models/common-models.js +449 -0
  215. package/esm/schemas/models/courses.js +62 -0
  216. package/esm/schemas/models/customer_redemptions.js +82 -0
  217. package/esm/schemas/models/customers.js +269 -0
  218. package/esm/schemas/models/deliveries.js +137 -0
  219. package/esm/schemas/models/delivery_areas.js +97 -0
  220. package/esm/schemas/models/dinein_floors.js +55 -0
  221. package/esm/schemas/models/dinein_tables.js +97 -0
  222. package/esm/schemas/models/dinein_tables_fingerprints.js +96 -0
  223. package/esm/schemas/models/discounts.js +87 -0
  224. package/esm/schemas/models/expense_categories.js +61 -0
  225. package/esm/schemas/models/expense_details.js +130 -0
  226. package/esm/schemas/models/gift_cards.js +342 -0
  227. package/esm/schemas/models/halfhalf_setup.js +142 -0
  228. package/esm/schemas/models/index.js +111 -0
  229. package/esm/schemas/models/internal_customers.js +139 -0
  230. package/esm/schemas/models/internal_invoices.js +119 -0
  231. package/esm/schemas/models/internal_leads.js +78 -0
  232. package/esm/schemas/models/internal_operational_roles.js +85 -0
  233. package/esm/schemas/models/internal_staffs.js +65 -0
  234. package/esm/schemas/models/inventories.js +103 -0
  235. package/esm/schemas/models/inventory_categories.js +52 -0
  236. package/esm/schemas/models/inventory_transactions.js +143 -0
  237. package/esm/schemas/models/item_transactions.js +117 -0
  238. package/esm/schemas/models/items.js +341 -0
  239. package/esm/schemas/models/marketing_fingerprints.js +92 -0
  240. package/esm/schemas/models/menus.js +66 -0
  241. package/esm/schemas/models/messaging_devices.js +99 -0
  242. package/esm/schemas/models/modifier_extras.js +120 -0
  243. package/esm/schemas/models/offers.js +470 -0
  244. package/esm/schemas/models/offers_fingerprints.js +61 -0
  245. package/esm/schemas/models/operational_roles.js +155 -0
  246. package/esm/schemas/models/orders.js +1051 -0
  247. package/esm/schemas/models/printer_settings.js +245 -0
  248. package/esm/schemas/models/public_holidays.js +58 -0
  249. package/esm/schemas/models/reservations.js +127 -0
  250. package/esm/schemas/models/reviews.js +145 -0
  251. package/esm/schemas/models/rewards_usage.js +61 -0
  252. package/esm/schemas/models/riders.js +75 -0
  253. package/esm/schemas/models/specials.js +169 -0
  254. package/esm/schemas/models/staff_shifts.js +66 -0
  255. package/esm/schemas/models/tenant-activity-logs.js +126 -0
  256. package/esm/schemas/models/tenant_active_jobs.js +77 -0
  257. package/esm/schemas/models/tenant_calendar.js +89 -0
  258. package/esm/schemas/models/tenant_cash_drawer_sessions.js +208 -0
  259. package/esm/schemas/models/tenant_cash_drawers.js +60 -0
  260. package/esm/schemas/models/tenant_cash_in_hand_transactions.js +69 -0
  261. package/esm/schemas/models/tenant_cash_in_out.js +104 -0
  262. package/esm/schemas/models/tenant_clients.js +66 -0
  263. package/esm/schemas/models/tenant_day_sessions.js +166 -0
  264. package/esm/schemas/models/tenant_hr_attendance_records.js +87 -0
  265. package/esm/schemas/models/tenant_hr_biometric_enrollments.js +69 -0
  266. package/esm/schemas/models/tenant_hr_departments.js +42 -0
  267. package/esm/schemas/models/tenant_hr_documents.js +71 -0
  268. package/esm/schemas/models/tenant_hr_employees.js +172 -0
  269. package/esm/schemas/models/tenant_hr_leave_requests.js +80 -0
  270. package/esm/schemas/models/tenant_hr_payrolls.js +131 -0
  271. package/esm/schemas/models/tenant_hr_performance_reviews.js +58 -0
  272. package/esm/schemas/models/tenant_hr_policies.js +57 -0
  273. package/esm/schemas/models/tenant_hr_positions.js +48 -0
  274. package/esm/schemas/models/tenant_hr_shift_schedules.js +84 -0
  275. package/esm/schemas/models/tenant_hr_shifts.js +64 -0
  276. package/esm/schemas/models/tenant_instore_shift_sessions.js +204 -0
  277. package/esm/schemas/models/tenant_instore_shifts.js +63 -0
  278. package/esm/schemas/models/tenant_inventory_department_transactions.js +116 -0
  279. package/esm/schemas/models/tenant_inventory_department_utilities.js +85 -0
  280. package/esm/schemas/models/tenant_inventory_departments.js +55 -0
  281. package/esm/schemas/models/tenant_inventory_entries.js +131 -0
  282. package/esm/schemas/models/tenant_metadata.js +88 -0
  283. package/esm/schemas/models/tenant_order_item_instructions.js +66 -0
  284. package/esm/schemas/models/tenant_purchase_order_vendor_returns.js +80 -0
  285. package/esm/schemas/models/tenant_purchase_orders.js +158 -0
  286. package/esm/schemas/models/tenant_shifts.js +57 -0
  287. package/esm/schemas/models/tenant_staffs.js +129 -0
  288. package/esm/schemas/models/tenant_vendors.js +99 -0
  289. package/esm/schemas/models/tenants.js +811 -0
  290. package/esm/schemas/models/terminal_devices.js +63 -0
  291. package/esm/schemas/models/tokens.js +73 -0
  292. package/esm/schemas/models/track_order_numbers.js +42 -0
  293. package/esm/schemas/models/void_order_items.js +210 -0
  294. package/esm/schemas/models/vouchers.js +101 -0
  295. package/esm/schemas/models/wallet_transactions.js +128 -0
  296. package/esm/schemas/models/wallets.js +44 -0
  297. package/esm/schemas/models/warehouse-activity-logs.js +144 -0
  298. package/esm/schemas/models/warehouse_categories.js +83 -0
  299. package/esm/schemas/models/warehouse_clients.js +81 -0
  300. package/esm/schemas/models/warehouse_communications.js +226 -0
  301. package/esm/schemas/models/warehouse_internal_movements.js +463 -0
  302. package/esm/schemas/models/warehouse_inventory_entries.js +125 -0
  303. package/esm/schemas/models/warehouse_inventory_lot_serial_numbers.js +188 -0
  304. package/esm/schemas/models/warehouse_inventory_transactions.js +133 -0
  305. package/esm/schemas/models/warehouse_item_transactions.js +97 -0
  306. package/esm/schemas/models/warehouse_items.js +173 -0
  307. package/esm/schemas/models/warehouse_operational_roles.js +87 -0
  308. package/esm/schemas/models/warehouse_purchase_order_receipts.js +163 -0
  309. package/esm/schemas/models/warehouse_purchase_order_rfqs.js +339 -0
  310. package/esm/schemas/models/warehouse_purchase_order_vendor_returns.js +199 -0
  311. package/esm/schemas/models/warehouse_purchase_orders.js +334 -0
  312. package/esm/schemas/models/warehouse_sale_deliveries.js +155 -0
  313. package/esm/schemas/models/warehouse_sale_invoices.js +229 -0
  314. package/esm/schemas/models/warehouse_sale_order_rfqs.js +340 -0
  315. package/esm/schemas/models/warehouse_sale_orders.js +322 -0
  316. package/esm/schemas/models/warehouse_staffs.js +104 -0
  317. package/esm/schemas/models/warehouse_track_order_numbers.js +73 -0
  318. package/esm/schemas/models/warehouse_vendors.js +99 -0
  319. package/esm/schemas/models/warehouse_void_purchase_order_items.js +174 -0
  320. package/esm/schemas/models/warehouse_void_sale_order_items.js +174 -0
  321. package/esm/schemas/models/warehouses.js +253 -0
  322. package/esm/schemas/types/app_configs.js +1 -0
  323. package/esm/schemas/types/applied_order_discounts.js +1 -0
  324. package/esm/schemas/types/brands.js +1 -0
  325. package/esm/schemas/types/categories.js +1 -0
  326. package/esm/schemas/types/close_dates.js +1 -0
  327. package/esm/schemas/types/common.js +1 -0
  328. package/esm/schemas/types/courses.js +1 -0
  329. package/esm/schemas/types/customer_redemptions.js +1 -0
  330. package/esm/schemas/types/customers.js +1 -0
  331. package/esm/schemas/types/deliveries.js +1 -0
  332. package/esm/schemas/types/delivery_areas.js +1 -0
  333. package/esm/schemas/types/dinein_floors.js +1 -0
  334. package/esm/schemas/types/dinein_tables.js +1 -0
  335. package/esm/schemas/types/dinein_tables_fingerprints.js +1 -0
  336. package/esm/schemas/types/discounts.js +1 -0
  337. package/esm/schemas/types/expense_categories.js +1 -0
  338. package/esm/schemas/types/expense_details.js +1 -0
  339. package/esm/schemas/types/gift_cards.js +1 -0
  340. package/esm/schemas/types/halfhalf_setup.js +1 -0
  341. package/esm/schemas/types/index.js +113 -0
  342. package/esm/schemas/types/internal_customers.js +1 -0
  343. package/esm/schemas/types/internal_invoices.js +1 -0
  344. package/esm/schemas/types/internal_leads.js +1 -0
  345. package/esm/schemas/types/internal_operational_roles.js +16 -0
  346. package/esm/schemas/types/internal_staffs.js +1 -0
  347. package/esm/schemas/types/inventories.js +1 -0
  348. package/esm/schemas/types/inventory_categories.js +1 -0
  349. package/esm/schemas/types/inventory_department_transactions.js +1 -0
  350. package/esm/schemas/types/inventory_department_utilities.js +1 -0
  351. package/esm/schemas/types/inventory_departments.js +1 -0
  352. package/esm/schemas/types/inventory_transactions.js +1 -0
  353. package/esm/schemas/types/item_transactions.js +1 -0
  354. package/esm/schemas/types/items.js +1 -0
  355. package/esm/schemas/types/marketing_fingerprints.js +1 -0
  356. package/esm/schemas/types/menus.js +1 -0
  357. package/esm/schemas/types/messaging_devices.js +1 -0
  358. package/esm/schemas/types/modifier_extras.js +1 -0
  359. package/esm/schemas/types/multi_tenants.js +1 -0
  360. package/esm/schemas/types/offers.js +1 -0
  361. package/esm/schemas/types/offers_fingerprints.js +1 -0
  362. package/esm/schemas/types/operational_roles.js +15 -0
  363. package/esm/schemas/types/orders.js +1 -0
  364. package/esm/schemas/types/printer_settings.js +1 -0
  365. package/esm/schemas/types/public_holidays.js +1 -0
  366. package/esm/schemas/types/reservations.js +1 -0
  367. package/esm/schemas/types/reviews.js +1 -0
  368. package/esm/schemas/types/rewards_usage.js +1 -0
  369. package/esm/schemas/types/riders.js +1 -0
  370. package/esm/schemas/types/specials.js +1 -0
  371. package/esm/schemas/types/staff_shifts.js +1 -0
  372. package/esm/schemas/types/tenant-activity-logs.js +1 -0
  373. package/esm/schemas/types/tenant_active_jobs.js +1 -0
  374. package/esm/schemas/types/tenant_calendar.js +1 -0
  375. package/esm/schemas/types/tenant_cash_drawer_sessions.js +1 -0
  376. package/esm/schemas/types/tenant_cash_drawers.js +1 -0
  377. package/esm/schemas/types/tenant_cash_in_hand_transactions.js +1 -0
  378. package/esm/schemas/types/tenant_cash_in_out.js +1 -0
  379. package/esm/schemas/types/tenant_clients.js +1 -0
  380. package/esm/schemas/types/tenant_day_sessions.js +1 -0
  381. package/esm/schemas/types/tenant_hr_attendance_records.js +1 -0
  382. package/esm/schemas/types/tenant_hr_biometric_enrollments.js +1 -0
  383. package/esm/schemas/types/tenant_hr_departments.js +1 -0
  384. package/esm/schemas/types/tenant_hr_documents.js +1 -0
  385. package/esm/schemas/types/tenant_hr_employees.js +1 -0
  386. package/esm/schemas/types/tenant_hr_leave_requests.js +1 -0
  387. package/esm/schemas/types/tenant_hr_payrolls.js +1 -0
  388. package/esm/schemas/types/tenant_hr_performance_reviews.js +1 -0
  389. package/esm/schemas/types/tenant_hr_policies.js +1 -0
  390. package/esm/schemas/types/tenant_hr_positions.js +1 -0
  391. package/esm/schemas/types/tenant_hr_shift_schedules.js +1 -0
  392. package/esm/schemas/types/tenant_hr_shifts.js +1 -0
  393. package/esm/schemas/types/tenant_instore_shift_sessions.js +1 -0
  394. package/esm/schemas/types/tenant_instore_shifts.js +1 -0
  395. package/esm/schemas/types/tenant_inventory_entries.js +1 -0
  396. package/esm/schemas/types/tenant_metadata.js +1 -0
  397. package/esm/schemas/types/tenant_order_item_instructions.js +1 -0
  398. package/esm/schemas/types/tenant_purchase_order_vendor_returns.js +1 -0
  399. package/esm/schemas/types/tenant_purchase_orders.js +1 -0
  400. package/esm/schemas/types/tenant_shifts.js +1 -0
  401. package/esm/schemas/types/tenant_staffs.js +1 -0
  402. package/esm/schemas/types/tenant_vendors.js +1 -0
  403. package/esm/schemas/types/tenants.js +1 -0
  404. package/esm/schemas/types/terminal_devices.js +1 -0
  405. package/esm/schemas/types/tokens.js +1 -0
  406. package/esm/schemas/types/track_order_numbers.js +1 -0
  407. package/esm/schemas/types/void_order_items.js +1 -0
  408. package/esm/schemas/types/vouchers.js +1 -0
  409. package/esm/schemas/types/wallet_transactions.js +1 -0
  410. package/esm/schemas/types/wallets.js +1 -0
  411. package/esm/schemas/types/warehouse-activity-logs.js +1 -0
  412. package/esm/schemas/types/warehouse_categories.js +1 -0
  413. package/esm/schemas/types/warehouse_clients.js +1 -0
  414. package/esm/schemas/types/warehouse_communications.js +1 -0
  415. package/esm/schemas/types/warehouse_internal_movements.js +1 -0
  416. package/esm/schemas/types/warehouse_inventory_entries.js +1 -0
  417. package/esm/schemas/types/warehouse_inventory_lot_serial_numbers.js +1 -0
  418. package/esm/schemas/types/warehouse_inventory_transactions.js +1 -0
  419. package/esm/schemas/types/warehouse_item_transactions.js +1 -0
  420. package/esm/schemas/types/warehouse_items.js +1 -0
  421. package/esm/schemas/types/warehouse_operational_roles.js +15 -0
  422. package/esm/schemas/types/warehouse_purchase_order_receipts.js +18 -0
  423. package/esm/schemas/types/warehouse_purchase_order_rfqs.js +1 -0
  424. package/esm/schemas/types/warehouse_purchase_order_vendor_returns.js +1 -0
  425. package/esm/schemas/types/warehouse_purchase_orders.js +1 -0
  426. package/esm/schemas/types/warehouse_sale_deliveries.js +1 -0
  427. package/esm/schemas/types/warehouse_sale_invoices.js +1 -0
  428. package/esm/schemas/types/warehouse_sale_order_rfqs.js +1 -0
  429. package/esm/schemas/types/warehouse_sale_orders.js +1 -0
  430. package/esm/schemas/types/warehouse_staffs.js +1 -0
  431. package/esm/schemas/types/warehouse_track_order_numbers.js +1 -0
  432. package/esm/schemas/types/warehouse_vendors.js +1 -0
  433. package/esm/schemas/types/warehouse_void_purchase_order_items.js +1 -0
  434. package/esm/schemas/types/warehouse_void_sale_order_items.js +1 -0
  435. package/esm/schemas/types/warehouses.js +1 -0
  436. package/package.json +6 -3
@@ -0,0 +1,1050 @@
1
+ import emojiStrip from 'emoji-strip';
2
+ import moment from 'moment';
3
+ import { COUNTRY_ALPHA_2_ENUM, KITCHEN_DOCKET_FONT_TYPE_ENUM, MODIFIER_OPTION_REF_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM, ORDER_STATUS_ENUM, ORDER_TYPE_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM, PRINTING_PREFERENCE_ENUM, RECEIPT_QR_CODE_TYPE_ENUM, RECEIPT_TYPE_ENUM, } from '../../constants';
4
+ import { getCartItemsObj } from '../store';
5
+ import { optionallyGetOrderItemOriginalQuantityPrice } from './cart-helpers';
6
+ import { getFormattedCancellationReason, getGSTName, getNationalNumberFromPhone, getTaxNumberTitle, localeAmount, parseNum, sentenceCase, titleCase, } from './common';
7
+ import { getOrderPaymentsDetails, getPaymentSmartTitle, getQRCodePaymentLink, getSortedPayments, isOrderFullyPaid, } from './payment-helpers';
8
+ // =========================><=========================
9
+ export function getDiscountLabel(discount_details) {
10
+ let label = 'Discount';
11
+ if (discount_details != null) {
12
+ if (discount_details.special_discount != null &&
13
+ discount_details.special_discount > 0 &&
14
+ discount_details.is_special_discount_percentage &&
15
+ !discount_details.loyalty_discount &&
16
+ !discount_details.voucher_discount) {
17
+ label = `Discount (${discount_details.special_discount}%)`;
18
+ }
19
+ else if (discount_details.loyalty_discount != null &&
20
+ discount_details.loyalty_discount > 0 &&
21
+ !discount_details.is_loyalty_discount_percentage &&
22
+ !discount_details.special_discount &&
23
+ !discount_details.voucher_discount) {
24
+ label = `Loyalty Discount (${discount_details.loyalty_discount}%)`;
25
+ }
26
+ else if (discount_details.voucher_discount != null &&
27
+ discount_details.voucher_discount > 0 &&
28
+ !discount_details.is_voucher_discount_percentage &&
29
+ !discount_details.special_discount &&
30
+ !discount_details.loyalty_discount) {
31
+ label = `Voucher Discount (${discount_details.voucher_discount}%)`;
32
+ }
33
+ }
34
+ return label;
35
+ }
36
+ export function getReceiptEngineFooterDetails(order, settings) {
37
+ const currencySymbol = settings.currency_symbol ?? '';
38
+ const price = order.price ?? 0;
39
+ const grandTotal = order.grand_total ?? 0;
40
+ const totalDiscount = order.total_discount_applied ?? 0;
41
+ const orderDiscount = order.order_discount_details?.total_discount ?? 0;
42
+ const itemDiscount = totalDiscount - orderDiscount;
43
+ const deliveryFee = order.delivery_details?.delivery_cost;
44
+ const itemsPriceWithoutDiscount = price - totalDiscount;
45
+ let orderSubtotal = itemsPriceWithoutDiscount;
46
+ if (order.is_surcharge_taxable) {
47
+ orderSubtotal += order.surcharge_amount ?? 0;
48
+ }
49
+ if (order.is_service_fee_taxable) {
50
+ orderSubtotal += order.service_fee_amount ?? 0;
51
+ }
52
+ const { cardCharges } = getOrderPaymentsDetails(order.grand_total, order.payments);
53
+ // =========================><=========================
54
+ const details = [];
55
+ // 1. Price (base price before any adjustments)
56
+ if (price !== grandTotal || totalDiscount) {
57
+ const right = `${localeAmount(currencySymbol, price)}`;
58
+ details.push({
59
+ left: 'Price',
60
+ right,
61
+ });
62
+ }
63
+ // 2. Item Discount
64
+ if (itemDiscount) {
65
+ let label = getDiscountLabel(order.categories?.[0]?.items?.[0]?.item_discount_details);
66
+ const areAllDiscountsSame = label.endsWith('%)') &&
67
+ order.categories?.every((cat) => cat.items?.every((item) => getDiscountLabel(item.item_discount_details) === label));
68
+ if (!areAllDiscountsSame) {
69
+ label = 'Discount';
70
+ }
71
+ const right = `${localeAmount(currencySymbol, itemDiscount)}`;
72
+ details.push({
73
+ left: `Item ${label}`,
74
+ right,
75
+ });
76
+ }
77
+ // 3. Order Discount
78
+ if (orderDiscount) {
79
+ const right = `${localeAmount(currencySymbol, orderDiscount)}`;
80
+ const label = getDiscountLabel(order.order_discount_details);
81
+ details.push({
82
+ left: label,
83
+ right,
84
+ });
85
+ }
86
+ // 4. Taxable Surcharge
87
+ if (order.is_surcharge_taxable && order.surcharge) {
88
+ const surchargePercentage = order.is_surcharge_percentage ? ` (${order.surcharge}%)` : '';
89
+ const right = localeAmount(currencySymbol, order.surcharge_amount ?? 0);
90
+ details.push({
91
+ left: `Surcharge${surchargePercentage}`,
92
+ right,
93
+ });
94
+ }
95
+ // 5. Taxable Service Charges
96
+ if (order.is_service_fee_taxable && order.service_fee) {
97
+ const seriveFeePercentage = order.is_service_fee_percentage ? ` (${order.service_fee}%)` : '';
98
+ const right = localeAmount(currencySymbol, order.service_fee_amount ?? 0);
99
+ details.push({
100
+ left: `Service Charges${seriveFeePercentage}`,
101
+ right,
102
+ });
103
+ }
104
+ // 6. Tax
105
+ if (order.tax_amount) {
106
+ const right = localeAmount(currencySymbol, order.tax_amount);
107
+ details.push({
108
+ left: 'Tax',
109
+ right,
110
+ });
111
+ }
112
+ // 7. GST (Total before GST and GST amount)
113
+ if (order.gst && !settings.hide_gst_value && order.is_gst_inclusive) {
114
+ // Compute the actual GST base (the amount GST was calculated on)
115
+ let gstBase = price;
116
+ if (!order.exclude_discount_from_gst) {
117
+ // Discount is included in GST base — subtract all applied discounts
118
+ gstBase -= totalDiscount;
119
+ }
120
+ // When exclude_discount_from_gst is true, GST base stays at the full price
121
+ if (order.is_surcharge_taxable) {
122
+ gstBase += order.surcharge_amount ?? 0;
123
+ }
124
+ if (order.is_service_fee_taxable) {
125
+ gstBase += order.service_fee_amount ?? 0;
126
+ }
127
+ gstBase = parseNum(gstBase);
128
+ const right = localeAmount(currencySymbol, Math.max(0, gstBase - (order.gst_amount ?? 0)));
129
+ details.push({
130
+ left: `Total before ${settings.gstName}`,
131
+ right,
132
+ });
133
+ const gstRight = localeAmount(currencySymbol, order.gst_amount ?? 0);
134
+ details.push({
135
+ left: `${settings.gstName} (${parseNum(order.gst)}% Inclusive)`,
136
+ right: gstRight,
137
+ });
138
+ }
139
+ // 8. Subtotal (after discounts, before non-inclusive GST breakdown)
140
+ if (orderSubtotal !== price && orderSubtotal !== grandTotal) {
141
+ const right = localeAmount(currencySymbol, orderSubtotal);
142
+ details.push({
143
+ left: 'Subtotal',
144
+ right,
145
+ });
146
+ }
147
+ // 9. GST (non-inclusive)
148
+ if (order.gst && !settings.hide_gst_value && !order.is_gst_inclusive) {
149
+ const right = localeAmount(currencySymbol, order.gst_amount ?? 0);
150
+ details.push({
151
+ left: `${settings.gstName} (${parseNum(order.gst)}%)`,
152
+ right,
153
+ });
154
+ }
155
+ // 9. Non-Taxable Surcharge
156
+ if (!order.is_surcharge_taxable && order.surcharge) {
157
+ const right = localeAmount(currencySymbol, order.surcharge_amount ?? 0);
158
+ const surchargePercentage = order.is_surcharge_percentage ? ` (${order.surcharge}%)` : '';
159
+ details.push({
160
+ left: `Surcharge${surchargePercentage}`,
161
+ right,
162
+ });
163
+ }
164
+ // 10. Non-Taxable Service Charges
165
+ if (!order.is_service_fee_taxable && order.service_fee) {
166
+ const right = localeAmount(currencySymbol, order.service_fee_amount ?? 0);
167
+ const seriveFeePercentage = order.is_service_fee_percentage ? ` (${order.service_fee}%)` : '';
168
+ details.push({
169
+ left: `Service Charges${seriveFeePercentage}`,
170
+ right,
171
+ });
172
+ }
173
+ // 11. Delivery Charges
174
+ if (deliveryFee) {
175
+ const right = localeAmount(currencySymbol, deliveryFee);
176
+ details.push({
177
+ left: 'Delivery Charges',
178
+ right,
179
+ });
180
+ }
181
+ // 12. Packaging charges
182
+ if (order.packaging_charges) {
183
+ const right = localeAmount(currencySymbol, order.packaging_charges);
184
+ details.push({
185
+ left: 'Packaging Charges',
186
+ right,
187
+ });
188
+ }
189
+ // 13. Adjustment
190
+ if (order.adjustment_amount) {
191
+ const right = localeAmount(currencySymbol, order.adjustment_amount);
192
+ let reason = '';
193
+ if (order.adjustment_reason != null && order.adjustment_reason.length < 20) {
194
+ reason = ` (${order.adjustment_reason})`;
195
+ }
196
+ details.push({
197
+ left: `Adjustment${reason}`,
198
+ right,
199
+ });
200
+ }
201
+ // 14. Tip
202
+ if (order.tip_amount) {
203
+ const right = localeAmount(currencySymbol, order.tip_amount);
204
+ details.push({
205
+ left: 'Tip',
206
+ right,
207
+ });
208
+ }
209
+ // 15. POS Charges (added last in calculateCartOrderInfoAndSyncData)
210
+ if (order.tax_invoice_provider_charges) {
211
+ const right = localeAmount(currencySymbol, order.tax_invoice_provider_charges);
212
+ details.push({
213
+ left: 'POS Charges',
214
+ right,
215
+ });
216
+ }
217
+ // 16. Card Charges
218
+ if (cardCharges > 0) {
219
+ const right = localeAmount(currencySymbol, cardCharges);
220
+ details.push({
221
+ left: 'Card Charges',
222
+ right,
223
+ });
224
+ }
225
+ return details;
226
+ }
227
+ // =========================><=========================
228
+ const removeModifierFirstWord = ['select', 'choose', 'recommended', 'pick'];
229
+ const removeModifierSecondWord = ['your', 'one', 'any', 'a', 'an', 'the'];
230
+ export const plusSymbolModifierTitles = [
231
+ 'modifier',
232
+ 'modifiers',
233
+ 'add',
234
+ 'add-on',
235
+ 'add-ons',
236
+ 'add on',
237
+ 'add ons',
238
+ 'addon',
239
+ 'addons',
240
+ 'addition',
241
+ 'additions',
242
+ 'additionals',
243
+ 'additional',
244
+ 'topping',
245
+ 'toppings',
246
+ 'extra',
247
+ 'extras',
248
+ ];
249
+ export const minusSymbolModifierTitles = [
250
+ 'without',
251
+ 'exclude',
252
+ 'excluded',
253
+ 'remove',
254
+ 'removed',
255
+ 'less',
256
+ 'lessen',
257
+ 'lessened',
258
+ 'lessening',
259
+ 'minus',
260
+ 'minused',
261
+ ];
262
+ export function getItemModifierTitle(name) {
263
+ let modifierName = name;
264
+ const words = name.toLowerCase().split(' ');
265
+ // check if name has plus symbol
266
+ const plusSymbol = plusSymbolModifierTitles.some((title) => words.includes(title));
267
+ // check if name has minus symbol
268
+ const minusSymbol = minusSymbolModifierTitles.some((title) => words.includes(title));
269
+ if (words.length > 1) {
270
+ const firstWord = words[0];
271
+ if (removeModifierFirstWord.includes(firstWord)) {
272
+ let index = 1;
273
+ if (words.length > 2) {
274
+ const secondWord = words[1];
275
+ if (removeModifierSecondWord.includes(secondWord)) {
276
+ index = 2;
277
+ }
278
+ }
279
+ modifierName = words.slice(index).join(' ');
280
+ }
281
+ }
282
+ modifierName = modifierName.trim().toUpperCase();
283
+ if (minusSymbol) {
284
+ modifierName = `- ${modifierName}`;
285
+ }
286
+ else if (plusSymbol) {
287
+ modifierName = `+ ${modifierName}`;
288
+ }
289
+ return modifierName;
290
+ }
291
+ /**
292
+ * The modifier title with the option name removed, so the line does not print
293
+ * the overlap twice. A + / - marker (added by `getItemModifierTitle`) is always
294
+ * kept, and a title the option name already covers is dropped entirely.
295
+ * Matching is case-insensitive and treats whitespace runs as equivalent.
296
+ */
297
+ export function getStrippedModifierTitle(modifierTitle, optionName) {
298
+ const marker = modifierTitle.match(/^[+-]/)?.[0] ?? '';
299
+ const title = modifierTitle.replace(/^[+-]\s*/, '');
300
+ const normalizedTitle = title.trim().toLowerCase().replace(/\s+/g, ' ');
301
+ const normalizedOption = optionName.trim().toLowerCase().replace(/\s+/g, ' ');
302
+ // The option name already says everything the title says - keep only the marker.
303
+ if (normalizedTitle !== '' && normalizedOption.includes(normalizedTitle)) {
304
+ return marker;
305
+ }
306
+ const pattern = optionName
307
+ .trim()
308
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
309
+ .split(/\s+/)
310
+ .join('\\s+');
311
+ const strippedTitle = title.replace(new RegExp(pattern, 'gi'), '').trim();
312
+ return `${marker}${strippedTitle !== '' ? ` ${strippedTitle}` : ''}`.trim();
313
+ }
314
+ /**
315
+ * Mutates the options array by adding modifier options to it.
316
+ *
317
+ * @param itemModifiers - The item modifiers
318
+ * @param options - An array of IReceiptItem. Default is empty array []
319
+ * @param space - Space parameter would add space on left to the children of each modifier. Default is empty string ''
320
+ *
321
+ */
322
+ export function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_on_separate_lines = false, space = '', hide_modifier_name = false) {
323
+ space = space + ' ';
324
+ if (!display_modifiers_on_separate_lines) {
325
+ for (let i = 0; i < itemModifiers.length; i++) {
326
+ const modifier = itemModifiers[i];
327
+ const modifierName = getItemModifierTitle(modifier.name);
328
+ let modifierOptions = modifier.options;
329
+ if (modifierOptions.length > 1) {
330
+ const optionsWithModifiers = [];
331
+ const optionsWithoutModifiers = {};
332
+ for (let j = 0; j < modifierOptions.length; j++) {
333
+ const option = {
334
+ ...modifierOptions[j],
335
+ };
336
+ if (option.modifiers != null && option.modifiers.length > 0) {
337
+ optionsWithModifiers.push(option);
338
+ }
339
+ else {
340
+ if (optionsWithoutModifiers[option.quantity] != null) {
341
+ optionsWithoutModifiers[option.quantity].name += `, ${titleCase(option.name).trim()}`;
342
+ }
343
+ else {
344
+ option.name = titleCase(option.name).trim();
345
+ optionsWithoutModifiers[option.quantity] = option;
346
+ }
347
+ }
348
+ }
349
+ modifierOptions = [];
350
+ for (const quantity in optionsWithoutModifiers) {
351
+ modifierOptions.push(optionsWithoutModifiers[quantity]);
352
+ }
353
+ for (const option of optionsWithModifiers) {
354
+ modifierOptions.push(option);
355
+ }
356
+ }
357
+ for (let j = 0; j < modifierOptions.length; j++) {
358
+ const option = modifierOptions[j];
359
+ const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
360
+ // The option name is what survives; the modifier title only prints its
361
+ // non-overlapping remainder, so identical names collapse into the option
362
+ // name alone.
363
+ const strippedModifierName = hide_modifier_name ? '' : getStrippedModifierTitle(modifierName, option.name);
364
+ const optionDescription = strippedModifierName !== ''
365
+ ? `${space}${optionQuantity}${strippedModifierName} `
366
+ : `${space}${optionQuantity}`;
367
+ options.push({
368
+ left: emojiStrip(optionDescription),
369
+ option_name: emojiStrip(titleCase(option.name)),
370
+ });
371
+ if (option.modifiers != null && option.modifiers.length > 0) {
372
+ getReceiptItemModifiers(option.modifiers, options, display_modifiers_on_separate_lines, space, hide_modifier_name);
373
+ }
374
+ }
375
+ }
376
+ }
377
+ else {
378
+ for (let i = 0; i < itemModifiers.length; i++) {
379
+ const modifier = itemModifiers[i];
380
+ const modifierName = getItemModifierTitle(modifier.name);
381
+ for (let j = 0; j < modifier.options.length; j++) {
382
+ const option = modifier.options[j];
383
+ const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
384
+ // Mirrors the flat mode: the option name is what survives, and the
385
+ // modifier title only prints its non-overlapping remainder.
386
+ const strippedModifierName = hide_modifier_name ? '' : getStrippedModifierTitle(modifierName, option.name);
387
+ const optionDescription = strippedModifierName !== ''
388
+ ? `${space}${optionQuantity}${strippedModifierName} `
389
+ : `${space}${optionQuantity}`;
390
+ options.push({
391
+ left: emojiStrip(optionDescription),
392
+ option_name: emojiStrip(sentenceCase(option.name)),
393
+ });
394
+ if (option.modifiers) {
395
+ getReceiptItemModifiers(option.modifiers, options, display_modifiers_on_separate_lines, space, hide_modifier_name);
396
+ }
397
+ }
398
+ }
399
+ }
400
+ }
401
+ export function getOrderItemReceiptBody({ orderItem, currency_symbol, display_modifiers_on_separate_lines, displayItemInstructions, show_modifiers, displayUnitItemPrice, isRemoved, hide_modifier_name, }) {
402
+ const name = orderItem.name;
403
+ const quantity = orderItem.quantity;
404
+ const subtotal = parseNum(orderItem.subtotal);
405
+ const itemModifiers = orderItem.modifiers ?? [];
406
+ let description = `${quantity}x ${name}`;
407
+ const amount = localeAmount(currency_symbol, subtotal);
408
+ const prevItemPrice = optionallyGetOrderItemOriginalQuantityPrice(orderItem);
409
+ const showPrevPrice = prevItemPrice != null && prevItemPrice > subtotal;
410
+ const prev_right = showPrevPrice ? `${prevItemPrice}` : undefined;
411
+ if (displayUnitItemPrice) {
412
+ const total = showPrevPrice ? prevItemPrice : orderItem.subtotal;
413
+ description += ` @\u200E${parseNum(total / quantity)}`;
414
+ }
415
+ const options = [
416
+ // main orderItem
417
+ {
418
+ left: description,
419
+ right: amount,
420
+ prev_right,
421
+ _id: orderItem._id,
422
+ item_id: orderItem.item_id,
423
+ image_url: orderItem.image_url,
424
+ },
425
+ // modifiers
426
+ ];
427
+ // =========================><=========================
428
+ if (show_modifiers) {
429
+ // This mutates the options array
430
+ getReceiptItemModifiers(itemModifiers, options, display_modifiers_on_separate_lines, '', hide_modifier_name);
431
+ }
432
+ // =========================><=========================
433
+ // check if item has special instructions
434
+ if (!isRemoved && displayItemInstructions && orderItem.special_instructions.length > 0) {
435
+ options.push({
436
+ left: `** Note: ${emojiStrip(orderItem.special_instructions)} **`,
437
+ is_bold: true,
438
+ });
439
+ }
440
+ if (isRemoved && orderItem.void_reason != null && orderItem.void_reason.length > 0) {
441
+ options.push({
442
+ left: `** Reason: ${emojiStrip(orderItem.void_reason)} **`,
443
+ is_bold: true,
444
+ });
445
+ }
446
+ return options;
447
+ }
448
+ export function getReceiptBody({ orderItems, currency_symbol, show_modifiers, display_modifiers_on_separate_lines, displayItemInstructions, displayUnitItemPrice, isRemoved, hide_modifier_name, }) {
449
+ const currency = currency_symbol ?? '';
450
+ const items = orderItems
451
+ .map((item) => getOrderItemReceiptBody({
452
+ orderItem: item,
453
+ currency_symbol: currency,
454
+ display_modifiers_on_separate_lines,
455
+ displayItemInstructions,
456
+ show_modifiers,
457
+ displayUnitItemPrice,
458
+ isRemoved,
459
+ hide_modifier_name,
460
+ }))
461
+ .flat();
462
+ return items;
463
+ }
464
+ // =========================><=========================
465
+ /**
466
+ * For a SPECIAL / HALF_HALF order item (a deal or half-half pizza), the
467
+ * top-level modifiers hold the real constituent items as options. Each option
468
+ * carries a `ref_type` (MODIFIER_OPTION_REF_TYPE_ENUM):
469
+ * - ITEM -> the option `ref` is a real menu product id. It can NEVER contain
470
+ * nested ITEM / HALF_HALF options - it is filtered by partial-menu membership
471
+ * only, never recursed;
472
+ * - HALF_HALF -> the option `ref` is the half-half setup id (not a catalog
473
+ * item id), and its OWN top-level modifiers (segment groups) hold options
474
+ * with ref_type ITEM. Its survival is decided by those segment items:
475
+ * filtering is recursive there, and the option is dropped when nothing
476
+ * survives;
477
+ * - OPTION (or unset) -> a regular modifier option (size, topping, ...). It is
478
+ * a terminal leaf: it never contains nested ITEM / HALF_HALF options, so it
479
+ * passes through fully (never partialed).
480
+ *
481
+ * Only options whose ref_type is ITEM or HALF_HALF qualify for partial
482
+ * printing - including at the top level. In partial printing these composite
483
+ * products must not be printed blindly:
484
+ * - ITEM / HALF_HALF options whose product is not selected in ANY included
485
+ * category are dropped (they belong to another partial menu / KOT);
486
+ * - a HALF_HALF option whose nested constituent parts are all dropped is
487
+ * dropped as well (nothing printable remains);
488
+ * - a modifier left with no options is dropped;
489
+ * - if every modifier is dropped the whole item is dropped as well.
490
+ *
491
+ * Returns a shallow-cloned item with the trimmed modifiers, or null when
492
+ * nothing survives the filter.
493
+ */
494
+ function getTrimmedCompositeModifiers(modifiers, includedItemIds) {
495
+ const trimmedModifiers = [];
496
+ for (let i = 0; i < modifiers.length; i++) {
497
+ const modifier = modifiers[i];
498
+ const keptOptions = [];
499
+ for (let j = 0; j < modifier.options.length; j++) {
500
+ const option = modifier.options[j];
501
+ const isItemLike = option.ref_type === MODIFIER_OPTION_REF_TYPE_ENUM.ITEM ||
502
+ option.ref_type === MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF;
503
+ // A normal modifier option (OPTION / unset) is a terminal leaf: it
504
+ // passes through fully, never filtered and never recursed.
505
+ if (!isItemLike) {
506
+ keptOptions.push(option);
507
+ continue;
508
+ }
509
+ // An ITEM option is a real menu product: keep it only when the product
510
+ // is part of the partial menu. ITEM options can never contain nested
511
+ // item-like options, so they are kept as-is (no recursion).
512
+ if (option.ref_type === MODIFIER_OPTION_REF_TYPE_ENUM.ITEM) {
513
+ if (!includedItemIds.has(option.ref))
514
+ continue;
515
+ keptOptions.push(option);
516
+ continue;
517
+ }
518
+ // A HALF_HALF option's ref is the half-half setup id, which is NOT a
519
+ // catalog item id, so it is not present in `includedItemIds` (built from
520
+ // catalog items only). Its survival is decided by its own segment groups
521
+ // (options with ref_type ITEM): recurse into them and keep only the
522
+ // segments whose items are part of the partial menu. Drop the option
523
+ // when nothing printable remains.
524
+ const nestedModifiers = option.modifiers != null ? getTrimmedCompositeModifiers(option.modifiers, includedItemIds) : null;
525
+ if (nestedModifiers == null || nestedModifiers.length === 0)
526
+ continue;
527
+ keptOptions.push({
528
+ ...option,
529
+ modifiers: nestedModifiers,
530
+ });
531
+ }
532
+ if (keptOptions.length === 0)
533
+ continue;
534
+ trimmedModifiers.push({
535
+ ...modifier,
536
+ options: keptOptions,
537
+ });
538
+ }
539
+ return trimmedModifiers;
540
+ }
541
+ function getPartiallyIncludedCompositeItem(item, includedItemIds) {
542
+ const trimmedModifiers = getTrimmedCompositeModifiers(item.modifiers ?? [], includedItemIds);
543
+ if (trimmedModifiers.length === 0)
544
+ return null;
545
+ return {
546
+ ...item,
547
+ modifiers: trimmedModifiers,
548
+ };
549
+ }
550
+ export const getPartialItems = (categories = [], included_categories_map, filterEmpty) => {
551
+ const partialCategories = [];
552
+ // Union of every included item id across all categories. Built lazily and
553
+ // only when a composite item (deal / half-half) actually needs it, so plain
554
+ // orders don't pay for it.
555
+ let allIncludedItemIds = null;
556
+ const getAllIncludedItemIds = () => {
557
+ if (allIncludedItemIds == null) {
558
+ allIncludedItemIds = new Set();
559
+ for (const categoryId in included_categories_map) {
560
+ const includedItems = included_categories_map[categoryId].includedItemsMap;
561
+ for (const itemId in includedItems) {
562
+ allIncludedItemIds.add(itemId);
563
+ }
564
+ }
565
+ }
566
+ return allIncludedItemIds;
567
+ };
568
+ for (let i = 0; i < categories.length; i++) {
569
+ const category = categories[i];
570
+ const includedCategory = included_categories_map[category.category_id];
571
+ if (!includedCategory)
572
+ continue;
573
+ const partialItems = [];
574
+ for (let j = 0; j < category.items.length; j++) {
575
+ const item = category.items[j];
576
+ const includedItem = includedCategory.includedItemsMap[item.item_id];
577
+ // A composite item (deal / half-half) is still gated by its own item_id
578
+ // exactly like any other item; only once included do we trim its parts.
579
+ if (!includedItem)
580
+ continue;
581
+ if ([ORDER_ITEM_TYPE_ENUM.SPECIAL, ORDER_ITEM_TYPE_ENUM.HALF_HALF].includes(item.item_type)) {
582
+ const partialItem = getPartiallyIncludedCompositeItem(item, getAllIncludedItemIds());
583
+ if (partialItem == null)
584
+ continue;
585
+ partialItems.push({
586
+ sortId: includedItem.sortId,
587
+ item: partialItem,
588
+ });
589
+ continue;
590
+ }
591
+ partialItems.push({
592
+ sortId: includedItem.sortId,
593
+ item,
594
+ });
595
+ }
596
+ // sort partial items
597
+ partialItems.sort((a, b) => a.sortId - b.sortId);
598
+ // get items from partial items
599
+ const items = partialItems.map((partialItem) => partialItem.item);
600
+ if (filterEmpty && items.length === 0)
601
+ continue;
602
+ const orderCategory = {
603
+ name: category.name,
604
+ category_id: category.category_id,
605
+ items,
606
+ };
607
+ partialCategories.push({
608
+ sortId: includedCategory.sortId,
609
+ orderCategory,
610
+ });
611
+ }
612
+ // sort partial categories
613
+ partialCategories.sort((a, b) => a.sortId - b.sortId);
614
+ const categoriesFromPartialCategories = partialCategories.map((partialCategory) => partialCategory.orderCategory);
615
+ return categoriesFromPartialCategories;
616
+ };
617
+ export function receiptEngine(payload, mappedItems = {}) {
618
+ const { currency_symbol, image_url, name, public_phone_numbers, restaurant_address, support_email, tax_business_number, takeaway_is_pickup, tax_invoice_provider, country_alpha_2, hide_gst_value, receipt_qr_type, business_website, google_review_link, playstore_url, appstore_url, fb_link, instagram_link, twitter_link, tiktok_link, } = payload.tenant_settings;
619
+ const { full_width, included_categories_map, printing_preference, receipt_type, show_modifiers, display_modifiers_on_separate_lines, display_item_instructions_on_customer_receipt, display_order_instructions_on_customer_receipt, display_unit_item_price_on_customer_receipt, hide_modifier_name, display_qr_code_on_receipt, customMessage, } = payload.printer_settings;
620
+ const currencySymbol = currency_symbol ?? '';
621
+ const grandTotal = payload.order.grand_total ?? 0;
622
+ const { amountPayedSoFar, existingPayments, change, creditAmount } = getOrderPaymentsDetails(payload.order.grand_total, payload.order.payments);
623
+ const payments = getSortedPayments(existingPayments.filter((payment) => payment.payment_status === PAYMENT_STATUS_ENUM.SETTLED ||
624
+ payment.payment_status === PAYMENT_STATUS_ENUM.REFUNDED));
625
+ const gstName = getGSTName(country_alpha_2, tax_invoice_provider);
626
+ const taxNumberTitle = getTaxNumberTitle(country_alpha_2, tax_invoice_provider);
627
+ const isFullyPaid = isOrderFullyPaid(grandTotal, payload.order.payments);
628
+ const settings = {
629
+ currency_symbol,
630
+ show_modifiers,
631
+ tax_invoice_provider,
632
+ gstName,
633
+ hide_gst_value,
634
+ };
635
+ const estimated_time = payload.order.takeaway_details?.estimated_takeaway_time !== undefined
636
+ ? payload.order.takeaway_details?.estimated_takeaway_time
637
+ : payload.order.delivery_details?.estimated_delivery_time;
638
+ // =========================><=========================
639
+ const [order_from, order_type] = payload.order.platform?.split('_') ?? ['', ''];
640
+ let orderTypeName = order_type;
641
+ if (takeaway_is_pickup && order_type === ORDER_TYPE_ENUM.TAKE_AWAY) {
642
+ orderTypeName = 'PICK-UP';
643
+ }
644
+ const is_kitchen_receipt = receipt_type === RECEIPT_TYPE_ENUM.KITCHEN;
645
+ const displayItemInstructions = is_kitchen_receipt || display_item_instructions_on_customer_receipt;
646
+ const displayOrderInstructions = is_kitchen_receipt || display_order_instructions_on_customer_receipt;
647
+ let unchanged_items;
648
+ let edited_items;
649
+ let removed_items;
650
+ let new_items;
651
+ let order_courses;
652
+ let total_items = 0;
653
+ let prev_dinein_table_name = null;
654
+ const categories = payload.order.categories ?? [];
655
+ if (is_kitchen_receipt) {
656
+ const firstIteration = payload.order.iterations?.[0];
657
+ let currentIterationCategories = payload.order.categories;
658
+ let currentDineinCourses = payload.order.dinein_details?.courses;
659
+ let previousIterationCategories = firstIteration?.categories;
660
+ let previousDineinCourses = firstIteration?.dinein_details?.courses;
661
+ if (payload.order.dinein_details != null &&
662
+ firstIteration != null &&
663
+ firstIteration.dinein_details != null &&
664
+ firstIteration.dinein_details.table_name !== payload.order.dinein_details.table_name) {
665
+ prev_dinein_table_name = firstIteration.dinein_details.table_name ?? null;
666
+ }
667
+ const isPartial = printing_preference === PRINTING_PREFERENCE_ENUM.PARTIAL;
668
+ const isAnEdit = firstIteration != null && firstIteration.categories != null && firstIteration.categories.length > 0;
669
+ const printUnchangedItems = payload.printer_settings.display_old_items_on_kitchen_receipt || !isAnEdit;
670
+ if (isPartial) {
671
+ currentIterationCategories = getPartialItems(currentIterationCategories, included_categories_map);
672
+ if (currentDineinCourses) {
673
+ const currentIterationItemIds = currentIterationCategories.reduce((acc, category) => {
674
+ category.items.forEach((item) => {
675
+ acc.push(item.item_id);
676
+ });
677
+ return acc;
678
+ }, []);
679
+ currentDineinCourses.forEach((courseObj) => {
680
+ courseObj.item_ids = courseObj.item_ids.filter((itemId) => currentIterationItemIds.includes(itemId));
681
+ });
682
+ currentDineinCourses = currentDineinCourses.filter((courseObj) => courseObj.item_ids.length > 0);
683
+ }
684
+ previousIterationCategories = getPartialItems(previousIterationCategories, included_categories_map);
685
+ if (previousDineinCourses) {
686
+ const previousIterationItemIds = previousIterationCategories.reduce((acc, category) => {
687
+ category.items.forEach((item) => {
688
+ acc.push(item.item_id);
689
+ });
690
+ return acc;
691
+ }, []);
692
+ previousDineinCourses = previousDineinCourses.map((courseObj) => ({
693
+ ...courseObj,
694
+ item_ids: courseObj.item_ids.filter((itemId) => previousIterationItemIds.includes(itemId)),
695
+ }));
696
+ previousDineinCourses = previousDineinCourses.filter((courseObj) => courseObj.item_ids.length > 0);
697
+ }
698
+ }
699
+ const cartItems = getCartItemsObj({
700
+ currentIterationCategories,
701
+ currentDineinCourses,
702
+ previousIterationCategories,
703
+ previousDineinCourses,
704
+ mappedItems,
705
+ shouldSortItemsViaId: !isPartial,
706
+ platform: payload.order.platform,
707
+ isAnEdit,
708
+ });
709
+ total_items = cartItems.totalSelectedItems;
710
+ if (printUnchangedItems || prev_dinein_table_name) {
711
+ const unchanged = getReceiptBody({
712
+ orderItems: cartItems.unChangedItems.map((item) => ({ ...item.orderItem, image_url: item.image_url })),
713
+ currency_symbol,
714
+ show_modifiers,
715
+ display_modifiers_on_separate_lines,
716
+ displayItemInstructions,
717
+ hide_modifier_name,
718
+ });
719
+ if (prev_dinein_table_name != null && unchanged.length === 0) {
720
+ prev_dinein_table_name = null;
721
+ }
722
+ if (printUnchangedItems) {
723
+ unchanged_items = unchanged;
724
+ }
725
+ }
726
+ edited_items = getReceiptBody({
727
+ orderItems: cartItems.editedItems.map((item) => ({ ...item.orderItem, image_url: item.image_url })),
728
+ currency_symbol,
729
+ show_modifiers,
730
+ display_modifiers_on_separate_lines,
731
+ displayItemInstructions,
732
+ hide_modifier_name,
733
+ });
734
+ removed_items = getReceiptBody({
735
+ orderItems: cartItems.removedItems.map((item) => ({ ...item.orderItem, image_url: item.image_url })),
736
+ currency_symbol,
737
+ show_modifiers,
738
+ display_modifiers_on_separate_lines,
739
+ displayItemInstructions,
740
+ isRemoved: true,
741
+ hide_modifier_name,
742
+ });
743
+ new_items = getReceiptBody({
744
+ orderItems: cartItems.newItems.map((item) => ({ ...item.orderItem, image_url: item.image_url })),
745
+ currency_symbol,
746
+ show_modifiers,
747
+ display_modifiers_on_separate_lines,
748
+ displayItemInstructions,
749
+ hide_modifier_name,
750
+ });
751
+ order_courses = [];
752
+ for (let i = 0; i < cartItems.orderCourses.length; i++) {
753
+ const courseObj = cartItems.orderCourses[i];
754
+ const called = courseObj.called && !courseObj.has_already_been_called;
755
+ const uncalled = !courseObj.called && courseObj.has_already_been_called;
756
+ const unchanged_items = printUnchangedItems || called || uncalled
757
+ ? getReceiptBody({
758
+ orderItems: courseObj.cartItemsObj.unChangedItems.map((item) => ({
759
+ ...item.orderItem,
760
+ image_url: item.image_url,
761
+ })),
762
+ currency_symbol,
763
+ show_modifiers,
764
+ display_modifiers_on_separate_lines,
765
+ displayItemInstructions,
766
+ hide_modifier_name,
767
+ })
768
+ : [];
769
+ const edited_items = getReceiptBody({
770
+ orderItems: courseObj.cartItemsObj.editedItems.map((item) => ({
771
+ ...item.orderItem,
772
+ image_url: item.image_url,
773
+ })),
774
+ currency_symbol,
775
+ show_modifiers,
776
+ display_modifiers_on_separate_lines,
777
+ displayItemInstructions,
778
+ hide_modifier_name,
779
+ });
780
+ const removed_items = getReceiptBody({
781
+ orderItems: courseObj.cartItemsObj.removedItems.map((item) => ({
782
+ ...item.orderItem,
783
+ image_url: item.image_url,
784
+ })),
785
+ currency_symbol,
786
+ show_modifiers,
787
+ display_modifiers_on_separate_lines,
788
+ displayItemInstructions,
789
+ isRemoved: true,
790
+ hide_modifier_name,
791
+ });
792
+ const new_items = getReceiptBody({
793
+ orderItems: courseObj.cartItemsObj.newItems.map((item) => ({ ...item.orderItem, image_url: item.image_url })),
794
+ currency_symbol,
795
+ show_modifiers,
796
+ display_modifiers_on_separate_lines,
797
+ displayItemInstructions,
798
+ hide_modifier_name,
799
+ });
800
+ if (!unchanged_items.length && !edited_items.length && !removed_items.length && !new_items.length) {
801
+ continue;
802
+ }
803
+ order_courses.push({
804
+ called: courseObj.called,
805
+ has_already_been_called: courseObj.has_already_been_called,
806
+ is_removed: courseObj.is_removed,
807
+ name: courseObj.name,
808
+ total_amount: courseObj.total_amount,
809
+ total_selected_items: courseObj.totalSelectedItems,
810
+ course_items_obj: {
811
+ unchanged_items,
812
+ edited_items,
813
+ removed_items,
814
+ new_items,
815
+ },
816
+ });
817
+ }
818
+ }
819
+ else {
820
+ const items = categories.reduce((acc, category) => acc.concat(category.items.map((item) => ({
821
+ ...item,
822
+ image_url: mappedItems[item.item_id]?.image_url,
823
+ }))), []);
824
+ unchanged_items = getReceiptBody({
825
+ orderItems: items,
826
+ currency_symbol,
827
+ show_modifiers,
828
+ display_modifiers_on_separate_lines,
829
+ displayItemInstructions,
830
+ displayUnitItemPrice: display_unit_item_price_on_customer_receipt,
831
+ hide_modifier_name,
832
+ });
833
+ total_items = items.length;
834
+ }
835
+ const changeAmount = change > 0 ? localeAmount(currencySymbol, change) : null;
836
+ const payment_details = [
837
+ ...payments.map((payment) => {
838
+ const isRefund = payment.amount_refunded > 0 && payment.amount_refunded > payment.amount_paid;
839
+ const paymentTitle = getPaymentSmartTitle(payment.payment_type).title;
840
+ const amount = (payment.payment_type !== PAYMENT_TYPE_ENUM.UNPAID
841
+ ? isRefund
842
+ ? payment.amount_refunded - payment.amount_paid
843
+ : payment.amount_paid
844
+ : payment.amount_due) + (payment.card_details?.card_charges ?? 0);
845
+ return {
846
+ left: `${sentenceCase(paymentTitle).replace(/_/g, ' ')}${isRefund ? ' (Refund)' : ''}`,
847
+ right: localeAmount(currencySymbol, amount),
848
+ };
849
+ }),
850
+ ...(changeAmount
851
+ ? [
852
+ {
853
+ left: 'Change',
854
+ right: changeAmount,
855
+ },
856
+ ]
857
+ : []),
858
+ ];
859
+ const parsedAmountPayedSoFar = parseNum(amountPayedSoFar);
860
+ let customerName = null;
861
+ let customerPhone = null;
862
+ if (payload.order.consumer != null &&
863
+ (payload.order.staff_details == null || payload.order.consumer.phone !== payload.order.staff_details.staff_mobile)) {
864
+ const phoneNumber = getNationalNumberFromPhone(payload.order.consumer.phone);
865
+ customerName = `${payload.order.consumer.first_name} ${payload.order.consumer.last_name}`.trim();
866
+ customerPhone = phoneNumber ?? payload.order.consumer.phone;
867
+ }
868
+ const staff_name = payload.printer_settings.print_staff_name && payload.order.staff_details != null
869
+ ? (payload.order.staff_details.staff_name ?? null)
870
+ : null;
871
+ const order_taker_name = payload.order.order_taker_details?.staff_name ?? null;
872
+ const rider_name = payload.order.delivery_details?.rider_details?.staff_name ?? null;
873
+ let payment_status = null;
874
+ // Helper to get expected payment label suffix
875
+ const getExpectedPaymentLabel = () => {
876
+ if (payload.order.payment_method_expected) {
877
+ return ` (Expected: ${sentenceCase(payload.order.payment_method_expected.replace(/_/g, ' '))})`;
878
+ }
879
+ return '';
880
+ };
881
+ if (payload.order.is_deleted) {
882
+ payment_status = '* DELETED *';
883
+ }
884
+ else if (payload.order.order_status === ORDER_STATUS_ENUM.CANCELLED) {
885
+ payment_status = '* CANCELLED *';
886
+ }
887
+ else if (receipt_type === RECEIPT_TYPE_ENUM.CUSTOMER || !payload.printer_settings.keep_kitchen_receipt_concise) {
888
+ // CREDIT BILL has priority - check first if there's an credit amount (PAY_LATER)
889
+ if (creditAmount > 0) {
890
+ payment_status = '* CREDIT BILL *';
891
+ payment_details.push({
892
+ left: `Credit Amount${getExpectedPaymentLabel()}`,
893
+ right: localeAmount(currencySymbol, creditAmount),
894
+ });
895
+ }
896
+ else if (parsedAmountPayedSoFar >= parseNum(grandTotal)) {
897
+ payment_status = '* PAID *';
898
+ }
899
+ else if (parsedAmountPayedSoFar > 0) {
900
+ payment_status = '* PARTIALLY PAID *';
901
+ payment_details.push({
902
+ left: `Pending Amount${getExpectedPaymentLabel()}`,
903
+ right: localeAmount(currencySymbol, grandTotal - parsedAmountPayedSoFar),
904
+ });
905
+ }
906
+ else {
907
+ payment_status = '* UNPAID *';
908
+ const expectedPaymentLabel = getExpectedPaymentLabel();
909
+ if (expectedPaymentLabel) {
910
+ payment_details.push({
911
+ left: `Amount Due${expectedPaymentLabel}`,
912
+ right: localeAmount(currencySymbol, grandTotal),
913
+ });
914
+ }
915
+ }
916
+ }
917
+ let delivery_instructions = null;
918
+ let cancel_reason = null;
919
+ if (payload.order.order_status === ORDER_STATUS_ENUM.CANCELLED) {
920
+ cancel_reason = getFormattedCancellationReason(payload.order.cancel_reason) ?? null;
921
+ }
922
+ else if (payload.order.delivery_details != null && payload.printer_settings.print_delivery_details) {
923
+ delivery_instructions = `${payload.order.delivery_details.street}${payload.order.delivery_details.address_instructions.trim() !== ''
924
+ ? `\n** ${payload.order.delivery_details.address_instructions} **`
925
+ : ''}`.trim();
926
+ }
927
+ let order_link = null;
928
+ let invoice_name = '';
929
+ let custom_message = null;
930
+ if (is_kitchen_receipt) {
931
+ invoice_name = `Order #${payload.order.order_number ?? ''}`;
932
+ }
933
+ else {
934
+ invoice_name = `Invoice #${payload.order.order_number ?? ''}`;
935
+ custom_message = customMessage;
936
+ if (isFullyPaid) {
937
+ // Either tax invoice ID is present or country is not Pakistan and tax business number is present
938
+ if (payload.order.tax_invoice_id || (country_alpha_2 !== COUNTRY_ALPHA_2_ENUM.PK && tax_business_number)) {
939
+ invoice_name = `Tax ${invoice_name}`;
940
+ }
941
+ }
942
+ if (payload.order.tax_invoice_id) {
943
+ order_link = payload.order.tax_invoice_id;
944
+ }
945
+ else {
946
+ // Use raw order.payments here (not the settled-only `payments` list) because
947
+ // getQRCodePaymentLink looks for a PENDING RAAST_PAY payment to derive the QR link.
948
+ const qrCodePayment = getQRCodePaymentLink(grandTotal, payload.order.payments);
949
+ if (qrCodePayment != null) {
950
+ order_link = qrCodePayment.qrLink;
951
+ custom_message = qrCodePayment.scanMessage;
952
+ }
953
+ else if (display_qr_code_on_receipt) {
954
+ const digitalReceiptLink = business_website != null ? `https://${business_website}/orders/${payload.order._id}` : null;
955
+ if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.DIGITAL_RECEIPT && digitalReceiptLink != null) {
956
+ order_link = digitalReceiptLink;
957
+ }
958
+ else if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.APPSTORE_APP_DOWNLOAD && appstore_url != null) {
959
+ order_link = appstore_url;
960
+ }
961
+ else if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.PLAYSTORE_APP_DOWNLOAD && playstore_url != null) {
962
+ order_link = playstore_url;
963
+ }
964
+ else if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.GOOGLE_REVIEW && google_review_link != null) {
965
+ order_link = google_review_link;
966
+ }
967
+ else if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.FACEBOOK_FOLLOW && fb_link != null) {
968
+ order_link = fb_link;
969
+ }
970
+ else if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.INSTA_FOLLOW && instagram_link != null) {
971
+ order_link = instagram_link;
972
+ }
973
+ else if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.TWITTER_FOLLOW && twitter_link != null) {
974
+ order_link = twitter_link;
975
+ }
976
+ else if (receipt_qr_type === RECEIPT_QR_CODE_TYPE_ENUM.TIKTOK_FOLLOW && tiktok_link != null) {
977
+ order_link = tiktok_link;
978
+ }
979
+ else if (digitalReceiptLink != null) {
980
+ order_link = digitalReceiptLink;
981
+ }
982
+ }
983
+ }
984
+ }
985
+ const engine = {
986
+ _id: payload.order._id ?? '',
987
+ tenant_details: {
988
+ image_url,
989
+ name,
990
+ restaurant_address,
991
+ support_email,
992
+ public_phone_numbers,
993
+ tax_business_number,
994
+ taxNumberTitle,
995
+ },
996
+ order_type: orderTypeName,
997
+ order_from,
998
+ placed_time: moment(payload.order.createdAt).format('ddd, MMMM Do, h:mmA'),
999
+ expected_time: estimated_time === null
1000
+ ? '(ASAP)'
1001
+ : estimated_time
1002
+ ? `${moment(new Date(estimated_time).getTime()).calendar()}`
1003
+ : null,
1004
+ order_number: invoice_name,
1005
+ customer_details: {
1006
+ customer: receipt_type === RECEIPT_TYPE_ENUM.CUSTOMER || !payload.printer_settings.keep_kitchen_receipt_concise
1007
+ ? `${customerName ?? ''}${customerName && customerPhone ? ' - ' : ''}${customerPhone ?? ''}`
1008
+ : null,
1009
+ special_instructions: displayOrderInstructions && payload.order.special_instructions != null
1010
+ ? payload.order.special_instructions
1011
+ : null,
1012
+ delivery_instructions,
1013
+ },
1014
+ order_details: {
1015
+ staff_name,
1016
+ order_taker_name,
1017
+ rider_name,
1018
+ covers: payload.order.dinein_details?.num_of_guests ?? null,
1019
+ dinein_table_name: payload.order.dinein_details?.table_name ?? null,
1020
+ prev_dinein_table_name,
1021
+ },
1022
+ payment_status,
1023
+ order_link,
1024
+ total_items,
1025
+ unchanged_items,
1026
+ edited_items,
1027
+ removed_items,
1028
+ new_items,
1029
+ order_courses,
1030
+ payment_details,
1031
+ // // ====================<Footer>====================
1032
+ footer: (() => {
1033
+ const orderGrandTotal = payload.order.grand_total ?? 0;
1034
+ const footerDetails = getReceiptEngineFooterDetails(payload.order, settings);
1035
+ return footerDetails.concat({
1036
+ left: `Grand Total${payload.order.gst && hide_gst_value ? ` (Incl. ${gstName})` : ''}`,
1037
+ right: localeAmount(currencySymbol, orderGrandTotal),
1038
+ });
1039
+ })(),
1040
+ show_modifiers,
1041
+ is_kitchen_receipt,
1042
+ full_width,
1043
+ font_preference: payload.printer_settings.font_preference ?? KITCHEN_DOCKET_FONT_TYPE_ENUM.DEFAULT,
1044
+ display_item_price_on_kitchen_receipt: payload.printer_settings.display_item_price_on_kitchen_receipt,
1045
+ keep_kitchen_receipt_concise: payload.printer_settings.keep_kitchen_receipt_concise,
1046
+ cancel_reason,
1047
+ custom_message,
1048
+ };
1049
+ return engine;
1050
+ }