Skip to content

Commit

Permalink
Merge pull request #2 from jajoho/Get-Prime-Rate
Browse files Browse the repository at this point in the history
v2.0
  • Loading branch information
jajoho authored Feb 5, 2022
2 parents d948344 + f3823e9 commit c1e1954
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CalculateInterest.grandtotalplugin/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<key>copyright</key>
<string>© 2022 Jatayu Holznagel</string>
<key>CFBundleVersion</key>
<string>1.0.1</string>
<string>2.0</string>
<key>width</key>
<real>500</real>
<key>GrandTotalMinimumVersion</key>
Expand Down
30 changes: 24 additions & 6 deletions CalculateInterest.grandtotalplugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@
*/

// Function to fetch via API the prime rate from bundesbank.de
function getXML(){
string = loadURL("GET","https://api.statistiken.bundesbank.de/rest/data/BBK01/SU0115?detail=dataonly&lastNObservations=1");
if (string.length == 0){
return null;
}
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*/
// Check if year is leap (366 days) year or regular year (365 days) for interest calculation
function daysOfYear(year) {
return isLeapYear(year) ? 366 : 365;
}
Expand All @@ -28,16 +42,19 @@ update();
function update() {
var result = {};

/* Calculate delay period in number of days */
///Calculate delay period in number of days
delayEnd = new Date(delayEnd);
delayStart = new Date(delayStart);
var delayInDays = ((delayEnd - delayStart) / (1000 * 3600 * 24)) + 1; // +1 to count first and last day

/* Calculate interest and round the result of the calculation */
var sumInterest = originalClaimAmount * interestRate / 100 / daysOfYear(currentYear) * delayInDays;
// Calculate final interest rate with interest rate entered by user and prime rate from bundesbank.de
var calculatedInterestRate = parseInt(interestRate) + +getXML();

// Calculate interest and round the result of the calculation
var sumInterest = originalClaimAmount * calculatedInterestRate / 100 / daysOfYear(currentYear) * delayInDays;
var interestRounded = Math.round((sumInterest + Number.EPSILON) * 100) / 100;

/* Create and change notes and provide GrandTotal interest sum for the document*/
// Create and change notes and provide GrandTotal interest sum for the document
var aNotes = valueForKeyPath("notes");
if (!aNotes)
aNotes = "";
Expand All @@ -50,7 +67,8 @@ function update() {
day: 'numeric'
};

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(interestRate)} %`;

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 = "<i>" + aLine + "</i>";
Expand Down
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
# Calculate-Interest-GrandTotal Plugin
# Deutsch: Calculate-Interest-GrandTotal Plugin
Ein Plugin für GrandTotal, um die Verzugszinsen zu berechnen.

## Installieren und nutzen
1. Die [aktuelleste Version](https://github.com/jajoho/Calculate-Interest-GrandTotal-Plugin/releases), herunterladen, die Datei entpacken und <code>CalculateInterest.grandtotalplugin</code> nach <code>~/Library/Application Support/com.mediaatelier.GrandTotal3/Plugins/</code> verschieben.
2. GrandTotal öffnen, ein neues Dokument anlegen oder zu einem bestehenden eine neue Zeile hinzufügen.
3. Auf das Zahnradsymbol klicken und auf <code>Verzugszinsen berechnen</code>
4. Eigene Werte eintragen.

![Verzugszinsen berechnen](https://user-images.githubusercontent.com/15175599/152641374-c7db59d9-2bf1-45eb-ac41-897b7c4fdaa6.png)



### Berechnungsmethode
- Die Zinsen werden nach der Effektivzinsmethode ([ICMA-Methode, früher ISMA-Methode)](https://de.wikipedia.org/wiki/Zinsberechnungsmethode#act/act_–_tagesgenaue_oder_Effektivzinsmethode_(ICMA-Methode,_früher_ISMA-Methode)) berechnet.
- Der erste und der letzte Tag werden gezählt.([§§ 187](https://www.gesetze-im-internet.de/bgb/__187.html), [188 BGB](https://www.gesetze-im-internet.de/bgb/__188.html)).
- Der Zinssatz wird anhand des aktuellen Basiszinssatzes von der Bundesbank berechnet.
- Die Berechnung ist nicht genau, wenn die Zinsenen über mehrere Jahre berechnet werden und eines der Jahre ein Schaltjahr ist.

### Mehr GrandTotal Plugins
Mehr Informationen zu Plugins gibt es hier: [GrandTotal-Plugins](https://github.com/mediaatelier/GrandTotal-Plugins). Und die Hilfe von [GrandTotal hier](https://www.mediaatelier.com/GrandTotal7/help/?lang=de).
Dieses Plugins basiert auf dem Area und Volume Plugin.

### Haftungsausschluss
Ich übernehme keine Haftung für die Richtigkeit und Vollständigkeit des Plugins und der bereitgestellten Informationen.
Haftungsansprüche gegen mich, die sich auf Schäden materieller oder ideeller Art beziehen, welche durch die Nutzung des Plugins entstanden sind, sind ausgeschlossen, sofern kein nachweislich vorsätzliches oder grob fahrlässiges Verschulden vorliegt.


# English: Calculate-Interest-GrandTotal Plugin
A plugin for GranTotal to calculate interest rate.

# Hot to install and use it?
## Hot to install and use it?
1. Dowload the [latest release](https://github.com/jajoho/Calculate-Interest-GrandTotal-Plugin/releases), unzip the file, and move <code>CalculateInterest.grandtotalplugin</code> to <code>~/Library/Application Support/com.mediaatelier.GrandTotal3/Plugins/</code>
2. Open GrandTotal, create a new document or add a line item to an existing document
3. Click on the wheeel icon and on <code>Calculate interest</code>
2. Open GrandTotal, create a new document or add a line item to an existing document.
3. Click on the wheeel icon and on <code>Calculate interest</code>.
4. Insert your values.

![Calculate Interest Rate](https://user-images.githubusercontent.com/15175599/152641465-27db9988-ff97-467b-8806-22ad7a6018de.png)

![Calculate Interest Screenshot](https://user-images.githubusercontent.com/15175599/151969970-22a6bd5a-a078-4f07-b708-4ec4791d8a5c.png)


## Calculation method
### Calculation method
- The interest rate is calculated using the effective interest method ([ICMA (ISMA)-Rule (act/act)](https://en.wikipedia.org/wiki/Day_count_convention#Actual_methods)).
- The first and the last day are counted ([§§ 187](https://www.gesetze-im-internet.de/bgb/__187.html), [188 BGB](https://www.gesetze-im-internet.de/bgb/__188.html)).
- The interest rate is calculated using the current prime rate from the Bundesbank.
- The calculation is not accurate if the interest is calculated over several years and one of the years is a leap year.

## Offical Plugin repository
### Offical Plugin repository
For more information see [GrandTotal-Plugins](https://github.com/mediaatelier/GrandTotal-Plugins) and the [GrandTotal help page](https://www.mediaatelier.com/GrandTotal7/help/?lang=en).
This plugin is based on the Area and Volume Plugin.

## Disclaimer
### Disclaimer
I assume no liability for the correctness and completeness of the plugin and the information provided.
Liability claims against me, which refer to damages of material or immaterial nature arising from the use of the plugin are excluded, unless a demonstrably intentional or grossly negligent fault.

0 comments on commit c1e1954

Please sign in to comment.