update the reports and fix bug

This commit is contained in:
Sibunnayak 2024-11-02 12:18:55 +05:30
parent ddaadce053
commit ba690d4913
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: { $group: {
_id: "$products.SKU", _id: "$products.SKU",
pdCount: { $sum: 1 }, totalPdOpeningInventory: { $sum: "$products.openingInventory" },
}, },
}, },
]); ]);
@ -57,20 +57,20 @@ export const getProductsWithOpenInventoryInfo = async (req, res) => {
{ {
$group: { $group: {
_id: "$products.SKU", _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 = {}; const pdMap = {};
pdOIs.forEach((pd) => { pdOIs.forEach((pd) => {
pdMap[pd._id] = pd.pdCount; pdMap[pd._id] = pd.totalPdOpeningInventory;
}); });
const rdMap = {}; const rdMap = {};
rdOIs.forEach((rd) => { rdOIs.forEach((rd) => {
rdMap[rd._id] = rd.rdCount; rdMap[rd._id] = rd.totalRdOpeningInventory;
}); });
// Step 6: Combine product info with PD/RD counts using SKU // Step 6: Combine product info with PD/RD counts using SKU
@ -139,7 +139,7 @@ export const getProductsWithStockInfo = async (req, res) => {
{ {
$group: { $group: {
_id: "$products.SKU", _id: "$products.SKU",
pdCount: { $sum: 1 }, totalpdStock: { $sum: "$products.Stock" },
}, },
}, },
]); ]);
@ -156,20 +156,20 @@ export const getProductsWithStockInfo = async (req, res) => {
{ {
$group: { $group: {
_id: "$products.SKU", _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 = {}; const pdMap = {};
pdStocks.forEach((pd) => { pdStocks.forEach((pd) => {
pdMap[pd._id] = pd.pdCount; pdMap[pd._id] = pd.totalpdStock;
}); });
const rdMap = {}; const rdMap = {};
rdStocks.forEach((rd) => { rdStocks.forEach((rd) => {
rdMap[rd._id] = rd.rdCount; rdMap[rd._id] = rd.totalrdStock;
}); });
// Step 6: Combine product info with PD/RD counts using SKU // 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, tradeName: item.trade_name,
user: Retaildistributor._id, user: Retaildistributor._id,
}; };
console.log(addressData); // console.log(addressData);
let addressUpdated = false; let addressUpdated = false;
if (existingAddress) { if (existingAddress) {
const addressUpdates = []; const addressUpdates = [];

View File

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