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.
 
 

347 line
16 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import * as React from "react";
  11. import * as ComboData from "utils/ComboData";
  12. import * as DateUtils from "utils/DateUtils";
  13. import * as FormatUtils from "utils/FormatUtils";
  14. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  15. import {ThemeProvider} from "@emotion/react";
  16. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  17. const SearchDemandNoteForm = ({ applySearch, orgComboData, searchCriteria, issueComboData
  18. }) => {
  19. const [type, setType] = React.useState([]);
  20. // const [status, setStatus] = React.useState({ key: 0, label: 'All', type: 'all' });
  21. const [orgSelected, setOrgSelected] = React.useState({});
  22. const [orgCombo, setOrgCombo] = React.useState();
  23. const [issueSelected, setIssueSelected] = React.useState({});
  24. const [issueCombo, setIssueCombo] = React.useState([]);
  25. const [selectedStatus, setSelectedStatus] = React.useState([]);
  26. const [selectedLabelsString, setSelectedLabelsString] = React.useState('');
  27. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  28. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  29. const [minDueDate, setMinDueDate] = React.useState(searchCriteria.dueDateFrom);
  30. const [maxDueDate, setMaxDueDate] = React.useState(searchCriteria.dueDateTo);
  31. const { reset, register, handleSubmit } = useForm()
  32. const onSubmit = (data) => {
  33. data.status = selectedLabelsString
  34. let typeArray = [];
  35. for (let i = 0; i < type.length; i++) {
  36. typeArray.push(type[i].label);
  37. }
  38. const temp = {
  39. appNo: data.appNo,
  40. issueId: issueSelected?.id,
  41. orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
  42. dnNo: data.dnNo,
  43. dateFrom: data.dateFrom,
  44. dateTo: data.dateTo,
  45. dueDateFrom: data.dueDateFrom,
  46. dueDateTo: data.dueDateTo,
  47. status: (data.status === '' || data.status.includes("all")) ? "" : data.status,
  48. };
  49. applySearch(temp);
  50. };
  51. React.useEffect(() => {
  52. if (orgComboData && orgComboData.length > 0) {
  53. setOrgCombo(orgComboData);
  54. }
  55. }, [orgComboData]);
  56. React.useEffect(() => {
  57. if (issueComboData && issueComboData.length > 0) {
  58. setIssueCombo(issueComboData);
  59. }
  60. }, [issueComboData]);
  61. function resetForm() {
  62. setType([]);
  63. // setStatus({ key: 0, label: 'All', type: 'all' });
  64. setOrgSelected({});
  65. setIssueSelected({});
  66. reset();
  67. }
  68. function getIssueLabel(data) {
  69. if (data == {}) return "";
  70. return data.issueYear
  71. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  72. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  73. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  74. }
  75. return (
  76. <MainCard xs={12} md={12} lg={12}
  77. border={false}
  78. content={false}
  79. sx={{ backgroundColor: '#fff' }}
  80. >
  81. <form onSubmit={handleSubmit(onSubmit)}>
  82. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1 }} width="98%">
  83. {/*row 1*/}
  84. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1, ml:3,mb:2.5}}>
  85. <Typography variant="pnspsFormHeader" >
  86. Search
  87. </Typography>
  88. </Grid>
  89. {/*row 2*/}
  90. <Grid container display="flex" alignItems={"center"}>
  91. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  92. <Autocomplete
  93. {...register("issueId")}
  94. disablePortal
  95. id="issueId"
  96. size="small"
  97. options={issueCombo}
  98. value={issueSelected}
  99. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  100. getOptionLabel={(option) => getIssueLabel(option)}
  101. onChange={(event, newValue) => {
  102. if (newValue !== null) {
  103. setIssueSelected(newValue);
  104. }
  105. }}
  106. renderInput={(params) => (
  107. <TextField {...params}
  108. label="Gazette Issue"
  109. InputLabelProps={{
  110. shrink: true
  111. }}
  112. />
  113. )}
  114. />
  115. </Grid>
  116. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  117. <TextField
  118. fullWidth
  119. {...register("appNo")}
  120. id='appNo'
  121. label={"App No."}
  122. defaultValue={searchCriteria.appNo}
  123. InputLabelProps={{
  124. shrink: true
  125. }}
  126. />
  127. </Grid>
  128. {
  129. orgCombo ?
  130. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  131. <Autocomplete
  132. {...register("orgId")}
  133. disablePortal
  134. id="orgId"
  135. size="small"
  136. options={orgCombo}
  137. value={orgSelected}
  138. inputValue={(orgSelected?.label) ? orgSelected?.label : ""}
  139. onChange={(event, newValue) => {
  140. if (newValue !== null) {
  141. setOrgSelected(newValue);
  142. }
  143. }}
  144. renderInput={(params) => (
  145. <TextField {...params}
  146. label="BR No./Organisation"
  147. InputLabelProps={{
  148. shrink: true
  149. }}
  150. />
  151. )}
  152. />
  153. </Grid>
  154. : <></>
  155. }
  156. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  157. <TextField
  158. fullWidth
  159. {...register("dnNo")}
  160. id='dnNo'
  161. label="DN No."
  162. defaultValue={searchCriteria.dnNo}
  163. InputLabelProps={{
  164. shrink: true
  165. }}
  166. />
  167. </Grid>
  168. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  169. <Grid container>
  170. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  171. <TextField
  172. fullWidth
  173. {...register("dateFrom")}
  174. id="dateFrom"
  175. type="date"
  176. label={"Issue Date(From)"}
  177. defaultValue={searchCriteria.dateFrom}
  178. InputProps={{ inputProps: { max: maxDate } }}
  179. onChange={(newValue) => {
  180. setMinDate(DateUtils.dateStr(newValue));
  181. }}
  182. InputLabelProps={{
  183. shrink: true
  184. }}
  185. />
  186. </Grid>
  187. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:0.8, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  188. To
  189. </Grid>
  190. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  191. <TextField
  192. fullWidth
  193. InputLabelProps={{
  194. shrink: true
  195. }}
  196. {...register("dateTo")}
  197. InputProps={{ inputProps: { min: minDate } }}
  198. onChange={(newValue) => {
  199. setMaxDate(DateUtils.dateStr(newValue));
  200. }}
  201. id="dateTo"
  202. type="date"
  203. //label={"Submit Date(To)"}
  204. defaultValue={searchCriteria.dateTo}
  205. />
  206. </Grid>
  207. </Grid>
  208. </Grid>
  209. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
  210. <Grid container>
  211. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  212. <TextField
  213. fullWidth
  214. {...register("dueDateFrom")}
  215. id="dueDateFrom"
  216. type="date"
  217. label={"Due Date(From)"}
  218. defaultValue={searchCriteria.dueDateFrom}
  219. InputProps={{ inputProps: { max: maxDueDate } }}
  220. onChange={(newValue) => {
  221. setMinDueDate(DateUtils.dateStr(newValue));
  222. }}
  223. InputLabelProps={{
  224. shrink: true
  225. }}
  226. />
  227. </Grid>
  228. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:0.8, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  229. To
  230. </Grid>
  231. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  232. <TextField
  233. fullWidth
  234. InputLabelProps={{
  235. shrink: true
  236. }}
  237. {...register("dueDateTo")}
  238. InputProps={{ inputProps: { min: minDueDate } }}
  239. onChange={(newValue) => {
  240. setMaxDueDate(DateUtils.dateStr(newValue));
  241. }}
  242. id="dueDateTo"
  243. type="date"
  244. //label={"Submit Date(To)"}
  245. defaultValue={searchCriteria.dueDateTo}
  246. />
  247. </Grid>
  248. </Grid>
  249. </Grid>
  250. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  251. <Autocomplete
  252. multiple
  253. size="small"
  254. {...register("status")}
  255. id="status"
  256. options={ComboData.denmandNoteStatus}
  257. value={selectedStatus}
  258. onChange={(event, newValue) => {
  259. const findAllIndex = newValue.findIndex((ele) => {
  260. return ele.type === "all"
  261. })
  262. if (findAllIndex > -1) {
  263. setSelectedStatus([newValue[findAllIndex]]);
  264. setSelectedLabelsString('all')
  265. } else {
  266. const selectedLabels = newValue.map(option => option.type);
  267. const selectedLabelsString = `${selectedLabels.join(',')}`;
  268. setSelectedStatus(newValue);
  269. setSelectedLabelsString(selectedLabelsString);
  270. }
  271. }}
  272. getOptionLabel={(option) => option.label}
  273. renderInput={(params) => (
  274. <TextField
  275. {...params}
  276. label="Status"
  277. InputLabelProps={{
  278. shrink: true
  279. }}
  280. />
  281. )}
  282. />
  283. </Grid>
  284. </Grid>
  285. {/*last row*/}
  286. <Grid container maxWidth justifyContent="flex-end">
  287. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  288. <Grid item sx={{ ml: 3, mb:3 }}>
  289. <Button
  290. variant="contained"
  291. onClick={resetForm}
  292. >
  293. Clear
  294. </Button>
  295. </Grid>
  296. <Grid item sx={{ ml: 3, mr: 3, mb:3}}>
  297. <Button
  298. variant="contained"
  299. type="submit"
  300. >
  301. Submit
  302. </Button>
  303. </Grid>
  304. </ThemeProvider>
  305. </Grid>
  306. </Grid>
  307. </form>
  308. </MainCard>
  309. );
  310. };
  311. export default SearchDemandNoteForm;