Created
November 14, 2024 14:51
-
-
Save sareiodata/5ea8f9f475dd7324a8673b5ecfd2902f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Dividend Distribution Calculator</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
max-width: 600px; | |
margin: 20px auto; | |
} | |
h1 { | |
text-align: center; | |
} | |
.container { | |
display: flex; | |
flex-direction: column; | |
gap: 10px; | |
} | |
label { | |
font-weight: bold; | |
} | |
.input-group { | |
display: flex; | |
flex-direction: column; | |
} | |
.result { | |
margin-top: 20px; | |
padding: 10px; | |
border: 1px solid #ddd; | |
background: #f9f9f9; | |
} | |
button { | |
padding: 10px; | |
background: #007bff; | |
color: white; | |
border: none; | |
cursor: pointer; | |
} | |
button:hover { | |
background: #0056b3; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Dividend Distribution Calculator</h1> | |
<div class="container"> | |
<div class="input-group"> | |
<label for="totalDividends">Total Dividends:</label> | |
<input type="number" id="totalDividends" placeholder="Enter total dividends" step="0.01" min="0" required> | |
</div> | |
<div class="input-group"> | |
<label>Initial Ownership Percentage (0-100):</label> | |
<label for="ownerA">Owner A:</label> | |
<input type="number" id="ownerA" placeholder="Enter percentage for Owner A" step="0.01" min="0" max="100" required> | |
<label for="ownerB">Owner B:</label> | |
<input type="number" id="ownerB" placeholder="Enter percentage for Owner B" step="0.01" min="0" max="100" required> | |
<label for="ownerC">Owner C:</label> | |
<input type="number" id="ownerC" placeholder="Enter percentage for Owner C" step="0.01" min="0" max="100" required> | |
</div> | |
<div class="input-group"> | |
<label for="extraAmount">Extra Amount:</label> | |
<input type="number" id="extraAmount" placeholder="Enter extra amount" step="0.01" min="0" required> | |
</div> | |
<div class="input-group"> | |
<label>Select Owner with Extra Amount:</label> | |
<input type="radio" id="extraOwnerA" name="extraOwner" value="A" required> Owner A | |
<input type="radio" id="extraOwnerB" name="extraOwner" value="B" required> Owner B | |
<input type="radio" id="extraOwnerC" name="extraOwner" value="C" required> Owner C | |
</div> | |
<button onclick="calculateDistribution()">Calculate Distribution</button> | |
<div class="result" id="result"> | |
<!-- Results will be displayed here --> | |
</div> | |
</div> | |
<script> | |
function calculateDistribution() { | |
const totalDividends = parseFloat(document.getElementById("totalDividends").value); | |
const ownerA = parseFloat(document.getElementById("ownerA").value) / 100; | |
const ownerB = parseFloat(document.getElementById("ownerB").value) / 100; | |
const ownerC = parseFloat(document.getElementById("ownerC").value) / 100; | |
const extraAmount = parseFloat(document.getElementById("extraAmount").value); | |
const extraOwner = document.querySelector('input[name="extraOwner"]:checked'); | |
// Error checking for valid inputs | |
if (isNaN(totalDividends) || isNaN(ownerA) || isNaN(ownerB) || isNaN(ownerC) || isNaN(extraAmount) || !extraOwner) { | |
document.getElementById("result").innerHTML = "<p style='color:red;'>Please fill in all fields correctly.</p>"; | |
return; | |
} | |
const selectedOwner = extraOwner.value; | |
const initialA = totalDividends * ownerA; | |
const initialB = totalDividends * ownerB; | |
const initialC = totalDividends * ownerC; | |
let adjustedA = initialA, adjustedB = initialB, adjustedC = initialC; | |
if (selectedOwner === 'A') { | |
const deductionFactor = ownerB + ownerC; | |
const deductionB = extraAmount * (ownerB / deductionFactor); | |
const deductionC = extraAmount * (ownerC / deductionFactor); | |
adjustedA = initialA + extraAmount; | |
adjustedB = initialB - deductionB; | |
adjustedC = initialC - deductionC; | |
} else if (selectedOwner === 'B') { | |
const deductionFactor = ownerA + ownerC; | |
const deductionA = extraAmount * (ownerA / deductionFactor); | |
const deductionC = extraAmount * (ownerC / deductionFactor); | |
adjustedB = initialB + extraAmount; | |
adjustedA = initialA - deductionA; | |
adjustedC = initialC - deductionC; | |
} else if (selectedOwner === 'C') { | |
const deductionFactor = ownerA + ownerB; | |
const deductionA = extraAmount * (ownerA / deductionFactor); | |
const deductionB = extraAmount * (ownerB / deductionFactor); | |
adjustedC = initialC + extraAmount; | |
adjustedA = initialA - deductionA; | |
adjustedB = initialB - deductionB; | |
} | |
const totalAdjusted = adjustedA + adjustedB + adjustedC; | |
const percentA = ((adjustedA / totalAdjusted) * 100).toFixed(2); | |
const percentB = ((adjustedB / totalAdjusted) * 100).toFixed(2); | |
const percentC = ((adjustedC / totalAdjusted) * 100).toFixed(2); | |
document.getElementById("result").innerHTML = ` | |
<p><strong>Adjusted Distribution:</strong></p> | |
<p>Owner A: $${adjustedA.toFixed(2)} (${percentA}%)</p> | |
<p>Owner B: $${adjustedB.toFixed(2)} (${percentB}%)</p> | |
<p>Owner C: $${adjustedC.toFixed(2)} (${percentC}%)</p> | |
`; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment