// lib/accounting/core/open-balance-engine.ts

import { JournalEntry } from './journal-types';

export function recalculateOpenBalance(journals: JournalEntry[]): number {
  // Example: sum all debits - credits for AP accounts, including reversals/FX
  let balance = 0;
  for (const entry of journals) {
    for (const line of entry.lines) {
      if (line.accountCode.startsWith('2110')) {
        balance += (line.debit - line.credit);
      }
    }
  }
  return balance;
}
