@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,486 +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.getWarehouseClientInvoiceItemComparableData = void 0;
|
|
7
|
-
exports.calculateCartWarehouseClientInvoiceInfoAndSyncData = calculateCartWarehouseClientInvoiceInfoAndSyncData;
|
|
8
|
-
exports.getUpdatedWarehouseInvoiceCartInfoOnInit = getUpdatedWarehouseInvoiceCartInfoOnInit;
|
|
9
|
-
exports.getRemoveItemFromWarehouseInvoiceCartData = getRemoveItemFromWarehouseInvoiceCartData;
|
|
10
|
-
exports.getUpdateWarehouseInvoiceCartInfoData = getUpdateWarehouseInvoiceCartInfoData;
|
|
11
|
-
exports.getAddItemToWarehouseInvoiceCartData = getAddItemToWarehouseInvoiceCartData;
|
|
12
|
-
exports.getUpdateItemInWarehouseInvoiceCartData = getUpdateItemInWarehouseInvoiceCartData;
|
|
13
|
-
exports.getUpdateItemsInWarehouseInvoiceCartData = getUpdateItemsInWarehouseInvoiceCartData;
|
|
14
|
-
exports.getSplitWarehouseInvoiceCartItemToTwo = getSplitWarehouseInvoiceCartItemToTwo;
|
|
15
|
-
exports.getAddItemsToWarehouseInvoiceCartData = getAddItemsToWarehouseInvoiceCartData;
|
|
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 getWarehouseClientInvoiceItemComparableData = (item) => ({
|
|
21
|
-
item_id: item.item_id,
|
|
22
|
-
name: item.name,
|
|
23
|
-
price: item.price,
|
|
24
|
-
special_instructions: item.special_instructions,
|
|
25
|
-
_id: item._id,
|
|
26
|
-
quantity: item.quantity,
|
|
27
|
-
});
|
|
28
|
-
exports.getWarehouseClientInvoiceItemComparableData = getWarehouseClientInvoiceItemComparableData;
|
|
29
|
-
function calculateCartWarehouseClientInvoiceInfoAndSyncData(data, calculateItemMetadata) {
|
|
30
|
-
const isCompleted = data.order_status === constants_1.WAREHOUSE_INVOICE_STATUS_ENUM.COMPLETED;
|
|
31
|
-
/* ===============================><=============================== */
|
|
32
|
-
let subtotal = 0;
|
|
33
|
-
const categories = [];
|
|
34
|
-
const length = data.categories?.length ?? 0;
|
|
35
|
-
for (let c = 0; c < length; c++) {
|
|
36
|
-
const category = data.categories[c];
|
|
37
|
-
const newItems = [];
|
|
38
|
-
const itemsLength = category.items.length;
|
|
39
|
-
for (let i = 0; i < itemsLength; i++) {
|
|
40
|
-
const item = category.items[i];
|
|
41
|
-
// For warehouse client invoices, subtotal is already set as price * quantity
|
|
42
|
-
// But to ensure, we can recalculate
|
|
43
|
-
const itemSubtotal = (0, utils_1.parseNum)(item.price * item.quantity);
|
|
44
|
-
const newItem = {
|
|
45
|
-
...item,
|
|
46
|
-
is_ready: item.is_ready || isCompleted,
|
|
47
|
-
subtotal: itemSubtotal,
|
|
48
|
-
// These values will be auto calculated
|
|
49
|
-
_discount_amount: 0,
|
|
50
|
-
_gross_amount: 0,
|
|
51
|
-
_gst_amount: 0,
|
|
52
|
-
_net_amount: 0,
|
|
53
|
-
};
|
|
54
|
-
delete newItem.void_reason;
|
|
55
|
-
newItems.push(newItem);
|
|
56
|
-
subtotal += itemSubtotal;
|
|
57
|
-
}
|
|
58
|
-
categories.push({
|
|
59
|
-
...category,
|
|
60
|
-
items: newItems,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
let grand_total = subtotal;
|
|
64
|
-
// GST is represented in percentage. We convert it to decimal
|
|
65
|
-
let gst_amount = 0;
|
|
66
|
-
const gst = data.gst ?? 0;
|
|
67
|
-
if (data.is_gst_inclusive) {
|
|
68
|
-
// If GST is inclusive, it means that the Tax is already included in the Sale Value
|
|
69
|
-
// However, we need to calculate the Sale Value without the Tax
|
|
70
|
-
// And then calculate the Tax amount from the Sale Value without Tax
|
|
71
|
-
gst_amount = (0, utils_1.parseFloatCeil)((grand_total * gst) / (100 + gst));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
gst_amount = (0, utils_1.getPercentageAmount)(grand_total, gst);
|
|
75
|
-
// Add GST amount to orderSubtotal
|
|
76
|
-
grand_total += gst_amount;
|
|
77
|
-
}
|
|
78
|
-
// Add Card Charges to grand_total
|
|
79
|
-
const { cardCharges, amountCollected } = (0, utils_1.getCardChargesAndAmountCollected)(data.payments);
|
|
80
|
-
grand_total += cardCharges;
|
|
81
|
-
grand_total = (0, utils_1.parseNum)(grand_total);
|
|
82
|
-
const amount_collected = (0, utils_1.parseNum)(amountCollected);
|
|
83
|
-
const amount_earned = (0, utils_1.parseNum)(grand_total - cardCharges);
|
|
84
|
-
if (calculateItemMetadata) {
|
|
85
|
-
let leftGrossAmount = subtotal;
|
|
86
|
-
let leftNetAmount = subtotal;
|
|
87
|
-
let leftDiscountAmount = 0; // No discounts
|
|
88
|
-
let leftGstAmount = gst_amount;
|
|
89
|
-
categories.forEach((category, categoryIndex) => {
|
|
90
|
-
const isLastCategory = categoryIndex === categories.length - 1;
|
|
91
|
-
category.items.forEach((item, itemIndex) => {
|
|
92
|
-
const isLastItem = isLastCategory && itemIndex === category.items.length - 1;
|
|
93
|
-
let grossAmount = item.subtotal; // No discounts, so gross = subtotal
|
|
94
|
-
let netAmount = item.subtotal; // No discounts
|
|
95
|
-
let itemTotalDiscountAmount = 0; // No discounts
|
|
96
|
-
let itemGst = 0;
|
|
97
|
-
if (gst_amount > 0) {
|
|
98
|
-
itemGst = (item.subtotal / subtotal) * gst_amount;
|
|
99
|
-
}
|
|
100
|
-
grossAmount = (0, utils_1.parseFloatCeil)(grossAmount);
|
|
101
|
-
const netAmountParsed = (0, utils_1.parseFloatCeil)(netAmount);
|
|
102
|
-
const itemTotalDiscountAmountParsed = (0, utils_1.parseFloatCeil)(itemTotalDiscountAmount);
|
|
103
|
-
itemGst = (0, utils_1.parseFloatCeil)(itemGst);
|
|
104
|
-
leftGrossAmount -= grossAmount;
|
|
105
|
-
leftNetAmount -= netAmountParsed;
|
|
106
|
-
leftDiscountAmount -= itemTotalDiscountAmountParsed;
|
|
107
|
-
leftGstAmount -= itemGst;
|
|
108
|
-
if (isLastItem) {
|
|
109
|
-
grossAmount += leftGrossAmount;
|
|
110
|
-
netAmount += leftNetAmount;
|
|
111
|
-
itemTotalDiscountAmount += leftDiscountAmount;
|
|
112
|
-
itemGst += leftGstAmount;
|
|
113
|
-
}
|
|
114
|
-
item._gross_amount = Math.max(grossAmount, 0);
|
|
115
|
-
item._net_amount = Math.max(netAmount, 0);
|
|
116
|
-
item._discount_amount = Math.max(itemTotalDiscountAmount, 0);
|
|
117
|
-
item._gst_amount = Math.max(itemGst, 0);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
const cartData = {
|
|
122
|
-
...data,
|
|
123
|
-
categories,
|
|
124
|
-
amount_collected,
|
|
125
|
-
amount_earned,
|
|
126
|
-
gst_amount,
|
|
127
|
-
price: (0, utils_1.parseNum)(subtotal),
|
|
128
|
-
grand_total,
|
|
129
|
-
};
|
|
130
|
-
return cartData;
|
|
131
|
-
}
|
|
132
|
-
// =====================><=====================
|
|
133
|
-
function getUpdatedWarehouseInvoiceCartInfoOnInit(data, order) {
|
|
134
|
-
const merged = { ...data, ...order };
|
|
135
|
-
return calculateCartWarehouseClientInvoiceInfoAndSyncData(merged);
|
|
136
|
-
}
|
|
137
|
-
function getRemoveItemFromWarehouseInvoiceCartData(data, payload) {
|
|
138
|
-
const orderItemIdsMap = {};
|
|
139
|
-
let categories;
|
|
140
|
-
if (data.categories != null) {
|
|
141
|
-
categories = [];
|
|
142
|
-
for (let i = 0; i < data.categories.length; i++) {
|
|
143
|
-
const category = data.categories[i];
|
|
144
|
-
const items = [];
|
|
145
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
146
|
-
const item = category.items[j];
|
|
147
|
-
if (item._id !== payload._id) {
|
|
148
|
-
items.push(item);
|
|
149
|
-
orderItemIdsMap[item._id] = item.quantity;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (items.length > 0) {
|
|
153
|
-
categories.push({
|
|
154
|
-
...category,
|
|
155
|
-
items,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const iterations = [];
|
|
161
|
-
if (data.iterations != null && data.iterations.length > 0) {
|
|
162
|
-
const [firstIteration, ...restIterations] = data.iterations;
|
|
163
|
-
const firstIterationCategories = [];
|
|
164
|
-
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
165
|
-
const category = firstIteration.categories[i];
|
|
166
|
-
const allPrevItems = [];
|
|
167
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
168
|
-
const prevItem = category.items[j];
|
|
169
|
-
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
170
|
-
const newItem = {
|
|
171
|
-
...prevItem,
|
|
172
|
-
void_reason: payload.void_reason,
|
|
173
|
-
};
|
|
174
|
-
allPrevItems.push(newItem);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
// A Removed Item is one that is not in the orderItemIdsMap
|
|
178
|
-
// Or it is in the orderItemIdsMap but its quantity is less than newItem.quantity
|
|
179
|
-
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
180
|
-
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
181
|
-
if (isRemovedItem) {
|
|
182
|
-
allPrevItems.push(prevItem);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
// If the item is not removed, then we make sure to remove the void_reason
|
|
186
|
-
const updatedPrevItem = {
|
|
187
|
-
...prevItem,
|
|
188
|
-
};
|
|
189
|
-
delete updatedPrevItem.void_reason;
|
|
190
|
-
allPrevItems.push(updatedPrevItem);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (allPrevItems.length > 0) {
|
|
195
|
-
firstIterationCategories.push({
|
|
196
|
-
...category,
|
|
197
|
-
items: allPrevItems,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const firstIterationData = {
|
|
202
|
-
...firstIteration,
|
|
203
|
-
categories: firstIterationCategories,
|
|
204
|
-
};
|
|
205
|
-
iterations.push(firstIterationData);
|
|
206
|
-
iterations.push(...restIterations);
|
|
207
|
-
}
|
|
208
|
-
const order = {
|
|
209
|
-
...data,
|
|
210
|
-
...(iterations.length > 0 && { iterations }),
|
|
211
|
-
categories,
|
|
212
|
-
};
|
|
213
|
-
const newData = calculateCartWarehouseClientInvoiceInfoAndSyncData(order);
|
|
214
|
-
return newData;
|
|
215
|
-
}
|
|
216
|
-
function getUpdateWarehouseInvoiceCartInfoData(data, payload) {
|
|
217
|
-
const order = {
|
|
218
|
-
...data,
|
|
219
|
-
...payload,
|
|
220
|
-
};
|
|
221
|
-
const newData = calculateCartWarehouseClientInvoiceInfoAndSyncData(order);
|
|
222
|
-
return newData;
|
|
223
|
-
}
|
|
224
|
-
function getAddItemToWarehouseInvoiceCartData(data, payload) {
|
|
225
|
-
const getUpdatedWarehouseClientInvoiceItem = (item) => ({
|
|
226
|
-
item_id: item.item_id,
|
|
227
|
-
name: item.name,
|
|
228
|
-
price: item.price,
|
|
229
|
-
special_instructions: item.special_instructions,
|
|
230
|
-
});
|
|
231
|
-
const { category_id, name, item, replace_id } = payload;
|
|
232
|
-
let mainItemId = item._id;
|
|
233
|
-
const orderData = { ...data };
|
|
234
|
-
// =====================><=====================
|
|
235
|
-
const categories = [...(orderData.categories ?? [])];
|
|
236
|
-
let didFindCategory = false;
|
|
237
|
-
const categoriesLength = categories.length;
|
|
238
|
-
for (let i = 0; i < categoriesLength; i++) {
|
|
239
|
-
const category = categories[i];
|
|
240
|
-
if (category.category_id !== category_id)
|
|
241
|
-
continue;
|
|
242
|
-
const updatedItem = getUpdatedWarehouseClientInvoiceItem(item);
|
|
243
|
-
const allItems = [...category.items];
|
|
244
|
-
let didFindItem = false;
|
|
245
|
-
let itemExists = false;
|
|
246
|
-
const totalItems = allItems.length;
|
|
247
|
-
for (let j = 0; j < totalItems; j++) {
|
|
248
|
-
const itm = allItems[j];
|
|
249
|
-
if (itm._id === item._id) {
|
|
250
|
-
allItems[j] = item;
|
|
251
|
-
didFindItem = true;
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
if (itm.item_id === item.item_id) {
|
|
255
|
-
itemExists = true;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (!didFindItem && itemExists) {
|
|
259
|
-
for (let j = 0; j < totalItems; j++) {
|
|
260
|
-
const itm = allItems[j];
|
|
261
|
-
if (itm.item_id === item.item_id && (0, lodash_1.isEqual)(getUpdatedWarehouseClientInvoiceItem(itm), updatedItem)) {
|
|
262
|
-
mainItemId = replace_id ?? itm._id;
|
|
263
|
-
allItems[j] = {
|
|
264
|
-
...item,
|
|
265
|
-
_id: mainItemId,
|
|
266
|
-
quantity: item.quantity + itm.quantity,
|
|
267
|
-
};
|
|
268
|
-
didFindItem = true;
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (!didFindItem) {
|
|
274
|
-
allItems.push(item);
|
|
275
|
-
}
|
|
276
|
-
categories[i] = {
|
|
277
|
-
...category,
|
|
278
|
-
items: allItems,
|
|
279
|
-
};
|
|
280
|
-
didFindCategory = true;
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
if (!didFindCategory) {
|
|
284
|
-
categories.push({
|
|
285
|
-
category_id,
|
|
286
|
-
name,
|
|
287
|
-
items: [item],
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
// =====================><=====================
|
|
291
|
-
const iterations = [];
|
|
292
|
-
if (orderData.iterations != null && orderData.iterations.length > 0) {
|
|
293
|
-
const orderItemIdsMap = {};
|
|
294
|
-
for (let i = 0; i < categories.length; i++) {
|
|
295
|
-
const category = categories[i];
|
|
296
|
-
const items = category.items;
|
|
297
|
-
for (let j = 0; j < items.length; j++) {
|
|
298
|
-
const item = items[j];
|
|
299
|
-
orderItemIdsMap[item._id] = item.quantity;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
const [firstIteration, ...restIterations] = orderData.iterations;
|
|
303
|
-
const firstIterationCategories = [];
|
|
304
|
-
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
305
|
-
const category = firstIteration.categories[i];
|
|
306
|
-
const allPrevItems = [];
|
|
307
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
308
|
-
const prevItem = category.items[j];
|
|
309
|
-
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
310
|
-
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
311
|
-
if (isRemovedItem) {
|
|
312
|
-
allPrevItems.push(prevItem);
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
const updatedPrevItem = {
|
|
316
|
-
...prevItem,
|
|
317
|
-
};
|
|
318
|
-
delete updatedPrevItem.void_reason;
|
|
319
|
-
allPrevItems.push(updatedPrevItem);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
if (allPrevItems.length > 0) {
|
|
323
|
-
firstIterationCategories.push({
|
|
324
|
-
...category,
|
|
325
|
-
items: allPrevItems,
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
const firstIterationData = {
|
|
330
|
-
...firstIteration,
|
|
331
|
-
categories: firstIterationCategories,
|
|
332
|
-
};
|
|
333
|
-
iterations.push(firstIterationData);
|
|
334
|
-
iterations.push(...restIterations);
|
|
335
|
-
}
|
|
336
|
-
// =====================><=====================
|
|
337
|
-
const order = {
|
|
338
|
-
...orderData,
|
|
339
|
-
...(iterations.length > 0 && { iterations }),
|
|
340
|
-
categories,
|
|
341
|
-
};
|
|
342
|
-
const newData = calculateCartWarehouseClientInvoiceInfoAndSyncData(order);
|
|
343
|
-
return newData;
|
|
344
|
-
}
|
|
345
|
-
function getUpdateItemInWarehouseInvoiceCartData(data, payload) {
|
|
346
|
-
const orderItemIdsMap = {};
|
|
347
|
-
let categories;
|
|
348
|
-
if (data.categories != null) {
|
|
349
|
-
categories = [];
|
|
350
|
-
for (let i = 0; i < data.categories.length; i++) {
|
|
351
|
-
const category = data.categories[i];
|
|
352
|
-
const items = [];
|
|
353
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
354
|
-
const item = category.items[j];
|
|
355
|
-
let newItem = item;
|
|
356
|
-
if (item._id === payload._id) {
|
|
357
|
-
newItem = {
|
|
358
|
-
...item,
|
|
359
|
-
...payload,
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
if (newItem.quantity > 0) {
|
|
363
|
-
items.push(newItem);
|
|
364
|
-
orderItemIdsMap[newItem._id] = newItem.quantity;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
if (items.length > 0) {
|
|
368
|
-
categories.push({
|
|
369
|
-
...category,
|
|
370
|
-
items,
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
const iterations = [];
|
|
376
|
-
if (payload.quantity != null && data.iterations != null && data.iterations.length > 0) {
|
|
377
|
-
const [firstIteration, ...restIterations] = data.iterations;
|
|
378
|
-
const firstIterationCategories = [];
|
|
379
|
-
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
380
|
-
const category = firstIteration.categories[i];
|
|
381
|
-
const allPrevItems = [];
|
|
382
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
383
|
-
const prevItem = category.items[j];
|
|
384
|
-
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
385
|
-
const updatedPrevItem = {
|
|
386
|
-
...prevItem,
|
|
387
|
-
void_reason: payload.void_reason,
|
|
388
|
-
};
|
|
389
|
-
allPrevItems.push(updatedPrevItem);
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
// A Removed Item is one that is not in the orderItemIdsMap
|
|
393
|
-
// Or it is in the orderItemIdsMap but its quantity is less than newItem.quantity
|
|
394
|
-
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
395
|
-
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
396
|
-
if (isRemovedItem) {
|
|
397
|
-
allPrevItems.push(prevItem);
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
// If the item is not removed, then we make sure to remove the void_reason
|
|
401
|
-
const updatedPrevItem = {
|
|
402
|
-
...prevItem,
|
|
403
|
-
};
|
|
404
|
-
delete updatedPrevItem.void_reason;
|
|
405
|
-
allPrevItems.push(updatedPrevItem);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if (allPrevItems.length > 0) {
|
|
410
|
-
firstIterationCategories.push({
|
|
411
|
-
...category,
|
|
412
|
-
items: allPrevItems,
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
const firstIterationData = {
|
|
417
|
-
...firstIteration,
|
|
418
|
-
categories: firstIterationCategories,
|
|
419
|
-
};
|
|
420
|
-
iterations.push(firstIterationData);
|
|
421
|
-
iterations.push(...restIterations);
|
|
422
|
-
}
|
|
423
|
-
const order = {
|
|
424
|
-
...data,
|
|
425
|
-
...(iterations.length > 0 && { iterations }),
|
|
426
|
-
categories,
|
|
427
|
-
};
|
|
428
|
-
const newData = calculateCartWarehouseClientInvoiceInfoAndSyncData(order);
|
|
429
|
-
return newData;
|
|
430
|
-
}
|
|
431
|
-
function getUpdateItemsInWarehouseInvoiceCartData(data, payload) {
|
|
432
|
-
const newData = payload.reduce((acc, item) => getUpdateItemInWarehouseInvoiceCartData(acc, item), data);
|
|
433
|
-
return newData;
|
|
434
|
-
}
|
|
435
|
-
function getSplitWarehouseInvoiceCartItemToTwo({ data, orderItemId, }) {
|
|
436
|
-
if (data.categories == null)
|
|
437
|
-
return data;
|
|
438
|
-
const newCategories = [];
|
|
439
|
-
for (let i = 0; i < data.categories.length; i++) {
|
|
440
|
-
const category = data.categories[i];
|
|
441
|
-
const newItems = [];
|
|
442
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
443
|
-
const item = {
|
|
444
|
-
...category.items[j],
|
|
445
|
-
};
|
|
446
|
-
if (item._id !== orderItemId) {
|
|
447
|
-
newItems.push(item);
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
if (item.quantity === 1) {
|
|
451
|
-
newItems.push(item);
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
const prevQuantity = item.quantity;
|
|
455
|
-
const newQuantity = item.quantity - 1;
|
|
456
|
-
const prevItem = {
|
|
457
|
-
...item,
|
|
458
|
-
quantity: newQuantity,
|
|
459
|
-
subtotal: (0, utils_1.parseNum)(item.price * newQuantity),
|
|
460
|
-
};
|
|
461
|
-
newItems.push(prevItem);
|
|
462
|
-
const _id = new bson_objectid_1.default(Math.floor(new bson_objectid_1.default(item._id).getTimestamp().getTime() / 1000) + 1).toHexString();
|
|
463
|
-
newItems.push({
|
|
464
|
-
...item,
|
|
465
|
-
_id,
|
|
466
|
-
quantity: 1,
|
|
467
|
-
subtotal: (0, utils_1.parseNum)(item.price * 1),
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
newCategories.push({
|
|
471
|
-
...category,
|
|
472
|
-
items: newItems,
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
const order = {
|
|
476
|
-
...data,
|
|
477
|
-
categories: newCategories,
|
|
478
|
-
};
|
|
479
|
-
const newData = calculateCartWarehouseClientInvoiceInfoAndSyncData(order);
|
|
480
|
-
return newData;
|
|
481
|
-
}
|
|
482
|
-
function getAddItemsToWarehouseInvoiceCartData(data, payload) {
|
|
483
|
-
const newData = payload.reduce((acc, item) => getAddItemToWarehouseInvoiceCartData(acc, item), data);
|
|
484
|
-
return newData;
|
|
485
|
-
}
|
|
486
|
-
/* ======================><====================== */
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ITenantCashDrawerSession, ITenantDaySession, ITenantInstoreShiftSession } from '../../schemas';
|
|
2
|
-
export interface ISocket_FinalizedTenantDay {
|
|
3
|
-
shiftSessions: ITenantInstoreShiftSession[];
|
|
4
|
-
drawerSessions: ITenantCashDrawerSession[];
|
|
5
|
-
daySession: ITenantDaySession;
|
|
6
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { IWarehouseClientInvoiceItem } from '../../schemas';
|
|
2
|
-
export interface IGeneralWarehouseClientInvoiceItem {
|
|
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 IWarehouseClientInvoiceCartItem {
|
|
12
|
-
orderItem: IWarehouseClientInvoiceItem;
|
|
13
|
-
image_url: string | null;
|
|
14
|
-
description: string;
|
|
15
|
-
category_name: string;
|
|
16
|
-
category_id: string;
|
|
17
|
-
}
|
|
18
|
-
export interface IWarehouseClientInvoiceCartItemsObj {
|
|
19
|
-
unChangedItems: IWarehouseClientInvoiceCartItem[];
|
|
20
|
-
editedItems: IWarehouseClientInvoiceCartItem[];
|
|
21
|
-
removedItems: IWarehouseClientInvoiceCartItem[];
|
|
22
|
-
newItems: IWarehouseClientInvoiceCartItem[];
|
|
23
|
-
totalSelectedItems: number;
|
|
24
|
-
disabledReason: string;
|
|
25
|
-
isAnUpdate: boolean;
|
|
26
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ISalesOverviewBucket, ITenantSalesOverviewReport } from '../../schemas/types';
|
|
2
|
-
/**
|
|
3
|
-
* The rollup payload of a materialized sales overview doc — every
|
|
4
|
-
* additive metric, without identity/period metadata.
|
|
5
|
-
*/
|
|
6
|
-
export interface ISalesOverviewRollupPayload {
|
|
7
|
-
total_sales: ISalesOverviewBucket;
|
|
8
|
-
cancelled_orders: ISalesOverviewBucket;
|
|
9
|
-
total_payment_sales: ISalesOverviewBucket[];
|
|
10
|
-
sales_by_platform: ISalesOverviewBucket[];
|
|
11
|
-
complimentary_amount: number;
|
|
12
|
-
unpaid_amount: number;
|
|
13
|
-
amount_collected: number;
|
|
14
|
-
net_sales: number;
|
|
15
|
-
average_order_value: number;
|
|
16
|
-
covers: number;
|
|
17
|
-
first_order_at: Date | null;
|
|
18
|
-
last_order_at: Date | null;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Sums an array of bucket arrays, merging buckets by _id.
|
|
22
|
-
* Used to roll up localDate docs into week/month/quarter/semester/year docs.
|
|
23
|
-
*/
|
|
24
|
-
export declare function mergeSalesOverviewBuckets(bucketArrays: ISalesOverviewBucket[][]): ISalesOverviewBucket[];
|
|
25
|
-
/**
|
|
26
|
-
* Sums a single bucket across multiple docs.
|
|
27
|
-
*/
|
|
28
|
-
export declare function sumSalesOverviewBuckets(buckets: ISalesOverviewBucket[]): ISalesOverviewBucket;
|
|
29
|
-
/**
|
|
30
|
-
* Merges (rolls up) multiple materialized sales overview docs into one
|
|
31
|
-
* payload. All additive fields are summed; first/last order timestamps are
|
|
32
|
-
* min/max respectively. Non-additive derived fields (average_order_value)
|
|
33
|
-
* are recomputed from the summed values.
|
|
34
|
-
*/
|
|
35
|
-
export declare function rollupSalesOverviewDocs(docs: ITenantSalesOverviewReport[]): ISalesOverviewRollupPayload;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeSalesOverviewBuckets = mergeSalesOverviewBuckets;
|
|
4
|
-
exports.sumSalesOverviewBuckets = sumSalesOverviewBuckets;
|
|
5
|
-
exports.rollupSalesOverviewDocs = rollupSalesOverviewDocs;
|
|
6
|
-
/**
|
|
7
|
-
* Sums an array of bucket arrays, merging buckets by _id.
|
|
8
|
-
* Used to roll up localDate docs into week/month/quarter/semester/year docs.
|
|
9
|
-
*/
|
|
10
|
-
function mergeSalesOverviewBuckets(bucketArrays) {
|
|
11
|
-
const map = new Map();
|
|
12
|
-
for (const buckets of bucketArrays) {
|
|
13
|
-
for (const bucket of buckets) {
|
|
14
|
-
const existing = map.get(bucket._id);
|
|
15
|
-
if (existing == null) {
|
|
16
|
-
map.set(bucket._id, { ...bucket });
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
existing.count += bucket.count;
|
|
20
|
-
existing.grossAmount += bucket.grossAmount;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return Array.from(map.values());
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Sums a single bucket across multiple docs.
|
|
28
|
-
*/
|
|
29
|
-
function sumSalesOverviewBuckets(buckets) {
|
|
30
|
-
return buckets.reduce((acc, b) => {
|
|
31
|
-
acc.count += b.count;
|
|
32
|
-
acc.grossAmount += b.grossAmount;
|
|
33
|
-
return acc;
|
|
34
|
-
}, { _id: buckets[0]?._id ?? '', count: 0, grossAmount: 0 });
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Merges (rolls up) multiple materialized sales overview docs into one
|
|
38
|
-
* payload. All additive fields are summed; first/last order timestamps are
|
|
39
|
-
* min/max respectively. Non-additive derived fields (average_order_value)
|
|
40
|
-
* are recomputed from the summed values.
|
|
41
|
-
*/
|
|
42
|
-
function rollupSalesOverviewDocs(docs) {
|
|
43
|
-
const totalSales = sumSalesOverviewBuckets(docs.map((d) => d.total_sales));
|
|
44
|
-
return {
|
|
45
|
-
total_sales: totalSales,
|
|
46
|
-
cancelled_orders: sumSalesOverviewBuckets(docs.map((d) => d.cancelled_orders)),
|
|
47
|
-
total_payment_sales: mergeSalesOverviewBuckets(docs.map((d) => d.total_payment_sales)),
|
|
48
|
-
sales_by_platform: mergeSalesOverviewBuckets(docs.map((d) => d.sales_by_platform)),
|
|
49
|
-
complimentary_amount: sumField(docs, 'complimentary_amount'),
|
|
50
|
-
unpaid_amount: sumField(docs, 'unpaid_amount'),
|
|
51
|
-
amount_collected: sumField(docs, 'amount_collected'),
|
|
52
|
-
net_sales: sumField(docs, 'net_sales'),
|
|
53
|
-
covers: sumField(docs, 'covers'),
|
|
54
|
-
first_order_at: minDate(docs.map((d) => d.first_order_at)),
|
|
55
|
-
last_order_at: maxDate(docs.map((d) => d.last_order_at)),
|
|
56
|
-
average_order_value: totalSales.count > 0 ? totalSales.grossAmount / totalSales.count : 0,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function sumField(docs, field) {
|
|
60
|
-
return docs.reduce((sum, doc) => sum + (doc[field] ?? 0), 0);
|
|
61
|
-
}
|
|
62
|
-
function minDate(dates) {
|
|
63
|
-
const valid = dates.filter((d) => d != null);
|
|
64
|
-
return valid.length > 0
|
|
65
|
-
? new Date(Math.min(...valid.map((d) => new Date(d).getTime())))
|
|
66
|
-
: null;
|
|
67
|
-
}
|
|
68
|
-
function maxDate(dates) {
|
|
69
|
-
const valid = dates.filter((d) => d != null);
|
|
70
|
-
return valid.length > 0
|
|
71
|
-
? new Date(Math.max(...valid.map((d) => new Date(d).getTime())))
|
|
72
|
-
: null;
|
|
73
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { IWarehouseVoidInvoiceItem } from '../../schemas';
|
|
2
|
-
export declare function getVoidWarehouseInvoiceItemFromCents<T extends Partial<IWarehouseVoidInvoiceItem> | IWarehouseVoidInvoiceItem>(voidWarehouseInvoiceItem: T): T;
|
|
3
|
-
export declare function getFetchedWarehouseVoidInvoiceItems(voidItems: IWarehouseVoidInvoiceItem[]): IWarehouseVoidInvoiceItem[];
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVoidWarehouseInvoiceItemFromCents = getVoidWarehouseInvoiceItemFromCents;
|
|
4
|
-
exports.getFetchedWarehouseVoidInvoiceItems = getFetchedWarehouseVoidInvoiceItems;
|
|
5
|
-
const common_order_actions_1 = require("../store/common-order-actions");
|
|
6
|
-
const price_conversion_1 = require("./price-conversion");
|
|
7
|
-
function getVoidWarehouseInvoiceItemFromCents(voidWarehouseInvoiceItem) {
|
|
8
|
-
return {
|
|
9
|
-
...voidWarehouseInvoiceItem,
|
|
10
|
-
...(typeof voidWarehouseInvoiceItem.subtotal === 'number'
|
|
11
|
-
? {
|
|
12
|
-
subtotal: (0, price_conversion_1.convertPriceFromCents)(voidWarehouseInvoiceItem.subtotal),
|
|
13
|
-
}
|
|
14
|
-
: {}),
|
|
15
|
-
...(typeof voidWarehouseInvoiceItem.total_adjusted_subtotal === 'number'
|
|
16
|
-
? {
|
|
17
|
-
total_adjusted_subtotal: (0, price_conversion_1.convertPriceFromCents)(voidWarehouseInvoiceItem.total_adjusted_subtotal),
|
|
18
|
-
}
|
|
19
|
-
: {}),
|
|
20
|
-
...(voidWarehouseInvoiceItem.adjustments != null
|
|
21
|
-
? {
|
|
22
|
-
adjustments: voidWarehouseInvoiceItem.adjustments.map((adjustment) => ({
|
|
23
|
-
...adjustment,
|
|
24
|
-
...(typeof adjustment.subtotal === 'number'
|
|
25
|
-
? {
|
|
26
|
-
subtotal: (0, price_conversion_1.convertPriceFromCents)(adjustment.subtotal),
|
|
27
|
-
}
|
|
28
|
-
: {}),
|
|
29
|
-
})),
|
|
30
|
-
}
|
|
31
|
-
: {}),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function getFetchedWarehouseVoidInvoiceItems(voidItems) {
|
|
35
|
-
return voidItems
|
|
36
|
-
.map((voidWarehouseInvoiceItem) => getVoidWarehouseInvoiceItemFromCents(voidWarehouseInvoiceItem))
|
|
37
|
-
.sort(common_order_actions_1.sortByCreatedAt);
|
|
38
|
-
}
|