@managesome/eposmatic-toolkit 0.2.462 → 0.2.464

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 (53) hide show
  1. package/lib/constants/WAREHOUSE_ANALYTICS.d.ts +1 -100
  2. package/lib/constants/WAREHOUSE_ANALYTICS.js +1 -11
  3. package/lib/constants/WAREHOUSE_ENUMS.d.ts +0 -6
  4. package/lib/constants/WAREHOUSE_ENUMS.js +1 -9
  5. package/lib/constants/WORKER_ENDPOINTS.d.ts +0 -4
  6. package/lib/constants/WORKER_ENDPOINTS.js +0 -4
  7. package/lib/constants/index.d.ts +0 -1
  8. package/lib/constants/index.js +0 -1
  9. package/lib/helpers/order/generate-warehouse-invoice.d.ts +3 -3
  10. package/lib/helpers/order/generate-warehouse-sale-order-rfq.d.ts +3 -0
  11. package/lib/helpers/order/generate-warehouse-sale-order-rfq.js +64 -0
  12. package/lib/helpers/order/generate-warehouse-sale-order.d.ts +11 -0
  13. package/lib/helpers/order/generate-warehouse-sale-order.js +158 -0
  14. package/lib/helpers/order/index.d.ts +2 -1
  15. package/lib/helpers/order/index.js +2 -1
  16. package/lib/helpers/store/all-warehouse-sale-orders-actions.d.ts +13 -0
  17. package/lib/helpers/store/all-warehouse-sale-orders-actions.js +79 -0
  18. package/lib/helpers/store/common-warehouse-sale-order-actions.d.ts +26 -0
  19. package/lib/helpers/store/common-warehouse-sale-order-actions.js +428 -0
  20. package/lib/helpers/store/common-warehouse-sale-order-rfq-actions.d.ts +0 -1
  21. package/lib/helpers/store/common-warehouse-sale-order-rfq-actions.js +2 -88
  22. package/lib/helpers/store/index.d.ts +2 -3
  23. package/lib/helpers/store/index.js +2 -3
  24. package/lib/helpers/store/warehouse-invoice-cart-actions.d.ts +2 -34
  25. package/lib/helpers/store/warehouse-sale-order-rfq-cart-actions.d.ts +1 -0
  26. package/lib/helpers/store/warehouse-sale-order-rfq-cart-actions.js +93 -7
  27. package/lib/helpers/store/warehouse-sale-orders-cart-actions.d.ts +55 -0
  28. package/lib/helpers/store/warehouse-sale-orders-cart-actions.js +472 -0
  29. package/lib/helpers/types/index.d.ts +5 -5
  30. package/lib/helpers/types/index.js +5 -5
  31. package/lib/helpers/types/warehouse-sale-order-cart-actions.d.ts +26 -0
  32. package/lib/helpers/types/warehouse-sale-order-cart-actions.js +2 -0
  33. package/lib/helpers/types/workers.d.ts +2 -24
  34. package/lib/helpers/utils/index.d.ts +4 -4
  35. package/lib/helpers/utils/index.js +4 -4
  36. package/lib/helpers/utils/warehouse-sale-order-engine.d.ts +9 -0
  37. package/lib/helpers/utils/warehouse-sale-order-engine.js +34 -0
  38. package/lib/helpers/utils/warehouse-sale-order-receipt-engine.d.ts +89 -0
  39. package/lib/helpers/utils/warehouse-sale-order-receipt-engine.js +216 -0
  40. package/lib/helpers/utils/warehouse-void-sale-order-items-helpers.d.ts +3 -0
  41. package/lib/helpers/utils/warehouse-void-sale-order-items-helpers.js +38 -0
  42. package/lib/helpers/utils/warehouse-void-sale-order-items-report-helpers.d.ts +13 -0
  43. package/lib/helpers/utils/warehouse-void-sale-order-items-report-helpers.js +22 -0
  44. package/lib/schemas/models/index.d.ts +1 -2
  45. package/lib/schemas/models/index.js +1 -2
  46. package/lib/schemas/models/warehouse_void_sale_order_items.d.ts +176 -0
  47. package/lib/schemas/models/warehouse_void_sale_order_items.js +177 -0
  48. package/lib/schemas/types/index.d.ts +1 -2
  49. package/lib/schemas/types/index.js +1 -2
  50. package/lib/schemas/types/warehouse_sale_orders.d.ts +6 -0
  51. package/lib/schemas/types/warehouse_void_sale_order_items.d.ts +37 -0
  52. package/lib/schemas/types/warehouse_void_sale_order_items.js +2 -0
  53. package/package.json +1 -1
@@ -1,6 +1,32 @@
1
+ import { SORT_TYPE_ENUM } from '../../constants';
1
2
  import { IWarehouseSaleOrder, IWarehouseSaleOrderCategory, IWarehouseSaleOrderItem, IWarehouseSaleOrderIteration } from '../../schemas';
3
+ import { IWarehouseGeneralSaleOrderItem, IWarehouseSaleOrderCartItemsObj } from '../types';
2
4
  export declare function getWarehouseSaleOrdersFetchedData(data: IWarehouseSaleOrder[]): IWarehouseSaleOrder[];
3
5
  export declare function getWarehouseSaleOrderIterationsWithPrice(iterations?: IWarehouseSaleOrderIteration[] | undefined, writeable?: boolean): IWarehouseSaleOrderIteration[];
4
6
  export declare function getWarehouseSaleOrderItemsWithPrice(items: IWarehouseSaleOrderItem[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderItem[];
5
7
  export declare function getWarehouseSaleOrderCategoriesWithPrice(categories: IWarehouseSaleOrderCategory[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderCategory[];
6
8
  export declare function getWarehouseSaleOrderWithPrice<T extends Partial<IWarehouseSaleOrder> | IWarehouseSaleOrder | IWarehouseSaleOrderIteration>(order: T, writeable?: boolean): T;
9
+ export declare function syncWarehouseSaleOrderData(order: IWarehouseSaleOrder): IWarehouseSaleOrder;
10
+ export declare function skipItemMetadataFromWarehouseSaleOrderCategories(categories: IWarehouseSaleOrder['categories'], previousCategories?: IWarehouseSaleOrder['categories']): IWarehouseSaleOrder['categories'];
11
+ export declare function getWarehouseSaleOrderWithAllFields<T extends IWarehouseSaleOrder | Partial<IWarehouseSaleOrder>>(order: T, skipItemMetadata?: boolean): T;
12
+ export interface IGetSaleOrderCartItemsObjPayload {
13
+ currentIterationCategories: IWarehouseSaleOrderCategory[] | undefined;
14
+ previousIterationCategories: IWarehouseSaleOrderCategory[] | undefined;
15
+ mappedItems: Record<string, IWarehouseGeneralSaleOrderItem>;
16
+ shouldSortItemsViaId?: boolean;
17
+ isAnEdit?: boolean;
18
+ sortType?: SORT_TYPE_ENUM;
19
+ }
20
+ export declare function getWarehouseSaleOrderCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId, isAnEdit, sortType, }: IGetSaleOrderCartItemsObjPayload): IWarehouseSaleOrderCartItemsObj;
21
+ interface IGetVoidItemsWithReasonSaleOrder {
22
+ currentCategories: IWarehouseSaleOrderCategory[];
23
+ iterationsFromFrontend: IWarehouseSaleOrderIteration[] | undefined;
24
+ previousCategories: IWarehouseSaleOrderCategory[];
25
+ }
26
+ export declare function getVoidItemsWithReasonWarehouseSaleOrder({ currentCategories, iterationsFromFrontend, previousCategories, }: IGetVoidItemsWithReasonSaleOrder): {
27
+ categories: IWarehouseSaleOrderCategory[];
28
+ voidOrderItems: IWarehouseSaleOrderItem[];
29
+ hasNewItems: boolean;
30
+ voidItemsCount: number;
31
+ };
32
+ export {};
@@ -1,12 +1,24 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getWarehouseSaleOrdersFetchedData = getWarehouseSaleOrdersFetchedData;
4
7
  exports.getWarehouseSaleOrderIterationsWithPrice = getWarehouseSaleOrderIterationsWithPrice;
5
8
  exports.getWarehouseSaleOrderItemsWithPrice = getWarehouseSaleOrderItemsWithPrice;
6
9
  exports.getWarehouseSaleOrderCategoriesWithPrice = getWarehouseSaleOrderCategoriesWithPrice;
7
10
  exports.getWarehouseSaleOrderWithPrice = getWarehouseSaleOrderWithPrice;
11
+ exports.syncWarehouseSaleOrderData = syncWarehouseSaleOrderData;
12
+ exports.skipItemMetadataFromWarehouseSaleOrderCategories = skipItemMetadataFromWarehouseSaleOrderCategories;
13
+ exports.getWarehouseSaleOrderWithAllFields = getWarehouseSaleOrderWithAllFields;
14
+ exports.getWarehouseSaleOrderCartItemsObj = getWarehouseSaleOrderCartItemsObj;
15
+ exports.getVoidItemsWithReasonWarehouseSaleOrder = getVoidItemsWithReasonWarehouseSaleOrder;
16
+ const bson_objectid_1 = __importDefault(require("bson-objectid"));
17
+ const lodash_1 = require("lodash");
18
+ const constants_1 = require("../../constants");
8
19
  const utils_1 = require("../utils");
9
20
  const common_order_actions_1 = require("./common-order-actions");
21
+ const warehouse_sale_orders_cart_actions_1 = require("./warehouse-sale-orders-cart-actions");
10
22
  function getWarehouseSaleOrdersFetchedData(data) {
11
23
  return data.map((order) => getWarehouseSaleOrderWithPrice(order, false)).sort(common_order_actions_1.sortByCreatedAt);
12
24
  }
@@ -68,3 +80,419 @@ function getWarehouseSaleOrderWithPrice(order, writeable) {
68
80
  };
69
81
  return payload;
70
82
  }
83
+ function syncWarehouseSaleOrderData(order) {
84
+ const updatedOrder = {
85
+ ...order,
86
+ iterations: [],
87
+ };
88
+ const newOrder = getWarehouseSaleOrderWithPrice((0, warehouse_sale_orders_cart_actions_1.calculateCartWarehouseSaleOrderInfoAndSyncData)(getWarehouseSaleOrderWithPrice(updatedOrder), true), true);
89
+ newOrder.iterations = order.iterations;
90
+ return newOrder;
91
+ }
92
+ function skipItemMetadataFromWarehouseSaleOrderCategories(categories, previousCategories) {
93
+ return categories.map((category) => {
94
+ const previousCategory = previousCategories?.find((prevCategory) => prevCategory.category_id === category.category_id);
95
+ return {
96
+ ...category,
97
+ items: category.items.map((item) => {
98
+ const previousItem = previousCategory?.items.find((prevItem) => prevItem._id === item._id);
99
+ const void_reason = previousItem?.void_reason ?? item.void_reason;
100
+ const newItem = {
101
+ ...item,
102
+ void_reason,
103
+ _discount_amount: 0,
104
+ _gst_amount: 0,
105
+ _gross_amount: 0,
106
+ _net_amount: 0,
107
+ };
108
+ return newItem;
109
+ }),
110
+ };
111
+ });
112
+ }
113
+ function getCommonOptionalBoolFieldsSaleOrder(order, partial) {
114
+ const defaultValue = partial ? undefined : false;
115
+ return {
116
+ is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
117
+ is_reopened: order['is_reopened'] || defaultValue,
118
+ };
119
+ }
120
+ function getCommonOptionalNumFieldsSaleOrder(order, partial) {
121
+ const defaultValue = partial ? undefined : 0;
122
+ return {
123
+ gst: order['gst'] || defaultValue,
124
+ gst_amount: order['gst_amount'] || defaultValue,
125
+ };
126
+ }
127
+ function getWarehouseSaleOrderWithAllFields(order, skipItemMetadata) {
128
+ return {
129
+ ...order,
130
+ ...getCommonOptionalBoolFieldsSaleOrder(order, false),
131
+ ...getCommonOptionalNumFieldsSaleOrder(order, false),
132
+ ...(skipItemMetadata && order.categories != null
133
+ ? {
134
+ categories: skipItemMetadataFromWarehouseSaleOrderCategories(order.categories),
135
+ }
136
+ : {}),
137
+ delete_reason: order['delete_reason'] ?? null,
138
+ cancel_reason: order['cancel_reason'] ?? null,
139
+ };
140
+ }
141
+ function getWarehouseSaleOrderCartItemsObj({ currentIterationCategories, previousIterationCategories, mappedItems, shouldSortItemsViaId = true, isAnEdit, sortType, }) {
142
+ const newMappedItems = { ...mappedItems };
143
+ if (Object.keys(newMappedItems).length === 0) {
144
+ previousIterationCategories?.forEach((category) => {
145
+ category.items.forEach((item) => {
146
+ if (newMappedItems[item.item_id] == null) {
147
+ newMappedItems[item.item_id] = {
148
+ _id: item.item_id,
149
+ name: item.name,
150
+ category_id: category.category_id,
151
+ category_name: category.name,
152
+ category_image_url: '',
153
+ image_url: '',
154
+ description: '',
155
+ };
156
+ }
157
+ });
158
+ });
159
+ currentIterationCategories?.forEach((category) => {
160
+ category.items.forEach((item) => {
161
+ if (newMappedItems[item.item_id] == null) {
162
+ newMappedItems[item.item_id] = {
163
+ _id: item.item_id,
164
+ name: item.name,
165
+ category_id: category.category_id,
166
+ category_name: category.name,
167
+ category_image_url: '',
168
+ image_url: '',
169
+ description: '',
170
+ };
171
+ }
172
+ });
173
+ });
174
+ }
175
+ // =====================><=====================
176
+ const getCartItems = (items) => {
177
+ const orderItems = items.map((item) => {
178
+ const selectedItem = newMappedItems[item.item_id] ?? {};
179
+ return {
180
+ orderItem: item,
181
+ image_url: selectedItem.image_url ?? '',
182
+ description: selectedItem.description ?? '',
183
+ category_name: selectedItem.category_name ?? '',
184
+ category_id: selectedItem.category_id ?? '',
185
+ };
186
+ });
187
+ if (shouldSortItemsViaId) {
188
+ if (sortType === constants_1.SORT_TYPE_ENUM.DESC) {
189
+ orderItems.sort((a, b) => (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime());
190
+ }
191
+ else {
192
+ orderItems.sort((a, b) => (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime());
193
+ }
194
+ }
195
+ return orderItems;
196
+ };
197
+ // =====================><=====================
198
+ let totalItemsInCart = 0;
199
+ const currentItems = [];
200
+ if (currentIterationCategories != null) {
201
+ for (let i = 0; i < currentIterationCategories.length; i++) {
202
+ const category = currentIterationCategories[i];
203
+ for (let j = 0; j < category.items.length; j++) {
204
+ const item = { ...category.items[j] };
205
+ currentItems.push(item);
206
+ totalItemsInCart += item.quantity;
207
+ }
208
+ }
209
+ }
210
+ let unChangedItems = currentItems;
211
+ const editedItems = [];
212
+ let removedItems = [];
213
+ let newItems = [];
214
+ let disabledReason = '';
215
+ const isAnUpdate = isAnEdit ?? (previousIterationCategories != null && previousIterationCategories.length > 0);
216
+ if (isAnUpdate) {
217
+ const currentItemsMap = currentItems.reduce((acc, currentItem) => {
218
+ acc[currentItem._id] = currentItem;
219
+ return acc;
220
+ }, {});
221
+ const prevItems = [];
222
+ const prevItemsMap = {};
223
+ const prevCategories = previousIterationCategories ?? [];
224
+ for (let i = 0; i < prevCategories.length; i++) {
225
+ const category = prevCategories[i];
226
+ for (let j = 0; j < category.items.length; j++) {
227
+ const prevItem = category.items[j];
228
+ let item = prevItem;
229
+ const currentItem = currentItemsMap[prevItem._id];
230
+ if (currentItem != null && currentItem.is_ready != null) {
231
+ item = {
232
+ ...item,
233
+ is_ready: currentItem.is_ready,
234
+ };
235
+ }
236
+ prevItems.push(item);
237
+ prevItemsMap[item._id] = item;
238
+ }
239
+ }
240
+ unChangedItems = [];
241
+ let totalTempRemovedItems = 0;
242
+ for (let i = 0; i < prevItems.length; i++) {
243
+ const prevItem = {
244
+ ...prevItems[i],
245
+ };
246
+ const currentItem = {
247
+ ...currentItemsMap[prevItem._id],
248
+ };
249
+ if (currentItemsMap[prevItem._id] == null) {
250
+ removedItems.push(prevItem);
251
+ }
252
+ else if ((0, lodash_1.isEqual)((0, warehouse_sale_orders_cart_actions_1.getWarehouseSaleOrderItemComparableData)(currentItem), (0, warehouse_sale_orders_cart_actions_1.getWarehouseSaleOrderItemComparableData)(prevItem))) {
253
+ unChangedItems.push(prevItem);
254
+ }
255
+ else {
256
+ const currQty = currentItem.quantity;
257
+ const prevQty = prevItem.quantity;
258
+ if (currQty !== prevQty) {
259
+ const subtotalForOne = currentItem.subtotal / currentItem.quantity;
260
+ const diff = currQty - prevQty;
261
+ const changeQty = Math.abs(diff);
262
+ const itm = {
263
+ ...currentItem,
264
+ quantity: changeQty,
265
+ subtotal: (0, utils_1.parseNum)(changeQty * subtotalForOne),
266
+ };
267
+ if (diff > 0) {
268
+ newItems.push(itm);
269
+ const unchangedQty = currQty - changeQty;
270
+ const tempUnchangedItm = {
271
+ ...currentItem,
272
+ quantity: unchangedQty,
273
+ subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
274
+ };
275
+ unChangedItems.push(tempUnchangedItm);
276
+ }
277
+ else {
278
+ itm.void_reason = prevItem.void_reason ?? currentItem.void_reason;
279
+ removedItems.push(itm);
280
+ const unchangedQty = prevQty - changeQty;
281
+ const tempUnchangedItm = {
282
+ ...currentItem,
283
+ quantity: unchangedQty,
284
+ subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
285
+ };
286
+ unChangedItems.push(tempUnchangedItm);
287
+ totalTempRemovedItems++;
288
+ }
289
+ }
290
+ else {
291
+ const curr = {
292
+ _id: currentItem._id,
293
+ item_id: currentItem.item_id,
294
+ name: currentItem.name,
295
+ special_instructions: currentItem.special_instructions,
296
+ };
297
+ const prev = {
298
+ _id: prevItem._id,
299
+ item_id: prevItem.item_id,
300
+ name: prevItem.name,
301
+ special_instructions: prevItem.special_instructions,
302
+ };
303
+ const isBothEqual = (0, lodash_1.isEqual)(curr, prev);
304
+ if (isBothEqual) {
305
+ unChangedItems.push(currentItem);
306
+ }
307
+ else {
308
+ editedItems.push(currentItem);
309
+ }
310
+ }
311
+ }
312
+ }
313
+ for (let i = 0; i < currentItems.length; i++) {
314
+ const item = currentItems[i];
315
+ if (prevItemsMap[item._id] == null) {
316
+ newItems.push(item);
317
+ }
318
+ }
319
+ if (removedItems.length > 0 && newItems.length > 0) {
320
+ const newItemsMap = newItems.reduce((acc, item) => {
321
+ acc[item.item_id] = [...(acc[item.item_id] ?? []), item];
322
+ return acc;
323
+ }, {});
324
+ const revertedRemovedItems = [];
325
+ const revertedNewItems = [];
326
+ const additionalNewItems = [];
327
+ for (let i = 0; i < removedItems.length; i++) {
328
+ const removedItem = removedItems[i];
329
+ const newItemsForItem = newItemsMap[removedItem.item_id];
330
+ if (newItemsForItem == null)
331
+ continue;
332
+ if (newItemsForItem.length > 0) {
333
+ const newItemsForItemLength = newItemsForItem.length;
334
+ for (let j = 0; j < newItemsForItemLength; j++) {
335
+ const newItem = newItemsForItem[j];
336
+ const newI = {
337
+ item_id: newItem.item_id,
338
+ name: newItem.name,
339
+ price: newItem.price,
340
+ special_instructions: newItem.special_instructions,
341
+ };
342
+ const removedI = {
343
+ item_id: removedItem.item_id,
344
+ name: removedItem.name,
345
+ price: removedItem.price,
346
+ special_instructions: removedItem.special_instructions,
347
+ };
348
+ if ((0, lodash_1.isEqual)(newI, removedI)) {
349
+ if (newItem.quantity === removedItem.quantity) {
350
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
351
+ if (newItemsMap[removedItem.item_id].length === 0) {
352
+ delete newItemsMap[removedItem.item_id];
353
+ }
354
+ revertedNewItems.push(newItem);
355
+ revertedRemovedItems.push(removedItem);
356
+ break;
357
+ }
358
+ else {
359
+ if (removedItem.quantity > newItem.quantity) {
360
+ newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
361
+ if (newItemsMap[removedItem.item_id].length === 0) {
362
+ delete newItemsMap[removedItem.item_id];
363
+ }
364
+ revertedNewItems.push(newItem);
365
+ const subtotalForSingle = removedItem.subtotal / removedItem.quantity;
366
+ const newQuantity = removedItem.quantity - newItem.quantity;
367
+ const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
368
+ removedItem.quantity = newQuantity;
369
+ removedItem.subtotal = newSubtotal;
370
+ }
371
+ else {
372
+ revertedRemovedItems.push(removedItem);
373
+ const nQuantity = newItem.quantity;
374
+ const subtotalForSingle = newItem.subtotal / nQuantity;
375
+ const newQuantity = nQuantity - removedItem.quantity;
376
+ const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
377
+ newItem.quantity = newQuantity;
378
+ newItem.subtotal = newSubtotal;
379
+ const remainingQuantity = nQuantity - newQuantity;
380
+ const adItem = {
381
+ ...newItem,
382
+ quantity: remainingQuantity,
383
+ subtotal: (0, utils_1.parseNum)(remainingQuantity * subtotalForSingle),
384
+ };
385
+ additionalNewItems.push(adItem);
386
+ break;
387
+ }
388
+ }
389
+ }
390
+ }
391
+ }
392
+ else {
393
+ delete newItemsMap[removedItem.item_id];
394
+ }
395
+ }
396
+ for (let i = 0; i < revertedRemovedItems.length; i++) {
397
+ const rItem = revertedRemovedItems[i];
398
+ removedItems = removedItems.filter((item) => item._id !== rItem._id);
399
+ }
400
+ for (let i = 0; i < revertedNewItems.length; i++) {
401
+ const nItem = revertedNewItems[i];
402
+ newItems = newItems.filter((item) => item._id !== nItem._id);
403
+ unChangedItems.push(nItem);
404
+ }
405
+ for (let i = 0; i < additionalNewItems.length; i++) {
406
+ const aItem = additionalNewItems[i];
407
+ unChangedItems.push(aItem);
408
+ }
409
+ }
410
+ disabledReason =
411
+ unChangedItems.length === prevItems.length &&
412
+ newItems.length === 0 &&
413
+ removedItems.length === 0 &&
414
+ editedItems.length === 0
415
+ ? 'No changes in the order'
416
+ : prevItems.length === removedItems.length - totalTempRemovedItems &&
417
+ editedItems.length === 0 &&
418
+ newItems.length === 0
419
+ ? 'At least one item is required'
420
+ : '';
421
+ }
422
+ const cartItemsObj = {
423
+ unChangedItems: getCartItems(unChangedItems),
424
+ editedItems: getCartItems(editedItems),
425
+ removedItems: getCartItems(removedItems),
426
+ newItems: getCartItems(newItems),
427
+ totalSelectedItems: (0, utils_1.parseNum)(totalItemsInCart, true),
428
+ disabledReason,
429
+ isAnUpdate,
430
+ };
431
+ return cartItemsObj;
432
+ }
433
+ function getVoidItemsWithReasonWarehouseSaleOrder({ currentCategories, iterationsFromFrontend, previousCategories, }) {
434
+ const voidOrderItemReasonsMap = {};
435
+ const latestIterationCategories = iterationsFromFrontend?.[0]?.categories;
436
+ if (latestIterationCategories != null && latestIterationCategories.length > 0) {
437
+ for (let i = 0; i < latestIterationCategories.length; i++) {
438
+ const category = latestIterationCategories[i];
439
+ for (let j = 0; j < category.items.length; j++) {
440
+ const item = category.items[j];
441
+ if (item.void_reason != null && item.void_reason.length > 0) {
442
+ voidOrderItemReasonsMap[item._id] = item.void_reason;
443
+ }
444
+ }
445
+ }
446
+ }
447
+ const { newItems, removedItems } = getWarehouseSaleOrderCartItemsObj({
448
+ currentIterationCategories: currentCategories,
449
+ previousIterationCategories: previousCategories,
450
+ mappedItems: {},
451
+ shouldSortItemsViaId: false,
452
+ isAnEdit: true,
453
+ });
454
+ const hasNewItems = newItems.length > 0;
455
+ const voidOrderItems = [];
456
+ const newVoidOrderItemReasonsMap = {};
457
+ for (let i = 0; i < removedItems.length; i++) {
458
+ const { orderItem } = removedItems[i];
459
+ const voidReason = voidOrderItemReasonsMap[orderItem._id];
460
+ voidOrderItems.push({
461
+ ...orderItem,
462
+ subtotal: Math.round(orderItem.subtotal),
463
+ void_reason: voidReason ?? '-',
464
+ });
465
+ if (voidReason != null) {
466
+ newVoidOrderItemReasonsMap[orderItem._id] = voidReason;
467
+ }
468
+ }
469
+ const newIterationCategories = [];
470
+ for (let i = 0; i < previousCategories.length; i++) {
471
+ const category = previousCategories[i];
472
+ const newCategoryItems = [];
473
+ for (let j = 0; j < category.items.length; j++) {
474
+ const prevItem = category.items[j];
475
+ const voidReason = newVoidOrderItemReasonsMap[prevItem._id];
476
+ const orderItem = {
477
+ ...prevItem,
478
+ subtotal: Math.round(prevItem.subtotal),
479
+ };
480
+ if (voidReason != null) {
481
+ orderItem.void_reason = voidReason;
482
+ }
483
+ newCategoryItems.push(orderItem);
484
+ }
485
+ if (newCategoryItems.length === 0)
486
+ continue;
487
+ newIterationCategories.push({
488
+ ...category,
489
+ items: newCategoryItems,
490
+ });
491
+ }
492
+ return {
493
+ categories: newIterationCategories,
494
+ voidOrderItems,
495
+ hasNewItems,
496
+ voidItemsCount: voidOrderItems.length,
497
+ };
498
+ }
@@ -5,7 +5,6 @@ export declare function getWarehouseSaleOrderRfqIterationsWithPrice(iterations?:
5
5
  export declare function getWarehouseSaleOrderRfqItemsWithPrice(items: IWarehouseSaleOrderRFQItem[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderRFQItem[];
6
6
  export declare function getWarehouseSaleOrderRfqCategoriesWithPrice(categories: IWarehouseSaleOrderRFQCategory[] | undefined, convertToPrice: (price: number) => number): IWarehouseSaleOrderRFQCategory[];
7
7
  export declare function getWarehouseSaleOrderRfqWithPrice<T extends Partial<IWarehouseSaleOrderRFQ> | IWarehouseSaleOrderRFQ | IWarehouseSaleOrderRFQIteration>(order: T, writeable?: boolean): T;
8
- export declare function calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData<T extends IWarehouseSaleOrderRFQ | Partial<IWarehouseSaleOrderRFQ>>(data: T, calculateItemMetadata?: boolean): T;
9
8
  export declare function syncWarehouseSaleOrderRfqData(order: IWarehouseSaleOrderRFQ): IWarehouseSaleOrderRFQ;
10
9
  export declare function skipItemMetadataFromWarehouseSaleOrderRfqCategories(categories: IWarehouseSaleOrderRFQ['categories'], previousCategories?: IWarehouseSaleOrderRFQ['categories']): IWarehouseSaleOrderRFQ['categories'];
11
10
  export declare function getWarehouseSaleOrderRfqWithAllFields<T extends IWarehouseSaleOrderRFQ | Partial<IWarehouseSaleOrderRFQ>>(order: T, skipItemMetadata?: boolean): T;
@@ -7,7 +7,6 @@ exports.getWarehouseSaleOrderRfqIterationsWithPrice = getWarehouseSaleOrderRfqIt
7
7
  exports.getWarehouseSaleOrderRfqItemsWithPrice = getWarehouseSaleOrderRfqItemsWithPrice;
8
8
  exports.getWarehouseSaleOrderRfqCategoriesWithPrice = getWarehouseSaleOrderRfqCategoriesWithPrice;
9
9
  exports.getWarehouseSaleOrderRfqWithPrice = getWarehouseSaleOrderRfqWithPrice;
10
- exports.calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData = calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData;
11
10
  exports.syncWarehouseSaleOrderRfqData = syncWarehouseSaleOrderRfqData;
12
11
  exports.skipItemMetadataFromWarehouseSaleOrderRfqCategories = skipItemMetadataFromWarehouseSaleOrderRfqCategories;
13
12
  exports.getWarehouseSaleOrderRfqWithAllFields = getWarehouseSaleOrderRfqWithAllFields;
@@ -17,6 +16,7 @@ const bson_objectid_1 = __importDefault(require("bson-objectid"));
17
16
  const lodash_1 = require("lodash");
18
17
  const constants_1 = require("../../constants");
19
18
  const utils_1 = require("../utils");
19
+ const warehouse_sale_order_rfq_cart_actions_1 = require("./warehouse-sale-order-rfq-cart-actions");
20
20
  /* =================================================================
21
21
  * Sale-order RFQ common helpers — price conversion, field defaults, cart UI.
22
22
  * Mirrors common-warehouse-purchase-order-rfq-actions.ts for sale RFQ types.
@@ -74,99 +74,13 @@ function getWarehouseSaleOrderRfqWithPrice(order, writeable) {
74
74
  };
75
75
  return payload;
76
76
  }
77
- // ── Cart calculation ──
78
- function calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData(data, calculateItemMetadata) {
79
- const isConfirmed = data.order_status === constants_1.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM.CONFIRMED;
80
- let subtotal = 0;
81
- const categories = [];
82
- const length = data.categories?.length ?? 0;
83
- for (let c = 0; c < length; c++) {
84
- const category = data.categories[c];
85
- const newItems = [];
86
- const itemsLength = category.items.length;
87
- for (let i = 0; i < itemsLength; i++) {
88
- const item = category.items[i];
89
- const itemSubtotal = (0, utils_1.parseNum)(item.price * item.quantity);
90
- const newItem = {
91
- ...item,
92
- is_ready: item.is_ready || isConfirmed,
93
- subtotal: itemSubtotal,
94
- _discount_amount: 0,
95
- _gross_amount: 0,
96
- _gst_amount: 0,
97
- _net_amount: 0,
98
- };
99
- delete newItem.void_reason;
100
- newItems.push(newItem);
101
- subtotal += itemSubtotal;
102
- }
103
- categories.push({ ...category, items: newItems });
104
- }
105
- let grand_total = subtotal;
106
- let gst_amount = 0;
107
- const gst = data.gst ?? 0;
108
- if (data.is_gst_inclusive) {
109
- gst_amount = (0, utils_1.parseFloatCeil)((grand_total * gst) / (100 + gst));
110
- }
111
- else {
112
- gst_amount = (0, utils_1.getPercentageAmount)(grand_total, gst);
113
- grand_total += gst_amount;
114
- }
115
- grand_total = (0, utils_1.parseNum)(grand_total);
116
- const amount_earned = (0, utils_1.parseNum)(grand_total);
117
- if (calculateItemMetadata) {
118
- let leftGrossAmount = subtotal;
119
- let leftNetAmount = subtotal;
120
- let leftDiscountAmount = 0;
121
- let leftGstAmount = gst_amount;
122
- categories.forEach((category, categoryIndex) => {
123
- const isLastCategory = categoryIndex === categories.length - 1;
124
- category.items.forEach((item, itemIndex) => {
125
- const isLastItem = isLastCategory && itemIndex === category.items.length - 1;
126
- let grossAmount = item.subtotal;
127
- let netAmount = item.subtotal;
128
- let itemTotalDiscountAmount = 0;
129
- let itemGst = 0;
130
- if (gst_amount > 0) {
131
- itemGst = (item.subtotal / subtotal) * gst_amount;
132
- }
133
- grossAmount = (0, utils_1.parseFloatCeil)(grossAmount);
134
- const netAmountParsed = (0, utils_1.parseFloatCeil)(netAmount);
135
- const itemTotalDiscountAmountParsed = (0, utils_1.parseFloatCeil)(itemTotalDiscountAmount);
136
- itemGst = (0, utils_1.parseFloatCeil)(itemGst);
137
- leftGrossAmount -= grossAmount;
138
- leftNetAmount -= netAmountParsed;
139
- leftDiscountAmount -= itemTotalDiscountAmountParsed;
140
- leftGstAmount -= itemGst;
141
- if (isLastItem) {
142
- grossAmount += leftGrossAmount;
143
- netAmount += leftNetAmount;
144
- itemTotalDiscountAmount += leftDiscountAmount;
145
- itemGst += leftGstAmount;
146
- }
147
- item._gross_amount = Math.max(grossAmount, 0);
148
- item._net_amount = Math.max(netAmount, 0);
149
- item._discount_amount = Math.max(itemTotalDiscountAmount, 0);
150
- item._gst_amount = Math.max(itemGst, 0);
151
- });
152
- });
153
- }
154
- return {
155
- ...data,
156
- categories,
157
- amount_earned,
158
- gst_amount,
159
- price: (0, utils_1.parseNum)(subtotal),
160
- grand_total,
161
- };
162
- }
163
77
  // ── Sync ──
164
78
  function syncWarehouseSaleOrderRfqData(order) {
165
79
  const updatedOrder = {
166
80
  ...order,
167
81
  iterations: [],
168
82
  };
169
- const newOrder = getWarehouseSaleOrderRfqWithPrice(calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData(getWarehouseSaleOrderRfqWithPrice(updatedOrder), true), true);
83
+ const newOrder = getWarehouseSaleOrderRfqWithPrice((0, warehouse_sale_order_rfq_cart_actions_1.calculateCartWarehouseSaleOrderRfqOrderInfoAndSyncData)(getWarehouseSaleOrderRfqWithPrice(updatedOrder), true), true);
170
84
  newOrder.iterations = order.iterations;
171
85
  return newOrder;
172
86
  }
@@ -1,14 +1,13 @@
1
1
  export * from './all-orders-actions';
2
- export * from './all-warehouse-invoice-actions';
3
2
  export * from './all-warehouse-purchase-order-rfqs-actions';
4
3
  export * from './all-warehouse-purchase-order-vendor-return-actions';
5
4
  export * from './all-warehouse-purchase-orders-actions';
6
5
  export * from './all-warehouse-sale-order-rfqs-actions';
6
+ export * from './all-warehouse-sale-orders-actions';
7
7
  export * from './cart-actions';
8
8
  export * from './catalog-actions';
9
9
  export * from './common-order-actions';
10
10
  export * from './common-tenant-purchase-order-actions';
11
- export * from './common-warehouse-invoice-actions';
12
11
  export * from './common-warehouse-internal-movement-actions';
13
12
  export * from './common-warehouse-purchase-order-actions';
14
13
  export * from './common-warehouse-purchase-order-receipt-actions';
@@ -19,7 +18,7 @@ export * from './common-warehouse-sale-order-invoice-actions';
19
18
  export * from './common-warehouse-sale-order-rfq-actions';
20
19
  export * from './offline-ordering';
21
20
  export * from './tenant-purchase-orders-cart-actions';
22
- export * from './warehouse-invoice-cart-actions';
23
21
  export * from './warehouse-purchase-order-rfq-cart-actions';
24
22
  export * from './warehouse-purchase-orders-cart-actions';
25
23
  export * from './warehouse-sale-order-rfq-cart-actions';
24
+ export * from './warehouse-sale-orders-cart-actions';
@@ -15,16 +15,15 @@ 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
18
  __exportStar(require("./all-warehouse-purchase-order-rfqs-actions"), exports);
20
19
  __exportStar(require("./all-warehouse-purchase-order-vendor-return-actions"), exports);
21
20
  __exportStar(require("./all-warehouse-purchase-orders-actions"), exports);
22
21
  __exportStar(require("./all-warehouse-sale-order-rfqs-actions"), exports);
22
+ __exportStar(require("./all-warehouse-sale-orders-actions"), exports);
23
23
  __exportStar(require("./cart-actions"), exports);
24
24
  __exportStar(require("./catalog-actions"), exports);
25
25
  __exportStar(require("./common-order-actions"), exports);
26
26
  __exportStar(require("./common-tenant-purchase-order-actions"), exports);
27
- __exportStar(require("./common-warehouse-invoice-actions"), exports);
28
27
  __exportStar(require("./common-warehouse-internal-movement-actions"), exports);
29
28
  __exportStar(require("./common-warehouse-purchase-order-actions"), exports);
30
29
  __exportStar(require("./common-warehouse-purchase-order-receipt-actions"), exports);
@@ -35,7 +34,7 @@ __exportStar(require("./common-warehouse-sale-order-invoice-actions"), exports);
35
34
  __exportStar(require("./common-warehouse-sale-order-rfq-actions"), exports);
36
35
  __exportStar(require("./offline-ordering"), exports);
37
36
  __exportStar(require("./tenant-purchase-orders-cart-actions"), exports);
38
- __exportStar(require("./warehouse-invoice-cart-actions"), exports);
39
37
  __exportStar(require("./warehouse-purchase-order-rfq-cart-actions"), exports);
40
38
  __exportStar(require("./warehouse-purchase-orders-cart-actions"), exports);
41
39
  __exportStar(require("./warehouse-sale-order-rfq-cart-actions"), exports);
40
+ __exportStar(require("./warehouse-sale-orders-cart-actions"), exports);