| Server IP : 72.60.21.38 / Your IP : 216.73.217.140 Web Server : LiteSpeed System : Linux uk-fast-web1372.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64 User : u390967363 ( 390967363) PHP Version : 8.2.30 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/u390967363/domains/aibenproperties.com/public_html/app/ |
Upload File : |
<?php
if (session_status() === PHP_SESSION_NONE) { session_start(); }
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/functions.php';
global $pdo;
$uid = $_SESSION['user_id'] ?? null;
$role = $_SESSION['user_role'] ?? 'guest';
if (!$uid) { http_response_code(403); exit('Forbidden'); }
$companyId = function_exists('getCurrentCompanyId') ? getCurrentCompanyId() : ($_SESSION['company_id'] ?? null);
$isDownload = isset($_GET['download']) && $_GET['download'] === '1';
$receiptId = (int)($_GET['id'] ?? ($_GET['receipt_id'] ?? 0));
if ($receiptId <= 0) { http_response_code(400); exit('Invalid receipt id'); }
function colExistsLocal($table, $col) {
static $C=[]; global $pdo; $t=strtolower($table); $c=strtolower($col);
if (isset($C[$t])) return in_array($c, $C[$t], true);
try { $st=$pdo->query("SHOW COLUMNS FROM `$table`"); $cols=$st?$st->fetchAll(PDO::FETCH_COLUMN):[]; $cols=array_map('strtolower',$cols?:[]); $C[$t]=$cols; return in_array($c,$cols,true);} catch (Throwable $e){$C[$t]=[]; return false;}
}
$companyName = 'Aiben Group';
$companyHead = 'Plot 486, Wole Soyinka Street,<br/>2nd Ave, Gwarimpa Estate, Abuja';
$companyBranch = 'AIBEN HOUSE, Minangoloro Golf City,<br/>Beside NIPCO Filling Station, Karasana North, Abuja';
$companyContact = '+234 904 4444 4111';
$companyWebsite = 'www.aibenproperties.com';
$companyLogo = '';
$companySignature = '';
try {
$hasCompanies = $pdo->query("SHOW TABLES LIKE 'companies'")->rowCount() > 0;
if ($hasCompanies) {
$where = ''; $params = [];
if ($companyId) { $where = "WHERE id = ?"; $params[] = $companyId; } else { $where = "ORDER BY id DESC"; }
$stC = $pdo->prepare("SELECT * FROM companies ".$where." LIMIT 1");
$stC->execute($params);
$co = $stC->fetch(PDO::FETCH_ASSOC) ?: [];
if ($co) {
if (!empty($co['name'])) $companyName = (string)$co['name'];
if (!empty($co['head_office'])) $companyHead = nl2br(htmlspecialchars($co['head_office']));
if (!empty($co['branch_office'])) $companyBranch = nl2br(htmlspecialchars($co['branch_office']));
if (!empty($co['contact_numbers'])) $companyContact = htmlspecialchars($co['contact_numbers']);
if (!empty($co['website'])) $companyWebsite = htmlspecialchars($co['website']);
if (!empty($co['logo_path'])) $companyLogo = (string)$co['logo_path'];
if (!empty($co['signature_path'])) $companySignature = (string)$co['signature_path'];
}
}
} catch (Throwable $e) {}
$companyHead = 'Plot 486, Wole Soyinka Street,<br/>2nd Ave, Gwarimpa Estate, Abuja';
$companyBranch = 'AIBEN HOUSE, Maralago Golf City,<br/>Beside NIPCO Filling Station,<br/>Karsana North, Abuja';
$companyContact = '+234 904 4444 4411';
$companyWebsite = 'www.aibenproperties.com';
$companyContact = preg_replace('/\+234\s*908\s*111\s*1115\s*(<br\s*\/?>\s*)?/i', '', (string)$companyContact) ?? (string)$companyContact;
$companyContact = preg_replace('/(<br\s*\/?>\s*){2,}/i', '<br/>', (string)$companyContact) ?? (string)$companyContact;
$companyContact = trim((string)$companyContact);
$companyContact = preg_replace('/^(<br\s*\/?>\s*)+/i', '', (string)$companyContact) ?? (string)$companyContact;
$companyContact = preg_replace('/(<br\s*\/?>\s*)+$/i', '', (string)$companyContact) ?? (string)$companyContact;
$rcp = [];
try {
$hasR = $pdo->query("SHOW TABLES LIKE 'receipts'")->rowCount() > 0;
if (!$hasR) { http_response_code(404); exit('Receipts table not found'); }
$cmpClause = '';
$cmpParams = [];
if ($companyId && colExistsLocal('receipts','company_id')) { $cmpClause = " AND (r.company_id = ? OR r.company_id IS NULL)"; $cmpParams[] = $companyId; }
$sel = "r.*";
$joinU = "";
$selU = "";
if ($pdo->query("SHOW TABLES LIKE 'users'")->rowCount() > 0) {
$joinU = " LEFT JOIN users u ON u.id = r.user_id ";
$selU = ", " . (colExistsLocal('users','name') ? "u.name" : (colExistsLocal('users','username') ? "u.username" : "NULL")) . " AS client_name";
}
$joinD = "";
$selD = "";
$joinP = "";
$selP = "";
$joinI = "";
$selI = "";
if ($pdo->query("SHOW TABLES LIKE 'payments'")->rowCount() > 0) {
if (colExistsLocal('receipts','payment_id')) {
$joinP = " LEFT JOIN payments p ON p.id = r.payment_id ";
$selP = ", p.user_id AS p_user_id"
. (colExistsLocal('payments','deal_id') ? ", p.deal_id AS p_deal_id" : ", NULL AS p_deal_id")
. (colExistsLocal('payments','allocation_id') ? ", p.allocation_id AS p_allocation_id" : ", NULL AS p_allocation_id");
}
}
if ($pdo->query("SHOW TABLES LIKE 'invoices'")->rowCount() > 0) {
if (colExistsLocal('receipts','invoice_id')) {
$joinI = " LEFT JOIN invoices i ON i.id = r.invoice_id ";
$selI = (colExistsLocal('invoices','allocation_id') ? ", i.allocation_id AS i_allocation_id" : ", NULL AS i_allocation_id")
. (colExistsLocal('invoices','tenant_id') ? ", i.tenant_id AS i_user_id" : ", NULL AS i_user_id");
}
}
if ($pdo->query("SHOW TABLES LIKE 'deals_submit'")->rowCount() > 0) {
$joinD = " LEFT JOIN deals_submit d ON d.id = r.deal_id ";
$parts = [];
if (colExistsLocal('deals_submit','project_desc')) { $parts[] = "d.project_desc AS property"; }
if (colExistsLocal('deals_submit','project_name')) { $parts[] = "d.project_name AS project_name"; }
if (colExistsLocal('deals_submit','property_type')) { $parts[] = "d.property_type AS property_type"; }
if (colExistsLocal('deals_submit','plot_size')) { $parts[] = "d.plot_size AS plot_size"; }
if (colExistsLocal('deals_submit','estate_name')) { $parts[] = "d.estate_name AS estate_name"; }
$selD = $parts ? (", ".implode(", ", $parts)) : "";
}
$q = "SELECT $sel $selU $selP $selI $selD FROM receipts r $joinU $joinP $joinI $joinD WHERE r.id = ?" . $cmpClause . " LIMIT 1";
$st = $pdo->prepare($q);
$st->execute(array_merge([$receiptId], $cmpParams));
$rcp = $st->fetch(PDO::FETCH_ASSOC) ?: [];
} catch (Throwable $e) {}
if (!$rcp) { http_response_code(404); exit('Receipt not found'); }
$dealId = (int)($rcp['deal_id'] ?? 0);
$userId = (int)($rcp['user_id'] ?? 0);
$pUserId = (int)($rcp['p_user_id'] ?? 0);
$pDealId = (int)($rcp['p_deal_id'] ?? 0);
$pAllocId = (int)($rcp['p_allocation_id'] ?? 0);
$iAllocId = (int)($rcp['i_allocation_id'] ?? 0);
$iUserId = (int)($rcp['i_user_id'] ?? 0);
if ($userId <= 0 && $pUserId > 0) $userId = $pUserId;
if ($userId <= 0 && $iUserId > 0) $userId = $iUserId;
if ($dealId <= 0 && $pDealId > 0) $dealId = $pDealId;
$amount = (float)($rcp['amount_paid'] ?? ($rcp['amount'] ?? 0));
$method = (string)($rcp['payment_method'] ?? '');
$receiptNo = (string)($rcp['receipt_number'] ?? ($rcp['receipt_no'] ?? ('RCPT-'.(int)$receiptId)));
$createdAt = (string)($rcp['created_at'] ?? date('Y-m-d H:i:s'));
$clientName = (string)($rcp['client_name'] ?? '');
$property = (string)($rcp['property'] ?? '');
$projectName = (string)($rcp['project_name'] ?? '');
$propertyType = (string)($rcp['property_type'] ?? '');
$plotSize = (string)($rcp['plot_size'] ?? ($rcp['size'] ?? ($rcp['land_size'] ?? ($rcp['square_meters'] ?? ($rcp['sqm'] ?? '')))));
$estateName = (string)($rcp['estate_name'] ?? '');
try {
if ($clientName === '' && $userId > 0 && $pdo->query("SHOW TABLES LIKE 'users'")->rowCount() > 0) {
$fields = [];
if (colExistsLocal('users','name')) $fields[] = 'name';
if (colExistsLocal('users','first_name')) $fields[] = 'first_name';
if (colExistsLocal('users','last_name')) $fields[] = 'last_name';
if (empty($fields)) {
$col = colExistsLocal('users','username') ? 'username' : 'NULL AS username';
$stU = $pdo->prepare("SELECT {$col} FROM users WHERE id = ? LIMIT 1");
$stU->execute([$userId]);
$clientName = (string)($stU->fetchColumn() ?: '');
} else {
$selCols = implode(',', array_unique($fields));
$stU = $pdo->prepare("SELECT {$selCols} FROM users WHERE id = ? LIMIT 1");
$stU->execute([$userId]);
$rowU = $stU->fetch(PDO::FETCH_ASSOC) ?: [];
$nm = '';
if (isset($rowU['name']) && trim((string)$rowU['name']) !== '') { $nm = (string)$rowU['name']; }
elseif (isset($rowU['first_name']) || isset($rowU['last_name'])) {
$fn = isset($rowU['first_name']) ? trim((string)$rowU['first_name']) : '';
$ln = isset($rowU['last_name']) ? trim((string)$rowU['last_name']) : '';
$nm = trim($fn . ' ' . $ln);
}
if ($nm === '' && colExistsLocal('users','username')) {
$stU2 = $pdo->prepare("SELECT username FROM users WHERE id = ? LIMIT 1");
$stU2->execute([$userId]); $nm = (string)($stU2->fetchColumn() ?: '');
}
$clientName = (string)$nm;
}
}
} catch (Throwable $e) {}
try {
if ($property === '' && $dealId > 0) {
if ($pdo->query("SHOW TABLES LIKE 'deals_submit'")->rowCount() > 0) {
$sel = "project_desc";
if (!colExistsLocal('deals_submit','project_desc')) { $sel = colExistsLocal('deals_submit','project_name') ? "project_name" : (colExistsLocal('deals_submit','estate_name') ? "estate_name" : "NULL"); }
$stD = $pdo->prepare("SELECT {$sel}, " . (colExistsLocal('deals_submit','meta_json') ? "meta_json" : "NULL AS meta_json") . " FROM deals_submit WHERE id = ? LIMIT 1");
$stD->execute([$dealId]);
$dr = $stD->fetch(PDO::FETCH_ASSOC) ?: [];
$property = (string)($dr[$sel] ?? '');
if ($property === '' && isset($dr['meta_json']) && is_string($dr['meta_json']) && $dr['meta_json'] !== '') {
$m = json_decode($dr['meta_json'], true);
if (is_array($m)) {
$keys = ['project_desc','project_name','property','estate_name','property_estate','project','property_title','property_name','project_title','Project Name'];
foreach ($keys as $k) { if (!empty($m[$k])) { $property = (string)$m[$k]; break; } }
}
}
}
if ($property === '' && $pdo->query("SHOW TABLES LIKE 'deals'")->rowCount() > 0) {
$selCol = "project_desc";
try { $selCol = colExistsLocal('deals','project_desc') ? "project_desc" : (colExistsLocal('deals','project_name') ? "project_name" : "title"); } catch (Throwable $e2) {}
$stDz = $pdo->prepare("SELECT {$selCol} FROM deals WHERE id = ? LIMIT 1"); $stDz->execute([$dealId]);
$property = (string)($stDz->fetchColumn() ?: $property);
}
}
if ($property === '' && ($pAllocId > 0 || $iAllocId > 0) && $pdo->query("SHOW TABLES LIKE 'allocations'")->rowCount() > 0) {
$q = "SELECT pr.title FROM allocations a LEFT JOIN properties pr ON a.property_id = pr.id WHERE a.id = ? LIMIT 1";
$aid = $pAllocId > 0 ? $pAllocId : $iAllocId;
$stA = $pdo->prepare($q); $stA->execute([$aid]);
$property = (string)($stA->fetchColumn() ?: $property);
}
if ($property === '' && $userId > 0 && $pdo->query("SHOW TABLES LIKE 'deals_submit'")->rowCount() > 0 && colExistsLocal('deals_submit','user_id')) {
$sel = "project_desc";
if (!colExistsLocal('deals_submit','project_desc')) { $sel = colExistsLocal('deals_submit','project_name') ? "project_name" : (colExistsLocal('deals_submit','estate_name') ? "estate_name" : "NULL"); }
$stDU = $pdo->prepare("SELECT {$sel}, " . (colExistsLocal('deals_submit','meta_json') ? "meta_json" : "NULL AS meta_json") . " FROM deals_submit WHERE user_id = ? ORDER BY id DESC LIMIT 1");
$stDU->execute([$userId]);
$drU = $stDU->fetch(PDO::FETCH_ASSOC) ?: [];
$property = (string)($drU[$sel] ?? $property);
if ($property === '' && isset($drU['meta_json']) && is_string($drU['meta_json']) && $drU['meta_json'] !== '') {
$m = json_decode($drU['meta_json'], true);
if (is_array($m)) {
$keys = ['project_desc','project_name','property','estate_name','property_estate','project','property_title','property_name','project_title','Project Name'];
foreach ($keys as $k) { if (!empty($m[$k])) { $property = (string)$m[$k]; break; } }
}
}
}
} catch (Throwable $e) {}
$propertyFinal = $property !== '' ? $property : ($projectName !== '' ? $projectName : '');
if ($propertyFinal === '' && $estateName !== '') { $propertyFinal = $estateName; }
$amountOffered = 0.0;
$totalPaid = 0.0;
try {
if ($dealId > 0) {
if ($pdo->query("SHOW TABLES LIKE 'deals_submit'")->rowCount() > 0 && colExistsLocal('deals_submit','amount_offered')) {
$stAO = $pdo->prepare("SELECT amount_offered FROM deals_submit WHERE id = ? LIMIT 1");
$stAO->execute([$dealId]); $amountOffered = (float)($stAO->fetchColumn() ?: 0);
}
if ($pdo->query("SHOW TABLES LIKE 'payments'")->rowCount() > 0 && colExistsLocal('payments','deal_id')) {
$cmpPaid = ''; $cmpParams2 = [];
if ($companyId && colExistsLocal('payments','company_id')) { $cmpPaid = " AND (company_id = ? OR company_id IS NULL)"; $cmpParams2[] = $companyId; }
$stP = $pdo->prepare("SELECT COALESCE(SUM(amount),0) FROM payments WHERE deal_id = ? AND status = 'approved'".$cmpPaid);
$stP->execute(array_merge([$dealId], $cmpParams2)); $totalPaid = (float)($stP->fetchColumn() ?: 0);
}
}
} catch (Throwable $e) {}
$balanceAfter = max(0.0, $amountOffered - $totalPaid);
$amountWords = '';
function numToWordsSmall($n) {
$ones = ['','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'];
$tens = ['','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'];
if ($n < 20) return $ones[$n];
if ($n < 100) return $tens[intval($n/10)] . (($n%10)?'-'.$ones[$n%10]:'');
if ($n < 1000) return $ones[intval($n/100)].' hundred'.(($n%100)?' '.numToWordsSmall($n%100):'');
return '';
}
function numToWords($num) {
$num = (int)$num;
if ($num === 0) return 'zero';
$units = ['',' thousand',' million',' billion',' trillion'];
$words = '';
$i = 0;
while ($num > 0 && $i < count($units)) {
$chunk = $num % 1000;
if ($chunk) {
$chunkWords = '';
if ($chunk < 1000) $chunkWords = numToWordsSmall($chunk);
$words = trim($chunkWords . $units[$i] . ' ' . $words);
}
$num = intdiv($num, 1000);
$i++;
}
return trim($words);
}
function nairaInWords($amount) {
$naira = floor($amount);
$kobo = round(($amount - $naira) * 100);
$w = ucfirst(numToWords($naira)) . ' naira';
if ($kobo > 0) $w .= ' ' . numToWords($kobo) . ' kobo';
return $w;
}
$amountWords = nairaInWords($amount);
$brandOverrideUrl = 'https://aibenproperties.com/wp-content/uploads/2024/09/Aiben-Group-Logo.png';
$logo = '';
if ($brandOverrideUrl !== '') {
$logoTag = '<img src="'.$brandOverrideUrl.'" style="height:60px;" />';
} else {
$logoCandidates = [
$companyLogo ? (is_file($companyLogo) ? $companyLogo : (__DIR__ . '/' . ltrim($companyLogo,'/\\'))) : '',
__DIR__ . '/assets/logo.png',
__DIR__ . '/assets/img/logo.png',
__DIR__ . '/assets/images/logo.png',
__DIR__ . '/images/logo.png'
];
foreach ($logoCandidates as $p) { if ($p && is_file($p)) { $logo = $p; break; } }
$logoTag = $logo !== '' ? '<img src="file://' . str_replace('\\','/',$logo) . '" style="height:60px;" />' : '<div style="font-weight:700;font-size:18px">'.htmlspecialchars($companyName).'</div>';
}
$sigTag = '';
if ($companySignature) {
$sigPath = is_file($companySignature) ? $companySignature : (__DIR__ . '/' . ltrim($companySignature,'/\\'));
if (is_file($sigPath)) { $sigTag = '<img src="file://' . str_replace('\\','/',$sigPath) . '" style="height:50px;" />'; }
}
$baseTitle = $propertyFinal !== '' ? $propertyFinal : ($projectName !== '' ? $projectName : '');
$compound = $baseTitle;
if ($plotSize !== '' && $baseTitle !== '') { $compound = trim($plotSize).' of '.$baseTitle; }
$lineDesc = $compound !== '' ? (($balanceAfter > 0) ? 'Installment Payment for '.$compound : 'Payment for '.$compound) : (($balanceAfter > 0) ? 'Installment Property Payment' : 'Property Payment');
if ($isDownload) {
require_once __DIR__ . '/vendor/autoload.php';
$options = new \Dompdf\Options();
$options->set('isRemoteEnabled', true);
$dompdf = new \Dompdf\Dompdf($options);
$txnDate = $createdAt !== "" ? date("F d, Y", strtotime($createdAt)) : "-";
$currencyPrefix = 'NGN ';
$html = '
<html><head><meta charset="utf-8" />
<style>
body{font-family:DejaVu Sans,Arial,Helvetica,sans-serif;background:#ffffff;color:#0f172a;font-size:12px;margin:0}
.card{max-width:900px;margin:24px auto;background:#fff;border:1px solid #e5e7eb;border-radius:10px;box-shadow:0 2px 8px rgba(0,0,0,0.06);overflow:hidden}
.toolbar{display:flex;gap:8px;justify-content:flex-end;padding:12px 16px;border-bottom:1px solid #eef2f7}
.btn{padding:8px 12px;border-radius:6px;text-decoration:none;font-size:12px;border:1px solid #0d6efd;color:#0d6efd}
.btn.primary{background:#0d6efd;color:#fff;border-color:#0d6efd}
.header{display:flex;align-items:flex-start;justify-content:space-between;padding:16px 20px}
.brand{display:flex;gap:8px;flex-direction:column}
.brand .meta{font-size:11px;color:#334155;line-height:1.4}
.titlebox{text-align:right}
.title{font-weight:800;font-size:18px;letter-spacing:.5px;color:#0f172a}
.recno{font-size:12px;color:#0f172a;margin-top:4px}
.divider{height:2px;background:#0b2447;margin:0 0 12px}
.section{padding:0 20px 16px}
.row{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.badge{background:#0b3d91;color:#fff;padding:6px 10px;border-radius:6px;font-size:11px;margin-bottom:6px}
table{width:100%;border-collapse:collapse}
th,td{border:1px solid #e5e7eb;padding:10px;text-align:left}
th{background:#0b3d91;color:#fff;font-weight:700}
tfoot td{border:none}
.totals{width:100%;margin-top:8px}
.totals td{padding:6px 0}
.totals .label{text-align:right;color:#334155}
.totals .value{text-align:right;font-weight:600}
.verify{display:flex;justify-content:space-between;align-items:center;margin-top:16px;padding-top:12px;border-top:1px solid #e5e7eb}
.vbadge{display:inline-block;border:1px solid #059669;color:#059669;padding:4px 10px;border-radius:9999px;font-size:11px;font-weight:700}
.footer{display:flex;gap:24px;font-size:11px;color:#334155;margin-top:16px}
.footer .col{flex:1}
.footer .col .hd{font-weight:700;margin-bottom:6px;color:#0f172a}
</style></head><body>
<div class="card">
<div class="toolbar"></div>
<div class="header">
<div class="brand">
<div>'.$logoTag.'</div>
<div class="meta">'.$companyHead.'<br/>'.$companyContact.'<br/>'.$companyWebsite.'</div>
</div>
<div class="titlebox">
<div class="title">RECEIPT</div>
<div class="recno">Receipt No: '.$receiptNo.'</div>
</div>
</div>
<div class="divider"></div>
<div class="section">
<div class="row">
<div><div style="font-size:11px;color:#64748b">RECIPIENT</div><div style="font-weight:700;color:#0f172a">'.htmlspecialchars($clientName !== "" ? $clientName : "Client").'</div></div>
<div><span class="badge">Receipt for #'.$receiptNo.'</span><div style="text-align:right;font-size:11px;color:#64748b;margin-top:4px">Transaction Date: '.$txnDate.'</div></div>
</div>
<table>
<thead><tr><th>PRODUCT / SERVICE</th><th>DESCRIPTION</th><th style="width:80px">QTY.</th><th style="width:120px">COST</th><th style="width:140px">TOTAL</th></tr></thead>
<tbody>
<tr><td>Payment</td><td>'.htmlspecialchars($lineDesc).'</td><td>1</td><td>'.$currencyPrefix.number_format($amount,2).'</td><td>'.$currencyPrefix.number_format($amount,2).'</td></tr>
<tr><td colspan="5" style="border:none;padding-top:12px;color:#334155">Thanks for your business!</td></tr>
</tbody>
</table>
<table class="totals">
<tr><td class="label" colspan="4">Subtotal</td><td class="value">'.$currencyPrefix.number_format($amount,2).'</td></tr>
<tr><td class="label" colspan="4">Tax</td><td class="value">'.$currencyPrefix.'0.00</td></tr>
<tr><td class="label" colspan="4" style="font-size:14px">Total</td><td class="value" style="font-size:14px">'.$currencyPrefix.number_format($amount,2).'</td></tr>
</table>
<div class="footer">
<div class="col"><div class="hd">Head Office</div><div>'.$companyHead.'</div></div>
<div class="col"><div class="hd">Branch Office</div><div>'.$companyBranch.'</div></div>
<div class="col"><div class="hd">Contact</div><div>'.$companyContact.'<br/>'.$companyWebsite.'</div></div>
</div>
</div>
</div>
</body></html>';
$dompdf->loadHtml($html, 'UTF-8');
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream('Receipt_'.$receiptNo.'.pdf', ['Attachment' => true]);
exit;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Receipt <?= htmlspecialchars($receiptNo) ?></title>
<style>
body{font-family:DejaVu Sans,Arial,Helvetica,sans-serif;background:#f3f4f6;color:#0f172a;font-size:12px;margin:0}
.card{max-width:900px;margin:24px auto;background:#fff;border:1px solid #e5e7eb;border-radius:10px;box-shadow:0 10px 30px rgba(0,0,0,0.08);overflow:hidden}
.toolbar{position:sticky;top:0;z-index:10;display:flex;gap:8px;justify-content:flex-end;padding:12px 16px;background:#fff;border-bottom:1px solid #eef2f7}
.btn{display:inline-block;padding:8px 12px;border-radius:6px;text-decoration:none;font-size:12px;border:1px solid #0d6efd;color:#0d6efd;background:#fff}
.btn.primary{background:#0d6efd;color:#fff;border-color:#0d6efd}
.header{display:flex;align-items:flex-start;justify-content:space-between;padding:16px 20px}
.brand{display:flex;gap:8px;flex-direction:column}
.brand .meta{font-size:11px;color:#334155;line-height:1.4}
.titlebox{text-align:right}
.title{font-weight:800;font-size:18px;letter-spacing:.5px;color:#0f172a}
.recno{font-size:12px;color:#0f172a;margin-top:4px}
.divider{height:2px;background:#0b2447;margin:0 0 12px}
.section{padding:0 20px 16px}
.row{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.badge{background:#0b3d91;color:#fff;padding:6px 10px;border-radius:8px;font-size:11px;margin-bottom:6px}
table{width:100%;border-collapse:collapse}
th,td{border:1px solid #e5e7eb;padding:10px;text-align:left}
th{background:#0b3d91;color:#fff;font-weight:700}
tfoot td{border:none}
.totals{width:100%;margin-top:8px}
.totals td{padding:6px 0}
.totals .label{text-align:right;color:#334155}
.totals .value{text-align:right;font-weight:600}
.verify{display:flex;justify-content:space-between;align-items:center;margin-top:16px;padding-top:12px;border-top:1px solid #e5e7eb}
.vbadge{display:inline-block;border:1px solid #059669;color:#059669;padding:4px 10px;border-radius:9999px;font-size:11px;font-weight:700}
.footer{display:flex;gap:24px;font-size:11px;color:#334155;margin-top:16px}
.footer .col{flex:1}
.footer .col .hd{font-weight:700;margin-bottom:6px;color:#0f172a}
</style>
</head>
<body>
<div class="card">
<div class="toolbar">
<a class="btn" href="javascript:window.print()">Print Receipt</a>
<a class="btn primary" href="receipt_view.php?id=<?= (int)$receiptId ?>&download=1">Download PDF</a>
</div>
<div class="header">
<div class="brand">
<div><?= $logoTag ?></div>
<div class="meta"><?= $companyHead ?><br/><?= $companyContact ?><br/><?= $companyWebsite ?></div>
</div>
<div class="titlebox">
<div class="title">RECEIPT</div>
<div class="recno">Receipt No: <?= htmlspecialchars($receiptNo) ?></div>
</div>
</div>
<div class="divider"></div>
<div class="section">
<div class="row">
<div>
<div style="font-size:11px;color:#64748b">RECIPIENT</div>
<div style="font-weight:700;color:#0f172a"><?= htmlspecialchars($clientName !== '' ? $clientName : 'Client') ?></div>
</div>
<div>
<span class="badge">Receipt for #<?= htmlspecialchars($receiptNo) ?></span>
<div style="text-align:right;font-size:11px;color:#64748b;margin-top:4px">Transaction Date: <?= htmlspecialchars($createdAt !== '' ? date('F d, Y', strtotime($createdAt)) : '-') ?></div>
</div>
</div>
<table>
<thead>
<tr><th>PRODUCT / SERVICE</th><th>DESCRIPTION</th><th style="width:80px">QTY.</th><th style="width:120px">COST</th><th style="width:140px">TOTAL</th></tr>
</thead>
<tbody>
<tr><td>Payment</td><td><?= htmlspecialchars($lineDesc) ?></td><td>1</td><td>₦<?= number_format($amount,2) ?></td><td>₦<?= number_format($amount,2) ?></td></tr>
<tr><td colspan="5" style="border:none;padding-top:12px;color:#334155">Thanks for your business!</td></tr>
</tbody>
</table>
<table class="totals">
<tr><td class="label" colspan="4">Subtotal</td><td class="value">₦<?= number_format($amount,2) ?></td></tr>
<tr><td class="label" colspan="4">Tax</td><td class="value">₦0.00</td></tr>
<tr><td class="label" colspan="4" style="font-size:14px">Total</td><td class="value" style="font-size:14px">₦<?= number_format($amount,2) ?></td></tr>
</table>
<div class="footer">
<div class="col">
<div class="hd">Head Office</div>
<div><?= $companyHead ?></div>
</div>
<div class="col">
<div class="hd">Branch Office</div>
<div><?= $companyBranch ?></div>
</div>
<div class="col">
<div class="hd">Contact</div>
<div><?= $companyContact ?><br/><?= $companyWebsite ?></div>
</div>
</div>
</div>
</div>
</body>
</html>