@baruchiro/actual-mcp
Version:
Actual Budget MCP server exposing API functionality
29 lines (28 loc) • 1.44 kB
JavaScript
// Generates the markdown report for balance-history tool
import { formatAmount } from "../../utils.js";
export class BalanceHistoryReportGenerator {
generate(account, period, sortedMonths) {
let markdown = `# Account Balance History\n\n`;
markdown += `Account: ${account.name}\n`;
markdown += `Period: ${period.start} to ${period.end}\n\n`;
// Add balance history table
markdown += `| Month | End of Month Balance | Monthly Change | Transactions |\n`;
markdown += `| ----- | -------------------- | -------------- | ------------ |\n`;
let previousBalance = null;
sortedMonths.forEach((month) => {
const monthName = new Date(month.year, month.month - 1, 1).toLocaleString("default", { month: "long" });
const balance = formatAmount(month.balance);
let change = "";
let changeAmount = 0;
if (previousBalance !== null) {
changeAmount = month.balance - previousBalance;
const changeFormatted = formatAmount(changeAmount);
const direction = changeAmount > 0 ? "↑" : changeAmount < 0 ? "↓" : "";
change = `${direction} ${changeFormatted}`;
}
previousBalance = month.balance;
markdown += `| ${monthName} ${month.year} | ${balance} | ${change} | ${month.transactions} |\n`;
});
return markdown;
}
}