403Webshell
Server IP : 72.60.21.38  /  Your IP : 216.73.217.154
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/ledger.php
<?php
// Temporary compatibility shim: Redirect all ledger views to the unified client_ledger.php
$__did = isset($_GET['deal_id']) ? (int)$_GET['deal_id'] : 0;
if (!headers_sent()) {
    header("Location: client_ledger.php?deal_id=" . $__did);
    exit;
}
require_once __DIR__ . '/includes/db.php';
$deal_id = (int)($_GET['deal_id'] ?? 0);
if ($deal_id <= 0) { http_response_code(400); echo 'Invalid deal'; exit; }
$userIdForDeal = 0;
$colExists = function($table, $col) use ($pdo) {
    try { $stmt = $pdo->query("SHOW COLUMNS FROM `$table`"); $cols = $stmt ? $stmt->fetchAll(PDO::FETCH_COLUMN) : []; $cols = array_map('strtolower', $cols ?: []); return in_array(strtolower($col), $cols, true); } catch (Throwable $e) { return false; }
};
$deal = [];
try {
    $st = $pdo->prepare("SELECT client_name, project_desc, amount_offered, user_id FROM deals_submit WHERE id = ? LIMIT 1");
    $st->execute([$deal_id]);
    $deal = $st->fetch(PDO::FETCH_ASSOC) ?: [];
} catch (Throwable $e) {}
$clientName = '';
$projectDesc = '';
$amountOffered = 0.0;
if (!$deal) {
    try {
        $st2 = $pdo->prepare("SELECT user_id, project_desc, amount_offered FROM deals WHERE id = ? LIMIT 1");
        $st2->execute([$deal_id]);
        $d2 = $st2->fetch(PDO::FETCH_ASSOC) ?: [];
        if ($d2) {
            $projectDesc = (string)($d2['project_desc'] ?? '');
            $amountOffered = isset($d2['amount_offered']) && is_numeric($d2['amount_offered']) ? (float)$d2['amount_offered'] : 0.0;
            $userIdForDeal = (int)($d2['user_id'] ?? 0);
            if ($userIdForDeal > 0) {
                try {
                    $sn = $pdo->prepare("SELECT name FROM users WHERE id = ? LIMIT 1");
                    $sn->execute([$userIdForDeal]);
                    $clientName = (string)($sn->fetchColumn() ?: '');
                } catch (Throwable $e3) {}
            }
        } else {
            $projectDesc = 'Deal #'.$deal_id;
            try {
                $pp = $pdo->prepare("SELECT user_id FROM payments WHERE deal_id = ? ORDER BY id DESC LIMIT 1");
                $pp->execute([$deal_id]);
                $userIdForDeal = (int)($pp->fetchColumn() ?: 0);
                if ($userIdForDeal > 0) {
                    try {
                        $sn = $pdo->prepare("SELECT name FROM users WHERE id = ? LIMIT 1");
                        $sn->execute([$userIdForDeal]);
                        $clientName = (string)($sn->fetchColumn() ?: '');
                    } catch (Throwable $e3) {}
                }
            } catch (Throwable $e4) {}
        }
    } catch (Throwable $e2) {
        $projectDesc = 'Deal #'.$deal_id;
        try {
            $pp = $pdo->prepare("SELECT user_id FROM payments WHERE deal_id = ? ORDER BY id DESC LIMIT 1");
            $pp->execute([$deal_id]);
            $userIdForDeal = (int)($pp->fetchColumn() ?: 0);
            if ($userIdForDeal > 0) {
                try {
                    $sn = $pdo->prepare("SELECT name FROM users WHERE id = ? LIMIT 1");
                    $sn->execute([$userIdForDeal]);
                    $clientName = (string)($sn->fetchColumn() ?: '');
                } catch (Throwable $e3) {}
            }
        } catch (Throwable $e4) {}
    }
} else {
    $clientName = (string)($deal['client_name'] ?? '');
    $projectDesc = (string)($deal['project_desc'] ?? '');
    $amountOffered = isset($deal['amount_offered']) && is_numeric($deal['amount_offered']) ? (float)$deal['amount_offered'] : 0.0;
    $userIdForDeal = (int)($deal['user_id'] ?? 0);
    if ($clientName === '' && $userIdForDeal > 0) {
        try {
            $sn = $pdo->prepare("SELECT name FROM users WHERE id = ? LIMIT 1");
            $sn->execute([$userIdForDeal]);
            $clientName = (string)($sn->fetchColumn() ?: '');
        } catch (Throwable $e3) {}
    }
}
$payments = [];
try {
    $ps = $pdo->prepare("SELECT amount, created_at FROM payments WHERE deal_id = ? AND (LOWER(status) = 'approved') ORDER BY created_at ASC");
    $ps->execute([$deal_id]);
    $payments = $ps->fetchAll(PDO::FETCH_ASSOC) ?: [];
} catch (Throwable $e) {}
$tryInvoices = false;
try { $tryInvoices = ($pdo->query("SHOW TABLES LIKE 'invoices'")->rowCount() > 0); } catch (Throwable $e0) {}
$invoiceIdList = [];
if ($tryInvoices) {
    $selTotal = $colExists('invoices','total_amount') ? 'total_amount' : ($colExists('invoices','amount') ? 'amount' : null);
    $hasDealCol = $colExists('invoices','deal_id');
    $hasTenantCol = $colExists('invoices','tenant_id');
    if ($hasDealCol) {
        try {
            $cols = [];
            $cols[] = 'id';
            if ($selTotal) $cols[] = $selTotal . ' AS total_amount';
            if ($hasTenantCol) $cols[] = 'tenant_id';
            $sqlInv = "SELECT " . implode(',', $cols) . " FROM invoices WHERE deal_id = ?";
            $stInv = $pdo->prepare($sqlInv);
            $stInv->execute([$deal_id]);
            $rowsInv = $stInv->fetchAll(PDO::FETCH_ASSOC) ?: [];
            if (!empty($rowsInv)) {
                $sumInv = 0.0;
                foreach ($rowsInv as $iv) {
                    $invoiceIdList[] = (int)$iv['id'];
                    if (isset($iv['total_amount']) && is_numeric($iv['total_amount'])) {
                        $sumInv += (float)$iv['total_amount'];
                    }
                    if ($userIdForDeal <= 0 && isset($iv['tenant_id'])) {
                        $tid = (int)$iv['tenant_id'];
                        if ($tid > 0) $userIdForDeal = $tid;
                    }
                }
                if ($amountOffered <= 0 && $sumInv > 0) { $amountOffered = $sumInv; }
            }
        } catch (Throwable $eInv) {}
    }
}
if ($userIdForDeal > 0 && $clientName === '') {
    try {
        $sn = $pdo->prepare("SELECT name FROM users WHERE id = ? LIMIT 1");
        $sn->execute([$userIdForDeal]);
        $clientName = (string)($sn->fetchColumn() ?: $clientName);
    } catch (Throwable $eNm) {}
}
$balance = $amountOffered;
$rows = [];
if ($amountOffered > 0) {
    $rows[] = [
        'date' => '',
        'desc' => 'Property Purchase',
        'debit' => $amountOffered,
        'credit' => 0.0,
        'balance' => $balance
    ];
}
$totalPaid = 0.0;
foreach ($payments as $p) {
    $amt = isset($p['amount']) && is_numeric($p['amount']) ? (float)$p['amount'] : 0.0;
    $dt = (string)($p['created_at'] ?? '');
    $totalPaid += $amt;
    $balance -= $amt;
    $rows[] = [
        'date' => $dt,
        'desc' => 'Payment',
        'debit' => 0.0,
        'credit' => $amt,
        'balance' => $balance
    ];
}
if (empty($payments) && !empty($invoiceIdList) && $colExists('payments','invoice_id')) {
    try {
        // Fetch approved payments tied to the deal's invoices
        $place = implode(',', array_fill(0, count($invoiceIdList), '?'));
        $sql = "SELECT amount, created_at FROM payments WHERE invoice_id IN ($place) AND (LOWER(status) = 'approved') ORDER BY created_at ASC";
        $sp = $pdo->prepare($sql);
        $sp->execute($invoiceIdList);
        $p2 = $sp->fetchAll(PDO::FETCH_ASSOC) ?: [];
        foreach ($p2 as $p) {
            $amt = isset($p['amount']) && is_numeric($p['amount']) ? (float)$p['amount'] : 0.0;
            $dt = (string)($p['created_at'] ?? '');
            $totalPaid += $amt;
            $balance -= $amt;
            $rows[] = [
                'date' => $dt,
                'desc' => 'Payment',
                'debit' => 0.0,
                'credit' => $amt,
                'balance' => $balance
            ];
        }
    } catch (Throwable $eJoin) {}
}
?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Client Ledger</title>
    <style>
        :root { --card-bg:#ffffff; --text:#1f2937; --muted:#6b7280; --border:#e5e7eb; --accent:#111827; --pill:#0ea5e9; }
        *{box-sizing:border-box}
        body{margin:0;padding:24px;background:#f7f8fa;color:var(--text);font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif}
        .wrap{max-width:980px;margin:0 auto}
        .card{background:var(--card-bg);border:1px solid var(--border);border-radius:16px;box-shadow:0 10px 30px rgba(0,0,0,.06);overflow:hidden}
        .card-header{display:flex;align-items:center;justify-content:space-between;padding:20px 24px;border-bottom:1px solid var(--border)}
        .title{margin:0;font-size:20px;font-weight:700;letter-spacing:.2px}
        .btn{appearance:none;border:1px solid var(--border);background:#fff;color:#111827;padding:8px 12px;border-radius:10px;cursor:pointer;font-weight:600}
        .btn:hover{background:#f3f4f6}
        .summary{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:14px;padding:16px 24px;border-bottom:1px solid var(--border)}
        .summary .item{background:#fafafa;border:1px solid var(--border);border-radius:12px;padding:12px}
        .summary .label{font-size:12px;color:var(--muted);margin-bottom:6px}
        .summary .value{font-size:16px;font-weight:700;color:var(--accent)}
        .table{width:100%;border-collapse:collapse}
        .table th,.table td{padding:12px 14px;border-bottom:1px solid var(--border);text-align:left}
        .table thead th{background:#fbfbfb;font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.6px}
        .text-end{text-align:right}
        .pill{display:inline-block;background:#e6f6fe;color:#0369a1;border:1px solid #bae6fd;padding:2px 8px;border-radius:999px;font-size:12px}
        .meta{display:flex;align-items:center;gap:10px}
        @media (max-width:720px){.summary{grid-template-columns:1fr 1fr}.card-header{flex-direction:column;gap:12px;align-items:flex-start}}
        @media print {
            body{background:#fff;padding:0}
            .btn{display:none}
            .card{border:0;box-shadow:none}
        }
    </style>
</head>
<body>
    <div class="wrap">
        <div class="card">
            <div class="card-header">
                <h1 class="title">Client Ledger</h1>
                <button class="btn" onclick="window.print()">Print Ledger</button>
            </div>
            <div class="summary">
                <div class="item">
                    <div class="label">Client Name</div>
                    <div class="value"><?= htmlspecialchars($clientName !== '' ? $clientName : 'Unknown') ?></div>
                </div>
                <div class="item">
                    <div class="label">Property</div>
                    <div class="value"><?= htmlspecialchars($projectDesc !== '' ? $projectDesc : 'N/A') ?></div>
                </div>
                <div class="item">
                    <div class="label">Total Amount</div>
                    <div class="value">₦<?= number_format($amountOffered,2) ?></div>
                </div>
                <div class="item">
                    <div class="label">Total Paid</div>
                    <div class="value">₦<?= number_format($totalPaid,2) ?></div>
                </div>
                <div class="item">
                    <div class="label">Balance Remaining</div>
                    <div class="value">₦<?= number_format(max(0,$amountOffered-$totalPaid),2) ?></div>
                </div>
            </div>
            <div style="padding:10px 24px 0 24px">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Description</th>
                            <th class="text-end">Debit</th>
                            <th class="text-end">Credit</th>
                            <th class="text-end">Balance</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($rows as $r): ?>
                        <tr>
                            <td><?= htmlspecialchars($r['date']) ?></td>
                            <td><?= htmlspecialchars($r['desc']) ?></td>
                            <td class="text-end"><?= $r['debit']>0 ? '₦'.number_format($r['debit'],2) : '' ?></td>
                            <td class="text-end"><?= $r['credit']>0 ? '₦'.number_format($r['credit'],2) : '' ?></td>
                            <td class="text-end"><?= '₦'.number_format(max(0,$r['balance']),2) ?></td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
            <div style="padding:12px 24px 24px 24px;display:flex;justify-content:flex-end;gap:8px">
                <span class="pill">Deal #<?= (int)$deal_id ?></span>
                <span class="pill"><?= count($payments) ?> payment<?= count($payments)===1?'':'s' ?></span>
            </div>
        </div>
    </div>
</body>
<?php ?>

Youez - 2016 - github.com/yon3zu
LinuXploit