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.

412 lines
18 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete
  6. } from '@mui/material';
  7. import MainCard from "components/MainCard";
  8. import { useForm } from "react-hook-form";
  9. import * as React from "react";
  10. import * as ComboData from "utils/ComboData";
  11. import * as DateUtils from "utils/DateUtils";
  12. import * as FormatUtils from "utils/FormatUtils";
  13. import { Typography } from '../../../../node_modules/@mui/material/index';
  14. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  15. import {ThemeProvider} from "@emotion/react";
  16. import { useIntl } from "react-intl";
  17. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  18. import dayjs from "dayjs";
  19. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  20. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  21. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  22. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  23. const SearchPublicNoticeForm = ({ applySearch, orgComboData, searchCriteria, issueComboData, onGridReady
  24. }) => {
  25. const [type, setType] = React.useState([]);
  26. const [status, setStatus] = React.useState(ComboData.proofStatus[0]);
  27. const [orgSelected, setOrgSelected] = React.useState({});
  28. const [orgCombo, setOrgCombo] = React.useState();
  29. const [issueSelected, setIssueSelected] = React.useState({});
  30. const [issueCombo, setIssueCombo] = React.useState([]);
  31. const [groupSelected, setGroupSelected] = React.useState({});
  32. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  33. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  34. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  35. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  36. React.useEffect(() => {
  37. setFromDateValue(minDate);
  38. }, [minDate]);
  39. React.useEffect(() => {
  40. setToDateValue(maxDate);
  41. }, [maxDate]);
  42. const intl = useIntl();
  43. const { locale } = intl;
  44. const marginBottom = 2.5;
  45. const { reset, register, handleSubmit } = useForm()
  46. const onSubmit = (data) => {
  47. let typeArray = [];
  48. let sentDateFrom = "";
  49. let sentDateTo = "";
  50. for (let i = 0; i < type.length; i++) {
  51. typeArray.push(type[i].label);
  52. }
  53. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  54. sentDateFrom = DateUtils.dateValue(fromDateValue)
  55. sentDateTo = DateUtils.dateValue(toDateValue)
  56. }
  57. const temp = {
  58. refNo: data.refNo,
  59. code: data.code,
  60. issueId: issueSelected?.id,
  61. gazettGroup: groupSelected?.type,
  62. dateFrom: sentDateFrom,
  63. dateTo: sentDateTo,
  64. contact: data.contact,
  65. orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
  66. };
  67. if(status?.type && status?.type != 'all'){
  68. if (status?.type == "Confirmed"){
  69. temp["replyed"] = "T";
  70. temp["action"] = true;
  71. temp["cancelled"] = false;
  72. }else if(status?.type == "Re-proofing"){
  73. temp["replyed"] = "T";
  74. temp["action"] = false;
  75. temp["cancelled"] = false;
  76. }else if(status?.type == "No Reply"){
  77. temp["replyed"] = "F";
  78. temp["timeOut"] = "T";
  79. temp["cancelled"] = false;
  80. }else if(status?.type == "Cancelled"){
  81. temp["cancelled"] = true;
  82. } else{
  83. temp["replyed"] = "F";
  84. temp["timeOut"] = "F";
  85. temp["cancelled"] = false;
  86. }
  87. }
  88. applySearch(temp);
  89. };
  90. React.useEffect(() => {
  91. if (orgComboData && orgComboData.length > 0) {
  92. setOrgCombo(orgComboData);
  93. }
  94. }, [orgComboData]);
  95. React.useEffect(() => {
  96. if (issueComboData && issueComboData.length > 0) {
  97. setIssueCombo(issueComboData);
  98. }
  99. }, [issueComboData]);
  100. function resetForm() {
  101. setType([]);
  102. setStatus(ComboData.proofStatus[0]);
  103. setOrgSelected({});
  104. setIssueSelected({});
  105. setGroupSelected({});
  106. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  107. setMaxDate(DateUtils.dateValue(new Date()))
  108. reset();
  109. }
  110. function getIssueLabel(data) {
  111. let issueYear = data.issueYear
  112. let volume = data.volume;
  113. let issueNo = data.issueNo;
  114. let issueDate = data.issueDate;
  115. if (locale === 'zh-HK') {
  116. return issueYear
  117. + " 第" + volume + "卷,"
  118. + " 第" + issueNo + "期,"
  119. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  120. + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
  121. } else if (locale === 'zh-CN') {
  122. return issueYear
  123. + " 第" + volume + "卷,"
  124. + " 第" + issueNo + "期,"
  125. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  126. + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
  127. }
  128. return issueYear
  129. + " Vol. " + FormatUtils.zeroPad(volume, 3)
  130. + ", No. " + FormatUtils.zeroPad(issueNo, 2)
  131. + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
  132. }
  133. return (
  134. <MainCard xs={12} md={12} lg={12}
  135. border={false}
  136. content={false}
  137. sx={{ backgroundColor: '#fff' }}
  138. >
  139. <form onSubmit={handleSubmit(onSubmit)}>
  140. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1 }} width="98%">
  141. {/*row 1*/}
  142. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  143. <Typography variant="pnspsFormHeader" >
  144. Search
  145. </Typography>
  146. </Grid>
  147. {/*row 2*/}
  148. <Grid container alignItems={"center"}>
  149. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  150. <TextField
  151. fullWidth
  152. {...register("refNo")}
  153. id='refNo'
  154. label="Proof No."
  155. defaultValue={searchCriteria.refNo}
  156. InputLabelProps={{
  157. shrink: true
  158. }}
  159. />
  160. </Grid>
  161. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  162. <TextField
  163. fullWidth
  164. {...register("code")}
  165. id='code'
  166. label="Application No. / Gazette Code"
  167. defaultValue={searchCriteria.code}
  168. InputLabelProps={{
  169. shrink: true
  170. }}
  171. />
  172. </Grid>
  173. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  174. <Autocomplete
  175. {...register("issueId")}
  176. disablePortal
  177. size="small"
  178. id="issueId"
  179. options={issueCombo}
  180. value={issueSelected}
  181. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  182. getOptionLabel={(option) => getIssueLabel(option)}
  183. onChange={(event, newValue) => {
  184. setIssueSelected(newValue);
  185. }}
  186. renderInput={(params) => (
  187. <TextField {...params}
  188. label="Gazette Issue No."
  189. InputLabelProps={{
  190. shrink: true
  191. }}
  192. />
  193. )}
  194. />
  195. </Grid>
  196. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  197. <Autocomplete
  198. {...register("gazettGroup")}
  199. disablePortal
  200. size="small"
  201. id="gazettGroup"
  202. options={ComboData.groupTitle}
  203. value={groupSelected}
  204. inputValue={(groupSelected?.label) ? groupSelected?.label : ""}
  205. getOptionLabel={(option) => option.label}
  206. onChange={(event, newValue) => {
  207. setGroupSelected(newValue);
  208. }}
  209. renderInput={(params) => (
  210. <TextField {...params}
  211. label="Gazette Group"
  212. InputLabelProps={{
  213. shrink: true
  214. }}
  215. />
  216. )}
  217. />
  218. </Grid>
  219. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  220. <Grid container spacing={1}>
  221. <Grid item xs={6}>
  222. <LocalizationProvider dateAdapter={AdapterDayjs}>
  223. <DemoItem components={['DatePicker']}>
  224. <DatePicker
  225. id="dateFrom"
  226. // onError={(newError) => setReceiptFromError(newError)}
  227. slotProps={{
  228. field: { readOnly: true, },
  229. // textField: {
  230. // helperText: receiptFromErrorMessage,
  231. // },
  232. }}
  233. format="DD/MM/YYYY"
  234. label="Proof Issue Date (From)"
  235. value={minDate === null ? null : dayjs(minDate)}
  236. maxDate={maxDate === null ? null : dayjs(maxDate)}
  237. onChange={(newValue) => {
  238. // console.log(newValue)
  239. if(newValue!=null){
  240. setMinDate(newValue);
  241. }
  242. }}
  243. />
  244. </DemoItem >
  245. </LocalizationProvider>
  246. </Grid>
  247. <Grid item xs={6}>
  248. <LocalizationProvider dateAdapter={AdapterDayjs}>
  249. <DemoItem components={['DatePicker']}>
  250. <DatePicker
  251. id="dateTo"
  252. // onError={(newError) => setReceiptFromError(newError)}
  253. slotProps={{
  254. field: { readOnly: true, },
  255. // textField: {
  256. // helperText: receiptFromErrorMessage,
  257. // },
  258. }}
  259. format="DD/MM/YYYY"
  260. label="Proof Issue Date (To)"
  261. value={maxDate === null ? null : dayjs(maxDate)}
  262. minDate={minDate === null ? null : dayjs(minDate)}
  263. onChange={(newValue) => {
  264. // console.log(newValue)
  265. if(newValue!=null){
  266. setMaxDate(newValue);
  267. }
  268. }}
  269. />
  270. </DemoItem >
  271. </LocalizationProvider>
  272. </Grid>
  273. </Grid>
  274. </Grid>
  275. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  276. <TextField
  277. fullWidth
  278. {...register("contact")}
  279. id="contact"
  280. label="Client"
  281. defaultValue={searchCriteria.contact}
  282. InputLabelProps={{
  283. shrink: true
  284. }}
  285. />
  286. </Grid>
  287. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  288. <Autocomplete
  289. {...register("status")}
  290. disablePortal={false}
  291. id="status"
  292. size="small"
  293. filterOptions={(options) => options}
  294. options={ComboData.proofStatus_GLD}
  295. value={status}
  296. getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""}
  297. inputValue={status? intl.formatMessage({id: status.i18nLabel}):""}
  298. onChange={(event, newValue) => {
  299. if (newValue !== null) {
  300. setStatus(newValue);
  301. }
  302. }}
  303. renderInput={(params) => (
  304. <TextField {...params}
  305. label="Status"
  306. />
  307. )}
  308. InputLabelProps={{
  309. shrink: true
  310. }}
  311. />
  312. </Grid>
  313. {
  314. orgCombo ?
  315. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  316. <Autocomplete
  317. {...register("orgId")}
  318. disablePortal={false}
  319. id="orgId"
  320. size="small"
  321. options={orgCombo}
  322. value={orgSelected}
  323. getOptionLabel={(option) => option.name? option.name : ""}
  324. inputValue={orgSelected ? orgSelected.name : ""}
  325. onChange={(event, newValue) => {
  326. if (newValue !== null) {
  327. setOrgSelected(newValue);
  328. }else{
  329. setOrgSelected({});
  330. }
  331. }}
  332. renderInput={(params) => (
  333. <TextField {...params}
  334. label="Organisation"
  335. InputLabelProps={{
  336. shrink: true
  337. }}
  338. />
  339. )}
  340. />
  341. </Grid>
  342. : <></>
  343. }
  344. </Grid>
  345. {/*last row*/}
  346. <Grid container maxWidth justifyContent="flex-end">
  347. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  348. <Grid item sx={{ ml: 3, mb: 3 }}>
  349. <Button
  350. variant="contained"
  351. color="cancel"
  352. onClick={resetForm}
  353. >
  354. Reset
  355. </Button>
  356. </Grid>
  357. <Grid item sx={{ ml: 3, mb: 3 }}>
  358. <Button
  359. variant="contained"
  360. type="submit"
  361. disabled={onGridReady}
  362. >
  363. Submit
  364. </Button>
  365. </Grid>
  366. </ThemeProvider>
  367. </Grid>
  368. </Grid>
  369. </form>
  370. </MainCard>
  371. );
  372. };
  373. export default SearchPublicNoticeForm;