bug fixed of opening inventory single product update
This commit is contained in:
parent
d197cb2c43
commit
9e25d6f37b
@ -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(
|
||||||
|
@ -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({
|
||||||
|
@ -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({
|
||||||
|
Loading…
Reference in New Issue
Block a user