@managesome/eposmatic-toolkit 0.2.475 → 0.2.477

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.
@@ -21,7 +21,7 @@ export interface IRfqRespondPageResult {
21
21
  message: string;
22
22
  completedAt?: string;
23
23
  }
24
- export declare function getRfqRespondPageResult(code: RFQ_PUBLIC_RESPOND_CODE_ENUM, action: RFQ_PUBLIC_RESPOND_ACTION_ENUM, rfqType: RfqType): IRfqRespondPageResult;
24
+ export declare function getRfqRespondPageResult(response: IPublicRfqRespondResponse, action: RFQ_PUBLIC_RESPOND_ACTION_ENUM, rfqType: RfqType): IRfqRespondPageResult;
25
25
  export interface IPublicRfqRespondRequest {
26
26
  rfq_id: string;
27
27
  vendor_id: string;
@@ -21,44 +21,45 @@ var RFQ_PUBLIC_RESPOND_CODE_ENUM;
21
21
  RFQ_PUBLIC_RESPOND_CODE_ENUM["INVALID_REQUEST"] = "INVALID_REQUEST";
22
22
  })(RFQ_PUBLIC_RESPOND_CODE_ENUM || (exports.RFQ_PUBLIC_RESPOND_CODE_ENUM = RFQ_PUBLIC_RESPOND_CODE_ENUM = {}));
23
23
  exports.ALL_RFQ_PUBLIC_RESPOND_CODES = Object.values(RFQ_PUBLIC_RESPOND_CODE_ENUM);
24
- function getRfqRespondPageResult(code, action, rfqType) {
24
+ function getRfqRespondPageResult(response, action, rfqType) {
25
+ const { code, message: responseMessage } = response;
25
26
  const label = rfqType === 'sale' ? 'Quotation' : 'RFQ';
26
27
  switch (code) {
27
28
  case RFQ_PUBLIC_RESPOND_CODE_ENUM.PROCESSED:
28
29
  return {
29
30
  status: 'PENDING',
30
31
  title: action === RFQ_PUBLIC_RESPOND_ACTION_ENUM.CONFIRM ? `${label} Accepted` : `${label} Declined`,
31
- message: getRfqPublicRespondMessage(code, action),
32
+ message: responseMessage || getRfqPublicRespondMessage(code, action),
32
33
  };
33
34
  case RFQ_PUBLIC_RESPOND_CODE_ENUM.ALREADY_PROCESSED:
34
35
  return {
35
36
  status: 'COMPLETED',
36
37
  title: action === RFQ_PUBLIC_RESPOND_ACTION_ENUM.CONFIRM ? 'Already Accepted' : 'Already Declined',
37
- message: getRfqPublicRespondMessage(code, action),
38
+ message: responseMessage || getRfqPublicRespondMessage(code, action),
38
39
  };
39
40
  case RFQ_PUBLIC_RESPOND_CODE_ENUM.EXPIRED:
40
41
  return {
41
42
  status: 'EXPIRED',
42
43
  title: `${label} Expired`,
43
- message: getRfqPublicRespondMessage(code, action),
44
+ message: responseMessage || getRfqPublicRespondMessage(code, action),
44
45
  };
45
46
  case RFQ_PUBLIC_RESPOND_CODE_ENUM.NOT_FOUND:
46
47
  return {
47
48
  status: 'INVALID',
48
49
  title: `${label} Not Found`,
49
- message: getRfqPublicRespondMessage(code, action),
50
+ message: responseMessage || getRfqPublicRespondMessage(code, action),
50
51
  };
51
52
  case RFQ_PUBLIC_RESPOND_CODE_ENUM.INVALID_TRANSITION:
52
53
  return {
53
54
  status: 'INVALID',
54
55
  title: 'Action Not Allowed',
55
- message: getRfqPublicRespondMessage(code, action),
56
+ message: responseMessage || getRfqPublicRespondMessage(code, action),
56
57
  };
57
58
  default:
58
59
  return {
59
60
  status: 'INVALID',
60
61
  title: 'Unexpected Error',
61
- message: 'An unexpected response was received. Please try again or contact support.',
62
+ message: responseMessage || 'An unexpected response was received. Please try again or contact support.',
62
63
  };
63
64
  }
64
65
  }
@@ -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 });
@@ -8,6 +8,7 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
8
8
  createdAt: NativeDate;
9
9
  updatedAt: NativeDate;
10
10
  } & {
11
+ code: string;
11
12
  _id: import("mongoose").Types.ObjectId;
12
13
  name: string;
13
14
  tenants: string[];
@@ -17,7 +18,6 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
17
18
  brand_id: string;
18
19
  active: boolean;
19
20
  reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
20
- code: string;
21
21
  used_count: number;
22
22
  assigned_count: number;
23
23
  reward_items?: {
@@ -142,6 +142,7 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
142
142
  createdAt: NativeDate;
143
143
  updatedAt: NativeDate;
144
144
  } & {
145
+ code: string;
145
146
  _id: import("mongoose").Types.ObjectId;
146
147
  name: string;
147
148
  tenants: string[];
@@ -151,7 +152,6 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
151
152
  brand_id: string;
152
153
  active: boolean;
153
154
  reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
154
- code: string;
155
155
  used_count: number;
156
156
  assigned_count: number;
157
157
  reward_items?: {
@@ -276,6 +276,7 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
276
276
  createdAt: NativeDate;
277
277
  updatedAt: NativeDate;
278
278
  } & {
279
+ code: string;
279
280
  _id: import("mongoose").Types.ObjectId;
280
281
  name: string;
281
282
  tenants: string[];
@@ -285,7 +286,6 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
285
286
  brand_id: string;
286
287
  active: boolean;
287
288
  reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
288
- code: string;
289
289
  used_count: number;
290
290
  assigned_count: number;
291
291
  reward_items?: {
@@ -8,6 +8,7 @@ export declare const InventorySchema: Schema<any, import("mongoose").Model<any,
8
8
  createdAt: NativeDate;
9
9
  updatedAt: NativeDate;
10
10
  } & {
11
+ code: string;
11
12
  _id: import("mongoose").Types.ObjectId;
12
13
  type: INVENTORY_ITEM_TYPE_ENUM;
13
14
  name: string;
@@ -16,7 +17,6 @@ export declare const InventorySchema: Schema<any, import("mongoose").Model<any,
16
17
  updatedAt: NativeDate;
17
18
  image_url: string;
18
19
  active: boolean;
19
- code: string;
20
20
  unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
21
21
  threshold_quantity: number;
22
22
  quantity_left: number;
@@ -37,6 +37,7 @@ export declare const InventorySchema: Schema<any, import("mongoose").Model<any,
37
37
  createdAt: NativeDate;
38
38
  updatedAt: NativeDate;
39
39
  } & {
40
+ code: string;
40
41
  _id: import("mongoose").Types.ObjectId;
41
42
  type: INVENTORY_ITEM_TYPE_ENUM;
42
43
  name: string;
@@ -45,7 +46,6 @@ export declare const InventorySchema: Schema<any, import("mongoose").Model<any,
45
46
  updatedAt: NativeDate;
46
47
  image_url: string;
47
48
  active: boolean;
48
- code: string;
49
49
  unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
50
50
  threshold_quantity: number;
51
51
  quantity_left: number;
@@ -66,6 +66,7 @@ export declare const InventorySchema: Schema<any, import("mongoose").Model<any,
66
66
  createdAt: NativeDate;
67
67
  updatedAt: NativeDate;
68
68
  } & {
69
+ code: string;
69
70
  _id: import("mongoose").Types.ObjectId;
70
71
  type: INVENTORY_ITEM_TYPE_ENUM;
71
72
  name: string;
@@ -74,7 +75,6 @@ export declare const InventorySchema: Schema<any, import("mongoose").Model<any,
74
75
  updatedAt: NativeDate;
75
76
  image_url: string;
76
77
  active: boolean;
77
- code: string;
78
78
  unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
79
79
  threshold_quantity: number;
80
80
  quantity_left: number;
@@ -7,6 +7,7 @@ export declare const MarketingFingerprintSchema: Schema<any, import("mongoose").
7
7
  createdAt: NativeDate;
8
8
  updatedAt: NativeDate;
9
9
  } & {
10
+ message: string;
10
11
  _id: import("mongoose").Types.ObjectId;
11
12
  type: import("../../constants").MARKETING_TYPE_ENUM;
12
13
  tenant_id: string;
@@ -15,7 +16,6 @@ export declare const MarketingFingerprintSchema: Schema<any, import("mongoose").
15
16
  createdAt: NativeDate;
16
17
  updatedAt: NativeDate;
17
18
  description: string;
18
- message: string;
19
19
  customer_phone: string;
20
20
  intent: string;
21
21
  cost: number;
@@ -24,6 +24,7 @@ export declare const MarketingFingerprintSchema: Schema<any, import("mongoose").
24
24
  createdAt: NativeDate;
25
25
  updatedAt: NativeDate;
26
26
  } & {
27
+ message: string;
27
28
  _id: import("mongoose").Types.ObjectId;
28
29
  type: import("../../constants").MARKETING_TYPE_ENUM;
29
30
  tenant_id: string;
@@ -32,7 +33,6 @@ export declare const MarketingFingerprintSchema: Schema<any, import("mongoose").
32
33
  createdAt: NativeDate;
33
34
  updatedAt: NativeDate;
34
35
  description: string;
35
- message: string;
36
36
  customer_phone: string;
37
37
  intent: string;
38
38
  cost: number;
@@ -41,6 +41,7 @@ export declare const MarketingFingerprintSchema: Schema<any, import("mongoose").
41
41
  createdAt: NativeDate;
42
42
  updatedAt: NativeDate;
43
43
  } & {
44
+ message: string;
44
45
  _id: import("mongoose").Types.ObjectId;
45
46
  type: import("../../constants").MARKETING_TYPE_ENUM;
46
47
  tenant_id: string;
@@ -49,7 +50,6 @@ export declare const MarketingFingerprintSchema: Schema<any, import("mongoose").
49
50
  createdAt: NativeDate;
50
51
  updatedAt: NativeDate;
51
52
  description: string;
52
- message: string;
53
53
  customer_phone: string;
54
54
  intent: string;
55
55
  cost: number;
@@ -7,6 +7,7 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
7
7
  createdAt: NativeDate;
8
8
  updatedAt: NativeDate;
9
9
  } & {
10
+ code: string;
10
11
  _id: import("mongoose").Types.ObjectId;
11
12
  name: string;
12
13
  tenants: string[];
@@ -15,7 +16,6 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
15
16
  description: string;
16
17
  brand_id: string;
17
18
  active: boolean;
18
- code: string;
19
19
  is_public: boolean;
20
20
  used_count: number;
21
21
  assigned_count: number;
@@ -30,6 +30,7 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
30
30
  createdAt: NativeDate;
31
31
  updatedAt: NativeDate;
32
32
  } & {
33
+ code: string;
33
34
  _id: import("mongoose").Types.ObjectId;
34
35
  name: string;
35
36
  tenants: string[];
@@ -38,7 +39,6 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
38
39
  description: string;
39
40
  brand_id: string;
40
41
  active: boolean;
41
- code: string;
42
42
  is_public: boolean;
43
43
  used_count: number;
44
44
  assigned_count: number;
@@ -53,6 +53,7 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
53
53
  createdAt: NativeDate;
54
54
  updatedAt: NativeDate;
55
55
  } & {
56
+ code: string;
56
57
  _id: import("mongoose").Types.ObjectId;
57
58
  name: string;
58
59
  tenants: string[];
@@ -61,7 +62,6 @@ export declare const VouchersSchema: Schema<any, import("mongoose").Model<any, a
61
62
  description: string;
62
63
  brand_id: string;
63
64
  active: boolean;
64
- code: string;
65
65
  is_public: boolean;
66
66
  used_count: number;
67
67
  assigned_count: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.475",
3
+ "version": "0.2.477",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",