@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,251 @@
1
+ import { isEqual } from 'lodash';
2
+ import Mongoose from 'mongoose';
3
+ import { ALL_ORDER_STATUS_NAMES, ORDER_STATUS_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM } from '../../constants';
4
+ import { CUSTOM_ERROR_CODES, CustomError, getCardChargesAndAmountCollected, getOfflineOrderNumber, getOrderPaymentsDetails, isOrderFullyPaid, syncPayments, } from '../utils';
5
+ import { generateOrderIteration, getVoidItemsWithReason, syncOrderData } from './common-order-actions';
6
+ export function processPaymentsForOrder({ payments, grand_total, }) {
7
+ const mutableData = {
8
+ new_card_charges: 0,
9
+ amount_collected: 0,
10
+ is_order_fully_paid: false,
11
+ };
12
+ let allPayments = [];
13
+ let amountLeftToPay = getOrderPaymentsDetails(grand_total, payments).amountLeftToPay;
14
+ let totalFailedPayments = 0;
15
+ let payLaterAmount = 0;
16
+ for (let i = 0; i < payments.length; i++) {
17
+ const payment = payments[i];
18
+ // We need to process the payment if it is not already processed
19
+ // A payment is considered processed if it has a payment_id
20
+ if (payment.payment_id == null) {
21
+ // We need to check if the amount due is greater than the amount left to pay
22
+ // and if the amount paid is greater than 0, then we need to adjust the amount due
23
+ if (payment.amount_due > amountLeftToPay && payment.amount_paid > 0) {
24
+ const prevAmountDue = payment.amount_due;
25
+ payment.amount_due = amountLeftToPay;
26
+ if (payment.amount_paid === prevAmountDue) {
27
+ payment.amount_paid = amountLeftToPay;
28
+ }
29
+ amountLeftToPay = 0;
30
+ }
31
+ if (payment.payment_type === PAYMENT_TYPE_ENUM.UNPAID) {
32
+ continue;
33
+ }
34
+ else if (payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER) {
35
+ // PAY_LATER is treated similar to UNPAID - can only be PENDING
36
+ payment.payment_status = PAYMENT_STATUS_ENUM.PENDING;
37
+ payment.payment_id = new Mongoose.Types.ObjectId().toHexString();
38
+ payment.card_details = null;
39
+ }
40
+ else if (payment.payment_type === PAYMENT_TYPE_ENUM.CARD) {
41
+ continue;
42
+ }
43
+ else if (payment.payment_type === PAYMENT_TYPE_ENUM.EASYPAISA_PAY) {
44
+ continue;
45
+ }
46
+ else if (payment.payment_type === PAYMENT_TYPE_ENUM.JAZZCASH_PAY) {
47
+ continue;
48
+ }
49
+ else if (payment.payment_type === PAYMENT_TYPE_ENUM.TERMINAL) {
50
+ continue;
51
+ }
52
+ else {
53
+ const isRefund = payment.amount_refunded > 0 && payment.amount_paid === 0;
54
+ // Remaining Payment Types are ===> CASH, MARKED_PAID, etc
55
+ // We don't need to check if it has been refunded
56
+ // This is because a refund payment in cash or marked_paid, etc is the responsibility of the tenant
57
+ payment.payment_id = new Mongoose.Types.ObjectId().toHexString();
58
+ payment.card_details = null;
59
+ payment.payment_status = isRefund ? PAYMENT_STATUS_ENUM.REFUNDED : PAYMENT_STATUS_ENUM.SETTLED;
60
+ }
61
+ }
62
+ if (payment.payment_status === PAYMENT_STATUS_ENUM.FAILED) {
63
+ totalFailedPayments++;
64
+ }
65
+ if (payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER &&
66
+ payment.payment_status === PAYMENT_STATUS_ENUM.PENDING) {
67
+ payLaterAmount += payment.amount_due;
68
+ }
69
+ allPayments.push(payment);
70
+ }
71
+ allPayments = syncPayments(allPayments);
72
+ const { amountCollected, amountPaid } = getCardChargesAndAmountCollected(allPayments);
73
+ mutableData.amount_collected = amountCollected;
74
+ const orderTotal = grand_total + mutableData.new_card_charges;
75
+ const unPaidAmount = orderTotal - amountPaid - payLaterAmount;
76
+ if (unPaidAmount > 0) {
77
+ const unpaidPayment = {
78
+ _id: new Mongoose.Types.ObjectId().toHexString(),
79
+ payment_type: PAYMENT_TYPE_ENUM.UNPAID,
80
+ amount_due: unPaidAmount,
81
+ payment_id: null,
82
+ card_details: null,
83
+ amount_paid: 0,
84
+ amount_refunded: 0,
85
+ payment_status: PAYMENT_STATUS_ENUM.PENDING,
86
+ };
87
+ allPayments.push(unpaidPayment);
88
+ }
89
+ else {
90
+ mutableData.is_order_fully_paid = true;
91
+ }
92
+ return [allPayments, mutableData];
93
+ }
94
+ // =======================>>><<<=======================
95
+ export function getMergedPayments(prevPayments, newPayments) {
96
+ const mergedPaymentsObj = {};
97
+ for (let i = 0; i < prevPayments.length; i++) {
98
+ const payment = prevPayments[i];
99
+ if (payment._id == null)
100
+ continue;
101
+ // Filter out pay later payments that have a payment_id
102
+ if (payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER && payment.payment_id != null) {
103
+ continue;
104
+ }
105
+ const _id = payment._id.toString();
106
+ mergedPaymentsObj[_id] = {
107
+ ...payment,
108
+ _id,
109
+ };
110
+ }
111
+ if (newPayments != null) {
112
+ for (let i = 0; i < newPayments.length; i++) {
113
+ const payment = newPayments[i];
114
+ const _id = payment._id?.toString() ?? new Mongoose.Types.ObjectId().toHexString();
115
+ mergedPaymentsObj[_id] = {
116
+ ...payment,
117
+ _id,
118
+ };
119
+ }
120
+ }
121
+ return Object.values(mergedPaymentsObj).sort((a, b) => new Mongoose.Types.ObjectId(a._id).getTimestamp().getTime() -
122
+ new Mongoose.Types.ObjectId(b._id).getTimestamp().getTime());
123
+ }
124
+ export function renderPostOfflineOrder(body) {
125
+ const copiedBody = JSON.parse(JSON.stringify(body));
126
+ copiedBody.iterations = copiedBody.iterations ?? [];
127
+ copiedBody.special_instructions = copiedBody.special_instructions ?? '';
128
+ copiedBody.tax_number = copiedBody.tax_number ?? '';
129
+ copiedBody.tax_amount = copiedBody.tax_amount ?? 0;
130
+ copiedBody.is_deleted = copiedBody.is_deleted ?? false;
131
+ copiedBody.order_status = ORDER_STATUS_ENUM.PLACED;
132
+ copiedBody._id = new Mongoose.Types.ObjectId().toHexString();
133
+ copiedBody.createdAt = new Date();
134
+ copiedBody.createdAt_mins = Math.floor(copiedBody.createdAt.getHours() * 60 + copiedBody.createdAt.getMinutes());
135
+ copiedBody.updatedAt = copiedBody.createdAt;
136
+ copiedBody.order_settled_at = copiedBody.createdAt;
137
+ copiedBody.order_settled_at_mins = copiedBody.createdAt_mins;
138
+ copiedBody.order_status_updated_at = copiedBody.createdAt;
139
+ copiedBody.order_number = getOfflineOrderNumber();
140
+ let updatedOrder = syncOrderData(copiedBody);
141
+ // We calculate the payments for the order only after syncing the order data
142
+ // This is because we need to make sure that the order is in the correct format
143
+ // and the grand total is calculated correctly
144
+ const [payments, mutableData] = processPaymentsForOrder({
145
+ payments: updatedOrder.payments,
146
+ grand_total: updatedOrder.grand_total,
147
+ });
148
+ updatedOrder.payments = payments;
149
+ updatedOrder.is_unpaid = !mutableData.is_order_fully_paid;
150
+ updatedOrder.amount_collected = mutableData.amount_collected;
151
+ // Add card charges to grand total
152
+ updatedOrder.grand_total += mutableData.new_card_charges;
153
+ updatedOrder = JSON.parse(JSON.stringify(updatedOrder));
154
+ return updatedOrder;
155
+ }
156
+ export function renderUpdateOfflineOrder(body, prev) {
157
+ const copiedBody = JSON.parse(JSON.stringify(body));
158
+ const prevOrder = JSON.parse(JSON.stringify(prev));
159
+ if (!copiedBody.updatedAt) {
160
+ throw new CustomError('Invalid Data', CUSTOM_ERROR_CODES.INVALID_DATA);
161
+ }
162
+ if (new Date(prevOrder.updatedAt ?? 0).getTime() !== new Date(copiedBody.updatedAt).getTime()) {
163
+ throw new CustomError('This version of the order is outdated', CUSTOM_ERROR_CODES.OUTDATED_ORDER);
164
+ }
165
+ // Iterations are only added/updated by the backend
166
+ const iterationsFromFrontend = copiedBody.iterations;
167
+ delete copiedBody.iterations;
168
+ // We only allow to update the order status to COMPLETED, but in offline mode we don't allow that
169
+ // Any other status change should be done by the updateOrderStatus function
170
+ delete copiedBody.order_status;
171
+ const grandTotalDidChange = copiedBody.grand_total != null;
172
+ const coursesExist = copiedBody.dinein_details?.courses != null;
173
+ const staffDetailsExist = copiedBody.staff_details != null;
174
+ // Check if the order has any changes that would require an iteration
175
+ if (
176
+ // Either the categories field is present
177
+ Array.isArray(copiedBody.categories) ||
178
+ // or the staff_details field is present
179
+ staffDetailsExist ||
180
+ // or the grand_total field is present
181
+ grandTotalDidChange ||
182
+ // or the dinein_details.courses field is present
183
+ coursesExist) {
184
+ // We would only add prev order to iterations if there are any changes in categories
185
+ const itemsDidChange = copiedBody.categories != null && JSON.stringify(prevOrder.categories) !== JSON.stringify(copiedBody.categories);
186
+ const iterationNeedToBeAdded =
187
+ // Either items have changed
188
+ itemsDidChange ||
189
+ // or the grand total has changed
190
+ grandTotalDidChange ||
191
+ // or the dinein_details.courses has changed
192
+ coursesExist ||
193
+ // or the staff_details has changed
194
+ (staffDetailsExist && !isEqual(copiedBody.staff_details, prevOrder.staff_details));
195
+ if (iterationNeedToBeAdded) {
196
+ const { newIterationCategories, voidOrderItems, hasNewItems } = getVoidItemsWithReason({
197
+ currentCategories: copiedBody.categories ?? [],
198
+ iterationsFromFrontend,
199
+ platform: copiedBody.platform ?? prevOrder.platform,
200
+ previousCategories: prevOrder.categories ?? [],
201
+ });
202
+ if (hasNewItems &&
203
+ copiedBody.order_status == null &&
204
+ ALL_ORDER_STATUS_NAMES.indexOf(prevOrder.order_status) >
205
+ ALL_ORDER_STATUS_NAMES.indexOf(ORDER_STATUS_ENUM.PREPARING)) {
206
+ copiedBody.order_status = ORDER_STATUS_ENUM.PREPARING;
207
+ copiedBody.order_status_updated_at = new Date();
208
+ }
209
+ if (voidOrderItems.length > 0) {
210
+ prevOrder.categories = newIterationCategories;
211
+ }
212
+ const orderIteration = generateOrderIteration(prevOrder);
213
+ // Mutate the copiedBody to add the old order iterations
214
+ copiedBody.iterations = [orderIteration, ...(prevOrder.iterations ?? [])];
215
+ }
216
+ }
217
+ // Here we merge the copiedBody with the prevOrder to get the updated order
218
+ // Then we sync the order data to make sure that the order is in the correct format
219
+ const iterations = copiedBody.iterations ?? [];
220
+ let updatedOrder = {
221
+ ...prevOrder,
222
+ ...copiedBody,
223
+ payments: getMergedPayments(prevOrder.payments, copiedBody.payments),
224
+ iterations: [], // Ommiting the iterations field
225
+ };
226
+ // updatedOrder is the actual foot print of the order
227
+ // Sync Order Data before processing payments because
228
+ // we need to make sure that the order is in the correct format
229
+ // and the grand total is calculated correctly
230
+ updatedOrder = syncOrderData(updatedOrder);
231
+ // process payments if order has payments
232
+ const [payments, mutableData] = processPaymentsForOrder({
233
+ payments: updatedOrder.payments,
234
+ grand_total: updatedOrder.grand_total,
235
+ });
236
+ // ======>>> Set the updated order <<<=======
237
+ updatedOrder.iterations = iterations;
238
+ updatedOrder.payments = payments;
239
+ updatedOrder.is_unpaid = !mutableData.is_order_fully_paid;
240
+ updatedOrder.amount_collected = mutableData.amount_collected;
241
+ // Add card charges to grand total
242
+ updatedOrder.grand_total += mutableData.new_card_charges;
243
+ updatedOrder.updatedAt = new Date();
244
+ if (mutableData.is_order_fully_paid && !isOrderFullyPaid(updatedOrder.grand_total, prevOrder.payments)) {
245
+ const newOrderSettledAt = new Date();
246
+ updatedOrder.order_settled_at = newOrderSettledAt;
247
+ copiedBody.order_settled_at_mins = Math.floor(newOrderSettledAt.getHours() * 60 + newOrderSettledAt.getMinutes());
248
+ }
249
+ updatedOrder = JSON.parse(JSON.stringify(updatedOrder));
250
+ return updatedOrder;
251
+ }
@@ -0,0 +1,379 @@
1
+ import ObjectID from 'bson-objectid';
2
+ import { isEqual } from 'lodash';
3
+ import { TENANT_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
4
+ import { getCardChargesAndAmountCollected, getPercentageAmount, parseFloatCeil, parseNum } from '../utils';
5
+ export function calculateCartTenantPurchaseOrderInfoAndSyncData(data, calculateItemMetadata) {
6
+ const isCompleted = data.order_status === TENANT_PURCHASE_ORDER_STATUS_ENUM.COMPLETED;
7
+ let subtotal = 0;
8
+ const categories = [];
9
+ const length = data.categories?.length ?? 0;
10
+ for (let c = 0; c < length; c++) {
11
+ const category = data.categories[c];
12
+ const newItems = [];
13
+ const itemsLength = category.items.length;
14
+ for (let i = 0; i < itemsLength; i++) {
15
+ const item = category.items[i];
16
+ const itemSubtotal = parseNum(item.price * item.quantity);
17
+ const newItem = {
18
+ ...item,
19
+ is_ready: item.is_ready || isCompleted,
20
+ subtotal: itemSubtotal,
21
+ _discount_amount: 0,
22
+ _gross_amount: 0,
23
+ _gst_amount: 0,
24
+ _net_amount: 0,
25
+ };
26
+ delete newItem.void_reason;
27
+ newItems.push(newItem);
28
+ subtotal += itemSubtotal;
29
+ }
30
+ categories.push({
31
+ ...category,
32
+ items: newItems,
33
+ });
34
+ }
35
+ let grand_total = subtotal;
36
+ let gst_amount = 0;
37
+ const gst = data.gst ?? 0;
38
+ if (data.is_gst_inclusive) {
39
+ gst_amount = parseFloatCeil((grand_total * gst) / (100 + gst));
40
+ }
41
+ else {
42
+ gst_amount = getPercentageAmount(grand_total, gst);
43
+ grand_total += gst_amount;
44
+ }
45
+ const { cardCharges, amountCollected } = getCardChargesAndAmountCollected(data.payments);
46
+ grand_total += cardCharges;
47
+ grand_total = parseNum(grand_total);
48
+ const amount_collected = parseNum(amountCollected);
49
+ const amount_earned = parseNum(grand_total - cardCharges);
50
+ if (calculateItemMetadata) {
51
+ let leftGrossAmount = subtotal;
52
+ let leftNetAmount = subtotal;
53
+ let leftDiscountAmount = 0;
54
+ let leftGstAmount = gst_amount;
55
+ categories.forEach((category, categoryIndex) => {
56
+ const isLastCategory = categoryIndex === categories.length - 1;
57
+ category.items.forEach((item, itemIndex) => {
58
+ const isLastItem = isLastCategory && itemIndex === category.items.length - 1;
59
+ let grossAmount = item.subtotal;
60
+ let netAmount = item.subtotal;
61
+ let itemTotalDiscountAmount = 0;
62
+ let itemGst = 0;
63
+ if (gst_amount > 0) {
64
+ itemGst = (item.subtotal / subtotal) * gst_amount;
65
+ }
66
+ grossAmount = parseFloatCeil(grossAmount);
67
+ const netAmountParsed = parseFloatCeil(netAmount);
68
+ const itemTotalDiscountAmountParsed = parseFloatCeil(itemTotalDiscountAmount);
69
+ itemGst = parseFloatCeil(itemGst);
70
+ leftGrossAmount -= grossAmount;
71
+ leftNetAmount -= netAmountParsed;
72
+ leftDiscountAmount -= itemTotalDiscountAmountParsed;
73
+ leftGstAmount -= itemGst;
74
+ if (isLastItem) {
75
+ grossAmount += leftGrossAmount;
76
+ netAmount += leftNetAmount;
77
+ itemTotalDiscountAmount += leftDiscountAmount;
78
+ itemGst += leftGstAmount;
79
+ }
80
+ item._gross_amount = Math.max(grossAmount, 0);
81
+ item._net_amount = Math.max(netAmount, 0);
82
+ item._discount_amount = Math.max(itemTotalDiscountAmount, 0);
83
+ item._gst_amount = Math.max(itemGst, 0);
84
+ });
85
+ });
86
+ }
87
+ const cartData = {
88
+ ...data,
89
+ categories,
90
+ amount_collected,
91
+ amount_earned,
92
+ gst_amount,
93
+ price: parseNum(subtotal),
94
+ grand_total,
95
+ };
96
+ return cartData;
97
+ }
98
+ export const getTenantPurchaseOrderItemComparableData = (item) => ({
99
+ item_id: item.item_id,
100
+ name: item.name,
101
+ price: item.price,
102
+ special_instructions: item.special_instructions,
103
+ _id: item._id,
104
+ quantity: item.quantity,
105
+ });
106
+ const getUpdatedTenantPurchaseOrderItem = (item) => ({
107
+ item_id: item.item_id,
108
+ name: item.name,
109
+ price: item.price,
110
+ special_instructions: item.special_instructions,
111
+ });
112
+ export function getUpdatedTenantPurchaseOrderCartInfoOnInit(data, order) {
113
+ const merged = { ...data, ...order };
114
+ return calculateCartTenantPurchaseOrderInfoAndSyncData(merged);
115
+ }
116
+ export function getRemoveItemFromTenantPurchaseOrderCartData(data, payload) {
117
+ const orderItemIdsMap = {};
118
+ let categories;
119
+ if (data.categories != null) {
120
+ categories = [];
121
+ for (let i = 0; i < data.categories.length; i++) {
122
+ const category = data.categories[i];
123
+ const items = [];
124
+ for (let j = 0; j < category.items.length; j++) {
125
+ const item = category.items[j];
126
+ if (item._id !== payload._id) {
127
+ items.push(item);
128
+ orderItemIdsMap[item._id] = item.quantity;
129
+ }
130
+ }
131
+ if (items.length > 0) {
132
+ categories.push({ ...category, items });
133
+ }
134
+ }
135
+ }
136
+ const iterations = [];
137
+ if (data.iterations != null && data.iterations.length > 0) {
138
+ const [firstIteration, ...restIterations] = data.iterations;
139
+ const firstIterationCategories = [];
140
+ for (let i = 0; i < firstIteration.categories.length; i++) {
141
+ const category = firstIteration.categories[i];
142
+ const allPrevItems = [];
143
+ for (let j = 0; j < category.items.length; j++) {
144
+ const prevItem = category.items[j];
145
+ if (prevItem._id === payload._id && payload.void_reason != null) {
146
+ allPrevItems.push({ ...prevItem, void_reason: payload.void_reason });
147
+ }
148
+ else {
149
+ const currentItemQuantity = orderItemIdsMap[prevItem._id];
150
+ const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
151
+ if (isRemovedItem) {
152
+ allPrevItems.push(prevItem);
153
+ }
154
+ else {
155
+ const updatedPrevItem = { ...prevItem };
156
+ delete updatedPrevItem.void_reason;
157
+ allPrevItems.push(updatedPrevItem);
158
+ }
159
+ }
160
+ }
161
+ if (allPrevItems.length > 0) {
162
+ firstIterationCategories.push({ ...category, items: allPrevItems });
163
+ }
164
+ }
165
+ iterations.push({ ...firstIteration, categories: firstIterationCategories });
166
+ iterations.push(...restIterations);
167
+ }
168
+ const order = {
169
+ ...data,
170
+ ...(iterations.length > 0 && { iterations }),
171
+ categories,
172
+ };
173
+ return calculateCartTenantPurchaseOrderInfoAndSyncData(order);
174
+ }
175
+ export function getUpdateTenantPurchaseOrderCartInfoData(data, payload) {
176
+ const order = { ...data, ...payload };
177
+ return calculateCartTenantPurchaseOrderInfoAndSyncData(order);
178
+ }
179
+ export function getAddItemToTenantPurchaseOrderCartData(data, payload) {
180
+ const { category_id, name, item, replace_id } = payload;
181
+ const orderData = { ...data };
182
+ const categories = [...(orderData.categories ?? [])];
183
+ let didFindCategory = false;
184
+ for (let i = 0; i < categories.length; i++) {
185
+ const category = categories[i];
186
+ if (category.category_id !== category_id)
187
+ continue;
188
+ const updatedItem = getUpdatedTenantPurchaseOrderItem(item);
189
+ const allItems = [...category.items];
190
+ let didFindItem = false;
191
+ let itemExists = false;
192
+ for (let j = 0; j < allItems.length; j++) {
193
+ if (allItems[j]._id === item._id) {
194
+ allItems[j] = item;
195
+ didFindItem = true;
196
+ break;
197
+ }
198
+ if (allItems[j].item_id === item.item_id) {
199
+ itemExists = true;
200
+ }
201
+ }
202
+ if (!didFindItem && itemExists) {
203
+ for (let j = 0; j < allItems.length; j++) {
204
+ const itm = allItems[j];
205
+ if (itm.item_id === item.item_id &&
206
+ isEqual(getUpdatedTenantPurchaseOrderItem(itm), updatedItem)) {
207
+ allItems[j] = {
208
+ ...item,
209
+ _id: replace_id ?? itm._id,
210
+ quantity: item.quantity + itm.quantity,
211
+ };
212
+ didFindItem = true;
213
+ break;
214
+ }
215
+ }
216
+ }
217
+ if (!didFindItem) {
218
+ allItems.push(item);
219
+ }
220
+ categories[i] = { ...category, items: allItems };
221
+ didFindCategory = true;
222
+ break;
223
+ }
224
+ if (!didFindCategory) {
225
+ categories.push({ category_id, name, items: [item] });
226
+ }
227
+ const iterations = [];
228
+ if (orderData.iterations != null && orderData.iterations.length > 0) {
229
+ const orderItemIdsMap = {};
230
+ for (const cat of categories) {
231
+ for (const itm of cat.items) {
232
+ orderItemIdsMap[itm._id] = itm.quantity;
233
+ }
234
+ }
235
+ const [firstIteration, ...restIterations] = orderData.iterations;
236
+ const firstIterationCategories = [];
237
+ for (const cat of firstIteration.categories) {
238
+ const allPrevItems = [];
239
+ for (const prevItem of cat.items) {
240
+ const currentItemQuantity = orderItemIdsMap[prevItem._id];
241
+ const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
242
+ if (isRemovedItem) {
243
+ allPrevItems.push(prevItem);
244
+ }
245
+ else {
246
+ const updatedPrevItem = { ...prevItem };
247
+ delete updatedPrevItem.void_reason;
248
+ allPrevItems.push(updatedPrevItem);
249
+ }
250
+ }
251
+ if (allPrevItems.length > 0) {
252
+ firstIterationCategories.push({ ...cat, items: allPrevItems });
253
+ }
254
+ }
255
+ iterations.push({ ...firstIteration, categories: firstIterationCategories });
256
+ iterations.push(...restIterations);
257
+ }
258
+ const order = {
259
+ ...orderData,
260
+ ...(iterations.length > 0 && { iterations }),
261
+ categories,
262
+ };
263
+ return calculateCartTenantPurchaseOrderInfoAndSyncData(order);
264
+ }
265
+ export function getUpdateItemInTenantPurchaseOrderCartData(data, payload) {
266
+ const orderItemIdsMap = {};
267
+ let categories;
268
+ if (data.categories != null) {
269
+ categories = [];
270
+ for (let i = 0; i < data.categories.length; i++) {
271
+ const category = data.categories[i];
272
+ const items = [];
273
+ for (let j = 0; j < category.items.length; j++) {
274
+ const item = category.items[j];
275
+ let newItem = item;
276
+ if (item._id === payload._id) {
277
+ newItem = { ...item, ...payload };
278
+ }
279
+ if (newItem.quantity > 0) {
280
+ items.push(newItem);
281
+ orderItemIdsMap[newItem._id] = newItem.quantity;
282
+ }
283
+ }
284
+ if (items.length > 0) {
285
+ categories.push({ ...category, items });
286
+ }
287
+ }
288
+ }
289
+ const iterations = [];
290
+ if (payload.quantity != null && data.iterations != null && data.iterations.length > 0) {
291
+ const [firstIteration, ...restIterations] = data.iterations;
292
+ const firstIterationCategories = [];
293
+ for (const cat of firstIteration.categories) {
294
+ const allPrevItems = [];
295
+ for (const prevItem of cat.items) {
296
+ if (prevItem._id === payload._id && payload.void_reason != null) {
297
+ allPrevItems.push({ ...prevItem, void_reason: payload.void_reason });
298
+ }
299
+ else {
300
+ const currentItemQuantity = orderItemIdsMap[prevItem._id];
301
+ const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
302
+ if (isRemovedItem) {
303
+ allPrevItems.push(prevItem);
304
+ }
305
+ else {
306
+ const updatedPrevItem = { ...prevItem };
307
+ delete updatedPrevItem.void_reason;
308
+ allPrevItems.push(updatedPrevItem);
309
+ }
310
+ }
311
+ }
312
+ if (allPrevItems.length > 0) {
313
+ firstIterationCategories.push({ ...cat, items: allPrevItems });
314
+ }
315
+ }
316
+ iterations.push({ ...firstIteration, categories: firstIterationCategories });
317
+ iterations.push(...restIterations);
318
+ }
319
+ const order = {
320
+ ...data,
321
+ ...(iterations.length > 0 && { iterations }),
322
+ categories,
323
+ };
324
+ return calculateCartTenantPurchaseOrderInfoAndSyncData(order);
325
+ }
326
+ export function getUpdateItemsInTenantPurchaseOrderCartData(data, payload) {
327
+ return payload.reduce((acc, item) => getUpdateItemInTenantPurchaseOrderCartData(acc, item), data);
328
+ }
329
+ export function getSplitTenantPurchaseOrderCartItemToTwo({ data, orderItemId, }) {
330
+ if (data.categories == null)
331
+ return data;
332
+ const newCategories = [];
333
+ for (let i = 0; i < data.categories.length; i++) {
334
+ const category = data.categories[i];
335
+ const newItems = [];
336
+ for (let j = 0; j < category.items.length; j++) {
337
+ const item = {
338
+ ...category.items[j],
339
+ };
340
+ if (item._id !== orderItemId) {
341
+ newItems.push(item);
342
+ continue;
343
+ }
344
+ if (item.quantity === 1) {
345
+ newItems.push(item);
346
+ continue;
347
+ }
348
+ const prevQuantity = item.quantity;
349
+ const newQuantity = item.quantity - 1;
350
+ const prevItem = {
351
+ ...item,
352
+ quantity: newQuantity,
353
+ subtotal: parseNum(item.price * newQuantity),
354
+ };
355
+ newItems.push(prevItem);
356
+ const _id = new ObjectID(Math.floor(new ObjectID(item._id).getTimestamp().getTime() / 1000) + 1).toHexString();
357
+ newItems.push({
358
+ ...item,
359
+ _id,
360
+ quantity: 1,
361
+ subtotal: parseNum(item.price * 1),
362
+ });
363
+ }
364
+ newCategories.push({
365
+ ...category,
366
+ items: newItems,
367
+ });
368
+ }
369
+ const order = {
370
+ ...data,
371
+ categories: newCategories,
372
+ };
373
+ const newData = calculateCartTenantPurchaseOrderInfoAndSyncData(order);
374
+ return newData;
375
+ }
376
+ export function getAddItemsToTenantPurchaseOrderCartData(data, payload) {
377
+ const newData = payload.reduce((acc, item) => getAddItemToTenantPurchaseOrderCartData(acc, item), data);
378
+ return newData;
379
+ }