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.
 
 

230 line
10 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 DateUtils from "utils/DateUtils";
  12. import * as ComboData from "utils/ComboData";
  13. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  14. import {ThemeProvider} from "@emotion/react";
  15. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  16. import dayjs from "dayjs";
  17. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  18. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  19. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  20. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  21. const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => {
  22. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  23. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  24. const [status, setStatus] = React.useState(ComboData.paymentStatus[0]);
  25. const { reset, register, handleSubmit } = useForm()
  26. const marginBottom = 2.5;
  27. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  28. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  29. React.useEffect(() => {
  30. setFromDateValue(minDate);
  31. }, [minDate]);
  32. React.useEffect(() => {
  33. setToDateValue(maxDate);
  34. }, [maxDate]);
  35. const onSubmit = (data) => {
  36. let sentDateFrom = "";
  37. let sentDateTo = "";
  38. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  39. sentDateFrom = DateUtils.dateValue(fromDateValue)
  40. sentDateTo = DateUtils.dateValue(toDateValue)
  41. }
  42. const temp = {
  43. code: data.code,
  44. transNo: data.transNo,
  45. dateFrom: sentDateFrom,
  46. dateTo: sentDateTo,
  47. status : (status?.type && status?.type != 'all') ? status?.type : "",
  48. };
  49. applySearch(temp);
  50. };
  51. function resetForm() {
  52. setStatus(ComboData.paymentStatus[0]);
  53. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  54. setMaxDate(DateUtils.dateValue(new Date()))
  55. reset();
  56. }
  57. return (
  58. <MainCard xs={12} md={12} lg={12}
  59. border={false}
  60. content={false}
  61. >
  62. <form onSubmit={handleSubmit(onSubmit)} >
  63. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom}} width="98%">
  64. {/*row 1*/}
  65. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  66. <Typography variant="pnspsFormHeader" >
  67. Search
  68. </Typography>
  69. </Grid>
  70. {/*row 2*/}
  71. <Grid container display="flex" alignItems={"center"}>
  72. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3,mb: marginBottom}}>
  73. <TextField
  74. fullWidth
  75. {...register("code")}
  76. id='code'
  77. label="Application No."
  78. defaultValue={searchCriteria.code}
  79. InputLabelProps={{
  80. shrink: true
  81. }}
  82. />
  83. </Grid>
  84. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  85. <Grid container spacing={1}>
  86. <Grid item xs={6}>
  87. <LocalizationProvider dateAdapter={AdapterDayjs}>
  88. <DemoItem components={['DatePicker']}>
  89. <DatePicker
  90. id="dateFrom"
  91. // onError={(newError) => setReceiptFromError(newError)}
  92. slotProps={{
  93. field: { readOnly: true, },
  94. // textField: {
  95. // helperText: receiptFromErrorMessage,
  96. // },
  97. }}
  98. format="DD/MM/YYYY"
  99. label="Transaction Date (From)"
  100. value={minDate === null ? null : dayjs(minDate)}
  101. maxDate={maxDate === null ? null : dayjs(maxDate)}
  102. onChange={(newValue) => {
  103. // console.log(newValue)
  104. if(newValue!=null){
  105. setMinDate(newValue);
  106. }
  107. }}
  108. />
  109. </DemoItem >
  110. </LocalizationProvider>
  111. </Grid>
  112. <Grid item xs={6}>
  113. <LocalizationProvider dateAdapter={AdapterDayjs}>
  114. <DemoItem components={['DatePicker']}>
  115. <DatePicker
  116. id="dateTo"
  117. // onError={(newError) => setReceiptFromError(newError)}
  118. slotProps={{
  119. field: { readOnly: true, },
  120. // textField: {
  121. // helperText: receiptFromErrorMessage,
  122. // },
  123. }}
  124. format="DD/MM/YYYY"
  125. label="Transaction Date (To)"
  126. value={maxDate === null ? null : dayjs(maxDate)}
  127. minDate={minDate === null ? null : dayjs(minDate)}
  128. onChange={(newValue) => {
  129. // console.log(newValue)
  130. if(newValue!=null){
  131. setMaxDate(newValue);
  132. }
  133. }}
  134. />
  135. </DemoItem >
  136. </LocalizationProvider>
  137. </Grid>
  138. </Grid>
  139. </Grid>
  140. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom}}>
  141. <TextField
  142. fullWidth
  143. {...register("transNo")}
  144. id='transNo'
  145. label="Transaction No."
  146. defaultValue={searchCriteria.transNo}
  147. InputLabelProps={{
  148. shrink: true
  149. }}
  150. />
  151. </Grid>
  152. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  153. <Autocomplete
  154. {...register("status")}
  155. disablePortal={false}
  156. size="small"
  157. id="status"
  158. filterOptions={(options) => options}
  159. options={ComboData.paymentStatus}
  160. value={status}
  161. getOptionLabel={(option) => option.label}
  162. inputValue={status?.label ? status?.label : ""}
  163. onChange={(event, newValue) => {
  164. if(newValue==null){
  165. setStatus(ComboData.paymentStatus[0]);
  166. }else{
  167. setStatus(newValue);
  168. }
  169. }}
  170. renderInput={(params) => (
  171. <TextField {...params}
  172. label="Status"
  173. />
  174. )}
  175. InputLabelProps={{
  176. shrink: true
  177. }}
  178. />
  179. </Grid>
  180. </Grid>
  181. </Grid>
  182. {/*last row*/}
  183. <Grid container maxWidth justifyContent="flex-end">
  184. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  185. <Grid item sx={{ ml: 3, mb: 3}}>
  186. <Button
  187. variant="contained"
  188. color="cancel"
  189. onClick={resetForm}
  190. >
  191. Reset
  192. </Button>
  193. </Grid>
  194. <Grid item sx={{ ml: 3, mr: 3, mb: 3 }}>
  195. <Button
  196. variant="contained"
  197. type="submit"
  198. >
  199. Submit
  200. </Button>
  201. </Grid>
  202. </ThemeProvider>
  203. </Grid>
  204. </form>
  205. </MainCard>
  206. );
  207. };
  208. export default SearchPublicNoticeForm;