commit 8b72c9df74623c97044137ec23a4e3a165b0fc10 Author: Hao Tran Date: Wed Jan 8 08:03:00 2025 -0500 Init diff --git a/index.html b/index.html new file mode 100644 index 0000000..5f6b138 --- /dev/null +++ b/index.html @@ -0,0 +1,124 @@ + + + + + + Calculator + + + +
+

Calculator

+
+ +
+ +
+
+
+

Policy Details

+ + +
+ + +
+ Days in policy term: - +

+ + +
+ Days in force: - +
+ Days remaining: - +

+ Factor method: + Pro Rata + Short Rate +

+ Earned factor: - +
+ Unearned factor: - +

+ + +
+ Earned premium: - +
+ Return premium: - +
+ +
+

Breakdown

+

Total breakdown: N/A

+ + + +
+ Earned premium: - +
+ Return premium: - +

+ + + +
+ Earned premium: - +
+ Return premium: - +

+ + + +
+ Earned premium: - +
+ Return premium: - +

+ + + +
+ Earned premium: - +
+ Return premium: - +

+ + + +
+ Earned premium: - +
+ Return premium: - +

+ + + +
+ Earned premium: - +
+ Return premium: - +

+ + + +
+ Earned premium: - +
+ Return premium: - +

+
+
+
+ + + +
+ + + + + diff --git a/scripts/calculator.js b/scripts/calculator.js new file mode 100644 index 0000000..8e699ed --- /dev/null +++ b/scripts/calculator.js @@ -0,0 +1,114 @@ +function calculator() { + // pull from input fields + var effectiveDate = document.getElementById("effectiveDate").value; + var expiryDate = document.getElementById("expiryDate").value; + var cancelDate = document.getElementById("cancelDate").value; + var totalPremium = document.getElementById("totalPremium").value; + var breakDO = document.getElementById("breakDO").value || 0; + var breakEO = document.getElementById("breakEO").value || 0; + var breakCyber = document.getElementById("breakCyber").value || 0; + var breakLEI = document.getElementById("breakLEI").value || 0; + var breakCGL = document.getElementById("breakCGL").value || 0; + var breakProperty = document.getElementById("breakProperty").value || 0; + var breakEB = document.getElementById("breakEB").value || 0; + + // calculate dates in policy term + var policyDays = new Date(expiryDate).getTime() - new Date(effectiveDate).getTime(); + var termDays = policyDays / (1000 * 60 * 60 * 24); + + // calculate dates involved with cancellation + var cancelDays = new Date(cancelDate).getTime() - new Date(effectiveDate).getTime(); + var forceDays = cancelDays / (1000 * 60 * 60 * 24); + var remainingDays = termDays - forceDays; + + // calculate pro rata + if(document.getElementById('calcProRata').checked) { + var earnedFactor = Math.round(((forceDays / termDays) + Number.EPSILON)*1000)/1000; + var unearnedFactor = Math.round(((remainingDays / termDays) + Number.EPSILON)*1000)/1000; + // calculate short rate + }else if(document.getElementById('calcShortRate').checked) { + var earnedFactor = Math.round(((1 - ((remainingDays / termDays ) * 0.9)) + Number.EPSILON)*1000)/1000; + var unearnedFactor = Math.round((((remainingDays / termDays) * 0.9) + Number.EPSILON)*1000)/1000; + } + + // calculate premiums + var earnedPremium = Math.round(((totalPremium * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedPremium = Math.round(((totalPremium * unearnedFactor) + Number.EPSILON)*1000)/1000; + + // calculate breakdown + var calcBreak = +breakDO + +breakEO + +breakCyber + +breakLEI + +breakCGL + +breakProperty + +breakEB; + // check if breakdown matches total premium + var calcMatch = calcBreak-totalPremium; + if(totalPremiumcalcBreak) { + var checkMatch = "Total breakdown is too low by " + calcMatch + "."; + document.getElementById("checkMatch").className = 'red'; + var calculateBreakdown = false; + }else { + var checkMatch = "Total breakdown matches total premium! Success!"; + document.getElementById("checkMatch").className = 'green'; + var calculateBreakdown = true; + } + + // calculate breakdowns + if(calculateBreakdown == true) { + var earnedDO = Math.round(((breakDO * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedDO = Math.round(((breakDO * unearnedFactor) + Number.EPSILON)*1000)/1000; + var earnedEO = Math.round(((breakEO * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedEO = Math.round(((breakEO * unearnedFactor) + Number.EPSILON)*1000)/1000; + var earnedCyber = Math.round(((breakCyber * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedCyber = Math.round(((breakCyber * unearnedFactor) + Number.EPSILON)*1000)/1000; + var earnedLEI = Math.round(((breakLEI * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedLEI = Math.round(((breakLEI * unearnedFactor) + Number.EPSILON)*1000)/1000; + var earnedCGL = Math.round(((breakCGL * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedCGL = Math.round(((breakCGL * unearnedFactor) + Number.EPSILON)*1000)/1000; + var earnedProperty = Math.round(((breakProperty * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedProperty = Math.round(((breakProperty * unearnedFactor) + Number.EPSILON)*1000)/1000; + var earnedEB = Math.round(((breakEB * earnedFactor) + Number.EPSILON)*1000)/1000; + var unearnedEB = Math.round(((breakEB * unearnedFactor) + Number.EPSILON)*1000)/1000; + }else { + var earnedDO = 'ERROR' + var unearnedDO = 'ERROR' + var earnedEO = 'ERROR' + var unearnedEO = 'ERROR' + var earnedCyber = 'ERROR' + var unearnedCyber = 'ERROR' + var earnedLEI = 'ERROR' + var unearnedLEI = 'ERROR' + var earnedCGL = 'ERROR' + var unearnedCGL = 'ERROR' + var earnedProperty = 'ERROR' + var unearnedProperty = 'ERROR' + var earnedEB = 'ERROR' + var unearnedEB = 'ERROR' + } + + // display policy terms + document.getElementById("termDays").innerHTML = termDays; + document.getElementById("forceDays").innerHTML = forceDays; + document.getElementById("remainingDays").innerHTML = remainingDays; + document.getElementById("earnedFactor").innerHTML = earnedFactor; + document.getElementById("unearnedFactor").innerHTML = unearnedFactor; + document.getElementById("earnedPremium").innerHTML = earnedPremium; + document.getElementById("unearnedPremium").innerHTML = unearnedPremium; + // display breakdown + document.getElementById("checkMatch").innerHTML = checkMatch; + document.getElementById("earnedDO").innerHTML = earnedDO; + document.getElementById("unearnedDO").innerHTML = unearnedDO; + document.getElementById("earnedEO").innerHTML = earnedEO; + document.getElementById("unearnedEO").innerHTML = unearnedEO; + document.getElementById("earnedCyber").innerHTML = earnedCyber; + document.getElementById("unearnedCyber").innerHTML = unearnedCyber; + document.getElementById("earnedLEI").innerHTML = earnedLEI; + document.getElementById("unearnedLEI").innerHTML = unearnedLEI; + document.getElementById("earnedCGL").innerHTML = earnedCGL; + document.getElementById("unearnedCGL").innerHTML = unearnedCGL; + document.getElementById("earnedProperty").innerHTML = earnedProperty; + document.getElementById("unearnedProperty").innerHTML = unearnedProperty; + document.getElementById("earnedEB").innerHTML = earnedEB; + document.getElementById("unearnedEB").innerHTML = unearnedEB; +} +doSomething diff --git a/style.css b/style.css new file mode 100644 index 0000000..c861333 --- /dev/null +++ b/style.css @@ -0,0 +1,76 @@ +:root { + --width: 900px; + --font-family: Verdana, sans-serif; + --font-scale: 1em; + --bg-100: #100F0F; + --bg-200: #1C1B1A; + --ui-100: #292726; + --ui-200: #343331; + --ui-300: #403E3C; + --text-100: #CECDC3; + + + --cyan-400: #3AA99F; + --green-400: #879A39; + --red-400: #D14D41; +} +@media (prefers-color-scheme: dark) { + :root { + } +} + +body { + margin: 0 auto; + padding: 0 16px; + max-width: var(--width); + background-color: var(--bg-100); + font-family: var(--font-family); + font-size: var(--font-scale); + color: var(--text-100); +} + +.green { color: var(--green-400); } +.red { color: var(--red-400); } + + + +button { + margin-top: 2rem; + padding: 10px; + width: 100%; + border: 1px solid var(--ui-300); + background-color: var(--green-400); + color: var(--text-100); +} +input { + border: 1px solid var(--ui-300); + background-color: var(--ui-100); + color: var(--text-100); +} +input:focus { + outline: none; + border-color: var(--cyan-400); +} + + +header { + margin-top: 4rem; +} + +main { + margin: 4rem 0; +} + +.flex-container { + display: flex; + flex-direction: row; + column-gap: 1rem; +} +.flex-1 { + order: 1; + width: 400px; +} + +.flex-2 { + order: 2; +}