You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

651 line
38 KiB

  1. // material-ui
  2. import {
  3. FormControl,
  4. Button,
  5. Grid,
  6. Typography, FormLabel,
  7. OutlinedInput,
  8. Stack,
  9. Dialog, DialogTitle, DialogContent, DialogActions, InputAdornment,
  10. } from '@mui/material';
  11. import {isGranted, delBugMode } from "auth/utils";
  12. const MainCard = Loadable(lazy(() => import('components/MainCard')));
  13. import { useForm } from "react-hook-form";
  14. import {
  15. useEffect,
  16. useState,
  17. lazy
  18. } from "react";
  19. import Loadable from 'components/Loadable';
  20. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  21. import * as HttpUtils from "utils/HttpUtils"
  22. import * as DateUtils from "utils/DateUtils"
  23. import {CHECK_CREATE_PROOF} from "utils/ApiPathConst"
  24. import * as StatusUtils from "utils/statusUtils/PublicNoteStatusUtils";
  25. import DoneIcon from '@mui/icons-material/Done';
  26. import CloseIcon from '@mui/icons-material/Close';
  27. import EditNoteIcon from '@mui/icons-material/EditNote';
  28. import DownloadIcon from '@mui/icons-material/Download';
  29. import ReplayIcon from '@mui/icons-material/Replay';
  30. import { notifyDownloadSuccess } from 'utils/CommonFunction';
  31. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  32. const ApplicationDetailCard = (
  33. { applicationDetailData,
  34. setStatus,
  35. setUploadStatus
  36. }
  37. ) => {
  38. const [currentApplicationDetailData, setCurrentApplicationDetailData] = useState({});
  39. const [companyName, setCompanyName] = useState({});
  40. const [verified, setVerified] = useState(null);
  41. const [fileDetail, setfileDetail] = useState({});
  42. const [onReady, setOnReady] = useState(false);
  43. const { register } = useForm()
  44. const [isWarningPopUp, setIsWarningPopUp] = useState(false);
  45. const [warningText, setWarningText] = useState("");
  46. useEffect(() => {
  47. //if user data from parent are not null
  48. // console.log(applicationDetailData)
  49. if (Object.keys(applicationDetailData).length > 0) {
  50. loadApplicationDetail()
  51. }
  52. }, [applicationDetailData]);
  53. useEffect(() => {
  54. //if state data are ready and assign to different field
  55. // console.log(currentApplicationDetailData)
  56. if (Object.keys(currentApplicationDetailData).length > 0) {
  57. setOnReady(true);
  58. }
  59. }, [currentApplicationDetailData]);
  60. const loadApplicationDetail = () => {
  61. setCurrentApplicationDetailData(applicationDetailData.data);
  62. setCompanyName(applicationDetailData.companyName);
  63. setVerified(applicationDetailData.userData.verifiedBy ? true : false)
  64. setfileDetail(applicationDetailData.fileDetail);
  65. // setReload(false)
  66. }
  67. const onDownloadClick = () => () => {
  68. HttpUtils.fileDownload({
  69. fileId: fileDetail?.id,
  70. skey: fileDetail?.skey,
  71. filename: fileDetail?.filename,
  72. });
  73. notifyDownloadSuccess()
  74. setUploadStatus(true)
  75. };
  76. const reSubmitClick = () => () => {
  77. setStatus("resubmit")
  78. };
  79. const notAcceptedClick = () => () => {
  80. setStatus("notAccepted")
  81. };
  82. const setCompleteDisable = () => {
  83. if (delBugMode) return false;
  84. return (new Date()).getTime() < DateUtils.convertToDate(applicationDetailData.gazetteIssueDetail.issueDate).getTime();
  85. }
  86. const complatedClick = () => () => {
  87. let issueDate = DateUtils.convertToDate(applicationDetailData.gazetteIssueDetail.issueDate);
  88. let current = new Date();
  89. if (delBugMode) {
  90. setStatus("complete")
  91. } else if (current.getTime() >= issueDate.getTime()) {
  92. setStatus("complete")
  93. }
  94. };
  95. const withdrawnClick = () => () => {
  96. setStatus("withdraw")
  97. };
  98. const doPublish = () => () => {
  99. setStatus("publish")
  100. }
  101. const revokeClick = () => () => {
  102. setStatus("revoke")
  103. };
  104. const onProofClick = () => {
  105. if (applicationDetailData.data.groupNo) {
  106. HttpUtils.get({
  107. url: CHECK_CREATE_PROOF + "/" + currentApplicationDetailData.id,
  108. onSuccess: function (responeData) {
  109. if (responeData.success == true) {
  110. window.open("/proof/create/" + currentApplicationDetailData.id, "_blank", "noreferrer");
  111. window.addEventListener("focus", onFocus)
  112. } else {
  113. let msg = responeData.msg;
  114. if (msg === "haveActiveProof") {
  115. msg = "Action Failed: There is already a pending payment and proofreading record for client review."
  116. } else if (msg === "haveProofed") {
  117. msg = "Action Failed: Already proofed."
  118. }
  119. setWarningText(msg);
  120. setIsWarningPopUp(true);
  121. }
  122. }
  123. });
  124. } else {
  125. setWarningText("Please generate Gazette Code before Create Proof.");
  126. setIsWarningPopUp(true);
  127. }
  128. }
  129. const onFocus = () => {
  130. location.reload();
  131. window.removeEventListener("focus", onFocus)
  132. }
  133. return (
  134. !onReady ?
  135. <LoadingComponent />
  136. :
  137. <MainCard elevation={0}
  138. border={false}
  139. content={false}
  140. >
  141. {verified && currentApplicationDetailData.status !== "notAccepted" ?
  142. <Grid container spacing={4} direction="row">
  143. <Grid item xs={12} md={4} >
  144. <Stack
  145. direction="row"
  146. justifyContent="flex-start"
  147. alignItems="center"
  148. spacing={2}
  149. mb={2}
  150. >
  151. {currentApplicationDetailData.status === "reviewed" && isGranted("MAINTAIN_PROOF") ?
  152. <Button
  153. // size="large"
  154. variant="contained"
  155. onClick={() => { onProofClick() }}
  156. sx={{
  157. textTransform: 'capitalize',
  158. alignItems: 'end'
  159. }}>
  160. <EditNoteIcon />
  161. <Typography ml={1} variant="h5"> Create Proof</Typography>
  162. </Button> :
  163. null
  164. }
  165. </Stack>
  166. </Grid>
  167. <Grid item xs={12} md={8} >
  168. <Stack
  169. direction="row"
  170. justifyContent="flex-start"
  171. alignItems="center"
  172. spacing={2}
  173. mb={2}
  174. >
  175. {currentApplicationDetailData.status === "submitted" || currentApplicationDetailData.status == "reviewed" ?
  176. <>
  177. <Button
  178. // size="large"
  179. variant="contained"
  180. onClick={reSubmitClick()}
  181. color="orange"
  182. >
  183. <ReplayIcon />
  184. <Typography ml={1} variant="h5"> Re-Submit</Typography>
  185. </Button>
  186. <Button
  187. // size="large"
  188. variant="contained"
  189. onClick={notAcceptedClick()}
  190. color="error"
  191. sx={{
  192. textTransform: 'capitalize',
  193. alignItems: 'end',
  194. }}>
  195. <CloseIcon />
  196. <Typography ml={1} variant="h5">Not Accept</Typography>
  197. </Button>
  198. </> :
  199. (currentApplicationDetailData.status == "confirmed" && currentApplicationDetailData.creditor == 1) ?
  200. <>
  201. <Button
  202. // size="large"
  203. variant="contained"
  204. onClick={doPublish()}
  205. disabled={setCompleteDisable()}
  206. sx={{
  207. textTransform: 'capitalize',
  208. alignItems: 'end',
  209. backgroundColor: '#52b202'
  210. }}>
  211. <DoneIcon />
  212. <Typography ml={1} variant="h5">Publish</Typography>
  213. </Button>
  214. <Button
  215. // size="large"
  216. variant="contained"
  217. onClick={withdrawnClick()}
  218. sx={{
  219. textTransform: 'capitalize',
  220. alignItems: 'end',
  221. backgroundColor: '#ffa733'
  222. }}>
  223. <CloseIcon />
  224. <Typography ml={1} variant="h5">Withdraw</Typography>
  225. </Button>
  226. </>
  227. :
  228. (currentApplicationDetailData.status == "confirmed" && currentApplicationDetailData.creditor == 0) ?
  229. <>
  230. <Button
  231. // size="large"
  232. variant="contained"
  233. onClick={withdrawnClick()}
  234. sx={{
  235. textTransform: 'capitalize',
  236. alignItems: 'end',
  237. backgroundColor: '#ffa733'
  238. }}>
  239. <CloseIcon />
  240. <Typography ml={1} variant="h5">Withdraw</Typography>
  241. </Button>
  242. </>
  243. :
  244. (
  245. (currentApplicationDetailData.status == "paid" && currentApplicationDetailData.creditor == 0) ?
  246. <>
  247. <Button
  248. // size="large"
  249. variant="contained"
  250. onClick={revokeClick()}
  251. disabled={currentApplicationDetailData.paymentMethod=="online"||currentApplicationDetailData.paymentMethod==null}
  252. sx={{
  253. textTransform: 'capitalize',
  254. alignItems: 'end',
  255. backgroundColor: '#ffa733'
  256. }}>
  257. <ReplayIcon />
  258. <Typography ml={1} variant="h5">Revoke Payment</Typography>
  259. </Button>
  260. <Button
  261. // size="large"
  262. variant="contained"
  263. onClick={complatedClick()}
  264. disabled={setCompleteDisable()}
  265. sx={{
  266. textTransform: 'capitalize',
  267. alignItems: 'end',
  268. backgroundColor: '#52b202'
  269. }}>
  270. <DoneIcon />
  271. <Typography ml={1} variant="h5">Publish</Typography>
  272. </Button>
  273. <Button
  274. // size="large"
  275. variant="contained"
  276. onClick={withdrawnClick()}
  277. sx={{
  278. textTransform: 'capitalize',
  279. alignItems: 'end',
  280. backgroundColor: '#ffa733'
  281. }}>
  282. <CloseIcon />
  283. <Typography ml={1} variant="h5">Withdraw</Typography>
  284. </Button>
  285. </> : null
  286. )
  287. }
  288. </Stack>
  289. </Grid>
  290. </Grid> : null
  291. }
  292. <Typography variant="h4" xs={12} md={12} sx={{ mb: 2, borderBottom: "1px solid black" }}>
  293. Application Details
  294. </Typography>
  295. <form>
  296. <Grid container direction="column">
  297. <Grid item xs={12} md={12}>
  298. <Grid container direction="row" justifyContent="flex-start"
  299. alignItems="center">
  300. <Grid item xs={12} md={6} lg={6} sx={{ mb: 1 }}>
  301. <Grid container alignItems={"center"}>
  302. <Grid item xs={12} md={4} lg={4}
  303. sx={{ display: 'flex', alignItems: 'center' }}>
  304. <FormLabel><Typography variant="h5">Application No:</Typography></FormLabel>
  305. </Grid>
  306. <Grid item xs={12} md={8} lg={8}>
  307. <FormControl variant="outlined" fullWidth disabled >
  308. <OutlinedInput
  309. fullWidth
  310. size="small"
  311. {...register("appNo",
  312. {
  313. value: currentApplicationDetailData.appNo,
  314. })}
  315. id='appNo'
  316. sx={{
  317. "& .MuiInputBase-input.Mui-disabled": {
  318. WebkitTextFillColor: "#000000",
  319. background: "#f8f8f8",
  320. },
  321. }}
  322. />
  323. </FormControl>
  324. </Grid>
  325. </Grid>
  326. </Grid>
  327. <Grid item xs={12} sm={12} md={5.5} lg={5} sx={{ mb: 1 , ml: { md: 1, lg: 3 } }}>
  328. <Grid container alignItems={"center"}>
  329. <Grid item xs={12} md={4} lg={4}
  330. sx={{ display: 'flex', alignItems: 'center' }}>
  331. <FormLabel><Typography variant="h5">Status:</Typography></FormLabel>
  332. </Grid>
  333. <Grid item xs={12} md={8} lg={8}>
  334. <FormControl variant="outlined">
  335. {StatusUtils.getStatusByTextEng(currentApplicationDetailData.status, currentApplicationDetailData.creditor)}
  336. </FormControl>
  337. </Grid>
  338. </Grid>
  339. {
  340. currentApplicationDetailData.reason ?
  341. <Grid item xs={12} md={12} lg={12}>
  342. <Grid container alignItems={"center"} direction="row" >
  343. <Grid item xs={12} md={4} lg={4}>
  344. <FormLabel><Typography variant="h5">Reason:</Typography></FormLabel>
  345. </Grid>
  346. <Grid item xs={12} md={8} lg={8}>
  347. <FormLabel>
  348. <Typography id='reason' variant="pnspsFormParagraph">
  349. {currentApplicationDetailData.reason}
  350. </Typography>
  351. </FormLabel>
  352. </Grid>
  353. </Grid>
  354. </Grid>
  355. : ""
  356. }
  357. </Grid>
  358. </Grid>
  359. <Grid container direction="row" justifyContent="flex-start"
  360. alignItems="center">
  361. <Grid item xs={12} md={6} lg={6} sx={{ mb: 1 }}>
  362. <Grid container alignItems={"center"}>
  363. <Grid item xs={12} md={4} lg={4}
  364. sx={{ display: 'flex', alignItems: 'center' }}>
  365. <FormLabel><Typography variant="h5">Applicant:</Typography></FormLabel>
  366. </Grid>
  367. <Grid item xs={12} md={8} lg={8}>
  368. <FormControl variant="outlined" fullWidth disabled >
  369. {currentApplicationDetailData.orgId === null ?
  370. <OutlinedInput
  371. fullWidth
  372. size="small"
  373. {...register("contactPerson",
  374. {
  375. value: currentApplicationDetailData.contactPerson,
  376. })}
  377. id='contactPerson'
  378. sx={{
  379. "& .MuiInputBase-input.Mui-disabled": {
  380. WebkitTextFillColor: "#000000",
  381. background: "#f8f8f8",
  382. },
  383. }}
  384. /> :
  385. <OutlinedInput
  386. fullWidth
  387. size="small"
  388. {...register("companyName",
  389. {
  390. value: companyName.enCompanyName,
  391. })}
  392. id='companyName'
  393. sx={{
  394. "& .MuiInputBase-input.Mui-disabled": {
  395. WebkitTextFillColor: "#000000",
  396. background: "#f8f8f8",
  397. },
  398. }}
  399. />
  400. }
  401. </FormControl>
  402. </Grid>
  403. </Grid>
  404. </Grid>
  405. <Grid item xs={12} md={5.5} lg={5.5} sx={{ mb: 1, ml: { md: 1, lg: 3 } }}>
  406. <Grid container alignItems={"center"}>
  407. <Grid item xs={12} md={4} lg={4}
  408. sx={{ display: 'flex', alignItems: 'center' }}>
  409. <FormLabel><Typography variant="h5">Contact Phone:</Typography></FormLabel>
  410. </Grid>
  411. <Grid item xs={12} md={8} lg={8}>
  412. <Stack direction="row">
  413. <FormControl variant="outlined" sx={{ width: '25%', minWidth: 100, }} disabled >
  414. <OutlinedInput
  415. size="small"
  416. {...register("contactTelNo.countryCode",
  417. {
  418. value: currentApplicationDetailData.contactTelNo.countryCode,
  419. })}
  420. id='countryCode'
  421. sx={{
  422. "& .MuiInputBase-input.Mui-disabled": {
  423. WebkitTextFillColor: "#000000",
  424. background: "#f8f8f8",
  425. },
  426. mr: 1
  427. }}
  428. inputProps={{
  429. maxLength: 3,
  430. }}
  431. endAdornment={<InputAdornment position="end">-</InputAdornment>}
  432. />
  433. </FormControl>
  434. <FormControl variant="outlined" sx={{ width: '75%' }} disabled >
  435. <OutlinedInput
  436. size="small"
  437. type="tel"
  438. {...register("contactTelNo.phoneNumber",
  439. {
  440. value: currentApplicationDetailData.contactTelNo.phoneNumber,
  441. })}
  442. id='phoneNumber'
  443. sx={{
  444. "& .MuiInputBase-input.Mui-disabled": {
  445. WebkitTextFillColor: "#000000",
  446. background: "#f8f8f8",
  447. },
  448. }}
  449. inputProps={{
  450. maxLength: 11,
  451. }}
  452. />
  453. </FormControl>
  454. </Stack>
  455. </Grid>
  456. </Grid>
  457. </Grid>
  458. </Grid>
  459. <Grid container direction="row" justifyContent="flex-start"
  460. alignItems="center">
  461. <Grid item xs={12} md={6} lg={6} sx={{ mb: 1 }}>
  462. <Grid container alignItems={"center"}>
  463. <Grid item xs={12} md={4} lg={4}
  464. sx={{ display: 'flex', alignItems: 'center' }}>
  465. <FormLabel><Typography variant="h5">Contact Person:</Typography></FormLabel>
  466. </Grid>
  467. <Grid item xs={12} md={8} lg={8}>
  468. <FormControl variant="outlined" fullWidth disabled>
  469. <OutlinedInput
  470. fullWidth
  471. size="small"
  472. {...register("contactPerson",
  473. {
  474. value: currentApplicationDetailData.contactPerson,
  475. })}
  476. id='contactPerson'
  477. sx={{
  478. "& .MuiInputBase-input.Mui-disabled": {
  479. WebkitTextFillColor: "#000000",
  480. background: "#f8f8f8",
  481. },
  482. }}
  483. />
  484. </FormControl>
  485. </Grid>
  486. </Grid>
  487. </Grid>
  488. <Grid item xs={12} md={5.5} lg={5.5} sx={{ mb: 1, ml: { md: 1, lg: 3 } }}>
  489. <Grid container alignItems={"center"}>
  490. <Grid item xs={12} md={4} lg={4}
  491. sx={{ display: 'flex', alignItems: 'center' }}>
  492. <FormLabel><Typography variant="h5">Contact Fax:</Typography></FormLabel>
  493. </Grid>
  494. <Grid item xs={12} md={8} lg={8}>
  495. <Stack direction="row">
  496. <FormControl variant="outlined" sx={{ width: '25%', minWidth: 100, }} disabled>
  497. <OutlinedInput
  498. size="small"
  499. {...register("contactFaxNo.countryCode",
  500. {
  501. value: currentApplicationDetailData.contactFaxNo.countryCode,
  502. })}
  503. id='countryCode'
  504. sx={{
  505. "& .MuiInputBase-input.Mui-disabled": {
  506. WebkitTextFillColor: "#000000",
  507. background: "#f8f8f8",
  508. },
  509. mr: 1,
  510. }}
  511. inputProps={{
  512. maxLength: 3,
  513. type: "tel"
  514. }}
  515. endAdornment={<InputAdornment position="end">-</InputAdornment>}
  516. />
  517. </FormControl>
  518. <FormControl variant="outlined" sx={{ width: '75%' }} disabled>
  519. <OutlinedInput
  520. size="small"
  521. type="tel"
  522. {...register("contactFaxNo.faxNumber",
  523. {
  524. value: currentApplicationDetailData.contactFaxNo.faxNumber,
  525. })}
  526. id='faxNumber'
  527. sx={{
  528. "& .MuiInputBase-input.Mui-disabled": {
  529. WebkitTextFillColor: "#000000",
  530. background: "#f8f8f8",
  531. },
  532. }}
  533. inputProps={{
  534. maxLength: 8,
  535. }}
  536. />
  537. </FormControl>
  538. </Stack>
  539. </Grid>
  540. </Grid>
  541. </Grid>
  542. </Grid>
  543. <Grid container direction="row" justifyContent="flex-start"
  544. alignItems="center">
  545. <Grid item xs={12} md={12} lg={12} mt={1} >
  546. <Grid container alignItems={"center"}>
  547. <Grid item xs={12} md={12} lg={12}>
  548. <Grid container direction="row">
  549. <Grid item xs={12} md={2} lg={2}
  550. sx={{ display: 'flex', alignItems: 'center' }}>
  551. <FormLabel><Typography variant="h5" >Manuscript File:</Typography></FormLabel>
  552. </Grid>
  553. <Grid item xs={12} md={8} lg={8} sx={{ display: 'flex', alignItems: 'center' }}>
  554. <Grid container direction="row" justifyContent="flex-start">
  555. <Grid item xs={10} md={8} lg={8} sx={{ display: 'flex', alignItems: 'center' }}>
  556. <FormControl variant="outlined" fullWidth >
  557. <Typography
  558. // fullWidth
  559. id='fileName'
  560. variant="h5"
  561. sx={{ wordBreak: 'break-word' }}
  562. >
  563. {fileDetail?.filename}
  564. </Typography>
  565. </FormControl>
  566. </Grid>
  567. <Grid item md={2} lg={2}>
  568. <Button
  569. size="small"
  570. variant="contained"
  571. onClick={onDownloadClick()}
  572. disabled={!fileDetail?.filename}
  573. sx={{
  574. textTransform: 'capitalize',
  575. alignItems: 'end',
  576. }}>
  577. <DownloadIcon />
  578. </Button>
  579. </Grid>
  580. </Grid>
  581. </Grid>
  582. </Grid>
  583. </Grid>
  584. </Grid>
  585. </Grid>
  586. </Grid>
  587. </Grid>
  588. </Grid>
  589. </form>
  590. <div>
  591. <Dialog
  592. open={isWarningPopUp}
  593. onClose={() => setIsWarningPopUp(false)}
  594. PaperProps={{
  595. sx: {
  596. minWidth: '40vw',
  597. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  598. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  599. }
  600. }}
  601. >
  602. <DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle>
  603. <DialogContent style={{ display: 'flex', }}>
  604. <Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography>
  605. </DialogContent>
  606. <DialogActions>
  607. <Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  608. </DialogActions>
  609. </Dialog>
  610. </div>
  611. </MainCard>
  612. );
  613. };
  614. export default ApplicationDetailCard;