download reports

This commit is contained in:
Sibunnayak 2024-11-06 14:12:51 +05:30
parent aef4fa2fad
commit f8a9673e24
3 changed files with 96 additions and 2 deletions

View File

@ -55,6 +55,40 @@ const OpeningInventoryReports = () => {
}
};
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
});
// 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' }));
// 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
} catch (err) {
const msg = err?.response?.data?.msg || "Something went wrong!";
swal({
title: "Error",
text: msg,
icon: "error",
button: "Retry",
dangerMode: true,
});
}
};
const getCatagories = () => {
axios
.get(`/api/category/getCategories`, {
@ -193,6 +227,18 @@ const OpeningInventoryReports = () => {
))}
</select>
</div>
<div className="col-lg-2">
<Button
className="mt-4"
variant="contained"
color="primary"
size="small"
onClick={handleDownloadReport}
disabled={loading}
>
Download Report
</Button>
</div>
</div>
<div className="table-responsive table-shoot mt-3">

View File

@ -102,7 +102,43 @@ const StockReports = () => {
const handleSearchChange = () => {
debouncedSearch();
};
const handleDownloadReport = async () => {
try {
const response = await axios.get(`/api/report/stock/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",
})
);
// Step 2: Create a download link and trigger the download
const link = document.createElement("a");
link.setAttribute("href", url);
link.setAttribute("download", "StockReports.xlsx");
document.body.appendChild(link);
link.click();
// Step 3: Clean up
document.body.removeChild(link);
window.URL.revokeObjectURL(url); // Clean up the Blob URL
} catch (err) {
const msg = err?.response?.data?.msg || "Something went wrong!";
swal({
title: "Error",
text: msg,
icon: "error",
button: "Retry",
dangerMode: true,
});
}
};
return (
<div className="main-content">
<div className="page-content">
@ -193,6 +229,18 @@ const StockReports = () => {
))}
</select>
</div>
<div className="col-lg-2">
<Button
className="mt-4"
variant="contained"
color="primary"
size="small"
onClick={handleDownloadReport}
disabled={loading}
>
Download Report
</Button>
</div>
</div>
<div className="table-responsive table-shoot mt-3">

View File

@ -306,7 +306,7 @@ function MobileApp() {
useEffect(() => {
async function getConfiguration() {
try {
const configDetails = await axios.get(`/api/config`, {
const configDetails = await axios.get(`/api/mobileapp/getall`, {
headers: {
Authorization: `Bearer ${token}`,
},
@ -333,7 +333,7 @@ function MobileApp() {
if (TMApp) formData.append("TMApp", TMApp);
try {
const response = await axios.post(`/api/config/mobile-app`, formData, {
const response = await axios.post(`/api/mobileapp/add`, formData, {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "multipart/form-data",