businessId.':'.$this->sourceType.':'.$this->sourceId; } public function isBalanced(float $tolerance = 0.01): bool { $debit = 0.0; $credit = 0.0; foreach ($this->lines as $line) { if (($line['type'] ?? '') === 'debit') { $debit += (float) ($line['amount'] ?? 0); } if (($line['type'] ?? '') === 'credit') { $credit += (float) ($line['amount'] ?? 0); } } return abs($debit - $credit) <= $tolerance; } }