This commit is contained in:
omkieit 2024-10-09 19:32:59 +05:30
parent 680642715e
commit 17d889edc3
4 changed files with 290 additions and 22 deletions

View File

@ -206,6 +206,18 @@ const propertySchema = mongoose.Schema({
type: Number, type: Number,
required: true, // Set to true if this field is mandatory required: true, // Set to true if this field is mandatory
}, },
adjustments:[
{
title: {
type: String,
required: true, // Set to true if this field is mandatory
},
price: {
type: Number,
required: true, // Set to true if this field is mandatory
},
},
],
totaladjustments:{ totaladjustments:{
type: Number, type: Number,
required: true, // Set to true if this field is mandatory required: true, // Set to true if this field is mandatory
@ -222,6 +234,26 @@ const propertySchema = mongoose.Schema({
type: Number, type: Number,
required: true, // Set to true if this field is mandatory required: true, // Set to true if this field is mandatory
}, },
incomestatement: [
{
title: {
type: String,
required: true, // Set to true if this field is mandatory
},
price: {
type: Number,
required: true, // Set to true if this field is mandatory
},
},
],
totalincomestatement:{
type: Number,
required: true, // Set to true if this field is mandatory
},
netBtoCsalevalue:{
type: Number,
required: true, // Set to true if this field is mandatory
},
}); });
const PropertyModal = mongoose.model("property", propertySchema); const PropertyModal = mongoose.model("property", propertySchema);

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,7 @@
<script type="module" crossorigin src="/assets/index-Bl7AZtqa.js"></script> <script type="module" crossorigin src="/assets/index-GLZpwqbK.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-iEl-il0E.css"> <link rel="stylesheet" crossorigin href="/assets/index-iEl-il0E.css">
</head> </head>

View File

@ -96,6 +96,10 @@ const Addproperty = () => {
], ],
adjustments:[ adjustments:[
{ title: "adjustments", price: "0"}, { title: "adjustments", price: "0"},
],
incomestatement:[
{ title: "income statement", price: "0"},
{ title: "income statement", price: "0"},
] ]
}); });
@ -698,6 +702,78 @@ const Addproperty = () => {
}; };
const addincomestatement = () => {
setFormData((prevData) => ({
...prevData,
incomestatement: [...prevData.incomestatement, { title: "", price: "" }],
}));
};
const deleteincomestatement = (index) => {
const updatedincomestatement = formData.incomestatement.filter(
(_, i) => i !== index
);
setFormData((prevData) => ({
...prevData,
incomestatement: updatedincomestatement,
}));
};
// Function to handle changes to incidentalCost title and price
const handleincomestatementTitle = (index, field, value) => {
const updatedincomestatement = [...formData.incomestatement];
updatedincomestatement[index][field] = value;
setFormData((prevData) => ({
...prevData,
incomestatement: updatedincomestatement,
}));
};
const handleincomestatementChange = (e, index) => {
const value = e.target.value;
// Regular expression to allow only numbers and optional decimals
const isNumber = /^\d*\.?\d*$/.test(value);
// If valid number, update state, otherwise show the alert
if (isNumber || value === "") {
const updatedincomestatement= formData.incomestatement.map(
(incomestatement, i) =>
i === index
? { ...incomestatement, price: value, isInvalid: false } // Reset isInvalid if valid number
: incomestatement
);
setFormData({ ...formData, incomestatement: updatedincomestatement });
} else {
const updatedincomestatement= formData.incomestatement.map(
(incomestatement, i) =>
i === index
? { ...incomestatement, isInvalid: true } // Set isInvalid true for invalid input
: incomestatement
);
setFormData({ ...formData, incomestatement: updatedincomestatement });
}
};
// Calculate total from incidentalCost array
const calculateTotalincomestatement = () => {
return formData.incomestatement.reduce((total, incomestatement) => {
const price = parseFloat(incomestatement.price);
return total + (isNaN(price) ? 0 : price); // Ensure only valid numbers are added
}, 0);
};
const calculatenetBtoCsalevalue = () =>{
const totalincomestatement= calculateTotalincomestatement();
const totalcosttosellbtoc= calculateTotalCosttoSellBtoC();
return totalincomestatement + totalcosttosellbtoc;
}
const handleSubmit = () => { const handleSubmit = () => {
if ( if (
formData.address && formData.address &&
@ -748,6 +824,8 @@ const Addproperty = () => {
const fundsavailablefordistribution = calculatefundsavailablefordistribution(); const fundsavailablefordistribution = calculatefundsavailablefordistribution();
const grossproceedsperHUD = calculateTotalCosttoSellBtoC(); const grossproceedsperHUD = calculateTotalCosttoSellBtoC();
const totalCosttoSellBtoC = calculateTotalCosttoSellBtoC(); const totalCosttoSellBtoC = calculateTotalCosttoSellBtoC();
const totalincomestatement = calculateTotalincomestatement();
const netBtoCsalevalue = calculatenetBtoCsalevalue();
// Add user info to formData, including the propertyTaxInfo array // Add user info to formData, including the propertyTaxInfo array
const formDataWithUserInfo = { const formDataWithUserInfo = {
@ -772,7 +850,9 @@ const Addproperty = () => {
totaladjustments:totaladjustments, totaladjustments:totaladjustments,
fundsavailablefordistribution:fundsavailablefordistribution, fundsavailablefordistribution:fundsavailablefordistribution,
grossproceedsperHUD:grossproceedsperHUD, grossproceedsperHUD:grossproceedsperHUD,
totalCosttoSellBtoC:totalCosttoSellBtoC totalCosttoSellBtoC:totalCosttoSellBtoC,
totalincomestatement:totalincomestatement,
netBtoCsalevalue:netBtoCsalevalue
}; };
// Check if propertyTaxInfo is an array and has values // Check if propertyTaxInfo is an array and has values
@ -3184,6 +3264,162 @@ Renovation Risk
</div> </div>
<hr
style={{
borderColor: "#fda417", // Set the color of the line
borderWidth: "1px", // Optional: Adjust the thickness of the line
backgroundColor: "#fda417", // Optional: Apply color if using for background
height: "1px", // Optional: Set height to match the border width
}}
/>
<span
style={{
color: "#fda417",
fontSize: "14px",
fontWeight: "bold",
}}
>
Income Statement Adjustments:
</span>
{formData.incomestatement.map((cost, index) => (
<div key={index} className="row gy-3 align-items-center">
<div className="col-md-4">
<input
type="text"
className="form-control"
value={cost.title}
onChange={(e) =>
handleincomestatementTitle(
index,
"title",
e.target.value
)
}
placeholder="Title"
required
/>
</div>
<div className="col-md-4">
<input
type="text"
className={`form-control ${
cost.isInvalid ? "is-invalid" : ""
}`} // Apply 'is-invalid' class when invalid
value={cost.price}
onChange={(e) => handleincomestatementChange(e, index)} // Use a new handler for price validation
placeholder="Price"
style={{ textAlign: "right" }}
required
/>
{cost.isInvalid && (
<div className="invalid-feedback">
Please enter a valid number.
</div>
)}
</div>
<div className="col-md-2 d-flex justify-content-start">
<button
className="btn btn-danger"
onClick={() => deleteincomestatement(index)}
style={{ marginLeft: "5px" }}
>
x
</button>
</div>
</div>
))}
<div className="col-md-4">
<button
className="btn btn-primary back"
onClick={addincomestatement}
style={{ backgroundColor: "#fda417", border: "#fda417" }}
>
<span
style={{
fontSize: "20px",
fontWeight: "normal",
}}
>
+
</span>{" "}
Add Income Statement
</button>
</div>
<div className="row gy-3 align-items-center">
<span
className="col-md-4"
style={{
color: "#fda417",
fontSize: "14px",
fontWeight: "bold",
}}
>
Total Income Statement Adjustment
</span>
<div className="col-md-4">
<input
type="text"
className="form-control"
name="totalincomestatement"
value={calculateTotalincomestatement()}
readOnly
style={{
borderColor: "#fda417", // Custom border color for the input field
color: "#fda417", // Optionally apply text color to the input text
textAlign: "right",
}}
// placeholder="Total Incidental Cost"
required
/>
</div>
</div>
<hr
style={{
borderColor: "#fda417", // Set the color of the line
borderWidth: "1px", // Optional: Adjust the thickness of the line
backgroundColor: "#fda417", // Optional: Apply color if using for background
height: "1px", // Optional: Set height to match the border width
}}
/>
<div className="row gy-3 align-items-center">
<span
className="col-md-4"
style={{
color: "#fda417",
fontSize: "14px",
fontWeight: "bold",
}}
>
Net B to C Sale Value
</span>
<div className="col-md-4">
<input
type="text"
className="form-control"
name="netBtoCsalevalue"
value={calculatenetBtoCsalevalue()}
readOnly
style={{
borderColor: "#fda417", // Custom border color for the input field
color: "#fda417", // Optionally apply text color to the input text
textAlign: "right",
}}
// placeholder="Total Incidental Cost"
required
/>
</div>
</div>