30 lines
951 B
JavaScript
30 lines
951 B
JavaScript
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();
|