// material-ui import { Button, Grid, TextField, Autocomplete, Typography } from '@mui/material'; import MainCard from "components/MainCard"; import { useForm } from "react-hook-form"; import * as React from "react"; import * as ComboData from "utils/ComboData"; import * as DateUtils from "utils/DateUtils"; import * as FormatUtils from "utils/FormatUtils"; import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst"; import {ThemeProvider} from "@emotion/react"; import { useIntl } from "react-intl"; import {DatePicker} from "@mui/x-date-pickers/DatePicker"; import dayjs from "dayjs"; import {DemoItem} from "@mui/x-date-pickers/internals/demo"; import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider"; import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const SearchDemandNoteForm = ({ applySearch, orgComboData, searchCriteria, issueComboData, onGridReady }) => { const [type, setType] = React.useState([]); const [orgSelected, setOrgSelected] = React.useState({}); const [orgCombo, setOrgCombo] = React.useState(); const [issueSelected, setIssueSelected] = React.useState({}); const [issueCombo, setIssueCombo] = React.useState([]); const [selectedStatus, setSelectedStatus] = React.useState(ComboData.denmandNoteStatus[0]); const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom); const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo); const [fromDateValue, setFromDateValue] = React.useState(searchCriteria.dateFrom); const [toDateValue, setToDateValue] = React.useState(searchCriteria.dateTo); const [minDueDate, setMinDueDate] = React.useState(null); const [maxDueDate, setMaxDueDate] = React.useState(null); const [fromDueDateValue, setFromDueDateValue] = React.useState(null); const [toDueDateValue, setToDueDateValue] = React.useState(null); const intl = useIntl(); const { locale } = intl; React.useEffect(() => { if(searchCriteria.status!=undefined){ if(searchCriteria.status === ""){ ComboData.denmandNoteStatus[0] }else{ setSelectedStatus(ComboData.denmandNoteStatus.find(item => item.type === searchCriteria.status)) } if(searchCriteria.dueDateFrom != ""){ setMinDueDate(DateUtils.dateValue(searchCriteria.dueDateFrom)) }else{ setMinDueDate(null) } if(searchCriteria.dueDateTo != ""){ setMaxDueDate(DateUtils.dateValue(searchCriteria.dueDateTo)) }else{ setMaxDueDate(null); } }else{ setSelectedStatus(ComboData.denmandNoteStatus[0]) } }, [searchCriteria]); React.useEffect(() => { setFromDateValue(minDate); }, [minDate]); React.useEffect(() => { setToDateValue(maxDate); }, [maxDate]); React.useEffect(() => { setFromDueDateValue(minDueDate); }, [minDueDate]); React.useEffect(() => { setToDueDateValue(maxDueDate); }, [maxDueDate]); const { reset, register, handleSubmit } = useForm() const onSubmit = (data) => { data.status = selectedStatus?.type; let typeArray = []; let sentDateFrom = ""; let sentDateTo = ""; let sentDueDateFrom = ""; let sentDueDateTo = ""; for (let i = 0; i < type.length; i++) { typeArray.push(type[i].label); } if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") { sentDateFrom = DateUtils.dateValue(fromDateValue) sentDateTo = DateUtils.dateValue(toDateValue) } if (fromDueDateValue != "dd / mm / yyyy" && toDueDateValue != "dd / mm / yyyy") { sentDueDateFrom = DateUtils.dateValue(fromDueDateValue) sentDueDateTo = DateUtils.dateValue(toDueDateValue) } const temp = { appNo: data.appNo, issueId: issueSelected?.id, orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "", dnNo: data.dnNo, dateFrom: sentDateFrom, dateTo: sentDateTo, dueDateFrom: sentDueDateFrom, dueDateTo: sentDueDateTo, status: (data?.status === '' || data?.status?.includes("all")) ? "" : data.status, start:0, limit:10 }; applySearch(temp); }; React.useEffect(() => { if (orgComboData && orgComboData.length > 0) { setOrgCombo(orgComboData); if(searchCriteria.orgId!=undefined){ setOrgSelected(orgComboData.find(item => item.key === searchCriteria.orgId)) } } }, [orgComboData]); React.useEffect(() => { if (issueComboData && issueComboData.length > 0) { setIssueCombo(issueComboData); if(searchCriteria.issueId!=undefined){ setIssueSelected(issueComboData.find(item => item.id === searchCriteria.issueId)) } } }, [issueComboData]); function resetForm() { setType([]); setOrgSelected({}); setIssueSelected({}); setSelectedStatus(ComboData.denmandNoteStatus[0]); setMinDueDate(null); setMaxDueDate(null); setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14))) setMaxDate(DateUtils.dateValue(new Date())) reset({ appNo:"", dnNo:"", }); localStorage.setItem('searchCriteria',"") } function getIssueLabel(data) { let issueYear = data.issueYear let volume = data.volume; let issueNo = data.issueNo; let issueDate = data.issueDate; if (locale === 'zh-HK') { return issueYear + " 第" + volume + "卷," + " 第" + issueNo + "期," + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日") + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")"; } else if (locale === 'zh-CN') { return issueYear + " 第" + volume + "卷," + " 第" + issueNo + "期," + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日") + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")"; } return issueYear + " Vol. " + FormatUtils.zeroPad(volume, 3) + ", No. " + FormatUtils.zeroPad(issueNo, 2) + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)"); } return (
{/*row 1*/} Search {/*row 2*/} getIssueLabel(option)} onChange={(event, newValue) => { setIssueSelected(newValue); }} sx={{ '& .MuiInputBase-root': { alignItems: 'center' }, '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' }, '& .MuiOutlinedInput-root': { height: 40 } }} renderInput={(params) => ( )} /> { orgCombo ? option.groupType} size="small" value={orgSelected} getOptionLabel={(option) => option.name? option.name : ""} inputValue={orgSelected ? orgSelected.name!=undefined?orgSelected.name:"" : ""} onChange={(event, newValue) => { if (newValue !== null) { setOrgSelected(newValue); }else{ setOrgSelected({}); } }} sx={{ '& .MuiInputBase-root': { alignItems: 'center' }, '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' }, '& .MuiOutlinedInput-root': { height: 40 } }} renderInput={(params) => ( )} renderGroup={(params) => ( {params.group} {params.children} )} /> : <> } setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, // textField: { // helperText: receiptFromErrorMessage, // }, }} format="DD/MM/YYYY" label={"Issue Date (From)"} value={minDate === null ? null : dayjs(minDate)} maxDate={maxDate === null ? null : dayjs(maxDate)} onChange={(newValue) => { // console.log(newValue) if(newValue!=null){ setMinDate(newValue); } }} /> setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, // textField: { // helperText: receiptFromErrorMessage, // }, }} format="DD/MM/YYYY" label={"Issue Date (To)"} value={maxDate === null ? null : dayjs(maxDate)} minDate={minDate === null ? null : dayjs(minDate)} onChange={(newValue) => { // console.log(newValue) if(newValue!=null){ setMaxDate(newValue); } }} /> setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, textField: { // helperText: receiptFromErrorMessage, InputLabelProps: { shrink: true } }, }} format="DD/MM/YYYY" label={"Due Date (From)"} value={minDueDate === null ? null : dayjs(minDueDate)} maxDate={maxDueDate === null ? null : dayjs(maxDueDate)} onChange={(newValue) => { // console.log(newValue) setMinDueDate(newValue); }} /> setReceiptFromError(newError)} slotProps={{ field: { readOnly: true, }, textField: { // helperText: receiptFromErrorMessage, InputLabelProps: { shrink: true } }, }} format="DD/MM/YYYY" label={"Due Date (To)"} value={maxDueDate === null ? null : dayjs(maxDueDate)} minDate={minDueDate === null ? null : dayjs(minDueDate)} onChange={(newValue) => { // console.log(newValue) setMaxDueDate(newValue); }} /> { if(newValue==null){ setSelectedStatus(ComboData.denmandNoteStatus[0]); }else{ setSelectedStatus(newValue); } }} sx={{ '& .MuiInputBase-root': { alignItems: 'center' }, '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' }, '& .MuiOutlinedInput-root': { height: 40 } }} getOptionLabel={(option) => option.label} renderInput={(params) => ( )} /> {/*last row*/}
); }; export default SearchDemandNoteForm;