Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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