@managesome/eposmatic-toolkit 0.2.448 → 0.2.449
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.
- package/lib/helpers/store/common-warehouse-purchase-order-rfq-actions.js +1 -1
- package/lib/helpers/store/index.d.ts +1 -0
- package/lib/helpers/store/index.js +1 -0
- package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.d.ts +9 -9
- package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +26 -26
- package/lib/helpers/store/warehouse-sale-order-rfq-cart-actions.d.ts +18 -0
- package/lib/helpers/store/warehouse-sale-order-rfq-cart-actions.js +286 -0
- package/package.json +1 -1
|
@@ -80,7 +80,7 @@ function syncWarehousePurchaseOrderRfqData(order) {
|
|
|
80
80
|
...order,
|
|
81
81
|
iterations: [],
|
|
82
82
|
};
|
|
83
|
-
const newOrder = getWarehousePurchaseOrderRfqWithPrice((0, warehouse_purchase_order_rfq_cart_actions_1.
|
|
83
|
+
const newOrder = getWarehousePurchaseOrderRfqWithPrice((0, warehouse_purchase_order_rfq_cart_actions_1.calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData)(getWarehousePurchaseOrderRfqWithPrice(updatedOrder), true), true);
|
|
84
84
|
newOrder.iterations = order.iterations;
|
|
85
85
|
return newOrder;
|
|
86
86
|
}
|
|
@@ -18,3 +18,4 @@ export * from './offline-ordering';
|
|
|
18
18
|
export * from './warehouse-invoice-cart-actions';
|
|
19
19
|
export * from './warehouse-purchase-order-rfq-cart-actions';
|
|
20
20
|
export * from './warehouse-purchase-orders-cart-actions';
|
|
21
|
+
export * from './warehouse-sale-order-rfq-cart-actions';
|
|
@@ -34,3 +34,4 @@ __exportStar(require("./offline-ordering"), exports);
|
|
|
34
34
|
__exportStar(require("./warehouse-invoice-cart-actions"), exports);
|
|
35
35
|
__exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
|
|
36
36
|
__exportStar(require("./warehouse-purchase-orders-cart-actions"), exports);
|
|
37
|
+
__exportStar(require("./warehouse-sale-order-rfq-cart-actions"), exports);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { IWarehousePurchaseOrderRFQ, IWarehousePurchaseOrderRFQItem } from '../../schemas';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
2
|
+
export declare function calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData<T extends IWarehousePurchaseOrderRFQ | Partial<IWarehousePurchaseOrderRFQ>>(data: T, calculateItemMetadata?: boolean): T;
|
|
3
|
+
export declare function getRemoveItemFromWarehousePurchaseOrderRfqCartData(data: Partial<IWarehousePurchaseOrderRFQ>, payload: {
|
|
4
4
|
_id: string;
|
|
5
5
|
void_reason?: string;
|
|
6
6
|
}): Partial<IWarehousePurchaseOrderRFQ>;
|
|
7
|
-
export declare function
|
|
8
|
-
interface
|
|
7
|
+
export declare function getUpdateWarehousePurchaseOrderRfqCartInfoData(data: Partial<IWarehousePurchaseOrderRFQ>, payload: Partial<IWarehousePurchaseOrderRFQ>): Partial<IWarehousePurchaseOrderRFQ>;
|
|
8
|
+
interface ISetAddItemToPurchaseOrderRfqCartActionPayload {
|
|
9
9
|
name: string;
|
|
10
10
|
category_id: string;
|
|
11
11
|
item: IWarehousePurchaseOrderRFQItem;
|
|
12
12
|
replace_id?: string;
|
|
13
13
|
}
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function
|
|
14
|
+
export declare function getAddItemToWarehousePurchaseOrderRfqCartData(data: Partial<IWarehousePurchaseOrderRFQ>, payload: ISetAddItemToPurchaseOrderRfqCartActionPayload): Partial<IWarehousePurchaseOrderRFQ>;
|
|
15
|
+
export declare function getUpdateItemInWarehousePurchaseOrderRfqCartData(data: Partial<IWarehousePurchaseOrderRFQ>, payload: Partial<IWarehousePurchaseOrderRFQItem>): Partial<IWarehousePurchaseOrderRFQ>;
|
|
16
|
+
export declare function getUpdateItemsInWarehousePurchaseOrderRfqCartData(data: Partial<IWarehousePurchaseOrderRFQ>, payload: Partial<IWarehousePurchaseOrderRFQItem>[]): Partial<IWarehousePurchaseOrderRFQ>;
|
|
17
|
+
export declare function getSplitWarehousePurchaseOrderRfqCartItemToTwo(data: Partial<IWarehousePurchaseOrderRFQ>, orderItemId: string): Partial<IWarehousePurchaseOrderRFQ>;
|
|
18
|
+
export declare function getAddItemsToWarehousePurchaseOrderRfqCartData(data: Partial<IWarehousePurchaseOrderRFQ>, payload: ISetAddItemToPurchaseOrderRfqCartActionPayload[]): Partial<IWarehousePurchaseOrderRFQ>;
|
|
19
19
|
export {};
|
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
6
|
+
exports.calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData = calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData;
|
|
7
|
+
exports.getRemoveItemFromWarehousePurchaseOrderRfqCartData = getRemoveItemFromWarehousePurchaseOrderRfqCartData;
|
|
8
|
+
exports.getUpdateWarehousePurchaseOrderRfqCartInfoData = getUpdateWarehousePurchaseOrderRfqCartInfoData;
|
|
9
|
+
exports.getAddItemToWarehousePurchaseOrderRfqCartData = getAddItemToWarehousePurchaseOrderRfqCartData;
|
|
10
|
+
exports.getUpdateItemInWarehousePurchaseOrderRfqCartData = getUpdateItemInWarehousePurchaseOrderRfqCartData;
|
|
11
|
+
exports.getUpdateItemsInWarehousePurchaseOrderRfqCartData = getUpdateItemsInWarehousePurchaseOrderRfqCartData;
|
|
12
|
+
exports.getSplitWarehousePurchaseOrderRfqCartItemToTwo = getSplitWarehousePurchaseOrderRfqCartItemToTwo;
|
|
13
|
+
exports.getAddItemsToWarehousePurchaseOrderRfqCartData = getAddItemsToWarehousePurchaseOrderRfqCartData;
|
|
14
14
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
15
15
|
const lodash_1 = require("lodash");
|
|
16
16
|
const constants_1 = require("../../constants");
|
|
@@ -20,7 +20,7 @@ const utils_1 = require("../utils");
|
|
|
20
20
|
* IWarehousePurchaseOrderRFQCategory ≡ IPurchaseOrderCategory (same type),
|
|
21
21
|
* IWarehousePurchaseOrderRFQItem ≡ IWarehousePurchaseOrderItem (same type).
|
|
22
22
|
* ================================================================= */
|
|
23
|
-
function
|
|
23
|
+
function calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData(data, calculateItemMetadata) {
|
|
24
24
|
const isConfirmed = data.order_status === constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM.CONFIRMED;
|
|
25
25
|
let subtotal = 0;
|
|
26
26
|
const categories = [];
|
|
@@ -106,14 +106,14 @@ function calculateCartWarehouseRfqOrderInfoAndSyncData(data, calculateItemMetada
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
// ── Shared ──
|
|
109
|
-
const
|
|
109
|
+
const getUpdatedPurchaseOrderRfqItem = (item) => ({
|
|
110
110
|
item_id: item.item_id,
|
|
111
111
|
name: item.name,
|
|
112
112
|
price: item.price,
|
|
113
113
|
special_instructions: item.special_instructions,
|
|
114
114
|
});
|
|
115
115
|
// ── Remove ──
|
|
116
|
-
function
|
|
116
|
+
function getRemoveItemFromWarehousePurchaseOrderRfqCartData(data, payload) {
|
|
117
117
|
const orderItemIdsMap = {};
|
|
118
118
|
let categories;
|
|
119
119
|
if (data.categories != null) {
|
|
@@ -164,17 +164,17 @@ function getRemoveItemFromWarehouseRfqCartData(data, payload) {
|
|
|
164
164
|
}
|
|
165
165
|
iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
|
|
166
166
|
}
|
|
167
|
-
return
|
|
167
|
+
return calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData({
|
|
168
168
|
...data,
|
|
169
169
|
...(iterations.length > 0 && { iterations }),
|
|
170
170
|
categories,
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
// ── Update Info ──
|
|
174
|
-
function
|
|
175
|
-
return
|
|
174
|
+
function getUpdateWarehousePurchaseOrderRfqCartInfoData(data, payload) {
|
|
175
|
+
return calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData({ ...data, ...payload });
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function getAddItemToWarehousePurchaseOrderRfqCartData(data, payload) {
|
|
178
178
|
const { category_id, name, item, replace_id } = payload;
|
|
179
179
|
let mainItemId = item._id;
|
|
180
180
|
const orderData = { ...data };
|
|
@@ -184,7 +184,7 @@ function getAddItemToWarehouseRfqCartData(data, payload) {
|
|
|
184
184
|
const category = categories[i];
|
|
185
185
|
if (category.category_id !== category_id)
|
|
186
186
|
continue;
|
|
187
|
-
const updatedItem =
|
|
187
|
+
const updatedItem = getUpdatedPurchaseOrderRfqItem(item);
|
|
188
188
|
const allItems = [...category.items];
|
|
189
189
|
let didFindItem = false;
|
|
190
190
|
let itemExists = false;
|
|
@@ -202,7 +202,7 @@ function getAddItemToWarehouseRfqCartData(data, payload) {
|
|
|
202
202
|
if (!didFindItem && itemExists) {
|
|
203
203
|
for (let j = 0; j < allItems.length; j++) {
|
|
204
204
|
const itm = allItems[j];
|
|
205
|
-
if (itm.item_id === item.item_id && (0, lodash_1.isEqual)(
|
|
205
|
+
if (itm.item_id === item.item_id && (0, lodash_1.isEqual)(getUpdatedPurchaseOrderRfqItem(itm), updatedItem)) {
|
|
206
206
|
mainItemId = replace_id ?? itm._id;
|
|
207
207
|
allItems[j] = {
|
|
208
208
|
...item,
|
|
@@ -256,14 +256,14 @@ function getAddItemToWarehouseRfqCartData(data, payload) {
|
|
|
256
256
|
}
|
|
257
257
|
iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
|
|
258
258
|
}
|
|
259
|
-
return
|
|
259
|
+
return calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData({
|
|
260
260
|
...orderData,
|
|
261
261
|
...(iterations.length > 0 && { iterations }),
|
|
262
262
|
categories,
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
265
|
// ── Update Item ──
|
|
266
|
-
function
|
|
266
|
+
function getUpdateItemInWarehousePurchaseOrderRfqCartData(data, payload) {
|
|
267
267
|
const orderItemIdsMap = {};
|
|
268
268
|
let categories;
|
|
269
269
|
if (data.categories != null) {
|
|
@@ -318,18 +318,18 @@ function getUpdateItemInWarehouseRfqCartData(data, payload) {
|
|
|
318
318
|
}
|
|
319
319
|
iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
|
|
320
320
|
}
|
|
321
|
-
return
|
|
321
|
+
return calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData({
|
|
322
322
|
...data,
|
|
323
323
|
...(iterations.length > 0 && { iterations }),
|
|
324
324
|
categories,
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
// ── Update Items (batch) ──
|
|
328
|
-
function
|
|
329
|
-
return payload.reduce((acc, item) =>
|
|
328
|
+
function getUpdateItemsInWarehousePurchaseOrderRfqCartData(data, payload) {
|
|
329
|
+
return payload.reduce((acc, item) => getUpdateItemInWarehousePurchaseOrderRfqCartData(acc, item), data);
|
|
330
330
|
}
|
|
331
331
|
// ── Split Item ──
|
|
332
|
-
function
|
|
332
|
+
function getSplitWarehousePurchaseOrderRfqCartItemToTwo(data, orderItemId) {
|
|
333
333
|
if (data.categories == null)
|
|
334
334
|
return data;
|
|
335
335
|
const newCategories = [];
|
|
@@ -362,12 +362,12 @@ function getSplitWarehouseRfqCartItemToTwo(data, orderItemId) {
|
|
|
362
362
|
}
|
|
363
363
|
newCategories.push({ ...category, items: newItems });
|
|
364
364
|
}
|
|
365
|
-
return
|
|
365
|
+
return calculateCartWarehousePurchaseOrderRfqOrderInfoAndSyncData({
|
|
366
366
|
...data,
|
|
367
367
|
categories: newCategories,
|
|
368
368
|
});
|
|
369
369
|
}
|
|
370
370
|
// ── Add Items (batch) ──
|
|
371
|
-
function
|
|
372
|
-
return payload.reduce((acc, item) =>
|
|
371
|
+
function getAddItemsToWarehousePurchaseOrderRfqCartData(data, payload) {
|
|
372
|
+
return payload.reduce((acc, item) => getAddItemToWarehousePurchaseOrderRfqCartData(acc, item), data);
|
|
373
373
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IWarehouseSaleOrderRFQ, IWarehouseSaleOrderRFQItem } from '../../schemas';
|
|
2
|
+
export declare function getRemoveItemFromWarehouseSaleOrderRfqCartData(data: Partial<IWarehouseSaleOrderRFQ>, payload: {
|
|
3
|
+
_id: string;
|
|
4
|
+
void_reason?: string;
|
|
5
|
+
}): Partial<IWarehouseSaleOrderRFQ>;
|
|
6
|
+
export declare function getUpdateWarehouseSaleOrderRfqCartInfoData(data: Partial<IWarehouseSaleOrderRFQ>, payload: Partial<IWarehouseSaleOrderRFQ>): Partial<IWarehouseSaleOrderRFQ>;
|
|
7
|
+
interface ISetAddItemToSaleOrderRfqCartActionPayload {
|
|
8
|
+
name: string;
|
|
9
|
+
category_id: string;
|
|
10
|
+
item: IWarehouseSaleOrderRFQItem;
|
|
11
|
+
replace_id?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function getAddItemToWarehouseSaleOrderRfqCartData(data: Partial<IWarehouseSaleOrderRFQ>, payload: ISetAddItemToSaleOrderRfqCartActionPayload): Partial<IWarehouseSaleOrderRFQ>;
|
|
14
|
+
export declare function getUpdateItemInWarehouseSaleOrderRfqCartData(data: Partial<IWarehouseSaleOrderRFQ>, payload: Partial<IWarehouseSaleOrderRFQItem>): Partial<IWarehouseSaleOrderRFQ>;
|
|
15
|
+
export declare function getUpdateItemsInWarehouseSaleOrderRfqCartData(data: Partial<IWarehouseSaleOrderRFQ>, payload: Partial<IWarehouseSaleOrderRFQItem>[]): Partial<IWarehouseSaleOrderRFQ>;
|
|
16
|
+
export declare function getSplitWarehouseSaleOrderRfqCartItemToTwo(data: Partial<IWarehouseSaleOrderRFQ>, orderItemId: string): Partial<IWarehouseSaleOrderRFQ>;
|
|
17
|
+
export declare function getAddItemsToWarehouseSaleOrderRfqCartData(data: Partial<IWarehouseSaleOrderRFQ>, payload: ISetAddItemToSaleOrderRfqCartActionPayload[]): Partial<IWarehouseSaleOrderRFQ>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,286 @@
|
|
|
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.getRemoveItemFromWarehouseSaleOrderRfqCartData = getRemoveItemFromWarehouseSaleOrderRfqCartData;
|
|
7
|
+
exports.getUpdateWarehouseSaleOrderRfqCartInfoData = getUpdateWarehouseSaleOrderRfqCartInfoData;
|
|
8
|
+
exports.getAddItemToWarehouseSaleOrderRfqCartData = getAddItemToWarehouseSaleOrderRfqCartData;
|
|
9
|
+
exports.getUpdateItemInWarehouseSaleOrderRfqCartData = getUpdateItemInWarehouseSaleOrderRfqCartData;
|
|
10
|
+
exports.getUpdateItemsInWarehouseSaleOrderRfqCartData = getUpdateItemsInWarehouseSaleOrderRfqCartData;
|
|
11
|
+
exports.getSplitWarehouseSaleOrderRfqCartItemToTwo = getSplitWarehouseSaleOrderRfqCartItemToTwo;
|
|
12
|
+
exports.getAddItemsToWarehouseSaleOrderRfqCartData = getAddItemsToWarehouseSaleOrderRfqCartData;
|
|
13
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
14
|
+
const lodash_1 = require("lodash");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
16
|
+
const common_warehouse_sale_order_rfq_actions_1 = require("./common-warehouse-sale-order-rfq-actions");
|
|
17
|
+
/* =================================================================
|
|
18
|
+
* Sale-order RFQ cart helpers — CRUD operations for cart items.
|
|
19
|
+
* Mirrors warehouse-purchase-order-rfq-cart-actions.ts for sale RFQ types.
|
|
20
|
+
* ================================================================= */
|
|
21
|
+
// ── Shared ──
|
|
22
|
+
const getUpdatedSaleOrderRfqItem = (item) => ({
|
|
23
|
+
item_id: item.item_id,
|
|
24
|
+
name: item.name,
|
|
25
|
+
price: item.price,
|
|
26
|
+
special_instructions: item.special_instructions,
|
|
27
|
+
});
|
|
28
|
+
// ── Remove ──
|
|
29
|
+
function getRemoveItemFromWarehouseSaleOrderRfqCartData(data, payload) {
|
|
30
|
+
const orderItemIdsMap = {};
|
|
31
|
+
let categories;
|
|
32
|
+
if (data.categories != null) {
|
|
33
|
+
categories = [];
|
|
34
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
35
|
+
const category = data.categories[i];
|
|
36
|
+
const items = [];
|
|
37
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
38
|
+
const item = category.items[j];
|
|
39
|
+
if (item._id !== payload._id) {
|
|
40
|
+
items.push(item);
|
|
41
|
+
orderItemIdsMap[item._id] = item.quantity;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (items.length > 0) {
|
|
45
|
+
categories.push({ ...category, items });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const iterations = [];
|
|
50
|
+
if (data.iterations != null && data.iterations.length > 0) {
|
|
51
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
52
|
+
const firstIterationCategories = [];
|
|
53
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
54
|
+
const category = firstIteration.categories[i];
|
|
55
|
+
const allPrevItems = [];
|
|
56
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
57
|
+
const prevItem = category.items[j];
|
|
58
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
59
|
+
allPrevItems.push({ ...prevItem, void_reason: payload.void_reason });
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
63
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
64
|
+
if (isRemovedItem) {
|
|
65
|
+
allPrevItems.push(prevItem);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const updatedPrevItem = { ...prevItem };
|
|
69
|
+
delete updatedPrevItem.void_reason;
|
|
70
|
+
allPrevItems.push(updatedPrevItem);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (allPrevItems.length > 0) {
|
|
75
|
+
firstIterationCategories.push({ ...category, items: allPrevItems });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
|
|
79
|
+
}
|
|
80
|
+
return (0, common_warehouse_sale_order_rfq_actions_1.calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData)({
|
|
81
|
+
...data,
|
|
82
|
+
...(iterations.length > 0 && { iterations }),
|
|
83
|
+
categories,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// ── Update Info ──
|
|
87
|
+
function getUpdateWarehouseSaleOrderRfqCartInfoData(data, payload) {
|
|
88
|
+
return (0, common_warehouse_sale_order_rfq_actions_1.calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData)({ ...data, ...payload });
|
|
89
|
+
}
|
|
90
|
+
function getAddItemToWarehouseSaleOrderRfqCartData(data, payload) {
|
|
91
|
+
const { category_id, name, item, replace_id } = payload;
|
|
92
|
+
let mainItemId = item._id;
|
|
93
|
+
const orderData = { ...data };
|
|
94
|
+
const categories = [...(orderData.categories ?? [])];
|
|
95
|
+
let didFindCategory = false;
|
|
96
|
+
for (let i = 0; i < categories.length; i++) {
|
|
97
|
+
const category = categories[i];
|
|
98
|
+
if (category.category_id !== category_id)
|
|
99
|
+
continue;
|
|
100
|
+
const updatedItem = getUpdatedSaleOrderRfqItem(item);
|
|
101
|
+
const allItems = [...category.items];
|
|
102
|
+
let didFindItem = false;
|
|
103
|
+
let itemExists = false;
|
|
104
|
+
for (let j = 0; j < allItems.length; j++) {
|
|
105
|
+
const itm = allItems[j];
|
|
106
|
+
if (itm._id === item._id) {
|
|
107
|
+
allItems[j] = item;
|
|
108
|
+
didFindItem = true;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (itm.item_id === item.item_id) {
|
|
112
|
+
itemExists = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!didFindItem && itemExists) {
|
|
116
|
+
for (let j = 0; j < allItems.length; j++) {
|
|
117
|
+
const itm = allItems[j];
|
|
118
|
+
if (itm.item_id === item.item_id && (0, lodash_1.isEqual)(getUpdatedSaleOrderRfqItem(itm), updatedItem)) {
|
|
119
|
+
mainItemId = replace_id ?? itm._id;
|
|
120
|
+
allItems[j] = {
|
|
121
|
+
...item,
|
|
122
|
+
_id: mainItemId,
|
|
123
|
+
quantity: item.quantity + itm.quantity,
|
|
124
|
+
};
|
|
125
|
+
didFindItem = true;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!didFindItem) {
|
|
131
|
+
allItems.push(item);
|
|
132
|
+
}
|
|
133
|
+
categories[i] = { ...category, items: allItems };
|
|
134
|
+
didFindCategory = true;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (!didFindCategory) {
|
|
138
|
+
categories.push({ category_id, name, items: [item] });
|
|
139
|
+
}
|
|
140
|
+
const iterations = [];
|
|
141
|
+
if (orderData.iterations != null && orderData.iterations.length > 0) {
|
|
142
|
+
const orderItemIdsMap = {};
|
|
143
|
+
for (let i = 0; i < categories.length; i++) {
|
|
144
|
+
for (let j = 0; j < categories[i].items.length; j++) {
|
|
145
|
+
orderItemIdsMap[categories[i].items[j]._id] = categories[i].items[j].quantity;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const [firstIteration, ...restIterations] = orderData.iterations;
|
|
149
|
+
const firstIterationCategories = [];
|
|
150
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
151
|
+
const category = firstIteration.categories[i];
|
|
152
|
+
const allPrevItems = [];
|
|
153
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
154
|
+
const prevItem = category.items[j];
|
|
155
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
156
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
157
|
+
if (isRemovedItem) {
|
|
158
|
+
allPrevItems.push(prevItem);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const updatedPrevItem = { ...prevItem };
|
|
162
|
+
delete updatedPrevItem.void_reason;
|
|
163
|
+
allPrevItems.push(updatedPrevItem);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (allPrevItems.length > 0) {
|
|
167
|
+
firstIterationCategories.push({ ...category, items: allPrevItems });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
|
|
171
|
+
}
|
|
172
|
+
return (0, common_warehouse_sale_order_rfq_actions_1.calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData)({
|
|
173
|
+
...orderData,
|
|
174
|
+
...(iterations.length > 0 && { iterations }),
|
|
175
|
+
categories,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
// ── Update Item ──
|
|
179
|
+
function getUpdateItemInWarehouseSaleOrderRfqCartData(data, payload) {
|
|
180
|
+
const orderItemIdsMap = {};
|
|
181
|
+
let categories;
|
|
182
|
+
if (data.categories != null) {
|
|
183
|
+
categories = [];
|
|
184
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
185
|
+
const category = data.categories[i];
|
|
186
|
+
const items = [];
|
|
187
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
188
|
+
const item = category.items[j];
|
|
189
|
+
let newItem = item;
|
|
190
|
+
if (item._id === payload._id) {
|
|
191
|
+
newItem = { ...item, ...payload };
|
|
192
|
+
}
|
|
193
|
+
if (newItem.quantity > 0) {
|
|
194
|
+
items.push(newItem);
|
|
195
|
+
orderItemIdsMap[newItem._id] = newItem.quantity;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (items.length > 0) {
|
|
199
|
+
categories.push({ ...category, items });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const iterations = [];
|
|
204
|
+
if (payload.quantity != null && data.iterations != null && data.iterations.length > 0) {
|
|
205
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
206
|
+
const firstIterationCategories = [];
|
|
207
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
208
|
+
const category = firstIteration.categories[i];
|
|
209
|
+
const allPrevItems = [];
|
|
210
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
211
|
+
const prevItem = category.items[j];
|
|
212
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
213
|
+
allPrevItems.push({ ...prevItem, void_reason: payload.void_reason });
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
217
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
218
|
+
if (isRemovedItem) {
|
|
219
|
+
allPrevItems.push(prevItem);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
const updatedPrevItem = { ...prevItem };
|
|
223
|
+
delete updatedPrevItem.void_reason;
|
|
224
|
+
allPrevItems.push(updatedPrevItem);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (allPrevItems.length > 0) {
|
|
229
|
+
firstIterationCategories.push({ ...category, items: allPrevItems });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
|
|
233
|
+
}
|
|
234
|
+
return (0, common_warehouse_sale_order_rfq_actions_1.calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData)({
|
|
235
|
+
...data,
|
|
236
|
+
...(iterations.length > 0 && { iterations }),
|
|
237
|
+
categories,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
// ── Update Items (batch) ──
|
|
241
|
+
function getUpdateItemsInWarehouseSaleOrderRfqCartData(data, payload) {
|
|
242
|
+
return payload.reduce((acc, item) => getUpdateItemInWarehouseSaleOrderRfqCartData(acc, item), data);
|
|
243
|
+
}
|
|
244
|
+
// ── Split Item ──
|
|
245
|
+
function getSplitWarehouseSaleOrderRfqCartItemToTwo(data, orderItemId) {
|
|
246
|
+
if (data.categories == null)
|
|
247
|
+
return data;
|
|
248
|
+
const newCategories = [];
|
|
249
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
250
|
+
const category = data.categories[i];
|
|
251
|
+
const newItems = [];
|
|
252
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
253
|
+
const item = { ...category.items[j] };
|
|
254
|
+
if (item._id !== orderItemId) {
|
|
255
|
+
newItems.push(item);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (item.quantity === 1) {
|
|
259
|
+
newItems.push(item);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const newQuantity = item.quantity - 1;
|
|
263
|
+
newItems.push({
|
|
264
|
+
...item,
|
|
265
|
+
quantity: newQuantity,
|
|
266
|
+
subtotal: (0, utils_1.parseNum)(item.price * newQuantity),
|
|
267
|
+
});
|
|
268
|
+
const newId = new bson_objectid_1.default(Math.floor(new bson_objectid_1.default(item._id).getTimestamp().getTime() / 1000) + 1).toHexString();
|
|
269
|
+
newItems.push({
|
|
270
|
+
...item,
|
|
271
|
+
_id: newId,
|
|
272
|
+
quantity: 1,
|
|
273
|
+
subtotal: (0, utils_1.parseNum)(item.price * 1),
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
newCategories.push({ ...category, items: newItems });
|
|
277
|
+
}
|
|
278
|
+
return (0, common_warehouse_sale_order_rfq_actions_1.calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData)({
|
|
279
|
+
...data,
|
|
280
|
+
categories: newCategories,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
// ── Add Items (batch) ──
|
|
284
|
+
function getAddItemsToWarehouseSaleOrderRfqCartData(data, payload) {
|
|
285
|
+
return payload.reduce((acc, item) => getAddItemToWarehouseSaleOrderRfqCartData(acc, item), data);
|
|
286
|
+
}
|