@managesome/eposmatic-toolkit 0.2.440 → 0.2.442

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.
@@ -1,37 +0,0 @@
1
- export declare enum RFQ_PUBLIC_RESPOND_ACTION_ENUM {
2
- CONFIRM = "confirm",
3
- CANCEL = "cancel"
4
- }
5
- export declare const ALL_RFQ_PUBLIC_RESPOND_ACTIONS: RFQ_PUBLIC_RESPOND_ACTION_ENUM[];
6
- export declare enum RFQ_PUBLIC_RESPOND_CODE_ENUM {
7
- PROCESSED = "PROCESSED",
8
- ALREADY_PROCESSED = "ALREADY_PROCESSED",
9
- EXPIRED = "EXPIRED",
10
- NOT_FOUND = "NOT_FOUND",
11
- INVALID_TRANSITION = "INVALID_TRANSITION",
12
- /** Used by routes when the request body is missing required fields. */
13
- INVALID_REQUEST = "INVALID_REQUEST"
14
- }
15
- export declare const ALL_RFQ_PUBLIC_RESPOND_CODES: RFQ_PUBLIC_RESPOND_CODE_ENUM[];
16
- export type RfqType = 'purchase' | 'sale';
17
- export type ActionStatus = 'PENDING' | 'COMPLETED' | 'EXPIRED' | 'INVALID';
18
- export interface IRfqRespondPageResult {
19
- status: ActionStatus;
20
- title: string;
21
- message: string;
22
- completedAt?: string;
23
- }
24
- export declare function getRfqRespondPageResult(code: RFQ_PUBLIC_RESPOND_CODE_ENUM, action: RFQ_PUBLIC_RESPOND_ACTION_ENUM, rfqType: RfqType): IRfqRespondPageResult;
25
- export interface IPublicRfqRespondRequest {
26
- rfq_id: string;
27
- vendor_id: string;
28
- action: RFQ_PUBLIC_RESPOND_ACTION_ENUM;
29
- }
30
- export interface IPublicRfqRespondResponse {
31
- success: boolean;
32
- code: RFQ_PUBLIC_RESPOND_CODE_ENUM;
33
- message: string;
34
- order_status?: string;
35
- rfq_id?: string;
36
- }
37
- export declare function getRfqPublicRespondMessage(code: RFQ_PUBLIC_RESPOND_CODE_ENUM, action: RFQ_PUBLIC_RESPOND_ACTION_ENUM): string;
@@ -1,86 +1 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ALL_RFQ_PUBLIC_RESPOND_CODES = exports.RFQ_PUBLIC_RESPOND_CODE_ENUM = exports.ALL_RFQ_PUBLIC_RESPOND_ACTIONS = exports.RFQ_PUBLIC_RESPOND_ACTION_ENUM = void 0;
4
- exports.getRfqRespondPageResult = getRfqRespondPageResult;
5
- exports.getRfqPublicRespondMessage = getRfqPublicRespondMessage;
6
- var RFQ_PUBLIC_RESPOND_ACTION_ENUM;
7
- (function (RFQ_PUBLIC_RESPOND_ACTION_ENUM) {
8
- RFQ_PUBLIC_RESPOND_ACTION_ENUM["CONFIRM"] = "confirm";
9
- RFQ_PUBLIC_RESPOND_ACTION_ENUM["CANCEL"] = "cancel";
10
- })(RFQ_PUBLIC_RESPOND_ACTION_ENUM || (exports.RFQ_PUBLIC_RESPOND_ACTION_ENUM = RFQ_PUBLIC_RESPOND_ACTION_ENUM = {}));
11
- exports.ALL_RFQ_PUBLIC_RESPOND_ACTIONS = Object.values(RFQ_PUBLIC_RESPOND_ACTION_ENUM);
12
- var RFQ_PUBLIC_RESPOND_CODE_ENUM;
13
- (function (RFQ_PUBLIC_RESPOND_CODE_ENUM) {
14
- RFQ_PUBLIC_RESPOND_CODE_ENUM["PROCESSED"] = "PROCESSED";
15
- RFQ_PUBLIC_RESPOND_CODE_ENUM["ALREADY_PROCESSED"] = "ALREADY_PROCESSED";
16
- RFQ_PUBLIC_RESPOND_CODE_ENUM["EXPIRED"] = "EXPIRED";
17
- RFQ_PUBLIC_RESPOND_CODE_ENUM["NOT_FOUND"] = "NOT_FOUND";
18
- RFQ_PUBLIC_RESPOND_CODE_ENUM["INVALID_TRANSITION"] = "INVALID_TRANSITION";
19
- /** Used by routes when the request body is missing required fields. */
20
- RFQ_PUBLIC_RESPOND_CODE_ENUM["INVALID_REQUEST"] = "INVALID_REQUEST";
21
- })(RFQ_PUBLIC_RESPOND_CODE_ENUM || (exports.RFQ_PUBLIC_RESPOND_CODE_ENUM = RFQ_PUBLIC_RESPOND_CODE_ENUM = {}));
22
- exports.ALL_RFQ_PUBLIC_RESPOND_CODES = Object.values(RFQ_PUBLIC_RESPOND_CODE_ENUM);
23
- function getRfqRespondPageResult(code, action, rfqType) {
24
- const label = rfqType === 'sale' ? 'Quotation' : 'RFQ';
25
- switch (code) {
26
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.PROCESSED:
27
- return {
28
- status: 'PENDING',
29
- title: action === RFQ_PUBLIC_RESPOND_ACTION_ENUM.CONFIRM ? `${label} Accepted` : `${label} Declined`,
30
- message: getRfqPublicRespondMessage(code, action),
31
- };
32
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.ALREADY_PROCESSED:
33
- return {
34
- status: 'COMPLETED',
35
- title: action === RFQ_PUBLIC_RESPOND_ACTION_ENUM.CONFIRM ? 'Already Accepted' : 'Already Declined',
36
- message: getRfqPublicRespondMessage(code, action),
37
- };
38
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.EXPIRED:
39
- return {
40
- status: 'EXPIRED',
41
- title: `${label} Expired`,
42
- message: getRfqPublicRespondMessage(code, action),
43
- };
44
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.NOT_FOUND:
45
- return {
46
- status: 'INVALID',
47
- title: `${label} Not Found`,
48
- message: getRfqPublicRespondMessage(code, action),
49
- };
50
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.INVALID_TRANSITION:
51
- return {
52
- status: 'INVALID',
53
- title: 'Action Not Allowed',
54
- message: getRfqPublicRespondMessage(code, action),
55
- };
56
- default:
57
- return {
58
- status: 'INVALID',
59
- title: 'Unexpected Error',
60
- message: 'An unexpected response was received. Please try again or contact support.',
61
- };
62
- }
63
- }
64
- // ─── Message helpers ───────────────────────────────────────────────
65
- function getRfqPublicRespondMessage(code, action) {
66
- switch (code) {
67
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.PROCESSED:
68
- return action === RFQ_PUBLIC_RESPOND_ACTION_ENUM.CONFIRM
69
- ? 'You have accepted this RFQ. The buyer will review your response.'
70
- : 'You have declined this RFQ.';
71
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.ALREADY_PROCESSED:
72
- return action === RFQ_PUBLIC_RESPOND_ACTION_ENUM.CONFIRM
73
- ? 'You have already accepted this RFQ.'
74
- : 'You have already declined this RFQ.';
75
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.EXPIRED:
76
- return 'This RFQ has expired and can no longer be responded to.';
77
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.NOT_FOUND:
78
- return 'This RFQ could not be found. It may have been deleted or the link is invalid.';
79
- case RFQ_PUBLIC_RESPOND_CODE_ENUM.INVALID_TRANSITION:
80
- return action === RFQ_PUBLIC_RESPOND_ACTION_ENUM.CONFIRM
81
- ? 'This RFQ has already been declined and cannot be accepted.'
82
- : 'This RFQ has already been accepted and cannot be declined via this link.';
83
- default:
84
- return 'An unknown error occurred.';
85
- }
86
- }
@@ -286,8 +286,6 @@ export declare enum WAREHOUSE_USER_PERMISSIONS_ENUM {
286
286
  WAREHOUSE_DELETE_CLIENT = "WAREHOUSE_DELETE_CLIENT",
287
287
  WAREHOUSE_DELETE_CATALOG = "WAREHOUSE_DELETE_CATALOG",
288
288
  WAREHOUSE_DELETE_INVENTORY = "WAREHOUSE_DELETE_INVENTORY",
289
- WAREHOUSE_DELETE_PURCHASE_ORDER = "WAREHOUSE_DELETE_PURCHASE_ORDER",
290
- WAREHOUSE_DELETE_INVOICE = "WAREHOUSE_DELETE_INVOICE",
291
289
  WAREHOUSE_DELETE_CANCEL_PURCHASE_ORDER = "WAREHOUSE_DELETE_CANCEL_PURCHASE_ORDER",
292
290
  WAREHOUSE_DELETE_CANCEL_INVOICE = "WAREHOUSE_DELETE_CANCEL_INVOICE",
293
291
  WAREHOUSE_DELETE_EXPENSE = "WAREHOUSE_DELETE_EXPENSE",
@@ -350,8 +350,6 @@ var WAREHOUSE_USER_PERMISSIONS_ENUM;
350
350
  WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_CLIENT"] = "WAREHOUSE_DELETE_CLIENT";
351
351
  WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_CATALOG"] = "WAREHOUSE_DELETE_CATALOG";
352
352
  WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_INVENTORY"] = "WAREHOUSE_DELETE_INVENTORY";
353
- WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_PURCHASE_ORDER"] = "WAREHOUSE_DELETE_PURCHASE_ORDER";
354
- WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_INVOICE"] = "WAREHOUSE_DELETE_INVOICE";
355
353
  WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_CANCEL_PURCHASE_ORDER"] = "WAREHOUSE_DELETE_CANCEL_PURCHASE_ORDER";
356
354
  WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_CANCEL_INVOICE"] = "WAREHOUSE_DELETE_CANCEL_INVOICE";
357
355
  WAREHOUSE_USER_PERMISSIONS_ENUM["WAREHOUSE_DELETE_EXPENSE"] = "WAREHOUSE_DELETE_EXPENSE";
@@ -8,7 +8,6 @@ export * from './NOTIFICATIONS';
8
8
  export * from './ORDER';
9
9
  export * from './PRA_ENUMS';
10
10
  export * from './REPORT_WEBVIEW';
11
- export * from './RFQ';
12
11
  export * from './SMARTPAY_ENUMS';
13
12
  export * from './SOCKET';
14
13
  export * from './SRB_ENUMS';
@@ -24,7 +24,6 @@ __exportStar(require("./NOTIFICATIONS"), exports);
24
24
  __exportStar(require("./ORDER"), exports);
25
25
  __exportStar(require("./PRA_ENUMS"), exports);
26
26
  __exportStar(require("./REPORT_WEBVIEW"), exports);
27
- __exportStar(require("./RFQ"), exports);
28
27
  __exportStar(require("./SMARTPAY_ENUMS"), exports);
29
28
  __exportStar(require("./SOCKET"), exports);
30
29
  __exportStar(require("./SRB_ENUMS"), exports);
@@ -0,0 +1,17 @@
1
+ import { WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
2
+ import { IWarehousePurchaseOrderRFQ } from '../../schemas';
3
+ interface IWarehouseRfqStatusInfo {
4
+ currentStatus: WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM;
5
+ priority: number;
6
+ }
7
+ export declare function getWarehousePurchaseOrderRfqsFetchedData(data: IWarehousePurchaseOrderRFQ[]): IWarehousePurchaseOrderRFQ[];
8
+ export declare function getWarehousePurchaseOrderRfqsPostedData(data: IWarehousePurchaseOrderRFQ[], order: IWarehousePurchaseOrderRFQ): IWarehousePurchaseOrderRFQ[];
9
+ export declare function getWarehousePurchaseOrderRfqsUpdatedData(data: IWarehousePurchaseOrderRFQ[], order: Partial<IWarehousePurchaseOrderRFQ>): IWarehousePurchaseOrderRFQ[];
10
+ export declare function getWarehousePurchaseOrderRfqsDeletedData(data: IWarehousePurchaseOrderRFQ[], orderId: string): IWarehousePurchaseOrderRFQ[];
11
+ interface IWarehouseGetPurchaseOrderRfqStatusInfoReturn {
12
+ currentOrderStatus: IWarehouseRfqStatusInfo | null;
13
+ nextOrderStatus: IWarehouseRfqStatusInfo | null;
14
+ orderProgress: number;
15
+ }
16
+ export declare function getWarehousePurchaseOrderRfqStatusInfo(currentStatus: WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM): IWarehouseGetPurchaseOrderRfqStatusInfoReturn;
17
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWarehousePurchaseOrderRfqsFetchedData = getWarehousePurchaseOrderRfqsFetchedData;
4
+ exports.getWarehousePurchaseOrderRfqsPostedData = getWarehousePurchaseOrderRfqsPostedData;
5
+ exports.getWarehousePurchaseOrderRfqsUpdatedData = getWarehousePurchaseOrderRfqsUpdatedData;
6
+ exports.getWarehousePurchaseOrderRfqsDeletedData = getWarehousePurchaseOrderRfqsDeletedData;
7
+ exports.getWarehousePurchaseOrderRfqStatusInfo = getWarehousePurchaseOrderRfqStatusInfo;
8
+ const constants_1 = require("../../constants");
9
+ const common_order_actions_1 = require("./common-order-actions");
10
+ const common_warehouse_purchase_order_rfq_actions_1 = require("./common-warehouse-purchase-order-rfq-actions");
11
+ const DEFAULT_WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS = [
12
+ {
13
+ currentStatus: constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM.DRAFT,
14
+ priority: 0,
15
+ },
16
+ {
17
+ currentStatus: constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM.SENT,
18
+ priority: 1,
19
+ },
20
+ {
21
+ currentStatus: constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM.CONFIRMED,
22
+ priority: 2,
23
+ },
24
+ {
25
+ currentStatus: constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM.CANCELLED,
26
+ priority: 3,
27
+ },
28
+ ];
29
+ function getWarehousePurchaseOrderRfqsFetchedData(data) {
30
+ return data.map((order) => (0, common_warehouse_purchase_order_rfq_actions_1.getWarehousePurchaseOrderRfqWithPrice)(order, false)).sort(common_order_actions_1.sortByCreatedAt);
31
+ }
32
+ function getWarehousePurchaseOrderRfqsPostedData(data, order) {
33
+ const newOrders = data.filter((item) => item._id !== order._id).concat((0, common_warehouse_purchase_order_rfq_actions_1.getWarehousePurchaseOrderRfqWithPrice)(order));
34
+ return newOrders.sort(common_order_actions_1.sortByCreatedAt);
35
+ }
36
+ function getWarehousePurchaseOrderRfqsUpdatedData(data, order) {
37
+ const updatedOrder = (0, common_warehouse_purchase_order_rfq_actions_1.getWarehousePurchaseOrderRfqWithPrice)(order);
38
+ const newOrders = data.map((item) => item._id === updatedOrder._id ? { ...item, ...updatedOrder } : item);
39
+ return newOrders;
40
+ }
41
+ function getWarehousePurchaseOrderRfqsDeletedData(data, orderId) {
42
+ return data.filter((item) => item._id !== orderId);
43
+ }
44
+ function getWarehousePurchaseOrderRfqStatusInfo(currentStatus) {
45
+ const info = {
46
+ orderProgress: 0,
47
+ nextOrderStatus: null,
48
+ currentOrderStatus: null,
49
+ };
50
+ let currentStatusIndex;
51
+ for (let i = 0; i < DEFAULT_WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS.length; i++) {
52
+ const obj = DEFAULT_WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS[i];
53
+ if (obj.currentStatus === currentStatus) {
54
+ info.currentOrderStatus = obj;
55
+ currentStatusIndex = i;
56
+ if (info.currentOrderStatus.currentStatus !== constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM.CANCELLED) {
57
+ // Total is -2 because we don't want to count unconfirmed and cancelled
58
+ const total = DEFAULT_WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS.length - 2;
59
+ info.orderProgress = Math.round((obj.priority / total) * 100);
60
+ }
61
+ break;
62
+ }
63
+ }
64
+ if (currentStatusIndex == null) {
65
+ return info;
66
+ }
67
+ const nextObj = DEFAULT_WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS[currentStatusIndex + 1];
68
+ if (!nextObj || nextObj.currentStatus === constants_1.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM.CANCELLED) {
69
+ return info;
70
+ }
71
+ info.nextOrderStatus = nextObj;
72
+ return info;
73
+ }
@@ -0,0 +1,17 @@
1
+ import { WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM } from '../../constants';
2
+ import { IWarehouseSaleOrderRFQ } from '../../schemas';
3
+ interface IWarehouseSaleRfqStatusInfo {
4
+ currentStatus: WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM;
5
+ priority: number;
6
+ }
7
+ export declare function getWarehouseSaleOrderRfqsFetchedData(data: IWarehouseSaleOrderRFQ[]): IWarehouseSaleOrderRFQ[];
8
+ export declare function getWarehouseSaleOrderRfqsPostedData(data: IWarehouseSaleOrderRFQ[], order: IWarehouseSaleOrderRFQ): IWarehouseSaleOrderRFQ[];
9
+ export declare function getWarehouseSaleOrderRfqsUpdatedData(data: IWarehouseSaleOrderRFQ[], order: Partial<IWarehouseSaleOrderRFQ>): IWarehouseSaleOrderRFQ[];
10
+ export declare function getWarehouseSaleOrderRfqsDeletedData(data: IWarehouseSaleOrderRFQ[], orderId: string): IWarehouseSaleOrderRFQ[];
11
+ interface IWarehouseGetSaleOrderRfqStatusInfoReturn {
12
+ currentOrderStatus: IWarehouseSaleRfqStatusInfo | null;
13
+ nextOrderStatus: IWarehouseSaleRfqStatusInfo | null;
14
+ orderProgress: number;
15
+ }
16
+ export declare function getWarehouseSaleOrderRfqStatusInfo(currentStatus: WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM): IWarehouseGetSaleOrderRfqStatusInfoReturn;
17
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWarehouseSaleOrderRfqsFetchedData = getWarehouseSaleOrderRfqsFetchedData;
4
+ exports.getWarehouseSaleOrderRfqsPostedData = getWarehouseSaleOrderRfqsPostedData;
5
+ exports.getWarehouseSaleOrderRfqsUpdatedData = getWarehouseSaleOrderRfqsUpdatedData;
6
+ exports.getWarehouseSaleOrderRfqsDeletedData = getWarehouseSaleOrderRfqsDeletedData;
7
+ exports.getWarehouseSaleOrderRfqStatusInfo = getWarehouseSaleOrderRfqStatusInfo;
8
+ const constants_1 = require("../../constants");
9
+ const common_order_actions_1 = require("./common-order-actions");
10
+ const common_warehouse_sale_order_rfq_actions_1 = require("./common-warehouse-sale-order-rfq-actions");
11
+ const DEFAULT_WAREHOUSE_SALE_ORDER_RFQ_STATUS = [
12
+ {
13
+ currentStatus: constants_1.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM.DRAFT,
14
+ priority: 0,
15
+ },
16
+ {
17
+ currentStatus: constants_1.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM.SENT,
18
+ priority: 1,
19
+ },
20
+ {
21
+ currentStatus: constants_1.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM.CONFIRMED,
22
+ priority: 2,
23
+ },
24
+ {
25
+ currentStatus: constants_1.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM.CANCELLED,
26
+ priority: 3,
27
+ },
28
+ ];
29
+ function getWarehouseSaleOrderRfqsFetchedData(data) {
30
+ return data.map((order) => (0, common_warehouse_sale_order_rfq_actions_1.getWarehouseSaleOrderRfqWithPrice)(order, false)).sort(common_order_actions_1.sortByCreatedAt);
31
+ }
32
+ function getWarehouseSaleOrderRfqsPostedData(data, order) {
33
+ const newOrders = data.filter((item) => item._id !== order._id).concat((0, common_warehouse_sale_order_rfq_actions_1.getWarehouseSaleOrderRfqWithPrice)(order));
34
+ return newOrders.sort(common_order_actions_1.sortByCreatedAt);
35
+ }
36
+ function getWarehouseSaleOrderRfqsUpdatedData(data, order) {
37
+ const updatedOrder = (0, common_warehouse_sale_order_rfq_actions_1.getWarehouseSaleOrderRfqWithPrice)(order);
38
+ const newOrders = data.map((item) => item._id === updatedOrder._id ? { ...item, ...updatedOrder } : item);
39
+ return newOrders;
40
+ }
41
+ function getWarehouseSaleOrderRfqsDeletedData(data, orderId) {
42
+ return data.filter((item) => item._id !== orderId);
43
+ }
44
+ function getWarehouseSaleOrderRfqStatusInfo(currentStatus) {
45
+ const info = {
46
+ orderProgress: 0,
47
+ nextOrderStatus: null,
48
+ currentOrderStatus: null,
49
+ };
50
+ let currentStatusIndex;
51
+ for (let i = 0; i < DEFAULT_WAREHOUSE_SALE_ORDER_RFQ_STATUS.length; i++) {
52
+ const obj = DEFAULT_WAREHOUSE_SALE_ORDER_RFQ_STATUS[i];
53
+ if (obj.currentStatus === currentStatus) {
54
+ info.currentOrderStatus = obj;
55
+ currentStatusIndex = i;
56
+ if (info.currentOrderStatus.currentStatus !== constants_1.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM.CANCELLED) {
57
+ // Total is -2 because we don't want to count unconfirmed and cancelled
58
+ const total = DEFAULT_WAREHOUSE_SALE_ORDER_RFQ_STATUS.length - 2;
59
+ info.orderProgress = Math.round((obj.priority / total) * 100);
60
+ }
61
+ break;
62
+ }
63
+ }
64
+ if (currentStatusIndex == null) {
65
+ return info;
66
+ }
67
+ const nextObj = DEFAULT_WAREHOUSE_SALE_ORDER_RFQ_STATUS[currentStatusIndex + 1];
68
+ if (!nextObj || nextObj.currentStatus === constants_1.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM.CANCELLED) {
69
+ return info;
70
+ }
71
+ info.nextOrderStatus = nextObj;
72
+ return info;
73
+ }
@@ -0,0 +1,30 @@
1
+ import { SORT_TYPE_ENUM } from '../../constants';
2
+ import { IWarehousePurchaseOrderRFQ, IWarehousePurchaseOrderRFQCategory, IWarehousePurchaseOrderRFQItem, IWarehousePurchaseOrderRFQIteration } from '../../schemas';
3
+ import { IWarehouseGeneralPurchaseOrderRfqItem, IWarehousePurchaseOrderRfqCartItemsObj } from '../types';
4
+ export declare function getWarehousePurchaseOrderRfqIterationsWithPrice(iterations?: IWarehousePurchaseOrderRFQIteration[] | undefined, writeable?: boolean): IWarehousePurchaseOrderRFQIteration[];
5
+ export declare function getWarehousePurchaseOrderRfqItemsWithPrice(items: IWarehousePurchaseOrderRFQItem[] | undefined, convertToPrice: (price: number) => number): IWarehousePurchaseOrderRFQItem[];
6
+ export declare function getWarehousePurchaseOrderRfqCategoriesWithPrice(categories: IWarehousePurchaseOrderRFQCategory[] | undefined, convertToPrice: (price: number) => number): IWarehousePurchaseOrderRFQCategory[];
7
+ export declare function getWarehousePurchaseOrderRfqWithPrice<T extends Partial<IWarehousePurchaseOrderRFQ> | IWarehousePurchaseOrderRFQ | IWarehousePurchaseOrderRFQIteration>(order: T, writeable?: boolean): T;
8
+ export declare function syncWarehousePurchaseOrderRfqData(order: IWarehousePurchaseOrderRFQ): IWarehousePurchaseOrderRFQ;
9
+ export declare function skipItemMetadataFromWarehousePurchaseOrderRfqCategories(categories: IWarehousePurchaseOrderRFQ['categories'], previousCategories?: IWarehousePurchaseOrderRFQ['categories']): IWarehousePurchaseOrderRFQ['categories'];
10
+ export declare function getWarehousePurchaseOrderRfqWithAllFields<T extends IWarehousePurchaseOrderRFQ | Partial<IWarehousePurchaseOrderRFQ>>(order: T, skipItemMetadata?: boolean): T;
11
+ export interface IGetPurchaseOrderRfqCartItemsObjPayload {
12
+ currentIterationCategories: IWarehousePurchaseOrderRFQCategory[] | undefined;
13
+ previousIterationCategories: IWarehousePurchaseOrderRFQCategory[] | undefined;
14
+ mappedItems: Record<string, IWarehouseGeneralPurchaseOrderRfqItem>;
15
+ shouldSortItemsViaId?: boolean;
16
+ isAnEdit?: boolean;
17
+ sortType?: SORT_TYPE_ENUM;
18
+ }
19
+ export declare function getWarehousePurchaseOrderRfqCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId, isAnEdit, sortType, }: IGetPurchaseOrderRfqCartItemsObjPayload): IWarehousePurchaseOrderRfqCartItemsObj;
20
+ interface IGetVoidItemsWithReasonRfq {
21
+ currentCategories: IWarehousePurchaseOrderRFQCategory[];
22
+ iterationsFromFrontend: IWarehousePurchaseOrderRFQIteration[] | undefined;
23
+ previousCategories: IWarehousePurchaseOrderRFQCategory[];
24
+ }
25
+ export declare function getVoidItemsWithReasonWarehousePurchaseOrderRfq({ currentCategories, iterationsFromFrontend, previousCategories, }: IGetVoidItemsWithReasonRfq): {
26
+ newIterationCategories: IWarehousePurchaseOrderRFQCategory[];
27
+ voidOrderItems: IWarehousePurchaseOrderRFQItem[];
28
+ hasNewItems: boolean;
29
+ };
30
+ export {};
@@ -0,0 +1,537 @@
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.getWarehousePurchaseOrderRfqIterationsWithPrice = getWarehousePurchaseOrderRfqIterationsWithPrice;
7
+ exports.getWarehousePurchaseOrderRfqItemsWithPrice = getWarehousePurchaseOrderRfqItemsWithPrice;
8
+ exports.getWarehousePurchaseOrderRfqCategoriesWithPrice = getWarehousePurchaseOrderRfqCategoriesWithPrice;
9
+ exports.getWarehousePurchaseOrderRfqWithPrice = getWarehousePurchaseOrderRfqWithPrice;
10
+ exports.syncWarehousePurchaseOrderRfqData = syncWarehousePurchaseOrderRfqData;
11
+ exports.skipItemMetadataFromWarehousePurchaseOrderRfqCategories = skipItemMetadataFromWarehousePurchaseOrderRfqCategories;
12
+ exports.getWarehousePurchaseOrderRfqWithAllFields = getWarehousePurchaseOrderRfqWithAllFields;
13
+ exports.getWarehousePurchaseOrderRfqCartItemsObj = getWarehousePurchaseOrderRfqCartItemsObj;
14
+ exports.getVoidItemsWithReasonWarehousePurchaseOrderRfq = getVoidItemsWithReasonWarehousePurchaseOrderRfq;
15
+ const bson_objectid_1 = __importDefault(require("bson-objectid"));
16
+ const lodash_1 = require("lodash");
17
+ const constants_1 = require("../../constants");
18
+ const utils_1 = require("../utils");
19
+ const warehouse_purchase_order_rfq_cart_actions_1 = require("./warehouse-purchase-order-rfq-cart-actions");
20
+ /* =================================================================
21
+ * RFQ common helpers — price conversion, field defaults, cart UI.
22
+ * Mirrors common-warehouse-purchase-order-actions.ts for PO types.
23
+ * ================================================================= */
24
+ // ── Iterations ──
25
+ function getWarehousePurchaseOrderRfqIterationsWithPrice(iterations, writeable) {
26
+ if (!iterations)
27
+ return [];
28
+ return iterations.map((iteration) => getWarehousePurchaseOrderRfqWithPrice(iteration, writeable));
29
+ }
30
+ // ── Items ──
31
+ function getWarehousePurchaseOrderRfqItemsWithPrice(items, convertToPrice) {
32
+ if (!items)
33
+ return [];
34
+ return items.map((item) => ({
35
+ ...item,
36
+ quantity: (0, utils_1.parseNum)(item.quantity || 1, true),
37
+ price: convertToPrice(item.price ?? 0),
38
+ subtotal: convertToPrice(item.subtotal ?? 0),
39
+ _gst_amount: convertToPrice(item._gst_amount ?? 0),
40
+ _net_amount: convertToPrice(item._net_amount ?? 0),
41
+ _gross_amount: convertToPrice(item._gross_amount ?? 0),
42
+ _discount_amount: convertToPrice(item._discount_amount ?? 0),
43
+ }));
44
+ }
45
+ // ── Categories ──
46
+ function getWarehousePurchaseOrderRfqCategoriesWithPrice(categories, convertToPrice) {
47
+ if (!categories)
48
+ return [];
49
+ return categories.map((category) => ({
50
+ ...category,
51
+ items: getWarehousePurchaseOrderRfqItemsWithPrice(category.items, convertToPrice),
52
+ }));
53
+ }
54
+ // ── Order ──
55
+ function getWarehousePurchaseOrderRfqWithPrice(order, writeable) {
56
+ const convertToPrice = writeable ? utils_1.convertDecimalToInt : utils_1.convertIntToDecimal;
57
+ const payload = {
58
+ ...order,
59
+ ...(order.iterations != null
60
+ ? {
61
+ iterations: getWarehousePurchaseOrderRfqIterationsWithPrice(order.iterations, writeable),
62
+ }
63
+ : {}),
64
+ ...(order.categories != null
65
+ ? {
66
+ categories: getWarehousePurchaseOrderRfqCategoriesWithPrice(order.categories, convertToPrice),
67
+ }
68
+ : {}),
69
+ ...(order.gst != null ? { gst: convertToPrice(order.gst) } : {}),
70
+ ...(order.gst_amount != null ? { gst_amount: convertToPrice(order.gst_amount) } : {}),
71
+ ...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
72
+ ...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
73
+ ...(order.price != null ? { price: convertToPrice(order.price) } : {}),
74
+ };
75
+ return payload;
76
+ }
77
+ // ── Sync ──
78
+ function syncWarehousePurchaseOrderRfqData(order) {
79
+ const updatedOrder = {
80
+ ...order,
81
+ iterations: [],
82
+ };
83
+ const newOrder = getWarehousePurchaseOrderRfqWithPrice((0, warehouse_purchase_order_rfq_cart_actions_1.calculateCartWarehouseRfqOrderInfoAndSyncData)(getWarehousePurchaseOrderRfqWithPrice(updatedOrder), true), true);
84
+ newOrder.iterations = order.iterations;
85
+ return newOrder;
86
+ }
87
+ // ── Skip item metadata ──
88
+ function skipItemMetadataFromWarehousePurchaseOrderRfqCategories(categories, previousCategories) {
89
+ return categories.map((category) => {
90
+ const previousCategory = previousCategories?.find((prevCategory) => prevCategory.category_id === category.category_id);
91
+ return {
92
+ ...category,
93
+ items: category.items.map((item) => {
94
+ const previousItem = previousCategory?.items.find((prevItem) => prevItem._id === item._id);
95
+ const void_reason = previousItem?.void_reason ?? item.void_reason;
96
+ const newItem = {
97
+ ...item,
98
+ void_reason,
99
+ _discount_amount: 0,
100
+ _gst_amount: 0,
101
+ _gross_amount: 0,
102
+ _net_amount: 0,
103
+ };
104
+ return newItem;
105
+ }),
106
+ };
107
+ });
108
+ }
109
+ // ── Optional field helpers ──
110
+ function getCommonOptionalBoolFieldsPurchaseOrderRfq(order, partial) {
111
+ const defaultValue = partial ? undefined : false;
112
+ return {
113
+ is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
114
+ is_reopened: order['is_reopened'] || defaultValue,
115
+ };
116
+ }
117
+ function getCommonOptionalNumFieldsPurchaseOrderRfq(order, partial) {
118
+ const defaultValue = partial ? undefined : 0;
119
+ return {
120
+ gst: order['gst'] || defaultValue,
121
+ gst_amount: order['gst_amount'] || defaultValue,
122
+ };
123
+ }
124
+ function getWarehousePurchaseOrderRfqWithAllFields(order, skipItemMetadata) {
125
+ return {
126
+ ...order,
127
+ ...getCommonOptionalBoolFieldsPurchaseOrderRfq(order, false),
128
+ ...getCommonOptionalNumFieldsPurchaseOrderRfq(order, false),
129
+ ...(skipItemMetadata && order.categories != null
130
+ ? {
131
+ categories: skipItemMetadataFromWarehousePurchaseOrderRfqCategories(order.categories),
132
+ }
133
+ : {}),
134
+ delete_reason: order['delete_reason'] ?? null,
135
+ cancel_reason: order['cancel_reason'] ?? null,
136
+ };
137
+ }
138
+ const getRfqItemComparableData = (item) => ({
139
+ item_id: item.item_id,
140
+ name: item.name,
141
+ price: item.price,
142
+ special_instructions: item.special_instructions,
143
+ _id: item._id,
144
+ quantity: item.quantity,
145
+ });
146
+ function getWarehousePurchaseOrderRfqCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId = true, isAnEdit, sortType, }) {
147
+ const newMappedItems = { ...mappedItems };
148
+ if (Object.keys(newMappedItems).length === 0) {
149
+ previousIterationCategories?.forEach((category) => {
150
+ category.items.forEach((item) => {
151
+ if (newMappedItems[item.item_id] == null) {
152
+ newMappedItems[item.item_id] = {
153
+ _id: item.item_id,
154
+ name: item.name,
155
+ category_id: category.category_id,
156
+ category_name: category.name,
157
+ category_image_url: '',
158
+ image_url: '',
159
+ description: '',
160
+ };
161
+ }
162
+ });
163
+ });
164
+ currentIterationCategories?.forEach((category) => {
165
+ category.items.forEach((item) => {
166
+ if (newMappedItems[item.item_id] == null) {
167
+ newMappedItems[item.item_id] = {
168
+ _id: item.item_id,
169
+ name: item.name,
170
+ category_id: category.category_id,
171
+ category_name: category.name,
172
+ category_image_url: '',
173
+ image_url: '',
174
+ description: '',
175
+ };
176
+ }
177
+ });
178
+ });
179
+ }
180
+ // =====================><=====================
181
+ const getCartItems = (items) => {
182
+ const orderItems = items.map((item) => {
183
+ const selectedItem = newMappedItems[item.item_id] ?? {};
184
+ return {
185
+ orderItem: item,
186
+ image_url: selectedItem.image_url ?? '',
187
+ description: selectedItem.description ?? '',
188
+ category_name: selectedItem.category_name ?? '',
189
+ category_id: selectedItem.category_id ?? '',
190
+ };
191
+ });
192
+ if (shouldSortItemsViaId) {
193
+ if (sortType === constants_1.SORT_TYPE_ENUM.DESC) {
194
+ orderItems.sort((a, b) => (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime());
195
+ }
196
+ else {
197
+ orderItems.sort((a, b) => (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime());
198
+ }
199
+ }
200
+ return orderItems;
201
+ };
202
+ // =====================><=====================
203
+ /*
204
+ If the order has iterations in it, then we get the last iteration.
205
+ We would compare the changes in the last iteration with the current iteration
206
+ and show the changes in the cart.
207
+ */
208
+ let totalItemsInCart = 0;
209
+ const currentItems = [];
210
+ if (currentIterationCategories != null) {
211
+ for (let i = 0; i < currentIterationCategories.length; i++) {
212
+ const category = currentIterationCategories[i];
213
+ for (let j = 0; j < category.items.length; j++) {
214
+ const item = { ...category.items[j] };
215
+ currentItems.push(item);
216
+ totalItemsInCart += item.quantity;
217
+ }
218
+ }
219
+ }
220
+ let unChangedItems = currentItems;
221
+ const editedItems = [];
222
+ let removedItems = [];
223
+ let newItems = [];
224
+ let disabledReason = '';
225
+ // If previous iteration exists, then it's an update to the order.
226
+ // In that case we would keep the previous iteration as it is and
227
+ // compare the current iteration with the previous iteration.
228
+ // If the current iteration is different from the previous iteration in any way
229
+ // then we would update the current iteration with only those items that are different
230
+ const isAnUpdate = isAnEdit ?? (previousIterationCategories != null && previousIterationCategories.length > 0);
231
+ if (isAnUpdate) {
232
+ // we need to compare the current iteration with the previous iteration
233
+ const currentItemsMap = currentItems.reduce((acc, currentItem) => {
234
+ acc[currentItem._id] = currentItem;
235
+ return acc;
236
+ }, {});
237
+ const prevItems = [];
238
+ const prevItemsMap = {};
239
+ const prevCategories = previousIterationCategories ?? [];
240
+ for (let i = 0; i < prevCategories.length; i++) {
241
+ const category = prevCategories[i];
242
+ for (let j = 0; j < category.items.length; j++) {
243
+ const prevItem = category.items[j];
244
+ let item = prevItem;
245
+ const currentItem = currentItemsMap[prevItem._id];
246
+ if (currentItem != null && currentItem.is_ready != null) {
247
+ item = {
248
+ ...item,
249
+ is_ready: currentItem.is_ready,
250
+ };
251
+ }
252
+ prevItems.push(item);
253
+ prevItemsMap[item._id] = item;
254
+ }
255
+ }
256
+ // NOTE: We will always set the items from currentItemsMap because we are dealing with current iteration
257
+ unChangedItems = [];
258
+ let totalTempRemovedItems = 0;
259
+ for (let i = 0; i < prevItems.length; i++) {
260
+ const prevItem = {
261
+ ...prevItems[i],
262
+ };
263
+ const currentItem = {
264
+ ...currentItemsMap[prevItem._id],
265
+ };
266
+ // Step 1: Get the items that are not present in the current iteration
267
+ if (currentItemsMap[prevItem._id] == null) {
268
+ removedItems.push(prevItem);
269
+ }
270
+ // Step 2: Get the items that are same in the current iteration
271
+ else if ((0, lodash_1.isEqual)(getRfqItemComparableData(currentItem), getRfqItemComparableData(prevItem))) {
272
+ unChangedItems.push(prevItem);
273
+ }
274
+ // Step 3: Get the items that are present in the previous iteration but
275
+ // This is turn for edit items
276
+ // but we change logic for display purpose
277
+ else {
278
+ const currQty = currentItem.quantity;
279
+ const prevQty = prevItem.quantity;
280
+ if (currQty !== prevQty) {
281
+ const subtotalForOne = currentItem.subtotal / currentItem.quantity;
282
+ // currQty = 8
283
+ // prevQty = 3
284
+ // diff = 5
285
+ const diff = currQty - prevQty;
286
+ const changeQty = Math.abs(diff);
287
+ const itm = {
288
+ ...currentItem,
289
+ quantity: changeQty,
290
+ subtotal: (0, utils_1.parseNum)(changeQty * subtotalForOne),
291
+ };
292
+ if (diff > 0) {
293
+ // We need to show it as a new item
294
+ newItems.push(itm);
295
+ const unchangedQty = currQty - changeQty;
296
+ const tempUnchangedItm = {
297
+ ...currentItem,
298
+ quantity: unchangedQty,
299
+ subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
300
+ };
301
+ unChangedItems.push(tempUnchangedItm);
302
+ }
303
+ else {
304
+ itm.void_reason = prevItem.void_reason ?? currentItem.void_reason;
305
+ // We need to show it as a removed item
306
+ removedItems.push(itm);
307
+ const unchangedQty = prevQty - changeQty;
308
+ const tempUnchangedItm = {
309
+ ...currentItem,
310
+ quantity: unchangedQty,
311
+ subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
312
+ };
313
+ unChangedItems.push(tempUnchangedItm);
314
+ totalTempRemovedItems++;
315
+ }
316
+ }
317
+ else {
318
+ const curr = {
319
+ _id: currentItem._id,
320
+ item_id: currentItem.item_id,
321
+ name: currentItem.name,
322
+ special_instructions: currentItem.special_instructions,
323
+ };
324
+ const prev = {
325
+ _id: prevItem._id,
326
+ item_id: prevItem.item_id,
327
+ name: prevItem.name,
328
+ special_instructions: prevItem.special_instructions,
329
+ };
330
+ const isBothEqual = (0, lodash_1.isEqual)(curr, prev);
331
+ if (isBothEqual) {
332
+ unChangedItems.push(currentItem);
333
+ }
334
+ else {
335
+ // For edited item, we don't need to have tempUnchangedItemIds
336
+ // because it's the turn for edited item
337
+ editedItems.push(currentItem);
338
+ }
339
+ }
340
+ }
341
+ }
342
+ // Step 4: Get the items that are present in the current iteration
343
+ // but not present in the previous iteration
344
+ for (let i = 0; i < currentItems.length; i++) {
345
+ const item = currentItems[i];
346
+ if (prevItemsMap[item._id] == null) {
347
+ newItems.push(item);
348
+ }
349
+ }
350
+ // Lastly, we need to check if any same item has been removed and added
351
+ // If so, the we need to remove the item from removedItems and newItems, and add it to unChangedItems
352
+ if (removedItems.length > 0 && newItems.length > 0) {
353
+ const newItemsMap = newItems.reduce((acc, item) => {
354
+ acc[item.item_id] = [...(acc[item.item_id] ?? []), item];
355
+ return acc;
356
+ }, {});
357
+ const revertedRemovedItems = [];
358
+ const revertedNewItems = [];
359
+ const additionalNewItems = [];
360
+ for (let i = 0; i < removedItems.length; i++) {
361
+ const removedItem = removedItems[i];
362
+ // Need to check if the removed item is present in the newItems
363
+ const newItemsForItem = newItemsMap[removedItem.item_id];
364
+ if (newItemsForItem == null)
365
+ continue;
366
+ if (newItemsForItem.length > 0) {
367
+ const newItemsForItemLength = newItemsForItem.length;
368
+ for (let j = 0; j < newItemsForItemLength; j++) {
369
+ const newItem = newItemsForItem[j];
370
+ const newI = {
371
+ // _id: newItem._id,
372
+ item_id: newItem.item_id,
373
+ name: newItem.name,
374
+ price: newItem.price,
375
+ // subtotal: number;
376
+ // quantity: newItem.quantity,
377
+ special_instructions: newItem.special_instructions,
378
+ };
379
+ const removedI = {
380
+ // _id: removedItem._id,
381
+ item_id: removedItem.item_id,
382
+ name: removedItem.name,
383
+ price: removedItem.price,
384
+ // subtotal: number;
385
+ // quantity: removedItem.quantity,
386
+ special_instructions: removedItem.special_instructions,
387
+ };
388
+ if ((0, lodash_1.isEqual)(newI, removedI)) {
389
+ if (newItem.quantity === removedItem.quantity) {
390
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
391
+ if (newItemsMap[removedItem.item_id].length === 0) {
392
+ delete newItemsMap[removedItem.item_id];
393
+ }
394
+ revertedNewItems.push(newItem);
395
+ revertedRemovedItems.push(removedItem);
396
+ // We will break the loop when ever we push to revertedRemovedItems
397
+ break;
398
+ }
399
+ else {
400
+ if (removedItem.quantity > newItem.quantity) {
401
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
402
+ if (newItemsMap[removedItem.item_id].length === 0) {
403
+ delete newItemsMap[removedItem.item_id];
404
+ }
405
+ revertedNewItems.push(newItem);
406
+ const subtotalForSingle = removedItem.subtotal / removedItem.quantity;
407
+ // We will only minus the quantity from removedItem
408
+ const newQuantity = removedItem.quantity - newItem.quantity;
409
+ const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
410
+ removedItem.quantity = newQuantity;
411
+ removedItem.subtotal = newSubtotal;
412
+ }
413
+ else {
414
+ revertedRemovedItems.push(removedItem);
415
+ const nQuantity = newItem.quantity;
416
+ const subtotalForSingle = newItem.subtotal / nQuantity;
417
+ const newQuantity = nQuantity - removedItem.quantity;
418
+ const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
419
+ newItem.quantity = newQuantity;
420
+ newItem.subtotal = newSubtotal;
421
+ // =====================><=====================
422
+ const remainingQuantity = nQuantity - newQuantity;
423
+ const adItem = {
424
+ ...newItem,
425
+ quantity: remainingQuantity,
426
+ subtotal: (0, utils_1.parseNum)(remainingQuantity * subtotalForSingle),
427
+ };
428
+ additionalNewItems.push(adItem);
429
+ // We will break the loop when ever we push to revertedRemovedItems
430
+ break;
431
+ }
432
+ }
433
+ }
434
+ }
435
+ }
436
+ else {
437
+ delete newItemsMap[removedItem.item_id];
438
+ }
439
+ }
440
+ for (let i = 0; i < revertedRemovedItems.length; i++) {
441
+ const rItem = revertedRemovedItems[i];
442
+ removedItems = removedItems.filter((item) => item._id !== rItem._id);
443
+ }
444
+ for (let i = 0; i < revertedNewItems.length; i++) {
445
+ const nItem = revertedNewItems[i];
446
+ newItems = newItems.filter((item) => item._id !== nItem._id);
447
+ unChangedItems.push(nItem);
448
+ }
449
+ for (let i = 0; i < additionalNewItems.length; i++) {
450
+ const aItem = additionalNewItems[i];
451
+ unChangedItems.push(aItem);
452
+ }
453
+ }
454
+ disabledReason =
455
+ unChangedItems.length === prevItems.length &&
456
+ newItems.length === 0 &&
457
+ removedItems.length === 0 &&
458
+ editedItems.length === 0
459
+ ? 'No changes in the order'
460
+ : prevItems.length === removedItems.length - totalTempRemovedItems &&
461
+ editedItems.length === 0 &&
462
+ newItems.length === 0
463
+ ? 'At least one item is required'
464
+ : '';
465
+ }
466
+ const cartItemsObj = {
467
+ unChangedItems: getCartItems(unChangedItems),
468
+ editedItems: getCartItems(editedItems),
469
+ removedItems: getCartItems(removedItems),
470
+ newItems: getCartItems(newItems),
471
+ totalSelectedItems: (0, utils_1.parseNum)(totalItemsInCart, true),
472
+ disabledReason,
473
+ isAnUpdate,
474
+ };
475
+ return cartItemsObj;
476
+ }
477
+ function getVoidItemsWithReasonWarehousePurchaseOrderRfq({ currentCategories, iterationsFromFrontend, previousCategories, }) {
478
+ const voidOrderItemReasonsMap = {};
479
+ const latestIterationCategories = iterationsFromFrontend?.[0]?.categories;
480
+ if (latestIterationCategories != null && latestIterationCategories.length > 0) {
481
+ for (let i = 0; i < latestIterationCategories.length; i++) {
482
+ const category = latestIterationCategories[i];
483
+ for (let j = 0; j < category.items.length; j++) {
484
+ const item = category.items[j];
485
+ if (item.void_reason != null && item.void_reason.length > 0) {
486
+ voidOrderItemReasonsMap[item._id] = item.void_reason;
487
+ }
488
+ }
489
+ }
490
+ }
491
+ const { newItems, removedItems } = getWarehousePurchaseOrderRfqCartItemsObj({
492
+ currentIterationCategories: currentCategories,
493
+ previousIterationCategories: previousCategories,
494
+ mappedItems: {},
495
+ shouldSortItemsViaId: false,
496
+ isAnEdit: true,
497
+ });
498
+ const hasNewItems = newItems.length > 0;
499
+ const voidOrderItems = [];
500
+ const newVoidOrderItemReasonsMap = {};
501
+ for (let i = 0; i < removedItems.length; i++) {
502
+ const { orderItem } = removedItems[i];
503
+ const voidReason = voidOrderItemReasonsMap[orderItem._id];
504
+ voidOrderItems.push({
505
+ ...orderItem,
506
+ subtotal: Math.round(orderItem.subtotal),
507
+ void_reason: voidReason ?? '-',
508
+ });
509
+ if (voidReason != null) {
510
+ newVoidOrderItemReasonsMap[orderItem._id] = voidReason;
511
+ }
512
+ }
513
+ const newIterationCategories = [];
514
+ for (let i = 0; i < previousCategories.length; i++) {
515
+ const category = previousCategories[i];
516
+ const newCategoryItems = [];
517
+ for (let j = 0; j < category.items.length; j++) {
518
+ const prevItem = category.items[j];
519
+ const voidReason = newVoidOrderItemReasonsMap[prevItem._id];
520
+ const orderItem = {
521
+ ...prevItem,
522
+ subtotal: Math.round(prevItem.subtotal),
523
+ };
524
+ if (voidReason != null) {
525
+ orderItem.void_reason = voidReason;
526
+ }
527
+ newCategoryItems.push(orderItem);
528
+ }
529
+ if (newCategoryItems.length === 0)
530
+ continue;
531
+ newIterationCategories.push({
532
+ ...category,
533
+ items: newCategoryItems,
534
+ });
535
+ }
536
+ return { newIterationCategories, voidOrderItems, hasNewItems };
537
+ }
@@ -0,0 +1,5 @@
1
+ import { IWarehouseSaleOrderRFQ, IWarehouseSaleOrderRFQCategory, IWarehouseSaleOrderRFQItem, IWarehouseSaleOrderRFQIteration } from '../../schemas';
2
+ export declare function getWarehouseSaleOrderRfqIterationsWithPrice(iterations?: IWarehouseSaleOrderRFQIteration[] | undefined, writeable?: boolean): IWarehouseSaleOrderRFQIteration[];
3
+ export declare function getWarehouseSaleOrderRfqItemsWithPrice(items: IWarehouseSaleOrderRFQItem[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderRFQItem[];
4
+ export declare function getWarehouseSaleOrderRfqCategoriesWithPrice(categories: IWarehouseSaleOrderRFQCategory[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderRFQCategory[];
5
+ export declare function getWarehouseSaleOrderRfqWithPrice<T extends Partial<IWarehouseSaleOrderRFQ> | IWarehouseSaleOrderRFQ | IWarehouseSaleOrderRFQIteration>(order: T, writeable?: boolean): T;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWarehouseSaleOrderRfqIterationsWithPrice = getWarehouseSaleOrderRfqIterationsWithPrice;
4
+ exports.getWarehouseSaleOrderRfqItemsWithPrice = getWarehouseSaleOrderRfqItemsWithPrice;
5
+ exports.getWarehouseSaleOrderRfqCategoriesWithPrice = getWarehouseSaleOrderRfqCategoriesWithPrice;
6
+ exports.getWarehouseSaleOrderRfqWithPrice = getWarehouseSaleOrderRfqWithPrice;
7
+ const utils_1 = require("../utils");
8
+ // ── Iterations ──────────────────────────────────────────────────
9
+ function getWarehouseSaleOrderRfqIterationsWithPrice(iterations, writeable) {
10
+ if (!iterations)
11
+ return [];
12
+ return iterations.map((iteration) => getWarehouseSaleOrderRfqWithPrice(iteration, writeable));
13
+ }
14
+ // ── Items ───────────────────────────────────────────────────────
15
+ function getWarehouseSaleOrderRfqItemsWithPrice(items, convertToPrice) {
16
+ if (!items)
17
+ return [];
18
+ return items.map((item) => ({
19
+ ...item,
20
+ quantity: (0, utils_1.parseNum)(item.quantity || 1, true),
21
+ price: convertToPrice(item.price ?? 0),
22
+ subtotal: convertToPrice(item.subtotal ?? 0),
23
+ _gst_amount: convertToPrice(item._gst_amount ?? 0),
24
+ _net_amount: convertToPrice(item._net_amount ?? 0),
25
+ _gross_amount: convertToPrice(item._gross_amount ?? 0),
26
+ _discount_amount: convertToPrice(item._discount_amount ?? 0),
27
+ }));
28
+ }
29
+ // ── Categories ──────────────────────────────────────────────────
30
+ function getWarehouseSaleOrderRfqCategoriesWithPrice(categories, convertToPrice) {
31
+ if (!categories)
32
+ return [];
33
+ return categories.map((category) => ({
34
+ ...category,
35
+ items: getWarehouseSaleOrderRfqItemsWithPrice(category.items, convertToPrice),
36
+ }));
37
+ }
38
+ // ── Main helper ─────────────────────────────────────────────────
39
+ function getWarehouseSaleOrderRfqWithPrice(order, writeable) {
40
+ const convertToPrice = writeable ? utils_1.convertDecimalToInt : utils_1.convertIntToDecimal;
41
+ const payload = {
42
+ ...order,
43
+ ...(order.iterations != null
44
+ ? {
45
+ iterations: getWarehouseSaleOrderRfqIterationsWithPrice(order.iterations, writeable),
46
+ }
47
+ : {}),
48
+ ...(order.categories != null
49
+ ? {
50
+ categories: getWarehouseSaleOrderRfqCategoriesWithPrice(order.categories, convertToPrice),
51
+ }
52
+ : {}),
53
+ ...(order.gst != null ? { gst: convertToPrice(order.gst) } : {}),
54
+ ...(order.gst_amount != null ? { gst_amount: convertToPrice(order.gst_amount) } : {}),
55
+ ...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
56
+ ...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
57
+ ...(order.price != null ? { price: convertToPrice(order.price) } : {}),
58
+ };
59
+ return payload;
60
+ }
@@ -1,14 +1,18 @@
1
1
  export * from './all-orders-actions';
2
+ export * from './all-warehouse-invoice-actions';
3
+ export * from './all-warehouse-purchase-order-rfqs-actions';
2
4
  export * from './all-warehouse-purchase-orders-actions';
5
+ export * from './all-warehouse-sale-order-rfqs-actions';
3
6
  export * from './all-warehouse-sale-orders-actions';
4
- export * from './all-warehouse-invoice-actions';
5
7
  export * from './cart-actions';
6
8
  export * from './catalog-actions';
7
9
  export * from './common-order-actions';
10
+ export * from './common-warehouse-invoice-actions';
8
11
  export * from './common-warehouse-purchase-order-actions';
12
+ export * from './common-warehouse-purchase-order-rfq-actions';
9
13
  export * from './common-warehouse-sale-order-actions';
10
- export * from './common-warehouse-invoice-actions';
14
+ export * from './common-warehouse-sale-order-rfq-actions';
11
15
  export * from './offline-ordering';
16
+ export * from './warehouse-invoice-cart-actions';
12
17
  export * from './warehouse-purchase-order-rfq-cart-actions';
13
18
  export * from './warehouse-purchase-orders-cart-actions';
14
- export * from './warehouse-invoice-cart-actions';
@@ -15,16 +15,20 @@ 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-warehouse-invoice-actions"), exports);
19
+ __exportStar(require("./all-warehouse-purchase-order-rfqs-actions"), exports);
18
20
  __exportStar(require("./all-warehouse-purchase-orders-actions"), exports);
21
+ __exportStar(require("./all-warehouse-sale-order-rfqs-actions"), exports);
19
22
  __exportStar(require("./all-warehouse-sale-orders-actions"), exports);
20
- __exportStar(require("./all-warehouse-invoice-actions"), exports);
21
23
  __exportStar(require("./cart-actions"), exports);
22
24
  __exportStar(require("./catalog-actions"), exports);
23
25
  __exportStar(require("./common-order-actions"), exports);
26
+ __exportStar(require("./common-warehouse-invoice-actions"), exports);
24
27
  __exportStar(require("./common-warehouse-purchase-order-actions"), exports);
28
+ __exportStar(require("./common-warehouse-purchase-order-rfq-actions"), exports);
25
29
  __exportStar(require("./common-warehouse-sale-order-actions"), exports);
26
- __exportStar(require("./common-warehouse-invoice-actions"), exports);
30
+ __exportStar(require("./common-warehouse-sale-order-rfq-actions"), exports);
27
31
  __exportStar(require("./offline-ordering"), exports);
32
+ __exportStar(require("./warehouse-invoice-cart-actions"), exports);
28
33
  __exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
29
34
  __exportStar(require("./warehouse-purchase-orders-cart-actions"), exports);
30
- __exportStar(require("./warehouse-invoice-cart-actions"), exports);
@@ -17,6 +17,7 @@ export * from './marketing';
17
17
  export * from './order-engine';
18
18
  export * from './pra-generate-invoice';
19
19
  export * from './warehouse-purchase-order-cart-actions';
20
+ export * from './warehouse-purchase-order-rfq-cart-actions';
20
21
  export * from './report-webview';
21
22
  export * from './reports';
22
23
  export * from './smartpay-apis';
@@ -33,6 +33,7 @@ __exportStar(require("./marketing"), exports);
33
33
  __exportStar(require("./order-engine"), exports);
34
34
  __exportStar(require("./pra-generate-invoice"), exports);
35
35
  __exportStar(require("./warehouse-purchase-order-cart-actions"), exports);
36
+ __exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
36
37
  __exportStar(require("./report-webview"), exports);
37
38
  __exportStar(require("./reports"), exports);
38
39
  __exportStar(require("./smartpay-apis"), exports);
@@ -0,0 +1,26 @@
1
+ import { IWarehousePurchaseOrderRFQItem } from '../../schemas';
2
+ export interface IWarehouseGeneralPurchaseOrderRfqItem {
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 IWarehousePurchaseOrderRfqCartItem {
12
+ orderItem: IWarehousePurchaseOrderRFQItem;
13
+ image_url: string | null;
14
+ description: string;
15
+ category_name: string;
16
+ category_id: string;
17
+ }
18
+ export interface IWarehousePurchaseOrderRfqCartItemsObj {
19
+ unChangedItems: IWarehousePurchaseOrderRfqCartItem[];
20
+ editedItems: IWarehousePurchaseOrderRfqCartItem[];
21
+ removedItems: IWarehousePurchaseOrderRfqCartItem[];
22
+ newItems: IWarehousePurchaseOrderRfqCartItem[];
23
+ totalSelectedItems: number;
24
+ disabledReason: string;
25
+ isAnUpdate: boolean;
26
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.440",
3
+ "version": "0.2.442",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",