bug fixed of opening inventory single product update

This commit is contained in:
Sibunnayak 2024-11-06 22:24:52 +05:30
parent d197cb2c43
commit 9e25d6f37b
3 changed files with 23 additions and 7 deletions

View File

@ -184,12 +184,26 @@ const DistributorOpeningInventory = () => {
const handleSubmitStocks = async () => { const handleSubmitStocks = async () => {
try { try {
const updatedProducts = allProductsData.map((product) => ({ // const updatedProducts = allProductsData.map((product) => ({
_id: product._id, // _id: product._id,
SKU: product.SKU, // SKU: product.SKU,
name: product.name, // name: product.name,
openingInventory: updatedStocks[product.SKU] || product.stock, // openingInventory: updatedStocks[product.SKU] || product.stock,
})); // }));
// Filter and map only products whose stock was changed
const updatedProducts = allProductsData
.filter((product) => updatedStocks[product.SKU] !== undefined)
.map((product) => ({
_id: product._id,
SKU: product.SKU,
name: product.name,
openingInventory: updatedStocks[product.SKU],
}));
if (updatedProducts.length === 0) {
swal("Info", "No stock changes to update.", "info");
return;
}
// console.log(updatedProducts); // console.log(updatedProducts);
// console.log(id); // console.log(id);
await axios.put( await axios.put(

View File

@ -38,7 +38,7 @@ const OpeningInventoryReports = () => {
brand: brandRef.current?.value || "", brand: brandRef.current?.value || "",
}, },
}); });
// console.log(response.data); // console.log(response.data.data);
setProductsData(response.data?.data || []); setProductsData(response.data?.data || []);
setTotalData(response.data?.pagination?.total || 0); setTotalData(response.data?.pagination?.total || 0);
} catch (err) { } catch (err) {
@ -84,6 +84,7 @@ const OpeningInventoryReports = () => {
// Step 3: Clean up // Step 3: Clean up
document.body.removeChild(link); document.body.removeChild(link);
window.URL.revokeObjectURL(url); // Clean up the Blob URL window.URL.revokeObjectURL(url); // Clean up the Blob URL
toast.success("Report downloaded successfully!");
} catch (err) { } catch (err) {
const msg = err?.response?.data?.msg || "Something went wrong!"; const msg = err?.response?.data?.msg || "Something went wrong!";
swal({ swal({

View File

@ -128,6 +128,7 @@ const StockReports = () => {
// Step 3: Clean up // Step 3: Clean up
document.body.removeChild(link); document.body.removeChild(link);
window.URL.revokeObjectURL(url); // Clean up the Blob URL window.URL.revokeObjectURL(url); // Clean up the Blob URL
toast.success("Report downloaded successfully!");
} catch (err) { } catch (err) {
const msg = err?.response?.data?.msg || "Something went wrong!"; const msg = err?.response?.data?.msg || "Something went wrong!";
swal({ swal({