LFFE-26 excel report output for passenger office
This commit is contained in:
@@ -170,7 +170,8 @@
|
||||
"state_name": "وضعیت درخواست",
|
||||
"confirm": "ارجاع به کارشناس ماشین آلات",
|
||||
"upload_file_unit": "فایل بارگذاری شده باید حداکثر 2Mb باشد",
|
||||
"upload_file_format": "فرمت قابل قبول : png,jpg,pdf"
|
||||
"upload_file_format": "فرمت قابل قبول : png,jpg,pdf",
|
||||
"excel_report": "گزارش اکسل"
|
||||
},
|
||||
"CommercialChief": {
|
||||
"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_PASSENGER_OFFICE} from "@/core/data/apiRoutes";
|
||||
import moment from "jalali-moment";
|
||||
import FileSaver from 'file-saver';
|
||||
import TableChartIcon from '@mui/icons-material/TableChart';
|
||||
|
||||
const PrintReport = ({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 fetchUrl = 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_PASSENGER_OFFICE}?${fetchUrl}`, '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"/> : <TableChartIcon/>}
|
||||
onClick={clickHandler}
|
||||
>
|
||||
{t("PassengerOffice.excel_report")}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export default PrintReport
|
||||
13
src/components/dashboard/passenger-office/TableToolbar.jsx
Normal file
13
src/components/dashboard/passenger-office/TableToolbar.jsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import {Stack} from "@mui/material";
|
||||
import PrintReport from "@/components/dashboard/passenger-office/Buttons/printReport";
|
||||
|
||||
const TableToolbar = ({table}) => {
|
||||
|
||||
return (
|
||||
<Stack direction={"row"} spacing={2}>
|
||||
<PrintReport table={table}/>
|
||||
</Stack>
|
||||
)
|
||||
}
|
||||
|
||||
export default TableToolbar
|
||||
@@ -6,6 +6,7 @@ import TableRowActions from "./TableRowActions";
|
||||
import moment from "jalali-moment";
|
||||
import DataTable from "@/core/components/DataTable";
|
||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||
import TableToolbar from "@/components/dashboard/passenger-office/TableToolbar";
|
||||
|
||||
function DashboardPassengerOfficeComponent() {
|
||||
const t = useTranslations();
|
||||
@@ -161,7 +162,8 @@ function DashboardPassengerOfficeComponent() {
|
||||
tableUrl={GET_PASSENGER_OFFICE}
|
||||
columns={columns}
|
||||
selectableRow={false}
|
||||
enableCustomToolbar={false}
|
||||
enableCustomToolbar={true}
|
||||
CustomToolbar={TableToolbar}
|
||||
enableLastUpdate={true}
|
||||
sorting={[{
|
||||
id: 'id', desc: false
|
||||
|
||||
@@ -114,6 +114,7 @@ function DataTable(props) {
|
||||
renderTopToolbarCustomActions={({table}) => (<>
|
||||
{props.enableCustomToolbar /* send condition */ ?
|
||||
<props.CustomToolbar
|
||||
table={table}
|
||||
mutate={mutate}/> /* send component */ : <span></span>}
|
||||
</>)}
|
||||
renderBottomToolbarCustomActions={({table}) => (<>
|
||||
|
||||
@@ -21,6 +21,9 @@ export const CONFIRM_PASSENGER_OFFICE =
|
||||
|
||||
export const REJECT_PASSENGER_OFFICE =
|
||||
BASE_URL + "/dashboard/passenger_office_chief/reject";
|
||||
|
||||
export const EXPORT_PASSENGER_OFFICE =
|
||||
BASE_URL + "/dashboard/passenger_office_chief/export"
|
||||
//passenger office
|
||||
|
||||
//passenger boss
|
||||
|
||||
Reference in New Issue
Block a user