@managesome/eposmatic-toolkit 0.2.461 → 0.2.463
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/constants/WAREHOUSE_ANALYTICS.d.ts +1 -100
- package/lib/constants/WAREHOUSE_ANALYTICS.js +1 -11
- package/lib/constants/WAREHOUSE_ENUMS.d.ts +0 -6
- package/lib/constants/WAREHOUSE_ENUMS.js +1 -9
- package/lib/constants/WORKER_ENDPOINTS.d.ts +0 -4
- package/lib/constants/WORKER_ENDPOINTS.js +0 -4
- package/lib/constants/index.d.ts +0 -1
- package/lib/constants/index.js +0 -1
- package/lib/helpers/order/generate-warehouse-invoice.d.ts +3 -3
- package/lib/helpers/order/generate-warehouse-sale-order.d.ts +11 -0
- package/lib/helpers/order/generate-warehouse-sale-order.js +158 -0
- package/lib/helpers/order/index.d.ts +1 -1
- package/lib/helpers/order/index.js +1 -1
- package/lib/helpers/store/all-warehouse-sale-orders-actions.d.ts +12 -0
- package/lib/helpers/store/all-warehouse-sale-orders-actions.js +78 -0
- package/lib/helpers/store/common-warehouse-sale-order-actions.d.ts +26 -0
- package/lib/helpers/store/common-warehouse-sale-order-actions.js +428 -0
- package/lib/helpers/store/index.d.ts +2 -3
- package/lib/helpers/store/index.js +2 -3
- package/lib/helpers/store/warehouse-invoice-cart-actions.d.ts +2 -34
- package/lib/helpers/store/warehouse-sale-orders-cart-actions.d.ts +55 -0
- package/lib/helpers/store/warehouse-sale-orders-cart-actions.js +472 -0
- package/lib/helpers/types/index.d.ts +5 -5
- package/lib/helpers/types/index.js +5 -5
- package/lib/helpers/types/warehouse-sale-order-cart-actions.d.ts +26 -0
- package/lib/helpers/types/warehouse-sale-order-cart-actions.js +2 -0
- package/lib/helpers/types/workers.d.ts +4 -26
- package/lib/helpers/utils/index.d.ts +4 -4
- package/lib/helpers/utils/index.js +4 -4
- package/lib/helpers/utils/warehouse-sale-order-engine.d.ts +9 -0
- package/lib/helpers/utils/warehouse-sale-order-engine.js +34 -0
- package/lib/helpers/utils/warehouse-sale-order-receipt-engine.d.ts +89 -0
- package/lib/helpers/utils/warehouse-sale-order-receipt-engine.js +216 -0
- package/lib/helpers/utils/warehouse-void-sale-order-items-helpers.d.ts +3 -0
- package/lib/helpers/utils/warehouse-void-sale-order-items-helpers.js +38 -0
- package/lib/helpers/utils/warehouse-void-sale-order-items-report-helpers.d.ts +13 -0
- package/lib/helpers/utils/warehouse-void-sale-order-items-report-helpers.js +22 -0
- package/lib/schemas/models/index.d.ts +1 -2
- package/lib/schemas/models/index.js +1 -2
- package/lib/schemas/models/warehouse_void_sale_order_items.d.ts +176 -0
- package/lib/schemas/models/warehouse_void_sale_order_items.js +177 -0
- package/lib/schemas/types/index.d.ts +1 -2
- package/lib/schemas/types/index.js +1 -2
- package/lib/schemas/types/warehouse_sale_orders.d.ts +6 -0
- package/lib/schemas/types/warehouse_void_sale_order_items.d.ts +37 -0
- package/lib/schemas/types/warehouse_void_sale_order_items.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,472 @@
|
|
|
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.getWarehouseSaleOrderItemComparableData = void 0;
|
|
7
|
+
exports.calculateCartWarehouseSaleOrderInfoAndSyncData = calculateCartWarehouseSaleOrderInfoAndSyncData;
|
|
8
|
+
exports.getUpdatedWarehouseSaleOrderCartInfoOnInit = getUpdatedWarehouseSaleOrderCartInfoOnInit;
|
|
9
|
+
exports.getRemoveItemFromWarehouseSaleOrderCartData = getRemoveItemFromWarehouseSaleOrderCartData;
|
|
10
|
+
exports.getUpdateWarehouseSaleOrderCartInfoData = getUpdateWarehouseSaleOrderCartInfoData;
|
|
11
|
+
exports.getAddItemToWarehouseSaleOrderCartData = getAddItemToWarehouseSaleOrderCartData;
|
|
12
|
+
exports.getUpdateItemInWarehouseSaleOrderCartData = getUpdateItemInWarehouseSaleOrderCartData;
|
|
13
|
+
exports.getUpdateItemsInWarehouseSaleOrderCartData = getUpdateItemsInWarehouseSaleOrderCartData;
|
|
14
|
+
exports.getSplitWarehouseSaleOrderCartItemToTwo = getSplitWarehouseSaleOrderCartItemToTwo;
|
|
15
|
+
exports.getAddItemsToWarehouseSaleOrderCartData = getAddItemsToWarehouseSaleOrderCartData;
|
|
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
|
+
function calculateCartWarehouseSaleOrderInfoAndSyncData(data, calculateItemMetadata) {
|
|
21
|
+
const isCompleted = data.order_status === constants_1.WAREHOUSE_SALES_ORDER_STATUS_ENUM.COMPLETED;
|
|
22
|
+
/* ===============================><=============================== */
|
|
23
|
+
let subtotal = 0;
|
|
24
|
+
const categories = [];
|
|
25
|
+
const length = data.categories?.length ?? 0;
|
|
26
|
+
for (let c = 0; c < length; c++) {
|
|
27
|
+
const category = data.categories[c];
|
|
28
|
+
const newItems = [];
|
|
29
|
+
const itemsLength = category.items.length;
|
|
30
|
+
for (let i = 0; i < itemsLength; i++) {
|
|
31
|
+
const item = category.items[i];
|
|
32
|
+
// For sale orders, subtotal is already set as price * quantity
|
|
33
|
+
const itemSubtotal = (0, utils_1.parseNum)(item.price * item.quantity);
|
|
34
|
+
const newItem = {
|
|
35
|
+
...item,
|
|
36
|
+
is_ready: item.is_ready || isCompleted,
|
|
37
|
+
subtotal: itemSubtotal,
|
|
38
|
+
// These values will be auto calculated
|
|
39
|
+
_discount_amount: 0,
|
|
40
|
+
_gross_amount: 0,
|
|
41
|
+
_gst_amount: 0,
|
|
42
|
+
_net_amount: 0,
|
|
43
|
+
};
|
|
44
|
+
delete newItem.void_reason;
|
|
45
|
+
newItems.push(newItem);
|
|
46
|
+
subtotal += itemSubtotal;
|
|
47
|
+
}
|
|
48
|
+
categories.push({
|
|
49
|
+
...category,
|
|
50
|
+
items: newItems,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
let grand_total = subtotal;
|
|
54
|
+
// GST is represented in percentage. We convert it to decimal
|
|
55
|
+
let gst_amount = 0;
|
|
56
|
+
const gst = data.gst ?? 0;
|
|
57
|
+
if (data.is_gst_inclusive) {
|
|
58
|
+
gst_amount = (0, utils_1.parseFloatCeil)((grand_total * gst) / (100 + gst));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
gst_amount = (0, utils_1.getPercentageAmount)(grand_total, gst);
|
|
62
|
+
grand_total += gst_amount;
|
|
63
|
+
}
|
|
64
|
+
grand_total = (0, utils_1.parseNum)(grand_total);
|
|
65
|
+
const amount_collected = (0, utils_1.parseNum)(grand_total);
|
|
66
|
+
const amount_earned = (0, utils_1.parseNum)(grand_total);
|
|
67
|
+
if (calculateItemMetadata) {
|
|
68
|
+
let leftGrossAmount = subtotal;
|
|
69
|
+
let leftNetAmount = subtotal;
|
|
70
|
+
let leftDiscountAmount = 0;
|
|
71
|
+
let leftGstAmount = gst_amount;
|
|
72
|
+
categories.forEach((category, categoryIndex) => {
|
|
73
|
+
const isLastCategory = categoryIndex === categories.length - 1;
|
|
74
|
+
category.items.forEach((item, itemIndex) => {
|
|
75
|
+
const isLastItem = isLastCategory && itemIndex === category.items.length - 1;
|
|
76
|
+
let grossAmount = item.subtotal;
|
|
77
|
+
let netAmount = item.subtotal;
|
|
78
|
+
let itemTotalDiscountAmount = 0;
|
|
79
|
+
let itemGst = 0;
|
|
80
|
+
if (gst_amount > 0) {
|
|
81
|
+
itemGst = (item.subtotal / subtotal) * gst_amount;
|
|
82
|
+
}
|
|
83
|
+
grossAmount = (0, utils_1.parseFloatCeil)(grossAmount);
|
|
84
|
+
const netAmountParsed = (0, utils_1.parseFloatCeil)(netAmount);
|
|
85
|
+
const itemTotalDiscountAmountParsed = (0, utils_1.parseFloatCeil)(itemTotalDiscountAmount);
|
|
86
|
+
itemGst = (0, utils_1.parseFloatCeil)(itemGst);
|
|
87
|
+
leftGrossAmount -= grossAmount;
|
|
88
|
+
leftNetAmount -= netAmountParsed;
|
|
89
|
+
leftDiscountAmount -= itemTotalDiscountAmountParsed;
|
|
90
|
+
leftGstAmount -= itemGst;
|
|
91
|
+
if (isLastItem) {
|
|
92
|
+
grossAmount += leftGrossAmount;
|
|
93
|
+
netAmount += leftNetAmount;
|
|
94
|
+
itemTotalDiscountAmount += leftDiscountAmount;
|
|
95
|
+
itemGst += leftGstAmount;
|
|
96
|
+
}
|
|
97
|
+
item._gross_amount = Math.max(grossAmount, 0);
|
|
98
|
+
item._net_amount = Math.max(netAmount, 0);
|
|
99
|
+
item._discount_amount = Math.max(itemTotalDiscountAmount, 0);
|
|
100
|
+
item._gst_amount = Math.max(itemGst, 0);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const cartData = {
|
|
105
|
+
...data,
|
|
106
|
+
categories,
|
|
107
|
+
amount_collected,
|
|
108
|
+
amount_earned,
|
|
109
|
+
gst_amount,
|
|
110
|
+
price: (0, utils_1.parseNum)(subtotal),
|
|
111
|
+
grand_total,
|
|
112
|
+
};
|
|
113
|
+
return cartData;
|
|
114
|
+
}
|
|
115
|
+
const getWarehouseSaleOrderItemComparableData = (item) => ({
|
|
116
|
+
item_id: item.item_id,
|
|
117
|
+
name: item.name,
|
|
118
|
+
price: item.price,
|
|
119
|
+
special_instructions: item.special_instructions,
|
|
120
|
+
_id: item._id,
|
|
121
|
+
quantity: item.quantity,
|
|
122
|
+
});
|
|
123
|
+
exports.getWarehouseSaleOrderItemComparableData = getWarehouseSaleOrderItemComparableData;
|
|
124
|
+
const getUpdatedSaleOrderItem = (item) => ({
|
|
125
|
+
item_id: item.item_id,
|
|
126
|
+
name: item.name,
|
|
127
|
+
price: item.price,
|
|
128
|
+
special_instructions: item.special_instructions,
|
|
129
|
+
});
|
|
130
|
+
// =====================><=====================
|
|
131
|
+
function getUpdatedWarehouseSaleOrderCartInfoOnInit(data, order) {
|
|
132
|
+
const merged = { ...data, ...order };
|
|
133
|
+
return calculateCartWarehouseSaleOrderInfoAndSyncData(merged);
|
|
134
|
+
}
|
|
135
|
+
function getRemoveItemFromWarehouseSaleOrderCartData(data, payload) {
|
|
136
|
+
const orderItemIdsMap = {};
|
|
137
|
+
let categories;
|
|
138
|
+
if (data.categories != null) {
|
|
139
|
+
categories = [];
|
|
140
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
141
|
+
const category = data.categories[i];
|
|
142
|
+
const items = [];
|
|
143
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
144
|
+
const item = category.items[j];
|
|
145
|
+
if (item._id !== payload._id) {
|
|
146
|
+
items.push(item);
|
|
147
|
+
orderItemIdsMap[item._id] = item.quantity;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (items.length > 0) {
|
|
151
|
+
categories.push({
|
|
152
|
+
...category,
|
|
153
|
+
items,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const iterations = [];
|
|
159
|
+
if (data.iterations != null && data.iterations.length > 0) {
|
|
160
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
161
|
+
const firstIterationCategories = [];
|
|
162
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
163
|
+
const category = firstIteration.categories[i];
|
|
164
|
+
const allPrevItems = [];
|
|
165
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
166
|
+
const prevItem = category.items[j];
|
|
167
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
168
|
+
const newItem = {
|
|
169
|
+
...prevItem,
|
|
170
|
+
void_reason: payload.void_reason,
|
|
171
|
+
};
|
|
172
|
+
allPrevItems.push(newItem);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
176
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
177
|
+
if (isRemovedItem) {
|
|
178
|
+
allPrevItems.push(prevItem);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const updatedPrevItem = {
|
|
182
|
+
...prevItem,
|
|
183
|
+
};
|
|
184
|
+
delete updatedPrevItem.void_reason;
|
|
185
|
+
allPrevItems.push(updatedPrevItem);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (allPrevItems.length > 0) {
|
|
190
|
+
firstIterationCategories.push({
|
|
191
|
+
...category,
|
|
192
|
+
items: allPrevItems,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const firstIterationData = {
|
|
197
|
+
...firstIteration,
|
|
198
|
+
categories: firstIterationCategories,
|
|
199
|
+
};
|
|
200
|
+
iterations.push(firstIterationData);
|
|
201
|
+
iterations.push(...restIterations);
|
|
202
|
+
}
|
|
203
|
+
const order = {
|
|
204
|
+
...data,
|
|
205
|
+
...(iterations.length > 0 && { iterations }),
|
|
206
|
+
categories,
|
|
207
|
+
};
|
|
208
|
+
const newData = calculateCartWarehouseSaleOrderInfoAndSyncData(order);
|
|
209
|
+
return newData;
|
|
210
|
+
}
|
|
211
|
+
function getUpdateWarehouseSaleOrderCartInfoData(data, payload) {
|
|
212
|
+
const order = {
|
|
213
|
+
...data,
|
|
214
|
+
...payload,
|
|
215
|
+
};
|
|
216
|
+
const newData = calculateCartWarehouseSaleOrderInfoAndSyncData(order);
|
|
217
|
+
return newData;
|
|
218
|
+
}
|
|
219
|
+
function getAddItemToWarehouseSaleOrderCartData(data, payload) {
|
|
220
|
+
const { category_id, name, item, replace_id } = payload;
|
|
221
|
+
let mainItemId = item._id;
|
|
222
|
+
const orderData = { ...data };
|
|
223
|
+
// =====================><=====================
|
|
224
|
+
const categories = [...(orderData.categories ?? [])];
|
|
225
|
+
let didFindCategory = false;
|
|
226
|
+
const categoriesLength = categories.length;
|
|
227
|
+
for (let i = 0; i < categoriesLength; i++) {
|
|
228
|
+
const category = categories[i];
|
|
229
|
+
if (category.category_id !== category_id)
|
|
230
|
+
continue;
|
|
231
|
+
const updatedItem = getUpdatedSaleOrderItem(item);
|
|
232
|
+
const allItems = [...category.items];
|
|
233
|
+
let didFindItem = false;
|
|
234
|
+
let itemExists = false;
|
|
235
|
+
const totalItems = allItems.length;
|
|
236
|
+
for (let j = 0; j < totalItems; j++) {
|
|
237
|
+
const itm = allItems[j];
|
|
238
|
+
if (itm._id === item._id) {
|
|
239
|
+
allItems[j] = item;
|
|
240
|
+
didFindItem = true;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
if (itm.item_id === item.item_id) {
|
|
244
|
+
itemExists = true;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (!didFindItem && itemExists) {
|
|
248
|
+
for (let j = 0; j < totalItems; j++) {
|
|
249
|
+
const itm = allItems[j];
|
|
250
|
+
if (itm.item_id === item.item_id && (0, lodash_1.isEqual)(getUpdatedSaleOrderItem(itm), updatedItem)) {
|
|
251
|
+
mainItemId = replace_id ?? itm._id;
|
|
252
|
+
allItems[j] = {
|
|
253
|
+
...item,
|
|
254
|
+
_id: mainItemId,
|
|
255
|
+
quantity: item.quantity + itm.quantity,
|
|
256
|
+
};
|
|
257
|
+
didFindItem = true;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (!didFindItem) {
|
|
263
|
+
allItems.push(item);
|
|
264
|
+
}
|
|
265
|
+
categories[i] = {
|
|
266
|
+
...category,
|
|
267
|
+
items: allItems,
|
|
268
|
+
};
|
|
269
|
+
didFindCategory = true;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
if (!didFindCategory) {
|
|
273
|
+
categories.push({
|
|
274
|
+
category_id,
|
|
275
|
+
name,
|
|
276
|
+
items: [item],
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
// =====================><=====================
|
|
280
|
+
const iterations = [];
|
|
281
|
+
if (orderData.iterations != null && orderData.iterations.length > 0) {
|
|
282
|
+
const orderItemIdsMap = {};
|
|
283
|
+
for (let i = 0; i < categories.length; i++) {
|
|
284
|
+
const category = categories[i];
|
|
285
|
+
const items = category.items;
|
|
286
|
+
for (let j = 0; j < items.length; j++) {
|
|
287
|
+
const item = items[j];
|
|
288
|
+
orderItemIdsMap[item._id] = item.quantity;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const [firstIteration, ...restIterations] = orderData.iterations;
|
|
292
|
+
const firstIterationCategories = [];
|
|
293
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
294
|
+
const category = firstIteration.categories[i];
|
|
295
|
+
const allPrevItems = [];
|
|
296
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
297
|
+
const prevItem = category.items[j];
|
|
298
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
299
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
300
|
+
if (isRemovedItem) {
|
|
301
|
+
allPrevItems.push(prevItem);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
const updatedPrevItem = {
|
|
305
|
+
...prevItem,
|
|
306
|
+
};
|
|
307
|
+
delete updatedPrevItem.void_reason;
|
|
308
|
+
allPrevItems.push(updatedPrevItem);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (allPrevItems.length > 0) {
|
|
312
|
+
firstIterationCategories.push({
|
|
313
|
+
...category,
|
|
314
|
+
items: allPrevItems,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const firstIterationData = {
|
|
319
|
+
...firstIteration,
|
|
320
|
+
categories: firstIterationCategories,
|
|
321
|
+
};
|
|
322
|
+
iterations.push(firstIterationData);
|
|
323
|
+
iterations.push(...restIterations);
|
|
324
|
+
}
|
|
325
|
+
// =====================><=====================
|
|
326
|
+
const order = {
|
|
327
|
+
...orderData,
|
|
328
|
+
...(iterations.length > 0 && { iterations }),
|
|
329
|
+
categories,
|
|
330
|
+
};
|
|
331
|
+
const newData = calculateCartWarehouseSaleOrderInfoAndSyncData(order);
|
|
332
|
+
return newData;
|
|
333
|
+
}
|
|
334
|
+
function getUpdateItemInWarehouseSaleOrderCartData(data, payload) {
|
|
335
|
+
const orderItemIdsMap = {};
|
|
336
|
+
let categories;
|
|
337
|
+
if (data.categories != null) {
|
|
338
|
+
categories = [];
|
|
339
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
340
|
+
const category = data.categories[i];
|
|
341
|
+
const items = [];
|
|
342
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
343
|
+
const item = category.items[j];
|
|
344
|
+
let newItem = item;
|
|
345
|
+
if (item._id === payload._id) {
|
|
346
|
+
newItem = {
|
|
347
|
+
...item,
|
|
348
|
+
...payload,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
if (newItem.quantity > 0) {
|
|
352
|
+
items.push(newItem);
|
|
353
|
+
orderItemIdsMap[newItem._id] = newItem.quantity;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (items.length > 0) {
|
|
357
|
+
categories.push({
|
|
358
|
+
...category,
|
|
359
|
+
items,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const iterations = [];
|
|
365
|
+
if (payload.quantity != null && data.iterations != null && data.iterations.length > 0) {
|
|
366
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
367
|
+
const firstIterationCategories = [];
|
|
368
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
369
|
+
const category = firstIteration.categories[i];
|
|
370
|
+
const allPrevItems = [];
|
|
371
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
372
|
+
const prevItem = category.items[j];
|
|
373
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
374
|
+
const updatedPrevItem = {
|
|
375
|
+
...prevItem,
|
|
376
|
+
void_reason: payload.void_reason,
|
|
377
|
+
};
|
|
378
|
+
allPrevItems.push(updatedPrevItem);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
382
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
383
|
+
if (isRemovedItem) {
|
|
384
|
+
allPrevItems.push(prevItem);
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
const updatedPrevItem = {
|
|
388
|
+
...prevItem,
|
|
389
|
+
};
|
|
390
|
+
delete updatedPrevItem.void_reason;
|
|
391
|
+
allPrevItems.push(updatedPrevItem);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (allPrevItems.length > 0) {
|
|
396
|
+
firstIterationCategories.push({
|
|
397
|
+
...category,
|
|
398
|
+
items: allPrevItems,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const firstIterationData = {
|
|
403
|
+
...firstIteration,
|
|
404
|
+
categories: firstIterationCategories,
|
|
405
|
+
};
|
|
406
|
+
iterations.push(firstIterationData);
|
|
407
|
+
iterations.push(...restIterations);
|
|
408
|
+
}
|
|
409
|
+
const order = {
|
|
410
|
+
...data,
|
|
411
|
+
...(iterations.length > 0 && { iterations }),
|
|
412
|
+
categories,
|
|
413
|
+
};
|
|
414
|
+
const newData = calculateCartWarehouseSaleOrderInfoAndSyncData(order);
|
|
415
|
+
return newData;
|
|
416
|
+
}
|
|
417
|
+
function getUpdateItemsInWarehouseSaleOrderCartData(data, payload) {
|
|
418
|
+
const newData = payload.reduce((acc, item) => getUpdateItemInWarehouseSaleOrderCartData(acc, item), data);
|
|
419
|
+
return newData;
|
|
420
|
+
}
|
|
421
|
+
function getSplitWarehouseSaleOrderCartItemToTwo({ data, orderItemId, }) {
|
|
422
|
+
if (data.categories == null)
|
|
423
|
+
return data;
|
|
424
|
+
const newCategories = [];
|
|
425
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
426
|
+
const category = data.categories[i];
|
|
427
|
+
const newItems = [];
|
|
428
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
429
|
+
const item = {
|
|
430
|
+
...category.items[j],
|
|
431
|
+
};
|
|
432
|
+
if (item._id !== orderItemId) {
|
|
433
|
+
newItems.push(item);
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (item.quantity === 1) {
|
|
437
|
+
newItems.push(item);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const prevQuantity = item.quantity;
|
|
441
|
+
const newQuantity = item.quantity - 1;
|
|
442
|
+
const prevItem = {
|
|
443
|
+
...item,
|
|
444
|
+
quantity: newQuantity,
|
|
445
|
+
subtotal: (0, utils_1.parseNum)(item.price * newQuantity),
|
|
446
|
+
};
|
|
447
|
+
newItems.push(prevItem);
|
|
448
|
+
const _id = new bson_objectid_1.default(Math.floor(new bson_objectid_1.default(item._id).getTimestamp().getTime() / 1000) + 1).toHexString();
|
|
449
|
+
newItems.push({
|
|
450
|
+
...item,
|
|
451
|
+
_id,
|
|
452
|
+
quantity: 1,
|
|
453
|
+
subtotal: (0, utils_1.parseNum)(item.price * 1),
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
newCategories.push({
|
|
457
|
+
...category,
|
|
458
|
+
items: newItems,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
const order = {
|
|
462
|
+
...data,
|
|
463
|
+
categories: newCategories,
|
|
464
|
+
};
|
|
465
|
+
const newData = calculateCartWarehouseSaleOrderInfoAndSyncData(order);
|
|
466
|
+
return newData;
|
|
467
|
+
}
|
|
468
|
+
function getAddItemsToWarehouseSaleOrderCartData(data, payload) {
|
|
469
|
+
const newData = payload.reduce((acc, item) => getAddItemToWarehouseSaleOrderCartData(acc, item), data);
|
|
470
|
+
return newData;
|
|
471
|
+
}
|
|
472
|
+
/* ======================><====================== */
|
|
@@ -4,8 +4,8 @@ export * from './catalog';
|
|
|
4
4
|
export * from './common';
|
|
5
5
|
export * from './customer_wallet_assignments';
|
|
6
6
|
export * from './email-templates';
|
|
7
|
-
export * from './google-maps';
|
|
8
7
|
export * from './fbr-generate-invoice';
|
|
8
|
+
export * from './google-maps';
|
|
9
9
|
export * from './hubrise_catalog';
|
|
10
10
|
export * from './hubrise_customers';
|
|
11
11
|
export * from './hubrise_deliveries';
|
|
@@ -16,9 +16,6 @@ export * from './kpra-generate-invoice';
|
|
|
16
16
|
export * from './marketing';
|
|
17
17
|
export * from './order-engine';
|
|
18
18
|
export * from './pra-generate-invoice';
|
|
19
|
-
export * from './warehouse-purchase-order-cart-actions';
|
|
20
|
-
export * from './warehouse-purchase-order-rfq-cart-actions';
|
|
21
|
-
export * from './warehouse-sale-order-rfq-cart-actions';
|
|
22
19
|
export * from './report-webview';
|
|
23
20
|
export * from './reports';
|
|
24
21
|
export * from './smartpay-apis';
|
|
@@ -26,5 +23,8 @@ export * from './split_bill';
|
|
|
26
23
|
export * from './srb-generate-invoice';
|
|
27
24
|
export * from './switchpay';
|
|
28
25
|
export * from './warehouse-catalog';
|
|
29
|
-
export * from './warehouse-
|
|
26
|
+
export * from './warehouse-purchase-order-cart-actions';
|
|
27
|
+
export * from './warehouse-purchase-order-rfq-cart-actions';
|
|
28
|
+
export * from './warehouse-sale-order-cart-actions';
|
|
29
|
+
export * from './warehouse-sale-order-rfq-cart-actions';
|
|
30
30
|
export * from './workers';
|
|
@@ -20,8 +20,8 @@ __exportStar(require("./catalog"), exports);
|
|
|
20
20
|
__exportStar(require("./common"), exports);
|
|
21
21
|
__exportStar(require("./customer_wallet_assignments"), exports);
|
|
22
22
|
__exportStar(require("./email-templates"), exports);
|
|
23
|
-
__exportStar(require("./google-maps"), exports);
|
|
24
23
|
__exportStar(require("./fbr-generate-invoice"), exports);
|
|
24
|
+
__exportStar(require("./google-maps"), exports);
|
|
25
25
|
__exportStar(require("./hubrise_catalog"), exports);
|
|
26
26
|
__exportStar(require("./hubrise_customers"), exports);
|
|
27
27
|
__exportStar(require("./hubrise_deliveries"), exports);
|
|
@@ -32,9 +32,6 @@ __exportStar(require("./kpra-generate-invoice"), exports);
|
|
|
32
32
|
__exportStar(require("./marketing"), exports);
|
|
33
33
|
__exportStar(require("./order-engine"), exports);
|
|
34
34
|
__exportStar(require("./pra-generate-invoice"), exports);
|
|
35
|
-
__exportStar(require("./warehouse-purchase-order-cart-actions"), exports);
|
|
36
|
-
__exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
|
|
37
|
-
__exportStar(require("./warehouse-sale-order-rfq-cart-actions"), exports);
|
|
38
35
|
__exportStar(require("./report-webview"), exports);
|
|
39
36
|
__exportStar(require("./reports"), exports);
|
|
40
37
|
__exportStar(require("./smartpay-apis"), exports);
|
|
@@ -42,5 +39,8 @@ __exportStar(require("./split_bill"), exports);
|
|
|
42
39
|
__exportStar(require("./srb-generate-invoice"), exports);
|
|
43
40
|
__exportStar(require("./switchpay"), exports);
|
|
44
41
|
__exportStar(require("./warehouse-catalog"), exports);
|
|
45
|
-
__exportStar(require("./warehouse-
|
|
42
|
+
__exportStar(require("./warehouse-purchase-order-cart-actions"), exports);
|
|
43
|
+
__exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
|
|
44
|
+
__exportStar(require("./warehouse-sale-order-cart-actions"), exports);
|
|
45
|
+
__exportStar(require("./warehouse-sale-order-rfq-cart-actions"), exports);
|
|
46
46
|
__exportStar(require("./workers"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IWarehouseSaleOrderItem } from '../../schemas';
|
|
2
|
+
export interface IWarehouseGeneralSaleOrderItem {
|
|
3
|
+
_id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
category_id: string;
|
|
6
|
+
category_name: string;
|
|
7
|
+
category_image_url: string | null;
|
|
8
|
+
image_url: string | null;
|
|
9
|
+
description: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IWarehouseSaleOrderCartItem {
|
|
12
|
+
orderItem: IWarehouseSaleOrderItem;
|
|
13
|
+
image_url: string | null;
|
|
14
|
+
description: string;
|
|
15
|
+
category_name: string;
|
|
16
|
+
category_id: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IWarehouseSaleOrderCartItemsObj {
|
|
19
|
+
unChangedItems: IWarehouseSaleOrderCartItem[];
|
|
20
|
+
editedItems: IWarehouseSaleOrderCartItem[];
|
|
21
|
+
removedItems: IWarehouseSaleOrderCartItem[];
|
|
22
|
+
newItems: IWarehouseSaleOrderCartItem[];
|
|
23
|
+
totalSelectedItems: number;
|
|
24
|
+
disabledReason: string;
|
|
25
|
+
isAnUpdate: boolean;
|
|
26
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CARD_PROCESSING_PROVIDERS_ENUM, CURRENCY_SYMBOL_ENUM, DELIVERY_STATUS_ENUM, ORDER_STATUS_ENUM, PLATFORM_TYPE_ENUM, PLATFORMS_ENUM, VOID_ORDER_ITEM_TYPE_ENUM, WALLET_ASSET_TYPE_ENUM, WALLET_ASSIGNMENT_BEHAVIOR_ENUM, WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM, WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM, WAREHOUSE_ACTIVITY_LOG_SEVERITY_ENUM, WAREHOUSE_INTERNAL_MOVEMENT_STATUS_ENUM,
|
|
2
|
-
import { IDineinTableFingerprint, IInternalLead, IModifierExtra, IOrder, IOrderItem, IOrderPayment, ITenantPurchaseOrder,
|
|
1
|
+
import { CARD_PROCESSING_PROVIDERS_ENUM, CURRENCY_SYMBOL_ENUM, DELIVERY_STATUS_ENUM, ORDER_STATUS_ENUM, PLATFORM_TYPE_ENUM, PLATFORMS_ENUM, VOID_ORDER_ITEM_TYPE_ENUM, WALLET_ASSET_TYPE_ENUM, WALLET_ASSIGNMENT_BEHAVIOR_ENUM, WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM, WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM, WAREHOUSE_ACTIVITY_LOG_SEVERITY_ENUM, WAREHOUSE_INTERNAL_MOVEMENT_STATUS_ENUM, WAREHOUSE_REMOVAL_STRATEGY_ENUM, WAREHOUSE_TRACKING_MODE_ENUM } from '../../constants';
|
|
2
|
+
import { IDineinTableFingerprint, IInternalLead, IModifierExtra, IOrder, IOrderItem, IOrderPayment, ITenantPurchaseOrder, IWarehouseInternalMovement, IWarehousePurchaseOrder, IWarehousePurchaseOrderReceipt, IWarehousePurchaseOrderVendorReturn, IWarehouseSaleOrder, IWarehouseSaleOrderDelivery } from '../../schemas';
|
|
3
3
|
import { IWarehouseActivityLogChange } from '../../schemas/types/warehouse-activity-logs';
|
|
4
4
|
import { ISwitchPayEWalletRequestBody, ISwitchPayRefundRequestBody } from './switchpay';
|
|
5
5
|
export interface IWorker_CreateDelivery {
|
|
@@ -277,28 +277,6 @@ export interface IWorker_UpdateWarehouseInventoryOnCompletePurchaseOrder {
|
|
|
277
277
|
purchaseOrder: IWarehousePurchaseOrder;
|
|
278
278
|
currency_symbol: CURRENCY_SYMBOL_ENUM | undefined;
|
|
279
279
|
}
|
|
280
|
-
export interface IWorker_UpdateWarehouseInventoryOnCreateInvoice {
|
|
281
|
-
invoice: IWarehouseClientInvoice;
|
|
282
|
-
currency_symbol: CURRENCY_SYMBOL_ENUM;
|
|
283
|
-
warehouse_name: string;
|
|
284
|
-
}
|
|
285
|
-
export interface IWorker_UpdateClientInventoryOnCompleteWarehouseInvoice {
|
|
286
|
-
invoice: IWarehouseClientInvoice;
|
|
287
|
-
currency_symbol: CURRENCY_SYMBOL_ENUM;
|
|
288
|
-
warehouse_name: string;
|
|
289
|
-
}
|
|
290
|
-
export interface IWorker_UpdateWarehouseInventoryOnUpdateInvoice {
|
|
291
|
-
prevInvoiceJson: IWarehouseClientInvoice;
|
|
292
|
-
newInvoiceJson: IWarehouseClientInvoice;
|
|
293
|
-
currency_symbol: CURRENCY_SYMBOL_ENUM;
|
|
294
|
-
warehouse_name: string;
|
|
295
|
-
}
|
|
296
|
-
export interface IWorker_UpdateWarehouseInventoryOnCancelInvoice {
|
|
297
|
-
invoice: IWarehouseClientInvoice;
|
|
298
|
-
currency_symbol: CURRENCY_SYMBOL_ENUM;
|
|
299
|
-
warehouse_name: string;
|
|
300
|
-
prevInvoiceStatus?: WAREHOUSE_INVOICE_STATUS_ENUM;
|
|
301
|
-
}
|
|
302
280
|
export interface IWorker_SyncDineinTableWithOrder {
|
|
303
281
|
order: IOrder;
|
|
304
282
|
}
|
|
@@ -411,10 +389,10 @@ export interface ITrackedRollbackPlanLine {
|
|
|
411
389
|
export interface IWorker_PostWarehouseActivityLogs {
|
|
412
390
|
logs: {
|
|
413
391
|
warehouse_id: string;
|
|
414
|
-
entity_type: WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM
|
|
392
|
+
entity_type: WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM;
|
|
415
393
|
entity_id: string;
|
|
416
394
|
entity_number?: number | null;
|
|
417
|
-
action: WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM
|
|
395
|
+
action: WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
|
|
418
396
|
title: string;
|
|
419
397
|
description?: string | null;
|
|
420
398
|
changes?: IWarehouseActivityLogChange[];
|
|
@@ -23,7 +23,6 @@ export * from './ingredients';
|
|
|
23
23
|
export * from './internal-amount-helpers';
|
|
24
24
|
export * from './inventory';
|
|
25
25
|
export * from './inventory_transactions';
|
|
26
|
-
export * from './warehouse-invoice-x-report-helpers';
|
|
27
26
|
export * from './item-report-helpers';
|
|
28
27
|
export * from './items-comparison-report-helpers';
|
|
29
28
|
export * from './kds-helpers';
|
|
@@ -60,21 +59,22 @@ export * from './tenant-staff-helpers';
|
|
|
60
59
|
export * from './time-helpers';
|
|
61
60
|
export * from './void-items-report-helpers';
|
|
62
61
|
export * from './void-order-items-helpers';
|
|
63
|
-
export * from './void-warehouse-invoice-items-helpers';
|
|
64
|
-
export * from './void-warehouse-invoice-items-report-helpers';
|
|
65
62
|
export * from './voidations-summary-report-helpers';
|
|
66
63
|
export * from './wallet-helpers';
|
|
67
64
|
export * from './wallet-redemption-helpers';
|
|
68
65
|
export * from './warehouse-catalog-conversion';
|
|
69
66
|
export * from './warehouse-inventory';
|
|
70
|
-
export * from './warehouse-invoice-order-engine';
|
|
71
67
|
export * from './warehouse-purchase-order-engine';
|
|
72
68
|
export * from './warehouse-purchase-order-receipt-engine';
|
|
73
69
|
export * from './warehouse-purchase-order-x-report-helpers';
|
|
70
|
+
export * from './warehouse-sale-order-engine';
|
|
71
|
+
export * from './warehouse-sale-order-receipt-engine';
|
|
74
72
|
export * from './warehouse-sale-order-x-report-helpers';
|
|
75
73
|
export * from './warehouse-sale-x-report-helpers';
|
|
76
74
|
export * from './warehouse-settings-helpers';
|
|
77
75
|
export * from './warehouse-void-purchase-order-items-helpers';
|
|
78
76
|
export * from './warehouse-void-purchase-order-items-report-helpers';
|
|
77
|
+
export * from './warehouse-void-sale-order-items-helpers';
|
|
78
|
+
export * from './warehouse-void-sale-order-items-report-helpers';
|
|
79
79
|
export * from './warehouse_inventory_transactions';
|
|
80
80
|
export * from './x-report-helpers';
|
|
@@ -39,7 +39,6 @@ __exportStar(require("./ingredients"), exports);
|
|
|
39
39
|
__exportStar(require("./internal-amount-helpers"), exports);
|
|
40
40
|
__exportStar(require("./inventory"), exports);
|
|
41
41
|
__exportStar(require("./inventory_transactions"), exports);
|
|
42
|
-
__exportStar(require("./warehouse-invoice-x-report-helpers"), exports);
|
|
43
42
|
__exportStar(require("./item-report-helpers"), exports);
|
|
44
43
|
__exportStar(require("./items-comparison-report-helpers"), exports);
|
|
45
44
|
__exportStar(require("./kds-helpers"), exports);
|
|
@@ -76,21 +75,22 @@ __exportStar(require("./tenant-staff-helpers"), exports);
|
|
|
76
75
|
__exportStar(require("./time-helpers"), exports);
|
|
77
76
|
__exportStar(require("./void-items-report-helpers"), exports);
|
|
78
77
|
__exportStar(require("./void-order-items-helpers"), exports);
|
|
79
|
-
__exportStar(require("./void-warehouse-invoice-items-helpers"), exports);
|
|
80
|
-
__exportStar(require("./void-warehouse-invoice-items-report-helpers"), exports);
|
|
81
78
|
__exportStar(require("./voidations-summary-report-helpers"), exports);
|
|
82
79
|
__exportStar(require("./wallet-helpers"), exports);
|
|
83
80
|
__exportStar(require("./wallet-redemption-helpers"), exports);
|
|
84
81
|
__exportStar(require("./warehouse-catalog-conversion"), exports);
|
|
85
82
|
__exportStar(require("./warehouse-inventory"), exports);
|
|
86
|
-
__exportStar(require("./warehouse-invoice-order-engine"), exports);
|
|
87
83
|
__exportStar(require("./warehouse-purchase-order-engine"), exports);
|
|
88
84
|
__exportStar(require("./warehouse-purchase-order-receipt-engine"), exports);
|
|
89
85
|
__exportStar(require("./warehouse-purchase-order-x-report-helpers"), exports);
|
|
86
|
+
__exportStar(require("./warehouse-sale-order-engine"), exports);
|
|
87
|
+
__exportStar(require("./warehouse-sale-order-receipt-engine"), exports);
|
|
90
88
|
__exportStar(require("./warehouse-sale-order-x-report-helpers"), exports);
|
|
91
89
|
__exportStar(require("./warehouse-sale-x-report-helpers"), exports);
|
|
92
90
|
__exportStar(require("./warehouse-settings-helpers"), exports);
|
|
93
91
|
__exportStar(require("./warehouse-void-purchase-order-items-helpers"), exports);
|
|
94
92
|
__exportStar(require("./warehouse-void-purchase-order-items-report-helpers"), exports);
|
|
93
|
+
__exportStar(require("./warehouse-void-sale-order-items-helpers"), exports);
|
|
94
|
+
__exportStar(require("./warehouse-void-sale-order-items-report-helpers"), exports);
|
|
95
95
|
__exportStar(require("./warehouse_inventory_transactions"), exports);
|
|
96
96
|
__exportStar(require("./x-report-helpers"), exports);
|