diff --git a/src/pages/Report/Summary/SummaryForm.js b/src/pages/Report/Summary/SummaryForm.js index 7537312..60478ea 100644 --- a/src/pages/Report/Summary/SummaryForm.js +++ b/src/pages/Report/Summary/SummaryForm.js @@ -36,6 +36,8 @@ const SummaryForm = ({ searchCriteria, issueComboData}) => { const [waitDownload, setWaitDownload] = React.useState(false); + const [dateRangeError, setDateRangeError] = React.useState(""); + React.useEffect(() => { setFromDateValue(minDate); }, [minDate]); @@ -47,12 +49,40 @@ const SummaryForm = ({ searchCriteria, issueComboData}) => { const marginBottom = 2.5; const { reset, register, handleSubmit } = useForm() const onSubmit = (data) => { - setWaitDownload(true) + setWaitDownload(true); + setDateRangeError(""); + + // ---- 90-day validation (run on Export click) ---- + const from = dayjs(minDate); + const to = dayjs(maxDate); + + // If both dates are expected/required, validate both exist + range + if (!from.isValid() || !to.isValid()) { + setDateRangeError("Please select both Payment Date (From) and Payment Date (To)."); + setWaitDownload(false); + return; + } + + const diffDays = to.startOf("day").diff(from.startOf("day"), "day"); + if (diffDays > 90) { + setDateRangeError("Payment Date (From) and Payment Date (To) must be within 90 days."); + setWaitDownload(false); + return; + } + + // Optional: if you want to disallow negative ranges (should already be prevented by min/maxDate) + if (diffDays < 0) { + setDateRangeError("Payment Date (To) must be on or after Payment Date (From)."); + setWaitDownload(false); + return; + } + // ---- end validation ---- + let sentDateFrom = ""; let sentDateTo = ""; - if( fromDateValue!="dd / mm / yyyy"&&toDateValue!="dd / mm / yyyy"){ - sentDateFrom = DateUtils.dateValue(fromDateValue) - sentDateTo = DateUtils.dateValue(toDateValue) + if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") { + sentDateFrom = DateUtils.dateValue(fromDateValue); + sentDateTo = DateUtils.dateValue(toDateValue); } const temp = { @@ -64,6 +94,7 @@ const SummaryForm = ({ searchCriteria, issueComboData}) => { doExport(temp); }; + const doExport = (temp) => { HttpUtils.fileDownload({ url: UrlUtils.GEN_SUMMARY_LIST, @@ -170,10 +201,10 @@ const SummaryForm = ({ searchCriteria, issueComboData}) => { id="dateFrom" // onError={(newError) => setReceiptFromError(newError)} slotProps={{ - field: { readOnly: true, }, - // textField: { - // helperText: receiptFromErrorMessage, - // }, + field: { readOnly: true }, + textField: { + error: Boolean(dateRangeError) + } }} format="DD/MM/YYYY" label={"Submit Date (From)"} @@ -197,10 +228,10 @@ const SummaryForm = ({ searchCriteria, issueComboData}) => { id="dateTo" // onError={(newError) => setReceiptFromError(newError)} slotProps={{ - field: { readOnly: true, }, - // textField: { - // helperText: receiptFromErrorMessage, - // }, + field: { readOnly: true }, + textField: { + error: Boolean(dateRangeError) + } }} format="DD/MM/YYYY" label={"Submit Date (To)"} @@ -245,6 +276,14 @@ const SummaryForm = ({ searchCriteria, issueComboData}) => { + {dateRangeError && ( + + + {dateRangeError} + + + )} +