This commit is contained in:
Sibunnayak 2024-11-06 17:55:00 +05:30
parent f8a9673e24
commit d197cb2c43
2 changed files with 36 additions and 21 deletions

View File

@ -54,29 +54,36 @@ const OpeningInventoryReports = () => {
setLoading(false);
}
};
const handleDownloadReport = async () => {
try {
const response = await axios.get(`/api/report/opening-inventory/download`, {
headers: {
Authorization: `Bearer ${token}`,
},
responseType: 'arraybuffer', // Ensure that we handle the response as binary data
});
const response = await axios.get(
`/api/report/opening-inventory/download`,
{
headers: {
Authorization: `Bearer ${token}`,
},
responseType: "arraybuffer", // Ensure that we handle the response as binary data
}
);
// Step 1: Convert the response data into a Blob
const url = window.URL.createObjectURL(new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
const url = window.URL.createObjectURL(
new Blob([response.data], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
})
);
// Step 2: Create a download link and trigger the download
const link = document.createElement("a");
link.setAttribute("href", url);
link.setAttribute("download", "OpeningInventoryReport.xlsx");
document.body.appendChild(link);
link.click();
// Step 3: Clean up
document.body.removeChild(link);
window.URL.revokeObjectURL(url); // Clean up the Blob URL
window.URL.revokeObjectURL(url); // Clean up the Blob URL
} catch (err) {
const msg = err?.response?.data?.msg || "Something went wrong!";
swal({
@ -232,7 +239,7 @@ const OpeningInventoryReports = () => {
className="mt-4"
variant="contained"
color="primary"
size="small"
size="small"
onClick={handleDownloadReport}
disabled={loading}
>
@ -264,7 +271,7 @@ const OpeningInventoryReports = () => {
Brand Name
</th>
<th className="text-start" style={{ width: "15%" }}>
Total At PDs & Retailers
Total At PDs & Retailers
</th>
<th className="text-start" style={{ width: "10%" }}>
All PDs
@ -326,10 +333,14 @@ const OpeningInventoryReports = () => {
{product.brand || "Brand Not selected"}
</td>
<td className="text-start">
{product.allPdAndRd}
{parseFloat(product.allPdAndRd).toFixed(2)}
</td>
<td className="text-start">
{parseFloat(product.allPDs).toFixed(2)}
</td>
<td className="text-start">
{parseFloat(product.allRDs).toFixed(2)}
</td>
<td className="text-start">{product.allPDs}</td>
<td className="text-start">{product.allRDs}</td>
</tr>
))
) : (

View File

@ -234,7 +234,7 @@ const StockReports = () => {
className="mt-4"
variant="contained"
color="primary"
size="small"
size="small"
onClick={handleDownloadReport}
disabled={loading}
>
@ -328,10 +328,14 @@ const StockReports = () => {
{product.brand || "Brand Not selected"}
</td>
<td className="text-start">
{product.allPdAndRd}
{parseFloat(product.allPdAndRd).toFixed(2)}
</td>
<td className="text-start">
{parseFloat(product.allPDs).toFixed(2)}
</td>
<td className="text-start">
{parseFloat(product.allRDs).toFixed(2)}
</td>
<td className="text-start">{product.allPDs}</td>
<td className="text-start">{product.allRDs}</td>
</tr>
))
) : (