403Webshell
Server IP : 72.60.21.38  /  Your IP : 216.73.216.25
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/u390967363/domains/aibenproperties.com/public_html/app/invoice_view.php
<?php
session_start();
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/functions.php';
$userId = $_SESSION['user_id'] ?? null;
$userRole = $_SESSION['user_role'] ?? null;
if (!$userId || !in_array($userRole, ['admin','super_admin','finance','estate_manager'])) { header('Location: dashboard.php'); exit; }
$companyId = function_exists('getCurrentCompanyId') ? getCurrentCompanyId() : null;
function generateInvoiceNumber($id){ return 'AIB-INV-' . str_pad((string)max(0,(int)$id), 4, '0', STR_PAD_LEFT); }
$invId = (int)($_GET['invoice_id'] ?? ($_GET['id'] ?? 0));
if ($invId <= 0) { http_response_code(400); echo 'Invalid invoice id'; exit; }
$inv = [];
try {
    $hasInv = $pdo->query("SHOW TABLES LIKE 'invoices'")->rowCount() > 0;
    if (!$hasInv) { http_response_code(404); echo 'Invoices table not found'; exit; }
    $cmpClause = ''; $cmpParams = [];
    if ($companyId && function_exists('tableHasColumn') && tableHasColumn('invoices','company_id')) { $cmpClause = " AND company_id = ?"; $cmpParams[] = $companyId; }
    $st = $pdo->prepare("SELECT * FROM invoices WHERE id = ?" . $cmpClause . " LIMIT 1");
    $st->execute(array_merge([$invId], $cmpParams));
    $inv = $st->fetch(PDO::FETCH_ASSOC) ?: [];
} catch (Throwable $e) {}
if (!$inv) { http_response_code(404); echo 'Invoice not found'; exit; }
$totalAmount = (float)($inv['amount'] ?? ($inv['total'] ?? 0));
$dueDate = (string)($inv['due_date'] ?? ($inv['created_at'] ?? ''));
$status = (string)($inv['status'] ?? 'unpaid');
$tenantId = (int)($inv['tenant_id'] ?? ($inv['user_id'] ?? 0));
$dealId = (int)($inv['deal_id'] ?? 0);
$clientName = '';
$propertyDesc = '';
$amountPaid = 0.0;
$_ds_amount_offered = 0.0;
try {
    $hasDS = $pdo->query("SHOW TABLES LIKE 'deals_submit'")->rowCount() > 0;
    if ($hasDS) {
        $where = ''; $params = [];
        if ($dealId > 0 && function_exists('tableHasColumn') && tableHasColumn('deals_submit','id') && function_exists('tableHasColumn') && tableHasColumn('invoices','deal_id')) {
            $where = "id = ?"; $params[] = $dealId;
        } elseif ($tenantId > 0) {
            if (function_exists('tableHasColumn') && tableHasColumn('deals_submit','user_id')) { $where = "user_id = ?"; $params[] = $tenantId; }
            elseif (function_exists('tableHasColumn') && tableHasColumn('deals_submit','client_id')) { $where = "client_id = ?"; $params[] = $tenantId; }
        }
        if ($where !== '') {
            $cols = "client_name, project_desc, project_name, property_title, property_name"
                . (function_exists('tableHasColumn') && tableHasColumn('deals_submit','amount_offered') ? ", amount_offered" : "")
                . (function_exists('tableHasColumn') && tableHasColumn('deals_submit','meta_json') ? ", meta_json" : "");
            $q = "SELECT $cols FROM deals_submit WHERE $where ORDER BY id DESC LIMIT 1";
            $st = $pdo->prepare($q); $st->execute($params);
            $ds = $st->fetch(PDO::FETCH_ASSOC) ?: [];
            if ($ds) {
                $clientName = (string)($ds['client_name'] ?? '');
                $propertyDesc = (string)($ds['project_desc'] ?? ($ds['project_name'] ?? ($ds['property_title'] ?? ($ds['property_name'] ?? ''))));
                if (isset($ds['amount_offered'])) { $_ds_amount_offered = (float)$ds['amount_offered']; }
                if (($clientName === '' || $propertyDesc === '') && isset($ds['meta_json']) && $ds['meta_json']) {
                    $mj = json_decode($ds['meta_json'], true) ?: [];
                    if ($clientName === '') { $clientName = (string)($mj['client_name'] ?? ''); }
                    if ($propertyDesc === '') { $propertyDesc = (string)($mj['project_name'] ?? ($mj['project'] ?? ($mj['property'] ?? ''))); }
                    if ($_ds_amount_offered <= 0 && isset($mj['amount_offered'])) { $_ds_amount_offered = (float)$mj['amount_offered']; }
                }
            }
        }
    }
} catch (Throwable $e) {}
if ($_ds_amount_offered > 0) { $totalAmount = $_ds_amount_offered; }
try {
    if ($dealId > 0 && $pdo) {
        $cmpClauseP = ''; $cmpParamsP = [];
        if ($companyId && function_exists('tableHasColumn') && tableHasColumn('payments','company_id')) { $cmpClauseP = " AND company_id = ?"; $cmpParamsP[] = $companyId; }
        $sp = $pdo->prepare("SELECT COALESCE(SUM(amount),0) FROM payments WHERE deal_id = ? AND status = 'approved'" . $cmpClauseP);
        $sp->execute(array_merge([$dealId], $cmpParamsP));
        $amountPaid = (float)($sp->fetchColumn() ?: 0);
    } elseif ($tenantId > 0) {
        if ($pdo && function_exists('tableHasColumn') && tableHasColumn('payments','user_id')) {
            $cmpClauseP2 = ''; $cmpParamsP2 = [];
            if ($companyId && function_exists('tableHasColumn') && tableHasColumn('payments','company_id')) { $cmpClauseP2 = " AND company_id = ?"; $cmpParamsP2[] = $companyId; }
            $sp2 = $pdo->prepare("SELECT COALESCE(SUM(amount),0) FROM payments WHERE user_id = ? AND status = 'approved'" . $cmpClauseP2);
            $sp2->execute(array_merge([$tenantId], $cmpParamsP2));
            $amountPaid = (float)($sp2->fetchColumn() ?: 0);
        }
    }
} catch (Throwable $e) {}
if ($clientName === '' && $tenantId > 0) {
    try {
        $st = $pdo->prepare("SELECT " . (function_exists('tableHasColumn') && tableHasColumn('users','name') ? "name" : "username") . " FROM users WHERE id = ? LIMIT 1");
        $st->execute([$tenantId]); $clientName = (string)($st->fetchColumn() ?: '');
    } catch (Throwable $e) {}
}
if ($propertyDesc === '' && isset($inv['lease_id'])) {
    try {
        $leaseId = (int)$inv['lease_id'];
        if ($leaseId > 0) {
            $q = "SELECT p.title FROM leases l JOIN properties p ON l.property_id = p.id WHERE l.id = ? LIMIT 1";
            $st = $pdo->prepare($q); $st->execute([$leaseId]); $propertyDesc = (string)($st->fetchColumn() ?: '');
        }
    } catch (Throwable $e) {}
}
$uid = (int)($inv['user_id'] ?? ($inv['tenant_id'] ?? 0));
$in = $pdo->prepare("SELECT meta_json FROM deals_submit WHERE user_id = ? ORDER BY id DESC LIMIT 1");
$in->execute([$uid]);
$fullInv = $in->fetch(PDO::FETCH_ASSOC) ?: [];
$metaInv = json_decode($fullInv['meta_json'] ?? '', true) ?: [];
$totalAmountD = $metaInv['amount_offered'] ?? 0;
$amountPaidD = $metaInv['amount_paid_so_far'] ?? 0;
$balanceD = ($metaInv['amount_offered'] - $metaInv['amount_paid_so_far']) ?? 0;

$invoiceNumber = generateInvoiceNumber($invId);
include __DIR__ . '/includes/header.php';
?>
<style>
    .ap-invoice{max-width:1200px;margin:40px auto;background:#fff;padding:64px;border:1px solid #e5e7eb;border-radius:10px;font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;color:#111827;position:relative;overflow:hidden}
    .ap-row{display:flex;justify-content:space-between;align-items:center;gap:15px}
    .ap-toolbar.no-print{display:flex;justify-content:flex-end;gap:8px;max-width:1200px;margin:0 auto 14px}
    .ap-left{display:flex;align-items:center;gap:12px}
    .ap-logo{max-height:60px;width:auto;height:auto;object-fit:contain}
    .ap-brand{font-weight:800;font-size:18px;letter-spacing:.3px}
    .ap-title{text-align:right}
    .ap-title .ap-h{font-size:32px;font-weight:900;letter-spacing:1px}
    .ap-title .ap-meta{color:#6b7280;font-size:14px;margin-top:6px;line-height:1.4}
    .ap-sep{height:1px;background:#e5e7eb;margin:18px 0}
    .ap-section{margin:16px 0}
    .ap-label{color:#6b7280;text-transform:uppercase;font-size:12px;letter-spacing:.5px;margin-bottom:8px}
    .ap-value{font-size:18px;font-weight:700}
    .ap-card-row{display:flex;justify-content:space-between;gap:15px;margin-top:8px}
    .ap-card{flex:1;border:none;border-top:1px solid #e5e7eb;padding:14px;text-align:left}
    .ap-card .ap-k{color:#6b7280;font-size:12px;text-transform:uppercase;letter-spacing:.5px;margin-bottom:6px}
    .ap-card .ap-v{font-size:28px;font-weight:900}
    .ap-table{width:100%;border-collapse:collapse;border-spacing:0;border:none}
    .ap-table th,.ap-table td{padding:16px;border-bottom:1px solid #e5e7eb}
    .ap-table th{background:#fff;text-align:left;font-weight:600;text-transform:uppercase;font-size:13px;color:#1f2937;border-bottom:1px solid #e5e7eb}
    .ap-badge{display:inline-block;font-weight:700;font-size:12px;letter-spacing:.4px;border-radius:20px;padding:6px 12px;border:1px solid}
    .ap-badge.paid{color:#16a34a;background:#ecfdf5;border-color:#bbf7d0}
    .ap-badge.unpaid{color:#854d0e;background:#fefce8;border-color:#fde68a}
    .ap-badge.partial{color:#1d4ed8;background:#eff6ff;border-color:#bfdbfe}
    .ap-sign{margin-top:60px}
    .ap-sign-line{height:1px;background:#e5e7eb;margin-bottom:10px}
    .ap-sign-row{display:flex;justify-content:space-between;align-items:flex-end;gap:20px}
    .ap-center{text-align:center;color:#6b7280;margin-top:50px;font-size:12px}
    .no-print{display:block}
    .ap-invoice::before{content:"";position:absolute;left:0;right:0;bottom:0;top:260px;background:url('https://aibenproperties.com/wp-content/uploads/2024/09/Aiben-Group-Logo.png') no-repeat center 60%;background-size:50% auto;opacity:.08;filter:blur(2px);pointer-events:none;z-index:0}
    .ap-invoice>*{position:relative;z-index:1}
    @media print{
        body * { visibility: hidden; }
        .ap-invoice, .ap-invoice * { visibility: visible; }
        body{background:#fff}
        .no-print{display:none!important}
        .ap-invoice{border:none;box-shadow:none;margin:0;padding:40px;background:#fff!important}
        .ap-invoice::before{
            display:none!important;
            content:none!important;
            background:none!important;
            background-image:none!important;
            opacity:0!important;
            filter:none!important
        }
        header, nav, .navbar, .site-header, .topbar, .main-header, .app-header{display:none!important;visibility:hidden!important}
        header img, nav img, .navbar img, .site-header img, .topbar img, .main-header img, .app-header img{display:none!important;visibility:hidden!important}
        img{display:none!important}
        .ap-invoice img{display:inline-block!important}
        .ap-footer-rows{flex-wrap:nowrap!important;gap:16px!important}
        .ap-footer-rows>div{flex:1 1 0!important;min-width:0!important}
    }
</style>
<div class="ap-toolbar no-print">
    <button type="button" class="btn btn-primary btn-sm" onclick="window.print()">Print</button>
    <a href="invoice_html.php?invoice_id=<?= $invId ?>" class="btn btn-outline-secondary btn-sm">Download HTML</a>
    <a href="invoice_csv.php?invoice_id=<?= $invId ?>" class="btn btn-outline-secondary btn-sm">Download CSV</a>
</div>
<div class="ap-invoice">
    <div class="ap-row">
        <div class="ap-left">
            <img class="ap-logo" src="https://aibenproperties.com/wp-content/uploads/2024/09/Aiben-Group-Logo.png" alt="Aiben Logo" onerror="this.style.display='none'">
        </div>
        <div class="ap-title">
            <div class="ap-h">INVOICE</div>
            <div class="ap-meta">
                <div>Invoice No: <?= htmlspecialchars($invoiceNumber) ?></div>
                <div>Issue Date: <?= isset($inv['created_at']) && $inv['created_at'] ? htmlspecialchars(date('j M Y', strtotime($inv['created_at']))) : '—' ?></div>
                <div>Due Date: <?= $dueDate !== '' ? htmlspecialchars(date('j M Y', strtotime($dueDate))) : '—' ?></div>
            </div>
        </div>
    </div>
    <div class="ap-sep"></div>
    <div class="ap-section" style="margin-top:20px">
        <div class="ap-label">Bill To</div>
        <div class="ap-value" style="font-size:20px"><?= htmlspecialchars($clientName !== '' ? $clientName : '-') ?></div>
        <div style="margin-top:6px;color:#6b7280"><?= htmlspecialchars($propertyDesc !== '' ? $propertyDesc : '-') ?></div>
        <?php if (!empty($inv['client_email'] ?? '')): ?><div style="color:#6b7280;margin-top:4px"><?= htmlspecialchars($inv['client_email']) ?></div><?php endif; ?>
        <?php if (!empty($inv['client_phone'] ?? '')): ?><div style="color:#6b7280"><?= htmlspecialchars($inv['client_phone']) ?></div><?php endif; ?>
    </div>
    <div class="ap-sep"></div>
    <div class="ap-section">
        <div class="ap-card-row">
            <div class="ap-card">
                <div class="ap-k">Total Amount</div>
                <div class="ap-v">₦<?= number_format($totalAmountD,2) ?></div>
            </div>
            <div class="ap-card">
                <div class="ap-k">Amount Paid</div>
                <div class="ap-v">₦<?= number_format($amountPaidD,2) ?></div>
            </div>
            <div class="ap-card">
                <div class="ap-k">Balance</div>
                <div class="ap-v">₦<?= number_format($balanceD,2) ?></div>
            </div>
        </div>
        
    </div>
    <div class="ap-section">
        <table class="ap-table">
            <thead>
                <tr><th>Description</th><th style="width:200px;text-align:right">Amount</th></tr>
            </thead>
            <tbody>
                <tr>
                    <td>Property Payment<?= $propertyDesc !== '' ? ' — ' . htmlspecialchars($propertyDesc) : '' ?></td>
                    <td style="text-align:right">₦<?= number_format($totalAmount,2) ?></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="ap-section" style="text-align:right">
        <?php
            $s = strtolower((string)$status);
            $cls = 'unpaid'; $txt = 'UNPAID';
            if ($s === 'paid') { $cls = 'paid'; $txt = 'PAID'; }
            elseif ($s === 'part_paid' || $s === 'partial') { $cls = 'partial'; $txt = 'PARTIAL'; }
        ?>
        <span class="ap-badge <?= $cls ?>"><?= $txt ?></span>
    </div>
    <div class="ap-sep"></div>
    <div class="ap-sign">
        <div class="ap-sign-row">
            <div class="ap-sign-col">
                <div class="ap-sign-line"></div>
                <div class="ap-label" style="margin-top:6px">Authorized Signature</div>
            </div>
            <div class="ap-sign-col" style="text-align:right">
                <div class="ap-label">For: Aiben Properties Ltd</div>
            </div>
        </div>
    </div>
    <div class="ap-section" style="margin-top:50px">
        <div class="ap-footer-rows" style="display:flex;justify-content:space-between;flex-wrap:wrap;gap:20px;color:#6b7280;font-size:12px;line-height:1.6">
            <div style="flex:1;min-width:220px;text-align:left">
                <div style="font-weight:600;color:#dc2626">Head Office</div>
                <div>Plot 486, Wole Soyinka Street,</div>
                <div>2nd Ave, Gwarimpa Estate, Abuja</div>
            </div>
            <div style="flex:1;min-width:220px;text-align:center">
                <div style="font-weight:600;color:#dc2626">Branch Office</div>
                <div>AIBEN HOUSE, Maralago Golf City,</div>
                <div>Beside NIPCO Filling Station,</div>
                <div>Karsana North, Abuja</div>
            </div>
            <div style="flex:1;min-width:220px;text-align:right">
                <div style="font-weight:600;color:#dc2626">Contact</div>
                <div>+234 904 4444 4411</div>
                <div>+234 908 111 1115</div>
                <div>www.aibenproperties.com</div>
            </div>
        </div>
    </div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>

Youez - 2016 - github.com/yon3zu
LinuXploit