pdo->prepare( "SELECT i.*, COALESCE(c.contact_name, '') AS contact_name FROM td_invoice i LEFT JOIN md_contact c ON c.company_id = i.company_id AND c.id = i.contact_id WHERE i.company_id = :cid AND i.id = :id AND i.doc_type = 'supplier_credit_note' LIMIT 1" ); $sth->execute([':cid' => $this->companyId, ':id' => $id]); $doc = $sth->fetch(PDO::FETCH_ASSOC); if (!$doc) throw new Exception("Supplier credit note #{$id} not found."); return $doc; } protected function getAmounts(array $doc): array { $grand_total = abs((float)$doc['grand_total']); $tax = abs((float)$doc['tax']); return [ 'grand_total' => $grand_total, 'tax' => $tax, 'total' => $grand_total - $tax, 'amount' => $grand_total, ]; } protected function getDocDate(array $doc): string { return $doc['issued_date'] ?? date('Y-m-d'); } }