Skip to content

Commit

Permalink
Merge pull request #5 from jajoho/Feature/Own-interest-rate
Browse files Browse the repository at this point in the history
- New: Own interest rate
- Fix: Error message when connection to Bundesbank.de is not working (Check network connection #4)
  • Loading branch information
jajoho authored Feb 6, 2022
2 parents e632883 + a8405a5 commit 8c6143e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
12 changes: 11 additions & 1 deletion CalculateInterest.grandtotalplugin/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@
<key>width</key>
<real>100</real>
</dict>
<dict>
<key>label</key>
<string>Own interest rate</string>
<key>name</key>
<string>ownInterestRate</string>
<key>type</key>
<string>number</string>
<key>width</key>
<real>100</real>
</dict>
</array>
<key>copyright</key>
<string>© 2022 Jatayu Holznagel</string>
<key>CFBundleVersion</key>
<string>2.1</string>
<string>2.2</string>
<key>width</key>
<real>500</real>
<key>GrandTotalMinimumVersion</key>
Expand Down
12 changes: 7 additions & 5 deletions CalculateInterest.grandtotalplugin/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"CalculateInterest" = "Verzugszinsen berechnen";
"Delay Start" = "Erster Verzugstag";
"Delay End" = "Zahlungseingang";
"Original claim amount" = "Ursprüngliche Forderung";
"OriginalClaimAmount" = "Ursprüngliche Forderung";
"Interest rate with percent" = "Prozentpunkte über Basiszinssatz";
"Days" = "Tage";
"Interest rate" = "Zinssatz";
"Delay Period" = "Verzugsdauer";
"days" = "Tage";
"InterestRate" = "Zinssatz";
"DelayPeriod" = "Verzugsdauer";
"from" = "vom";
"until" = "bis zum";
"until" = "bis zum";
"Check Internet Connection" = "Internet Verbindung prüfen, um den Basiszinssatz abzurufen.";
"Own interest rate" = "Eigener Zinssatz";
12 changes: 7 additions & 5 deletions CalculateInterest.grandtotalplugin/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"CalculateInterest" = "Calculate interest";
"Delay Start" = "First day after due date";
"Delay End" = "Date of payment";
"Original claim amount" = "Original claim amount";
"OriginalClaimAmount" = "Original claim amount";
"Interest rate with percent" = "Percentage points above prime rate";
"Days" = "Days";
"Interest rate" = "Interest rate";
"Delay Period" = "Delay period";
"days" = "days";
"InterestRate" = "Interest rate";
"DelayPeriod" = "Delay period";
"from" = "from";
"until" = "until";
"until" = "until";
"Check Internet Connection" = "Check internet connection to retrieve prime rate.";
"Own interest rate" = "Own interest rate";
27 changes: 20 additions & 7 deletions CalculateInterest.grandtotalplugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// delayEnd -> Delay period end date (date, formatted)
// outstandingDebt -> Outstanding debt (number)
// interestRate -> Interest rate (number)
// ownInterestRate -> Own interest rate, if the automatically calculated one is to be overwritten (number)

//

Expand All @@ -17,14 +18,15 @@ function getXML() {
if (string.length == 0) {
return null;
}
else {
getString();
return result;

function getString() {
var regExp = /-[0-9]*\.[0-9]+/m;
result = string.match(regExp);
}
}
}}

// Check if year is leap (366 days) year or regular year (365 days) for interest calculation
function daysOfYear(year) {
Expand All @@ -45,12 +47,23 @@ delayStart = new Date(delayStart);
// Math.round to still have delayInDays without decimals (can occur when date strings are not unified)
var delayInDays = Math.round((delayEnd - delayStart) / (1000 * 3600 * 24) + 1); // +1 to count first and last day

// Calculate final interest rate with interest rate entered by user and prime rate from bundesbank.de
var calculatedInterestRate = parseInt(interestRate) + +getXML();
// Calculate final interest rate with own interest rate or prime rate from bundesbank.de
function calculatedInterestRate() {
if (ownInterestRate > 0) {
return ownInterestRate;
}
if (getXML() == null) {
return localize("Check Internet Connection");
}
else {
result = parseInt(interestRate) + +getXML();
return result;
}
}

// Calculate interest and round the result of the calculation
var sumInterest =
((originalClaimAmount * calculatedInterestRate) /
((originalClaimAmount * calculatedInterestRate()) /
100 /
daysOfYear(currentYear)) *
delayInDays;
Expand All @@ -74,9 +87,9 @@ function update() {

aNotes = removePrevious(aNotes);

aLine = `${localize("Delay Period")}: ${delayInDays} ${localize("Days")} (${localize("from")} ${delayStart.toLocaleDateString("de-De",optionsLocaleDate)} ${localize("until")} ${delayEnd.toLocaleDateString("de-De",optionsLocaleDate
)})\n${localize("Original claim amount")}: ${currency} ${formattedNumber(originalClaimAmount
)}\n${localize("Interest rate")}: ${formattedNumber(calculatedInterestRate)} %`;
aLine = `${localize("DelayPeriod")}: ${delayInDays} ${localize("days")} (${localize("from")} ${delayStart.toLocaleDateString("de-De",optionsLocaleDate)} ${localize("until")} ${delayEnd.toLocaleDateString("de-De",optionsLocaleDate
)})\n${localize("OriginalClaimAmount")}: ${currency} ${formattedNumber(originalClaimAmount
)}\n${localize("InterestRate")}: ${formattedNumber(calculatedInterestRate())} %`;

aLine = "<i>" + aLine + "</i>";

Expand Down

0 comments on commit 8c6143e

Please sign in to comment.