@managesome/eposmatic-toolkit 0.2.770 → 0.2.772
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/utils/receipt-engine.d.ts +7 -1
- package/lib/helpers/utils/receipt-engine.js +38 -33
- package/lib/tests/receipt-engine.test.js +86 -21
- package/package.json +1 -1
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +0 -44
- package/lib/constants/MATERIALIZED_REPORTS.js +0 -58
- package/lib/constants/WAREHOUSE_INVOICE.d.ts +0 -14
- package/lib/constants/WAREHOUSE_INVOICE.js +0 -35
- package/lib/helpers/offer/generate-offer.d.ts +0 -11
- package/lib/helpers/offer/generate-offer.js +0 -143
- package/lib/helpers/offer/index.d.ts +0 -1
- package/lib/helpers/offer/index.js +0 -17
- package/lib/helpers/order/generate-warehouse-invoice.d.ts +0 -11
- package/lib/helpers/order/generate-warehouse-invoice.js +0 -196
- package/lib/helpers/store/all-warehouse-invoice-actions.d.ts +0 -13
- package/lib/helpers/store/all-warehouse-invoice-actions.js +0 -58
- package/lib/helpers/store/common-warehouse-invoice-actions.d.ts +0 -31
- package/lib/helpers/store/common-warehouse-invoice-actions.js +0 -545
- package/lib/helpers/store/warehouse-invoice-cart-actions.d.ts +0 -24
- package/lib/helpers/store/warehouse-invoice-cart-actions.js +0 -486
- package/lib/helpers/types/sockets.d.ts +0 -6
- package/lib/helpers/types/sockets.js +0 -2
- package/lib/helpers/types/warehouse-invoice-cart-actions.d.ts +0 -26
- package/lib/helpers/types/warehouse-invoice-cart-actions.js +0 -2
- package/lib/helpers/utils/materialized-report-helpers.d.ts +0 -35
- package/lib/helpers/utils/materialized-report-helpers.js +0 -73
- package/lib/helpers/utils/void-warehouse-invoice-items-helpers.d.ts +0 -3
- package/lib/helpers/utils/void-warehouse-invoice-items-helpers.js +0 -38
- package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.d.ts +0 -13
- package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.js +0 -22
- package/lib/helpers/utils/warehouse-invoice-order-engine.d.ts +0 -11
- package/lib/helpers/utils/warehouse-invoice-order-engine.js +0 -39
- package/lib/helpers/utils/warehouse-invoice-x-report-helpers.d.ts +0 -58
- package/lib/helpers/utils/warehouse-invoice-x-report-helpers.js +0 -1432
- package/lib/schemas/models/inventory_department_transactions.d.ts +0 -86
- package/lib/schemas/models/inventory_department_transactions.js +0 -116
- package/lib/schemas/models/inventory_department_utilities.d.ts +0 -108
- package/lib/schemas/models/inventory_department_utilities.js +0 -88
- package/lib/schemas/models/inventory_departments.d.ts +0 -53
- package/lib/schemas/models/inventory_departments.js +0 -58
- package/lib/schemas/models/inventory_entries.d.ts +0 -152
- package/lib/schemas/models/inventory_entries.js +0 -142
- package/lib/schemas/models/materialized_reports.d.ts +0 -277
- package/lib/schemas/models/materialized_reports.js +0 -60
- package/lib/schemas/models/warehouse_invoices.d.ts +0 -2675
- package/lib/schemas/models/warehouse_invoices.js +0 -327
- package/lib/schemas/models/warehouse_void_invoice_items.d.ts +0 -176
- package/lib/schemas/models/warehouse_void_invoice_items.js +0 -176
- package/lib/schemas/types/inventory_entries.d.ts +0 -41
- package/lib/schemas/types/inventory_entries.js +0 -2
- package/lib/schemas/types/materialized_reports.d.ts +0 -82
- package/lib/schemas/types/materialized_reports.js +0 -2
- package/lib/schemas/types/warehouse_invoices.d.ts +0 -69
- package/lib/schemas/types/warehouse_invoices.js +0 -2
- package/lib/schemas/types/warehouse_void_invoice_items.d.ts +0 -37
- package/lib/schemas/types/warehouse_void_invoice_items.js +0 -2
- package/lib/tests/materialized-report-helpers.test.d.ts +0 -1
- package/lib/tests/no-choice-modifier-selection.test.d.ts +0 -1
- package/lib/tests/no-choice-modifier-selection.test.js +0 -142
|
@@ -1,545 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getWarehouseClientInvoiceIterationsWithPrice = getWarehouseClientInvoiceIterationsWithPrice;
|
|
7
|
-
exports.getWarehouseClientInvoicePaymentsWithPrice = getWarehouseClientInvoicePaymentsWithPrice;
|
|
8
|
-
exports.getWarehouseClientInvoiceItemsWithPrice = getWarehouseClientInvoiceItemsWithPrice;
|
|
9
|
-
exports.getWarehouseClientInvoiceCategoriesWithPrice = getWarehouseClientInvoiceCategoriesWithPrice;
|
|
10
|
-
exports.getWarehouseClientInvoiceWithPrice = getWarehouseClientInvoiceWithPrice;
|
|
11
|
-
exports.syncWarehouseClientInvoiceData = syncWarehouseClientInvoiceData;
|
|
12
|
-
exports.skipItemMetadataFromWarehouseClientInvoiceCategories = skipItemMetadataFromWarehouseClientInvoiceCategories;
|
|
13
|
-
exports.getWarehouseClientInvoiceWithAllFields = getWarehouseClientInvoiceWithAllFields;
|
|
14
|
-
exports.getWarehouseClientInvoiceCartItemsObj = getWarehouseClientInvoiceCartItemsObj;
|
|
15
|
-
exports.getVoidItemsWithReasonWarehouseClientInvoice = getVoidItemsWithReasonWarehouseClientInvoice;
|
|
16
|
-
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
17
|
-
const lodash_1 = require("lodash");
|
|
18
|
-
const constants_1 = require("../../constants");
|
|
19
|
-
const utils_1 = require("../utils");
|
|
20
|
-
const common_order_actions_1 = require("./common-order-actions");
|
|
21
|
-
const warehouse_invoice_cart_actions_1 = require("./warehouse-invoice-cart-actions");
|
|
22
|
-
function getWarehouseClientInvoiceIterationsWithPrice(iterations, writeable) {
|
|
23
|
-
if (!iterations)
|
|
24
|
-
return [];
|
|
25
|
-
return iterations.map((iteration) => getWarehouseClientInvoiceWithPrice(iteration, writeable));
|
|
26
|
-
}
|
|
27
|
-
function getWarehouseClientInvoicePaymentsWithPrice(payments, convertToPrice) {
|
|
28
|
-
if (!payments)
|
|
29
|
-
return [];
|
|
30
|
-
return payments.map((payment) => ({
|
|
31
|
-
...payment,
|
|
32
|
-
card_details: (0, common_order_actions_1.getOrderPaymentsCardDetailsWithPrice)(payment.card_details, convertToPrice),
|
|
33
|
-
amount_paid: convertToPrice(payment.amount_paid),
|
|
34
|
-
amount_due: convertToPrice(payment.amount_due),
|
|
35
|
-
amount_refunded: convertToPrice(payment.amount_refunded),
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
function getWarehouseClientInvoiceItemsWithPrice(items, convertToPrice) {
|
|
39
|
-
if (!items)
|
|
40
|
-
return [];
|
|
41
|
-
return items.map((item) => ({
|
|
42
|
-
...item,
|
|
43
|
-
quantity: (0, utils_1.parseNum)(item.quantity || 1, true),
|
|
44
|
-
price: convertToPrice(item.price ?? 0),
|
|
45
|
-
subtotal: convertToPrice(item.subtotal ?? 0),
|
|
46
|
-
_gst_amount: convertToPrice(item._gst_amount ?? 0),
|
|
47
|
-
_net_amount: convertToPrice(item._net_amount ?? 0),
|
|
48
|
-
_gross_amount: convertToPrice(item._gross_amount ?? 0),
|
|
49
|
-
_discount_amount: convertToPrice(item._discount_amount ?? 0),
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
function getWarehouseClientInvoiceCategoriesWithPrice(categories, convertToPrice) {
|
|
53
|
-
if (!categories)
|
|
54
|
-
return [];
|
|
55
|
-
return categories.map((category) => ({
|
|
56
|
-
...category,
|
|
57
|
-
items: getWarehouseClientInvoiceItemsWithPrice(category.items, convertToPrice),
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
function getWarehouseClientInvoiceWithPrice(order, writeable) {
|
|
61
|
-
const convertToPrice = writeable ? utils_1.convertDecimalToInt : utils_1.convertIntToDecimal;
|
|
62
|
-
const payload = {
|
|
63
|
-
...order,
|
|
64
|
-
...(order.iterations != null
|
|
65
|
-
? {
|
|
66
|
-
iterations: getWarehouseClientInvoiceIterationsWithPrice(order.iterations, writeable),
|
|
67
|
-
}
|
|
68
|
-
: {}),
|
|
69
|
-
...(order.categories != null
|
|
70
|
-
? {
|
|
71
|
-
categories: getWarehouseClientInvoiceCategoriesWithPrice(order.categories, convertToPrice),
|
|
72
|
-
}
|
|
73
|
-
: {}),
|
|
74
|
-
...(order.payments != null
|
|
75
|
-
? { payments: getWarehouseClientInvoicePaymentsWithPrice(order.payments, convertToPrice) }
|
|
76
|
-
: {}),
|
|
77
|
-
...(order.gst != null ? { gst: convertToPrice(order.gst) } : {}),
|
|
78
|
-
...(order.gst_amount != null ? { gst_amount: convertToPrice(order.gst_amount) } : {}),
|
|
79
|
-
...(order.amount_collected != null
|
|
80
|
-
? { amount_collected: convertToPrice(order.amount_collected) }
|
|
81
|
-
: {}),
|
|
82
|
-
...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
|
|
83
|
-
...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
|
|
84
|
-
...(order.price != null ? { price: convertToPrice(order.price) } : {}),
|
|
85
|
-
};
|
|
86
|
-
return payload;
|
|
87
|
-
}
|
|
88
|
-
function syncWarehouseClientInvoiceData(order) {
|
|
89
|
-
const updatedOrder = {
|
|
90
|
-
...order,
|
|
91
|
-
iterations: [],
|
|
92
|
-
};
|
|
93
|
-
const newOrder = getWarehouseClientInvoiceWithPrice((0, warehouse_invoice_cart_actions_1.calculateCartWarehouseClientInvoiceInfoAndSyncData)(getWarehouseClientInvoiceWithPrice(updatedOrder), true), true);
|
|
94
|
-
newOrder.iterations = order.iterations;
|
|
95
|
-
return newOrder;
|
|
96
|
-
}
|
|
97
|
-
function skipItemMetadataFromWarehouseClientInvoiceCategories(categories, previousCategories) {
|
|
98
|
-
return categories.map((category) => {
|
|
99
|
-
const previousCategory = previousCategories?.find((prevCategory) => prevCategory.category_id === category.category_id);
|
|
100
|
-
return {
|
|
101
|
-
...category,
|
|
102
|
-
items: category.items.map((item) => {
|
|
103
|
-
const previousItem = previousCategory?.items.find((prevItem) => prevItem._id === item._id);
|
|
104
|
-
const void_reason = previousItem?.void_reason ?? item.void_reason;
|
|
105
|
-
const newItem = {
|
|
106
|
-
...item,
|
|
107
|
-
void_reason,
|
|
108
|
-
_discount_amount: 0,
|
|
109
|
-
_gst_amount: 0,
|
|
110
|
-
_gross_amount: 0,
|
|
111
|
-
_net_amount: 0,
|
|
112
|
-
};
|
|
113
|
-
return newItem;
|
|
114
|
-
}),
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
function getCommonOptionalBoolFieldsWarehouseClientInvoice(order, partial) {
|
|
119
|
-
const defaultValue = partial ? undefined : false;
|
|
120
|
-
return {
|
|
121
|
-
is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
|
|
122
|
-
is_reopened: order['is_reopened'] || defaultValue,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function getCommonOptionalNumFieldsWarehouseClientInvoice(order, partial) {
|
|
126
|
-
const defaultValue = partial ? undefined : 0;
|
|
127
|
-
return {
|
|
128
|
-
gst: order['gst'] || defaultValue,
|
|
129
|
-
gst_amount: order['gst_amount'] || defaultValue,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
function getWarehouseClientInvoiceWithAllFields(order, skipItemMetadata) {
|
|
133
|
-
return {
|
|
134
|
-
...order,
|
|
135
|
-
...getCommonOptionalBoolFieldsWarehouseClientInvoice(order, false),
|
|
136
|
-
...getCommonOptionalNumFieldsWarehouseClientInvoice(order, false),
|
|
137
|
-
...(skipItemMetadata && order.categories != null
|
|
138
|
-
? {
|
|
139
|
-
categories: skipItemMetadataFromWarehouseClientInvoiceCategories(order.categories),
|
|
140
|
-
}
|
|
141
|
-
: {}),
|
|
142
|
-
delete_reason: order['delete_reason'] ?? null,
|
|
143
|
-
cancel_reason: order['cancel_reason'] ?? null,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function getWarehouseClientInvoiceCartItemsObj({ 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)((0, warehouse_invoice_cart_actions_1.getWarehouseClientInvoiceItemComparableData)(currentItem), (0, warehouse_invoice_cart_actions_1.getWarehouseClientInvoiceItemComparableData)(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
|
-
// price: number;
|
|
323
|
-
// subtotal: number;
|
|
324
|
-
// tax_rate: number;
|
|
325
|
-
// quantity: number;
|
|
326
|
-
special_instructions: currentItem.special_instructions,
|
|
327
|
-
};
|
|
328
|
-
const prev = {
|
|
329
|
-
_id: prevItem._id,
|
|
330
|
-
item_id: prevItem.item_id,
|
|
331
|
-
name: prevItem.name,
|
|
332
|
-
// price: number;
|
|
333
|
-
// subtotal: number;
|
|
334
|
-
// tax_rate: number;
|
|
335
|
-
// quantity: number;
|
|
336
|
-
special_instructions: prevItem.special_instructions,
|
|
337
|
-
};
|
|
338
|
-
const isBothEqual = (0, lodash_1.isEqual)(curr, prev);
|
|
339
|
-
if (isBothEqual) {
|
|
340
|
-
unChangedItems.push(currentItem);
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
// For edited item, we don't need to have tempUnchangedItemIds
|
|
344
|
-
// because it's the turn for edited item
|
|
345
|
-
editedItems.push(currentItem);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
// Step 4: Get the items that are present in the current iteration
|
|
351
|
-
// but not present in the previous iteration
|
|
352
|
-
for (let i = 0; i < currentItems.length; i++) {
|
|
353
|
-
const item = currentItems[i];
|
|
354
|
-
if (prevItemsMap[item._id] == null) {
|
|
355
|
-
newItems.push(item);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
// Lastly, we need to check if any same item has been removed and added
|
|
359
|
-
// If so, the we need to remove the item from removedItems and newItems, and add it to unChangedItems
|
|
360
|
-
if (removedItems.length > 0 && newItems.length > 0) {
|
|
361
|
-
const newItemsMap = newItems.reduce((acc, item) => {
|
|
362
|
-
acc[item.item_id] = [...(acc[item.item_id] ?? []), item];
|
|
363
|
-
return acc;
|
|
364
|
-
}, {});
|
|
365
|
-
const revertedRemovedItems = [];
|
|
366
|
-
const revertedNewItems = [];
|
|
367
|
-
const additionalNewItems = [];
|
|
368
|
-
for (let i = 0; i < removedItems.length; i++) {
|
|
369
|
-
const removedItem = removedItems[i];
|
|
370
|
-
// Need to check if the removed item is present in the newItems
|
|
371
|
-
const newItemsForItem = newItemsMap[removedItem.item_id];
|
|
372
|
-
if (newItemsForItem == null)
|
|
373
|
-
continue;
|
|
374
|
-
if (newItemsForItem.length > 0) {
|
|
375
|
-
const newItemsForItemLength = newItemsForItem.length;
|
|
376
|
-
for (let j = 0; j < newItemsForItemLength; j++) {
|
|
377
|
-
const newItem = newItemsForItem[j];
|
|
378
|
-
const newI = {
|
|
379
|
-
// _id: newItem._id,
|
|
380
|
-
item_id: newItem.item_id,
|
|
381
|
-
name: newItem.name,
|
|
382
|
-
price: newItem.price,
|
|
383
|
-
// subtotal: number;
|
|
384
|
-
// quantity: newItem.quantity,
|
|
385
|
-
special_instructions: newItem.special_instructions,
|
|
386
|
-
};
|
|
387
|
-
const removedI = {
|
|
388
|
-
// _id: removedItem._id,
|
|
389
|
-
item_id: removedItem.item_id,
|
|
390
|
-
name: removedItem.name,
|
|
391
|
-
price: removedItem.price,
|
|
392
|
-
// subtotal: number;
|
|
393
|
-
// quantity: removedItem.quantity,
|
|
394
|
-
special_instructions: removedItem.special_instructions,
|
|
395
|
-
};
|
|
396
|
-
if ((0, lodash_1.isEqual)(newI, removedI)) {
|
|
397
|
-
if (newItem.quantity === removedItem.quantity) {
|
|
398
|
-
newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
|
|
399
|
-
if (newItemsMap[removedItem.item_id].length === 0) {
|
|
400
|
-
delete newItemsMap[removedItem.item_id];
|
|
401
|
-
}
|
|
402
|
-
revertedNewItems.push(newItem);
|
|
403
|
-
revertedRemovedItems.push(removedItem);
|
|
404
|
-
// We will break the loop when ever we push to revertedRemovedItems
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
408
|
-
if (removedItem.quantity > newItem.quantity) {
|
|
409
|
-
newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
|
|
410
|
-
if (newItemsMap[removedItem.item_id].length === 0) {
|
|
411
|
-
delete newItemsMap[removedItem.item_id];
|
|
412
|
-
}
|
|
413
|
-
revertedNewItems.push(newItem);
|
|
414
|
-
const subtotalForSingle = removedItem.subtotal / removedItem.quantity;
|
|
415
|
-
// We will only minus the quantity from removedItem
|
|
416
|
-
const newQuantity = removedItem.quantity - newItem.quantity;
|
|
417
|
-
const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
|
|
418
|
-
removedItem.quantity = newQuantity;
|
|
419
|
-
removedItem.subtotal = newSubtotal;
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
revertedRemovedItems.push(removedItem);
|
|
423
|
-
const nQuantity = newItem.quantity;
|
|
424
|
-
const subtotalForSingle = newItem.subtotal / nQuantity;
|
|
425
|
-
const newQuantity = nQuantity - removedItem.quantity;
|
|
426
|
-
const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
|
|
427
|
-
newItem.quantity = newQuantity;
|
|
428
|
-
newItem.subtotal = newSubtotal;
|
|
429
|
-
// =====================><=====================
|
|
430
|
-
const remainingQuantity = nQuantity - newQuantity;
|
|
431
|
-
const adItem = {
|
|
432
|
-
...newItem,
|
|
433
|
-
quantity: remainingQuantity,
|
|
434
|
-
subtotal: (0, utils_1.parseNum)(remainingQuantity * subtotalForSingle),
|
|
435
|
-
};
|
|
436
|
-
additionalNewItems.push(adItem);
|
|
437
|
-
// We will break the loop when ever we push to revertedRemovedItems
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
delete newItemsMap[removedItem.item_id];
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
for (let i = 0; i < revertedRemovedItems.length; i++) {
|
|
449
|
-
const rItem = revertedRemovedItems[i];
|
|
450
|
-
removedItems = removedItems.filter((item) => item._id !== rItem._id);
|
|
451
|
-
}
|
|
452
|
-
for (let i = 0; i < revertedNewItems.length; i++) {
|
|
453
|
-
const nItem = revertedNewItems[i];
|
|
454
|
-
newItems = newItems.filter((item) => item._id !== nItem._id);
|
|
455
|
-
unChangedItems.push(nItem);
|
|
456
|
-
}
|
|
457
|
-
for (let i = 0; i < additionalNewItems.length; i++) {
|
|
458
|
-
const aItem = additionalNewItems[i];
|
|
459
|
-
unChangedItems.push(aItem);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
disabledReason =
|
|
463
|
-
unChangedItems.length === prevItems.length &&
|
|
464
|
-
newItems.length === 0 &&
|
|
465
|
-
removedItems.length === 0 &&
|
|
466
|
-
editedItems.length === 0
|
|
467
|
-
? 'No changes in the order'
|
|
468
|
-
: prevItems.length === removedItems.length - totalTempRemovedItems &&
|
|
469
|
-
editedItems.length === 0 &&
|
|
470
|
-
newItems.length === 0
|
|
471
|
-
? 'At least one item is required'
|
|
472
|
-
: '';
|
|
473
|
-
}
|
|
474
|
-
const cartItemsObj = {
|
|
475
|
-
unChangedItems: getCartItems(unChangedItems),
|
|
476
|
-
editedItems: getCartItems(editedItems),
|
|
477
|
-
removedItems: getCartItems(removedItems),
|
|
478
|
-
newItems: getCartItems(newItems),
|
|
479
|
-
totalSelectedItems: (0, utils_1.parseNum)(totalItemsInCart, true),
|
|
480
|
-
disabledReason,
|
|
481
|
-
isAnUpdate,
|
|
482
|
-
};
|
|
483
|
-
return cartItemsObj;
|
|
484
|
-
}
|
|
485
|
-
function getVoidItemsWithReasonWarehouseClientInvoice({ currentCategories, iterationsFromFrontend, previousCategories, }) {
|
|
486
|
-
const voidOrderItemReasonsMap = {};
|
|
487
|
-
const latestIterationCategories = iterationsFromFrontend?.[0]?.categories;
|
|
488
|
-
if (latestIterationCategories != null && latestIterationCategories.length > 0) {
|
|
489
|
-
for (let i = 0; i < latestIterationCategories.length; i++) {
|
|
490
|
-
const category = latestIterationCategories[i];
|
|
491
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
492
|
-
const item = category.items[j];
|
|
493
|
-
if (item.void_reason != null && item.void_reason.length > 0) {
|
|
494
|
-
voidOrderItemReasonsMap[item._id] = item.void_reason;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
const { newItems, removedItems } = getWarehouseClientInvoiceCartItemsObj({
|
|
500
|
-
currentIterationCategories: currentCategories,
|
|
501
|
-
previousIterationCategories: previousCategories,
|
|
502
|
-
mappedItems: {},
|
|
503
|
-
shouldSortItemsViaId: false,
|
|
504
|
-
isAnEdit: true,
|
|
505
|
-
});
|
|
506
|
-
const hasNewItems = newItems.length > 0;
|
|
507
|
-
const voidOrderItems = [];
|
|
508
|
-
const newVoidOrderItemReasonsMap = {};
|
|
509
|
-
for (let i = 0; i < removedItems.length; i++) {
|
|
510
|
-
const { orderItem } = removedItems[i];
|
|
511
|
-
const voidReason = voidOrderItemReasonsMap[orderItem._id];
|
|
512
|
-
voidOrderItems.push({
|
|
513
|
-
...orderItem,
|
|
514
|
-
subtotal: Math.round(orderItem.subtotal),
|
|
515
|
-
void_reason: voidReason ?? '-',
|
|
516
|
-
});
|
|
517
|
-
if (voidReason != null) {
|
|
518
|
-
newVoidOrderItemReasonsMap[orderItem._id] = voidReason;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
const newIterationCategories = [];
|
|
522
|
-
for (let i = 0; i < previousCategories.length; i++) {
|
|
523
|
-
const category = previousCategories[i];
|
|
524
|
-
const newCategoryItems = [];
|
|
525
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
526
|
-
const prevItem = category.items[j];
|
|
527
|
-
const voidReason = newVoidOrderItemReasonsMap[prevItem._id];
|
|
528
|
-
const orderItem = {
|
|
529
|
-
...prevItem,
|
|
530
|
-
subtotal: Math.round(prevItem.subtotal),
|
|
531
|
-
};
|
|
532
|
-
if (voidReason != null) {
|
|
533
|
-
orderItem.void_reason = voidReason;
|
|
534
|
-
}
|
|
535
|
-
newCategoryItems.push(orderItem);
|
|
536
|
-
}
|
|
537
|
-
if (newCategoryItems.length === 0)
|
|
538
|
-
continue;
|
|
539
|
-
newIterationCategories.push({
|
|
540
|
-
...category,
|
|
541
|
-
items: newCategoryItems,
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
return { newIterationCategories, voidOrderItems, hasNewItems };
|
|
545
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { IWarehouseClientInvoice, IWarehouseClientInvoiceItem } from '../../schemas';
|
|
2
|
-
export declare const getWarehouseClientInvoiceItemComparableData: (item: IWarehouseClientInvoiceItem) => Partial<IWarehouseClientInvoiceItem>;
|
|
3
|
-
export declare function calculateCartWarehouseClientInvoiceInfoAndSyncData<T extends IWarehouseClientInvoice | Partial<IWarehouseClientInvoice>>(data: T, calculateItemMetadata?: boolean): T;
|
|
4
|
-
export declare function getUpdatedWarehouseInvoiceCartInfoOnInit(data: Partial<IWarehouseClientInvoice>, order: Partial<IWarehouseClientInvoice>): any;
|
|
5
|
-
export declare function getRemoveItemFromWarehouseInvoiceCartData(data: Partial<IWarehouseClientInvoice>, payload: {
|
|
6
|
-
_id: string;
|
|
7
|
-
void_reason?: string;
|
|
8
|
-
}): Partial<IWarehouseClientInvoice>;
|
|
9
|
-
export declare function getUpdateWarehouseInvoiceCartInfoData(data: Partial<IWarehouseClientInvoice>, payload: Partial<IWarehouseClientInvoice>): Partial<IWarehouseClientInvoice>;
|
|
10
|
-
export interface ISetAddItemToWarehouseInvoiceCartActionPayload {
|
|
11
|
-
name: string;
|
|
12
|
-
category_id: string;
|
|
13
|
-
item: IWarehouseClientInvoiceItem;
|
|
14
|
-
replace_id?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function getAddItemToWarehouseInvoiceCartData(data: Partial<IWarehouseClientInvoice>, payload: ISetAddItemToWarehouseInvoiceCartActionPayload): Partial<IWarehouseClientInvoice>;
|
|
17
|
-
export declare function getUpdateItemInWarehouseInvoiceCartData(data: Partial<IWarehouseClientInvoice>, payload: Partial<IWarehouseClientInvoiceItem>): Partial<IWarehouseClientInvoice>;
|
|
18
|
-
export declare function getUpdateItemsInWarehouseInvoiceCartData(data: Partial<IWarehouseClientInvoice>, payload: Partial<IWarehouseClientInvoiceItem>[]): Partial<IWarehouseClientInvoice>;
|
|
19
|
-
export interface IGetSplitWarehouseInvoiceCartItemToTwo {
|
|
20
|
-
data: Partial<IWarehouseClientInvoice>;
|
|
21
|
-
orderItemId: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function getSplitWarehouseInvoiceCartItemToTwo({ data, orderItemId, }: IGetSplitWarehouseInvoiceCartItemToTwo): Partial<IWarehouseClientInvoice>;
|
|
24
|
-
export declare function getAddItemsToWarehouseInvoiceCartData(data: Partial<IWarehouseClientInvoice>, payload: ISetAddItemToWarehouseInvoiceCartActionPayload[]): Partial<IWarehouseClientInvoice>;
|