From be13022fbe676d10e066b41fff9864c0297d13d1 Mon Sep 17 00:00:00 2001 From: Hristo Petrov Date: Fri, 7 Apr 2023 21:29:05 +0300 Subject: [PATCH] Increase interest v1 --- index.html | 13 ++----------- src/js/calcLoan.js | 25 ++++++++++++++----------- src/js/interestChanges.js | 24 +++++++++++++++++++----- src/js/main.js | 1 + 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index b1f395e..9d0f363 100644 --- a/index.html +++ b/index.html @@ -38,20 +38,11 @@
+ header-text="Advanced settings" + collapsed >
Add extra payment -
-
-
-
-
-
Add Interest Rate Change
diff --git a/src/js/calcLoan.js b/src/js/calcLoan.js index f461e08..456fb75 100644 --- a/src/js/calcLoan.js +++ b/src/js/calcLoan.js @@ -52,17 +52,20 @@ export function setUpCalc(element) { if(!isNaN(interestRateChange[1])) { // the new interest rate should take effect (converted from %) monthlyInterestRate = interestRateChange[1] / 12 / 100; - // Calculate the new variable monthly payment based on - // - the remaining loan principal - // - the new interest rate - // - the remaining time - // payment = remainingBalance * (monthlyInterestRate * (Math.pow(1 + monthlyInterestRate, numberOfPayments - i + 1))) / ((Math.pow(1 + monthlyInterestRate, numberOfPayments - i + 1)) - 1); - fixedMonthlyPayment = remainingPrincipal * (monthlyInterestRate * (Math.pow(1 + monthlyInterestRate, remainingMonths + 1))) / ((Math.pow(1 + monthlyInterestRate, remainingMonths + 1)) - 1); - //if (newPayment > fixedMonthlyPayment) { - // fixedMonthlyPayment = newPayment; - //} - //console.log(fixedMonthlyPayment); - // fixedMonthlyPayment = calcfixedMonthlyPayment(remainingPrincipal, monthlyInterestRate, Math.abs(loanData.loanTerm - index)); + console.log(interestRateChange[2]); + if (interestRateChange[2]) { + // Calculate the new variable monthly payment based on + // - the remaining loan principal + // - the new interest rate + // - the remaining time + // payment = remainingBalance * (monthlyInterestRate * (Math.pow(1 + monthlyInterestRate, numberOfPayments - i + 1))) / ((Math.pow(1 + monthlyInterestRate, numberOfPayments - i + 1)) - 1); + fixedMonthlyPayment = remainingPrincipal * (monthlyInterestRate * (Math.pow(1 + monthlyInterestRate, remainingMonths + 1))) / ((Math.pow(1 + monthlyInterestRate, remainingMonths + 1)) - 1); + //if (newPayment > fixedMonthlyPayment) { + // fixedMonthlyPayment = newPayment; + //} + //console.log(fixedMonthlyPayment); + //const fixedMonthlyPayment2 = calcFixedMonthlyPayment(remainingPrincipal, monthlyInterestRate, Math.abs(loanData.loanTerm - index)); + } } }) diff --git a/src/js/interestChanges.js b/src/js/interestChanges.js index 73fa338..96b9ea7 100644 --- a/src/js/interestChanges.js +++ b/src/js/interestChanges.js @@ -1,14 +1,16 @@ const gatherInterestChanges = () => { const interestChanges = []; - const interestChangesRows = document.querySelectorAll("#interestChangesTable ui5-table-row"); + const interestChangesRows = document.querySelectorAll('#interestChangesTable ui5-table-row'); interestChangesRows.forEach((row) => { - const inputs = row.querySelectorAll("ui5-input"); + const inputs = row.querySelectorAll('ui5-input'); + const recalculateSwitch = row.querySelector('ui5-switch'); const month = Number.parseFloat(inputs[0].value); const newMonthly = Number.parseFloat(inputs[1].value) || 0; + const recalculatePayment = recalculateSwitch.getAttribute('checked') === ''; - interestChanges.push([month, newMonthly]); + interestChanges.push([month, newMonthly, recalculatePayment]); }); return interestChanges; @@ -28,6 +30,10 @@ function setUpInterestChanges (addInterestChangesButton) { New Interest + + Recalculate Payment + + Delete row @@ -64,11 +70,19 @@ function setUpInterestChanges (addInterestChangesButton) { }); const cell = document.createElement('ui5-table-cell') + const recalculateSwitch = document.createElement('ui5-switch'); + recalculateSwitch.setAttribute('text-on', 'Yes'); + recalculateSwitch.setAttribute('text-off', 'No'); + cell.appendChild(recalculateSwitch); + row.appendChild(cell); + + + const cellDel = document.createElement('ui5-table-cell') const button = document.createElement('ui5-button'); button.setAttribute('icon', 'delete'); button.addEventListener('click', () => deleteRow(row)); - cell.appendChild(button); - row.appendChild(cell); + cellDel.appendChild(button); + row.appendChild(cellDel); table.appendChild(row); diff --git a/src/js/main.js b/src/js/main.js index 4bf7a34..028589a 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -23,6 +23,7 @@ import "@ui5/webcomponents/dist/Icon"; import "@ui5/webcomponents/dist/List"; import "@ui5/webcomponents/dist/StandardListItem.js"; import "@ui5/webcomponents/dist/Slider"; +import "@ui5/webcomponents/dist/Switch"; import "@ui5/webcomponents-icons/dist/delete";