| @@ -27,6 +27,7 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p | |||
| const [isSuccessPopUp, setIsSuccessPopUp] = React.useState(false); | |||
| const [resultCount, setResultCount] = React.useState(0); | |||
| const [dnIdList, setDnIdList] = React.useState([]); | |||
| const [issueSelected, setIssueSelected] = React.useState({}); | |||
| const [paymentCount, setPaymentCount] = React.useState(0); | |||
| @@ -86,6 +87,7 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p | |||
| url: UrlUtils.DEMAND_NOTE_CREATE + "/" + issueSelected.id, | |||
| onSuccess: function (responseData) { | |||
| setResultCount(responseData.count); | |||
| setDnIdList(responseData.idList); | |||
| setIsSuccessPopUp(true); | |||
| } | |||
| }); | |||
| @@ -95,9 +97,10 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p | |||
| const fileDownload = () => { | |||
| HttpUtils.fileDownload({ | |||
| method:'post', | |||
| url: UrlUtils.DEMAND_NOTE_EXPORT, | |||
| params: { | |||
| "issueId": issueSelected.id | |||
| "dnIdList": dnIdList | |||
| }, | |||
| onSuccess: function () { | |||
| notifyDownloadSuccess(); | |||
| @@ -219,7 +222,7 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p | |||
| <Grid item md={12}> | |||
| <Button | |||
| size="large" | |||
| onClick={fileDownload} | |||
| onClick={()=>fileDownload()} | |||
| sx={{ | |||
| textTransform: 'capitalize', | |||
| alignItems: 'end' | |||
| @@ -11,15 +11,19 @@ import * as DateUtils from "utils/DateUtils"; | |||
| import * as StatusUtils from "utils/statusUtils/DnStatus"; | |||
| import { useNavigate } from "react-router-dom"; | |||
| import { FiDataGrid } from "components/FiDataGrid"; | |||
| import { notifyDownloadSuccess } from 'utils/CommonFunction'; | |||
| import * as UrlUtils from "utils/ApiPathConst"; | |||
| import * as HttpUtils from "utils/HttpUtils"; | |||
| // ==============================|| EVENT TABLE ||============================== // | |||
| export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun }) { | |||
| export default function SearchDemandNote({ recordList, reloadFun }) { | |||
| const [isConfirmPopUp, setConfirmPopUp] = React.useState(false); | |||
| const [isSendPopUp, setSendPopUp] = React.useState(false); | |||
| const [isErrorPopUp, setIsErrorPopUp] = React.useState(false); | |||
| const [selectonWarning, setSelectonWarning] = React.useState(false); | |||
| const [wait, setWait] = React.useState(false); | |||
| const [rows, setRows] = React.useState(recordList); | |||
| const [selectedRowItems, setSelectedRowItems] = React.useState([]); | |||
| @@ -33,6 +37,32 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| navigate('/paymentPage/demandNote/details/' + params.id); | |||
| }; | |||
| const exportXml = () => { | |||
| let idList = []; | |||
| const datas = rows?.filter((row) => | |||
| selectedRowItems.includes(row.id) | |||
| ); | |||
| if(datas?.length<1){ | |||
| setSelectonWarning(true); | |||
| return; | |||
| }else if (datas?.length >= 100) { | |||
| setIsErrorPopUp(true); | |||
| return; | |||
| } | |||
| for (var i = 0; i < datas?.length; i++) { | |||
| idList.push(datas[i].id); | |||
| } | |||
| HttpUtils.fileDownload({ | |||
| method:'post', | |||
| url: UrlUtils.DEMAND_NOTE_EXPORT, | |||
| params: { | |||
| dnIdList:idList | |||
| }, | |||
| onSuccess: function () { | |||
| notifyDownloadSuccess(); | |||
| } | |||
| }); | |||
| } | |||
| const onDownloadClick = (params) => () => { | |||
| HttpUtils.fileDownload({ | |||
| @@ -48,6 +78,10 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| const datas = rows?.filter((row) => | |||
| selectedRowItems.includes(row.id) | |||
| ); | |||
| if(datas?.length<1){ | |||
| setSelectonWarning(true); | |||
| return; | |||
| } | |||
| for (var i = 0; i < datas?.length; i++) { | |||
| idList.push(datas[i].id); | |||
| } | |||
| @@ -64,6 +98,7 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| } | |||
| const doUploadFile = (event) => { | |||
| setWait(true); | |||
| let dnMap = {}; | |||
| const datas = rows?.filter((row) => | |||
| selectedRowItems.includes(row.id) | |||
| @@ -80,6 +115,7 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| }, | |||
| files:[file], | |||
| onSuccess() { | |||
| setWait(false); | |||
| if (reloadFun) reloadFun(); | |||
| }, | |||
| }); | |||
| @@ -92,6 +128,10 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| const datas = rows?.filter((row) => | |||
| selectedRowItems.includes(row.id) | |||
| ); | |||
| if(datas?.length<1){ | |||
| setSelectonWarning(true); | |||
| return; | |||
| } | |||
| for (var i = 0; i < datas?.length; i++) { | |||
| idList.push(datas[i].id); | |||
| } | |||
| @@ -198,6 +238,14 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| accept=".pdf" | |||
| style={{ display: 'none' }} | |||
| onChange={(event) => { | |||
| const datas = rows?.filter((row) => | |||
| selectedRowItems.includes(row.id) | |||
| ); | |||
| if(datas.length==0){ | |||
| setSelectonWarning(true); | |||
| document.getElementById("uploadFileBtn").value = ""; | |||
| return; | |||
| } | |||
| doUploadFile(event) | |||
| }} | |||
| /> | |||
| @@ -228,7 +276,7 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| <Button | |||
| size="large" | |||
| variant="contained" | |||
| onClick={exportXmlFun} | |||
| onClick={()=>exportXml()} | |||
| sx={{ | |||
| textTransform: 'capitalize', | |||
| alignItems: 'end' | |||
| @@ -268,6 +316,28 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| onRowDoubleClick={handleRowDoubleClick} | |||
| /> | |||
| </Box> | |||
| <div> | |||
| <Dialog open={isErrorPopUp} onClose={() => setIsErrorPopUp(false)} > | |||
| <DialogTitle><Typography variant="h3">Action Fail</Typography></DialogTitle> | |||
| <DialogContent style={{ display: 'flex', }}> | |||
| <Typography variant="h4" style={{ padding: '16px' }}>Number of DN record must less than 100.<br/>Please edit search form.</Typography> | |||
| </DialogContent> | |||
| <DialogActions> | |||
| <Button onClick={() => setIsErrorPopUp(false)}><Typography variant="h5">OK</Typography></Button> | |||
| </DialogActions> | |||
| </Dialog> | |||
| </div> | |||
| <div> | |||
| <Dialog open={selectonWarning} onClose={() => setSelectonWarning(false)} > | |||
| <DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle> | |||
| <DialogContent style={{ display: 'flex', }}> | |||
| <Typography variant="h4" style={{ padding: '16px' }}>Please Select DN.</Typography> | |||
| </DialogContent> | |||
| <DialogActions> | |||
| <Button onClick={() => setSelectonWarning(false)}><Typography variant="h5">OK</Typography></Button> | |||
| </DialogActions> | |||
| </Dialog> | |||
| </div> | |||
| <div> | |||
| <Dialog open={isConfirmPopUp} onClose={() => setConfirmPopUp(false)} > | |||
| <DialogTitle><Typography variant="h3">Confirm</Typography></DialogTitle> | |||
| @@ -292,6 +362,13 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun } | |||
| </DialogActions> | |||
| </Dialog> | |||
| </div> | |||
| <div> | |||
| <Dialog open={wait} onClose={() => setWait(false)} > | |||
| <DialogContent style={{ display: 'flex', }}> | |||
| <Typography variant="h4" style={{ padding: '16px' }}>Calculating, please wait ...</Typography> | |||
| </DialogContent> | |||
| </Dialog> | |||
| </div> | |||
| </div> | |||
| ); | |||
| } | |||
| @@ -3,8 +3,6 @@ import { | |||
| Grid, | |||
| Typography, | |||
| Stack, | |||
| Button, | |||
| Dialog, DialogTitle, DialogContent, DialogActions, | |||
| } from '@mui/material'; | |||
| import MainCard from "components/MainCard"; | |||
| @@ -18,7 +16,7 @@ const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/Loa | |||
| const SearchForm = Loadable(React.lazy(() => import('./SearchForm'))); | |||
| const EventTable = Loadable(React.lazy(() => import('./DataGrid'))); | |||
| import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' | |||
| import { notifyDownloadSuccess } from 'utils/CommonFunction'; | |||
| const BackgroundHead = { | |||
| backgroundImage: `url(${titleBackgroundImg})`, | |||
| @@ -34,8 +32,6 @@ const BackgroundHead = { | |||
| const UserSearchPage_Individual = () => { | |||
| const [isErrorPopUp, setIsErrorPopUp] = React.useState(false); | |||
| const [record, setRecord] = React.useState([]); | |||
| const [orgCombo, setOrgCombo] = React.useState([]); | |||
| const [issueCombo, setIssueCombo] = React.useState([]); | |||
| @@ -69,20 +65,6 @@ const UserSearchPage_Individual = () => { | |||
| }); | |||
| } | |||
| function exportXml() { | |||
| if (record.length >= 100) { | |||
| setIsErrorPopUp(true); | |||
| return; | |||
| } | |||
| HttpUtils.fileDownload({ | |||
| url: UrlUtils.DEMAND_NOTE_EXPORT, | |||
| params: searchCriteria, | |||
| onSuccess: function () { | |||
| notifyDownloadSuccess(); | |||
| } | |||
| }); | |||
| } | |||
| function getOrgCombo() { | |||
| HttpUtils.get({ | |||
| url: UrlUtils.GET_ORG_COMBO, | |||
| @@ -140,21 +122,10 @@ const UserSearchPage_Individual = () => { | |||
| <EventTable | |||
| recordList={record} | |||
| reloadFun={getUserList} | |||
| exportXmlFun={exportXml} | |||
| /> | |||
| </MainCard> | |||
| </Grid> | |||
| <div> | |||
| <Dialog open={isErrorPopUp} onClose={() => setIsErrorPopUp(false)} > | |||
| <DialogTitle><Typography variant="h3">Action Fail</Typography></DialogTitle> | |||
| <DialogContent style={{ display: 'flex', }}> | |||
| <Typography variant="h4" style={{ padding: '16px' }}>Number of DN record must less than 100.<br/>Please edit search form.</Typography> | |||
| </DialogContent> | |||
| <DialogActions> | |||
| <Button onClick={() => setIsErrorPopUp(false)}><Typography variant="h5">OK</Typography></Button> | |||
| </DialogActions> | |||
| </Dialog> | |||
| </div> | |||
| </Grid> | |||
| ); | |||
| } | |||
| @@ -58,35 +58,56 @@ export const postWithFiles = ({url, params, files, onSuccess, onFail, onError}) | |||
| }); | |||
| }; | |||
| export const fileDownload = ({url, fileId, skey, filename, onResponse, onError}) =>{ | |||
| export const fileDownload = ({url, fileId, skey, filename, params, method, onResponse, onError}) =>{ | |||
| if(!url){ | |||
| url = FILE_DOWN_GET+"/"+fileId+"/"+skey+"/"+filename | |||
| } | |||
| axios.get( url, | |||
| { | |||
| responseType: 'blob', | |||
| } | |||
| ).then( | |||
| (response)=>{ | |||
| const fn = response.headers.get("content-disposition")?.split("filename=")[1]?.split('"')[1]?.trim()??filename; | |||
| const url = URL.createObjectURL(response.data); | |||
| const a = document.createElement('a'); | |||
| a.href = url; | |||
| a.setAttribute("download", fn); | |||
| document.body.appendChild(a); | |||
| a.click(); | |||
| document.body.removeChild(a); | |||
| URL.revokeObjectURL(url); | |||
| if(onResponse){ | |||
| onResponse(); | |||
| if(method == 'post'){ | |||
| axios.post( url, params, | |||
| { | |||
| responseType: 'blob', | |||
| headers:{ | |||
| "Content-Type":"application/json" | |||
| } | |||
| } | |||
| } | |||
| ).catch(error => { | |||
| return handleError(error,onError); | |||
| }); | |||
| }; | |||
| ).then( | |||
| (response)=>{ | |||
| fileDownloadResponse(response, onResponse) | |||
| } | |||
| ).catch(error => { | |||
| return handleError(error,onError); | |||
| }); | |||
| }else{ | |||
| axios.get( url, | |||
| { | |||
| responseType: 'blob', | |||
| params:params | |||
| } | |||
| ).then( | |||
| (response)=>{ | |||
| fileDownloadResponse(response, onResponse) | |||
| } | |||
| ).catch(error => { | |||
| return handleError(error,onError); | |||
| }); | |||
| } | |||
| }; | |||
| const fileDownloadResponse=(response, onResponse)=>{ | |||
| const fn = response.headers.get("content-disposition")?.split("filename=")[1]?.split('"')[1]?.trim()??filename; | |||
| const url = URL.createObjectURL(response.data); | |||
| const a = document.createElement('a'); | |||
| a.href = url; | |||
| a.setAttribute("download", fn); | |||
| document.body.appendChild(a); | |||
| a.click(); | |||
| document.body.removeChild(a); | |||
| URL.revokeObjectURL(url); | |||
| if(onResponse){ | |||
| onResponse(); | |||
| } | |||
| } | |||
| export const fileUpload = ({refType, refId, files, refCode, onSuccess, onFail, onError}) =>{ | |||
| postWithFiles({ | |||