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.

243 lines
10 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. CardContent,
  5. Grid, TextField,
  6. Autocomplete,
  7. Typography
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import { useForm } from "react-hook-form";
  11. import * as React from "react";
  12. import * as ComboData from "utils/ComboData";
  13. import * as DateUtils from "utils/DateUtils";
  14. import * as FormatUtils from "utils/FormatUtils";
  15. import {FormattedMessage, useIntl} from "react-intl";
  16. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  17. import {ThemeProvider} from "@emotion/react";
  18. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  19. const SearchDemandNoteForm = ({ applySearch, searchCriteria, issueComboData
  20. }) => {
  21. const intl = useIntl();
  22. const [type, setType] = React.useState([]);
  23. const [issueSelected, setIssueSelected] = React.useState({});
  24. const [issueCombo, setIssueCombo] = React.useState([]);
  25. const [selectedStatus, setSelectedStatus] = React.useState({});
  26. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  27. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  28. const { reset, register, handleSubmit } = useForm()
  29. const onSubmit = (data) => {
  30. let typeArray = [];
  31. for (let i = 0; i < type.length; i++) {
  32. typeArray.push(type[i].label);
  33. }
  34. const temp = {
  35. appNo: data.appNo,
  36. issueId: issueSelected?.id,
  37. dnNo: data.dnNo,
  38. sentDateFrom: data.dateFrom,
  39. sentDateTo: data.dateTo,
  40. status: (selectedStatus?.type && selectedStatus?.type != 'all') ? selectedStatus?.type : "",
  41. };
  42. applySearch(temp);
  43. };
  44. React.useEffect(() => {
  45. if (issueComboData && issueComboData.length > 0) {
  46. setIssueCombo(issueComboData);
  47. }
  48. }, [issueComboData]);
  49. function resetForm() {
  50. setType([]);
  51. // setStatus({ key: 0, label: 'All', type: 'all' });
  52. setOrgSelected({});
  53. setIssueSelected({});
  54. reset();
  55. }
  56. function getIssueLabel(data) {
  57. if (data == {}) return "";
  58. return data.year
  59. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  60. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  61. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  62. }
  63. return (
  64. <MainCard xs={12} md={12} lg={12}
  65. border={false}
  66. content={false}
  67. sx={{ backgroundColor: '#fff' }}
  68. >
  69. <form onSubmit={handleSubmit(onSubmit)}>
  70. <Grid container sx={{ backgroundColor: '#ffffff' }} width="98%">
  71. {/*row 1*/}
  72. <Grid item xs={12}>
  73. <CardContent sx={{ px: 2.5, pt: 3 }}>
  74. <Grid item justifyContent="space-between" alignItems="center" >
  75. <Typography variant="pnspsFormHeader">
  76. <FormattedMessage id="searchForm"/>
  77. </Typography>
  78. </Grid>
  79. </CardContent>
  80. </Grid>
  81. {/*row 2*/}
  82. <Grid container display="flex" alignItems={"center"}>
  83. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  84. <Autocomplete
  85. {...register("issueId")}
  86. disablePortal
  87. id="issueId"
  88. options={issueCombo}
  89. value={issueSelected}
  90. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  91. getOptionLabel={(option) => getIssueLabel(option)}
  92. onChange={(event, newValue) => {
  93. if (newValue !== null) {
  94. setIssueSelected(newValue);
  95. }
  96. }}
  97. renderInput={(params) => (
  98. <TextField {...params}
  99. label={intl.formatMessage({id: 'gazetteCount'})}
  100. InputLabelProps={{
  101. shrink: true
  102. }}
  103. />
  104. )}
  105. />
  106. </Grid>
  107. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  108. <TextField
  109. fullWidth
  110. {...register("appNo")}
  111. id='appNo'
  112. label={intl.formatMessage({id: 'applicationId'})}
  113. defaultValue={searchCriteria.appNo}
  114. InputLabelProps={{
  115. shrink: true
  116. }}
  117. />
  118. </Grid>
  119. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  120. <TextField
  121. fullWidth
  122. {...register("dnNo")}
  123. id='dnNo'
  124. label={intl.formatMessage({id: 'paymentRecordId'})}
  125. defaultValue={searchCriteria.dnNo}
  126. InputLabelProps={{
  127. shrink: true
  128. }}
  129. />
  130. </Grid>
  131. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  132. <TextField
  133. fullWidth
  134. {...register("dateFrom")}
  135. id="dateFrom"
  136. type="date"
  137. label={intl.formatMessage({id: 'sendDateFrom'})}
  138. defaultValue={searchCriteria.dateFrom}
  139. InputProps={{ inputProps: { max: maxDate } }}
  140. onChange={(newValue) => {
  141. setMinDate(DateUtils.dateStr(newValue));
  142. }}
  143. InputLabelProps={{
  144. shrink: true
  145. }}
  146. />
  147. </Grid>
  148. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  149. <TextField
  150. fullWidth
  151. InputLabelProps={{
  152. shrink: true
  153. }}
  154. {...register("dateTo")}
  155. InputProps={{ inputProps: { min: minDate } }}
  156. onChange={(newValue) => {
  157. setMaxDate(DateUtils.dateStr(newValue));
  158. }}
  159. id="dateTo"
  160. type="date"
  161. label={intl.formatMessage({id: 'sendDateTo'})}
  162. defaultValue={searchCriteria.dateTo}
  163. />
  164. </Grid>
  165. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  166. <Autocomplete
  167. {...register("status")}
  168. id="status"
  169. size="small"
  170. options={ComboData.denmandNoteStatus_Public}
  171. getOptionLabel={(option) => option.labelCht}
  172. inputValue={selectedStatus?.labelCht ? selectedStatus?.labelCht : ""}
  173. value={selectedStatus}
  174. onChange={(event, newValue) => {
  175. if (newValue !== null) {
  176. setSelectedStatus(newValue);
  177. }
  178. }}
  179. renderInput={(params) => (
  180. <TextField
  181. {...params}
  182. label={intl.formatMessage({id: 'status'})}
  183. />
  184. )}
  185. InputLabelProps={{
  186. shrink: true
  187. }}
  188. />
  189. </Grid>
  190. </Grid>
  191. {/*last row*/}
  192. <Grid container maxWidth justifyContent="flex-end">
  193. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  194. <Grid item sx={{mr: 3, mb: 3}}>
  195. <Button
  196. color="cancel"
  197. variant="contained"
  198. onClick={resetForm}
  199. >
  200. <FormattedMessage id="reset"/>
  201. </Button>
  202. </Grid>
  203. <Grid item sx={{ mb: 3 }}>
  204. <Button
  205. variant="contained"
  206. type="submit"
  207. >
  208. <FormattedMessage id="submit" />
  209. </Button>
  210. </Grid>
  211. </ThemeProvider>
  212. </Grid>
  213. </Grid>
  214. </form>
  215. </MainCard>
  216. );
  217. };
  218. export default SearchDemandNoteForm;