diff --git a/CalculateInterest.grandtotalplugin/Info.plist b/CalculateInterest.grandtotalplugin/Info.plist
index 6b985eb..19dc0bb 100644
--- a/CalculateInterest.grandtotalplugin/Info.plist
+++ b/CalculateInterest.grandtotalplugin/Info.plist
@@ -60,7 +60,7 @@
copyright
CC0 v1.0 2022 Jatayu Holznagel
CFBundleVersion
- 2.2.3
+ 2.5
width
500
GrandTotalMinimumVersion
diff --git a/CalculateInterest.grandtotalplugin/de.lproj/Localizable.strings b/CalculateInterest.grandtotalplugin/de.lproj/Localizable.strings
index 6c846b5..afc8b65 100644
--- a/CalculateInterest.grandtotalplugin/de.lproj/Localizable.strings
+++ b/CalculateInterest.grandtotalplugin/de.lproj/Localizable.strings
@@ -11,3 +11,4 @@
"until" = "bis zum";
"Check Internet Connection" = "Internet Verbindung prüfen, um den Basiszinssatz abzurufen.";
"Own interest rate" = "Eigener Zinssatz";
+"ErrorDayCount" = "Fehler: Anzahl der Tage muss eine positive Zahl sein";
diff --git a/CalculateInterest.grandtotalplugin/en.lproj/Localizable.strings b/CalculateInterest.grandtotalplugin/en.lproj/Localizable.strings
index 0d1bcc1..69ee018 100644
--- a/CalculateInterest.grandtotalplugin/en.lproj/Localizable.strings
+++ b/CalculateInterest.grandtotalplugin/en.lproj/Localizable.strings
@@ -11,3 +11,4 @@
"until" = "until";
"Check Internet Connection" = "Check internet connection to retrieve prime rate.";
"Own interest rate" = "Own interest rate";
+"ErrorDayCount" = "Error: Number of days must be a positive number";
diff --git a/CalculateInterest.grandtotalplugin/index.js b/CalculateInterest.grandtotalplugin/index.js
index 7f19612..6800453 100644
--- a/CalculateInterest.grandtotalplugin/index.js
+++ b/CalculateInterest.grandtotalplugin/index.js
@@ -7,6 +7,9 @@
// interestRate -> Interest rate (number)
// ownInterestRate -> Own interest rate, if the automatically calculated one is to be overwritten (number)
+// Interest rate calculated with actual/360 method (EZB): https://en.wikipedia.org/wiki/Day_count_convention#Actual/360
+var actEZB = parseInt(360.00);
+
// Function to fetch via API the prime rate from bundesbank.de
function getXML() {
const URL = "https://api.statistiken.bundesbank.de/rest/data/";
@@ -29,24 +32,12 @@ var primeRate = getXML();
var primeRate = parseFloat(primeRate);
var primeInterest = interestRate + primeRate;
-// Check if year is leap (366 days) year or regular year (365 days) for interest calculation
-function daysOfYear(year) {
- return isLeapYear(year) ? 366 : 365;
-}
-
-function isLeapYear(year) {
- return year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
-}
-
-var currentTime = new Date();
-var currentYear = currentTime.getFullYear();
-
///Calculate delay period in number of days
delayEnd = new Date(delayEnd);
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 difference between start and end of default period
+var delayInDays = ((delayEnd - delayStart) / (1000 * 3600 * 24)) + 1; // +1 to count first and last day
// Calculate final interest rate with own interest rate or prime rate from bundesbank.de
function calculatedInterestRate() {
@@ -58,11 +49,10 @@ function calculatedInterestRate() {
return result;
}
}
-var finalInterestRate = calculatedInterestRate();
+var interestRate = calculatedInterestRate();
-// Calculate interest and round the result of the calculation
-var sumInterest = ((originalClaimAmount * finalInterestRate) / 100 / daysOfYear(currentYear)) * delayInDays;
-var interestRounded = Math.round((sumInterest + Number.EPSILON) * 100) / 100;
+// Calculate interest
+var sumInterest = ((originalClaimAmount * interestRate) / 100 / actEZB) * delayInDays;
optionsLocaleDate = {
year: "numeric",
@@ -72,10 +62,13 @@ optionsLocaleDate = {
// Distinction between 1 and several days for notes
function localizeDay() {
+ if (delayInDays < 0) {
+ return `${localize("ErrorDayCount")}`;
+ }
if (delayInDays == 1) {
- return `${localize("Day")} (${delayStart.toLocaleDateString("de-De", optionsLocaleDate)})`;
+ return `${localize("DelayPeriod")}: ${new Intl.NumberFormat("de-DE").format(delayInDays)} ${localize("Day")} (${delayStart.toLocaleDateString("de-De", optionsLocaleDate)})`;
} else {
- return `${localize("Days")} (${localize("from")} ${delayStart.toLocaleDateString("de-De", optionsLocaleDate)} ${localize("until")} ${delayEnd.toLocaleDateString("de-De", optionsLocaleDate)})`;
+ return `${localize("DelayPeriod")}: ${new Intl.NumberFormat("de-DE").format(delayInDays)} ${localize("Day")} ${localize("Days")} (${localize("from")} ${delayStart.toLocaleDateString("de-De", optionsLocaleDate)} ${localize("until")} ${delayEnd.toLocaleDateString("de-De", optionsLocaleDate)})`;
}
}
@@ -91,7 +84,7 @@ function update() {
aNotes = removePrevious(aNotes);
- aLine = `${localize("DelayPeriod")}: ${new Intl.NumberFormat("de-DE").format(delayInDays)} ${localizeDay()}\n${localize("OriginalClaimAmount")}: ${new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', currencyDisplay: 'code'}).format(originalClaimAmount)}\n${localize("InterestRate")}: ${formattedNumber(finalInterestRate)} %`;
+ aLine = `${localizeDay()}\n${localize("OriginalClaimAmount")}: ${new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', currencyDisplay: 'code'}).format(originalClaimAmount)}\n${localize("InterestRate")}: ${new Intl.NumberFormat("de-DE").format((interestRate))} %`;
aLine = "" + aLine + "";
@@ -99,7 +92,7 @@ function update() {
else aNewNotes = aLine;
result.notes = aNewNotes;
- result.unitPrice = interestRounded;
+ result.unitPrice = parseFloat(sumInterest);
return result;
}