@managesome/eposmatic-toolkit 0.2.431 → 0.2.433
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/ENUMS.d.ts +0 -289
- package/lib/constants/ENUMS.js +2 -393
- package/lib/constants/PURCHASE_ORDER.d.ts +5 -3
- package/lib/constants/PURCHASE_ORDER.js +58 -20
- package/lib/constants/WAREHOUSE_ANALYTICS.d.ts +41 -41
- package/lib/constants/WAREHOUSE_ANALYTICS.js +28 -28
- package/lib/constants/WAREHOUSE_ENUMS.d.ts +289 -0
- package/lib/constants/WAREHOUSE_ENUMS.js +392 -0
- package/lib/constants/WAREHOUSE_INVOICE.js +10 -10
- package/lib/constants/WORKER_ENDPOINTS.d.ts +63 -0
- package/lib/constants/WORKER_ENDPOINTS.js +76 -0
- package/lib/constants/index.d.ts +2 -0
- package/lib/constants/index.js +2 -0
- package/lib/helpers/order/generate-purchase-order-rfq.d.ts +3 -3
- package/lib/helpers/order/generate-purchase-order-rfq.js +2 -2
- package/lib/helpers/order/generate-purchase-order.d.ts +8 -8
- package/lib/helpers/order/generate-purchase-order.js +2 -2
- package/lib/helpers/order/generate-warehouse-purchase-order-rfq.d.ts +3 -0
- package/lib/helpers/order/generate-warehouse-purchase-order-rfq.js +64 -0
- package/lib/helpers/order/generate-warehouse-purchase-order.d.ts +11 -0
- package/lib/helpers/order/generate-warehouse-purchase-order.js +196 -0
- package/lib/helpers/order/index.d.ts +2 -2
- package/lib/helpers/order/index.js +2 -2
- package/lib/helpers/store/all-purchase-orders-actions.d.ts +7 -7
- package/lib/helpers/store/all-purchase-orders-actions.js +2 -2
- package/lib/helpers/store/all-sale-orders-actions.d.ts +2 -2
- package/lib/helpers/store/all-warehouse-purchase-orders-actions.d.ts +13 -0
- package/lib/helpers/store/all-warehouse-purchase-orders-actions.js +56 -0
- package/lib/helpers/store/all-warehouse-sale-orders-actions.d.ts +2 -0
- package/lib/helpers/store/all-warehouse-sale-orders-actions.js +8 -0
- package/lib/helpers/store/common-purchase-order-actions.d.ts +15 -15
- package/lib/helpers/store/common-sale-order-actions.d.ts +5 -5
- package/lib/helpers/store/common-warehouse-purchase-order-actions.d.ts +31 -0
- package/lib/helpers/store/common-warehouse-purchase-order-actions.js +545 -0
- package/lib/helpers/store/common-warehouse-sale-order-actions.d.ts +5 -0
- package/lib/helpers/store/common-warehouse-sale-order-actions.js +65 -0
- package/lib/helpers/store/index.d.ts +6 -6
- package/lib/helpers/store/index.js +6 -6
- package/lib/helpers/store/purchase-order-rfq-cart-actions.d.ts +11 -11
- package/lib/helpers/store/purchase-order-rfq-cart-actions.js +3 -3
- package/lib/helpers/store/purchase-orders-cart-actions.d.ts +18 -18
- package/lib/helpers/store/purchase-orders-cart-actions.js +1 -1
- package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.d.ts +19 -0
- package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +373 -0
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.d.ts +57 -0
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +486 -0
- package/lib/helpers/types/index.d.ts +1 -1
- package/lib/helpers/types/index.js +1 -1
- package/lib/helpers/types/purchase-order-cart-actions.d.ts +2 -2
- package/lib/helpers/types/warehouse-purchase-order-cart-actions.d.ts +26 -0
- package/lib/helpers/types/warehouse-purchase-order-cart-actions.js +2 -0
- package/lib/helpers/types/workers.d.ts +39 -32
- package/lib/helpers/utils/index.d.ts +8 -8
- package/lib/helpers/utils/index.js +8 -11
- package/lib/helpers/utils/invoice-x-report-helpers.d.ts +2 -2
- package/lib/helpers/utils/invoice-x-report-helpers.js +14 -14
- package/lib/helpers/utils/purchase-order-engine.d.ts +4 -4
- package/lib/helpers/utils/purchase-order-receipt-engine.d.ts +5 -5
- package/lib/helpers/utils/purchase-order-receipt-engine.js +2 -2
- package/lib/helpers/utils/purchase-order-x-report-helpers.js +2 -2
- package/lib/helpers/utils/sale-x-report-helpers.js +2 -2
- package/lib/helpers/utils/void-purchase-order-items-helpers.d.ts +3 -3
- package/lib/helpers/utils/void-purchase-order-items-report-helpers.d.ts +2 -2
- package/lib/helpers/utils/void-warehouse-invoice-items-helpers.d.ts +3 -3
- package/lib/helpers/utils/void-warehouse-invoice-items-helpers.js +2 -2
- package/lib/helpers/utils/void-warehouse-invoice-items-report-helpers.d.ts +5 -5
- package/lib/helpers/utils/warehouse-catalog-conversion.d.ts +3 -3
- package/lib/helpers/utils/warehouse-catalog-conversion.js +9 -7
- package/lib/helpers/utils/warehouse-invoice-order-engine.js +1 -1
- package/lib/helpers/utils/warehouse-invoice-x-report-helpers.d.ts +58 -0
- package/lib/helpers/utils/warehouse-invoice-x-report-helpers.js +1432 -0
- package/lib/helpers/utils/warehouse-purchase-order-engine.d.ts +9 -0
- package/lib/helpers/utils/warehouse-purchase-order-engine.js +34 -0
- package/lib/helpers/utils/warehouse-purchase-order-receipt-engine.d.ts +149 -0
- package/lib/helpers/utils/warehouse-purchase-order-receipt-engine.js +214 -0
- package/lib/helpers/utils/warehouse-purchase-order-x-report-helpers.d.ts +58 -0
- package/lib/helpers/utils/warehouse-purchase-order-x-report-helpers.js +1440 -0
- package/lib/helpers/utils/warehouse-sale-order-x-report-helpers.d.ts +30 -0
- package/lib/helpers/utils/warehouse-sale-order-x-report-helpers.js +2 -0
- package/lib/helpers/utils/warehouse-sale-x-report-helpers.d.ts +58 -0
- package/lib/helpers/utils/warehouse-sale-x-report-helpers.js +1456 -0
- package/lib/helpers/utils/warehouse-void-purchase-order-items-helpers.d.ts +3 -0
- package/lib/helpers/utils/warehouse-void-purchase-order-items-helpers.js +38 -0
- package/lib/helpers/utils/warehouse-void-purchase-order-items-report-helpers.d.ts +13 -0
- package/lib/helpers/utils/warehouse-void-purchase-order-items-report-helpers.js +22 -0
- package/lib/schemas/models/gift_cards.d.ts +108 -108
- package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
- package/lib/schemas/models/index.d.ts +7 -7
- package/lib/schemas/models/index.js +7 -7
- package/lib/schemas/models/internal_invoices.d.ts +6 -6
- package/lib/schemas/models/inventory_lot_serial_numbers.d.ts +6 -6
- package/lib/schemas/models/inventory_transactions.d.ts +3 -3
- package/lib/schemas/models/item_transactions.d.ts +6 -6
- package/lib/schemas/models/offers.d.ts +146 -146
- package/lib/schemas/models/orders.d.ts +2573 -2573
- package/lib/schemas/models/printer_settings.d.ts +12 -12
- package/lib/schemas/models/reservations.d.ts +6 -6
- package/lib/schemas/models/rewards_usage.d.ts +6 -6
- package/lib/schemas/models/riders.d.ts +3 -3
- package/lib/schemas/models/tenants.d.ts +135 -135
- package/lib/schemas/models/void_order_items.d.ts +15 -15
- package/lib/schemas/models/void_warehouse_invoice_items.d.ts +25 -25
- package/lib/schemas/models/void_warehouse_invoice_items.js +2 -2
- package/lib/schemas/models/vouchers.d.ts +9 -9
- package/lib/schemas/models/warehouse-activity-logs.d.ts +13 -13
- package/lib/schemas/models/warehouse-activity-logs.js +4 -4
- package/lib/schemas/models/warehouse_categories.d.ts +4 -4
- package/lib/schemas/models/warehouse_categories.js +2 -2
- package/lib/schemas/models/warehouse_communications.d.ts +21 -21
- package/lib/schemas/models/warehouse_internal_movements.d.ts +33 -33
- package/lib/schemas/models/warehouse_internal_movements.js +8 -8
- package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.d.ts +154 -0
- package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.js +193 -0
- package/lib/schemas/models/warehouse_inventory_transactions.d.ts +6 -6
- package/lib/schemas/models/warehouse_invoices.d.ts +351 -351
- package/lib/schemas/models/warehouse_item_transactions.d.ts +9 -9
- package/lib/schemas/models/warehouse_items.d.ts +13 -13
- package/lib/schemas/models/warehouse_items.js +2 -2
- package/lib/schemas/models/warehouse_operational_roles.d.ts +3 -3
- package/lib/schemas/models/warehouse_purchase_order_receipts.d.ts +165 -0
- package/lib/schemas/models/warehouse_purchase_order_receipts.js +151 -0
- package/lib/schemas/models/warehouse_purchase_order_rfqs.d.ts +1959 -0
- package/lib/schemas/models/warehouse_purchase_order_rfqs.js +328 -0
- package/lib/schemas/models/warehouse_purchase_order_vendor_returns.d.ts +234 -0
- package/lib/schemas/models/warehouse_purchase_order_vendor_returns.js +188 -0
- package/lib/schemas/models/warehouse_purchase_orders.d.ts +2678 -0
- package/lib/schemas/models/warehouse_purchase_orders.js +336 -0
- package/lib/schemas/models/warehouse_sale_deliveries.d.ts +15 -15
- package/lib/schemas/models/warehouse_sale_deliveries.js +7 -4
- package/lib/schemas/models/warehouse_sale_invoices.d.ts +30 -30
- package/lib/schemas/models/warehouse_sale_invoices.js +8 -5
- package/lib/schemas/models/warehouse_sale_order_rfqs.d.ts +362 -362
- package/lib/schemas/models/warehouse_sale_order_rfqs.js +5 -5
- package/lib/schemas/models/warehouse_sale_orders.d.ts +367 -367
- package/lib/schemas/models/warehouse_sale_orders.js +5 -5
- package/lib/schemas/models/warehouse_void_invoice_items.d.ts +176 -0
- package/lib/schemas/models/warehouse_void_invoice_items.js +176 -0
- package/lib/schemas/models/warehouse_void_purchase_order_items.d.ts +176 -0
- package/lib/schemas/models/warehouse_void_purchase_order_items.js +177 -0
- package/lib/schemas/models/warehouses.d.ts +52 -52
- package/lib/schemas/models/warehouses.js +2 -2
- package/lib/schemas/types/index.d.ts +9 -9
- package/lib/schemas/types/index.js +9 -9
- package/lib/schemas/types/inventory_lot_serial_numbers.d.ts +5 -5
- package/lib/schemas/types/warehouse-activity-logs.d.ts +7 -7
- package/lib/schemas/types/warehouse_categories.d.ts +2 -2
- package/lib/schemas/types/warehouse_internal_movements.d.ts +9 -9
- package/lib/schemas/types/warehouse_inventory_lot_serial_numbers.d.ts +85 -0
- package/lib/schemas/types/warehouse_inventory_lot_serial_numbers.js +4 -0
- package/lib/schemas/types/warehouse_items.d.ts +2 -2
- package/lib/schemas/types/warehouse_purchase_order_common.d.ts +39 -0
- package/lib/schemas/types/warehouse_purchase_order_common.js +2 -0
- package/lib/schemas/types/warehouse_purchase_order_receipts.d.ts +39 -0
- package/lib/schemas/types/warehouse_purchase_order_receipts.js +21 -0
- package/lib/schemas/types/warehouse_purchase_order_rfqs.d.ts +33 -0
- package/lib/schemas/types/warehouse_purchase_order_rfqs.js +2 -0
- package/lib/schemas/types/warehouse_purchase_order_vendor_returns.d.ts +48 -0
- package/lib/schemas/types/warehouse_purchase_order_vendor_returns.js +2 -0
- package/lib/schemas/types/warehouse_purchase_orders.d.ts +33 -0
- package/lib/schemas/types/warehouse_purchase_orders.js +2 -0
- package/lib/schemas/types/warehouse_sale_deliveries.d.ts +29 -29
- package/lib/schemas/types/warehouse_sale_invoices.d.ts +17 -17
- package/lib/schemas/types/warehouse_sale_order_common.d.ts +39 -0
- package/lib/schemas/types/warehouse_sale_order_common.js +2 -0
- package/lib/schemas/types/warehouse_sale_order_rfqs.d.ts +7 -7
- package/lib/schemas/types/warehouse_sale_orders.d.ts +7 -7
- package/lib/schemas/types/warehouse_void_invoice_items.d.ts +37 -0
- package/lib/schemas/types/warehouse_void_invoice_items.js +2 -0
- package/lib/schemas/types/warehouse_void_purchase_order_items.d.ts +37 -0
- package/lib/schemas/types/warehouse_void_purchase_order_items.js +2 -0
- package/lib/schemas/types/warehouses.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,486 @@
|
|
|
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.getWarehousePurchaseOrderItemComaparableData = void 0;
|
|
7
|
+
exports.calculateCartWarehousePurchaseOrderInfoAndSyncData = calculateCartWarehousePurchaseOrderInfoAndSyncData;
|
|
8
|
+
exports.getUpdatedWarehousePurchaseOrderCartInfoOnInit = getUpdatedWarehousePurchaseOrderCartInfoOnInit;
|
|
9
|
+
exports.getRemoveItemFromWarehousePurchaseOrderCartData = getRemoveItemFromWarehousePurchaseOrderCartData;
|
|
10
|
+
exports.getUpdateWarehousePurchaseOrderCartInfoData = getUpdateWarehousePurchaseOrderCartInfoData;
|
|
11
|
+
exports.getAddItemToWarehousePurchaseOrderCartData = getAddItemToWarehousePurchaseOrderCartData;
|
|
12
|
+
exports.getUpdateItemInWarehousePurchaseOrderCartData = getUpdateItemInWarehousePurchaseOrderCartData;
|
|
13
|
+
exports.getUpdateItemsInWarehousePurchaseOrderCartData = getUpdateItemsInWarehousePurchaseOrderCartData;
|
|
14
|
+
exports.getSplitWarehousePurchaseOrderCartItemToTwo = getSplitWarehousePurchaseOrderCartItemToTwo;
|
|
15
|
+
exports.getAddItemsToWarehousePurchaseOrderCartData = getAddItemsToWarehousePurchaseOrderCartData;
|
|
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
|
+
function calculateCartWarehousePurchaseOrderInfoAndSyncData(data, calculateItemMetadata) {
|
|
21
|
+
const isCompleted = data.order_status === constants_1.WAREHOUSE_PURCHASE_ORDER_STATUS_ENUM.COMPLETED;
|
|
22
|
+
/* ===============================><=============================== */
|
|
23
|
+
let subtotal = 0;
|
|
24
|
+
const categories = [];
|
|
25
|
+
const length = data.categories?.length ?? 0;
|
|
26
|
+
for (let c = 0; c < length; c++) {
|
|
27
|
+
const category = data.categories[c];
|
|
28
|
+
const newItems = [];
|
|
29
|
+
const itemsLength = category.items.length;
|
|
30
|
+
for (let i = 0; i < itemsLength; i++) {
|
|
31
|
+
const item = category.items[i];
|
|
32
|
+
// For purchase orders, subtotal is already set as price * quantity
|
|
33
|
+
// But to ensure, we can recalculate
|
|
34
|
+
const itemSubtotal = (0, utils_1.parseNum)(item.price * item.quantity);
|
|
35
|
+
const newItem = {
|
|
36
|
+
...item,
|
|
37
|
+
is_ready: item.is_ready || isCompleted,
|
|
38
|
+
subtotal: itemSubtotal,
|
|
39
|
+
// These values will be auto calculated
|
|
40
|
+
_discount_amount: 0,
|
|
41
|
+
_gross_amount: 0,
|
|
42
|
+
_gst_amount: 0,
|
|
43
|
+
_net_amount: 0,
|
|
44
|
+
};
|
|
45
|
+
delete newItem.void_reason;
|
|
46
|
+
newItems.push(newItem);
|
|
47
|
+
subtotal += itemSubtotal;
|
|
48
|
+
}
|
|
49
|
+
categories.push({
|
|
50
|
+
...category,
|
|
51
|
+
items: newItems,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
let grand_total = subtotal;
|
|
55
|
+
// GST is represented in percentage. We convert it to decimal
|
|
56
|
+
let gst_amount = 0;
|
|
57
|
+
const gst = data.gst ?? 0;
|
|
58
|
+
if (data.is_gst_inclusive) {
|
|
59
|
+
// If GST is inclusive, it means that the Tax is already included in the Sale Value
|
|
60
|
+
// However, we need to calculate the Sale Value without the Tax
|
|
61
|
+
// And then calculate the Tax amount from the Sale Value without Tax
|
|
62
|
+
gst_amount = (0, utils_1.parseFloatCeil)((grand_total * gst) / (100 + gst));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
gst_amount = (0, utils_1.getPercentageAmount)(grand_total, gst);
|
|
66
|
+
// Add GST amount to orderSubtotal
|
|
67
|
+
grand_total += gst_amount;
|
|
68
|
+
}
|
|
69
|
+
// Add Card Charges to grand_total
|
|
70
|
+
const { cardCharges, amountCollected } = (0, utils_1.getCardChargesAndAmountCollected)(data.payments);
|
|
71
|
+
grand_total += cardCharges;
|
|
72
|
+
grand_total = (0, utils_1.parseNum)(grand_total);
|
|
73
|
+
const amount_collected = (0, utils_1.parseNum)(amountCollected);
|
|
74
|
+
const amount_earned = (0, utils_1.parseNum)(grand_total - cardCharges);
|
|
75
|
+
if (calculateItemMetadata) {
|
|
76
|
+
let leftGrossAmount = subtotal;
|
|
77
|
+
let leftNetAmount = subtotal;
|
|
78
|
+
let leftDiscountAmount = 0; // No discounts
|
|
79
|
+
let leftGstAmount = gst_amount;
|
|
80
|
+
categories.forEach((category, categoryIndex) => {
|
|
81
|
+
const isLastCategory = categoryIndex === categories.length - 1;
|
|
82
|
+
category.items.forEach((item, itemIndex) => {
|
|
83
|
+
const isLastItem = isLastCategory && itemIndex === category.items.length - 1;
|
|
84
|
+
let grossAmount = item.subtotal; // No discounts, so gross = subtotal
|
|
85
|
+
let netAmount = item.subtotal; // No discounts
|
|
86
|
+
let itemTotalDiscountAmount = 0; // No discounts
|
|
87
|
+
let itemGst = 0;
|
|
88
|
+
if (gst_amount > 0) {
|
|
89
|
+
itemGst = (item.subtotal / subtotal) * gst_amount;
|
|
90
|
+
}
|
|
91
|
+
grossAmount = (0, utils_1.parseFloatCeil)(grossAmount);
|
|
92
|
+
const netAmountParsed = (0, utils_1.parseFloatCeil)(netAmount);
|
|
93
|
+
const itemTotalDiscountAmountParsed = (0, utils_1.parseFloatCeil)(itemTotalDiscountAmount);
|
|
94
|
+
itemGst = (0, utils_1.parseFloatCeil)(itemGst);
|
|
95
|
+
leftGrossAmount -= grossAmount;
|
|
96
|
+
leftNetAmount -= netAmountParsed;
|
|
97
|
+
leftDiscountAmount -= itemTotalDiscountAmountParsed;
|
|
98
|
+
leftGstAmount -= itemGst;
|
|
99
|
+
if (isLastItem) {
|
|
100
|
+
grossAmount += leftGrossAmount;
|
|
101
|
+
netAmount += leftNetAmount;
|
|
102
|
+
itemTotalDiscountAmount += leftDiscountAmount;
|
|
103
|
+
itemGst += leftGstAmount;
|
|
104
|
+
}
|
|
105
|
+
item._gross_amount = Math.max(grossAmount, 0);
|
|
106
|
+
item._net_amount = Math.max(netAmount, 0);
|
|
107
|
+
item._discount_amount = Math.max(itemTotalDiscountAmount, 0);
|
|
108
|
+
item._gst_amount = Math.max(itemGst, 0);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const cartData = {
|
|
113
|
+
...data,
|
|
114
|
+
categories,
|
|
115
|
+
amount_collected,
|
|
116
|
+
amount_earned,
|
|
117
|
+
gst_amount,
|
|
118
|
+
price: (0, utils_1.parseNum)(subtotal),
|
|
119
|
+
grand_total,
|
|
120
|
+
};
|
|
121
|
+
return cartData;
|
|
122
|
+
}
|
|
123
|
+
const getWarehousePurchaseOrderItemComaparableData = (item) => ({
|
|
124
|
+
item_id: item.item_id,
|
|
125
|
+
name: item.name,
|
|
126
|
+
price: item.price,
|
|
127
|
+
special_instructions: item.special_instructions,
|
|
128
|
+
_id: item._id,
|
|
129
|
+
quantity: item.quantity,
|
|
130
|
+
});
|
|
131
|
+
exports.getWarehousePurchaseOrderItemComaparableData = getWarehousePurchaseOrderItemComaparableData;
|
|
132
|
+
const getUpdatedPurchaseOrderItem = (item) => ({
|
|
133
|
+
item_id: item.item_id,
|
|
134
|
+
name: item.name,
|
|
135
|
+
price: item.price,
|
|
136
|
+
special_instructions: item.special_instructions,
|
|
137
|
+
});
|
|
138
|
+
// =====================><=====================
|
|
139
|
+
function getUpdatedWarehousePurchaseOrderCartInfoOnInit(data, order) {
|
|
140
|
+
const merged = { ...data, ...order };
|
|
141
|
+
return calculateCartWarehousePurchaseOrderInfoAndSyncData(merged);
|
|
142
|
+
}
|
|
143
|
+
function getRemoveItemFromWarehousePurchaseOrderCartData(data, payload) {
|
|
144
|
+
const orderItemIdsMap = {};
|
|
145
|
+
let categories;
|
|
146
|
+
if (data.categories != null) {
|
|
147
|
+
categories = [];
|
|
148
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
149
|
+
const category = data.categories[i];
|
|
150
|
+
const items = [];
|
|
151
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
152
|
+
const item = category.items[j];
|
|
153
|
+
if (item._id !== payload._id) {
|
|
154
|
+
items.push(item);
|
|
155
|
+
orderItemIdsMap[item._id] = item.quantity;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (items.length > 0) {
|
|
159
|
+
categories.push({
|
|
160
|
+
...category,
|
|
161
|
+
items,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const iterations = [];
|
|
167
|
+
if (data.iterations != null && data.iterations.length > 0) {
|
|
168
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
169
|
+
const firstIterationCategories = [];
|
|
170
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
171
|
+
const category = firstIteration.categories[i];
|
|
172
|
+
const allPrevItems = [];
|
|
173
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
174
|
+
const prevItem = category.items[j];
|
|
175
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
176
|
+
const newItem = {
|
|
177
|
+
...prevItem,
|
|
178
|
+
void_reason: payload.void_reason,
|
|
179
|
+
};
|
|
180
|
+
allPrevItems.push(newItem);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// A Removed Item is one that is not in the orderItemIdsMap
|
|
184
|
+
// Or it is in the orderItemIdsMap but its quantity is less than newItem.quantity
|
|
185
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
186
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
187
|
+
if (isRemovedItem) {
|
|
188
|
+
allPrevItems.push(prevItem);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// If the item is not removed, then we make sure to remove the void_reason
|
|
192
|
+
const updatedPrevItem = {
|
|
193
|
+
...prevItem,
|
|
194
|
+
};
|
|
195
|
+
delete updatedPrevItem.void_reason;
|
|
196
|
+
allPrevItems.push(updatedPrevItem);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (allPrevItems.length > 0) {
|
|
201
|
+
firstIterationCategories.push({
|
|
202
|
+
...category,
|
|
203
|
+
items: allPrevItems,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const firstIterationData = {
|
|
208
|
+
...firstIteration,
|
|
209
|
+
categories: firstIterationCategories,
|
|
210
|
+
};
|
|
211
|
+
iterations.push(firstIterationData);
|
|
212
|
+
iterations.push(...restIterations);
|
|
213
|
+
}
|
|
214
|
+
const order = {
|
|
215
|
+
...data,
|
|
216
|
+
...(iterations.length > 0 && { iterations }),
|
|
217
|
+
categories,
|
|
218
|
+
};
|
|
219
|
+
const newData = calculateCartWarehousePurchaseOrderInfoAndSyncData(order);
|
|
220
|
+
return newData;
|
|
221
|
+
}
|
|
222
|
+
function getUpdateWarehousePurchaseOrderCartInfoData(data, payload) {
|
|
223
|
+
const order = {
|
|
224
|
+
...data,
|
|
225
|
+
...payload,
|
|
226
|
+
};
|
|
227
|
+
const newData = calculateCartWarehousePurchaseOrderInfoAndSyncData(order);
|
|
228
|
+
return newData;
|
|
229
|
+
}
|
|
230
|
+
function getAddItemToWarehousePurchaseOrderCartData(data, payload) {
|
|
231
|
+
const { category_id, name, item, replace_id } = payload;
|
|
232
|
+
let mainItemId = item._id;
|
|
233
|
+
const orderData = { ...data };
|
|
234
|
+
// =====================><=====================
|
|
235
|
+
const categories = [...(orderData.categories ?? [])];
|
|
236
|
+
let didFindCategory = false;
|
|
237
|
+
const categoriesLength = categories.length;
|
|
238
|
+
for (let i = 0; i < categoriesLength; i++) {
|
|
239
|
+
const category = categories[i];
|
|
240
|
+
if (category.category_id !== category_id)
|
|
241
|
+
continue;
|
|
242
|
+
const updatedItem = getUpdatedPurchaseOrderItem(item);
|
|
243
|
+
const allItems = [...category.items];
|
|
244
|
+
let didFindItem = false;
|
|
245
|
+
let itemExists = false;
|
|
246
|
+
const totalItems = allItems.length;
|
|
247
|
+
for (let j = 0; j < totalItems; j++) {
|
|
248
|
+
const itm = allItems[j];
|
|
249
|
+
if (itm._id === item._id) {
|
|
250
|
+
allItems[j] = item;
|
|
251
|
+
didFindItem = true;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (itm.item_id === item.item_id) {
|
|
255
|
+
itemExists = true;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!didFindItem && itemExists) {
|
|
259
|
+
for (let j = 0; j < totalItems; j++) {
|
|
260
|
+
const itm = allItems[j];
|
|
261
|
+
if (itm.item_id === item.item_id && (0, lodash_1.isEqual)(getUpdatedPurchaseOrderItem(itm), updatedItem)) {
|
|
262
|
+
mainItemId = replace_id ?? itm._id;
|
|
263
|
+
allItems[j] = {
|
|
264
|
+
...item,
|
|
265
|
+
_id: mainItemId,
|
|
266
|
+
quantity: item.quantity + itm.quantity,
|
|
267
|
+
};
|
|
268
|
+
didFindItem = true;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!didFindItem) {
|
|
274
|
+
allItems.push(item);
|
|
275
|
+
}
|
|
276
|
+
categories[i] = {
|
|
277
|
+
...category,
|
|
278
|
+
items: allItems,
|
|
279
|
+
};
|
|
280
|
+
didFindCategory = true;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
if (!didFindCategory) {
|
|
284
|
+
categories.push({
|
|
285
|
+
category_id,
|
|
286
|
+
name,
|
|
287
|
+
items: [item],
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
// =====================><=====================
|
|
291
|
+
const iterations = [];
|
|
292
|
+
if (orderData.iterations != null && orderData.iterations.length > 0) {
|
|
293
|
+
const orderItemIdsMap = {};
|
|
294
|
+
for (let i = 0; i < categories.length; i++) {
|
|
295
|
+
const category = categories[i];
|
|
296
|
+
const items = category.items;
|
|
297
|
+
for (let j = 0; j < items.length; j++) {
|
|
298
|
+
const item = items[j];
|
|
299
|
+
orderItemIdsMap[item._id] = item.quantity;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const [firstIteration, ...restIterations] = orderData.iterations;
|
|
303
|
+
const firstIterationCategories = [];
|
|
304
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
305
|
+
const category = firstIteration.categories[i];
|
|
306
|
+
const allPrevItems = [];
|
|
307
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
308
|
+
const prevItem = category.items[j];
|
|
309
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
310
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
311
|
+
if (isRemovedItem) {
|
|
312
|
+
allPrevItems.push(prevItem);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
const updatedPrevItem = {
|
|
316
|
+
...prevItem,
|
|
317
|
+
};
|
|
318
|
+
delete updatedPrevItem.void_reason;
|
|
319
|
+
allPrevItems.push(updatedPrevItem);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (allPrevItems.length > 0) {
|
|
323
|
+
firstIterationCategories.push({
|
|
324
|
+
...category,
|
|
325
|
+
items: allPrevItems,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const firstIterationData = {
|
|
330
|
+
...firstIteration,
|
|
331
|
+
categories: firstIterationCategories,
|
|
332
|
+
};
|
|
333
|
+
iterations.push(firstIterationData);
|
|
334
|
+
iterations.push(...restIterations);
|
|
335
|
+
}
|
|
336
|
+
// =====================><=====================
|
|
337
|
+
const order = {
|
|
338
|
+
...orderData,
|
|
339
|
+
...(iterations.length > 0 && { iterations }),
|
|
340
|
+
categories,
|
|
341
|
+
};
|
|
342
|
+
const newData = calculateCartWarehousePurchaseOrderInfoAndSyncData(order);
|
|
343
|
+
return newData;
|
|
344
|
+
}
|
|
345
|
+
function getUpdateItemInWarehousePurchaseOrderCartData(data, payload) {
|
|
346
|
+
const orderItemIdsMap = {};
|
|
347
|
+
let categories;
|
|
348
|
+
if (data.categories != null) {
|
|
349
|
+
categories = [];
|
|
350
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
351
|
+
const category = data.categories[i];
|
|
352
|
+
const items = [];
|
|
353
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
354
|
+
const item = category.items[j];
|
|
355
|
+
let newItem = item;
|
|
356
|
+
if (item._id === payload._id) {
|
|
357
|
+
newItem = {
|
|
358
|
+
...item,
|
|
359
|
+
...payload,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
if (newItem.quantity > 0) {
|
|
363
|
+
items.push(newItem);
|
|
364
|
+
orderItemIdsMap[newItem._id] = newItem.quantity;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (items.length > 0) {
|
|
368
|
+
categories.push({
|
|
369
|
+
...category,
|
|
370
|
+
items,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const iterations = [];
|
|
376
|
+
if (payload.quantity != null && data.iterations != null && data.iterations.length > 0) {
|
|
377
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
378
|
+
const firstIterationCategories = [];
|
|
379
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
380
|
+
const category = firstIteration.categories[i];
|
|
381
|
+
const allPrevItems = [];
|
|
382
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
383
|
+
const prevItem = category.items[j];
|
|
384
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
385
|
+
const updatedPrevItem = {
|
|
386
|
+
...prevItem,
|
|
387
|
+
void_reason: payload.void_reason,
|
|
388
|
+
};
|
|
389
|
+
allPrevItems.push(updatedPrevItem);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
// A Removed Item is one that is not in the orderItemIdsMap
|
|
393
|
+
// Or it is in the orderItemIdsMap but its quantity is less than newItem.quantity
|
|
394
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
395
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
396
|
+
if (isRemovedItem) {
|
|
397
|
+
allPrevItems.push(prevItem);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// If the item is not removed, then we make sure to remove the void_reason
|
|
401
|
+
const updatedPrevItem = {
|
|
402
|
+
...prevItem,
|
|
403
|
+
};
|
|
404
|
+
delete updatedPrevItem.void_reason;
|
|
405
|
+
allPrevItems.push(updatedPrevItem);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (allPrevItems.length > 0) {
|
|
410
|
+
firstIterationCategories.push({
|
|
411
|
+
...category,
|
|
412
|
+
items: allPrevItems,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const firstIterationData = {
|
|
417
|
+
...firstIteration,
|
|
418
|
+
categories: firstIterationCategories,
|
|
419
|
+
};
|
|
420
|
+
iterations.push(firstIterationData);
|
|
421
|
+
iterations.push(...restIterations);
|
|
422
|
+
}
|
|
423
|
+
const order = {
|
|
424
|
+
...data,
|
|
425
|
+
...(iterations.length > 0 && { iterations }),
|
|
426
|
+
categories,
|
|
427
|
+
};
|
|
428
|
+
const newData = calculateCartWarehousePurchaseOrderInfoAndSyncData(order);
|
|
429
|
+
return newData;
|
|
430
|
+
}
|
|
431
|
+
function getUpdateItemsInWarehousePurchaseOrderCartData(data, payload) {
|
|
432
|
+
const newData = payload.reduce((acc, item) => getUpdateItemInWarehousePurchaseOrderCartData(acc, item), data);
|
|
433
|
+
return newData;
|
|
434
|
+
}
|
|
435
|
+
function getSplitWarehousePurchaseOrderCartItemToTwo({ data, orderItemId, }) {
|
|
436
|
+
if (data.categories == null)
|
|
437
|
+
return data;
|
|
438
|
+
const newCategories = [];
|
|
439
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
440
|
+
const category = data.categories[i];
|
|
441
|
+
const newItems = [];
|
|
442
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
443
|
+
const item = {
|
|
444
|
+
...category.items[j],
|
|
445
|
+
};
|
|
446
|
+
if (item._id !== orderItemId) {
|
|
447
|
+
newItems.push(item);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (item.quantity === 1) {
|
|
451
|
+
newItems.push(item);
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const prevQuantity = item.quantity;
|
|
455
|
+
const newQuantity = item.quantity - 1;
|
|
456
|
+
const prevItem = {
|
|
457
|
+
...item,
|
|
458
|
+
quantity: newQuantity,
|
|
459
|
+
subtotal: (0, utils_1.parseNum)(item.price * newQuantity),
|
|
460
|
+
};
|
|
461
|
+
newItems.push(prevItem);
|
|
462
|
+
const _id = new bson_objectid_1.default(Math.floor(new bson_objectid_1.default(item._id).getTimestamp().getTime() / 1000) + 1).toHexString();
|
|
463
|
+
newItems.push({
|
|
464
|
+
...item,
|
|
465
|
+
_id,
|
|
466
|
+
quantity: 1,
|
|
467
|
+
subtotal: (0, utils_1.parseNum)(item.price * 1),
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
newCategories.push({
|
|
471
|
+
...category,
|
|
472
|
+
items: newItems,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
const order = {
|
|
476
|
+
...data,
|
|
477
|
+
categories: newCategories,
|
|
478
|
+
};
|
|
479
|
+
const newData = calculateCartWarehousePurchaseOrderInfoAndSyncData(order);
|
|
480
|
+
return newData;
|
|
481
|
+
}
|
|
482
|
+
function getAddItemsToWarehousePurchaseOrderCartData(data, payload) {
|
|
483
|
+
const newData = payload.reduce((acc, item) => getAddItemToWarehousePurchaseOrderCartData(acc, item), data);
|
|
484
|
+
return newData;
|
|
485
|
+
}
|
|
486
|
+
/* ======================><====================== */
|
|
@@ -16,7 +16,7 @@ export * from './kpra-generate-invoice';
|
|
|
16
16
|
export * from './marketing';
|
|
17
17
|
export * from './order-engine';
|
|
18
18
|
export * from './pra-generate-invoice';
|
|
19
|
-
export * from './purchase-order-cart-actions';
|
|
19
|
+
export * from './warehouse-purchase-order-cart-actions';
|
|
20
20
|
export * from './report-webview';
|
|
21
21
|
export * from './reports';
|
|
22
22
|
export * from './smartpay-apis';
|
|
@@ -32,7 +32,7 @@ __exportStar(require("./kpra-generate-invoice"), exports);
|
|
|
32
32
|
__exportStar(require("./marketing"), exports);
|
|
33
33
|
__exportStar(require("./order-engine"), exports);
|
|
34
34
|
__exportStar(require("./pra-generate-invoice"), exports);
|
|
35
|
-
__exportStar(require("./purchase-order-cart-actions"), exports);
|
|
35
|
+
__exportStar(require("./warehouse-purchase-order-cart-actions"), exports);
|
|
36
36
|
__exportStar(require("./report-webview"), exports);
|
|
37
37
|
__exportStar(require("./reports"), exports);
|
|
38
38
|
__exportStar(require("./smartpay-apis"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WarehouseIPurchaseOrderItem } from '../../schemas';
|
|
2
2
|
export interface IGeneralPurchaseOrderItem {
|
|
3
3
|
_id: string;
|
|
4
4
|
name: string;
|
|
@@ -9,7 +9,7 @@ export interface IGeneralPurchaseOrderItem {
|
|
|
9
9
|
description: string;
|
|
10
10
|
}
|
|
11
11
|
export interface IPurchaseOrderCartItem {
|
|
12
|
-
orderItem:
|
|
12
|
+
orderItem: WarehouseIPurchaseOrderItem;
|
|
13
13
|
image_url: string | null;
|
|
14
14
|
description: string;
|
|
15
15
|
category_name: string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IWarehousePurchaseOrderItem } from '../../schemas';
|
|
2
|
+
export interface IWarehouseGeneralPurchaseOrderItem {
|
|
3
|
+
_id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
category_id: string;
|
|
6
|
+
category_name: string;
|
|
7
|
+
category_image_url: string | null;
|
|
8
|
+
image_url: string | null;
|
|
9
|
+
description: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IWarehousePurchaseOrderCartItem {
|
|
12
|
+
orderItem: IWarehousePurchaseOrderItem;
|
|
13
|
+
image_url: string | null;
|
|
14
|
+
description: string;
|
|
15
|
+
category_name: string;
|
|
16
|
+
category_id: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IWarehousePurchaseOrderCartItemsObj {
|
|
19
|
+
unChangedItems: IWarehousePurchaseOrderCartItem[];
|
|
20
|
+
editedItems: IWarehousePurchaseOrderCartItem[];
|
|
21
|
+
removedItems: IWarehousePurchaseOrderCartItem[];
|
|
22
|
+
newItems: IWarehousePurchaseOrderCartItem[];
|
|
23
|
+
totalSelectedItems: number;
|
|
24
|
+
disabledReason: string;
|
|
25
|
+
isAnUpdate: boolean;
|
|
26
|
+
}
|