download reports
This commit is contained in:
parent
aef4fa2fad
commit
f8a9673e24
@ -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 = () => {
|
const getCatagories = () => {
|
||||||
axios
|
axios
|
||||||
.get(`/api/category/getCategories`, {
|
.get(`/api/category/getCategories`, {
|
||||||
@ -193,6 +227,18 @@ const OpeningInventoryReports = () => {
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div className="table-responsive table-shoot mt-3">
|
<div className="table-responsive table-shoot mt-3">
|
||||||
|
@ -102,7 +102,43 @@ const StockReports = () => {
|
|||||||
const handleSearchChange = () => {
|
const handleSearchChange = () => {
|
||||||
debouncedSearch();
|
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 (
|
return (
|
||||||
<div className="main-content">
|
<div className="main-content">
|
||||||
<div className="page-content">
|
<div className="page-content">
|
||||||
@ -193,6 +229,18 @@ const StockReports = () => {
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div className="table-responsive table-shoot mt-3">
|
<div className="table-responsive table-shoot mt-3">
|
||||||
|
@ -306,7 +306,7 @@ function MobileApp() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getConfiguration() {
|
async function getConfiguration() {
|
||||||
try {
|
try {
|
||||||
const configDetails = await axios.get(`/api/config`, {
|
const configDetails = await axios.get(`/api/mobileapp/getall`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
@ -333,7 +333,7 @@ function MobileApp() {
|
|||||||
if (TMApp) formData.append("TMApp", TMApp);
|
if (TMApp) formData.append("TMApp", TMApp);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`/api/config/mobile-app`, formData, {
|
const response = await axios.post(`/api/mobileapp/add`, formData, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
|
Loading…
Reference in New Issue
Block a user