@managesome/eposmatic-toolkit 0.2.454 → 0.2.457
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.
- package/lib/constants/WORKER_ENDPOINTS.d.ts +2 -0
- package/lib/constants/WORKER_ENDPOINTS.js +3 -0
- package/lib/helpers/store/common-warehouse-internal-movement-actions.d.ts +12 -0
- package/lib/helpers/store/common-warehouse-internal-movement-actions.js +33 -0
- package/lib/helpers/store/common-warehouse-purchase-order-receipt-actions.d.ts +12 -0
- package/lib/helpers/store/common-warehouse-purchase-order-receipt-actions.js +37 -0
- package/lib/helpers/store/index.d.ts +2 -0
- package/lib/helpers/store/index.js +2 -0
- package/lib/helpers/types/workers.d.ts +16 -1
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/warehouse_internal_movements.d.ts +3 -3
- package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_deliveries.d.ts +3 -3
- package/lib/schemas/models/warehouse_sale_invoices.d.ts +3 -3
- package/lib/schemas/types/index.d.ts +2 -0
- package/lib/schemas/types/index.js +2 -0
- package/package.json +1 -1
- package/lib/constants/PURCHASE_ORDER.d.ts +0 -16
- package/lib/constants/PURCHASE_ORDER.js +0 -100
- package/lib/constants/RFQ.d.ts +0 -0
- package/lib/constants/RFQ.js +0 -1
- package/lib/helpers/order/generate-purchase-order-rfq.d.ts +0 -3
- package/lib/helpers/order/generate-purchase-order-rfq.js +0 -64
- package/lib/helpers/order/generate-purchase-order.d.ts +0 -11
- package/lib/helpers/order/generate-purchase-order.js +0 -196
- package/lib/helpers/store/all-purchase-orders-actions.d.ts +0 -13
- package/lib/helpers/store/all-purchase-orders-actions.js +0 -56
- package/lib/helpers/store/all-sale-orders-actions.d.ts +0 -2
- package/lib/helpers/store/all-sale-orders-actions.js +0 -8
- package/lib/helpers/store/all-warehouse-sale-orders-actions.d.ts +0 -2
- package/lib/helpers/store/all-warehouse-sale-orders-actions.js +0 -8
- package/lib/helpers/store/common-purchase-order-actions.d.ts +0 -31
- package/lib/helpers/store/common-purchase-order-actions.js +0 -543
- package/lib/helpers/store/common-sale-order-actions.d.ts +0 -5
- package/lib/helpers/store/common-sale-order-actions.js +0 -65
- package/lib/helpers/store/purchase-order-rfq-cart-actions.d.ts +0 -19
- package/lib/helpers/store/purchase-order-rfq-cart-actions.js +0 -373
- package/lib/helpers/store/purchase-orders-cart-actions.d.ts +0 -57
- package/lib/helpers/store/purchase-orders-cart-actions.js +0 -486
- package/lib/helpers/types/purchase-order-cart-actions.d.ts +0 -26
- package/lib/helpers/types/purchase-order-cart-actions.js +0 -2
- package/lib/helpers/utils/invoice-x-report-helpers.d.ts +0 -58
- package/lib/helpers/utils/invoice-x-report-helpers.js +0 -1432
- package/lib/helpers/utils/purchase-order-engine.d.ts +0 -9
- package/lib/helpers/utils/purchase-order-engine.js +0 -34
- package/lib/helpers/utils/purchase-order-receipt-engine.d.ts +0 -149
- package/lib/helpers/utils/purchase-order-receipt-engine.js +0 -214
- package/lib/helpers/utils/purchase-order-x-report-helpers.d.ts +0 -58
- package/lib/helpers/utils/purchase-order-x-report-helpers.js +0 -1440
- package/lib/helpers/utils/sale-order-x-report-helpers.d.ts +0 -44
- package/lib/helpers/utils/sale-order-x-report-helpers.js +0 -22
- package/lib/helpers/utils/sale-x-report-helpers.d.ts +0 -58
- package/lib/helpers/utils/sale-x-report-helpers.js +0 -1456
- package/lib/helpers/utils/terminal-devices-helpers.d.ts +0 -2
- package/lib/helpers/utils/terminal-devices-helpers.js +0 -13
- package/lib/helpers/utils/void-purchase-order-items-helpers.d.ts +0 -3
- package/lib/helpers/utils/void-purchase-order-items-helpers.js +0 -38
- package/lib/helpers/utils/void-purchase-order-items-report-helpers.d.ts +0 -13
- package/lib/helpers/utils/void-purchase-order-items-report-helpers.js +0 -22
- package/lib/schemas/models/applied-order-discounts.d.ts +0 -80
- package/lib/schemas/models/applied-order-discounts.js +0 -106
- package/lib/schemas/models/brand.d.ts +0 -45
- package/lib/schemas/models/brand.js +0 -45
- package/lib/schemas/models/category.d.ts +0 -60
- package/lib/schemas/models/category.js +0 -67
- package/lib/schemas/models/dinein_table_fingerprints.d.ts +0 -65
- package/lib/schemas/models/dinein_table_fingerprints.js +0 -85
- package/lib/schemas/models/expense_category.d.ts +0 -83
- package/lib/schemas/models/expense_category.js +0 -64
- package/lib/schemas/models/internal_movements.d.ts +0 -357
- package/lib/schemas/models/internal_movements.js +0 -323
- package/lib/schemas/models/inventory.d.ts +0 -99
- package/lib/schemas/models/inventory.js +0 -87
- package/lib/schemas/models/inventory_lot_serial_numbers.d.ts +0 -154
- package/lib/schemas/models/inventory_lot_serial_numbers.js +0 -193
- package/lib/schemas/models/item.d.ts +0 -11269
- package/lib/schemas/models/item.js +0 -333
- package/lib/schemas/models/menu.d.ts +0 -941
- package/lib/schemas/models/menu.js +0 -69
- package/lib/schemas/models/order.d.ts +0 -15437
- package/lib/schemas/models/order.js +0 -891
- package/lib/schemas/models/purchase_order_receipts.d.ts +0 -165
- package/lib/schemas/models/purchase_order_receipts.js +0 -151
- package/lib/schemas/models/purchase_order_rfq.d.ts +0 -1959
- package/lib/schemas/models/purchase_order_rfq.js +0 -328
- package/lib/schemas/models/purchase_order_rfqs.d.ts +0 -1959
- package/lib/schemas/models/purchase_order_rfqs.js +0 -328
- package/lib/schemas/models/purchase_order_vendor_returns.d.ts +0 -234
- package/lib/schemas/models/purchase_order_vendor_returns.js +0 -188
- package/lib/schemas/models/purchase_orders.d.ts +0 -2678
- package/lib/schemas/models/purchase_orders.js +0 -336
- package/lib/schemas/models/rider.d.ts +0 -65
- package/lib/schemas/models/rider.js +0 -74
- package/lib/schemas/models/sale_order_deliveries.d.ts +0 -167
- package/lib/schemas/models/sale_order_deliveries.js +0 -155
- package/lib/schemas/models/sale_order_invoices.d.ts +0 -227
- package/lib/schemas/models/sale_order_invoices.js +0 -206
- package/lib/schemas/models/sale_order_rfq.d.ts +0 -1938
- package/lib/schemas/models/sale_order_rfq.js +0 -309
- package/lib/schemas/models/sale_orders.d.ts +0 -1943
- package/lib/schemas/models/sale_orders.js +0 -324
- package/lib/schemas/models/tenant.d.ts +0 -528
- package/lib/schemas/models/tenant.js +0 -755
- package/lib/schemas/models/tenant_staff.d.ts +0 -932
- package/lib/schemas/models/tenant_staff.js +0 -96
- package/lib/schemas/models/track_order_number.d.ts +0 -413
- package/lib/schemas/models/track_order_number.js +0 -45
- package/lib/schemas/models/void_purchase_order_items.d.ts +0 -176
- package/lib/schemas/models/void_purchase_order_items.js +0 -177
- package/lib/schemas/models/void_warehouse_invoice_items.d.ts +0 -176
- package/lib/schemas/models/void_warehouse_invoice_items.js +0 -176
- package/lib/schemas/models/wallet.d.ts +0 -38
- package/lib/schemas/models/wallet.js +0 -37
- package/lib/schemas/models/warehouse-communications.d.ts +0 -228
- package/lib/schemas/models/warehouse-communications.js +0 -216
- package/lib/schemas/models/warehouse.d.ts +0 -162
- package/lib/schemas/models/warehouse.js +0 -222
- package/lib/schemas/models/warehouse_staff.d.ts +0 -65
- package/lib/schemas/models/warehouse_staff.js +0 -78
- package/lib/schemas/models/warehouse_track_order_number.d.ts +0 -50
- package/lib/schemas/models/warehouse_track_order_number.js +0 -52
- package/lib/schemas/types/applied-order-discounts.d.ts +0 -22
- package/lib/schemas/types/applied-order-discounts.js +0 -2
- package/lib/schemas/types/brand.d.ts +0 -32
- package/lib/schemas/types/brand.js +0 -2
- package/lib/schemas/types/category.d.ts +0 -15
- package/lib/schemas/types/category.js +0 -2
- package/lib/schemas/types/expense_category.d.ts +0 -20
- package/lib/schemas/types/expense_category.js +0 -2
- package/lib/schemas/types/internal_movements.d.ts +0 -73
- package/lib/schemas/types/internal_movements.js +0 -2
- package/lib/schemas/types/inventory.d.ts +0 -48
- package/lib/schemas/types/inventory.js +0 -2
- package/lib/schemas/types/inventory_lot_serial_numbers.d.ts +0 -85
- package/lib/schemas/types/inventory_lot_serial_numbers.js +0 -4
- package/lib/schemas/types/item.d.ts +0 -89
- package/lib/schemas/types/item.js +0 -2
- package/lib/schemas/types/menu.d.ts +0 -17
- package/lib/schemas/types/menu.js +0 -2
- package/lib/schemas/types/order.d.ts +0 -242
- package/lib/schemas/types/order.js +0 -2
- package/lib/schemas/types/purchase_order_common.d.ts +0 -39
- package/lib/schemas/types/purchase_order_common.js +0 -2
- package/lib/schemas/types/purchase_order_receipts.d.ts +0 -39
- package/lib/schemas/types/purchase_order_receipts.js +0 -21
- package/lib/schemas/types/purchase_order_rfq.d.ts +0 -33
- package/lib/schemas/types/purchase_order_rfq.js +0 -2
- package/lib/schemas/types/purchase_order_rfqs.d.ts +0 -33
- package/lib/schemas/types/purchase_order_rfqs.js +0 -2
- package/lib/schemas/types/purchase_order_vendor_returns.d.ts +0 -49
- package/lib/schemas/types/purchase_order_vendor_returns.js +0 -42
- package/lib/schemas/types/purchase_orders.d.ts +0 -33
- package/lib/schemas/types/purchase_orders.js +0 -2
- package/lib/schemas/types/rider.d.ts +0 -16
- package/lib/schemas/types/rider.js +0 -2
- package/lib/schemas/types/sale_order_common.d.ts +0 -39
- package/lib/schemas/types/sale_order_common.js +0 -2
- package/lib/schemas/types/sale_order_deliveries.d.ts +0 -67
- package/lib/schemas/types/sale_order_deliveries.js +0 -2
- package/lib/schemas/types/sale_order_invoices.d.ts +0 -49
- package/lib/schemas/types/sale_order_invoices.js +0 -2
- package/lib/schemas/types/sale_order_rfq.d.ts +0 -25
- package/lib/schemas/types/sale_order_rfq.js +0 -2
- package/lib/schemas/types/sale_orders.d.ts +0 -30
- package/lib/schemas/types/sale_orders.js +0 -2
- package/lib/schemas/types/tenant.d.ts +0 -205
- package/lib/schemas/types/tenant.js +0 -2
- package/lib/schemas/types/tenant_staff.d.ts +0 -22
- package/lib/schemas/types/tenant_staff.js +0 -2
- package/lib/schemas/types/track_order_number.d.ts +0 -10
- package/lib/schemas/types/track_order_number.js +0 -2
- package/lib/schemas/types/void_purchase_order_items.d.ts +0 -37
- package/lib/schemas/types/void_purchase_order_items.js +0 -2
- package/lib/schemas/types/void_warehouse_invoice_items.d.ts +0 -37
- package/lib/schemas/types/void_warehouse_invoice_items.js +0 -2
- package/lib/schemas/types/wallet.d.ts +0 -7
- package/lib/schemas/types/wallet.js +0 -2
- package/lib/schemas/types/warehouse-communications.d.ts +0 -54
- package/lib/schemas/types/warehouse-communications.js +0 -2
- package/lib/schemas/types/warehouse.d.ts +0 -49
- package/lib/schemas/types/warehouse.js +0 -2
- package/lib/schemas/types/warehouse_purchase_order_common.d.ts +0 -39
- package/lib/schemas/types/warehouse_purchase_order_common.js +0 -2
- package/lib/schemas/types/warehouse_sale_order_common.d.ts +0 -39
- package/lib/schemas/types/warehouse_sale_order_common.js +0 -2
- package/lib/schemas/types/warehouse_staff.d.ts +0 -17
- package/lib/schemas/types/warehouse_staff.js +0 -2
- package/lib/schemas/types/warehouse_track_order_number.d.ts +0 -11
- package/lib/schemas/types/warehouse_track_order_number.js +0 -2
|
@@ -1,373 +0,0 @@
|
|
|
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
|
-
* WarehouseIPurchaseOrderRFQCategory ≡ IPurchaseOrderCategory (same type),
|
|
21
|
-
* WarehouseIPurchaseOrderRFQItem ≡ WarehouseIPurchaseOrderItem (same type).
|
|
22
|
-
* ================================================================= */
|
|
23
|
-
function calculateCartRfqOrderInfoAndSyncData(data, calculateItemMetadata) {
|
|
24
|
-
const isConfirmed = data.order_status === constants_1.WAREHOUSE_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
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { WAREHOUSE_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
|
|
2
|
-
import { WarehouseIPurchaseOrder, WarehouseIPurchaseOrderItem, WarehouseIPurchaseOrderIteration } from '../../schemas';
|
|
3
|
-
export declare function calculateCartPurchaseOrderInfoAndSyncData<T extends WarehouseIPurchaseOrder | Partial<WarehouseIPurchaseOrder>>(data: T, calculateItemMetadata?: boolean): T;
|
|
4
|
-
export declare const getPurchaseOrderItemComaparableData: (item: WarehouseIPurchaseOrderItem) => Partial<WarehouseIPurchaseOrderItem>;
|
|
5
|
-
export declare function getUpdatedPurchaseOrderCartInfoOnInit(data: Partial<WarehouseIPurchaseOrder>, order: Partial<WarehouseIPurchaseOrder>): {
|
|
6
|
-
_id?: string | undefined;
|
|
7
|
-
warehouse_id?: string | undefined;
|
|
8
|
-
vendor_id?: string | undefined;
|
|
9
|
-
vendor_name?: string | undefined;
|
|
10
|
-
rfq_id?: string | null;
|
|
11
|
-
iterations?: WarehouseIPurchaseOrderIteration[] | undefined;
|
|
12
|
-
amount_collected?: number | undefined;
|
|
13
|
-
order_number?: number | null | undefined;
|
|
14
|
-
delete_reason?: string | null;
|
|
15
|
-
cancel_reason?: string | null;
|
|
16
|
-
is_deleted?: boolean | undefined;
|
|
17
|
-
order_status_updated_at?: Date | undefined;
|
|
18
|
-
is_reopened?: boolean;
|
|
19
|
-
deferred_settlement?: boolean;
|
|
20
|
-
order_settled_at?: Date | undefined;
|
|
21
|
-
order_settled_at_mins?: number | undefined;
|
|
22
|
-
createdAt_mins?: number | undefined;
|
|
23
|
-
createdAt?: Date | undefined;
|
|
24
|
-
payments?: import("../../schemas").IOrderPayment[] | undefined;
|
|
25
|
-
tax_number?: string | undefined;
|
|
26
|
-
categories?: import("../../schemas").WarehouseIPurchaseOrderCommonCategoryByCategoryId[] | undefined;
|
|
27
|
-
staff_details?: import("../../schemas").IStaffDetails | undefined;
|
|
28
|
-
is_gst_inclusive?: boolean;
|
|
29
|
-
gst?: number | null;
|
|
30
|
-
gst_amount?: number | null;
|
|
31
|
-
special_instructions?: string | undefined;
|
|
32
|
-
price?: number | undefined;
|
|
33
|
-
amount_earned?: number | undefined;
|
|
34
|
-
grand_total?: number | undefined;
|
|
35
|
-
order_status?: WAREHOUSE_PURCHASE_ORDER_STATUS_ENUM | undefined;
|
|
36
|
-
updatedAt?: Date | undefined;
|
|
37
|
-
};
|
|
38
|
-
export declare function getRemoveItemFromPurchaseOrderCartData(data: Partial<WarehouseIPurchaseOrder>, payload: {
|
|
39
|
-
_id: string;
|
|
40
|
-
void_reason?: string;
|
|
41
|
-
}): Partial<WarehouseIPurchaseOrder>;
|
|
42
|
-
export declare function getUpdatePurchaseOrderCartInfoData(data: Partial<WarehouseIPurchaseOrder>, payload: Partial<WarehouseIPurchaseOrder>): Partial<WarehouseIPurchaseOrder>;
|
|
43
|
-
export interface ISetAddItemToPurchaseOrderCartActionPayload {
|
|
44
|
-
name: string;
|
|
45
|
-
category_id: string;
|
|
46
|
-
item: WarehouseIPurchaseOrderItem;
|
|
47
|
-
replace_id?: string;
|
|
48
|
-
}
|
|
49
|
-
export declare function getAddItemToPurchaseOrderCartData(data: Partial<WarehouseIPurchaseOrder>, payload: ISetAddItemToPurchaseOrderCartActionPayload): Partial<WarehouseIPurchaseOrder>;
|
|
50
|
-
export declare function getUpdateItemInPurchaseOrderCartData(data: Partial<WarehouseIPurchaseOrder>, payload: Partial<WarehouseIPurchaseOrderItem>): Partial<WarehouseIPurchaseOrder>;
|
|
51
|
-
export declare function getUpdateItemsInPurchaseOrderCartData(data: Partial<WarehouseIPurchaseOrder>, payload: Partial<WarehouseIPurchaseOrderItem>[]): Partial<WarehouseIPurchaseOrder>;
|
|
52
|
-
export interface IGetSplitPurchaseOrderCartItemToTwo {
|
|
53
|
-
data: Partial<WarehouseIPurchaseOrder>;
|
|
54
|
-
orderItemId: string;
|
|
55
|
-
}
|
|
56
|
-
export declare function getSplitPurchaseOrderCartItemToTwo({ data, orderItemId, }: IGetSplitPurchaseOrderCartItemToTwo): Partial<WarehouseIPurchaseOrder>;
|
|
57
|
-
export declare function getAddItemsToPurchaseOrderCartData(data: Partial<WarehouseIPurchaseOrder>, payload: ISetAddItemToPurchaseOrderCartActionPayload[]): Partial<WarehouseIPurchaseOrder>;
|