Parcourir la source

summary report, add 90 days validation check

CR013B2
Jason Chuang il y a 1 jour
Parent
révision
90d151dfa4
1 fichiers modifiés avec 51 ajouts et 12 suppressions
  1. +51
    -12
      src/pages/Report/Summary/SummaryForm.js

+ 51
- 12
src/pages/Report/Summary/SummaryForm.js Voir le fichier

@@ -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}) => {
</Grid>
</ThemeProvider>
</Grid>
{dateRangeError && (
<Grid item xs={12} sx={{ mt: 1 }}>
<Typography color="error" variant="body2">
{dateRangeError}
</Typography>
</Grid>
)}

</Grid>
</form>
</MainCard>


Chargement…
Annuler
Enregistrer