diff --git a/static/js/index.js b/static/js/index.js index 4daad64..d954432 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1419,7 +1419,9 @@ window.app = Vue.createApp({ }, getTotalAmount(entry) { if (!entry.lines || entry.lines.length === 0) return 0 - return entry.lines.reduce((sum, line) => sum + line.debit + line.credit, 0) / 2 + // Beancount-style: use absolute value of amounts + // All lines have amounts (positive or negative), we want the transaction size + return entry.lines.reduce((sum, line) => sum + Math.abs(line.amount || 0), 0) / 2 }, getEntryFiatAmount(entry) { // Extract fiat amount from metadata if available @@ -1434,12 +1436,13 @@ window.app = Vue.createApp({ }, isReceivable(entry) { // Check if this is a receivable entry (user owes castle) - // Receivables have a debit to an "Accounts Receivable" account with the user's ID + // Receivables have a positive amount (debit) to an "Accounts Receivable" account if (!entry.lines || entry.lines.length === 0) return false for (const line of entry.lines) { - // Look for a line with positive debit on an accounts receivable account - if (line.debit > 0) { + // Look for a line with positive amount on an accounts receivable account + // Beancount-style: positive amount = debit (asset increase) + if (line.amount > 0) { // Check if the account is associated with this user's receivables const account = this.accounts.find(a => a.id === line.account_id) if (account && account.name && account.name.includes('Assets:Receivable') && account.account_type === 'asset') { @@ -1451,12 +1454,13 @@ window.app = Vue.createApp({ }, isPayable(entry) { // Check if this is a payable entry (castle owes user) - // Payables have a credit to an "Accounts Payable" account with the user's ID + // Payables have a negative amount (credit) to an "Accounts Payable" account if (!entry.lines || entry.lines.length === 0) return false for (const line of entry.lines) { - // Look for a line with positive credit on an accounts payable account - if (line.credit > 0) { + // Look for a line with negative amount on an accounts payable account + // Beancount-style: negative amount = credit (liability increase) + if (line.amount < 0) { // Check if the account is associated with this user's payables const account = this.accounts.find(a => a.id === line.account_id) if (account && account.name && account.name.includes('Liabilities:Payable') && account.account_type === 'liability') {