@managesome/eposmatic-toolkit 0.2.431 → 0.2.432

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 (170) hide show
  1. package/lib/constants/ENUMS.d.ts +0 -289
  2. package/lib/constants/ENUMS.js +2 -393
  3. package/lib/constants/PURCHASE_ORDER.d.ts +5 -3
  4. package/lib/constants/PURCHASE_ORDER.js +58 -20
  5. package/lib/constants/WAREHOUSE_ANALYTICS.d.ts +41 -41
  6. package/lib/constants/WAREHOUSE_ANALYTICS.js +28 -28
  7. package/lib/constants/WAREHOUSE_ENUMS.d.ts +289 -0
  8. package/lib/constants/WAREHOUSE_ENUMS.js +392 -0
  9. package/lib/constants/WAREHOUSE_INVOICE.js +10 -10
  10. package/lib/constants/index.d.ts +1 -0
  11. package/lib/constants/index.js +1 -0
  12. package/lib/helpers/order/generate-purchase-order-rfq.d.ts +3 -3
  13. package/lib/helpers/order/generate-purchase-order-rfq.js +2 -2
  14. package/lib/helpers/order/generate-purchase-order.d.ts +8 -8
  15. package/lib/helpers/order/generate-purchase-order.js +2 -2
  16. package/lib/helpers/order/generate-warehouse-purchase-order-rfq.d.ts +3 -0
  17. package/lib/helpers/order/generate-warehouse-purchase-order-rfq.js +64 -0
  18. package/lib/helpers/order/generate-warehouse-purchase-order.d.ts +11 -0
  19. package/lib/helpers/order/generate-warehouse-purchase-order.js +196 -0
  20. package/lib/helpers/order/index.d.ts +2 -2
  21. package/lib/helpers/order/index.js +2 -2
  22. package/lib/helpers/store/all-purchase-orders-actions.d.ts +7 -7
  23. package/lib/helpers/store/all-purchase-orders-actions.js +2 -2
  24. package/lib/helpers/store/all-sale-orders-actions.d.ts +2 -2
  25. package/lib/helpers/store/all-warehouse-purchase-orders-actions.d.ts +13 -0
  26. package/lib/helpers/store/all-warehouse-purchase-orders-actions.js +56 -0
  27. package/lib/helpers/store/all-warehouse-sale-orders-actions.d.ts +2 -0
  28. package/lib/helpers/store/all-warehouse-sale-orders-actions.js +8 -0
  29. package/lib/helpers/store/common-purchase-order-actions.d.ts +15 -15
  30. package/lib/helpers/store/common-sale-order-actions.d.ts +5 -5
  31. package/lib/helpers/store/common-warehouse-purchase-order-actions.d.ts +31 -0
  32. package/lib/helpers/store/common-warehouse-purchase-order-actions.js +545 -0
  33. package/lib/helpers/store/common-warehouse-sale-order-actions.d.ts +5 -0
  34. package/lib/helpers/store/common-warehouse-sale-order-actions.js +65 -0
  35. package/lib/helpers/store/index.d.ts +6 -6
  36. package/lib/helpers/store/index.js +6 -6
  37. package/lib/helpers/store/purchase-order-rfq-cart-actions.d.ts +11 -11
  38. package/lib/helpers/store/purchase-order-rfq-cart-actions.js +3 -3
  39. package/lib/helpers/store/purchase-orders-cart-actions.d.ts +18 -18
  40. package/lib/helpers/store/purchase-orders-cart-actions.js +1 -1
  41. package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.d.ts +19 -0
  42. package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +373 -0
  43. package/lib/helpers/store/warehouse-purchase-orders-cart-actions.d.ts +57 -0
  44. package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +486 -0
  45. package/lib/helpers/types/index.d.ts +1 -1
  46. package/lib/helpers/types/index.js +1 -1
  47. package/lib/helpers/types/purchase-order-cart-actions.d.ts +2 -2
  48. package/lib/helpers/types/warehouse-purchase-order-cart-actions.d.ts +26 -0
  49. package/lib/helpers/types/warehouse-purchase-order-cart-actions.js +2 -0
  50. package/lib/helpers/types/workers.d.ts +18 -18
  51. package/lib/helpers/utils/index.d.ts +8 -8
  52. package/lib/helpers/utils/index.js +8 -11
  53. package/lib/helpers/utils/invoice-x-report-helpers.d.ts +2 -2
  54. package/lib/helpers/utils/invoice-x-report-helpers.js +14 -14
  55. package/lib/helpers/utils/purchase-order-engine.d.ts +4 -4
  56. package/lib/helpers/utils/purchase-order-receipt-engine.d.ts +5 -5
  57. package/lib/helpers/utils/purchase-order-receipt-engine.js +2 -2
  58. package/lib/helpers/utils/purchase-order-x-report-helpers.js +2 -2
  59. package/lib/helpers/utils/sale-x-report-helpers.js +2 -2
  60. package/lib/helpers/utils/void-purchase-order-items-helpers.d.ts +3 -3
  61. package/lib/helpers/utils/void-purchase-order-items-report-helpers.d.ts +2 -2
  62. package/lib/helpers/utils/void-warehouse-invoice-items-helpers.d.ts +3 -3
  63. package/lib/helpers/utils/void-warehouse-invoice-items-helpers.js +2 -2
  64. package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.d.ts +5 -5
  65. package/lib/helpers/utils/warehouse-catalog-conversion.d.ts +3 -3
  66. package/lib/helpers/utils/warehouse-catalog-conversion.js +9 -7
  67. package/lib/helpers/utils/warehouse-invoice-order-engine.js +1 -1
  68. package/lib/helpers/utils/warehouse-invoice-x-report-helpers.d.ts +58 -0
  69. package/lib/helpers/utils/warehouse-invoice-x-report-helpers.js +1432 -0
  70. package/lib/helpers/utils/warehouse-purchase-order-engine.d.ts +9 -0
  71. package/lib/helpers/utils/warehouse-purchase-order-engine.js +34 -0
  72. package/lib/helpers/utils/warehouse-purchase-order-receipt-engine.d.ts +149 -0
  73. package/lib/helpers/utils/warehouse-purchase-order-receipt-engine.js +214 -0
  74. package/lib/helpers/utils/warehouse-purchase-order-x-report-helpers.d.ts +58 -0
  75. package/lib/helpers/utils/warehouse-purchase-order-x-report-helpers.js +1440 -0
  76. package/lib/helpers/utils/warehouse-sale-order-x-report-helpers.d.ts +30 -0
  77. package/lib/helpers/utils/warehouse-sale-order-x-report-helpers.js +2 -0
  78. package/lib/helpers/utils/warehouse-sale-x-report-helpers.d.ts +58 -0
  79. package/lib/helpers/utils/warehouse-sale-x-report-helpers.js +1456 -0
  80. package/lib/helpers/utils/warehouse-void-purchase-order-items-helpers.d.ts +3 -0
  81. package/lib/helpers/utils/warehouse-void-purchase-order-items-helpers.js +38 -0
  82. package/lib/helpers/utils/warehouse-void-purchase-order-items-report-helpers.d.ts +13 -0
  83. package/lib/helpers/utils/warehouse-void-purchase-order-items-report-helpers.js +22 -0
  84. package/lib/schemas/models/gift_cards.d.ts +108 -108
  85. package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
  86. package/lib/schemas/models/index.d.ts +7 -7
  87. package/lib/schemas/models/index.js +7 -7
  88. package/lib/schemas/models/internal_invoices.d.ts +6 -6
  89. package/lib/schemas/models/inventory_lot_serial_numbers.d.ts +6 -6
  90. package/lib/schemas/models/inventory_transactions.d.ts +3 -3
  91. package/lib/schemas/models/item_transactions.d.ts +6 -6
  92. package/lib/schemas/models/offers.d.ts +146 -146
  93. package/lib/schemas/models/orders.d.ts +2573 -2573
  94. package/lib/schemas/models/printer_settings.d.ts +12 -12
  95. package/lib/schemas/models/reservations.d.ts +6 -6
  96. package/lib/schemas/models/rewards_usage.d.ts +6 -6
  97. package/lib/schemas/models/riders.d.ts +3 -3
  98. package/lib/schemas/models/tenants.d.ts +135 -135
  99. package/lib/schemas/models/void_order_items.d.ts +15 -15
  100. package/lib/schemas/models/void_warehouse_invoice_items.d.ts +25 -25
  101. package/lib/schemas/models/void_warehouse_invoice_items.js +2 -2
  102. package/lib/schemas/models/vouchers.d.ts +9 -9
  103. package/lib/schemas/models/warehouse-activity-logs.d.ts +13 -13
  104. package/lib/schemas/models/warehouse-activity-logs.js +4 -4
  105. package/lib/schemas/models/warehouse_categories.d.ts +4 -4
  106. package/lib/schemas/models/warehouse_categories.js +2 -2
  107. package/lib/schemas/models/warehouse_communications.d.ts +21 -21
  108. package/lib/schemas/models/warehouse_internal_movements.d.ts +33 -33
  109. package/lib/schemas/models/warehouse_internal_movements.js +8 -8
  110. package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.d.ts +154 -0
  111. package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.js +193 -0
  112. package/lib/schemas/models/warehouse_inventory_transactions.d.ts +6 -6
  113. package/lib/schemas/models/warehouse_invoices.d.ts +351 -351
  114. package/lib/schemas/models/warehouse_item_transactions.d.ts +9 -9
  115. package/lib/schemas/models/warehouse_items.d.ts +13 -13
  116. package/lib/schemas/models/warehouse_items.js +2 -2
  117. package/lib/schemas/models/warehouse_operational_roles.d.ts +3 -3
  118. package/lib/schemas/models/warehouse_purchase_order_receipts.d.ts +165 -0
  119. package/lib/schemas/models/warehouse_purchase_order_receipts.js +151 -0
  120. package/lib/schemas/models/warehouse_purchase_order_rfqs.d.ts +1959 -0
  121. package/lib/schemas/models/warehouse_purchase_order_rfqs.js +328 -0
  122. package/lib/schemas/models/warehouse_purchase_order_vendor_returns.d.ts +234 -0
  123. package/lib/schemas/models/warehouse_purchase_order_vendor_returns.js +188 -0
  124. package/lib/schemas/models/warehouse_purchase_orders.d.ts +2678 -0
  125. package/lib/schemas/models/warehouse_purchase_orders.js +336 -0
  126. package/lib/schemas/models/warehouse_sale_deliveries.d.ts +15 -15
  127. package/lib/schemas/models/warehouse_sale_deliveries.js +7 -4
  128. package/lib/schemas/models/warehouse_sale_invoices.d.ts +30 -30
  129. package/lib/schemas/models/warehouse_sale_invoices.js +8 -5
  130. package/lib/schemas/models/warehouse_sale_order_rfqs.d.ts +362 -362
  131. package/lib/schemas/models/warehouse_sale_order_rfqs.js +5 -5
  132. package/lib/schemas/models/warehouse_sale_orders.d.ts +367 -367
  133. package/lib/schemas/models/warehouse_sale_orders.js +5 -5
  134. package/lib/schemas/models/warehouse_void_invoice_items.d.ts +176 -0
  135. package/lib/schemas/models/warehouse_void_invoice_items.js +176 -0
  136. package/lib/schemas/models/warehouse_void_purchase_order_items.d.ts +176 -0
  137. package/lib/schemas/models/warehouse_void_purchase_order_items.js +177 -0
  138. package/lib/schemas/models/warehouses.d.ts +52 -52
  139. package/lib/schemas/models/warehouses.js +2 -2
  140. package/lib/schemas/types/index.d.ts +9 -9
  141. package/lib/schemas/types/index.js +9 -9
  142. package/lib/schemas/types/inventory_lot_serial_numbers.d.ts +5 -5
  143. package/lib/schemas/types/warehouse-activity-logs.d.ts +7 -7
  144. package/lib/schemas/types/warehouse_categories.d.ts +2 -2
  145. package/lib/schemas/types/warehouse_internal_movements.d.ts +9 -9
  146. package/lib/schemas/types/warehouse_inventory_lot_serial_numbers.d.ts +85 -0
  147. package/lib/schemas/types/warehouse_inventory_lot_serial_numbers.js +4 -0
  148. package/lib/schemas/types/warehouse_items.d.ts +2 -2
  149. package/lib/schemas/types/warehouse_purchase_order_common.d.ts +39 -0
  150. package/lib/schemas/types/warehouse_purchase_order_common.js +2 -0
  151. package/lib/schemas/types/warehouse_purchase_order_receipts.d.ts +39 -0
  152. package/lib/schemas/types/warehouse_purchase_order_receipts.js +21 -0
  153. package/lib/schemas/types/warehouse_purchase_order_rfqs.d.ts +33 -0
  154. package/lib/schemas/types/warehouse_purchase_order_rfqs.js +2 -0
  155. package/lib/schemas/types/warehouse_purchase_order_vendor_returns.d.ts +48 -0
  156. package/lib/schemas/types/warehouse_purchase_order_vendor_returns.js +2 -0
  157. package/lib/schemas/types/warehouse_purchase_orders.d.ts +33 -0
  158. package/lib/schemas/types/warehouse_purchase_orders.js +2 -0
  159. package/lib/schemas/types/warehouse_sale_deliveries.d.ts +29 -29
  160. package/lib/schemas/types/warehouse_sale_invoices.d.ts +17 -17
  161. package/lib/schemas/types/warehouse_sale_order_common.d.ts +39 -0
  162. package/lib/schemas/types/warehouse_sale_order_common.js +2 -0
  163. package/lib/schemas/types/warehouse_sale_order_rfqs.d.ts +7 -7
  164. package/lib/schemas/types/warehouse_sale_orders.d.ts +7 -7
  165. package/lib/schemas/types/warehouse_void_invoice_items.d.ts +37 -0
  166. package/lib/schemas/types/warehouse_void_invoice_items.js +2 -0
  167. package/lib/schemas/types/warehouse_void_purchase_order_items.d.ts +37 -0
  168. package/lib/schemas/types/warehouse_void_purchase_order_items.js +2 -0
  169. package/lib/schemas/types/warehouses.d.ts +2 -2
  170. package/package.json +1 -1
@@ -0,0 +1,545 @@
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.getWarehousePurchaseOrderIterationsWithPrice = getWarehousePurchaseOrderIterationsWithPrice;
7
+ exports.getWarehousePurchaseOrderPaymentsWithPrice = getWarehousePurchaseOrderPaymentsWithPrice;
8
+ exports.getWarehousePurchaseOrderItemsWithPrice = getWarehousePurchaseOrderItemsWithPrice;
9
+ exports.getWarehousePurchaseOrderCategoriesWithPrice = getWarehousePurchaseOrderCategoriesWithPrice;
10
+ exports.getWarehousePurchaseOrderWithPrice = getWarehousePurchaseOrderWithPrice;
11
+ exports.syncWarehousePurchaseOrderData = syncWarehousePurchaseOrderData;
12
+ exports.skipItemMetadataFromWarehousePurchaseOrderCategories = skipItemMetadataFromWarehousePurchaseOrderCategories;
13
+ exports.getWarehousePurchaseOrderWithAllFields = getWarehousePurchaseOrderWithAllFields;
14
+ exports.getWarehousePurchaseOrderCartItemsObj = getWarehousePurchaseOrderCartItemsObj;
15
+ exports.getVoidItemsWithReasonWarehousePurchaseOrder = getVoidItemsWithReasonWarehousePurchaseOrder;
16
+ const bson_objectid_1 = __importDefault(require("bson-objectid"));
17
+ const lodash_1 = require("lodash");
18
+ const constants_1 = require("../../constants");
19
+ const utils_1 = require("../utils");
20
+ const common_order_actions_1 = require("./common-order-actions");
21
+ const warehouse_purchase_orders_cart_actions_1 = require("./warehouse-purchase-orders-cart-actions");
22
+ function getWarehousePurchaseOrderIterationsWithPrice(iterations, writeable) {
23
+ if (!iterations)
24
+ return [];
25
+ return iterations.map((iteration) => getWarehousePurchaseOrderWithPrice(iteration, writeable));
26
+ }
27
+ function getWarehousePurchaseOrderPaymentsWithPrice(payments, convertToPrice) {
28
+ if (!payments)
29
+ return [];
30
+ return payments.map((payment) => ({
31
+ ...payment,
32
+ card_details: (0, common_order_actions_1.getOrderPaymentsCardDetailsWithPrice)(payment.card_details, convertToPrice),
33
+ amount_paid: convertToPrice(payment.amount_paid),
34
+ amount_due: convertToPrice(payment.amount_due),
35
+ amount_refunded: convertToPrice(payment.amount_refunded),
36
+ }));
37
+ }
38
+ function getWarehousePurchaseOrderItemsWithPrice(items, convertToPrice) {
39
+ if (!items)
40
+ return [];
41
+ return items.map((item) => ({
42
+ ...item,
43
+ quantity: (0, utils_1.parseNum)(item.quantity || 1, true),
44
+ price: convertToPrice(item.price ?? 0),
45
+ subtotal: convertToPrice(item.subtotal ?? 0),
46
+ _gst_amount: convertToPrice(item._gst_amount ?? 0),
47
+ _net_amount: convertToPrice(item._net_amount ?? 0),
48
+ _gross_amount: convertToPrice(item._gross_amount ?? 0),
49
+ _discount_amount: convertToPrice(item._discount_amount ?? 0),
50
+ }));
51
+ }
52
+ function getWarehousePurchaseOrderCategoriesWithPrice(categories, convertToPrice) {
53
+ if (!categories)
54
+ return [];
55
+ return categories.map((category) => ({
56
+ ...category,
57
+ items: getWarehousePurchaseOrderItemsWithPrice(category.items, convertToPrice),
58
+ }));
59
+ }
60
+ function getWarehousePurchaseOrderWithPrice(order, writeable) {
61
+ const convertToPrice = writeable ? utils_1.convertDecimalToInt : utils_1.convertIntToDecimal;
62
+ const payload = {
63
+ ...order,
64
+ ...(order.iterations != null
65
+ ? {
66
+ iterations: getWarehousePurchaseOrderIterationsWithPrice(order.iterations, writeable),
67
+ }
68
+ : {}),
69
+ ...(order.categories != null
70
+ ? {
71
+ categories: getWarehousePurchaseOrderCategoriesWithPrice(order.categories, convertToPrice),
72
+ }
73
+ : {}),
74
+ ...(order.payments != null
75
+ ? { payments: getWarehousePurchaseOrderPaymentsWithPrice(order.payments, convertToPrice) }
76
+ : {}),
77
+ ...(order.gst != null ? { gst: convertToPrice(order.gst) } : {}),
78
+ ...(order.gst_amount != null ? { gst_amount: convertToPrice(order.gst_amount) } : {}),
79
+ ...(order.amount_collected != null
80
+ ? { amount_collected: convertToPrice(order.amount_collected) }
81
+ : {}),
82
+ ...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
83
+ ...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
84
+ ...(order.price != null ? { price: convertToPrice(order.price) } : {}),
85
+ };
86
+ return payload;
87
+ }
88
+ function syncWarehousePurchaseOrderData(order) {
89
+ const updatedOrder = {
90
+ ...order,
91
+ iterations: [],
92
+ };
93
+ const newOrder = getWarehousePurchaseOrderWithPrice((0, warehouse_purchase_orders_cart_actions_1.calculateCartWarehousePurchaseOrderInfoAndSyncData)(getWarehousePurchaseOrderWithPrice(updatedOrder), true), true);
94
+ newOrder.iterations = order.iterations;
95
+ return newOrder;
96
+ }
97
+ function skipItemMetadataFromWarehousePurchaseOrderCategories(categories, previousCategories) {
98
+ return categories.map((category) => {
99
+ const previousCategory = previousCategories?.find((prevCategory) => prevCategory.category_id === category.category_id);
100
+ return {
101
+ ...category,
102
+ items: category.items.map((item) => {
103
+ const previousItem = previousCategory?.items.find((prevItem) => prevItem._id === item._id);
104
+ const void_reason = previousItem?.void_reason ?? item.void_reason;
105
+ const newItem = {
106
+ ...item,
107
+ void_reason,
108
+ _discount_amount: 0,
109
+ _gst_amount: 0,
110
+ _gross_amount: 0,
111
+ _net_amount: 0,
112
+ };
113
+ return newItem;
114
+ }),
115
+ };
116
+ });
117
+ }
118
+ function getCommonOptionalBoolFieldsPurchaseOrder(order, partial) {
119
+ const defaultValue = partial ? undefined : false;
120
+ return {
121
+ is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
122
+ is_reopened: order['is_reopened'] || defaultValue,
123
+ };
124
+ }
125
+ function getCommonOptionalNumFieldsPurchaseOrder(order, partial) {
126
+ const defaultValue = partial ? undefined : 0;
127
+ return {
128
+ gst: order['gst'] || defaultValue,
129
+ gst_amount: order['gst_amount'] || defaultValue,
130
+ };
131
+ }
132
+ function getWarehousePurchaseOrderWithAllFields(order, skipItemMetadata) {
133
+ return {
134
+ ...order,
135
+ ...getCommonOptionalBoolFieldsPurchaseOrder(order, false),
136
+ ...getCommonOptionalNumFieldsPurchaseOrder(order, false),
137
+ ...(skipItemMetadata && order.categories != null
138
+ ? {
139
+ categories: skipItemMetadataFromWarehousePurchaseOrderCategories(order.categories),
140
+ }
141
+ : {}),
142
+ delete_reason: order['delete_reason'] ?? null,
143
+ cancel_reason: order['cancel_reason'] ?? null,
144
+ };
145
+ }
146
+ function getWarehousePurchaseOrderCartItemsObj({ 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)((0, warehouse_purchase_orders_cart_actions_1.getWarehousePurchaseOrderItemComaparableData)(currentItem), (0, warehouse_purchase_orders_cart_actions_1.getWarehousePurchaseOrderItemComaparableData)(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
+ // price: number;
323
+ // subtotal: number;
324
+ // tax_rate: number;
325
+ // quantity: number;
326
+ special_instructions: currentItem.special_instructions,
327
+ };
328
+ const prev = {
329
+ _id: prevItem._id,
330
+ item_id: prevItem.item_id,
331
+ name: prevItem.name,
332
+ // price: number;
333
+ // subtotal: number;
334
+ // tax_rate: number;
335
+ // quantity: number;
336
+ special_instructions: prevItem.special_instructions,
337
+ };
338
+ const isBothEqual = (0, lodash_1.isEqual)(curr, prev);
339
+ if (isBothEqual) {
340
+ unChangedItems.push(currentItem);
341
+ }
342
+ else {
343
+ // For edited item, we don't need to have tempUnchangedItemIds
344
+ // because it's the turn for edited item
345
+ editedItems.push(currentItem);
346
+ }
347
+ }
348
+ }
349
+ }
350
+ // Step 4: Get the items that are present in the current iteration
351
+ // but not present in the previous iteration
352
+ for (let i = 0; i < currentItems.length; i++) {
353
+ const item = currentItems[i];
354
+ if (prevItemsMap[item._id] == null) {
355
+ newItems.push(item);
356
+ }
357
+ }
358
+ // Lastly, we need to check if any same item has been removed and added
359
+ // If so, the we need to remove the item from removedItems and newItems, and add it to unChangedItems
360
+ if (removedItems.length > 0 && newItems.length > 0) {
361
+ const newItemsMap = newItems.reduce((acc, item) => {
362
+ acc[item.item_id] = [...(acc[item.item_id] ?? []), item];
363
+ return acc;
364
+ }, {});
365
+ const revertedRemovedItems = [];
366
+ const revertedNewItems = [];
367
+ const additionalNewItems = [];
368
+ for (let i = 0; i < removedItems.length; i++) {
369
+ const removedItem = removedItems[i];
370
+ // Need to check if the removed item is present in the newItems
371
+ const newItemsForItem = newItemsMap[removedItem.item_id];
372
+ if (newItemsForItem == null)
373
+ continue;
374
+ if (newItemsForItem.length > 0) {
375
+ const newItemsForItemLength = newItemsForItem.length;
376
+ for (let j = 0; j < newItemsForItemLength; j++) {
377
+ const newItem = newItemsForItem[j];
378
+ const newI = {
379
+ // _id: newItem._id,
380
+ item_id: newItem.item_id,
381
+ name: newItem.name,
382
+ price: newItem.price,
383
+ // subtotal: number;
384
+ // quantity: newItem.quantity,
385
+ special_instructions: newItem.special_instructions,
386
+ };
387
+ const removedI = {
388
+ // _id: removedItem._id,
389
+ item_id: removedItem.item_id,
390
+ name: removedItem.name,
391
+ price: removedItem.price,
392
+ // subtotal: number;
393
+ // quantity: removedItem.quantity,
394
+ special_instructions: removedItem.special_instructions,
395
+ };
396
+ if ((0, lodash_1.isEqual)(newI, removedI)) {
397
+ if (newItem.quantity === removedItem.quantity) {
398
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
399
+ if (newItemsMap[removedItem.item_id].length === 0) {
400
+ delete newItemsMap[removedItem.item_id];
401
+ }
402
+ revertedNewItems.push(newItem);
403
+ revertedRemovedItems.push(removedItem);
404
+ // We will break the loop when ever we push to revertedRemovedItems
405
+ break;
406
+ }
407
+ else {
408
+ if (removedItem.quantity > newItem.quantity) {
409
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
410
+ if (newItemsMap[removedItem.item_id].length === 0) {
411
+ delete newItemsMap[removedItem.item_id];
412
+ }
413
+ revertedNewItems.push(newItem);
414
+ const subtotalForSingle = removedItem.subtotal / removedItem.quantity;
415
+ // We will only minus the quantity from removedItem
416
+ const newQuantity = removedItem.quantity - newItem.quantity;
417
+ const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
418
+ removedItem.quantity = newQuantity;
419
+ removedItem.subtotal = newSubtotal;
420
+ }
421
+ else {
422
+ revertedRemovedItems.push(removedItem);
423
+ const nQuantity = newItem.quantity;
424
+ const subtotalForSingle = newItem.subtotal / nQuantity;
425
+ const newQuantity = nQuantity - removedItem.quantity;
426
+ const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
427
+ newItem.quantity = newQuantity;
428
+ newItem.subtotal = newSubtotal;
429
+ // =====================><=====================
430
+ const remainingQuantity = nQuantity - newQuantity;
431
+ const adItem = {
432
+ ...newItem,
433
+ quantity: remainingQuantity,
434
+ subtotal: (0, utils_1.parseNum)(remainingQuantity * subtotalForSingle),
435
+ };
436
+ additionalNewItems.push(adItem);
437
+ // We will break the loop when ever we push to revertedRemovedItems
438
+ break;
439
+ }
440
+ }
441
+ }
442
+ }
443
+ }
444
+ else {
445
+ delete newItemsMap[removedItem.item_id];
446
+ }
447
+ }
448
+ for (let i = 0; i < revertedRemovedItems.length; i++) {
449
+ const rItem = revertedRemovedItems[i];
450
+ removedItems = removedItems.filter((item) => item._id !== rItem._id);
451
+ }
452
+ for (let i = 0; i < revertedNewItems.length; i++) {
453
+ const nItem = revertedNewItems[i];
454
+ newItems = newItems.filter((item) => item._id !== nItem._id);
455
+ unChangedItems.push(nItem);
456
+ }
457
+ for (let i = 0; i < additionalNewItems.length; i++) {
458
+ const aItem = additionalNewItems[i];
459
+ unChangedItems.push(aItem);
460
+ }
461
+ }
462
+ disabledReason =
463
+ unChangedItems.length === prevItems.length &&
464
+ newItems.length === 0 &&
465
+ removedItems.length === 0 &&
466
+ editedItems.length === 0
467
+ ? 'No changes in the order'
468
+ : prevItems.length === removedItems.length - totalTempRemovedItems &&
469
+ editedItems.length === 0 &&
470
+ newItems.length === 0
471
+ ? 'At least one item is required'
472
+ : '';
473
+ }
474
+ const cartItemsObj = {
475
+ unChangedItems: getCartItems(unChangedItems),
476
+ editedItems: getCartItems(editedItems),
477
+ removedItems: getCartItems(removedItems),
478
+ newItems: getCartItems(newItems),
479
+ totalSelectedItems: (0, utils_1.parseNum)(totalItemsInCart, true),
480
+ disabledReason,
481
+ isAnUpdate,
482
+ };
483
+ return cartItemsObj;
484
+ }
485
+ function getVoidItemsWithReasonWarehousePurchaseOrder({ currentCategories, iterationsFromFrontend, previousCategories, }) {
486
+ const voidOrderItemReasonsMap = {};
487
+ const latestIterationCategories = iterationsFromFrontend?.[0]?.categories;
488
+ if (latestIterationCategories != null && latestIterationCategories.length > 0) {
489
+ for (let i = 0; i < latestIterationCategories.length; i++) {
490
+ const category = latestIterationCategories[i];
491
+ for (let j = 0; j < category.items.length; j++) {
492
+ const item = category.items[j];
493
+ if (item.void_reason != null && item.void_reason.length > 0) {
494
+ voidOrderItemReasonsMap[item._id] = item.void_reason;
495
+ }
496
+ }
497
+ }
498
+ }
499
+ const { newItems, removedItems } = getWarehousePurchaseOrderCartItemsObj({
500
+ currentIterationCategories: currentCategories,
501
+ previousIterationCategories: previousCategories,
502
+ mappedItems: {},
503
+ shouldSortItemsViaId: false,
504
+ isAnEdit: true,
505
+ });
506
+ const hasNewItems = newItems.length > 0;
507
+ const voidOrderItems = [];
508
+ const newVoidOrderItemReasonsMap = {};
509
+ for (let i = 0; i < removedItems.length; i++) {
510
+ const { orderItem } = removedItems[i];
511
+ const voidReason = voidOrderItemReasonsMap[orderItem._id];
512
+ voidOrderItems.push({
513
+ ...orderItem,
514
+ subtotal: Math.round(orderItem.subtotal),
515
+ void_reason: voidReason ?? '-',
516
+ });
517
+ if (voidReason != null) {
518
+ newVoidOrderItemReasonsMap[orderItem._id] = voidReason;
519
+ }
520
+ }
521
+ const newIterationCategories = [];
522
+ for (let i = 0; i < previousCategories.length; i++) {
523
+ const category = previousCategories[i];
524
+ const newCategoryItems = [];
525
+ for (let j = 0; j < category.items.length; j++) {
526
+ const prevItem = category.items[j];
527
+ const voidReason = newVoidOrderItemReasonsMap[prevItem._id];
528
+ const orderItem = {
529
+ ...prevItem,
530
+ subtotal: Math.round(prevItem.subtotal),
531
+ };
532
+ if (voidReason != null) {
533
+ orderItem.void_reason = voidReason;
534
+ }
535
+ newCategoryItems.push(orderItem);
536
+ }
537
+ if (newCategoryItems.length === 0)
538
+ continue;
539
+ newIterationCategories.push({
540
+ ...category,
541
+ items: newCategoryItems,
542
+ });
543
+ }
544
+ return { newIterationCategories, voidOrderItems, hasNewItems };
545
+ }
@@ -0,0 +1,5 @@
1
+ import { IWarehouseSaleOrder, IWarehouseSaleOrderCategory, IWarehouseSaleOrderItem, IWarehouseSaleOrderIteration } from '../../schemas';
2
+ export declare function getWarehouseSaleOrderIterationsWithPrice(iterations?: IWarehouseSaleOrderIteration[] | undefined, writeable?: boolean): IWarehouseSaleOrderIteration[];
3
+ export declare function getWarehouseSaleOrderItemsWithPrice(items: IWarehouseSaleOrderItem[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderItem[];
4
+ export declare function getWarehouseSaleOrderCategoriesWithPrice(categories: IWarehouseSaleOrderCategory[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderCategory[];
5
+ export declare function getWarehouseSaleOrderWithPrice<T extends Partial<IWarehouseSaleOrder> | IWarehouseSaleOrder | IWarehouseSaleOrderIteration>(order: T, writeable?: boolean): T;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWarehouseSaleOrderIterationsWithPrice = getWarehouseSaleOrderIterationsWithPrice;
4
+ exports.getWarehouseSaleOrderItemsWithPrice = getWarehouseSaleOrderItemsWithPrice;
5
+ exports.getWarehouseSaleOrderCategoriesWithPrice = getWarehouseSaleOrderCategoriesWithPrice;
6
+ exports.getWarehouseSaleOrderWithPrice = getWarehouseSaleOrderWithPrice;
7
+ const utils_1 = require("../utils");
8
+ // ── Iterations ──────────────────────────────────────────────────
9
+ function getWarehouseSaleOrderIterationsWithPrice(iterations, writeable) {
10
+ if (!iterations)
11
+ return [];
12
+ return iterations.map((iteration) => getWarehouseSaleOrderWithPrice(iteration, writeable));
13
+ }
14
+ // ── Items ───────────────────────────────────────────────────────
15
+ function getWarehouseSaleOrderItemsWithPrice(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 getWarehouseSaleOrderCategoriesWithPrice(categories, convertToPrice) {
31
+ if (!categories)
32
+ return [];
33
+ return categories.map((category) => ({
34
+ ...category,
35
+ items: getWarehouseSaleOrderItemsWithPrice(category.items, convertToPrice),
36
+ }));
37
+ }
38
+ // ── Main helper ─────────────────────────────────────────────────
39
+ function getWarehouseSaleOrderWithPrice(order, writeable) {
40
+ const convertToPrice = writeable ? utils_1.convertDecimalToInt : utils_1.convertIntToDecimal;
41
+ const payload = {
42
+ ...order,
43
+ ...(order.iterations != null
44
+ ? {
45
+ iterations: getWarehouseSaleOrderIterationsWithPrice(order.iterations, writeable),
46
+ }
47
+ : {}),
48
+ ...(order.categories != null
49
+ ? {
50
+ categories: getWarehouseSaleOrderCategoriesWithPrice(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_collected != null
56
+ ? {
57
+ amount_collected: convertToPrice(order.amount_collected),
58
+ }
59
+ : {}),
60
+ ...(order.amount_earned != null ? { amount_earned: convertToPrice(order.amount_earned) } : {}),
61
+ ...(order.grand_total != null ? { grand_total: convertToPrice(order.grand_total) } : {}),
62
+ ...(order.price != null ? { price: convertToPrice(order.price) } : {}),
63
+ };
64
+ return payload;
65
+ }
@@ -1,14 +1,14 @@
1
1
  export * from './all-orders-actions';
2
- export * from './all-purchase-orders-actions';
3
- export * from './all-sale-orders-actions';
2
+ export * from './all-warehouse-purchase-orders-actions';
3
+ export * from './all-warehouse-sale-orders-actions';
4
4
  export * from './all-warehouse-invoice-actions';
5
5
  export * from './cart-actions';
6
6
  export * from './catalog-actions';
7
7
  export * from './common-order-actions';
8
- export * from './common-purchase-order-actions';
9
- export * from './common-sale-order-actions';
8
+ export * from './common-warehouse-purchase-order-actions';
9
+ export * from './common-warehouse-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';
13
- export * from './purchase-orders-cart-actions';
12
+ export * from './warehouse-purchase-order-rfq-cart-actions';
13
+ export * from './warehouse-purchase-orders-cart-actions';
14
14
  export * from './warehouse-invoice-cart-actions';
@@ -15,16 +15,16 @@ 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-purchase-orders-actions"), exports);
19
- __exportStar(require("./all-sale-orders-actions"), exports);
18
+ __exportStar(require("./all-warehouse-purchase-orders-actions"), exports);
19
+ __exportStar(require("./all-warehouse-sale-orders-actions"), exports);
20
20
  __exportStar(require("./all-warehouse-invoice-actions"), exports);
21
21
  __exportStar(require("./cart-actions"), exports);
22
22
  __exportStar(require("./catalog-actions"), exports);
23
23
  __exportStar(require("./common-order-actions"), exports);
24
- __exportStar(require("./common-purchase-order-actions"), exports);
25
- __exportStar(require("./common-sale-order-actions"), exports);
24
+ __exportStar(require("./common-warehouse-purchase-order-actions"), exports);
25
+ __exportStar(require("./common-warehouse-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);
29
- __exportStar(require("./purchase-orders-cart-actions"), exports);
28
+ __exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
29
+ __exportStar(require("./warehouse-purchase-orders-cart-actions"), exports);
30
30
  __exportStar(require("./warehouse-invoice-cart-actions"), exports);