diff --git a/src/pages/client/ClientMaintainPage/ClientForm.js b/src/pages/client/ClientMaintainPage/ClientForm.js index c40b569..a4c0d38 100644 --- a/src/pages/client/ClientMaintainPage/ClientForm.js +++ b/src/pages/client/ClientMaintainPage/ClientForm.js @@ -47,8 +47,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { const location = useLocation(); const queryParams = new URLSearchParams(location.search); const refId = queryParams.get("refId"); - const [isFirstInit, setIsFirstInit] = useState(true); - + const params = useParams(); const navigate = useNavigate(); const ability = useContext(AbilityContext); @@ -61,6 +60,8 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { const { setIsUploading } = useContext(UploadContext); const [refClient, setRefClient] = useState({}); const [consultantComboList, setConsultantComboList] = useState([]); + const [selectedConsultant, setSelectedConsultant] = useState(null); + const [isFirstInit, setIsFirstInit] = useState(true); // Form data const { register, getValues, setValue } = useForm(); @@ -70,7 +71,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { // Handler to navigate back const returnSearchPage = () => { - navigate('/search'); + navigate('/client'); } const FIXED_HEADER_HEIGHT = 120; // <-- **IMPORTANT: Set this to the height of your actual fixed header in pixels** @@ -100,6 +101,15 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { const handleEditClick = () => { setIsEditing(true); }; + + useEffect(() => { + if (!isObjEmpty(refClient) && consultantComboList.length > 0 && isFirstInit) { + const matched = consultantComboList.find(c => c.id === refClient.consultantId); + setSelectedConsultant(matched || null); + setValue("consultantId", matched || null); + setIsFirstInit(false); + } + }, [refClient, consultantComboList, isFirstInit]); // 1. Earned Income const [earnedIncome, setEarnedIncome] = useState({ @@ -253,6 +263,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { const handleLiabilitiesChange = (field, value) => { setLiabilities(prev => ({ ...prev, [field]: value })); }; + const totalLiabilitiesCurrent = (parseFloat(liabilities.personalLoansCurrent) || 0) + (parseFloat(liabilities.mortgagesCurrent) || 0) + (parseFloat(liabilities.marginAccountCurrent) || 0) + @@ -292,6 +303,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { }; const formatNumberForDisplay = (num) => { + console.log(num); // 1. Handle null, undefined, or empty string input gracefully (return as is) if (num === null || num === undefined || num === '') return ''; @@ -322,6 +334,8 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { return formatted + '.'; } } + + console.log(formatted); return formatted; }; @@ -392,9 +406,31 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { setValue("firstname", refClient.firstname); setValue("email", refClient.email); setValue("phone1", refClient.phone1); + setValue("phone1Code", refClient.phone1Code); setValue("phone2", refClient.phone2); setValue("remarks", refClient.remarks); setValue("caseManagerId", 1); + + setValue("crAddressRoom", refClient.crAddressRoom); + setValue("crAddressFloor", refClient.crAddressFloor); + setValue("crAddressBuilding", refClient.crAddressBuilding); + setValue("crAddressStreet", refClient.crAddressStreet); + setValue("crAddressStreet", refClient.crAddressStreet); + setValue("crAddressArea", refClient.crAddressArea); + setValue("crAddressCity", refClient.crAddressCity); + setValue("crAddressCountry", refClient.crAddressCountry); + setValue("crAddressPostalCode", refClient.crAddressPostalCode); + + setValue("corAddressRoom", refClient.corAddressRoom); + setValue("corAddressFloor", refClient.corAddressFloor); + setValue("corAddressBlock", refClient.corAddressBlock); + setValue("corAddressBuilding", refClient.corAddressBuilding); + setValue("corAddressStreet", refClient.corAddressStreet); + setValue("corAddressArea", refClient.corAddressArea); + setValue("corAddressCity", refClient.corAddressCity); + setValue("corAddressCountry", refClient.corAddressCountry); + setValue("corAddressPostalCode", refClient.corAddressPostalCode); + earnedIncome.salaryCurrent = refClient.salaryCurrent; earnedIncome.salaryLast = refClient.salaryLast; earnedIncome.bonusCurrent = refClient.bonusCurrent; @@ -412,9 +448,9 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { unearnedIncome.investmentIncomeLast = refClient.investmentIncomeLast; unearnedIncome.otherUnearnedCurrent = refClient.otherUnearnedCurrent; unearnedIncome.otherUnearnedLast = refClient.otherUnearnedLast; - unearnedIncome.mortgageCurrent = refClient.mortgageCurrent; - unearnedIncome.mortgageLast = refClient.mortgageLast; + expenditure.mortgageCurrent = refClient.mortgageCurrent; + expenditure.mortgageLast = refClient.mortgageLast; expenditure.rentCurrent = refClient.rentCurrent; expenditure.rentLast = refClient.rentLast; expenditure.schoolingCurrent = refClient.schoolingCurrent; @@ -500,6 +536,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { data["firstname"] = values.firstname; data["email"] = values.email; data["phone1"] = values.phone1; + data["phone1Code"] = values.phone1Code; data["phone2"] = values.phone2; data["remarks"] = values.remarks; data["caseManagerId"] = 1; @@ -514,6 +551,15 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { data["crAddressCity"] = values.crAddressCity; data["crAddressCountry"] = values.crAddressCountry; data["crAddressPostalCode"] = values.crAddressPostalCode; + data["corAddressRoom"] = values.corAddressRoom; + data["corAddressFloor"] = values.corAddressFloor; + data["corAddressBlock"] = values.corAddressBlock; + data["corAddressBuilding"] = values.corAddressBuilding; + data["corAddressStreet"] = values.corAddressStreet; + data["corAddressArea"] = values.corAddressArea; + data["corAddressCity"] = values.corAddressCity; + data["corAddressCountry"] = values.corAddressCountry; + data["corAddressPostalCode"] = values.corAddressPostalCode; data = { ...data, // Keep all existing header fields @@ -736,10 +782,23 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { Phone Number: - + + + + + + { options={consultantComboList} getOptionLabel={(option) => option.name || ""} isOptionEqualToValue={(option, value) => option.id === value.id} - value={getValues("consultantId") || null} - onChange={(event, newValue) => { - setValue('consultantId', newValue || null); - }} - renderInput={(params) => ( + value={selectedConsultant} + onChange={(e, v) => { + setSelectedConsultant(v); + setValue('consultantId', v); } + } + renderInput={(params) => ( { - Address(Room): + Rs. Address(Room): @@ -823,7 +883,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(Floor): + Rs. Address(Floor): @@ -843,7 +903,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(Block): + Rs. Address(Block): @@ -863,7 +923,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(Buliding): + Rs. Address(Buliding): @@ -883,7 +943,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(Street): + Rs. Address(Street): @@ -903,7 +963,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(Area): + Rs. Address(Area): @@ -923,7 +983,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(City): + Rs. Address(City): @@ -943,7 +1003,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(Country): + Rs. Address(Country): @@ -963,7 +1023,7 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { - Address(Postal Code): + Rs. Address(Postal Code): @@ -979,6 +1039,190 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { + + + + + + + Corr. Address(Room): + + + + + + + + + + + + Corr. Address(Floor): + + + + + + + + + + + + Corr. Address(Block): + + + + + + + + + + + + Corr. Address(Buliding): + + + + + + + + + + + + Corr. Address(Street): + + + + + + + + + + + + Corr. Address(Area): + + + + + + + + + + + + Corr. Address(City): + + + + + + + + + + + + Corr. Address(Country): + + + + + + + + + + + + Corr. Address(Postal Code): + + + + + + + + + @@ -1002,6 +1246,8 @@ const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => { + + {/* ======================================================================= */} {/* --- START: EARNED INCOME 薪酬收入 (Image 1) --- */}