@managesome/eposmatic-toolkit 0.2.454 → 0.2.457

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 (190) hide show
  1. package/lib/constants/WORKER_ENDPOINTS.d.ts +2 -0
  2. package/lib/constants/WORKER_ENDPOINTS.js +3 -0
  3. package/lib/helpers/store/common-warehouse-internal-movement-actions.d.ts +12 -0
  4. package/lib/helpers/store/common-warehouse-internal-movement-actions.js +33 -0
  5. package/lib/helpers/store/common-warehouse-purchase-order-receipt-actions.d.ts +12 -0
  6. package/lib/helpers/store/common-warehouse-purchase-order-receipt-actions.js +37 -0
  7. package/lib/helpers/store/index.d.ts +2 -0
  8. package/lib/helpers/store/index.js +2 -0
  9. package/lib/helpers/types/workers.d.ts +16 -1
  10. package/lib/schemas/models/index.d.ts +1 -0
  11. package/lib/schemas/models/index.js +1 -0
  12. package/lib/schemas/models/warehouse_internal_movements.d.ts +3 -3
  13. package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.d.ts +3 -3
  14. package/lib/schemas/models/warehouse_sale_deliveries.d.ts +3 -3
  15. package/lib/schemas/models/warehouse_sale_invoices.d.ts +3 -3
  16. package/lib/schemas/types/index.d.ts +2 -0
  17. package/lib/schemas/types/index.js +2 -0
  18. package/package.json +1 -1
  19. package/lib/constants/PURCHASE_ORDER.d.ts +0 -16
  20. package/lib/constants/PURCHASE_ORDER.js +0 -100
  21. package/lib/constants/RFQ.d.ts +0 -0
  22. package/lib/constants/RFQ.js +0 -1
  23. package/lib/helpers/order/generate-purchase-order-rfq.d.ts +0 -3
  24. package/lib/helpers/order/generate-purchase-order-rfq.js +0 -64
  25. package/lib/helpers/order/generate-purchase-order.d.ts +0 -11
  26. package/lib/helpers/order/generate-purchase-order.js +0 -196
  27. package/lib/helpers/store/all-purchase-orders-actions.d.ts +0 -13
  28. package/lib/helpers/store/all-purchase-orders-actions.js +0 -56
  29. package/lib/helpers/store/all-sale-orders-actions.d.ts +0 -2
  30. package/lib/helpers/store/all-sale-orders-actions.js +0 -8
  31. package/lib/helpers/store/all-warehouse-sale-orders-actions.d.ts +0 -2
  32. package/lib/helpers/store/all-warehouse-sale-orders-actions.js +0 -8
  33. package/lib/helpers/store/common-purchase-order-actions.d.ts +0 -31
  34. package/lib/helpers/store/common-purchase-order-actions.js +0 -543
  35. package/lib/helpers/store/common-sale-order-actions.d.ts +0 -5
  36. package/lib/helpers/store/common-sale-order-actions.js +0 -65
  37. package/lib/helpers/store/purchase-order-rfq-cart-actions.d.ts +0 -19
  38. package/lib/helpers/store/purchase-order-rfq-cart-actions.js +0 -373
  39. package/lib/helpers/store/purchase-orders-cart-actions.d.ts +0 -57
  40. package/lib/helpers/store/purchase-orders-cart-actions.js +0 -486
  41. package/lib/helpers/types/purchase-order-cart-actions.d.ts +0 -26
  42. package/lib/helpers/types/purchase-order-cart-actions.js +0 -2
  43. package/lib/helpers/utils/invoice-x-report-helpers.d.ts +0 -58
  44. package/lib/helpers/utils/invoice-x-report-helpers.js +0 -1432
  45. package/lib/helpers/utils/purchase-order-engine.d.ts +0 -9
  46. package/lib/helpers/utils/purchase-order-engine.js +0 -34
  47. package/lib/helpers/utils/purchase-order-receipt-engine.d.ts +0 -149
  48. package/lib/helpers/utils/purchase-order-receipt-engine.js +0 -214
  49. package/lib/helpers/utils/purchase-order-x-report-helpers.d.ts +0 -58
  50. package/lib/helpers/utils/purchase-order-x-report-helpers.js +0 -1440
  51. package/lib/helpers/utils/sale-order-x-report-helpers.d.ts +0 -44
  52. package/lib/helpers/utils/sale-order-x-report-helpers.js +0 -22
  53. package/lib/helpers/utils/sale-x-report-helpers.d.ts +0 -58
  54. package/lib/helpers/utils/sale-x-report-helpers.js +0 -1456
  55. package/lib/helpers/utils/terminal-devices-helpers.d.ts +0 -2
  56. package/lib/helpers/utils/terminal-devices-helpers.js +0 -13
  57. package/lib/helpers/utils/void-purchase-order-items-helpers.d.ts +0 -3
  58. package/lib/helpers/utils/void-purchase-order-items-helpers.js +0 -38
  59. package/lib/helpers/utils/void-purchase-order-items-report-helpers.d.ts +0 -13
  60. package/lib/helpers/utils/void-purchase-order-items-report-helpers.js +0 -22
  61. package/lib/schemas/models/applied-order-discounts.d.ts +0 -80
  62. package/lib/schemas/models/applied-order-discounts.js +0 -106
  63. package/lib/schemas/models/brand.d.ts +0 -45
  64. package/lib/schemas/models/brand.js +0 -45
  65. package/lib/schemas/models/category.d.ts +0 -60
  66. package/lib/schemas/models/category.js +0 -67
  67. package/lib/schemas/models/dinein_table_fingerprints.d.ts +0 -65
  68. package/lib/schemas/models/dinein_table_fingerprints.js +0 -85
  69. package/lib/schemas/models/expense_category.d.ts +0 -83
  70. package/lib/schemas/models/expense_category.js +0 -64
  71. package/lib/schemas/models/internal_movements.d.ts +0 -357
  72. package/lib/schemas/models/internal_movements.js +0 -323
  73. package/lib/schemas/models/inventory.d.ts +0 -99
  74. package/lib/schemas/models/inventory.js +0 -87
  75. package/lib/schemas/models/inventory_lot_serial_numbers.d.ts +0 -154
  76. package/lib/schemas/models/inventory_lot_serial_numbers.js +0 -193
  77. package/lib/schemas/models/item.d.ts +0 -11269
  78. package/lib/schemas/models/item.js +0 -333
  79. package/lib/schemas/models/menu.d.ts +0 -941
  80. package/lib/schemas/models/menu.js +0 -69
  81. package/lib/schemas/models/order.d.ts +0 -15437
  82. package/lib/schemas/models/order.js +0 -891
  83. package/lib/schemas/models/purchase_order_receipts.d.ts +0 -165
  84. package/lib/schemas/models/purchase_order_receipts.js +0 -151
  85. package/lib/schemas/models/purchase_order_rfq.d.ts +0 -1959
  86. package/lib/schemas/models/purchase_order_rfq.js +0 -328
  87. package/lib/schemas/models/purchase_order_rfqs.d.ts +0 -1959
  88. package/lib/schemas/models/purchase_order_rfqs.js +0 -328
  89. package/lib/schemas/models/purchase_order_vendor_returns.d.ts +0 -234
  90. package/lib/schemas/models/purchase_order_vendor_returns.js +0 -188
  91. package/lib/schemas/models/purchase_orders.d.ts +0 -2678
  92. package/lib/schemas/models/purchase_orders.js +0 -336
  93. package/lib/schemas/models/rider.d.ts +0 -65
  94. package/lib/schemas/models/rider.js +0 -74
  95. package/lib/schemas/models/sale_order_deliveries.d.ts +0 -167
  96. package/lib/schemas/models/sale_order_deliveries.js +0 -155
  97. package/lib/schemas/models/sale_order_invoices.d.ts +0 -227
  98. package/lib/schemas/models/sale_order_invoices.js +0 -206
  99. package/lib/schemas/models/sale_order_rfq.d.ts +0 -1938
  100. package/lib/schemas/models/sale_order_rfq.js +0 -309
  101. package/lib/schemas/models/sale_orders.d.ts +0 -1943
  102. package/lib/schemas/models/sale_orders.js +0 -324
  103. package/lib/schemas/models/tenant.d.ts +0 -528
  104. package/lib/schemas/models/tenant.js +0 -755
  105. package/lib/schemas/models/tenant_staff.d.ts +0 -932
  106. package/lib/schemas/models/tenant_staff.js +0 -96
  107. package/lib/schemas/models/track_order_number.d.ts +0 -413
  108. package/lib/schemas/models/track_order_number.js +0 -45
  109. package/lib/schemas/models/void_purchase_order_items.d.ts +0 -176
  110. package/lib/schemas/models/void_purchase_order_items.js +0 -177
  111. package/lib/schemas/models/void_warehouse_invoice_items.d.ts +0 -176
  112. package/lib/schemas/models/void_warehouse_invoice_items.js +0 -176
  113. package/lib/schemas/models/wallet.d.ts +0 -38
  114. package/lib/schemas/models/wallet.js +0 -37
  115. package/lib/schemas/models/warehouse-communications.d.ts +0 -228
  116. package/lib/schemas/models/warehouse-communications.js +0 -216
  117. package/lib/schemas/models/warehouse.d.ts +0 -162
  118. package/lib/schemas/models/warehouse.js +0 -222
  119. package/lib/schemas/models/warehouse_staff.d.ts +0 -65
  120. package/lib/schemas/models/warehouse_staff.js +0 -78
  121. package/lib/schemas/models/warehouse_track_order_number.d.ts +0 -50
  122. package/lib/schemas/models/warehouse_track_order_number.js +0 -52
  123. package/lib/schemas/types/applied-order-discounts.d.ts +0 -22
  124. package/lib/schemas/types/applied-order-discounts.js +0 -2
  125. package/lib/schemas/types/brand.d.ts +0 -32
  126. package/lib/schemas/types/brand.js +0 -2
  127. package/lib/schemas/types/category.d.ts +0 -15
  128. package/lib/schemas/types/category.js +0 -2
  129. package/lib/schemas/types/expense_category.d.ts +0 -20
  130. package/lib/schemas/types/expense_category.js +0 -2
  131. package/lib/schemas/types/internal_movements.d.ts +0 -73
  132. package/lib/schemas/types/internal_movements.js +0 -2
  133. package/lib/schemas/types/inventory.d.ts +0 -48
  134. package/lib/schemas/types/inventory.js +0 -2
  135. package/lib/schemas/types/inventory_lot_serial_numbers.d.ts +0 -85
  136. package/lib/schemas/types/inventory_lot_serial_numbers.js +0 -4
  137. package/lib/schemas/types/item.d.ts +0 -89
  138. package/lib/schemas/types/item.js +0 -2
  139. package/lib/schemas/types/menu.d.ts +0 -17
  140. package/lib/schemas/types/menu.js +0 -2
  141. package/lib/schemas/types/order.d.ts +0 -242
  142. package/lib/schemas/types/order.js +0 -2
  143. package/lib/schemas/types/purchase_order_common.d.ts +0 -39
  144. package/lib/schemas/types/purchase_order_common.js +0 -2
  145. package/lib/schemas/types/purchase_order_receipts.d.ts +0 -39
  146. package/lib/schemas/types/purchase_order_receipts.js +0 -21
  147. package/lib/schemas/types/purchase_order_rfq.d.ts +0 -33
  148. package/lib/schemas/types/purchase_order_rfq.js +0 -2
  149. package/lib/schemas/types/purchase_order_rfqs.d.ts +0 -33
  150. package/lib/schemas/types/purchase_order_rfqs.js +0 -2
  151. package/lib/schemas/types/purchase_order_vendor_returns.d.ts +0 -49
  152. package/lib/schemas/types/purchase_order_vendor_returns.js +0 -42
  153. package/lib/schemas/types/purchase_orders.d.ts +0 -33
  154. package/lib/schemas/types/purchase_orders.js +0 -2
  155. package/lib/schemas/types/rider.d.ts +0 -16
  156. package/lib/schemas/types/rider.js +0 -2
  157. package/lib/schemas/types/sale_order_common.d.ts +0 -39
  158. package/lib/schemas/types/sale_order_common.js +0 -2
  159. package/lib/schemas/types/sale_order_deliveries.d.ts +0 -67
  160. package/lib/schemas/types/sale_order_deliveries.js +0 -2
  161. package/lib/schemas/types/sale_order_invoices.d.ts +0 -49
  162. package/lib/schemas/types/sale_order_invoices.js +0 -2
  163. package/lib/schemas/types/sale_order_rfq.d.ts +0 -25
  164. package/lib/schemas/types/sale_order_rfq.js +0 -2
  165. package/lib/schemas/types/sale_orders.d.ts +0 -30
  166. package/lib/schemas/types/sale_orders.js +0 -2
  167. package/lib/schemas/types/tenant.d.ts +0 -205
  168. package/lib/schemas/types/tenant.js +0 -2
  169. package/lib/schemas/types/tenant_staff.d.ts +0 -22
  170. package/lib/schemas/types/tenant_staff.js +0 -2
  171. package/lib/schemas/types/track_order_number.d.ts +0 -10
  172. package/lib/schemas/types/track_order_number.js +0 -2
  173. package/lib/schemas/types/void_purchase_order_items.d.ts +0 -37
  174. package/lib/schemas/types/void_purchase_order_items.js +0 -2
  175. package/lib/schemas/types/void_warehouse_invoice_items.d.ts +0 -37
  176. package/lib/schemas/types/void_warehouse_invoice_items.js +0 -2
  177. package/lib/schemas/types/wallet.d.ts +0 -7
  178. package/lib/schemas/types/wallet.js +0 -2
  179. package/lib/schemas/types/warehouse-communications.d.ts +0 -54
  180. package/lib/schemas/types/warehouse-communications.js +0 -2
  181. package/lib/schemas/types/warehouse.d.ts +0 -49
  182. package/lib/schemas/types/warehouse.js +0 -2
  183. package/lib/schemas/types/warehouse_purchase_order_common.d.ts +0 -39
  184. package/lib/schemas/types/warehouse_purchase_order_common.js +0 -2
  185. package/lib/schemas/types/warehouse_sale_order_common.d.ts +0 -39
  186. package/lib/schemas/types/warehouse_sale_order_common.js +0 -2
  187. package/lib/schemas/types/warehouse_staff.d.ts +0 -17
  188. package/lib/schemas/types/warehouse_staff.js +0 -2
  189. package/lib/schemas/types/warehouse_track_order_number.d.ts +0 -11
  190. package/lib/schemas/types/warehouse_track_order_number.js +0 -2
@@ -1,543 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getPurchaseOrderIterationsWithPrice = getPurchaseOrderIterationsWithPrice;
7
- exports.getPurchaseOrderPaymentsWithPrice = getPurchaseOrderPaymentsWithPrice;
8
- exports.getPurchaseOrderItemsWithPrice = getPurchaseOrderItemsWithPrice;
9
- exports.getPurchaseOrderCategoriesWithPrice = getPurchaseOrderCategoriesWithPrice;
10
- exports.getPurchaseOrderWithPrice = getPurchaseOrderWithPrice;
11
- exports.syncPurchaseOrderData = syncPurchaseOrderData;
12
- exports.skipItemMetadataFromPurchaseOrderCategories = skipItemMetadataFromPurchaseOrderCategories;
13
- exports.getPurchaseOrderWithAllFields = getPurchaseOrderWithAllFields;
14
- exports.getPurchaseOrderCartItemsObj = getPurchaseOrderCartItemsObj;
15
- exports.getVoidItemsWithReasonPurchaseOrder = getVoidItemsWithReasonPurchaseOrder;
16
- const bson_objectid_1 = __importDefault(require("bson-objectid"));
17
- const lodash_1 = require("lodash");
18
- const constants_1 = require("../../constants");
19
- const utils_1 = require("../utils");
20
- const common_order_actions_1 = require("./common-order-actions");
21
- const purchase_orders_cart_actions_1 = require("./purchase-orders-cart-actions");
22
- function getPurchaseOrderIterationsWithPrice(iterations, writeable) {
23
- if (!iterations)
24
- return [];
25
- return iterations.map((iteration) => getPurchaseOrderWithPrice(iteration, writeable));
26
- }
27
- function getPurchaseOrderPaymentsWithPrice(payments, convertToPrice) {
28
- if (!payments)
29
- return [];
30
- return payments.map((payment) => ({
31
- ...payment,
32
- card_details: (0, common_order_actions_1.getOrderPaymentsCardDetailsWithPrice)(payment.card_details, convertToPrice),
33
- amount_paid: convertToPrice(payment.amount_paid),
34
- amount_due: convertToPrice(payment.amount_due),
35
- amount_refunded: convertToPrice(payment.amount_refunded),
36
- }));
37
- }
38
- function getPurchaseOrderItemsWithPrice(items, convertToPrice) {
39
- if (!items)
40
- return [];
41
- return items.map((item) => ({
42
- ...item,
43
- quantity: (0, utils_1.parseNum)(item.quantity || 1, true),
44
- price: convertToPrice(item.price ?? 0),
45
- subtotal: convertToPrice(item.subtotal ?? 0),
46
- _gst_amount: convertToPrice(item._gst_amount ?? 0),
47
- _net_amount: convertToPrice(item._net_amount ?? 0),
48
- _gross_amount: convertToPrice(item._gross_amount ?? 0),
49
- _discount_amount: convertToPrice(item._discount_amount ?? 0),
50
- }));
51
- }
52
- function getPurchaseOrderCategoriesWithPrice(categories, convertToPrice) {
53
- if (!categories)
54
- return [];
55
- return categories.map((category) => ({
56
- ...category,
57
- items: getPurchaseOrderItemsWithPrice(category.items, convertToPrice),
58
- }));
59
- }
60
- function getPurchaseOrderWithPrice(order, writeable) {
61
- const convertToPrice = writeable ? utils_1.convertDecimalToInt : utils_1.convertIntToDecimal;
62
- const payload = {
63
- ...order,
64
- ...(order.iterations != null
65
- ? {
66
- iterations: getPurchaseOrderIterationsWithPrice(order.iterations, writeable),
67
- }
68
- : {}),
69
- ...(order.categories != null
70
- ? {
71
- categories: getPurchaseOrderCategoriesWithPrice(order.categories, convertToPrice),
72
- }
73
- : {}),
74
- ...(order.payments != null ? { payments: getPurchaseOrderPaymentsWithPrice(order.payments, convertToPrice) } : {}),
75
- ...(order.gst != null ? { gst: convertToPrice(order.gst) } : {}),
76
- ...(order.gst_amount != null ? { gst_amount: convertToPrice(order.gst_amount) } : {}),
77
- ...(order.amount_collected != null
78
- ? { amount_collected: convertToPrice(order.amount_collected) }
79
- : {}),
80
- ...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
81
- ...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
82
- ...(order.price != null ? { price: convertToPrice(order.price) } : {}),
83
- };
84
- return payload;
85
- }
86
- function syncPurchaseOrderData(order) {
87
- const updatedOrder = {
88
- ...order,
89
- iterations: [],
90
- };
91
- const newOrder = getPurchaseOrderWithPrice((0, purchase_orders_cart_actions_1.calculateCartPurchaseOrderInfoAndSyncData)(getPurchaseOrderWithPrice(updatedOrder), true), true);
92
- newOrder.iterations = order.iterations;
93
- return newOrder;
94
- }
95
- function skipItemMetadataFromPurchaseOrderCategories(categories, previousCategories) {
96
- return categories.map((category) => {
97
- const previousCategory = previousCategories?.find((prevCategory) => prevCategory.category_id === category.category_id);
98
- return {
99
- ...category,
100
- items: category.items.map((item) => {
101
- const previousItem = previousCategory?.items.find((prevItem) => prevItem._id === item._id);
102
- const void_reason = previousItem?.void_reason ?? item.void_reason;
103
- const newItem = {
104
- ...item,
105
- void_reason,
106
- _discount_amount: 0,
107
- _gst_amount: 0,
108
- _gross_amount: 0,
109
- _net_amount: 0,
110
- };
111
- return newItem;
112
- }),
113
- };
114
- });
115
- }
116
- function getCommonOptionalBoolFieldsPurchaseOrder(order, partial) {
117
- const defaultValue = partial ? undefined : false;
118
- return {
119
- is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
120
- is_reopened: order['is_reopened'] || defaultValue,
121
- };
122
- }
123
- function getCommonOptionalNumFieldsPurchaseOrder(order, partial) {
124
- const defaultValue = partial ? undefined : 0;
125
- return {
126
- gst: order['gst'] || defaultValue,
127
- gst_amount: order['gst_amount'] || defaultValue,
128
- };
129
- }
130
- function getPurchaseOrderWithAllFields(order, skipItemMetadata) {
131
- return {
132
- ...order,
133
- ...getCommonOptionalBoolFieldsPurchaseOrder(order, false),
134
- ...getCommonOptionalNumFieldsPurchaseOrder(order, false),
135
- ...(skipItemMetadata && order.categories != null
136
- ? {
137
- categories: skipItemMetadataFromPurchaseOrderCategories(order.categories),
138
- }
139
- : {}),
140
- delete_reason: order['delete_reason'] ?? null,
141
- cancel_reason: order['cancel_reason'] ?? null,
142
- };
143
- }
144
- function getPurchaseOrderCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId = true, isAnEdit, sortType, }) {
145
- const newMappedItems = { ...mappedItems };
146
- if (Object.keys(newMappedItems).length === 0) {
147
- previousIterationCategories?.forEach((category) => {
148
- category.items.forEach((item) => {
149
- if (newMappedItems[item.item_id] == null) {
150
- newMappedItems[item.item_id] = {
151
- _id: item.item_id,
152
- name: item.name,
153
- category_id: category.category_id,
154
- category_name: category.name,
155
- category_image_url: '',
156
- image_url: '',
157
- description: '',
158
- };
159
- }
160
- });
161
- });
162
- currentIterationCategories?.forEach((category) => {
163
- category.items.forEach((item) => {
164
- if (newMappedItems[item.item_id] == null) {
165
- newMappedItems[item.item_id] = {
166
- _id: item.item_id,
167
- name: item.name,
168
- category_id: category.category_id,
169
- category_name: category.name,
170
- category_image_url: '',
171
- image_url: '',
172
- description: '',
173
- };
174
- }
175
- });
176
- });
177
- }
178
- // =====================><=====================
179
- const getCartItems = (items) => {
180
- const orderItems = items.map((item) => {
181
- const selectedItem = newMappedItems[item.item_id] ?? {};
182
- return {
183
- orderItem: item,
184
- image_url: selectedItem.image_url ?? '',
185
- description: selectedItem.description ?? '',
186
- category_name: selectedItem.category_name ?? '',
187
- category_id: selectedItem.category_id ?? '',
188
- };
189
- });
190
- if (shouldSortItemsViaId) {
191
- if (sortType === constants_1.SORT_TYPE_ENUM.DESC) {
192
- orderItems.sort((a, b) => (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime());
193
- }
194
- else {
195
- orderItems.sort((a, b) => (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime());
196
- }
197
- }
198
- return orderItems;
199
- };
200
- // =====================><=====================
201
- /*
202
- If the order has iterations in it, then we get the last iteration.
203
- We would compare the changes in the last iteration with the current iteration
204
- and show the changes in the cart.
205
- */
206
- let totalItemsInCart = 0;
207
- const currentItems = [];
208
- if (currentIterationCategories != null) {
209
- for (let i = 0; i < currentIterationCategories.length; i++) {
210
- const category = currentIterationCategories[i];
211
- for (let j = 0; j < category.items.length; j++) {
212
- const item = { ...category.items[j] };
213
- currentItems.push(item);
214
- totalItemsInCart += item.quantity;
215
- }
216
- }
217
- }
218
- let unChangedItems = currentItems;
219
- const editedItems = [];
220
- let removedItems = [];
221
- let newItems = [];
222
- let disabledReason = '';
223
- // If previous iteration exists, then it's an update to the order.
224
- // In that case we would keep the previous iteration as it is and
225
- // compare the current iteration with the previous iteration.
226
- // If the current iteration is different from the previous iteration in any way
227
- // then we would update the current iteration with only those items that are different
228
- const isAnUpdate = isAnEdit ?? (previousIterationCategories != null && previousIterationCategories.length > 0);
229
- if (isAnUpdate) {
230
- // we need to compare the current iteration with the previous iteration
231
- const currentItemsMap = currentItems.reduce((acc, currentItem) => {
232
- acc[currentItem._id] = currentItem;
233
- return acc;
234
- }, {});
235
- const prevItems = [];
236
- const prevItemsMap = {};
237
- const prevCategories = previousIterationCategories ?? [];
238
- for (let i = 0; i < prevCategories.length; i++) {
239
- const category = prevCategories[i];
240
- for (let j = 0; j < category.items.length; j++) {
241
- const prevItem = category.items[j];
242
- let item = prevItem;
243
- const currentItem = currentItemsMap[prevItem._id];
244
- if (currentItem != null && currentItem.is_ready != null) {
245
- item = {
246
- ...item,
247
- is_ready: currentItem.is_ready,
248
- };
249
- }
250
- prevItems.push(item);
251
- prevItemsMap[item._id] = item;
252
- }
253
- }
254
- // NOTE: We will always set the items from currentItemsMap because we are dealing with current iteration
255
- unChangedItems = [];
256
- let totalTempRemovedItems = 0;
257
- for (let i = 0; i < prevItems.length; i++) {
258
- const prevItem = {
259
- ...prevItems[i],
260
- };
261
- const currentItem = {
262
- ...currentItemsMap[prevItem._id],
263
- };
264
- // Step 1: Get the items that are not present in the current iteration
265
- if (currentItemsMap[prevItem._id] == null) {
266
- removedItems.push(prevItem);
267
- }
268
- // Step 2: Get the items that are same in the current iteration
269
- else if ((0, lodash_1.isEqual)((0, purchase_orders_cart_actions_1.getPurchaseOrderItemComaparableData)(currentItem), (0, purchase_orders_cart_actions_1.getPurchaseOrderItemComaparableData)(prevItem))) {
270
- unChangedItems.push(prevItem);
271
- }
272
- // Step 3: Get the items that are present in the previous iteration but
273
- // This is turn for edit items
274
- // but we change logic for display purpose
275
- else {
276
- const currQty = currentItem.quantity;
277
- const prevQty = prevItem.quantity;
278
- if (currQty !== prevQty) {
279
- const subtotalForOne = currentItem.subtotal / currentItem.quantity;
280
- // currQty = 8
281
- // prevQty = 3
282
- // diff = 5
283
- const diff = currQty - prevQty;
284
- const changeQty = Math.abs(diff);
285
- const itm = {
286
- ...currentItem,
287
- quantity: changeQty,
288
- subtotal: (0, utils_1.parseNum)(changeQty * subtotalForOne),
289
- };
290
- if (diff > 0) {
291
- // We need to show it as a new item
292
- newItems.push(itm);
293
- const unchangedQty = currQty - changeQty;
294
- const tempUnchangedItm = {
295
- ...currentItem,
296
- quantity: unchangedQty,
297
- subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
298
- };
299
- unChangedItems.push(tempUnchangedItm);
300
- }
301
- else {
302
- itm.void_reason = prevItem.void_reason ?? currentItem.void_reason;
303
- // We need to show it as a removed item
304
- removedItems.push(itm);
305
- const unchangedQty = prevQty - changeQty;
306
- const tempUnchangedItm = {
307
- ...currentItem,
308
- quantity: unchangedQty,
309
- subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
310
- };
311
- unChangedItems.push(tempUnchangedItm);
312
- totalTempRemovedItems++;
313
- }
314
- }
315
- else {
316
- const curr = {
317
- _id: currentItem._id,
318
- item_id: currentItem.item_id,
319
- name: currentItem.name,
320
- // price: number;
321
- // subtotal: number;
322
- // tax_rate: number;
323
- // quantity: number;
324
- special_instructions: currentItem.special_instructions,
325
- };
326
- const prev = {
327
- _id: prevItem._id,
328
- item_id: prevItem.item_id,
329
- name: prevItem.name,
330
- // price: number;
331
- // subtotal: number;
332
- // tax_rate: number;
333
- // quantity: number;
334
- special_instructions: prevItem.special_instructions,
335
- };
336
- const isBothEqual = (0, lodash_1.isEqual)(curr, prev);
337
- if (isBothEqual) {
338
- unChangedItems.push(currentItem);
339
- }
340
- else {
341
- // For edited item, we don't need to have tempUnchangedItemIds
342
- // because it's the turn for edited item
343
- editedItems.push(currentItem);
344
- }
345
- }
346
- }
347
- }
348
- // Step 4: Get the items that are present in the current iteration
349
- // but not present in the previous iteration
350
- for (let i = 0; i < currentItems.length; i++) {
351
- const item = currentItems[i];
352
- if (prevItemsMap[item._id] == null) {
353
- newItems.push(item);
354
- }
355
- }
356
- // Lastly, we need to check if any same item has been removed and added
357
- // If so, the we need to remove the item from removedItems and newItems, and add it to unChangedItems
358
- if (removedItems.length > 0 && newItems.length > 0) {
359
- const newItemsMap = newItems.reduce((acc, item) => {
360
- acc[item.item_id] = [...(acc[item.item_id] ?? []), item];
361
- return acc;
362
- }, {});
363
- const revertedRemovedItems = [];
364
- const revertedNewItems = [];
365
- const additionalNewItems = [];
366
- for (let i = 0; i < removedItems.length; i++) {
367
- const removedItem = removedItems[i];
368
- // Need to check if the removed item is present in the newItems
369
- const newItemsForItem = newItemsMap[removedItem.item_id];
370
- if (newItemsForItem == null)
371
- continue;
372
- if (newItemsForItem.length > 0) {
373
- const newItemsForItemLength = newItemsForItem.length;
374
- for (let j = 0; j < newItemsForItemLength; j++) {
375
- const newItem = newItemsForItem[j];
376
- const newI = {
377
- // _id: newItem._id,
378
- item_id: newItem.item_id,
379
- name: newItem.name,
380
- price: newItem.price,
381
- // subtotal: number;
382
- // quantity: newItem.quantity,
383
- special_instructions: newItem.special_instructions,
384
- };
385
- const removedI = {
386
- // _id: removedItem._id,
387
- item_id: removedItem.item_id,
388
- name: removedItem.name,
389
- price: removedItem.price,
390
- // subtotal: number;
391
- // quantity: removedItem.quantity,
392
- special_instructions: removedItem.special_instructions,
393
- };
394
- if ((0, lodash_1.isEqual)(newI, removedI)) {
395
- if (newItem.quantity === removedItem.quantity) {
396
- newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
397
- if (newItemsMap[removedItem.item_id].length === 0) {
398
- delete newItemsMap[removedItem.item_id];
399
- }
400
- revertedNewItems.push(newItem);
401
- revertedRemovedItems.push(removedItem);
402
- // We will break the loop when ever we push to revertedRemovedItems
403
- break;
404
- }
405
- else {
406
- if (removedItem.quantity > newItem.quantity) {
407
- newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
408
- if (newItemsMap[removedItem.item_id].length === 0) {
409
- delete newItemsMap[removedItem.item_id];
410
- }
411
- revertedNewItems.push(newItem);
412
- const subtotalForSingle = removedItem.subtotal / removedItem.quantity;
413
- // We will only minus the quantity from removedItem
414
- const newQuantity = removedItem.quantity - newItem.quantity;
415
- const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
416
- removedItem.quantity = newQuantity;
417
- removedItem.subtotal = newSubtotal;
418
- }
419
- else {
420
- revertedRemovedItems.push(removedItem);
421
- const nQuantity = newItem.quantity;
422
- const subtotalForSingle = newItem.subtotal / nQuantity;
423
- const newQuantity = nQuantity - removedItem.quantity;
424
- const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
425
- newItem.quantity = newQuantity;
426
- newItem.subtotal = newSubtotal;
427
- // =====================><=====================
428
- const remainingQuantity = nQuantity - newQuantity;
429
- const adItem = {
430
- ...newItem,
431
- quantity: remainingQuantity,
432
- subtotal: (0, utils_1.parseNum)(remainingQuantity * subtotalForSingle),
433
- };
434
- additionalNewItems.push(adItem);
435
- // We will break the loop when ever we push to revertedRemovedItems
436
- break;
437
- }
438
- }
439
- }
440
- }
441
- }
442
- else {
443
- delete newItemsMap[removedItem.item_id];
444
- }
445
- }
446
- for (let i = 0; i < revertedRemovedItems.length; i++) {
447
- const rItem = revertedRemovedItems[i];
448
- removedItems = removedItems.filter((item) => item._id !== rItem._id);
449
- }
450
- for (let i = 0; i < revertedNewItems.length; i++) {
451
- const nItem = revertedNewItems[i];
452
- newItems = newItems.filter((item) => item._id !== nItem._id);
453
- unChangedItems.push(nItem);
454
- }
455
- for (let i = 0; i < additionalNewItems.length; i++) {
456
- const aItem = additionalNewItems[i];
457
- unChangedItems.push(aItem);
458
- }
459
- }
460
- disabledReason =
461
- unChangedItems.length === prevItems.length &&
462
- newItems.length === 0 &&
463
- removedItems.length === 0 &&
464
- editedItems.length === 0
465
- ? 'No changes in the order'
466
- : prevItems.length === removedItems.length - totalTempRemovedItems &&
467
- editedItems.length === 0 &&
468
- newItems.length === 0
469
- ? 'At least one item is required'
470
- : '';
471
- }
472
- const cartItemsObj = {
473
- unChangedItems: getCartItems(unChangedItems),
474
- editedItems: getCartItems(editedItems),
475
- removedItems: getCartItems(removedItems),
476
- newItems: getCartItems(newItems),
477
- totalSelectedItems: (0, utils_1.parseNum)(totalItemsInCart, true),
478
- disabledReason,
479
- isAnUpdate,
480
- };
481
- return cartItemsObj;
482
- }
483
- function getVoidItemsWithReasonPurchaseOrder({ currentCategories, iterationsFromFrontend, previousCategories, }) {
484
- const voidOrderItemReasonsMap = {};
485
- const latestIterationCategories = iterationsFromFrontend?.[0]?.categories;
486
- if (latestIterationCategories != null && latestIterationCategories.length > 0) {
487
- for (let i = 0; i < latestIterationCategories.length; i++) {
488
- const category = latestIterationCategories[i];
489
- for (let j = 0; j < category.items.length; j++) {
490
- const item = category.items[j];
491
- if (item.void_reason != null && item.void_reason.length > 0) {
492
- voidOrderItemReasonsMap[item._id] = item.void_reason;
493
- }
494
- }
495
- }
496
- }
497
- const { newItems, removedItems } = getPurchaseOrderCartItemsObj({
498
- currentIterationCategories: currentCategories,
499
- previousIterationCategories: previousCategories,
500
- mappedItems: {},
501
- shouldSortItemsViaId: false,
502
- isAnEdit: true,
503
- });
504
- const hasNewItems = newItems.length > 0;
505
- const voidOrderItems = [];
506
- const newVoidOrderItemReasonsMap = {};
507
- for (let i = 0; i < removedItems.length; i++) {
508
- const { orderItem } = removedItems[i];
509
- const voidReason = voidOrderItemReasonsMap[orderItem._id];
510
- voidOrderItems.push({
511
- ...orderItem,
512
- subtotal: Math.round(orderItem.subtotal),
513
- void_reason: voidReason ?? '-',
514
- });
515
- if (voidReason != null) {
516
- newVoidOrderItemReasonsMap[orderItem._id] = voidReason;
517
- }
518
- }
519
- const newIterationCategories = [];
520
- for (let i = 0; i < previousCategories.length; i++) {
521
- const category = previousCategories[i];
522
- const newCategoryItems = [];
523
- for (let j = 0; j < category.items.length; j++) {
524
- const prevItem = category.items[j];
525
- const voidReason = newVoidOrderItemReasonsMap[prevItem._id];
526
- const orderItem = {
527
- ...prevItem,
528
- subtotal: Math.round(prevItem.subtotal),
529
- };
530
- if (voidReason != null) {
531
- orderItem.void_reason = voidReason;
532
- }
533
- newCategoryItems.push(orderItem);
534
- }
535
- if (newCategoryItems.length === 0)
536
- continue;
537
- newIterationCategories.push({
538
- ...category,
539
- items: newCategoryItems,
540
- });
541
- }
542
- return { newIterationCategories, voidOrderItems, hasNewItems };
543
- }
@@ -1,5 +0,0 @@
1
- import { WarehouseISaleOrder, WarehouseISaleOrderCategory, WarehouseISaleOrderItem, WarehouseISaleOrderIteration } from '../../schemas';
2
- export declare function getSaleOrderIterationsWithPrice(iterations?: WarehouseISaleOrderIteration[] | undefined, writeable?: boolean): WarehouseISaleOrderIteration[];
3
- export declare function getSaleOrderItemsWithPrice(items: WarehouseISaleOrderItem[] | undefined, convertToPrice: (price: number) => number): WarehouseISaleOrderItem[];
4
- export declare function getSaleOrderCategoriesWithPrice(categories: WarehouseISaleOrderCategory[] | undefined, convertToPrice: (price: number) => number): WarehouseISaleOrderCategory[];
5
- export declare function getSaleOrderWithPrice<T extends Partial<WarehouseISaleOrder> | WarehouseISaleOrder | WarehouseISaleOrderIteration>(order: T, writeable?: boolean): T;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSaleOrderIterationsWithPrice = getSaleOrderIterationsWithPrice;
4
- exports.getSaleOrderItemsWithPrice = getSaleOrderItemsWithPrice;
5
- exports.getSaleOrderCategoriesWithPrice = getSaleOrderCategoriesWithPrice;
6
- exports.getSaleOrderWithPrice = getSaleOrderWithPrice;
7
- const utils_1 = require("../utils");
8
- // ── Iterations ──────────────────────────────────────────────────
9
- function getSaleOrderIterationsWithPrice(iterations, writeable) {
10
- if (!iterations)
11
- return [];
12
- return iterations.map((iteration) => getSaleOrderWithPrice(iteration, writeable));
13
- }
14
- // ── Items ───────────────────────────────────────────────────────
15
- function getSaleOrderItemsWithPrice(items, convertToPrice) {
16
- if (!items)
17
- return [];
18
- return items.map((item) => ({
19
- ...item,
20
- quantity: (0, utils_1.parseNum)(item.quantity || 1, true),
21
- price: convertToPrice(item.price ?? 0),
22
- subtotal: convertToPrice(item.subtotal ?? 0),
23
- _gst_amount: convertToPrice(item._gst_amount ?? 0),
24
- _net_amount: convertToPrice(item._net_amount ?? 0),
25
- _gross_amount: convertToPrice(item._gross_amount ?? 0),
26
- _discount_amount: convertToPrice(item._discount_amount ?? 0),
27
- }));
28
- }
29
- // ── Categories ──────────────────────────────────────────────────
30
- function getSaleOrderCategoriesWithPrice(categories, convertToPrice) {
31
- if (!categories)
32
- return [];
33
- return categories.map((category) => ({
34
- ...category,
35
- items: getSaleOrderItemsWithPrice(category.items, convertToPrice),
36
- }));
37
- }
38
- // ── Main helper ─────────────────────────────────────────────────
39
- function getSaleOrderWithPrice(order, writeable) {
40
- const convertToPrice = writeable ? utils_1.convertDecimalToInt : utils_1.convertIntToDecimal;
41
- const payload = {
42
- ...order,
43
- ...(order.iterations != null
44
- ? {
45
- iterations: getSaleOrderIterationsWithPrice(order.iterations, writeable),
46
- }
47
- : {}),
48
- ...(order.categories != null
49
- ? {
50
- categories: getSaleOrderCategoriesWithPrice(order.categories, convertToPrice),
51
- }
52
- : {}),
53
- ...(order.gst != null ? { gst: convertToPrice(order.gst) } : {}),
54
- ...(order.gst_amount != null ? { gst_amount: convertToPrice(order.gst_amount) } : {}),
55
- ...(order.amount_collected != null
56
- ? {
57
- amount_collected: convertToPrice(order.amount_collected),
58
- }
59
- : {}),
60
- ...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
61
- ...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
62
- ...(order.price != null ? { price: convertToPrice(order.price) } : {}),
63
- };
64
- return payload;
65
- }
@@ -1,19 +0,0 @@
1
- import { WarehouseIPurchaseOrderRFQ, WarehouseIPurchaseOrderRFQItem } from '../../schemas';
2
- export declare function calculateCartRfqOrderInfoAndSyncData<T extends WarehouseIPurchaseOrderRFQ | Partial<WarehouseIPurchaseOrderRFQ>>(data: T, calculateItemMetadata?: boolean): T;
3
- export declare function getRemoveItemFromRfqCartData(data: Partial<WarehouseIPurchaseOrderRFQ>, payload: {
4
- _id: string;
5
- void_reason?: string;
6
- }): Partial<WarehouseIPurchaseOrderRFQ>;
7
- export declare function getUpdateRfqCartInfoData(data: Partial<WarehouseIPurchaseOrderRFQ>, payload: Partial<WarehouseIPurchaseOrderRFQ>): Partial<WarehouseIPurchaseOrderRFQ>;
8
- interface ISetAddItemToRfqCartActionPayload {
9
- name: string;
10
- category_id: string;
11
- item: WarehouseIPurchaseOrderRFQItem;
12
- replace_id?: string;
13
- }
14
- export declare function getAddItemToRfqCartData(data: Partial<WarehouseIPurchaseOrderRFQ>, payload: ISetAddItemToRfqCartActionPayload): Partial<WarehouseIPurchaseOrderRFQ>;
15
- export declare function getUpdateItemInRfqCartData(data: Partial<WarehouseIPurchaseOrderRFQ>, payload: Partial<WarehouseIPurchaseOrderRFQItem>): Partial<WarehouseIPurchaseOrderRFQ>;
16
- export declare function getUpdateItemsInRfqCartData(data: Partial<WarehouseIPurchaseOrderRFQ>, payload: Partial<WarehouseIPurchaseOrderRFQItem>[]): Partial<WarehouseIPurchaseOrderRFQ>;
17
- export declare function getSplitRfqCartItemToTwo(data: Partial<WarehouseIPurchaseOrderRFQ>, orderItemId: string): Partial<WarehouseIPurchaseOrderRFQ>;
18
- export declare function getAddItemsToRfqCartData(data: Partial<WarehouseIPurchaseOrderRFQ>, payload: ISetAddItemToRfqCartActionPayload[]): Partial<WarehouseIPurchaseOrderRFQ>;
19
- export {};