Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

255 righe
11 KiB

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