feat: added remaining after budget
This commit is contained in:
29
get-remaining.js
Normal file
29
get-remaining.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { format } from 'date-fns';
|
||||
import chalk from 'chalk';
|
||||
|
||||
import * as actual from './lib/actual.js';
|
||||
import { formatAmount, formatSchedule } from './lib/format.js';
|
||||
import { checkEnv } from './lib/env.js';
|
||||
|
||||
checkEnv([
|
||||
'ACCOUNT_ID',
|
||||
]);
|
||||
|
||||
const month = format(new Date(), 'yyyy-MM');
|
||||
|
||||
const balance = await actual.getAccountBalance(process.env.ACCOUNT_ID);
|
||||
const budget = await actual.getBudgetMonth(month);
|
||||
|
||||
const remaining = balance - budget.totalBalance;
|
||||
|
||||
console.log();
|
||||
console.log(`Balance: ${formatAmount(balance)}`);
|
||||
// TODO: what if no income yet
|
||||
console.log(`Budget balance for ${month}: ${chalk.red(formatAmount(budget.totalBalance))}`);
|
||||
console.log(`Remaining: ${chalk.blue(formatAmount(remaining))}`);
|
||||
console.log();
|
||||
|
||||
console.log(`Based on income for ${month}: you've got ${chalk.bgBlue((remaining / budget.totalBudgeted).toFixed(2))} times your budget left, even after spending everything`);
|
||||
console.log();
|
||||
|
||||
await actual.shutdown();
|
||||
Reference in New Issue
Block a user