update
This commit is contained in:
parent
6b9fbbb5b6
commit
6b910d10f7
@ -69,18 +69,22 @@ export const getProductsAndStockByPD = async (req, res) => {
|
||||
]),
|
||||
]);
|
||||
|
||||
// Create a stock map for easy lookup
|
||||
// Create a stock map for easy lookup from userStock
|
||||
const stockMap = {};
|
||||
if (userStock && userStock.products) {
|
||||
userStock.products.forEach((product) => {
|
||||
stockMap[product.productid.toString()] = product.Stock;
|
||||
stockMap[product.productid.toString()] = {
|
||||
Stock: product.Stock,
|
||||
openingInventory: product.openingInventory,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Combine products with their respective stock
|
||||
// Combine products with their respective stock and opening inventory
|
||||
const productsWithStock = products.map((product) => ({
|
||||
...product,
|
||||
stock: stockMap[product._id.toString()] || 0,
|
||||
stock: stockMap[product._id.toString()]?.Stock || 0,
|
||||
openingInventory: stockMap[product._id.toString()]?.openingInventory || 0,
|
||||
}));
|
||||
|
||||
// Get total count for pagination purposes
|
||||
|
Loading…
Reference in New Issue
Block a user