feat: investment chart alignment, auto-renew records, fund transfers, capital planning report, and upcoming activities (v2026.3.24)
- Lock InvestmentTimeline and ProjectionChart to shared X axis range - Auto-create renewal scenario_investments records when auto_renew is true - Add fund transfer mechanism between asset accounts with journal entries - Add Capital Planning Report (5-year forecast grouped by category) - Add Upcoming Investment Activities dashboard card (maturities + planned purchases) - Bump version to 2026.3.24 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -360,6 +360,62 @@ export class AccountsService {
|
||||
return journalEntry;
|
||||
}
|
||||
|
||||
async transferFunds(dto: {
|
||||
fromAccountId: string;
|
||||
toAccountId: string;
|
||||
amount: number;
|
||||
transferDate: string;
|
||||
memo?: string;
|
||||
}) {
|
||||
if (dto.amount <= 0) throw new BadRequestException('Transfer amount must be positive');
|
||||
if (dto.fromAccountId === dto.toAccountId) throw new BadRequestException('Cannot transfer to the same account');
|
||||
|
||||
const fromAccount = await this.findOne(dto.fromAccountId);
|
||||
const toAccount = await this.findOne(dto.toAccountId);
|
||||
|
||||
if (fromAccount.account_type !== 'asset') throw new BadRequestException('Source account must be an asset account');
|
||||
if (toAccount.account_type !== 'asset') throw new BadRequestException('Destination account must be an asset account');
|
||||
|
||||
// Find fiscal period
|
||||
const asOf = new Date(dto.transferDate);
|
||||
const year = asOf.getFullYear();
|
||||
const month = asOf.getMonth() + 1;
|
||||
const periods = await this.tenant.query(
|
||||
'SELECT id FROM fiscal_periods WHERE year = $1 AND month = $2',
|
||||
[year, month],
|
||||
);
|
||||
if (!periods.length) {
|
||||
throw new BadRequestException(`No fiscal period found for ${year}-${String(month).padStart(2, '0')}`);
|
||||
}
|
||||
|
||||
const memo = dto.memo || `Transfer from ${fromAccount.name} to ${toAccount.name}`;
|
||||
|
||||
// Create journal entry: debit destination (increase), credit source (decrease)
|
||||
const jeRows = await this.tenant.query(
|
||||
`INSERT INTO journal_entries (entry_date, description, entry_type, fiscal_period_id, is_posted, posted_at, created_by)
|
||||
VALUES ($1, $2, 'transfer', $3, true, NOW(), $4)
|
||||
RETURNING *`,
|
||||
[dto.transferDate, memo, periods[0].id, '00000000-0000-0000-0000-000000000000'],
|
||||
);
|
||||
const je = jeRows[0];
|
||||
|
||||
// Credit source account (reduces asset balance)
|
||||
await this.tenant.query(
|
||||
`INSERT INTO journal_entry_lines (journal_entry_id, account_id, debit, credit, memo)
|
||||
VALUES ($1, $2, 0, $3, $4)`,
|
||||
[je.id, dto.fromAccountId, dto.amount, memo],
|
||||
);
|
||||
|
||||
// Debit destination account (increases asset balance)
|
||||
await this.tenant.query(
|
||||
`INSERT INTO journal_entry_lines (journal_entry_id, account_id, debit, credit, memo)
|
||||
VALUES ($1, $2, $3, 0, $4)`,
|
||||
[je.id, dto.toAccountId, dto.amount, memo],
|
||||
);
|
||||
|
||||
return je;
|
||||
}
|
||||
|
||||
async getTrialBalance(asOfDate?: string) {
|
||||
const dateFilter = asOfDate
|
||||
? `AND je.entry_date <= $1`
|
||||
|
||||
Reference in New Issue
Block a user