Use API getAccountBalance
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
const api = require('@actual-app/api');
|
const api = require('@actual-app/api');
|
||||||
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getLastTransactionDate, openBudget, showPercent } = require('./utils');
|
const { closeBudget, ensurePayee, getAccountNote, getLastTransactionDate, openBudget, showPercent } = require('./utils');
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -35,7 +35,7 @@ require("dotenv").config();
|
|||||||
if (!lastDate) continue;
|
if (!lastDate) continue;
|
||||||
const daysPassed = Math.floor((interestTransactionDate - new Date(lastDate)) / 86400000);
|
const daysPassed = Math.floor((interestTransactionDate - new Date(lastDate)) / 86400000);
|
||||||
|
|
||||||
const balance = await getAccountBalance(account, interestTransactionDate);
|
const balance = await api.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);
|
interestRate = showPercent(interestRate);
|
||||||
|
|||||||
@@ -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, getLastTransactionDate, getTagValue, openBudget, setAccountNote, sleep } = require('./utils');
|
const { closeBudget, ensurePayee, getAccountNote, getLastTransactionDate, getTagValue, openBudget, setAccountNote, sleep } = require('./utils');
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
async function getKBB(URL) {
|
async function getKBB(URL) {
|
||||||
@@ -52,7 +52,7 @@ async function getKBB(URL) {
|
|||||||
console.log('Fetching KBB for account:', account.name);
|
console.log('Fetching KBB for account:', account.name);
|
||||||
|
|
||||||
const kbb = await getKBB(URL);
|
const kbb = await getKBB(URL);
|
||||||
const balance = await getAccountBalance(account);
|
const balance = await api.getAccountBalance(account);
|
||||||
const diff = kbb - balance;
|
const diff = kbb - balance;
|
||||||
|
|
||||||
console.log('KBB:', kbb);
|
console.log('KBB:', kbb);
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
const { closeBudget, openBudget, getTransactions, getAccountNote, getAccountBalance, ensurePayee } = require('./utils');
|
const { closeBudget, openBudget, getTransactions, getAccountNote, ensurePayee } = require('./utils');
|
||||||
const api = require('@actual-app/api');
|
const api = require('@actual-app/api');
|
||||||
|
|
||||||
function getValueAtPath(obj, path) {
|
function getValueAtPath(obj, path) {
|
||||||
@@ -53,7 +53,7 @@ async function getBitcoinPrice() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const btc_amount = note.split('BTC:')[1].split(' ')[0];
|
const btc_amount = note.split('BTC:')[1].split(' ')[0];
|
||||||
const currentBalance = await getAccountBalance(account);
|
const currentBalance = await api.getAccountBalance(account);
|
||||||
const targetBalance = Math.round(bitcoinPrice * btc_amount * 100);
|
const targetBalance = Math.round(bitcoinPrice * btc_amount * 100);
|
||||||
const diff = currentBalance - targetBalance;
|
const diff = currentBalance - targetBalance;
|
||||||
if (diff != 0) {
|
if (diff != 0) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const api = require('@actual-app/api');
|
const api = require('@actual-app/api');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const readline = require('readline-sync');
|
const readline = require('readline-sync');
|
||||||
const { closeBudget, ensureCategory, ensureCategoryGroup, ensurePayee, getAccountBalance, getAccountNote, getSimpleFinID, getTransactions, openBudget } = require('./utils');
|
const { closeBudget, ensureCategory, ensureCategoryGroup, ensurePayee, getAccountNote, getSimpleFinID, getTransactions, openBudget } = require('./utils');
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ const zeroTransaction = async (payment) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (note.indexOf('calcInvestment') > -1) {
|
if (note.indexOf('calcInvestment') > -1) {
|
||||||
const currentBalance = await getAccountBalance(account);
|
const currentBalance = await api.getAccountBalance(account);
|
||||||
const simpleFinID = await getSimpleFinID(account);
|
const simpleFinID = await getSimpleFinID(account);
|
||||||
const simplefinBalance = parseInt(simplefinBalances[simpleFinID] * 100);
|
const simplefinBalance = parseInt(simplefinBalances[simpleFinID] * 100);
|
||||||
const diff = simplefinBalance - currentBalance;
|
const diff = simplefinBalance - currentBalance;
|
||||||
|
|||||||
@@ -41,19 +41,6 @@ const Utils = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getAccountBalance: async function (account, cutoffDate=new Date()) {
|
|
||||||
const data = await api.runQuery(
|
|
||||||
api.q('transactions')
|
|
||||||
.filter({
|
|
||||||
'account': account.id,
|
|
||||||
'date': { $lt: cutoffDate },
|
|
||||||
})
|
|
||||||
.calculate({ $sum: '$amount' })
|
|
||||||
.options({ splits: 'grouped' })
|
|
||||||
);
|
|
||||||
return data.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTransactions: async function (account) {
|
getTransactions: async function (account) {
|
||||||
const data = await api.runQuery(
|
const data = await api.runQuery(
|
||||||
api.q('transactions')
|
api.q('transactions')
|
||||||
|
|||||||
+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, showPercent, sleep } = require('./utils');
|
const { closeBudget, ensurePayee, getAccountNote, openBudget, showPercent, sleep } = require('./utils');
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
async function getZestimate(URL) {
|
async function getZestimate(URL) {
|
||||||
@@ -59,7 +59,7 @@ async function getZestimate(URL) {
|
|||||||
console.log('Was unable to get Zestimate, skipping');
|
console.log('Was unable to get Zestimate, skipping');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const balance = await getAccountBalance(account);
|
const balance = await api.getAccountBalance(account);
|
||||||
const diff = (zestimate * ownership) - balance;
|
const diff = (zestimate * ownership) - balance;
|
||||||
|
|
||||||
console.log('Zestimate:', zestimate);
|
console.log('Zestimate:', zestimate);
|
||||||
|
|||||||
Reference in New Issue
Block a user