diff --git a/backend/src/modules/journal-entries/journal-entries.service.ts b/backend/src/modules/journal-entries/journal-entries.service.ts index a206adb..4f67d5c 100644 --- a/backend/src/modules/journal-entries/journal-entries.service.ts +++ b/backend/src/modules/journal-entries/journal-entries.service.ts @@ -140,11 +140,11 @@ export class JournalEntriesService { ); } - const result = await this.tenant.query( - `UPDATE journal_entries SET is_posted = true, posted_by = $1, posted_at = NOW() WHERE id = $2 RETURNING *`, + await this.tenant.query( + `UPDATE journal_entries SET is_posted = true, posted_by = $1, posted_at = NOW() WHERE id = $2`, [userId, id], ); - return this.findOne(result[0].id); + return this.findOne(id); } async void(id: string, userId: string, reason: string) { diff --git a/backend/src/modules/monthly-actuals/monthly-actuals.service.ts b/backend/src/modules/monthly-actuals/monthly-actuals.service.ts index 3d7f716..7179444 100644 --- a/backend/src/modules/monthly-actuals/monthly-actuals.service.ts +++ b/backend/src/modules/monthly-actuals/monthly-actuals.service.ts @@ -127,25 +127,28 @@ export class MonthlyActualsService { for (const line of filteredLines) { const acctType = accountTypeMap.get(line.accountId); if (!acctType) continue; + const abs = Math.abs(line.amount); if (acctType === 'expense') { - // Expense: debit expense account, credit cash - jeLines.push({ - accountId: line.accountId, - debit: Math.abs(line.amount), - credit: 0, - memo: `${monthLabel} actual`, - }); - totalCashCredit += Math.abs(line.amount); + if (line.amount > 0) { + // Normal expense: debit expense, credit cash + jeLines.push({ accountId: line.accountId, debit: abs, credit: 0, memo: `${monthLabel} actual` }); + totalCashCredit += abs; + } else { + // Negative expense (refund/correction): credit expense, debit cash + jeLines.push({ accountId: line.accountId, debit: 0, credit: abs, memo: `${monthLabel} actual (correction)` }); + totalCashDebit += abs; + } } else if (acctType === 'income') { - // Income: credit income account, debit cash - jeLines.push({ - accountId: line.accountId, - debit: 0, - credit: Math.abs(line.amount), - memo: `${monthLabel} actual`, - }); - totalCashDebit += Math.abs(line.amount); + if (line.amount > 0) { + // Normal income: credit income, debit cash + jeLines.push({ accountId: line.accountId, debit: 0, credit: abs, memo: `${monthLabel} actual` }); + totalCashDebit += abs; + } else { + // Negative income (correction): debit income, credit cash + jeLines.push({ accountId: line.accountId, debit: abs, credit: 0, memo: `${monthLabel} actual (correction)` }); + totalCashCredit += abs; + } } } diff --git a/frontend/src/pages/monthly-actuals/MonthlyActualsPage.tsx b/frontend/src/pages/monthly-actuals/MonthlyActualsPage.tsx index 6fa7f7f..615578e 100644 --- a/frontend/src/pages/monthly-actuals/MonthlyActualsPage.tsx +++ b/frontend/src/pages/monthly-actuals/MonthlyActualsPage.tsx @@ -203,7 +203,7 @@ export function MonthlyActualsPage() { size="xs" hideControls decimalScale={2} - min={0} + allowNegative styles={{ input: { textAlign: 'right', fontFamily: 'monospace' } }} />