This commit is contained in:
ROSHAN GARG 2024-11-04 10:31:24 +05:30
commit 208d356009
4 changed files with 17 additions and 17 deletions

Binary file not shown.

View File

@ -40,7 +40,7 @@ export const getProductsWithOpenInventoryInfo = async (req, res) => {
{
$group: {
_id: "$products.SKU",
pdCount: { $sum: 1 },
totalPdOpeningInventory: { $sum: "$products.openingInventory" },
},
},
]);
@ -57,20 +57,20 @@ export const getProductsWithOpenInventoryInfo = async (req, res) => {
{
$group: {
_id: "$products.SKU",
rdCount: { $sum: 1 },
totalRdOpeningInventory: { $sum: "$products.openingInventory" },
},
},
]);
// Step 5: Prepare a mapping of PD and RD counts by SKU
// Step 5: Prepare a mapping of PD and RD copening inventories by SKU
const pdMap = {};
pdOIs.forEach((pd) => {
pdMap[pd._id] = pd.pdCount;
pdMap[pd._id] = pd.totalPdOpeningInventory;
});
const rdMap = {};
rdOIs.forEach((rd) => {
rdMap[rd._id] = rd.rdCount;
rdMap[rd._id] = rd.totalRdOpeningInventory;
});
// Step 6: Combine product info with PD/RD counts using SKU
@ -139,7 +139,7 @@ export const getProductsWithStockInfo = async (req, res) => {
{
$group: {
_id: "$products.SKU",
pdCount: { $sum: 1 },
totalpdStock: { $sum: "$products.Stock" },
},
},
]);
@ -156,20 +156,20 @@ export const getProductsWithStockInfo = async (req, res) => {
{
$group: {
_id: "$products.SKU",
rdCount: { $sum: 1 },
totalrdStock: { $sum: "$products.Stock" },
},
},
]);
// Step 5: Prepare a mapping of PD and RD counts by SKU
// Step 5: Prepare a mapping of PD and RD Stocks by SKU
const pdMap = {};
pdStocks.forEach((pd) => {
pdMap[pd._id] = pd.pdCount;
pdMap[pd._id] = pd.totalpdStock;
});
const rdMap = {};
rdStocks.forEach((rd) => {
rdMap[rd._id] = rd.rdCount;
rdMap[rd._id] = rd.totalrdStock;
});
// Step 6: Combine product info with PD/RD counts using SKU

View File

@ -242,7 +242,7 @@ export const uploadRetaildistributors = async (req, res) => {
tradeName: item.trade_name,
user: Retaildistributor._id,
};
console.log(addressData);
// console.log(addressData);
let addressUpdated = false;
if (existingAddress) {
const addressUpdates = [];

View File

@ -46,9 +46,9 @@ export const uploadOpeningInventorypd = async (req, res) => {
// Map headers from the Excel file to your schema
const headerMapping = {
SKU: "SKU",
"SKU": "SKU",
"Product Name": "productName",
"Opening Inventory (Qty)": "openingInventory",
"Opening Inventory (Qty in Ltr/ Kg) ": "openingInventory",
};
const requiredHeaders = Object.keys(headerMapping);
@ -262,9 +262,9 @@ export const uploadOpeningInventoryrd = async (req, res) => {
// Map headers from the Excel file to your schema
const headerMapping = {
SKU: "SKU",
"SKU": "SKU",
"Product Name": "productName",
"Opening Inventory (Qty)": "openingInventory",
"Opening Inventory (Qty in Ltr/ Kg) ": "openingInventory",
};
const requiredHeaders = Object.keys(headerMapping);
@ -311,7 +311,7 @@ export const uploadOpeningInventoryrd = async (req, res) => {
item.openingInventory === ""
) {
missingFields.add("Opening Inventory (Qty)");
}
}
// Combine all errors into a single message
let errorMessage = "";
if (missingFields.size > 0) {
@ -339,7 +339,7 @@ export const uploadOpeningInventoryrd = async (req, res) => {
});
continue;
}
// Cast opening inventory to a number to handle leading zeros and ensure numeric comparisons
const newOpeningInventory = Number(item.openingInventory);
// Check if product exists in user's stock