format percents better
This commit is contained in:
+6
-4
@@ -1,5 +1,5 @@
|
|||||||
const api = require('@actual-app/api');
|
const api = require('@actual-app/api');
|
||||||
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getLastTransactionDate, openBudget } = require('./utils');
|
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getLastTransactionDate, openBudget, showPercent } = require('./utils');
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -17,7 +17,7 @@ require("dotenv").config();
|
|||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
if (note.indexOf('interestRate:') > -1 && note.indexOf('interestDay:') > -1) {
|
if (note.indexOf('interestRate:') > -1 && note.indexOf('interestDay:') > -1) {
|
||||||
const interestRate = parseFloat(note.split('interestRate:')[1].split(' ')[0]);
|
let interestRate = parseFloat(note.split('interestRate:')[1].split(' ')[0]);
|
||||||
const interestDay = parseInt(note.split('interestDay:')[1].split(' ')[0]);
|
const interestDay = parseInt(note.split('interestDay:')[1].split(' ')[0]);
|
||||||
|
|
||||||
const interestTransactionDate = new Date();
|
const interestTransactionDate = new Date();
|
||||||
@@ -38,11 +38,13 @@ require("dotenv").config();
|
|||||||
const balance = await getAccountBalance(account, interestTransactionDate);
|
const balance = await getAccountBalance(account, interestTransactionDate);
|
||||||
const compoundedInterest = Math.round(balance * (Math.pow(1 + interestRate / 12, 1) - 1));
|
const compoundedInterest = Math.round(balance * (Math.pow(1 + interestRate / 12, 1) - 1));
|
||||||
|
|
||||||
|
interestRate = showPercent(interestRate);
|
||||||
|
|
||||||
console.log(`== ${account.name} ==`);
|
console.log(`== ${account.name} ==`);
|
||||||
console.log(` -> Balance: ${balance}`);
|
console.log(` -> Balance: ${balance}`);
|
||||||
console.log(` as of ${lastDate}`);
|
console.log(` as of ${lastDate}`);
|
||||||
console.log(` -> # days: ${daysPassed}`);
|
console.log(` -> # days: ${daysPassed}`);
|
||||||
console.log(` -> Interest: ${compoundedInterest}`)
|
console.log(` -> Interest: ${compoundedInterest} (${interestRate})`)
|
||||||
|
|
||||||
if (compoundedInterest) {
|
if (compoundedInterest) {
|
||||||
await api.importTransactions(account.id, [{
|
await api.importTransactions(account.id, [{
|
||||||
@@ -50,7 +52,7 @@ require("dotenv").config();
|
|||||||
payee: payeeId,
|
payee: payeeId,
|
||||||
amount: compoundedInterest,
|
amount: compoundedInterest,
|
||||||
cleared: true,
|
cleared: true,
|
||||||
notes: `Interest for 1 month at ${100*interestRate}%`,
|
notes: `Interest for 1 month at ${interestRate}`,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,4 +137,9 @@ module.exports = {
|
|||||||
setTimeout(resolve, ms);
|
setTimeout(resolve, ms);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showPercent: function (pct) {
|
||||||
|
return Number(pct).toLocaleString(undefined,
|
||||||
|
{ style: 'percent', maximumFractionDigits: 2 })
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
const api = require('@actual-app/api');
|
const api = require('@actual-app/api');
|
||||||
const jsdom = require("jsdom");
|
const jsdom = require("jsdom");
|
||||||
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, openBudget, sleep } = require('./utils');
|
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, openBudget, showPercent, sleep } = require('./utils');
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
async function getZestimate(URL) {
|
async function getZestimate(URL) {
|
||||||
@@ -56,7 +56,7 @@ async function getZestimate(URL) {
|
|||||||
amount: diff,
|
amount: diff,
|
||||||
cleared: true,
|
cleared: true,
|
||||||
reconciled: true,
|
reconciled: true,
|
||||||
notes: `Update Zestimate to ${zestimate * ownership / 100} (${zestimate / 100}*${ownership * 100}%)`,
|
notes: `Update Zestimate to ${zestimate * ownership / 100} (${zestimate / 100}*${showPercent(ownership)})`,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user