Add investments to All tab, withdrawal on create, modal fixes, and login logo
- Show investment subtable under All accounts tab (was only under Operating/Reserve) - Add "Withdraw from primary account" switch (on by default) when creating investments; creates a journal entry to credit the primary asset account and debit the equity offset, keeping the books balanced - Prevent all account modals from closing on outside click to avoid data loss - Replace login page text title with the SVG logo Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -47,7 +47,57 @@ export class InvestmentsService {
|
||||
dto.fund_type || 'reserve', dto.principal, dto.interest_rate || 0,
|
||||
dto.maturity_date || null, dto.purchase_date || null, dto.current_value || dto.principal, dto.notes],
|
||||
);
|
||||
return rows[0];
|
||||
const investment = rows[0];
|
||||
|
||||
// If withdraw_from_primary is true, create a journal entry to debit the primary account
|
||||
if (dto.withdraw_from_primary && dto.principal > 0) {
|
||||
const fundType = dto.fund_type || 'reserve';
|
||||
const primaryRows = await this.tenant.query(
|
||||
`SELECT id, name FROM accounts WHERE is_primary = true AND fund_type = $1 AND is_active = true LIMIT 1`,
|
||||
[fundType],
|
||||
);
|
||||
if (primaryRows.length) {
|
||||
const primaryAccount = primaryRows[0];
|
||||
const equityAccountNumber = fundType === 'reserve' ? 3100 : 3000;
|
||||
const equityRows = await this.tenant.query(
|
||||
'SELECT id FROM accounts WHERE account_number = $1',
|
||||
[equityAccountNumber],
|
||||
);
|
||||
if (equityRows.length) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = now.getMonth() + 1;
|
||||
const periods = await this.tenant.query(
|
||||
'SELECT id FROM fiscal_periods WHERE year = $1 AND month = $2',
|
||||
[year, month],
|
||||
);
|
||||
if (periods.length) {
|
||||
const memo = `Transfer to investment: ${dto.name}`;
|
||||
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 (CURRENT_DATE, $1, 'transfer', $2, true, NOW(), '00000000-0000-0000-0000-000000000000')
|
||||
RETURNING *`,
|
||||
[memo, periods[0].id],
|
||||
);
|
||||
const je = jeRows[0];
|
||||
// Credit the primary asset account (reduces cash)
|
||||
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, primaryAccount.id, dto.principal, memo],
|
||||
);
|
||||
// Debit the equity offset account (reduces fund 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, equityRows[0].id, dto.principal, memo],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return investment;
|
||||
}
|
||||
|
||||
async update(id: string, dto: any) {
|
||||
|
||||
Reference in New Issue
Block a user