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)] ?? ''; ?>
| # | Product | Qty | Unit Price | Amount |
|---|---|---|---|---|
| = $i + 1 ?> |
= h($item['product_name'] ?? $item['product_sku'] ?? '') ?>
= h($item['product_sku']) ?>
|
= h(fmt($item['quantity'] ?? 0)) ?> | = h(fmt($item['price'] ?? 0)) ?> | = h(fmt($item['total_price'] ?? 0)) ?> |
| No items | ||||
| = h($label) ?> | = h(fmt($val)) ?> |
| Grand Total | = h(fmt($inv['grand_total'] ?? 0)) ?> |