LFFE-26 report toolbar machinary office
This commit is contained in:
@@ -315,7 +315,8 @@
|
||||
"upload_file_unit": "فایل بارگذاری شده باید حداکثر 2Mb باشد",
|
||||
"upload_file_format": "فرمت قابل قبول : png,jpg,pdf",
|
||||
"print_report": "چاپ گزارش کارشناسی ماشین آلات",
|
||||
"max_amount": "حداکثر مبلغ پیشنهادی {value} میلیون ریال می باشد"
|
||||
"max_amount": "حداکثر مبلغ پیشنهادی {value} میلیون ریال می باشد",
|
||||
"excel_report": "گزارش اکسل"
|
||||
},
|
||||
"UserManagement": {
|
||||
"name": "نام",
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import {Button, CircularProgress} from "@mui/material";
|
||||
import {useTranslations} from "next-intl";
|
||||
import {useMemo, useState} from "react";
|
||||
import useRequest from "@/lib/app/hooks/useRequest";
|
||||
import {EXPORT_MACHINARY_OFFICE} from "@/core/data/apiRoutes";
|
||||
import moment from "jalali-moment";
|
||||
import FileSaver from 'file-saver';
|
||||
import DescriptionIcon from '@mui/icons-material/Description';
|
||||
|
||||
const PrintExcel = ({table}) => {
|
||||
const t = useTranslations();
|
||||
const [loading, setLoading] = useState(false)
|
||||
const requestServer = useRequest({auth: true, pending: false, success: {notification: {show: false}}})
|
||||
const {columnFilters, columnFilterFns, sorting} = table.getState()
|
||||
const columns = table.getAllColumns()
|
||||
|
||||
const filterParams = useMemo(() => {
|
||||
const params = new URLSearchParams();
|
||||
const filters = columnFilters.map((filter) => {
|
||||
let datatype;
|
||||
for (const i in columns) {
|
||||
if (columns[i].id == filter.id) {
|
||||
datatype = columns[i].columnDef.datatype;
|
||||
}
|
||||
}
|
||||
return {
|
||||
...filter, fn: columnFilterFns[filter.id], datatype: datatype,
|
||||
};
|
||||
});
|
||||
params.set("start", '0');
|
||||
params.set("filters", JSON.stringify(filters ?? []));
|
||||
params.set("sorting", JSON.stringify(sorting ?? []));
|
||||
return params;
|
||||
}, [columnFilters, columnFilterFns, sorting, columns,]);
|
||||
|
||||
|
||||
const clickHandler = () => {
|
||||
setLoading(true)
|
||||
requestServer(`${EXPORT_MACHINARY_OFFICE}?${filterParams}`, 'get', {
|
||||
auth: true,
|
||||
notification: false,
|
||||
requestOptions: {responseType: 'blob'}
|
||||
}).then((response) => {
|
||||
const filename = `گزارش ماشین آلات تاریخ_${moment().format('jYYYY_jMM_jDD')}.xlsx`;
|
||||
FileSaver.saveAs(response.data, filename);
|
||||
}).catch(() => {
|
||||
}).finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Button
|
||||
color="primary"
|
||||
variant="contained"
|
||||
size="small"
|
||||
disabled={loading}
|
||||
sx={{textTransform: "unset", alignSelf: "center"}}
|
||||
startIcon={loading ? <CircularProgress size={18} color="inherit"/> : <DescriptionIcon/>}
|
||||
onClick={clickHandler}
|
||||
>
|
||||
{t("MachinaryOffice.excel_report")}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export default PrintExcel
|
||||
@@ -1,10 +1,12 @@
|
||||
import {Stack} from "@mui/material";
|
||||
import PrintReport from "@/components/dashboard/machinary-office/Buttons/printReport";
|
||||
import PrintExcel from "@/components/dashboard/machinary-office/Buttons/printExcel";
|
||||
|
||||
const TableToolbar = () => {
|
||||
const TableToolbar = ({table}) => {
|
||||
return (
|
||||
<Stack direction={"row"} spacing={2}>
|
||||
<PrintReport/>
|
||||
<PrintExcel table={table}/>
|
||||
</Stack>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ export const CONFIRM_MACHINARY_OFFICE =
|
||||
|
||||
export const REJECT_MACHINARY_OFFICE =
|
||||
BASE_URL + "/dashboard/machinery_expert/reject";
|
||||
export const EXPORT_MACHINARY_OFFICE =
|
||||
BASE_URL + "/dashboard/machinery_expert/export";
|
||||
//machinary office
|
||||
|
||||
//commercial chief
|
||||
|
||||
Reference in New Issue
Block a user