getInvoiceById($invoice_id); if (!$inv) { http_response_code(404); exit('Invoice not found.'); } // ── Load company profile ────────────────────────────────────────────────── $sth = $pdo1->prepare( "SELECT company_name, company_name2, company_logo, address, address2, tax_id, phone, email, fax, branch, branch_no FROM company_list WHERE company_id = :company_id LIMIT 1" ); $sth->execute([':company_id' => $company_id]); $co = $sth->fetch(PDO::FETCH_ASSOC) ?: []; // ── Helpers ─────────────────────────────────────────────────────────────── function h(mixed $v): string { return htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8'); } function fmt(mixed $v, int $dp = 2): string { return number_format((float)$v, $dp); } function fmt_date(string $d): string { if (!$d) return '—'; $ts = strtotime($d); return $ts ? date('d/m/Y', $ts) : h($d); } $items = $inv['items'] ?? []; $logo_url = !empty($co['company_logo']) ? $server_url . 'uploads/company/' . $co['company_logo'] : ''; $doc_labels = [ 'invoice' => 'INVOICE', 'credit_note' => 'CREDIT NOTE', 'debit_note' => 'DEBIT NOTE', ]; $doc_label = $doc_labels[$inv['doc_type'] ?? 'invoice'] ?? 'INVOICE'; $status_labels = [ '0' => 'Draft', '1' => 'Issued', '2' => 'Paid', '3' => 'Overdue', '4' => 'Void', ]; $status_label = $status_labels[strval($inv['status'] ?? 0)] ?? ''; ?> <?= h($doc_label) ?> — <?= h($inv['invoice_number']) ?>
Logo
', array_map('h', $co_lines)); ?>
Issued
Due
Order
'status-draft', '1' => 'status-issued', '2' => 'status-paid', '3' => 'status-overdue', '4' => 'status-void', ]; $sc = $status_classes[strval($inv['status'] ?? 0)] ?? 'status-draft'; ?>
Bill To
Tax ID:
$item): ?>
# Product Qty Unit Price Amount
No items
Grand Total
Notes