@managesome/eposmatic-toolkit 0.2.427 → 0.2.430

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.
Files changed (135) hide show
  1. package/lib/helpers/order/generate-purchase-order-rfq.d.ts +3 -0
  2. package/lib/helpers/order/generate-purchase-order-rfq.js +64 -0
  3. package/lib/helpers/order/index.d.ts +1 -0
  4. package/lib/helpers/order/index.js +1 -0
  5. package/lib/helpers/store/index.d.ts +1 -0
  6. package/lib/helpers/store/index.js +1 -0
  7. package/lib/helpers/store/purchase-order-rfq-cart-actions.d.ts +19 -0
  8. package/lib/helpers/store/purchase-order-rfq-cart-actions.js +373 -0
  9. package/lib/schemas/models/applied_order_discounts.d.ts +80 -0
  10. package/lib/schemas/models/applied_order_discounts.js +106 -0
  11. package/lib/schemas/models/brands.d.ts +45 -0
  12. package/lib/schemas/models/brands.js +45 -0
  13. package/lib/schemas/models/categories.d.ts +60 -0
  14. package/lib/schemas/models/categories.js +67 -0
  15. package/lib/schemas/models/close_dates.js +2 -2
  16. package/lib/schemas/models/dinein_tables.d.ts +6 -6
  17. package/lib/schemas/models/dinein_tables_fingerprints.d.ts +65 -0
  18. package/lib/schemas/models/dinein_tables_fingerprints.js +85 -0
  19. package/lib/schemas/models/discounts.js +3 -3
  20. package/lib/schemas/models/expense_categories.d.ts +83 -0
  21. package/lib/schemas/models/expense_categories.js +64 -0
  22. package/lib/schemas/models/halfhalf_setup.js +3 -3
  23. package/lib/schemas/models/index.d.ts +23 -23
  24. package/lib/schemas/models/index.js +23 -23
  25. package/lib/schemas/models/inventories.d.ts +99 -0
  26. package/lib/schemas/models/inventories.js +87 -0
  27. package/lib/schemas/models/inventory_lot_serial_numbers.d.ts +15 -15
  28. package/lib/schemas/models/items.d.ts +11269 -0
  29. package/lib/schemas/models/items.js +333 -0
  30. package/lib/schemas/models/menus.d.ts +941 -0
  31. package/lib/schemas/models/menus.js +69 -0
  32. package/lib/schemas/models/offers.js +3 -3
  33. package/lib/schemas/models/orders.d.ts +15437 -0
  34. package/lib/schemas/models/orders.js +891 -0
  35. package/lib/schemas/models/public_holidays.js +2 -2
  36. package/lib/schemas/models/purchase_order_receipts.d.ts +3 -3
  37. package/lib/schemas/models/purchase_order_receipts.js +2 -2
  38. package/lib/schemas/models/purchase_order_rfqs.d.ts +1959 -0
  39. package/lib/schemas/models/purchase_order_rfqs.js +328 -0
  40. package/lib/schemas/models/purchase_order_vendor_returns.d.ts +15 -15
  41. package/lib/schemas/models/purchase_order_vendor_returns.js +2 -2
  42. package/lib/schemas/models/purchase_orders.js +4 -4
  43. package/lib/schemas/models/riders.d.ts +65 -0
  44. package/lib/schemas/models/riders.js +74 -0
  45. package/lib/schemas/models/specials.js +3 -3
  46. package/lib/schemas/models/tenant_staffs.d.ts +932 -0
  47. package/lib/schemas/models/tenant_staffs.js +96 -0
  48. package/lib/schemas/models/tenants.d.ts +528 -0
  49. package/lib/schemas/models/tenants.js +755 -0
  50. package/lib/schemas/models/track_order_numbers.d.ts +413 -0
  51. package/lib/schemas/models/track_order_numbers.js +45 -0
  52. package/lib/schemas/models/void_purchase_order_items.js +2 -2
  53. package/lib/schemas/models/void_warehouse_invoice_items.d.ts +6 -6
  54. package/lib/schemas/models/void_warehouse_invoice_items.js +2 -2
  55. package/lib/schemas/models/wallets.d.ts +38 -0
  56. package/lib/schemas/models/wallets.js +37 -0
  57. package/lib/schemas/models/warehouse-activity-logs.js +2 -2
  58. package/lib/schemas/models/warehouse_communications.d.ts +228 -0
  59. package/lib/schemas/models/warehouse_communications.js +216 -0
  60. package/lib/schemas/models/warehouse_internal_movements.d.ts +33 -34
  61. package/lib/schemas/models/warehouse_internal_movements.js +2 -34
  62. package/lib/schemas/models/warehouse_invoices.js +2 -2
  63. package/lib/schemas/models/warehouse_items.js +2 -2
  64. package/lib/schemas/models/warehouse_sale_deliveries.d.ts +167 -0
  65. package/lib/schemas/models/warehouse_sale_deliveries.js +155 -0
  66. package/lib/schemas/models/warehouse_sale_invoices.d.ts +227 -0
  67. package/lib/schemas/models/warehouse_sale_invoices.js +206 -0
  68. package/lib/schemas/models/warehouse_sale_order_rfqs.d.ts +1938 -0
  69. package/lib/schemas/models/warehouse_sale_order_rfqs.js +309 -0
  70. package/lib/schemas/models/warehouse_sale_orders.d.ts +1943 -0
  71. package/lib/schemas/models/warehouse_sale_orders.js +324 -0
  72. package/lib/schemas/models/warehouse_staffs.d.ts +65 -0
  73. package/lib/schemas/models/warehouse_staffs.js +78 -0
  74. package/lib/schemas/models/warehouse_track_order_numbers.d.ts +50 -0
  75. package/lib/schemas/models/warehouse_track_order_numbers.js +52 -0
  76. package/lib/schemas/models/warehouse_vendors.d.ts +3 -3
  77. package/lib/schemas/models/warehouses.d.ts +162 -0
  78. package/lib/schemas/models/warehouses.js +222 -0
  79. package/lib/schemas/types/applied_order_discounts.d.ts +22 -0
  80. package/lib/schemas/types/applied_order_discounts.js +2 -0
  81. package/lib/schemas/types/brands.d.ts +32 -0
  82. package/lib/schemas/types/brands.js +2 -0
  83. package/lib/schemas/types/categories.d.ts +15 -0
  84. package/lib/schemas/types/categories.js +2 -0
  85. package/lib/schemas/types/deliveries.d.ts +1 -1
  86. package/lib/schemas/types/expense_categories.d.ts +20 -0
  87. package/lib/schemas/types/expense_categories.js +2 -0
  88. package/lib/schemas/types/expense_details.d.ts +1 -1
  89. package/lib/schemas/types/index.d.ts +22 -22
  90. package/lib/schemas/types/index.js +22 -22
  91. package/lib/schemas/types/inventories.d.ts +48 -0
  92. package/lib/schemas/types/inventories.js +2 -0
  93. package/lib/schemas/types/items.d.ts +89 -0
  94. package/lib/schemas/types/items.js +2 -0
  95. package/lib/schemas/types/menus.d.ts +17 -0
  96. package/lib/schemas/types/menus.js +2 -0
  97. package/lib/schemas/types/multi_tenants.d.ts +2 -2
  98. package/lib/schemas/types/orders.d.ts +242 -0
  99. package/lib/schemas/types/orders.js +2 -0
  100. package/lib/schemas/types/purchase_order_common.d.ts +1 -1
  101. package/lib/schemas/types/purchase_order_rfqs.d.ts +33 -0
  102. package/lib/schemas/types/purchase_order_rfqs.js +2 -0
  103. package/lib/schemas/types/purchase_orders.d.ts +1 -1
  104. package/lib/schemas/types/reservations.d.ts +1 -1
  105. package/lib/schemas/types/riders.d.ts +16 -0
  106. package/lib/schemas/types/riders.js +2 -0
  107. package/lib/schemas/types/sale_order_common.d.ts +1 -1
  108. package/lib/schemas/types/specials.d.ts +1 -1
  109. package/lib/schemas/types/tenant_staffs.d.ts +22 -0
  110. package/lib/schemas/types/tenant_staffs.js +2 -0
  111. package/lib/schemas/types/tenants.d.ts +205 -0
  112. package/lib/schemas/types/tenants.js +2 -0
  113. package/lib/schemas/types/track_order_numbers.d.ts +10 -0
  114. package/lib/schemas/types/track_order_numbers.js +2 -0
  115. package/lib/schemas/types/wallets.d.ts +7 -0
  116. package/lib/schemas/types/wallets.js +2 -0
  117. package/lib/schemas/types/warehouse_communications.d.ts +54 -0
  118. package/lib/schemas/types/warehouse_communications.js +2 -0
  119. package/lib/schemas/types/warehouse_internal_movements.d.ts +2 -2
  120. package/lib/schemas/types/warehouse_invoices.d.ts +1 -1
  121. package/lib/schemas/types/warehouse_sale_deliveries.d.ts +67 -0
  122. package/lib/schemas/types/warehouse_sale_deliveries.js +2 -0
  123. package/lib/schemas/types/warehouse_sale_invoices.d.ts +49 -0
  124. package/lib/schemas/types/warehouse_sale_invoices.js +2 -0
  125. package/lib/schemas/types/warehouse_sale_order_rfqs.d.ts +25 -0
  126. package/lib/schemas/types/warehouse_sale_order_rfqs.js +2 -0
  127. package/lib/schemas/types/warehouse_sale_orders.d.ts +30 -0
  128. package/lib/schemas/types/warehouse_sale_orders.js +2 -0
  129. package/lib/schemas/types/warehouse_staffs.d.ts +17 -0
  130. package/lib/schemas/types/warehouse_staffs.js +2 -0
  131. package/lib/schemas/types/warehouse_track_order_numbers.d.ts +11 -0
  132. package/lib/schemas/types/warehouse_track_order_numbers.js +2 -0
  133. package/lib/schemas/types/warehouses.d.ts +49 -0
  134. package/lib/schemas/types/warehouses.js +2 -0
  135. package/package.json +1 -1
@@ -0,0 +1,3 @@
1
+ import { IPurchaseOrderRFQ, IPurchaseOrderRFQIteration } from '../../schemas';
2
+ export declare function generatePurchaseOrderRfqCategories(categories?: IPurchaseOrderRFQ['categories']): IPurchaseOrderRFQ['categories'];
3
+ export declare function generatePurchaseOrderRfqIteration(order: IPurchaseOrderRFQ | IPurchaseOrderRFQIteration, partial?: boolean, skipItemMetadata?: boolean): IPurchaseOrderRFQIteration;
@@ -0,0 +1,64 @@
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.generatePurchaseOrderRfqCategories = generatePurchaseOrderRfqCategories;
7
+ exports.generatePurchaseOrderRfqIteration = generatePurchaseOrderRfqIteration;
8
+ const mongoose_1 = __importDefault(require("mongoose"));
9
+ const common_purchase_order_actions_1 = require("../store/common-purchase-order-actions");
10
+ function generatePurchaseOrderRfqCategories(categories) {
11
+ if (!categories)
12
+ return [];
13
+ return categories.map((category) => ({
14
+ ...category,
15
+ category_id: new mongoose_1.default.Types.ObjectId(category.category_id),
16
+ items: category.items.map((item) => ({
17
+ ...item,
18
+ _id: new mongoose_1.default.Types.ObjectId(item._id),
19
+ item_id: new mongoose_1.default.Types.ObjectId(item.item_id),
20
+ })),
21
+ }));
22
+ }
23
+ function getCommonOptionalBoolFieldsRfqIteration(order, partial) {
24
+ const defaultValue = partial ? undefined : false;
25
+ return {
26
+ is_gst_inclusive: order.is_gst_inclusive || defaultValue,
27
+ };
28
+ }
29
+ function getCommonOptionalNumFieldsRfqIteration(order, partial) {
30
+ const defaultValue = partial ? undefined : 0;
31
+ return {
32
+ gst: order.gst || defaultValue,
33
+ gst_amount: order.gst_amount || defaultValue,
34
+ };
35
+ }
36
+ function generatePurchaseOrderRfqIteration(order, partial = true, skipItemMetadata) {
37
+ const iteration = {
38
+ ...getCommonOptionalBoolFieldsRfqIteration(order, partial),
39
+ ...getCommonOptionalNumFieldsRfqIteration(order, partial),
40
+ ...(skipItemMetadata && order.categories != null
41
+ ? {
42
+ categories: (0, common_purchase_order_actions_1.skipItemMetadataFromPurchaseOrderCategories)(order.categories),
43
+ }
44
+ : {
45
+ categories: generatePurchaseOrderRfqCategories(order.categories),
46
+ }),
47
+ staff_details: order.staff_details,
48
+ special_instructions: order.special_instructions,
49
+ order_status: order.order_status,
50
+ price: order.price,
51
+ amount_earned: order.amount_earned,
52
+ grand_total: order.grand_total,
53
+ tax_number: order.tax_number,
54
+ updatedAt: order.updatedAt,
55
+ };
56
+ if (partial) {
57
+ Object.keys(iteration).forEach((key) => {
58
+ if (iteration[key] === undefined) {
59
+ delete iteration[key];
60
+ }
61
+ });
62
+ }
63
+ return iteration;
64
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './generate-order';
2
2
  export * from './generate-purchase-order';
3
+ export * from './generate-purchase-order-rfq';
3
4
  export * from './generate-warehouse-invoice';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./generate-order"), exports);
18
18
  __exportStar(require("./generate-purchase-order"), exports);
19
+ __exportStar(require("./generate-purchase-order-rfq"), exports);
19
20
  __exportStar(require("./generate-warehouse-invoice"), exports);
@@ -9,5 +9,6 @@ export * from './common-purchase-order-actions';
9
9
  export * from './common-sale-order-actions';
10
10
  export * from './common-warehouse-invoice-actions';
11
11
  export * from './offline-ordering';
12
+ export * from './purchase-order-rfq-cart-actions';
12
13
  export * from './purchase-orders-cart-actions';
13
14
  export * from './warehouse-invoice-cart-actions';
@@ -25,5 +25,6 @@ __exportStar(require("./common-purchase-order-actions"), exports);
25
25
  __exportStar(require("./common-sale-order-actions"), exports);
26
26
  __exportStar(require("./common-warehouse-invoice-actions"), exports);
27
27
  __exportStar(require("./offline-ordering"), exports);
28
+ __exportStar(require("./purchase-order-rfq-cart-actions"), exports);
28
29
  __exportStar(require("./purchase-orders-cart-actions"), exports);
29
30
  __exportStar(require("./warehouse-invoice-cart-actions"), exports);
@@ -0,0 +1,19 @@
1
+ import { IPurchaseOrderRFQ, IPurchaseOrderRFQItem } from '../../schemas';
2
+ export declare function calculateCartRfqOrderInfoAndSyncData<T extends IPurchaseOrderRFQ | Partial<IPurchaseOrderRFQ>>(data: T, calculateItemMetadata?: boolean): T;
3
+ export declare function getRemoveItemFromRfqCartData(data: Partial<IPurchaseOrderRFQ>, payload: {
4
+ _id: string;
5
+ void_reason?: string;
6
+ }): Partial<IPurchaseOrderRFQ>;
7
+ export declare function getUpdateRfqCartInfoData(data: Partial<IPurchaseOrderRFQ>, payload: Partial<IPurchaseOrderRFQ>): Partial<IPurchaseOrderRFQ>;
8
+ interface ISetAddItemToRfqCartActionPayload {
9
+ name: string;
10
+ category_id: string;
11
+ item: IPurchaseOrderRFQItem;
12
+ replace_id?: string;
13
+ }
14
+ export declare function getAddItemToRfqCartData(data: Partial<IPurchaseOrderRFQ>, payload: ISetAddItemToRfqCartActionPayload): Partial<IPurchaseOrderRFQ>;
15
+ export declare function getUpdateItemInRfqCartData(data: Partial<IPurchaseOrderRFQ>, payload: Partial<IPurchaseOrderRFQItem>): Partial<IPurchaseOrderRFQ>;
16
+ export declare function getUpdateItemsInRfqCartData(data: Partial<IPurchaseOrderRFQ>, payload: Partial<IPurchaseOrderRFQItem>[]): Partial<IPurchaseOrderRFQ>;
17
+ export declare function getSplitRfqCartItemToTwo(data: Partial<IPurchaseOrderRFQ>, orderItemId: string): Partial<IPurchaseOrderRFQ>;
18
+ export declare function getAddItemsToRfqCartData(data: Partial<IPurchaseOrderRFQ>, payload: ISetAddItemToRfqCartActionPayload[]): Partial<IPurchaseOrderRFQ>;
19
+ export {};
@@ -0,0 +1,373 @@
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.calculateCartRfqOrderInfoAndSyncData = calculateCartRfqOrderInfoAndSyncData;
7
+ exports.getRemoveItemFromRfqCartData = getRemoveItemFromRfqCartData;
8
+ exports.getUpdateRfqCartInfoData = getUpdateRfqCartInfoData;
9
+ exports.getAddItemToRfqCartData = getAddItemToRfqCartData;
10
+ exports.getUpdateItemInRfqCartData = getUpdateItemInRfqCartData;
11
+ exports.getUpdateItemsInRfqCartData = getUpdateItemsInRfqCartData;
12
+ exports.getSplitRfqCartItemToTwo = getSplitRfqCartItemToTwo;
13
+ exports.getAddItemsToRfqCartData = getAddItemsToRfqCartData;
14
+ const bson_objectid_1 = __importDefault(require("bson-objectid"));
15
+ const lodash_1 = require("lodash");
16
+ const constants_1 = require("../../constants");
17
+ const utils_1 = require("../utils");
18
+ /* =================================================================
19
+ * RFQ cart helpers — fully typed, no delegation to PO functions.
20
+ * IPurchaseOrderRFQCategory ≡ IPurchaseOrderCategory (same type),
21
+ * IPurchaseOrderRFQItem ≡ IPurchaseOrderItem (same type).
22
+ * ================================================================= */
23
+ function calculateCartRfqOrderInfoAndSyncData(data, calculateItemMetadata) {
24
+ const isConfirmed = data.order_status === constants_1.PURCHASE_ORDER_RFQ_STATUS_ENUM.CONFIRMED;
25
+ let subtotal = 0;
26
+ const categories = [];
27
+ const length = data.categories?.length ?? 0;
28
+ for (let c = 0; c < length; c++) {
29
+ const category = data.categories[c];
30
+ const newItems = [];
31
+ const itemsLength = category.items.length;
32
+ for (let i = 0; i < itemsLength; i++) {
33
+ const item = category.items[i];
34
+ const itemSubtotal = (0, utils_1.parseNum)(item.price * item.quantity);
35
+ const newItem = {
36
+ ...item,
37
+ is_ready: item.is_ready || isConfirmed,
38
+ subtotal: itemSubtotal,
39
+ _discount_amount: 0,
40
+ _gross_amount: 0,
41
+ _gst_amount: 0,
42
+ _net_amount: 0,
43
+ };
44
+ delete newItem.void_reason;
45
+ newItems.push(newItem);
46
+ subtotal += itemSubtotal;
47
+ }
48
+ categories.push({ ...category, items: newItems });
49
+ }
50
+ let grand_total = subtotal;
51
+ let gst_amount = 0;
52
+ const gst = data.gst ?? 0;
53
+ if (data.is_gst_inclusive) {
54
+ gst_amount = (0, utils_1.parseFloatCeil)((grand_total * gst) / (100 + gst));
55
+ }
56
+ else {
57
+ gst_amount = (0, utils_1.getPercentageAmount)(grand_total, gst);
58
+ grand_total += gst_amount;
59
+ }
60
+ grand_total = (0, utils_1.parseNum)(grand_total);
61
+ const amount_earned = (0, utils_1.parseNum)(grand_total);
62
+ if (calculateItemMetadata) {
63
+ let leftGrossAmount = subtotal;
64
+ let leftNetAmount = subtotal;
65
+ let leftDiscountAmount = 0;
66
+ let leftGstAmount = gst_amount;
67
+ categories.forEach((category, categoryIndex) => {
68
+ const isLastCategory = categoryIndex === categories.length - 1;
69
+ category.items.forEach((item, itemIndex) => {
70
+ const isLastItem = isLastCategory && itemIndex === category.items.length - 1;
71
+ let grossAmount = item.subtotal;
72
+ let netAmount = item.subtotal;
73
+ let itemTotalDiscountAmount = 0;
74
+ let itemGst = 0;
75
+ if (gst_amount > 0) {
76
+ itemGst = (item.subtotal / subtotal) * gst_amount;
77
+ }
78
+ grossAmount = (0, utils_1.parseFloatCeil)(grossAmount);
79
+ const netAmountParsed = (0, utils_1.parseFloatCeil)(netAmount);
80
+ const itemTotalDiscountAmountParsed = (0, utils_1.parseFloatCeil)(itemTotalDiscountAmount);
81
+ itemGst = (0, utils_1.parseFloatCeil)(itemGst);
82
+ leftGrossAmount -= grossAmount;
83
+ leftNetAmount -= netAmountParsed;
84
+ leftDiscountAmount -= itemTotalDiscountAmountParsed;
85
+ leftGstAmount -= itemGst;
86
+ if (isLastItem) {
87
+ grossAmount += leftGrossAmount;
88
+ netAmount += leftNetAmount;
89
+ itemTotalDiscountAmount += leftDiscountAmount;
90
+ itemGst += leftGstAmount;
91
+ }
92
+ item._gross_amount = Math.max(grossAmount, 0);
93
+ item._net_amount = Math.max(netAmount, 0);
94
+ item._discount_amount = Math.max(itemTotalDiscountAmount, 0);
95
+ item._gst_amount = Math.max(itemGst, 0);
96
+ });
97
+ });
98
+ }
99
+ return {
100
+ ...data,
101
+ categories,
102
+ amount_earned,
103
+ gst_amount,
104
+ price: (0, utils_1.parseNum)(subtotal),
105
+ grand_total,
106
+ };
107
+ }
108
+ // ── Shared ──
109
+ const getUpdatedRfqItem = (item) => ({
110
+ item_id: item.item_id,
111
+ name: item.name,
112
+ price: item.price,
113
+ special_instructions: item.special_instructions,
114
+ });
115
+ // ── Remove ──
116
+ function getRemoveItemFromRfqCartData(data, payload) {
117
+ const orderItemIdsMap = {};
118
+ let categories;
119
+ if (data.categories != null) {
120
+ categories = [];
121
+ for (let i = 0; i < data.categories.length; i++) {
122
+ const category = data.categories[i];
123
+ const items = [];
124
+ for (let j = 0; j < category.items.length; j++) {
125
+ const item = category.items[j];
126
+ if (item._id !== payload._id) {
127
+ items.push(item);
128
+ orderItemIdsMap[item._id] = item.quantity;
129
+ }
130
+ }
131
+ if (items.length > 0) {
132
+ categories.push({ ...category, items });
133
+ }
134
+ }
135
+ }
136
+ const iterations = [];
137
+ if (data.iterations != null && data.iterations.length > 0) {
138
+ const [firstIteration, ...restIterations] = data.iterations;
139
+ const firstIterationCategories = [];
140
+ for (let i = 0; i < firstIteration.categories.length; i++) {
141
+ const category = firstIteration.categories[i];
142
+ const allPrevItems = [];
143
+ for (let j = 0; j < category.items.length; j++) {
144
+ const prevItem = category.items[j];
145
+ if (prevItem._id === payload._id && payload.void_reason != null) {
146
+ allPrevItems.push({ ...prevItem, void_reason: payload.void_reason });
147
+ }
148
+ else {
149
+ const currentItemQuantity = orderItemIdsMap[prevItem._id];
150
+ const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
151
+ if (isRemovedItem) {
152
+ allPrevItems.push(prevItem);
153
+ }
154
+ else {
155
+ const updatedPrevItem = { ...prevItem };
156
+ delete updatedPrevItem.void_reason;
157
+ allPrevItems.push(updatedPrevItem);
158
+ }
159
+ }
160
+ }
161
+ if (allPrevItems.length > 0) {
162
+ firstIterationCategories.push({ ...category, items: allPrevItems });
163
+ }
164
+ }
165
+ iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
166
+ }
167
+ return calculateCartRfqOrderInfoAndSyncData({
168
+ ...data,
169
+ ...(iterations.length > 0 && { iterations }),
170
+ categories,
171
+ });
172
+ }
173
+ // ── Update Info ──
174
+ function getUpdateRfqCartInfoData(data, payload) {
175
+ return calculateCartRfqOrderInfoAndSyncData({ ...data, ...payload });
176
+ }
177
+ function getAddItemToRfqCartData(data, payload) {
178
+ const { category_id, name, item, replace_id } = payload;
179
+ let mainItemId = item._id;
180
+ const orderData = { ...data };
181
+ const categories = [...(orderData.categories ?? [])];
182
+ let didFindCategory = false;
183
+ for (let i = 0; i < categories.length; i++) {
184
+ const category = categories[i];
185
+ if (category.category_id !== category_id)
186
+ continue;
187
+ const updatedItem = getUpdatedRfqItem(item);
188
+ const allItems = [...category.items];
189
+ let didFindItem = false;
190
+ let itemExists = false;
191
+ for (let j = 0; j < allItems.length; j++) {
192
+ const itm = allItems[j];
193
+ if (itm._id === item._id) {
194
+ allItems[j] = item;
195
+ didFindItem = true;
196
+ break;
197
+ }
198
+ if (itm.item_id === item.item_id) {
199
+ itemExists = true;
200
+ }
201
+ }
202
+ if (!didFindItem && itemExists) {
203
+ for (let j = 0; j < allItems.length; j++) {
204
+ const itm = allItems[j];
205
+ if (itm.item_id === item.item_id && (0, lodash_1.isEqual)(getUpdatedRfqItem(itm), updatedItem)) {
206
+ mainItemId = replace_id ?? itm._id;
207
+ allItems[j] = {
208
+ ...item,
209
+ _id: mainItemId,
210
+ quantity: item.quantity + itm.quantity,
211
+ };
212
+ didFindItem = true;
213
+ break;
214
+ }
215
+ }
216
+ }
217
+ if (!didFindItem) {
218
+ allItems.push(item);
219
+ }
220
+ categories[i] = { ...category, items: allItems };
221
+ didFindCategory = true;
222
+ break;
223
+ }
224
+ if (!didFindCategory) {
225
+ categories.push({ category_id, name, items: [item] });
226
+ }
227
+ const iterations = [];
228
+ if (orderData.iterations != null && orderData.iterations.length > 0) {
229
+ const orderItemIdsMap = {};
230
+ for (let i = 0; i < categories.length; i++) {
231
+ for (let j = 0; j < categories[i].items.length; j++) {
232
+ orderItemIdsMap[categories[i].items[j]._id] = categories[i].items[j].quantity;
233
+ }
234
+ }
235
+ const [firstIteration, ...restIterations] = orderData.iterations;
236
+ const firstIterationCategories = [];
237
+ for (let i = 0; i < firstIteration.categories.length; i++) {
238
+ const category = firstIteration.categories[i];
239
+ const allPrevItems = [];
240
+ for (let j = 0; j < category.items.length; j++) {
241
+ const prevItem = category.items[j];
242
+ const currentItemQuantity = orderItemIdsMap[prevItem._id];
243
+ const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
244
+ if (isRemovedItem) {
245
+ allPrevItems.push(prevItem);
246
+ }
247
+ else {
248
+ const updatedPrevItem = { ...prevItem };
249
+ delete updatedPrevItem.void_reason;
250
+ allPrevItems.push(updatedPrevItem);
251
+ }
252
+ }
253
+ if (allPrevItems.length > 0) {
254
+ firstIterationCategories.push({ ...category, items: allPrevItems });
255
+ }
256
+ }
257
+ iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
258
+ }
259
+ return calculateCartRfqOrderInfoAndSyncData({
260
+ ...orderData,
261
+ ...(iterations.length > 0 && { iterations }),
262
+ categories,
263
+ });
264
+ }
265
+ // ── Update Item ──
266
+ function getUpdateItemInRfqCartData(data, payload) {
267
+ const orderItemIdsMap = {};
268
+ let categories;
269
+ if (data.categories != null) {
270
+ categories = [];
271
+ for (let i = 0; i < data.categories.length; i++) {
272
+ const category = data.categories[i];
273
+ const items = [];
274
+ for (let j = 0; j < category.items.length; j++) {
275
+ const item = category.items[j];
276
+ let newItem = item;
277
+ if (item._id === payload._id) {
278
+ newItem = { ...item, ...payload };
279
+ }
280
+ if (newItem.quantity > 0) {
281
+ items.push(newItem);
282
+ orderItemIdsMap[newItem._id] = newItem.quantity;
283
+ }
284
+ }
285
+ if (items.length > 0) {
286
+ categories.push({ ...category, items });
287
+ }
288
+ }
289
+ }
290
+ const iterations = [];
291
+ if (payload.quantity != null && data.iterations != null && data.iterations.length > 0) {
292
+ const [firstIteration, ...restIterations] = data.iterations;
293
+ const firstIterationCategories = [];
294
+ for (let i = 0; i < firstIteration.categories.length; i++) {
295
+ const category = firstIteration.categories[i];
296
+ const allPrevItems = [];
297
+ for (let j = 0; j < category.items.length; j++) {
298
+ const prevItem = category.items[j];
299
+ if (prevItem._id === payload._id && payload.void_reason != null) {
300
+ allPrevItems.push({ ...prevItem, void_reason: payload.void_reason });
301
+ }
302
+ else {
303
+ const currentItemQuantity = orderItemIdsMap[prevItem._id];
304
+ const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
305
+ if (isRemovedItem) {
306
+ allPrevItems.push(prevItem);
307
+ }
308
+ else {
309
+ const updatedPrevItem = { ...prevItem };
310
+ delete updatedPrevItem.void_reason;
311
+ allPrevItems.push(updatedPrevItem);
312
+ }
313
+ }
314
+ }
315
+ if (allPrevItems.length > 0) {
316
+ firstIterationCategories.push({ ...category, items: allPrevItems });
317
+ }
318
+ }
319
+ iterations.push({ ...firstIteration, categories: firstIterationCategories }, ...restIterations);
320
+ }
321
+ return calculateCartRfqOrderInfoAndSyncData({
322
+ ...data,
323
+ ...(iterations.length > 0 && { iterations }),
324
+ categories,
325
+ });
326
+ }
327
+ // ── Update Items (batch) ──
328
+ function getUpdateItemsInRfqCartData(data, payload) {
329
+ return payload.reduce((acc, item) => getUpdateItemInRfqCartData(acc, item), data);
330
+ }
331
+ // ── Split Item ──
332
+ function getSplitRfqCartItemToTwo(data, orderItemId) {
333
+ if (data.categories == null)
334
+ return data;
335
+ const newCategories = [];
336
+ for (let i = 0; i < data.categories.length; i++) {
337
+ const category = data.categories[i];
338
+ const newItems = [];
339
+ for (let j = 0; j < category.items.length; j++) {
340
+ const item = { ...category.items[j] };
341
+ if (item._id !== orderItemId) {
342
+ newItems.push(item);
343
+ continue;
344
+ }
345
+ if (item.quantity === 1) {
346
+ newItems.push(item);
347
+ continue;
348
+ }
349
+ const newQuantity = item.quantity - 1;
350
+ newItems.push({
351
+ ...item,
352
+ quantity: newQuantity,
353
+ subtotal: (0, utils_1.parseNum)(item.price * newQuantity),
354
+ });
355
+ const newId = new bson_objectid_1.default(Math.floor(new bson_objectid_1.default(item._id).getTimestamp().getTime() / 1000) + 1).toHexString();
356
+ newItems.push({
357
+ ...item,
358
+ _id: newId,
359
+ quantity: 1,
360
+ subtotal: (0, utils_1.parseNum)(item.price * 1),
361
+ });
362
+ }
363
+ newCategories.push({ ...category, items: newItems });
364
+ }
365
+ return calculateCartRfqOrderInfoAndSyncData({
366
+ ...data,
367
+ categories: newCategories,
368
+ });
369
+ }
370
+ // ── Add Items (batch) ──
371
+ function getAddItemsToRfqCartData(data, payload) {
372
+ return payload.reduce((acc, item) => getAddItemToRfqCartData(acc, item), data);
373
+ }
@@ -0,0 +1,80 @@
1
+ import { Schema } from 'mongoose';
2
+ export declare const AppliedOrderDiscountsSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
3
+ timestamps: true;
4
+ versionKey: false;
5
+ minimize: false;
6
+ }, {
7
+ createdAt: NativeDate;
8
+ updatedAt: NativeDate;
9
+ } & {
10
+ _id: import("mongoose").Types.ObjectId;
11
+ type: import("../../constants").DISCOUNT_TYPE_ENUM;
12
+ name: string;
13
+ tenant_id: string;
14
+ order_id: import("mongoose").Types.ObjectId;
15
+ discount_id: string;
16
+ applicability: import("../../constants").DISCOUNT_APPLICABILITY_ENUM;
17
+ platform: import("../../constants").PLATFORMS_ENUM;
18
+ order_amount: number;
19
+ discount_amount: number;
20
+ reason: string;
21
+ staff_id: string;
22
+ staff_phone: string;
23
+ staff_name: string;
24
+ createdAt_mins: number;
25
+ createdAt: NativeDate;
26
+ updatedAt: NativeDate;
27
+ discount_rate?: number | null | undefined;
28
+ reference_number?: string | null | undefined;
29
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
30
+ createdAt: NativeDate;
31
+ updatedAt: NativeDate;
32
+ } & {
33
+ _id: import("mongoose").Types.ObjectId;
34
+ type: import("../../constants").DISCOUNT_TYPE_ENUM;
35
+ name: string;
36
+ tenant_id: string;
37
+ order_id: import("mongoose").Types.ObjectId;
38
+ discount_id: string;
39
+ applicability: import("../../constants").DISCOUNT_APPLICABILITY_ENUM;
40
+ platform: import("../../constants").PLATFORMS_ENUM;
41
+ order_amount: number;
42
+ discount_amount: number;
43
+ reason: string;
44
+ staff_id: string;
45
+ staff_phone: string;
46
+ staff_name: string;
47
+ createdAt_mins: number;
48
+ createdAt: NativeDate;
49
+ updatedAt: NativeDate;
50
+ discount_rate?: number | null | undefined;
51
+ reference_number?: string | null | undefined;
52
+ }>> & import("mongoose").FlatRecord<{
53
+ createdAt: NativeDate;
54
+ updatedAt: NativeDate;
55
+ } & {
56
+ _id: import("mongoose").Types.ObjectId;
57
+ type: import("../../constants").DISCOUNT_TYPE_ENUM;
58
+ name: string;
59
+ tenant_id: string;
60
+ order_id: import("mongoose").Types.ObjectId;
61
+ discount_id: string;
62
+ applicability: import("../../constants").DISCOUNT_APPLICABILITY_ENUM;
63
+ platform: import("../../constants").PLATFORMS_ENUM;
64
+ order_amount: number;
65
+ discount_amount: number;
66
+ reason: string;
67
+ staff_id: string;
68
+ staff_phone: string;
69
+ staff_name: string;
70
+ createdAt_mins: number;
71
+ createdAt: NativeDate;
72
+ updatedAt: NativeDate;
73
+ discount_rate?: number | null | undefined;
74
+ reference_number?: string | null | undefined;
75
+ }> & Required<{
76
+ _id: import("mongoose").Types.ObjectId;
77
+ }> & {
78
+ __v: number;
79
+ }>;
80
+ export declare const APPLIED_ORDER_DISCOUNTS_COLLECTION_NAME = "applied_order_discounts";
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APPLIED_ORDER_DISCOUNTS_COLLECTION_NAME = exports.AppliedOrderDiscountsSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const constants_1 = require("../../constants");
6
+ exports.AppliedOrderDiscountsSchema = new mongoose_1.Schema({
7
+ _id: {
8
+ type: mongoose_1.Schema.Types.ObjectId,
9
+ required: true,
10
+ immutable: true,
11
+ },
12
+ tenant_id: {
13
+ type: String,
14
+ required: true,
15
+ immutable: true,
16
+ ref: 'tenants',
17
+ },
18
+ order_id: {
19
+ type: mongoose_1.Schema.Types.ObjectId,
20
+ required: true,
21
+ immutable: true,
22
+ },
23
+ discount_id: {
24
+ type: String,
25
+ required: true,
26
+ },
27
+ type: {
28
+ type: String,
29
+ required: true,
30
+ enum: constants_1.ALL_DISCOUNT_TYPES,
31
+ },
32
+ applicability: {
33
+ type: String,
34
+ required: true,
35
+ enum: constants_1.ALL_DISCOUNT_APPLICABILITY_TYPES,
36
+ },
37
+ platform: {
38
+ type: String,
39
+ enum: constants_1.ALL_PLATFORMS,
40
+ required: true,
41
+ },
42
+ name: {
43
+ type: String,
44
+ required: true,
45
+ },
46
+ order_amount: {
47
+ type: Number,
48
+ required: true,
49
+ min: 0,
50
+ },
51
+ discount_amount: {
52
+ type: Number,
53
+ required: true,
54
+ min: 0,
55
+ },
56
+ discount_rate: {
57
+ type: Number,
58
+ required: false,
59
+ default: null,
60
+ },
61
+ reason: {
62
+ type: String,
63
+ required: true,
64
+ },
65
+ reference_number: {
66
+ type: String,
67
+ required: false,
68
+ },
69
+ staff_id: {
70
+ type: String,
71
+ required: true,
72
+ },
73
+ staff_phone: {
74
+ type: String,
75
+ required: true,
76
+ },
77
+ staff_name: {
78
+ type: String,
79
+ required: true,
80
+ },
81
+ createdAt_mins: {
82
+ type: Number,
83
+ required: true,
84
+ immutable: true,
85
+ default: () => {
86
+ const date = new Date();
87
+ return Math.floor(date.getHours() * 60 + date.getMinutes());
88
+ },
89
+ },
90
+ createdAt: {
91
+ type: mongoose_1.Schema.Types.Date,
92
+ required: true,
93
+ default: () => new Date(),
94
+ immutable: true,
95
+ },
96
+ updatedAt: {
97
+ type: mongoose_1.Schema.Types.Date,
98
+ required: true,
99
+ default: () => new Date(),
100
+ },
101
+ }, {
102
+ timestamps: true,
103
+ versionKey: false,
104
+ minimize: false,
105
+ });
106
+ exports.APPLIED_ORDER_DISCOUNTS_COLLECTION_NAME = 'applied_order_discounts';