@managesome/eposmatic-toolkit 0.2.439 → 0.2.441

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