您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

305 行
12 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import * as React from "react";
  11. import * as FormatUtils from "utils/FormatUtils";
  12. import * as DateUtils from "utils/DateUtils";
  13. import * as UrlUtils from "utils/ApiPathConst";
  14. import * as HttpUtils from "utils/HttpUtils";
  15. import { useNavigate } from "react-router-dom";
  16. import { notifyDownloadSuccess } from 'utils/CommonFunction';
  17. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  18. import {ThemeProvider} from "@emotion/react";
  19. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  20. const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _publishCount }) => {
  21. const [isFailPopUp, setIsFailPopUp] = React.useState(false);
  22. const [failText, setFailText] = React.useState("");
  23. const [confirmPopUp, setConfirmPopUp] = React.useState(false);
  24. const [dueDate, setDueDate] = React.useState(DateUtils.dateStr(new Date()));
  25. const [isSuccessPopUp, setIsSuccessPopUp] = React.useState(false);
  26. const [resultCount, setResultCount] = React.useState(0);
  27. const [dnIdList, setDnIdList] = React.useState([]);
  28. const [issueSelected, setIssueSelected] = React.useState({});
  29. const [paymentCount, setPaymentCount] = React.useState(0);
  30. const [publishCount, setPublishCount] = React.useState(0);
  31. const [issueCombo, setIssueCombo] = React.useState([]);
  32. const navigate = useNavigate()
  33. React.useEffect(() => {
  34. if (issueComboData && issueComboData.length > 0) {
  35. setIssueCombo(issueComboData);
  36. }
  37. }, [issueComboData]);
  38. React.useEffect(() => {
  39. setPaymentCount(_paymentCount);
  40. }, [_paymentCount]);
  41. React.useEffect(() => {
  42. setPublishCount(_publishCount);
  43. }, [_publishCount]);
  44. React.useEffect(() => {
  45. onPreView();
  46. }, [issueSelected]);
  47. function getIssueLabel(data) {
  48. if (data == {}) return "";
  49. return data.issueYear
  50. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  51. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  52. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  53. }
  54. const onSubmit = () => {
  55. if (!issueSelected?.id) {
  56. setFailText("Fail Create: Please select Gazette Issue.");
  57. setIsFailPopUp(true);
  58. return;
  59. } else {
  60. setDueDate(DateUtils.dateStr(new Date()));
  61. setConfirmPopUp(true);
  62. }
  63. };
  64. const doDnCreate=()=>{
  65. setConfirmPopUp(false);
  66. HttpUtils.post({
  67. url: UrlUtils.DEMAND_NOTE_CREATE + "/" + issueSelected.id,
  68. params:{
  69. dueDate: dueDate
  70. },
  71. onSuccess: function (responseData) {
  72. setResultCount(responseData.count);
  73. setDnIdList(responseData.idList);
  74. setIsSuccessPopUp(true);
  75. }
  76. });
  77. }
  78. const fileDownload = () => {
  79. HttpUtils.fileDownload({
  80. method:'post',
  81. url: UrlUtils.DEMAND_NOTE_EXPORT,
  82. params: {
  83. "dnIdList": dnIdList
  84. },
  85. onSuccess: function () {
  86. notifyDownloadSuccess();
  87. }
  88. });
  89. }
  90. const onNavigate = () => {
  91. setIsSuccessPopUp(false);
  92. if(resultCount > 0)
  93. navigate('/paymentPage/demandNote');
  94. };
  95. const onPreView = () => {
  96. if (!issueSelected?.id) {
  97. return;
  98. }
  99. const temp = {
  100. issueId: issueSelected.id,
  101. };
  102. applySearch(temp);
  103. };
  104. return (
  105. <MainCard xs={12} md={12} lg={12}
  106. border={false}
  107. content={false}
  108. >
  109. <form>
  110. {/*row 1*/}
  111. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  112. {/*row 1*/}
  113. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  114. <Typography variant="h5" >
  115. Please Select Gazette Issue :
  116. </Typography>
  117. </Grid>
  118. {/*row 2*/}
  119. <Grid container display="flex" alignItems={"center"} sx={{mb:3}}>
  120. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3 }}>
  121. <Autocomplete
  122. disablePortal
  123. size="small"
  124. id="issueId"
  125. options={issueCombo}
  126. value={issueSelected}
  127. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  128. getOptionLabel={(option) => getIssueLabel(option)}
  129. onChange={(event, newValue) => {
  130. if (newValue !== null) {
  131. setIssueSelected(newValue);
  132. }
  133. }}
  134. renderInput={(params) => (
  135. <TextField {...params}
  136. label="Gazette Issue"
  137. InputLabelProps={{
  138. shrink: true
  139. }}
  140. />
  141. )}
  142. />
  143. </Grid>
  144. {/* <Grid item sx={{ ml: 3, mr: 3}} >
  145. <Button
  146. size="large"
  147. variant="contained"
  148. onClick={onPreView}
  149. sx={{
  150. textTransform: 'capitalize',
  151. alignItems: 'end'
  152. }}>
  153. <Typography variant="h5">Preview</Typography>
  154. </Button>
  155. </Grid> */}
  156. <Grid item sx={{ ml: 3, mr: 3 }} >
  157. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  158. <Button
  159. variant="contained"
  160. onClick={onSubmit}
  161. color="success"
  162. >
  163. Create
  164. </Button>
  165. </ThemeProvider>
  166. </Grid>
  167. <Grid item sx={{ ml: 3, mr: 3 }} >
  168. <Typography variant="h5">Pending Payment: {paymentCount}</Typography>
  169. </Grid>
  170. <Grid item sx={{ ml: 3, mr: 3 }} >
  171. <Typography variant="h5">Pending Publish: {publishCount}</Typography>
  172. </Grid>
  173. </Grid>
  174. </Grid>
  175. </form>
  176. <div>
  177. <Dialog
  178. open={isFailPopUp}
  179. onClose={() => setIsFailPopUp(false)}
  180. PaperProps={{
  181. sx: {
  182. minWidth: '40vw',
  183. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  184. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  185. }
  186. }}
  187. >
  188. <DialogTitle><Typography variant="h3">Action Fail</Typography></DialogTitle>
  189. <DialogContent style={{ display: 'flex', }}>
  190. <Typography variant="h4" style={{ padding: '16px' }}>{failText}</Typography>
  191. </DialogContent>
  192. <DialogActions>
  193. <Button onClick={() => setIsFailPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  194. </DialogActions>
  195. </Dialog>
  196. </div>
  197. <div>
  198. <Dialog
  199. open={confirmPopUp}
  200. onClose={() => setConfirmPopUp(false)}
  201. PaperProps={{
  202. sx: {
  203. minWidth: '40vw',
  204. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  205. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  206. }
  207. }}
  208. >
  209. <DialogTitle><Typography variant="h3">Create Confirm</Typography></DialogTitle>
  210. <DialogContent style={{ display: 'flex', }}>
  211. <Grid container alignItems={"center"}>
  212. <Grid item md={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  213. <Typography variant="h4" style={{ padding: '16px' }}>Due Date: </Typography>
  214. </Grid>
  215. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  216. <TextField
  217. fullWidth
  218. type="date"
  219. defaultValue={dueDate}
  220. InputProps={{ inputProps: { min: DateUtils.dateStr(new Date()) } }}
  221. onChange={(newValue) => {
  222. setDueDate(newValue.currentTarget.value)
  223. }}
  224. InputLabelProps={{
  225. shrink: true
  226. }}
  227. />
  228. </Grid>
  229. </Grid>
  230. </DialogContent>
  231. <DialogActions>
  232. <Button onClick={() => setConfirmPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  233. <Button onClick={() => doDnCreate()}><Typography variant="h5">Confirm</Typography></Button>
  234. </DialogActions>
  235. </Dialog>
  236. </div>
  237. <div>
  238. <Dialog
  239. open={isSuccessPopUp}
  240. onClose={() => setIsSuccessPopUp(false)}
  241. PaperProps={{
  242. sx: {
  243. minWidth: '40vw',
  244. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  245. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  246. }
  247. }}
  248. >
  249. <DialogTitle><Typography variant="h3">Create Result</Typography></DialogTitle>
  250. <DialogContent style={{ display: 'flex', }}>
  251. <Grid container alignItems={"center"}>
  252. <Grid item md={12}>
  253. <Typography variant="h4" style={{ padding: '16px' }}>Created DN record: {resultCount}</Typography>
  254. </Grid>
  255. {resultCount == 0 ? <></> :
  256. <Grid item md={12}>
  257. <Button
  258. size="large"
  259. onClick={()=>fileDownload()}
  260. sx={{
  261. textTransform: 'capitalize',
  262. alignItems: 'end'
  263. }}>
  264. <Typography variant="h5">Click here to download GDNS xml file.</Typography>
  265. </Button>
  266. </Grid>
  267. }
  268. </Grid>
  269. </DialogContent>
  270. <DialogActions>
  271. <Button onClick={() => onNavigate()}><Typography variant="h5">OK</Typography></Button>
  272. </DialogActions>
  273. </Dialog>
  274. </div>
  275. </MainCard>
  276. );
  277. };
  278. export default SearchPublicNoticeForm;