Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

315 rindas
15 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Button,
  7. Dialog, DialogTitle, DialogContent, DialogActions
  8. } from '@mui/material';
  9. import * as UrlUtils from "utils/ApiPathConst";
  10. import * as React from "react";
  11. import * as HttpUtils from "utils/HttpUtils";
  12. import { useParams } from "react-router-dom";
  13. import { useNavigate } from "react-router-dom";
  14. import * as DateUtils from "utils/DateUtils"
  15. import * as FormatUtils from "utils/FormatUtils";
  16. import { checkPaymentSuspention } from "utils/Utils";
  17. import {
  18. checkIsOnlyOnlinePayment,
  19. } from "utils/Utils";
  20. import Loadable from 'components/Loadable';
  21. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  22. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  23. const BackgroundHead = {
  24. backgroundImage: `url(${titleBackgroundImg})`,
  25. width: '100%',
  26. height: '100%',
  27. backgroundSize: 'contain',
  28. backgroundRepeat: 'no-repeat',
  29. backgroundColor: '#0C489E',
  30. backgroundPosition: 'right'
  31. }
  32. import {
  33. // useEffect,
  34. useState
  35. } from "react";
  36. import { PNSPS_BUTTON_THEME,
  37. // PNSPS_LONG_BUTTON_THEME
  38. } from "../../../themes/buttonConst";
  39. import { ThemeProvider } from "@emotion/react";
  40. import { FormattedMessage, useIntl } from "react-intl";
  41. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  42. const Index = () => {
  43. const params = useParams();
  44. const navigate = useNavigate()
  45. const [fee, setFee] = useState(0);
  46. const [record, setRecord] = React.useState({});
  47. const [onReady, setOnReady] = React.useState(false);
  48. const [isPopUp, setIsPopUp] = useState(false);
  49. const [paymentHoldedErrText, setPaymentHoldedErrText] = React.useState("");
  50. const [paymentHoldedErr, setPaymentHoldedErr] = React.useState(false);
  51. const intl = useIntl();
  52. const { locale } = intl;
  53. React.useEffect(() => {
  54. loadForm();
  55. }, []);
  56. React.useEffect(() => {
  57. setOnReady(true);
  58. }, [record]);
  59. const isAfter = checkIsOnlyOnlinePayment();
  60. const loadForm = () => {
  61. if (params.id > 0) {
  62. HttpUtils.get({
  63. url: UrlUtils.GET_PROOF_PAY + "/" + params.id,
  64. onSuccess: (responseData) => {
  65. // if (!responseData.data?.id) {
  66. // navigate("/proof/search");
  67. // }
  68. setRecord(responseData.data);
  69. setFee(responseData.data.fee);
  70. },
  71. onError: () => {
  72. }
  73. });
  74. }
  75. }
  76. function doPayment() {
  77. setIsPopUp(false);
  78. let appIdList = [record?.appId]
  79. handlePaymentCheck(appIdList)
  80. }
  81. const handlePaymentCheck = (appIdList) => {
  82. HttpUtils.post({
  83. url: UrlUtils.PAYMENT_CHECK,
  84. params: {
  85. appIds: appIdList
  86. },
  87. onSuccess: (responseData) => {
  88. const latestData = {};
  89. responseData.forEach(item => {
  90. const { appId, timeDiff } = item;
  91. if (latestData[appId] === undefined || timeDiff < latestData[appId].timeDiff) {
  92. latestData[appId] = item;
  93. }
  94. });
  95. const latestDataObjects = Object.values(latestData);
  96. const filteredData = latestDataObjects.filter(item => item.timeDiff > 30 || item.status !== "APPR");
  97. const filteredAppIds = filteredData.map(item => item.appId);
  98. const appIdsNotInData = appIdList.filter(appId => !latestDataObjects.some(item => item.appId === appId));
  99. const combinedAppIdsArray = [...appIdsNotInData, ...filteredAppIds];
  100. const readyToPayment = appIdList.every(appId => combinedAppIdsArray.includes(appId));
  101. if (readyToPayment) {
  102. navigate('/paymentPage', { state: { amount: fee, appIdList: appIdList } });
  103. } else {
  104. const appIdsInData = appIdList.filter(appId => !combinedAppIdsArray.some(item => item === appId));
  105. const HoldingApplication = latestDataObjects.filter(item => appIdsInData.includes(item.appId));
  106. const resultString = HoldingApplication.map(item => item.appNo).join(' , ');
  107. setPaymentHoldedErrText(resultString);
  108. // setPaymentHoldedErrText(intl.formatMessage({ id: 'MSG.paymentHolded' }, { appNo: record.appNo }));
  109. setPaymentHoldedErr(true);
  110. }
  111. }
  112. });
  113. };
  114. return (
  115. !onReady ?
  116. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  117. <Grid item>
  118. <LoadingComponent />
  119. </Grid>
  120. </Grid>
  121. :
  122. (
  123. <Grid container sx={{ minHeight: '110vh', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  124. <Grid item xs={12} width="100%">
  125. <div style={BackgroundHead} width="100%" >
  126. <Stack direction="row" height='70px'>
  127. <Typography ml={15} color='#FFF' variant="h4" sx={{ display: { xs: 'none', sm: 'none', md: 'block' }, pt: 2 }}>
  128. <FormattedMessage id="proofRecord" />
  129. </Typography>
  130. </Stack>
  131. </div>
  132. </Grid>
  133. {/*row 1*/}
  134. <Grid item xs={12} md={12} >
  135. <Grid container justifyContent="flex-start" alignItems="center" >
  136. <center>
  137. <Grid item xs={12} md={8} >
  138. <Typography variant="h4" sx={{ textAlign: "left", ml: 4, mr: 4, mt: 4, borderBottom: "1px solid black" }}>
  139. <FormattedMessage
  140. id={isAfter ? "proofPaymentHeader_online2" : "proofPaymentHeader_online"}
  141. />
  142. </Typography>
  143. <Typography variant="h5" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  144. <div dangerouslySetInnerHTML={{
  145. __html: intl.formatMessage(
  146. {
  147. id: 'proofPaymentBody_online'
  148. },
  149. {
  150. appNo: record?.appNo,
  151. }
  152. )
  153. }} />
  154. <br />
  155. <div dangerouslySetInnerHTML={{
  156. __html: intl.formatMessage(
  157. {
  158. id: 'proofPaymentBody_online2'
  159. },
  160. {
  161. paymentDeadline: DateUtils.formatDateForLocale(record?.expiryDate, intl, locale),
  162. }
  163. )
  164. }} />
  165. <br />
  166. {checkPaymentSuspention()?
  167. <div>
  168. <Typography style={{ textAlign: "flex-start", color: "red" }}>
  169. <div dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: "suspensionMessageText" }) }} />
  170. </Typography>
  171. <br />
  172. </div>:null
  173. }
  174. </Typography>
  175. {!checkPaymentSuspention()?
  176. <Typography variant="h4" sx={{ ml: 8, textAlign: "left" }}>
  177. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  178. <Button
  179. component="span"
  180. variant="contained"
  181. // sx={{ ml: { sm: 4, md: 4, lg: 4 }, mr: 4, mt: { xs: 2, sm: 2 }, mb: { xs: 2, sm: 2 } }}
  182. sx={{mr: 4 }}
  183. onClick={() => { setIsPopUp(true) }}
  184. >
  185. <FormattedMessage id="payInstantly" />
  186. </Button>
  187. </ThemeProvider>
  188. <FormattedMessage id="or" />
  189. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  190. <Button
  191. component="span"
  192. variant="contained"
  193. sx={{ ml: { sm: 4, md: 4, lg: 4 }, mr: 4, mt: { xs: 2, sm: 2 }, mb: { xs: 2, sm: 2 } }}
  194. onClick={() => {
  195. navigate("/publicNotice");
  196. }}
  197. >
  198. <FormattedMessage id="payLater" />
  199. </Button>
  200. </ThemeProvider>
  201. </Typography>:null
  202. }
  203. <Typography variant="h4" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  204. <div dangerouslySetInnerHTML={{
  205. __html: intl.formatMessage(
  206. {
  207. id: 'proofPaymentBody_online3'
  208. }
  209. )
  210. }} />
  211. <br />
  212. </Typography>
  213. </Grid>
  214. </center>
  215. </Grid>
  216. </Grid>
  217. <div>
  218. <Dialog
  219. open={isPopUp}
  220. onClose={() => setIsPopUp(false)}
  221. PaperProps={{
  222. sx: {
  223. minWidth: '40vw',
  224. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '30vw' },
  225. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '50vh' }
  226. }
  227. }}
  228. >
  229. <DialogTitle>
  230. <Typography variant="h3" >
  231. <FormattedMessage id="payConfirm" />
  232. </Typography>
  233. </DialogTitle>
  234. <DialogContent style={{ display: 'flex', }}>
  235. <Stack direction="column" justifyContent="space-between">
  236. <Typography variant="h4">
  237. <FormattedMessage id="totalAmount" /> ($): {FormatUtils.currencyFormat(fee)}
  238. </Typography>
  239. </Stack>
  240. </DialogContent>
  241. <DialogActions>
  242. <Button onClick={() => setIsPopUp(false)}>
  243. <Typography variant="h5">
  244. <FormattedMessage id="close" />
  245. </Typography></Button>
  246. <Button onClick={() => doPayment()}><Typography variant="h5">
  247. <FormattedMessage id="confirm" />
  248. </Typography></Button>
  249. </DialogActions>
  250. </Dialog>
  251. </div>
  252. {/*row 2*/}
  253. <div>
  254. <Dialog
  255. open={paymentHoldedErr}
  256. onClose={() => setPaymentHoldedErr(false)}
  257. PaperProps={{
  258. sx: {
  259. minWidth: '40vw',
  260. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  261. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  262. }
  263. }}
  264. >
  265. <DialogTitle></DialogTitle>
  266. <Typography variant="h4" style={{ paddingLeft: '24px' }}><FormattedMessage id="MSG.actionFail" /></Typography>
  267. <DialogContent style={{ display: 'flex', }}>
  268. <Stack direction="column" justifyContent="space-between">
  269. <div dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: 'MSG.paymentHolded' }, { appNo: paymentHoldedErrText }) }} />
  270. </Stack>
  271. </DialogContent>
  272. <DialogActions>
  273. <Button onClick={() => setPaymentHoldedErr(false)} aria-label={intl.formatMessage({ id: 'close' })}>
  274. <Typography variant="h5">
  275. <FormattedMessage id="close" />
  276. </Typography></Button>
  277. </DialogActions>
  278. </Dialog>
  279. </div>
  280. </Grid >
  281. )
  282. );
  283. };
  284. export default Index;