@managesome/eposmatic-toolkit 0.2.476 → 0.2.478

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.
@@ -215,6 +215,8 @@ export declare enum WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM {
215
215
  CANCELLED = "CANCELLED",
216
216
  VENDOR_ACCEPTED = "VENDOR_ACCEPTED",
217
217
  VENDOR_REJECTED = "VENDOR_REJECTED",
218
+ CLIENT_ACCEPTED = "CLIENT_ACCEPTED",
219
+ CLIENT_REJECTED = "CLIENT_REJECTED",
218
220
  ITEM_ADDED = "ITEM_ADDED",
219
221
  ITEM_UPDATED = "ITEM_UPDATED",
220
222
  ITEM_REMOVED = "ITEM_REMOVED",
@@ -265,6 +265,8 @@ var WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
265
265
  WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["CANCELLED"] = "CANCELLED";
266
266
  WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["VENDOR_ACCEPTED"] = "VENDOR_ACCEPTED";
267
267
  WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["VENDOR_REJECTED"] = "VENDOR_REJECTED";
268
+ WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["CLIENT_ACCEPTED"] = "CLIENT_ACCEPTED";
269
+ WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["CLIENT_REJECTED"] = "CLIENT_REJECTED";
268
270
  WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["ITEM_ADDED"] = "ITEM_ADDED";
269
271
  WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["ITEM_UPDATED"] = "ITEM_UPDATED";
270
272
  WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM["ITEM_REMOVED"] = "ITEM_REMOVED";
@@ -0,0 +1,13 @@
1
+ import { ITenantPurchaseOrderStatus, TENANT_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
2
+ import { ITenantPurchaseOrder } from '../../schemas';
3
+ export declare function getTenantPurchaseOrdersFetchedData(data: ITenantPurchaseOrder[]): ITenantPurchaseOrder[];
4
+ export declare function getTenantPurchaseOrdersPostedData(data: ITenantPurchaseOrder[], order: ITenantPurchaseOrder): ITenantPurchaseOrder[];
5
+ export declare function getTenantPurchaseOrdersUpdatedData(data: ITenantPurchaseOrder[], order: Partial<ITenantPurchaseOrder>): ITenantPurchaseOrder[];
6
+ export declare function getTenantPurchaseOrdersDeletedData(data: ITenantPurchaseOrder[], orderId: string): ITenantPurchaseOrder[];
7
+ interface ITenantGetPurchaseOrderStatusInfoReturn {
8
+ currentOrderStatus: ITenantPurchaseOrderStatus | null;
9
+ nextOrderStatus: ITenantPurchaseOrderStatus | null;
10
+ orderProgress: number;
11
+ }
12
+ export declare function getTenantPurchaseOrderStatusInfo(currentStatus: TENANT_PURCHASE_ORDER_STATUS_ENUM): ITenantGetPurchaseOrderStatusInfoReturn;
13
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTenantPurchaseOrdersFetchedData = getTenantPurchaseOrdersFetchedData;
4
+ exports.getTenantPurchaseOrdersPostedData = getTenantPurchaseOrdersPostedData;
5
+ exports.getTenantPurchaseOrdersUpdatedData = getTenantPurchaseOrdersUpdatedData;
6
+ exports.getTenantPurchaseOrdersDeletedData = getTenantPurchaseOrdersDeletedData;
7
+ exports.getTenantPurchaseOrderStatusInfo = getTenantPurchaseOrderStatusInfo;
8
+ const constants_1 = require("../../constants");
9
+ const common_order_actions_1 = require("./common-order-actions");
10
+ const common_tenant_purchase_order_actions_1 = require("./common-tenant-purchase-order-actions");
11
+ function getTenantPurchaseOrdersFetchedData(data) {
12
+ return data.map((order) => (0, common_tenant_purchase_order_actions_1.getTenantPurchaseOrderWithPrice)(order, false)).sort(common_order_actions_1.sortByCreatedAt);
13
+ }
14
+ function getTenantPurchaseOrdersPostedData(data, order) {
15
+ const newOrders = data.filter((item) => item._id !== order._id).concat((0, common_tenant_purchase_order_actions_1.getTenantPurchaseOrderWithPrice)(order));
16
+ return newOrders.sort(common_order_actions_1.sortByCreatedAt);
17
+ }
18
+ function getTenantPurchaseOrdersUpdatedData(data, order) {
19
+ const updatedOrder = (0, common_tenant_purchase_order_actions_1.getTenantPurchaseOrderWithPrice)(order);
20
+ return data.map((item) => (item._id === updatedOrder._id ? { ...item, ...updatedOrder } : item));
21
+ }
22
+ function getTenantPurchaseOrdersDeletedData(data, orderId) {
23
+ return data.filter((item) => item._id !== orderId);
24
+ }
25
+ function getTenantPurchaseOrderStatusInfo(currentStatus) {
26
+ const info = {
27
+ orderProgress: 0,
28
+ nextOrderStatus: null,
29
+ currentOrderStatus: null,
30
+ };
31
+ let currentStatusIndex;
32
+ for (let i = 0; i < constants_1.DEFAULT_TENANT_PURCHASE_ORDER_STATUS.length; i++) {
33
+ const obj = constants_1.DEFAULT_TENANT_PURCHASE_ORDER_STATUS[i];
34
+ if (obj.status === currentStatus) {
35
+ info.currentOrderStatus = obj;
36
+ currentStatusIndex = i;
37
+ if (info.currentOrderStatus.status !== constants_1.TENANT_PURCHASE_ORDER_STATUS_ENUM.CANCELLED) {
38
+ const total = constants_1.DEFAULT_TENANT_PURCHASE_ORDER_STATUS.length - 2;
39
+ info.orderProgress = Math.round((obj.priority / total) * 100);
40
+ }
41
+ break;
42
+ }
43
+ }
44
+ if (currentStatusIndex == null)
45
+ return info;
46
+ const nextObj = constants_1.DEFAULT_TENANT_PURCHASE_ORDER_STATUS[currentStatusIndex + 1];
47
+ if (!nextObj || nextObj.status === constants_1.TENANT_PURCHASE_ORDER_STATUS_ENUM.CANCELLED) {
48
+ return info;
49
+ }
50
+ info.nextOrderStatus = nextObj;
51
+ return info;
52
+ }
@@ -6,3 +6,26 @@ export declare function getTenantPurchaseOrderCategoriesWithPrice(categories: IT
6
6
  export declare function getTenantPurchaseOrderWithPrice<T extends Partial<ITenantPurchaseOrder> | ITenantPurchaseOrder | ITenantPurchaseOrderIteration>(order: T, writeable?: boolean): T;
7
7
  export declare function syncTenantPurchaseOrderData(order: ITenantPurchaseOrder): ITenantPurchaseOrder;
8
8
  export declare function skipItemMetadataFromTenantPurchaseOrderCategories(categories: ITenantPurchaseOrder['categories'], previousCategories?: ITenantPurchaseOrder['categories']): ITenantPurchaseOrder['categories'];
9
+ export declare function getTenantPurchaseOrderWithAllFields<T extends ITenantPurchaseOrder | Partial<ITenantPurchaseOrder>>(order: T, skipItemMetadata?: boolean): T;
10
+ import { SORT_TYPE_ENUM } from '../../constants';
11
+ import { ITenantGeneralPurchaseOrderItem, ITenantPurchaseOrderCartItemsObj } from '../types/tenant-purchase-order-cart-actions';
12
+ interface IGetTenantPurchaseOrderCartItemsObjPayload {
13
+ currentIterationCategories: ITenantPurchaseOrderCategory[] | undefined;
14
+ previousIterationCategories: ITenantPurchaseOrderCategory[] | undefined;
15
+ mappedItems: Record<string, ITenantGeneralPurchaseOrderItem>;
16
+ shouldSortItemsViaId?: boolean;
17
+ isAnEdit?: boolean;
18
+ sortType?: SORT_TYPE_ENUM;
19
+ }
20
+ export declare function getTenantPurchaseOrderCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId, isAnEdit, sortType, }: IGetTenantPurchaseOrderCartItemsObjPayload): ITenantPurchaseOrderCartItemsObj;
21
+ interface IGetVoidItemsWithReasonTenantPurchaseOrder {
22
+ currentCategories: ITenantPurchaseOrderCategory[];
23
+ iterationsFromFrontend: ITenantPurchaseOrderIteration[] | undefined;
24
+ previousCategories: ITenantPurchaseOrderCategory[];
25
+ }
26
+ export declare function getVoidItemsWithReasonTenantPurchaseOrder({ currentCategories, iterationsFromFrontend, previousCategories, }: IGetVoidItemsWithReasonTenantPurchaseOrder): {
27
+ newIterationCategories: ITenantPurchaseOrderCategory[];
28
+ voidOrderItems: ITenantPurchaseOrderItem[];
29
+ hasNewItems: boolean;
30
+ };
31
+ export {};
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getTenantPurchaseOrderIterationsWithPrice = getTenantPurchaseOrderIterationsWithPrice;
4
7
  exports.getTenantPurchaseOrderPaymentsWithPrice = getTenantPurchaseOrderPaymentsWithPrice;
@@ -7,6 +10,9 @@ exports.getTenantPurchaseOrderCategoriesWithPrice = getTenantPurchaseOrderCatego
7
10
  exports.getTenantPurchaseOrderWithPrice = getTenantPurchaseOrderWithPrice;
8
11
  exports.syncTenantPurchaseOrderData = syncTenantPurchaseOrderData;
9
12
  exports.skipItemMetadataFromTenantPurchaseOrderCategories = skipItemMetadataFromTenantPurchaseOrderCategories;
13
+ exports.getTenantPurchaseOrderWithAllFields = getTenantPurchaseOrderWithAllFields;
14
+ exports.getTenantPurchaseOrderCartItemsObj = getTenantPurchaseOrderCartItemsObj;
15
+ exports.getVoidItemsWithReasonTenantPurchaseOrder = getVoidItemsWithReasonTenantPurchaseOrder;
10
16
  const utils_1 = require("../utils");
11
17
  const common_order_actions_1 = require("./common-order-actions");
12
18
  const tenant_purchase_orders_cart_actions_1 = require("./tenant-purchase-orders-cart-actions");
@@ -105,3 +111,345 @@ function skipItemMetadataFromTenantPurchaseOrderCategories(categories, previousC
105
111
  };
106
112
  });
107
113
  }
114
+ function getCommonOptionalBoolFieldsTenantPurchaseOrder(order, partial) {
115
+ const defaultValue = partial ? undefined : false;
116
+ return {
117
+ is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
118
+ is_reopened: order['is_reopened'] || defaultValue,
119
+ };
120
+ }
121
+ function getCommonOptionalNumFieldsTenantPurchaseOrder(order, partial) {
122
+ const defaultValue = partial ? undefined : 0;
123
+ return {
124
+ gst: order['gst'] || defaultValue,
125
+ gst_amount: order['gst_amount'] || defaultValue,
126
+ };
127
+ }
128
+ function getTenantPurchaseOrderWithAllFields(order, skipItemMetadata) {
129
+ return {
130
+ ...order,
131
+ ...getCommonOptionalBoolFieldsTenantPurchaseOrder(order, false),
132
+ ...getCommonOptionalNumFieldsTenantPurchaseOrder(order, false),
133
+ ...(skipItemMetadata && order.categories != null
134
+ ? {
135
+ categories: skipItemMetadataFromTenantPurchaseOrderCategories(order.categories, order.categories),
136
+ }
137
+ : {}),
138
+ delete_reason: order['delete_reason'] ?? null,
139
+ cancel_reason: order['cancel_reason'] ?? null,
140
+ };
141
+ }
142
+ // ══════════════════════════════════════════════════════════════════════
143
+ // Cart Items Obj (moved from admin-panel utils)
144
+ // ══════════════════════════════════════════════════════════════════════
145
+ const bson_objectid_1 = __importDefault(require("bson-objectid"));
146
+ const lodash_1 = require("lodash");
147
+ const constants_1 = require("../../constants");
148
+ const tenant_purchase_orders_cart_actions_2 = require("./tenant-purchase-orders-cart-actions");
149
+ function getTenantPurchaseOrderCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId = true, isAnEdit, sortType, }) {
150
+ const newMappedItems = { ...mappedItems };
151
+ if (Object.keys(newMappedItems).length === 0) {
152
+ previousIterationCategories?.forEach((category) => {
153
+ category.items.forEach((item) => {
154
+ if (newMappedItems[item.item_id] == null) {
155
+ newMappedItems[item.item_id] = {
156
+ _id: item.item_id,
157
+ name: item.name,
158
+ category_id: category.category_id,
159
+ category_name: category.name,
160
+ category_image_url: '',
161
+ image_url: '',
162
+ description: '',
163
+ };
164
+ }
165
+ });
166
+ });
167
+ currentIterationCategories?.forEach((category) => {
168
+ category.items.forEach((item) => {
169
+ if (newMappedItems[item.item_id] == null) {
170
+ newMappedItems[item.item_id] = {
171
+ _id: item.item_id,
172
+ name: item.name,
173
+ category_id: category.category_id,
174
+ category_name: category.name,
175
+ category_image_url: '',
176
+ image_url: '',
177
+ description: '',
178
+ };
179
+ }
180
+ });
181
+ });
182
+ }
183
+ const getCartItems = (items) => {
184
+ const orderItems = items.map((item) => {
185
+ const selectedItem = newMappedItems[item.item_id] ?? {};
186
+ return {
187
+ orderItem: item,
188
+ image_url: selectedItem.image_url ?? '',
189
+ description: selectedItem.description ?? '',
190
+ category_name: selectedItem.category_name ?? '',
191
+ category_id: selectedItem.category_id ?? '',
192
+ };
193
+ });
194
+ if (shouldSortItemsViaId) {
195
+ if (sortType === constants_1.SORT_TYPE_ENUM.DESC) {
196
+ orderItems.sort((a, b) => (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime());
197
+ }
198
+ else {
199
+ orderItems.sort((a, b) => (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime());
200
+ }
201
+ }
202
+ return orderItems;
203
+ };
204
+ let totalItemsInCart = 0;
205
+ const currentItems = [];
206
+ if (currentIterationCategories != null) {
207
+ for (const category of currentIterationCategories) {
208
+ for (const item of category.items) {
209
+ currentItems.push({ ...item });
210
+ totalItemsInCart += item.quantity;
211
+ }
212
+ }
213
+ }
214
+ let unChangedItems = currentItems;
215
+ const editedItems = [];
216
+ let removedItems = [];
217
+ let newItems = [];
218
+ let disabledReason = '';
219
+ const isAnUpdate = isAnEdit ?? (previousIterationCategories != null && previousIterationCategories.length > 0);
220
+ if (isAnUpdate) {
221
+ const currentItemsMap = currentItems.reduce((acc, currentItem) => {
222
+ acc[currentItem._id] = currentItem;
223
+ return acc;
224
+ }, {});
225
+ const prevItems = [];
226
+ const prevItemsMap = {};
227
+ for (const category of previousIterationCategories ?? []) {
228
+ for (const prevItem of category.items) {
229
+ let item = prevItem;
230
+ const currentItem = currentItemsMap[prevItem._id];
231
+ if (currentItem != null && currentItem.is_ready != null) {
232
+ item = { ...item, is_ready: currentItem.is_ready };
233
+ }
234
+ prevItems.push(item);
235
+ prevItemsMap[item._id] = item;
236
+ }
237
+ }
238
+ unChangedItems = [];
239
+ let totalTempRemovedItems = 0;
240
+ for (const prevItem of prevItems) {
241
+ const currentItem = { ...currentItemsMap[prevItem._id] };
242
+ if (currentItemsMap[prevItem._id] == null) {
243
+ removedItems.push(prevItem);
244
+ }
245
+ else if ((0, lodash_1.isEqual)((0, tenant_purchase_orders_cart_actions_2.getTenantPurchaseOrderItemComparableData)(currentItem), (0, tenant_purchase_orders_cart_actions_2.getTenantPurchaseOrderItemComparableData)(prevItem))) {
246
+ unChangedItems.push(prevItem);
247
+ }
248
+ else {
249
+ const currQty = currentItem.quantity;
250
+ const prevQty = prevItem.quantity;
251
+ if (currQty !== prevQty) {
252
+ const subtotalForOne = currentItem.subtotal / currentItem.quantity;
253
+ const diff = currQty - prevQty;
254
+ const changeQty = Math.abs(diff);
255
+ const itm = {
256
+ ...currentItem,
257
+ quantity: changeQty,
258
+ subtotal: (0, utils_1.parseNum)(changeQty * subtotalForOne),
259
+ };
260
+ if (diff > 0) {
261
+ newItems.push(itm);
262
+ const unchangedQty = currQty - changeQty;
263
+ unChangedItems.push({
264
+ ...currentItem,
265
+ quantity: unchangedQty,
266
+ subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
267
+ });
268
+ }
269
+ else {
270
+ itm.void_reason = prevItem.void_reason ?? currentItem.void_reason;
271
+ removedItems.push(itm);
272
+ const unchangedQty = prevQty - changeQty;
273
+ unChangedItems.push({
274
+ ...currentItem,
275
+ quantity: unchangedQty,
276
+ subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
277
+ });
278
+ totalTempRemovedItems++;
279
+ }
280
+ }
281
+ else {
282
+ const curr = {
283
+ _id: currentItem._id,
284
+ item_id: currentItem.item_id,
285
+ name: currentItem.name,
286
+ special_instructions: currentItem.special_instructions,
287
+ };
288
+ const prev = {
289
+ _id: prevItem._id,
290
+ item_id: prevItem.item_id,
291
+ name: prevItem.name,
292
+ special_instructions: prevItem.special_instructions,
293
+ };
294
+ if ((0, lodash_1.isEqual)(curr, prev)) {
295
+ unChangedItems.push(currentItem);
296
+ }
297
+ else {
298
+ editedItems.push(currentItem);
299
+ }
300
+ }
301
+ }
302
+ }
303
+ for (const item of currentItems) {
304
+ if (prevItemsMap[item._id] == null) {
305
+ newItems.push(item);
306
+ }
307
+ }
308
+ if (removedItems.length > 0 && newItems.length > 0) {
309
+ const newItemsMap = newItems.reduce((acc, item) => {
310
+ acc[item.item_id] = [...(acc[item.item_id] ?? []), item];
311
+ return acc;
312
+ }, {});
313
+ const revertedRemovedItems = [];
314
+ const revertedNewItems = [];
315
+ const additionalNewItems = [];
316
+ for (const removedItem of removedItems) {
317
+ const newItemsForItem = newItemsMap[removedItem.item_id];
318
+ if (newItemsForItem == null)
319
+ continue;
320
+ for (const newItem of newItemsForItem) {
321
+ const newI = {
322
+ item_id: newItem.item_id,
323
+ name: newItem.name,
324
+ price: newItem.price,
325
+ special_instructions: newItem.special_instructions,
326
+ };
327
+ const removedI = {
328
+ item_id: removedItem.item_id,
329
+ name: removedItem.name,
330
+ price: removedItem.price,
331
+ special_instructions: removedItem.special_instructions,
332
+ };
333
+ if ((0, lodash_1.isEqual)(newI, removedI)) {
334
+ if (newItem.quantity === removedItem.quantity) {
335
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
336
+ if (newItemsMap[removedItem.item_id].length === 0) {
337
+ delete newItemsMap[removedItem.item_id];
338
+ }
339
+ revertedNewItems.push(newItem);
340
+ revertedRemovedItems.push(removedItem);
341
+ break;
342
+ }
343
+ else if (removedItem.quantity > newItem.quantity) {
344
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
345
+ if (newItemsMap[removedItem.item_id].length === 0) {
346
+ delete newItemsMap[removedItem.item_id];
347
+ }
348
+ revertedNewItems.push(newItem);
349
+ const subtotalForSingle = removedItem.subtotal / removedItem.quantity;
350
+ const newQuantity = removedItem.quantity - newItem.quantity;
351
+ removedItem.quantity = newQuantity;
352
+ removedItem.subtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
353
+ }
354
+ else {
355
+ revertedRemovedItems.push(removedItem);
356
+ const nQuantity = newItem.quantity;
357
+ const subtotalForSingle = newItem.subtotal / nQuantity;
358
+ const newQuantity = nQuantity - removedItem.quantity;
359
+ newItem.quantity = newQuantity;
360
+ newItem.subtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
361
+ const remainingQuantity = nQuantity - newQuantity;
362
+ additionalNewItems.push({
363
+ ...newItem,
364
+ quantity: remainingQuantity,
365
+ subtotal: (0, utils_1.parseNum)(remainingQuantity * subtotalForSingle),
366
+ });
367
+ break;
368
+ }
369
+ }
370
+ }
371
+ }
372
+ removedItems = removedItems.filter((item) => !revertedRemovedItems.some((r) => r._id === item._id));
373
+ for (const nItem of revertedNewItems) {
374
+ newItems = newItems.filter((item) => item._id !== nItem._id);
375
+ unChangedItems.push(nItem);
376
+ }
377
+ for (const aItem of additionalNewItems) {
378
+ unChangedItems.push(aItem);
379
+ }
380
+ }
381
+ disabledReason =
382
+ unChangedItems.length === prevItems.length &&
383
+ newItems.length === 0 &&
384
+ removedItems.length === 0 &&
385
+ editedItems.length === 0
386
+ ? 'No changes in the order'
387
+ : prevItems.length === removedItems.length - totalTempRemovedItems &&
388
+ editedItems.length === 0 &&
389
+ newItems.length === 0
390
+ ? 'At least one item is required'
391
+ : '';
392
+ }
393
+ return {
394
+ unChangedItems: getCartItems(unChangedItems),
395
+ editedItems: getCartItems(editedItems),
396
+ removedItems: getCartItems(removedItems),
397
+ newItems: getCartItems(newItems),
398
+ totalSelectedItems: (0, utils_1.parseNum)(totalItemsInCart, true),
399
+ disabledReason,
400
+ isAnUpdate,
401
+ };
402
+ }
403
+ function getVoidItemsWithReasonTenantPurchaseOrder({ currentCategories, iterationsFromFrontend, previousCategories, }) {
404
+ const voidOrderItemReasonsMap = {};
405
+ const latestIterationCategories = iterationsFromFrontend?.[0]?.categories;
406
+ if (latestIterationCategories != null && latestIterationCategories.length > 0) {
407
+ for (const category of latestIterationCategories) {
408
+ for (const item of category.items) {
409
+ if (item.void_reason != null && item.void_reason.length > 0) {
410
+ voidOrderItemReasonsMap[item._id] = item.void_reason;
411
+ }
412
+ }
413
+ }
414
+ }
415
+ const { newItems, removedItems } = getTenantPurchaseOrderCartItemsObj({
416
+ currentIterationCategories: currentCategories,
417
+ previousIterationCategories: previousCategories,
418
+ mappedItems: {},
419
+ shouldSortItemsViaId: false,
420
+ isAnEdit: true,
421
+ });
422
+ const hasNewItems = newItems.length > 0;
423
+ const voidOrderItems = [];
424
+ const newVoidOrderItemReasonsMap = {};
425
+ for (const { orderItem } of removedItems) {
426
+ const voidReason = voidOrderItemReasonsMap[orderItem._id];
427
+ voidOrderItems.push({
428
+ ...orderItem,
429
+ subtotal: Math.round(orderItem.subtotal),
430
+ void_reason: voidReason ?? '-',
431
+ });
432
+ if (voidReason != null) {
433
+ newVoidOrderItemReasonsMap[orderItem._id] = voidReason;
434
+ }
435
+ }
436
+ const newIterationCategories = [];
437
+ for (const category of previousCategories) {
438
+ const newCategoryItems = [];
439
+ for (const prevItem of category.items) {
440
+ const voidReason = newVoidOrderItemReasonsMap[prevItem._id];
441
+ const orderItem = {
442
+ ...prevItem,
443
+ subtotal: Math.round(prevItem.subtotal),
444
+ };
445
+ if (voidReason != null) {
446
+ orderItem.void_reason = voidReason;
447
+ }
448
+ newCategoryItems.push(orderItem);
449
+ }
450
+ if (newCategoryItems.length === 0)
451
+ continue;
452
+ newIterationCategories.push({ ...category, items: newCategoryItems });
453
+ }
454
+ return { newIterationCategories, voidOrderItems, hasNewItems };
455
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './all-orders-actions';
2
+ export * from './all-tenant-purchase-orders-actions';
2
3
  export * from './all-warehouse-purchase-order-rfqs-actions';
3
4
  export * from './all-warehouse-purchase-order-vendor-return-actions';
4
5
  export * from './all-warehouse-purchase-orders-actions';
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./all-orders-actions"), exports);
18
+ __exportStar(require("./all-tenant-purchase-orders-actions"), exports);
18
19
  __exportStar(require("./all-warehouse-purchase-order-rfqs-actions"), exports);
19
20
  __exportStar(require("./all-warehouse-purchase-order-vendor-return-actions"), exports);
20
21
  __exportStar(require("./all-warehouse-purchase-orders-actions"), exports);
@@ -22,6 +22,7 @@ export * from './smartpay-apis';
22
22
  export * from './split_bill';
23
23
  export * from './srb-generate-invoice';
24
24
  export * from './switchpay';
25
+ export * from './tenant-purchase-order-cart-actions';
25
26
  export * from './warehouse-catalog';
26
27
  export * from './warehouse-purchase-order-cart-actions';
27
28
  export * from './warehouse-purchase-order-rfq-cart-actions';
@@ -38,6 +38,7 @@ __exportStar(require("./smartpay-apis"), exports);
38
38
  __exportStar(require("./split_bill"), exports);
39
39
  __exportStar(require("./srb-generate-invoice"), exports);
40
40
  __exportStar(require("./switchpay"), exports);
41
+ __exportStar(require("./tenant-purchase-order-cart-actions"), exports);
41
42
  __exportStar(require("./warehouse-catalog"), exports);
42
43
  __exportStar(require("./warehouse-purchase-order-cart-actions"), exports);
43
44
  __exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
@@ -0,0 +1,26 @@
1
+ import { ITenantPurchaseOrderItem } from '../../schemas';
2
+ export interface ITenantGeneralPurchaseOrderItem {
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 ITenantPurchaseOrderCartItem {
12
+ orderItem: ITenantPurchaseOrderItem;
13
+ image_url: string | null;
14
+ description: string;
15
+ category_name: string;
16
+ category_id: string;
17
+ }
18
+ export interface ITenantPurchaseOrderCartItemsObj {
19
+ unChangedItems: ITenantPurchaseOrderCartItem[];
20
+ editedItems: ITenantPurchaseOrderCartItem[];
21
+ removedItems: ITenantPurchaseOrderCartItem[];
22
+ newItems: ITenantPurchaseOrderCartItem[];
23
+ totalSelectedItems: number;
24
+ disabledReason: string;
25
+ isAnUpdate: boolean;
26
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
1
  import { Schema } from 'mongoose';
2
- import { WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
2
+ import { WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM, WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
3
3
  export declare const SaleOrderRFQSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
4
4
  timestamps: true;
5
5
  versionKey: false;
@@ -646,6 +646,13 @@ export declare const SaleOrderRFQSchema: Schema<any, import("mongoose").Model<an
646
646
  is_gst_inclusive?: boolean | null | undefined;
647
647
  gst?: number | null | undefined;
648
648
  gst_amount?: number | null | undefined;
649
+ requested_clients?: Map<string, {
650
+ status: WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM;
651
+ client_id: import("mongoose").Types.ObjectId;
652
+ client_name?: string | null | undefined;
653
+ client_email?: string | null | undefined;
654
+ client_price?: number | null | undefined;
655
+ }> | null | undefined;
649
656
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
650
657
  createdAt: NativeDate;
651
658
  updatedAt: NativeDate;
@@ -1288,6 +1295,13 @@ export declare const SaleOrderRFQSchema: Schema<any, import("mongoose").Model<an
1288
1295
  is_gst_inclusive?: boolean | null | undefined;
1289
1296
  gst?: number | null | undefined;
1290
1297
  gst_amount?: number | null | undefined;
1298
+ requested_clients?: Map<string, {
1299
+ status: WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM;
1300
+ client_id: import("mongoose").Types.ObjectId;
1301
+ client_name?: string | null | undefined;
1302
+ client_email?: string | null | undefined;
1303
+ client_price?: number | null | undefined;
1304
+ }> | null | undefined;
1291
1305
  }>> & import("mongoose").FlatRecord<{
1292
1306
  createdAt: NativeDate;
1293
1307
  updatedAt: NativeDate;
@@ -1930,6 +1944,13 @@ export declare const SaleOrderRFQSchema: Schema<any, import("mongoose").Model<an
1930
1944
  is_gst_inclusive?: boolean | null | undefined;
1931
1945
  gst?: number | null | undefined;
1932
1946
  gst_amount?: number | null | undefined;
1947
+ requested_clients?: Map<string, {
1948
+ status: WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM;
1949
+ client_id: import("mongoose").Types.ObjectId;
1950
+ client_name?: string | null | undefined;
1951
+ client_email?: string | null | undefined;
1952
+ client_price?: number | null | undefined;
1953
+ }> | null | undefined;
1933
1954
  }> & Required<{
1934
1955
  _id: import("mongoose").Types.ObjectId;
1935
1956
  }> & {
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WAREHOUSE_SALE_ORDER_RFQ_COLLECTION_NAME = exports.SaleOrderRFQSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const constants_1 = require("../../constants");
6
- const warehouses_1 = require("./warehouses");
7
6
  const warehouse_categories_1 = require("./warehouse_categories");
8
7
  const warehouse_clients_1 = require("./warehouse_clients");
9
8
  const warehouse_items_1 = require("./warehouse_items");
9
+ const warehouses_1 = require("./warehouses");
10
10
  const StaffDetailsSchema = new mongoose_1.Schema({
11
11
  staff_id: {
12
12
  type: String,
@@ -111,6 +111,21 @@ const SaleOrderRFQCategoriesSchema = new mongoose_1.Schema({
111
111
  _id: false,
112
112
  minimize: false,
113
113
  });
114
+ const RequestedClientEntrySchema = new mongoose_1.Schema({
115
+ client_id: {
116
+ type: mongoose_1.Schema.Types.ObjectId,
117
+ required: true,
118
+ ref: warehouse_clients_1.WAREHOUSE_CLIENTS_COLLECTION_NAME,
119
+ },
120
+ client_name: { type: String, required: false },
121
+ client_email: { type: String, required: false },
122
+ client_price: { type: Number, min: 0, required: false },
123
+ status: {
124
+ type: String,
125
+ enum: constants_1.ALL_WAREHOUSE_RFQ_VENDOR_STATUS_NAMES,
126
+ default: constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM.PENDING,
127
+ },
128
+ }, { _id: false, minimize: false });
114
129
  const SaleOrderRFQIterationSchema = new mongoose_1.Schema({
115
130
  categories: {
116
131
  type: [SaleOrderRFQCategoriesSchema],
@@ -191,6 +206,11 @@ exports.SaleOrderRFQSchema = new mongoose_1.Schema({
191
206
  type: String,
192
207
  default: '',
193
208
  },
209
+ requested_clients: {
210
+ type: Map,
211
+ of: RequestedClientEntrySchema,
212
+ required: false,
213
+ },
194
214
  order_number: {
195
215
  type: Number,
196
216
  min: 0,
@@ -1,5 +1,12 @@
1
- import { WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
1
+ import { WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM, WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
2
2
  import { IStaffDetails } from './orders';
3
+ export interface IWarehouseRFQClientEntry {
4
+ client_id: string;
5
+ client_name: string;
6
+ client_email?: string | null;
7
+ client_price?: number | null;
8
+ status: WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM;
9
+ }
3
10
  export type IWarehouseSaleOrderRFQItem = {
4
11
  _id: string;
5
12
  item_id: string;
@@ -39,6 +46,7 @@ export interface IWarehouseSaleOrderRFQ extends IWarehouseSaleOrderRFQIteration
39
46
  warehouse_id: string;
40
47
  client_id: string;
41
48
  client_name: string;
49
+ requested_clients?: Record<string, IWarehouseRFQClientEntry> | null;
42
50
  iterations: IWarehouseSaleOrderRFQIteration[];
43
51
  order_number: number | null;
44
52
  expected_deadline: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.476",
3
+ "version": "0.2.478",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",