Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

575 rader
18 KiB

  1. import {
  2. useEffect,
  3. useState,
  4. lazy
  5. } from "react";
  6. // material-ui
  7. import {
  8. Grid,
  9. Typography,
  10. Stack,
  11. Box,
  12. Button
  13. } from '@mui/material';
  14. import Loadable from 'components/Loadable';
  15. import {
  16. // useNavigate,
  17. useParams
  18. } from "react-router-dom";
  19. import axios from "axios";
  20. import * as HttpUtils from "utils/HttpUtils";
  21. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  22. const ApplicationDetailCard = Loadable(lazy(() => import('./ApplicationDetailCard')));
  23. const GazetteDetailCard = Loadable(lazy(() => import('./GazetteDetailCard')));
  24. const ClientDetailCard = Loadable(lazy(() => import('./ClientDetailCard')));
  25. const TabTableDetail = Loadable(lazy(() => import('./tabTableDetail/TabTable')));
  26. import {
  27. GET_PUBLIC_NOTICE_APPLY_DETAIL,
  28. UPDATE_PUBLIC_NOTICE_APPLY_DETAIL,
  29. SET_PUBLIC_NOTICE_GROUP_DETAIL,
  30. SET_PUBLIC_NOTICE_STATUS_NOT_ACCEPT,
  31. SET_PUBLIC_NOTICE_STATUS_COMPLATED,
  32. SET_PUBLIC_NOTICE_STATUS_WITHDRAW,
  33. SET_PUBLIC_NOTICE_STATUS_RESUBMIT,
  34. SET_PUBLIC_NOTICE_STATUS_REVIEWED,
  35. SET_PUBLIC_NOTICE_STATUS_PUBLISH,
  36. SET_PUBLIC_NOTICE_STATUS_REVOKE,
  37. SET_PUBLIC_NOTICE_STATUS_PAID
  38. } from "utils/ApiPathConst";
  39. const StatusChangeDialog = Loadable(lazy(() => import('./StatusChangeDialog')));
  40. import * as DateUtils from "utils/DateUtils";
  41. import { notifyActionSuccess, notifySaveSuccess } from "utils/CommonFunction";
  42. import ForwardIcon from '@mui/icons-material/Forward';
  43. import { useNavigate } from "react-router-dom";
  44. import {getModeByTextEng} from "utils/statusUtils/PublicNoteStatusUtils";
  45. // ==============================|| Body - DEFAULT ||============================== //
  46. const PublicNoticeDetail_GLD = () => {
  47. const params = useParams();
  48. const navigate = useNavigate()
  49. const [applicationDetailData, setApplicationDetailData] = useState({});
  50. const [isLoading, setLoading] = useState(false);
  51. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  52. const [getUploadStatus, setUploadStatus] = useState(false);
  53. const [proofCount, setProofCount] = useState(0);
  54. const [paymentCount, setPaymentCount] = useState(0);
  55. const [statusHistoryCount, setStatusHistoryCount] = useState(0);
  56. //pageTitle
  57. const [appNo, setAapNo] = useState("");
  58. const [gazetteIssue, setGazetteIssue] = useState("");
  59. const [issueDate, setIssueDate] = useState("");
  60. const [issueNum, setIssueNum] = useState("");
  61. const [groupNo, setGroupNo] = useState("");
  62. // const [groupTitle, setGroupTitle] = useState("");
  63. const [mode, setMode] = useState("");
  64. //statusWindow
  65. const [open, setOpen] = useState(false);
  66. const [getStatus, setStatus] = useState("");
  67. const [statusWindowAccepted, setStatusWindowAccepted] = useState(false);
  68. const [statusConfirmLoading, setStatusConfirmLoading] = useState(false);
  69. const [selectedGazetteGroup, setSelectedGazetteGroup] = useState({});
  70. const [selectedGazetteGroupInputType, setSelectedGazetteGroupInputType] = useState("");
  71. const [getReason, setReason] = useState({});
  72. //editMode
  73. const [updateApplicationObject, setUpdateApplicationObject] = useState({});
  74. const [editMode, isEditMode] = useState(false);
  75. const [isSave, setiIsSave] = useState(false);
  76. const BackgroundHead = {
  77. backgroundImage: `url(${titleBackgroundImg})`,
  78. width: '100%',
  79. height: '100%',
  80. backgroundSize: 'contain',
  81. backgroundRepeat: 'no-repeat',
  82. backgroundColor: '#0C489E',
  83. backgroundPosition: 'right'
  84. }
  85. const title = groupNo != null ? (appNo + ", " + gazetteIssue + ", " + issueNum + " , " + groupNo +" "+ mode) : (appNo + ", " + gazetteIssue + ", " + issueNum+" "+ mode)
  86. useEffect(() => {
  87. loadApplicationDetail();
  88. }, []);
  89. // useEffect(() => {
  90. // if (reload){
  91. // loadApplicationDetail()
  92. // }
  93. // }, [reload]);
  94. useEffect(() => {
  95. if (editMode && isSave) {
  96. onUpdateClick(updateApplicationObject)
  97. }
  98. }, [updateApplicationObject]);
  99. const loadApplicationDetail = () => {
  100. if (params.id > 0) {
  101. axios.get(`${GET_PUBLIC_NOTICE_APPLY_DETAIL}/${params.id}`)
  102. .then((response) => {
  103. if (response.status === 200) {
  104. setApplicationDetailData(response.data);
  105. setProofCount(response.data.proofCount);
  106. setPaymentCount(response.data.paymentCount);
  107. setStatusHistoryCount(response.data.statusHistoryCount);
  108. const gazetteIssueDetail = response.data.gazetteIssueDetail;
  109. setAapNo(response.data.data.appNo);
  110. setGazetteIssue(gazetteIssueDetail.issueYear + " Vol " + gazetteIssueDetail.volume);
  111. setIssueNum(" No. " + gazetteIssueDetail.issueNo);
  112. setIssueDate(DateUtils.dateFormat(gazetteIssueDetail.issueDate, "D MMM YYYY (ddd)"));
  113. setGroupNo(response.data.data.groupNo);
  114. if (response.data.data?.mode != null){
  115. const modeStr = getModeByTextEng(response.data.data.mode);
  116. setMode("("+modeStr+")");
  117. }
  118. setLoading(false);
  119. }
  120. })
  121. .catch(error => {
  122. console.log(error);
  123. return false;
  124. });
  125. }
  126. }
  127. const onUpdateClick = (updateApplicationObject) => {
  128. const data = updateApplicationObject.objectData
  129. if (params.id > 0) {
  130. setLoading(true);
  131. axios.post(`${UPDATE_PUBLIC_NOTICE_APPLY_DETAIL}/${params.id}`,
  132. {
  133. contactPerson: data.contactPerson,
  134. contactFaxNo: data.contactFaxNo,
  135. contactTelNo: data.contactTelNo,
  136. }
  137. )
  138. .then((response) => {
  139. if (response.status === 200) {
  140. location.reload();
  141. }
  142. })
  143. .catch(error => {
  144. console.log(error);
  145. return false;
  146. });
  147. }
  148. };
  149. useEffect(() => {
  150. // console.log(getStatus)
  151. if (getStatus !== "") {
  152. setOpen(true)
  153. }
  154. }, [getStatus]);
  155. const handleClose = () => {
  156. handleReset()
  157. setOpen(false);
  158. setStatus("")
  159. setStatusWindowAccepted(false)
  160. };
  161. const handleReset = () => {
  162. setSelectedGazetteGroupInputType("")
  163. setSelectedGazetteGroup({});
  164. setReason({});
  165. };
  166. useEffect(() => {
  167. if (!statusWindowAccepted) {
  168. setStatusConfirmLoading(false);
  169. return;
  170. }
  171. setStatusConfirmLoading(true);
  172. if (getStatus == "genGazetteCode") {
  173. onAcceptedClick()
  174. } else if (getStatus == "complete") {
  175. onComplatedClick()
  176. } else if (getStatus == "withdraw") {
  177. onWithdrawnClick()
  178. } else if (getStatus == "notAccepted") {
  179. onNotAcceptClick(getReason);
  180. } else if (getStatus == "resubmit") {
  181. onReSubmitClick(getReason);
  182. } else if (getStatus == "publish") {
  183. onPublishClick();
  184. } else if (getStatus == "revoke") {
  185. onRevokeClick();
  186. } else if(getStatus == "paid"){
  187. onPaidClick();
  188. } else {
  189. setStatusConfirmLoading(false);
  190. setStatusWindowAccepted(false);
  191. }
  192. }, [statusWindowAccepted]);
  193. const onAcceptedClick = () => {
  194. if (params.id > 0) {
  195. axios.post(`${SET_PUBLIC_NOTICE_GROUP_DETAIL}/${params.id}`,
  196. {
  197. "groupTitle": selectedGazetteGroup.title,
  198. "groupNo": selectedGazetteGroup.type,
  199. }
  200. )
  201. .then((response) => {
  202. if (response.status === 204) {
  203. setOpen(false);
  204. handleClose();
  205. // location.reload();
  206. loadApplicationDetail()
  207. notifyActionSuccess("Gen Gazette Code Success!")
  208. }
  209. })
  210. .catch(error => {
  211. console.log(error);
  212. return false;
  213. })
  214. .finally(() => {
  215. setStatusConfirmLoading(false);
  216. setStatusWindowAccepted(false);
  217. });
  218. } else {
  219. setStatusConfirmLoading(false);
  220. setStatusWindowAccepted(false);
  221. }
  222. };
  223. const onNotAcceptClick = (reason) => {
  224. if (params.id <= 0) {
  225. setStatusConfirmLoading(false);
  226. setStatusWindowAccepted(false);
  227. return;
  228. }
  229. HttpUtils.post({
  230. url: `${SET_PUBLIC_NOTICE_STATUS_NOT_ACCEPT}/${params.id}`,
  231. params: reason,
  232. onSuccess: function () {
  233. setOpen(false);
  234. handleClose();
  235. // location.reload();
  236. loadApplicationDetail()
  237. notifySaveSuccess()
  238. },
  239. onFail: () => {
  240. setStatusConfirmLoading(false);
  241. setStatusWindowAccepted(false);
  242. },
  243. onError: () => {
  244. setStatusConfirmLoading(false);
  245. setStatusWindowAccepted(false);
  246. }
  247. });
  248. }
  249. const onPublishClick = () => {
  250. if (params.id <= 0) {
  251. setStatusConfirmLoading(false);
  252. setStatusWindowAccepted(false);
  253. return;
  254. }
  255. HttpUtils.post({
  256. url: `${SET_PUBLIC_NOTICE_STATUS_PUBLISH}/${params.id}`,
  257. onSuccess: function () {
  258. setOpen(false);
  259. handleClose();
  260. loadApplicationDetail()
  261. notifySaveSuccess()
  262. },
  263. onFail: () => {
  264. setStatusConfirmLoading(false);
  265. setStatusWindowAccepted(false);
  266. },
  267. onError: () => {
  268. setStatusConfirmLoading(false);
  269. setStatusWindowAccepted(false);
  270. },
  271. onFinally: () => {
  272. setStatusConfirmLoading(false);
  273. setStatusWindowAccepted(false);
  274. }
  275. });
  276. }
  277. const onPaidClick = () => {
  278. if (params.id > 0) {
  279. axios.post(`${SET_PUBLIC_NOTICE_STATUS_PAID}/${params.id}`)
  280. .then((response) => {
  281. if (response.status === 204) {
  282. setOpen(false);
  283. handleClose();
  284. // location.reload();
  285. loadApplicationDetail()
  286. notifySaveSuccess()
  287. }
  288. })
  289. .catch(error => {
  290. console.log(error);
  291. return false;
  292. })
  293. .finally(() => {
  294. setStatusConfirmLoading(false);
  295. setStatusWindowAccepted(false);
  296. });
  297. } else {
  298. setStatusConfirmLoading(false);
  299. setStatusWindowAccepted(false);
  300. }
  301. };
  302. const onComplatedClick = () => {
  303. if (params.id > 0) {
  304. axios.post(`${SET_PUBLIC_NOTICE_STATUS_COMPLATED}/${params.id}`)
  305. .then((response) => {
  306. if (response.status === 204) {
  307. setOpen(false);
  308. handleClose();
  309. // location.reload();
  310. loadApplicationDetail()
  311. notifySaveSuccess()
  312. }
  313. })
  314. .catch(error => {
  315. console.log(error);
  316. return false;
  317. })
  318. .finally(() => {
  319. setStatusConfirmLoading(false);
  320. setStatusWindowAccepted(false);
  321. });
  322. } else {
  323. setStatusConfirmLoading(false);
  324. setStatusWindowAccepted(false);
  325. }
  326. };
  327. const onWithdrawnClick = () => {
  328. if (params.id > 0) {
  329. axios.post(`${SET_PUBLIC_NOTICE_STATUS_WITHDRAW}/${params.id}`)
  330. .then((response) => {
  331. if (response.status === 204) {
  332. setOpen(false);
  333. handleClose();
  334. loadApplicationDetail()
  335. notifyActionSuccess("Withdrawn Success!")
  336. }
  337. })
  338. .catch(error => {
  339. console.log(error);
  340. return false;
  341. })
  342. .finally(() => {
  343. setStatusConfirmLoading(false);
  344. setStatusWindowAccepted(false);
  345. });
  346. } else {
  347. setStatusConfirmLoading(false);
  348. setStatusWindowAccepted(false);
  349. }
  350. };
  351. const onReSubmitClick = (reason) => {
  352. if (params.id > 0) {
  353. HttpUtils.post({
  354. url: `${SET_PUBLIC_NOTICE_STATUS_RESUBMIT}/${params.id}`,
  355. params: reason,
  356. onSuccess: function () {
  357. setOpen(false);
  358. handleClose();
  359. // location.reload();
  360. loadApplicationDetail()
  361. notifySaveSuccess()
  362. },
  363. onFail: () => {
  364. setStatusConfirmLoading(false);
  365. setStatusWindowAccepted(false);
  366. },
  367. onError: () => {
  368. setStatusConfirmLoading(false);
  369. setStatusWindowAccepted(false);
  370. }
  371. });
  372. // axios.post(`${SET_PUBLIC_NOTICE_STATUS_RESUBMIT}/${params.id}`)
  373. // .then((response) => {
  374. // if (response.status === 204) {
  375. // setOpen(false);
  376. // handleClose();
  377. // // location.reload();
  378. // loadApplicationDetail()
  379. // notifySaveSuccess()
  380. // }
  381. // })
  382. // .catch(error => {
  383. // console.log(error);
  384. // return false;
  385. // });
  386. } else {
  387. setStatusConfirmLoading(false);
  388. setStatusWindowAccepted(false);
  389. }
  390. };
  391. const onRevokeClick = () => {
  392. if (params.id <= 0) {
  393. setStatusConfirmLoading(false);
  394. setStatusWindowAccepted(false);
  395. return;
  396. }
  397. HttpUtils.post({
  398. url: `${SET_PUBLIC_NOTICE_STATUS_REVOKE}/${params.id}`,
  399. onSuccess: function () {
  400. setOpen(false);
  401. handleClose();
  402. loadApplicationDetail()
  403. notifySaveSuccess()
  404. },
  405. onFail: () => {
  406. setStatusConfirmLoading(false);
  407. setStatusWindowAccepted(false);
  408. },
  409. onError: () => {
  410. setStatusConfirmLoading(false);
  411. setStatusWindowAccepted(false);
  412. },
  413. onFinally: () => {
  414. setStatusConfirmLoading(false);
  415. setStatusWindowAccepted(false);
  416. }
  417. });
  418. }
  419. useEffect(() => {
  420. const status = applicationDetailData.data != undefined ? applicationDetailData.data.status : ""
  421. if (status === "submitted" && params.id > 0 && getUploadStatus) {
  422. axios.post(`${SET_PUBLIC_NOTICE_STATUS_REVIEWED}/${params.id}`)
  423. .then((response) => {
  424. if (response.status === 204) {
  425. setUploadStatus(false);
  426. location.reload();
  427. }
  428. })
  429. .catch(error => {
  430. console.log(error);
  431. return false;
  432. });
  433. } else {
  434. setUploadStatus(false);
  435. }
  436. }, [getUploadStatus]);
  437. return (
  438. <Grid container sx={{ width: "100%", backgroundColor: 'backgroundColor.default' }} direction="column">
  439. <StatusChangeDialog open={open}
  440. handleClose={handleClose}
  441. setReason={setReason}
  442. setStatusWindowAccepted={setStatusWindowAccepted}
  443. getStatus={getStatus}
  444. issueDate={issueDate}
  445. issueNum={issueNum}
  446. gazetteIssue={gazetteIssue}
  447. confirmLoading={statusConfirmLoading}
  448. //combo value
  449. selectedGazetteGroup={selectedGazetteGroup}
  450. setSelectedGazetteGroup={setSelectedGazetteGroup}
  451. selectedGazetteGroupInputType={selectedGazetteGroupInputType}
  452. setSelectedGazetteGroupInputType={setSelectedGazetteGroupInputType}
  453. />
  454. <Grid item xs={12} >
  455. <div style={BackgroundHead}>
  456. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  457. <Typography ml={15} color='#FFF' variant="h4">Application</Typography>
  458. </Stack>
  459. </div>
  460. </Grid>
  461. <Grid item xs={12} sm={12} md={12} lg={12}>
  462. <Stack direction="row">
  463. <Button title="Back" sx={{ ml: 3.5, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}>
  464. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  465. </Button>
  466. <Typography ml={4} mt={3} variant="h4">{title}</Typography>
  467. </Stack>
  468. </Grid>
  469. {/* <Grid item xs={12} >
  470. <Stack direction="row" height='20px' justifyContent="flex-start" alignItems="center">
  471. <Typography ml={4} mt={3} variant="h4">{title}</Typography>
  472. </Stack>
  473. </Grid> */}
  474. <Grid item xs={12} sm={12} md={12} lg={12} xl={12} >
  475. <Grid container direction="row">
  476. <Grid item xs={12} md={12} lg={9} xl={9}>
  477. <Grid container direction="column">
  478. <Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
  479. <Box xs={12} sx={{ ml: 2, mt: 3, mr: { xs: 2, sm: 2 }, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  480. {isLoading && editMode ?
  481. <LoadingComponent /> :
  482. <ApplicationDetailCard
  483. applicationDetailData={applicationDetailData}
  484. setStatus={setStatus}
  485. // setReload = {setReload}
  486. setUploadStatus={setUploadStatus}
  487. setUpdateApplicationObject={setUpdateApplicationObject}
  488. isEditMode={isEditMode}
  489. setiIsSave={setiIsSave}
  490. statusDialogOpen={open}
  491. statusDialogKind={getStatus}
  492. statusActionLoading={statusConfirmLoading}
  493. // isNewRecord={isNewRecord}
  494. />
  495. }
  496. </Box>
  497. </Grid>
  498. <Grid item xs={12} md={12} lg={12} xl={12}>
  499. <Box xs={12} sx={{ ml: 2, mt: 3, mr: { xs: 2, sm: 2 }, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  500. <GazetteDetailCard
  501. // updateUserObject={updateUserObject}
  502. applicationDetailData={applicationDetailData}
  503. setStatus={setStatus}
  504. // isCollectData={isCollectData}
  505. // isNewRecord={isNewRecord}
  506. />
  507. </Box>
  508. </Grid>
  509. <Grid item xs={12} md={12} lg={12} xl={12}>
  510. <Box xs={12} sx={{ ml: 2, mt: 3, mr: { sm: 2 }, borderRadius: '10px', width: { xs: '92vw', sm: '96.5vw', md: "auto" }, backgroundColor: '#ffffff' }}>
  511. <TabTableDetail
  512. appId={params.id}
  513. proofCount={proofCount}
  514. paymentCount={paymentCount}
  515. statusHistoryCount={statusHistoryCount}
  516. setProofCount = {setProofCount}
  517. setPaymentCount = {setPaymentCount}
  518. setStatusHistoryCount = {setStatusHistoryCount}
  519. />
  520. </Box>
  521. <br />
  522. </Grid>
  523. </Grid>
  524. </Grid>
  525. <Grid item xs={12} md={12} lg={3} xl={3} sx={{ mt: { xs: -3, sm: -3 } }}>
  526. <Grid container>
  527. <Grid item xs={12} md={12}>
  528. <Box xs={12} md={12} sx={{ ml: 2, mt: 3, mb: 3, mr: { xs: 2, sm: 2 }, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  529. <ClientDetailCard
  530. // updateUserObject={updateUserObject}
  531. applicationDetailData={applicationDetailData}
  532. // isCollectData={isCollectData}
  533. // isNewRecord={isNewRecord}
  534. />
  535. </Box>
  536. </Grid>
  537. </Grid>
  538. </Grid>
  539. </Grid>
  540. </Grid>
  541. </Grid>
  542. );
  543. };
  544. export default PublicNoticeDetail_GLD;