No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

495 líneas
27 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 {PNSPS_BUTTON_THEME} from "../../themes/buttonConst";
  13. import {ThemeProvider} from "@emotion/react";
  14. import * as ComboData from "utils/ComboData";
  15. import * as DateUtils from "utils/DateUtils";
  16. import Loadable from 'components/Loadable';
  17. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  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 SearchPublicNoticeForm = ({ applySearch, generateReport, onLoad }) => {
  25. const [sysTxnMinDate, setSysTxnMinDate] = React.useState(null);
  26. const [sysTxnMaxDate, setsysTxnMaxDate] = React.useState(null);
  27. const [txnMinDate, setTxnMinDate] = React.useState(null);
  28. const [txnMaxDate, setTxnMaxDate] = React.useState(null);
  29. const [collMinDate, setCollMinDate] = React.useState(null);
  30. const [collMaxDate, setCollMaxDate] = React.useState(null);
  31. const [sysTxnFromDateValue, setSysTxnFromDateValue] = React.useState(null);
  32. const [sysTxnToDateValue, setSysTxnToDateValue] = React.useState(null);
  33. const [txnFromDateValue, setTxnFromDateValue] = React.useState(null);
  34. const [txnToDateValue, setTxnToDateValue] = React.useState(null);
  35. const [collFromDateValue, setCollFromDateValue] = React.useState(null);
  36. const [collToDateValue, setCollToDateValue] = React.useState(null);
  37. const [status, setStatus] = React.useState(ComboData.paymentStatus[0]);
  38. const [method, setMethod] = React.useState(ComboData.paymentMethod[0]);
  39. const marginBottom = 2.5;
  40. const { register, handleSubmit } = useForm()
  41. React.useEffect(() => {
  42. setSysTxnFromDateValue(sysTxnMinDate);
  43. }, [sysTxnMinDate]);
  44. React.useEffect(() => {
  45. setSysTxnToDateValue(sysTxnMaxDate);
  46. }, [sysTxnMaxDate]);
  47. React.useEffect(() => {
  48. setTxnFromDateValue(txnMinDate);
  49. }, [txnMinDate]);
  50. React.useEffect(() => {
  51. setTxnToDateValue(txnMaxDate);
  52. }, [txnMaxDate]);
  53. React.useEffect(() => {
  54. setCollFromDateValue(collMinDate);
  55. }, [collMinDate]);
  56. React.useEffect(() => {
  57. setCollToDateValue(collMaxDate);
  58. }, [collMaxDate]);
  59. const onSubmit = () => {
  60. let sentSysTxnDateFrom = "";
  61. let sentSysTxnDateTo = "";
  62. let sentTxnDateFrom = "";
  63. let sentTxnDateTo = "";
  64. let sentCollDateFrom = "";
  65. let sentCollDateTo = "";
  66. // Invalid Date
  67. if (sysTxnFromDateValue != "dd / mm / yyyy" && sysTxnToDateValue != "dd / mm / yyyy" ) {
  68. sentSysTxnDateFrom = DateUtils.dateValue(sysTxnFromDateValue)!="Invalid Date"?DateUtils.dateValue(sysTxnFromDateValue):""
  69. sentSysTxnDateTo = DateUtils.dateValue(sysTxnToDateValue)!="Invalid Date"?DateUtils.dateValue(sysTxnToDateValue):""
  70. }
  71. if (txnFromDateValue != "dd / mm / yyyy" && txnToDateValue != "dd / mm / yyyy") {
  72. sentTxnDateFrom = DateUtils.dateValue(txnFromDateValue)!="Invalid Date"?DateUtils.dateValue(txnFromDateValue):""
  73. sentTxnDateTo = DateUtils.dateValue(txnToDateValue)!="Invalid Date"?DateUtils.dateValue(txnToDateValue):""
  74. }
  75. if (collFromDateValue != "dd / mm / yyyy" && collToDateValue != "dd / mm / yyyy") {
  76. sentCollDateFrom = DateUtils.dateValue(collFromDateValue)!="Invalid Date"?DateUtils.dateValue(collFromDateValue):""
  77. sentCollDateTo = DateUtils.dateValue(collToDateValue)!="Invalid Date"?DateUtils.dateValue(collToDateValue):""
  78. }
  79. const temp = {
  80. PaymentMethod:(method?.type && method?.type != 'Please Select') ? method?.type : "",
  81. PaymentStatus : (status?.type && status?.type != 'all') ? status?.type : "",
  82. SysTxnDateFrom: sentSysTxnDateFrom,
  83. SysTxnDateTo: sentSysTxnDateTo,
  84. TxnDateFrom: sentTxnDateFrom,
  85. TxnDateTo: sentTxnDateTo,
  86. CollDateFrom: sentCollDateFrom,
  87. CollDateTo: sentCollDateTo,
  88. };
  89. // console.log(temp)
  90. applySearch(temp);
  91. };
  92. const generateFileHandler = (fileFormart) => () => {
  93. let sentSysTxnDateFrom = "";
  94. let sentSysTxnDateTo = "";
  95. let sentTxnDateFrom = "";
  96. let sentTxnDateTo = "";
  97. let sentCollDateFrom = "";
  98. let sentCollDateTo = "";
  99. if (sysTxnFromDateValue != "dd / mm / yyyy" && sysTxnToDateValue != "dd / mm / yyyy" ) {
  100. sentSysTxnDateFrom = DateUtils.dateValue(sysTxnFromDateValue)!="Invalid Date"?DateUtils.dateValue(sysTxnFromDateValue):""
  101. sentSysTxnDateTo = DateUtils.dateValue(sysTxnToDateValue)!="Invalid Date"?DateUtils.dateValue(sysTxnToDateValue):""
  102. }
  103. if (txnFromDateValue != "dd / mm / yyyy" && txnToDateValue != "dd / mm / yyyy") {
  104. sentTxnDateFrom = DateUtils.dateValue(txnFromDateValue)!="Invalid Date"?DateUtils.dateValue(txnFromDateValue):""
  105. sentTxnDateTo = DateUtils.dateValue(txnToDateValue)!="Invalid Date"?DateUtils.dateValue(txnToDateValue):""
  106. }
  107. if (collFromDateValue != "dd / mm / yyyy" && collToDateValue != "dd / mm / yyyy") {
  108. sentCollDateFrom = DateUtils.dateValue(collFromDateValue)!="Invalid Date"?DateUtils.dateValue(collFromDateValue):""
  109. sentCollDateTo = DateUtils.dateValue(collToDateValue)!="Invalid Date"?DateUtils.dateValue(collToDateValue):""
  110. }
  111. const temp = {
  112. PaymentMethod:(method?.type && method?.type != 'Please Select') ? method?.type : "",
  113. PaymentStatus : (status?.type && status?.type != 'all') ? status?.type : "",
  114. SysTxnDateFrom: sentSysTxnDateFrom,
  115. SysTxnDateTo: sentSysTxnDateTo,
  116. TxnDateFrom: sentTxnDateFrom,
  117. TxnDateTo: sentTxnDateTo,
  118. CollDateFrom: sentCollDateFrom,
  119. CollDateTo: sentCollDateTo,
  120. ReportFormat:fileFormart
  121. };
  122. generateReport(temp);
  123. }
  124. const clearHandler = () => () => {
  125. setSysTxnMinDate(null)
  126. setsysTxnMaxDate(null)
  127. setTxnMinDate(null)
  128. setTxnMaxDate(null)
  129. setCollMinDate(null)
  130. setCollMaxDate(null)
  131. setSysTxnFromDateValue("")
  132. setSysTxnToDateValue("")
  133. setTxnFromDateValue("")
  134. setTxnToDateValue("")
  135. setCollFromDateValue("")
  136. setCollToDateValue("")
  137. setStatus(ComboData.paymentStatus[0])
  138. setMethod(ComboData.paymentMethod[0])
  139. }
  140. return (
  141. <MainCard xs={12} md={12} lg={12}
  142. border={false}
  143. content={false}
  144. >
  145. <form onSubmit={handleSubmit(onSubmit)} >
  146. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  147. {/*row 1*/}
  148. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  149. <Typography variant="h5" >
  150. Submit Form
  151. </Typography>
  152. </Grid>
  153. {/*row 2*/}
  154. <Grid item xs={12} s={12} md={12} lg={12} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  155. <Grid container spacing={3}>
  156. <Grid item xs={9} s={9} md={3} lg={3} >
  157. <Autocomplete
  158. {...register("paymentMethod")}
  159. disablePortal={false}
  160. size="small"
  161. id="paymentMethod"
  162. filterOptions={(options) => options}
  163. options={ComboData.paymentMethod}
  164. value={method}
  165. getOptionLabel={(option) => option.label}
  166. inputValue={method?.label ? method?.label : ""}
  167. onChange={(event, newValue) => {
  168. if (newValue !== null) {
  169. setMethod(newValue);
  170. }
  171. }}
  172. renderInput={(params) => (
  173. <TextField {...params}
  174. label="Payment Method"
  175. />
  176. )}
  177. InputLabelProps={{
  178. shrink: true
  179. }}
  180. />
  181. </Grid>
  182. <Grid item xs={9} s={9} md={3} lg={3} >
  183. <Autocomplete
  184. {...register("status")}
  185. disablePortal={false}
  186. size="small"
  187. id="status"
  188. filterOptions={(options) => options}
  189. options={ComboData.paymentStatus}
  190. value={status}
  191. getOptionLabel={(option) => option.label}
  192. inputValue={status?.label ? status?.label : ""}
  193. onChange={(event, newValue) => {
  194. if (newValue !== null) {
  195. setStatus(newValue);
  196. }
  197. }}
  198. renderInput={(params) => (
  199. <TextField {...params}
  200. label="Payment Status"
  201. />
  202. )}
  203. InputLabelProps={{
  204. shrink: true
  205. }}
  206. />
  207. </Grid>
  208. </Grid>
  209. </Grid>
  210. <Grid container display="flex" alignItems={"center"}>
  211. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml:3, mr:3, mb:marginBottom}}>
  212. <Grid container spacing={1}>
  213. <Grid item xs={4}>
  214. <LocalizationProvider dateAdapter={AdapterDayjs}>
  215. <DemoItem components={['DatePicker']}>
  216. <DatePicker
  217. id="sysTxnDateFrom"
  218. // onError={(newError) => setReceiptFromError(newError)}
  219. slotProps={{
  220. field: { readOnly: true, },
  221. textField: {
  222. // helperText: receiptFromErrorMessage,
  223. InputLabelProps: { shrink: true }
  224. },
  225. }}
  226. format="DD/MM/YYYY"
  227. label="PNSPS Transaction Date (From)"
  228. value={sysTxnMinDate === null ? null : dayjs(sysTxnMinDate)}
  229. maxDate={sysTxnMaxDate === null ? null : dayjs(sysTxnMaxDate)}
  230. onChange={(newValue) => {
  231. setSysTxnMinDate(newValue);
  232. }}
  233. />
  234. </DemoItem >
  235. </LocalizationProvider>
  236. </Grid>
  237. <Grid item xs={4}>
  238. <LocalizationProvider dateAdapter={AdapterDayjs}>
  239. <DemoItem components={['DatePicker']}>
  240. <DatePicker
  241. id="sysTxnDateTo"
  242. // onError={(newError) => setReceiptFromError(newError)}
  243. slotProps={{
  244. field: { readOnly: true, },
  245. textField: {
  246. // helperText: receiptFromErrorMessage,
  247. InputLabelProps: { shrink: true }
  248. },
  249. }}
  250. format="DD/MM/YYYY"
  251. label="PNSPS Transaction Date (To)"
  252. value={sysTxnMaxDate === null ? null : dayjs(sysTxnMaxDate)}
  253. minDate={sysTxnMinDate === null ? null : dayjs(sysTxnMinDate)}
  254. onChange={(newValue) => {
  255. // console.log(newValue)
  256. setsysTxnMaxDate(newValue);
  257. }}
  258. />
  259. </DemoItem >
  260. </LocalizationProvider>
  261. </Grid>
  262. </Grid>
  263. </Grid>
  264. </Grid>
  265. {/*row 3*/}
  266. <Grid container display="flex" alignItems={"center"}>
  267. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml:3, mr:3, mb:marginBottom}}>
  268. <Grid container spacing={1}>
  269. <Grid item xs={4}>
  270. <LocalizationProvider dateAdapter={AdapterDayjs}>
  271. <DemoItem components={['DatePicker']}>
  272. <DatePicker
  273. id="txnDateFrom"
  274. // onError={(newError) => setReceiptFromError(newError)}
  275. slotProps={{
  276. field: { readOnly: true, },
  277. textField: {
  278. // helperText: receiptFromErrorMessage,
  279. InputLabelProps: { shrink: true }
  280. },
  281. }}
  282. format="DD/MM/YYYY"
  283. label="FI Transaction Date (From)"
  284. value={txnMinDate === null ? null : dayjs(txnMinDate)}
  285. maxDate={txnMaxDate === null ? null : dayjs(txnMaxDate)}
  286. onChange={(newValue) => {
  287. // console.log(newValue)
  288. setTxnMinDate(newValue);
  289. }}
  290. />
  291. </DemoItem >
  292. </LocalizationProvider>
  293. </Grid>
  294. <Grid item xs={4}>
  295. <LocalizationProvider dateAdapter={AdapterDayjs}>
  296. <DemoItem components={['DatePicker']}>
  297. <DatePicker
  298. id="txnDateTo"
  299. // onError={(newError) => setReceiptFromError(newError)}
  300. slotProps={{
  301. field: { readOnly: true, },
  302. textField: {
  303. // helperText: receiptFromErrorMessage,
  304. InputLabelProps: { shrink: true }
  305. },
  306. }}
  307. format="DD/MM/YYYY"
  308. label="FI Transaction Date (To)"
  309. value={txnMaxDate === null ? null : dayjs(txnMaxDate)}
  310. minDate={txnMinDate === null ? null : dayjs(txnMinDate)}
  311. onChange={(newValue) => {
  312. // console.log(newValue)
  313. setTxnMaxDate(newValue);
  314. }}
  315. />
  316. </DemoItem >
  317. </LocalizationProvider>
  318. </Grid>
  319. </Grid>
  320. </Grid>
  321. </Grid>
  322. {/*row 5*/}
  323. <Grid container display="flex" alignItems={"center"}>
  324. <Grid item xs={12} s={12} md={12} lg={12} sx={{ml:3, mr:3, mb:marginBottom}}>
  325. <Grid container spacing={1}>
  326. <Grid item xs={4}>
  327. <LocalizationProvider dateAdapter={AdapterDayjs}>
  328. <DemoItem components={['DatePicker']}>
  329. <DatePicker
  330. id="collDateFrom"
  331. // onError={(newError) => setReceiptFromError(newError)}
  332. slotProps={{
  333. field: { readOnly: true, },
  334. textField: {
  335. // helperText: receiptFromErrorMessage,
  336. InputLabelProps: { shrink: true }
  337. },
  338. }}
  339. format="DD/MM/YYYY"
  340. label="Bank Credit Date (From)"
  341. value={collMinDate === null ? null : dayjs(collMinDate)}
  342. maxDate={collMaxDate === null ? null : dayjs(collMaxDate)}
  343. onChange={(newValue) => {
  344. // console.log(newValue)
  345. setCollMinDate(newValue);
  346. }}
  347. />
  348. </DemoItem >
  349. </LocalizationProvider>
  350. </Grid>
  351. <Grid item xs={4}>
  352. <LocalizationProvider dateAdapter={AdapterDayjs}>
  353. <DemoItem components={['DatePicker']}>
  354. <DatePicker
  355. id="collDateTo"
  356. // onError={(newError) => setReceiptFromError(newError)}
  357. slotProps={{
  358. field: { readOnly: true, },
  359. textField: {
  360. // helperText: receiptFromErrorMessage,
  361. InputLabelProps: { shrink: true }
  362. },
  363. }}
  364. format="DD/MM/YYYY"
  365. label="Bank Credit Date (To)"
  366. value={collMaxDate === null ? null : dayjs(collMaxDate)}
  367. minDate={collMinDate === null ? null : dayjs(collMinDate)}
  368. onChange={(newValue) => {
  369. // console.log(newValue)
  370. setCollMaxDate(newValue);
  371. }}
  372. />
  373. </DemoItem >
  374. </LocalizationProvider>
  375. </Grid>
  376. </Grid>
  377. </Grid>
  378. </Grid>
  379. <Grid container direction="row" justifyContent="space-between">
  380. <Grid item>
  381. <Grid container justifyContent="flex-Start" direction="row" alignItems="center" spacing={3}>
  382. <Grid item sx={{ ml: 3, mb: 3, }} >
  383. {/* <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  384. <Button
  385. variant="contained"
  386. color="cancel"
  387. onClick={clearHandler()}
  388. >
  389. Reset
  390. </Button>
  391. </ThemeProvider> */}
  392. </Grid>
  393. </Grid>
  394. </Grid>
  395. <Grid item>
  396. <Grid container justifyContent="flex-end" direction="row" alignItems="center" spacing={3}>
  397. {onLoad?
  398. <Grid item sx={{ ml: 3, mb: 3, mr:6 }} >
  399. <LoadingComponent disableText={true} alignItems="flex-start"/>
  400. </Grid>
  401. :
  402. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  403. <Grid item sx={{ mr: 3, mb: 3, }} >
  404. <Button
  405. variant="contained"
  406. color="cancel"
  407. onClick={clearHandler()}
  408. >
  409. Reset
  410. </Button>
  411. </Grid>
  412. <Grid item sx={{ ml: 3, mb: 3, }} >
  413. <Button
  414. variant="contained"
  415. type="submit"
  416. >
  417. View
  418. </Button>
  419. </Grid>
  420. <Grid item sx={{ ml: 3, mb: 3, }} >
  421. <Grid container spacing={3}>
  422. <Grid item sx={{ ml: 3, mr:3 }} >
  423. <Button
  424. variant="contained"
  425. onClick={generateFileHandler("csv")}
  426. >
  427. Generate CSV
  428. </Button>
  429. </Grid>
  430. <Grid item sx={{ ml: 3, }} >
  431. <Button
  432. variant="contained"
  433. onClick={generateFileHandler("pdf")}
  434. >
  435. Generate PDF
  436. </Button>
  437. </Grid>
  438. </Grid>
  439. </Grid>
  440. {/* <Grid item sx={{ ml: 3, mr: 3, mb: 3, }} >
  441. {onDownload?
  442. <LoadingComponent disableText={true} alignItems="flex-start"/>
  443. :
  444. <Button
  445. variant="contained"
  446. onClick={generatePDFHandler}
  447. >
  448. Generate PDF
  449. </Button>
  450. }
  451. </Grid> */}
  452. </ThemeProvider>
  453. }
  454. </Grid>
  455. </Grid>
  456. </Grid>
  457. </Grid>
  458. </form>
  459. </MainCard>
  460. );
  461. };
  462. export default SearchPublicNoticeForm;