Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

475 linhas
15 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. // ==============================|| Body - DEFAULT ||============================== //
  45. const PublicNoticeDetail_GLD = () => {
  46. const params = useParams();
  47. const navigate = useNavigate()
  48. const [applicationDetailData, setApplicationDetailData] = useState({});
  49. const [isLoading, setLoading] = useState(false);
  50. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  51. const [getUploadStatus, setUploadStatus] = useState(false);
  52. const [proofCount, setProofCount] = useState(0);
  53. const [paymentCount, setPaymentCount] = useState(0);
  54. const [statusHistoryCount, setStatusHistoryCount] = useState(0);
  55. //pageTitle
  56. const [appNo, setAapNo] = useState("");
  57. const [gazetteIssue, setGazetteIssue] = useState("");
  58. const [issueDate, setIssueDate] = useState("");
  59. const [issueNum, setIssueNum] = useState("");
  60. const [groupNo, setGroupNo] = useState("");
  61. // const [groupTitle, setGroupTitle] = useState("");
  62. //statusWindow
  63. const [open, setOpen] = useState(false);
  64. const [getStatus, setStatus] = useState("");
  65. const [statusWindowAccepted, setStatusWindowAccepted] = useState(false);
  66. const [selectedGazetteGroup, setSelectedGazetteGroup] = useState({});
  67. const [selectedGazetteGroupInputType, setSelectedGazetteGroupInputType] = useState("");
  68. const [getReason, setReason] = useState({});
  69. //editMode
  70. const [updateApplicationObject, setUpdateApplicationObject] = useState({});
  71. const [editMode, isEditMode] = useState(false);
  72. const [isSave, setiIsSave] = useState(false);
  73. const BackgroundHead = {
  74. backgroundImage: `url(${titleBackgroundImg})`,
  75. width: '100%',
  76. height: '100%',
  77. backgroundSize: 'contain',
  78. backgroundRepeat: 'no-repeat',
  79. backgroundColor: '#0C489E',
  80. backgroundPosition: 'right'
  81. }
  82. const title = groupNo != null ? (appNo + ", " + gazetteIssue + ", " + issueNum + " , " + groupNo) : (appNo + ", " + gazetteIssue + ", " + issueNum)
  83. useEffect(() => {
  84. loadApplicationDetail();
  85. }, []);
  86. // useEffect(() => {
  87. // if (reload){
  88. // loadApplicationDetail()
  89. // }
  90. // }, [reload]);
  91. useEffect(() => {
  92. if (editMode && isSave) {
  93. onUpdateClick(updateApplicationObject)
  94. }
  95. }, [updateApplicationObject]);
  96. const loadApplicationDetail = () => {
  97. if (params.id > 0) {
  98. axios.get(`${GET_PUBLIC_NOTICE_APPLY_DETAIL}/${params.id}`)
  99. .then((response) => {
  100. if (response.status === 200) {
  101. setApplicationDetailData(response.data);
  102. setProofCount(response.data.proofCount);
  103. setPaymentCount(response.data.paymentCount);
  104. setStatusHistoryCount(response.data.statusHistoryCount);
  105. const gazetteIssueDetail = response.data.gazetteIssueDetail;
  106. setAapNo(response.data.data.appNo);
  107. setGazetteIssue(gazetteIssueDetail.issueYear + " Vol " + gazetteIssueDetail.volume);
  108. setIssueNum(" No. " + gazetteIssueDetail.issueNo);
  109. setIssueDate(DateUtils.dateFormat(gazetteIssueDetail.issueDate, "D MMM YYYY (ddd)"));
  110. setGroupNo(response.data.data.groupNo);
  111. setLoading(false);
  112. }
  113. })
  114. .catch(error => {
  115. console.log(error);
  116. return false;
  117. });
  118. }
  119. }
  120. const onUpdateClick = (updateApplicationObject) => {
  121. const data = updateApplicationObject.objectData
  122. if (params.id > 0) {
  123. setLoading(true);
  124. axios.post(`${UPDATE_PUBLIC_NOTICE_APPLY_DETAIL}/${params.id}`,
  125. {
  126. contactPerson: data.contactPerson,
  127. contactFaxNo: data.contactFaxNo,
  128. contactTelNo: data.contactTelNo,
  129. }
  130. )
  131. .then((response) => {
  132. if (response.status === 200) {
  133. location.reload();
  134. }
  135. })
  136. .catch(error => {
  137. console.log(error);
  138. return false;
  139. });
  140. }
  141. };
  142. useEffect(() => {
  143. // console.log(getStatus)
  144. if (getStatus !== "") {
  145. setOpen(true)
  146. }
  147. }, [getStatus]);
  148. const handleClose = () => {
  149. handleReset()
  150. setOpen(false);
  151. setStatus("")
  152. setStatusWindowAccepted(false)
  153. };
  154. const handleReset = () => {
  155. setSelectedGazetteGroupInputType("")
  156. setSelectedGazetteGroup({});
  157. setReason({});
  158. };
  159. useEffect(() => {
  160. if (statusWindowAccepted) {
  161. if (getStatus == "genGazetteCode") {
  162. onAcceptedClick()
  163. } else if (getStatus == "complete") {
  164. onComplatedClick()
  165. } else if (getStatus == "withdraw") {
  166. onWithdrawnClick()
  167. } else if (getStatus == "notAccepted") {
  168. onNotAcceptClick(getReason);
  169. } else if (getStatus == "resubmit") {
  170. onReSubmitClick(getReason);
  171. } else if (getStatus == "publish") {
  172. onPublishClick();
  173. } else if (getStatus == "revoke") {
  174. onRevokeClick();
  175. } else if(getStatus == "paid"){
  176. onPaidClick();
  177. }
  178. }
  179. }, [statusWindowAccepted]);
  180. const onAcceptedClick = () => {
  181. if (params.id > 0) {
  182. axios.post(`${SET_PUBLIC_NOTICE_GROUP_DETAIL}/${params.id}`,
  183. {
  184. "groupTitle": selectedGazetteGroup.title,
  185. "groupNo": selectedGazetteGroup.type,
  186. }
  187. )
  188. .then((response) => {
  189. if (response.status === 204) {
  190. setOpen(false);
  191. handleClose();
  192. // location.reload();
  193. loadApplicationDetail()
  194. notifyActionSuccess("Gen Gazette Code Success!")
  195. }
  196. })
  197. .catch(error => {
  198. console.log(error);
  199. return false;
  200. });
  201. }
  202. };
  203. const onNotAcceptClick = (reason) => {
  204. if (params.id <= 0) return;
  205. HttpUtils.post({
  206. url: `${SET_PUBLIC_NOTICE_STATUS_NOT_ACCEPT}/${params.id}`,
  207. params: reason,
  208. onSuccess: function () {
  209. setOpen(false);
  210. handleClose();
  211. // location.reload();
  212. loadApplicationDetail()
  213. notifySaveSuccess()
  214. }
  215. });
  216. }
  217. const onPublishClick = () => {
  218. if (params.id <= 0) return;
  219. HttpUtils.get({
  220. url: `${SET_PUBLIC_NOTICE_STATUS_PUBLISH}/${params.id}`,
  221. onSuccess: function () {
  222. setOpen(false);
  223. handleClose();
  224. loadApplicationDetail()
  225. notifySaveSuccess()
  226. }
  227. });
  228. }
  229. const onPaidClick = () => {
  230. if (params.id > 0) {
  231. axios.get(`${SET_PUBLIC_NOTICE_STATUS_PAID}/${params.id}`)
  232. .then((response) => {
  233. if (response.status === 204) {
  234. setOpen(false);
  235. handleClose();
  236. // location.reload();
  237. loadApplicationDetail()
  238. notifySaveSuccess()
  239. }
  240. })
  241. .catch(error => {
  242. console.log(error);
  243. return false;
  244. });
  245. }
  246. };
  247. const onComplatedClick = () => {
  248. if (params.id > 0) {
  249. axios.get(`${SET_PUBLIC_NOTICE_STATUS_COMPLATED}/${params.id}`)
  250. .then((response) => {
  251. if (response.status === 204) {
  252. setOpen(false);
  253. handleClose();
  254. // location.reload();
  255. loadApplicationDetail()
  256. notifySaveSuccess()
  257. }
  258. })
  259. .catch(error => {
  260. console.log(error);
  261. return false;
  262. });
  263. }
  264. };
  265. const onWithdrawnClick = () => {
  266. if (params.id > 0) {
  267. axios.get(`${SET_PUBLIC_NOTICE_STATUS_WITHDRAW}/${params.id}`)
  268. .then((response) => {
  269. if (response.status === 204) {
  270. setOpen(false);
  271. handleClose();
  272. loadApplicationDetail()
  273. notifyActionSuccess("Withdrawn Success!")
  274. }
  275. })
  276. .catch(error => {
  277. console.log(error);
  278. return false;
  279. });
  280. }
  281. };
  282. const onReSubmitClick = (reason) => {
  283. if (params.id > 0) {
  284. HttpUtils.post({
  285. url: `${SET_PUBLIC_NOTICE_STATUS_RESUBMIT}/${params.id}`,
  286. params: reason,
  287. onSuccess: function () {
  288. setOpen(false);
  289. handleClose();
  290. // location.reload();
  291. loadApplicationDetail()
  292. notifySaveSuccess()
  293. }
  294. });
  295. // axios.post(`${SET_PUBLIC_NOTICE_STATUS_RESUBMIT}/${params.id}`)
  296. // .then((response) => {
  297. // if (response.status === 204) {
  298. // setOpen(false);
  299. // handleClose();
  300. // // location.reload();
  301. // loadApplicationDetail()
  302. // notifySaveSuccess()
  303. // }
  304. // })
  305. // .catch(error => {
  306. // console.log(error);
  307. // return false;
  308. // });
  309. }
  310. };
  311. const onRevokeClick = () => {
  312. if (params.id <= 0) return;
  313. HttpUtils.get({
  314. url: `${SET_PUBLIC_NOTICE_STATUS_REVOKE}/${params.id}`,
  315. onSuccess: function () {
  316. setOpen(false);
  317. handleClose();
  318. loadApplicationDetail()
  319. notifySaveSuccess()
  320. }
  321. });
  322. }
  323. useEffect(() => {
  324. const status = applicationDetailData.data != undefined ? applicationDetailData.data.status : ""
  325. if (status === "submitted" && params.id > 0 && getUploadStatus) {
  326. axios.get(`${SET_PUBLIC_NOTICE_STATUS_REVIEWED}/${params.id}`)
  327. .then((response) => {
  328. if (response.status === 204) {
  329. setUploadStatus(false);
  330. location.reload();
  331. }
  332. })
  333. .catch(error => {
  334. console.log(error);
  335. return false;
  336. });
  337. } else {
  338. setUploadStatus(false);
  339. }
  340. }, [getUploadStatus]);
  341. return (
  342. <Grid container sx={{ width: "100%", backgroundColor: 'backgroundColor.default' }} direction="column">
  343. <StatusChangeDialog open={open}
  344. handleClose={handleClose}
  345. setReason={setReason}
  346. setStatusWindowAccepted={setStatusWindowAccepted}
  347. getStatus={getStatus}
  348. issueDate={issueDate}
  349. issueNum={issueNum}
  350. gazetteIssue={gazetteIssue}
  351. //combo value
  352. selectedGazetteGroup={selectedGazetteGroup}
  353. setSelectedGazetteGroup={setSelectedGazetteGroup}
  354. selectedGazetteGroupInputType={selectedGazetteGroupInputType}
  355. setSelectedGazetteGroupInputType={setSelectedGazetteGroupInputType}
  356. />
  357. <Grid item xs={12} >
  358. <div style={BackgroundHead}>
  359. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  360. <Typography ml={15} color='#FFF' variant="h4">Application</Typography>
  361. </Stack>
  362. </div>
  363. </Grid>
  364. <Grid item xs={12} sm={12} md={12} lg={12}>
  365. <Stack direction="row">
  366. <Button title="Back" sx={{ ml: 3.5, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}>
  367. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  368. </Button>
  369. <Typography ml={4} mt={3} variant="h4">{title}</Typography>
  370. </Stack>
  371. </Grid>
  372. {/* <Grid item xs={12} >
  373. <Stack direction="row" height='20px' justifyContent="flex-start" alignItems="center">
  374. <Typography ml={4} mt={3} variant="h4">{title}</Typography>
  375. </Stack>
  376. </Grid> */}
  377. <Grid item xs={12} sm={12} md={12} lg={12} xl={12} >
  378. <Grid container direction="row">
  379. <Grid item xs={12} md={12} lg={9} xl={9}>
  380. <Grid container direction="column">
  381. <Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
  382. <Box xs={12} sx={{ ml: 2, mt: 3, mr: { xs: 2, sm: 2 }, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  383. {isLoading && editMode ?
  384. <LoadingComponent /> :
  385. <ApplicationDetailCard
  386. applicationDetailData={applicationDetailData}
  387. setStatus={setStatus}
  388. // setReload = {setReload}
  389. setUploadStatus={setUploadStatus}
  390. setUpdateApplicationObject={setUpdateApplicationObject}
  391. isEditMode={isEditMode}
  392. setiIsSave={setiIsSave}
  393. // isNewRecord={isNewRecord}
  394. />
  395. }
  396. </Box>
  397. </Grid>
  398. <Grid item xs={12} md={12} lg={12} xl={12}>
  399. <Box xs={12} sx={{ ml: 2, mt: 3, mr: { xs: 2, sm: 2 }, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  400. <GazetteDetailCard
  401. // updateUserObject={updateUserObject}
  402. applicationDetailData={applicationDetailData}
  403. setStatus={setStatus}
  404. // isCollectData={isCollectData}
  405. // isNewRecord={isNewRecord}
  406. />
  407. </Box>
  408. </Grid>
  409. <Grid item xs={12} md={12} lg={12} xl={12}>
  410. <Box xs={12} sx={{ ml: 2, mt: 3, mr: { sm: 2 }, borderRadius: '10px', width: { xs: '92vw', sm: '96.5vw', md: "auto" }, backgroundColor: '#ffffff' }}>
  411. <TabTableDetail
  412. appId={params.id}
  413. proofCount={proofCount}
  414. paymentCount={paymentCount}
  415. statusHistoryCount={statusHistoryCount}
  416. setProofCount = {setProofCount}
  417. setPaymentCount = {setPaymentCount}
  418. setStatusHistoryCount = {setStatusHistoryCount}
  419. />
  420. </Box>
  421. <br />
  422. </Grid>
  423. </Grid>
  424. </Grid>
  425. <Grid item xs={12} md={12} lg={3} xl={3} sx={{ mt: { xs: -3, sm: -3 } }}>
  426. <Grid container>
  427. <Grid item xs={12} md={12}>
  428. <Box xs={12} md={12} sx={{ ml: 2, mt: 3, mb: 3, mr: { xs: 2, sm: 2 }, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  429. <ClientDetailCard
  430. // updateUserObject={updateUserObject}
  431. applicationDetailData={applicationDetailData}
  432. // isCollectData={isCollectData}
  433. // isNewRecord={isNewRecord}
  434. />
  435. </Box>
  436. </Grid>
  437. </Grid>
  438. </Grid>
  439. </Grid>
  440. </Grid>
  441. </Grid>
  442. );
  443. };
  444. export default PublicNoticeDetail_GLD;