This commit is contained in:
omkieit 2024-10-09 12:27:21 +05:30
parent df7b057580
commit c996a2801d
4 changed files with 75 additions and 90 deletions

View File

@ -94,7 +94,7 @@ const propertySchema = mongoose.Schema({
},
},
],
totalCostsAtoB: {
totalPurchaseCosts: {
type: Number,
required: true, // Set to true if this field is mandatory
},
@ -114,7 +114,7 @@ const propertySchema = mongoose.Schema({
type: Number,
required: true, // Set to true if this field is mandatory
},
totalCostsAtoBaftercredits: {
totalPurchaseCostsaftercredits: {
type: Number,
required: true, // Set to true if this field is mandatory
},
@ -134,7 +134,8 @@ const propertySchema = mongoose.Schema({
type: Number,
required: true, // Set to true if this field is mandatory
},
totalcashsurplus :{
totalcashrequiredonsettlement:{
type: Number,
required: true, // Set to true if this field is mandatory
},

File diff suppressed because one or more lines are too long

View File

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

View File

@ -41,8 +41,8 @@ const Addproperty = () => {
{ title: "Recording Fee", price: "" },
{ title: "Property Tax", price: "" },
],
credits: [{ title: "Credits received on settlement", price: "" }],
cashAdjustments: [{ title: "Credits received on settlement", price: "" }],
credits: [{ title: "Credits", price: "" }],
cashAdjustments: [{ title: "Cash Adjustments", price: "" }],
incidentalCost: [
{ title: "Accounting Fees", price: "" },
{ title: "Bank Charges", price: "" },
@ -203,7 +203,7 @@ const Addproperty = () => {
}
};
const calculateTotalCosts = () => {
const calculateTotalPurchaseCosts = () => {
const totalCostsFromArray = formData.costPaidAtoB.reduce((total, cost) => {
const price = parseFloat(cost.price) || 0; // Convert price to number
return total + price;
@ -270,7 +270,7 @@ const Addproperty = () => {
}, 0);
};
const calculateTotalCostsWithCredits = () => {
const calculateTotalPurchaseCostsWithCredits = () => {
// Calculate total from costPaidAtoB array
const totalCostsFromArray = formData.costPaidAtoB.reduce((total, cost) => {
const price = parseFloat(cost.price) || 0; // Convert price to number
@ -349,6 +349,16 @@ const Addproperty = () => {
}, 0);
};
const calculateTotalCashRequiredonSettlement= () => {
const totalcashAdjustments = calculatecashAdjustments();
const totalcredits = calculateTotalCredits();
const totalPurchaseCosts= calculateTotalPurchaseCosts();
// Sum up all the values from the three functions
return totalcashAdjustments + totalcredits + totalPurchaseCosts;
};
const addincidentalCost = () => {
setFormData((prevData) => ({
...prevData,
@ -541,23 +551,7 @@ const Addproperty = () => {
return totalIncidentalCost + totalUtilMaintenanceCost + totalRenovationCost;
};
const handleNumericInput = (e) => {
const value = e.target.value;
// Check if the input is not a valid number
if (isNaN(value)) {
setFormData({
...formData,
isInvalid: true, // Set validation flag if not a number
});
} else {
setFormData({
...formData,
totalcashsurplus: value,
isInvalid: false, // Reset validation flag if valid
});
}
};
const handleSubmit = () => {
if (
@ -589,16 +583,17 @@ const Addproperty = () => {
formData.roofing &&
formData.totalSqft &&
formData.renovationRisk &&
formData.totalcashsurplus &&
formData.sellpricebtoc &&
formData.closeDateAtoB &&
formData.closeDateBtoC
) {
const totalCostsAtoB = calculateTotalCosts();
const totalCostsAtoBaftercredits = calculateTotalCostsWithCredits();
const totalPurchaseCosts = calculateTotalPurchaseCosts();
const totalPurchaseCostsaftercredits = calculateTotalPurchaseCostsWithCredits();
const totalcashAdjustments = calculatecashAdjustments();
const totalincidentalCost = calculateTotalincidentalCost();
const totalcredits = calculateTotalCredits();
const totalcashrequiredonsettlement = calculateTotalCashRequiredonSettlement();
const totalutilMaintenanceCost = calculatetotalutilMaintenanceCost();
const totalrenovationCost = calculaterenovationCost();
const costsAfterPropertyAcquisition =
@ -613,10 +608,11 @@ const Addproperty = () => {
usertitle: user?.result?.title,
useremail: user?.result?.email,
userId: user?.result?.userId,
totalCostsAtoB: totalCostsAtoB,
totalPurchaseCosts: totalPurchaseCosts,
totalcredits: totalcredits,
totalCostsAtoBaftercredits: totalCostsAtoBaftercredits,
totalPurchaseCostsaftercredits: totalPurchaseCostsaftercredits,
totalcashAdjustments: totalcashAdjustments,
totalcashrequiredonsettlement:totalcashrequiredonsettlement,
totalincidentalCost: totalincidentalCost,
totalutilMaintenanceCost: totalutilMaintenanceCost,
totalrenovationCost: totalrenovationCost,
@ -1674,7 +1670,6 @@ const Addproperty = () => {
color: "#fda417", // Optionally apply text color to the input text
textAlign: "right",
}}
placeholder="Total Costs to Buy A to B"
required
/>
</div>
@ -1730,27 +1725,18 @@ Renovation Risk
}}
/>
<div className="row gy-3 align-items-center">
<span
className="col-md-4"
style={{
color: "#fda417",
fontSize: "14px",
fontWeight: "bold",
}}
>
Property Acquisition A to B:
Purchase Price
</span>
<br />
<div className="row gy-3">
<div className="col-md-4">
<input
type="text"
className="form-control"
placeholder="Purchase Cost"
required
disabled
/>
</div>
<div className="col-md-4">
<input
type="text"
@ -1789,6 +1775,7 @@ Renovation Risk
)}
</div>
</div>
<hr
style={{
borderColor: "#fda417", // Set the color of the line
@ -1879,14 +1866,14 @@ Renovation Risk
fontWeight: "bold",
}}
>
Total Costs to Buy A to B
Total Purchase Cost
</span>
<div className="col-md-4">
<input
type="text"
className="form-control"
name="totalCostsAtoB"
value={calculateTotalCosts()}
name="totalPurchaseCosts"
value={calculateTotalPurchaseCosts()}
readOnly
style={{
borderColor: "#fda417", // Custom border color for the input field
@ -2025,21 +2012,20 @@ Renovation Risk
fontWeight: "bold",
}}
>
Total Costs to Buy A to B After credits
Total Purchase Cost after Credits Received
</span>
<div className="col-md-4">
<input
type="text"
className="form-control"
name="totalCostsAtoBaftercredits"
value={calculateTotalCostsWithCredits()}
name="totalPurchaseCostsaftercredits"
value={calculateTotalPurchaseCostsWithCredits()}
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 Costs to Buy A to B After credits"
required
/>
</div>
@ -2169,7 +2155,8 @@ Renovation Risk
}}
/>
<div className="row gy-3 align-items-center">
<div className="row gy-3 align-items-center">
<span
className="col-md-4"
style={{
@ -2178,33 +2165,30 @@ Renovation Risk
fontWeight: "bold",
}}
>
Total Cash Required/(Surplus) on Settlement
Total Cash Required on Settlement
</span>
<div className="col-md-4">
<input
type="text"
className={`form-control ${
formData.isInvalid ? "is-invalid" : ""
}`} // Apply 'is-invalid' class if invalid
name="totalcashsurplus"
value={formData.totalcashsurplus}
onChange={handleNumericInput} // Add handler for numeric validation
className="form-control"
name="totalcashrequiredonsettlement"
value={calculateTotalCashRequiredonSettlement()}
readOnly
style={{
borderColor: "#fda417", // Custom border color for the input field
color: "#fda417", // Optionally apply text color to the input text
textAlign: "right",
}}
placeholder="Enter only numbers"
// placeholder="Total Incidental Cost"
required
/>
{formData.isInvalid && (
<div className="invalid-feedback">
Please enter a valid number.
</div>
)}
</div>
</div>
<hr
style={{
borderColor: "#fda417", // Set the color of the line