Heray-Was-Here
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
Directory :  /home/u390967363/domains/aibenproperties.com/public_html/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/u390967363/domains/aibenproperties.com/public_html/app/executive-analytics.php
<?php
include 'includes/header.php';
require_once 'includes/db.php';
require_once 'includes/functions.php';

$role = $_SESSION['user_role'] ?? 'guest';
if ($role !== 'chairman_ceo') {
    echo "<div class='container p-4'><div class='alert alert-danger'>Access denied.</div></div>";
    include 'includes/footer.php';
    exit;
}

$companyId = getCurrentCompanyId();

function scalar($pdo,$sql,$params=[]){ try{$st=$pdo->prepare($sql);$st->execute($params);return (float)$st->fetchColumn();}catch(Exception $e){return 0;}}

// Revenue trend and allocations trend for last 12 months
$labels = []; $revSeries = []; $allocSeries = [];
for ($i = 11; $i >= 0; $i--) {
    $dt = (new DateTimeImmutable("first day of -$i month"));
    $label = $dt->format('M Y');
    $start = $dt->format('Y-m-01 00:00:00'); $end = $dt->format('Y-m-t 23:59:59');
    $companyFilter = (function_exists('tableHasColumn') && tableHasColumn('payments','company_id') && $companyId) ? " AND company_id = ? " : "";
    $rev = scalar($pdo,"SELECT COALESCE(SUM(amount),0) FROM payments WHERE status IN ('verified','approved','paid') AND created_at BETWEEN ? AND ?".$companyFilter,$companyFilter?[$start,$end,$companyId]:[$start,$end]);
    $allocWhere = " WHERE created_at BETWEEN ? AND ? ";
    if ($companyId && function_exists('tableHasColumn') && tableHasColumn('allocations','company_id')) { $allocWhere .= " AND company_id = ".((int)$companyId)." "; }
    $allocs = scalar($pdo,"SELECT COUNT(*) FROM allocations ".$allocWhere, [$start,$end]);
    $labels[] = $label; $revSeries[] = $rev; $allocSeries[] = $allocs;
}

// Acquisition sources
$sources = [];
try{
    if (function_exists('tableHasColumn') && tableHasColumn('leads','source')) {
        $sql = "SELECT source, COUNT(*) AS c FROM leads";
        $params = [];
        if ($companyId && function_exists('tableHasColumn') && tableHasColumn('leads','company_id')) { $sql .= " WHERE company_id = ? "; $params[] = $companyId; }
        $sql .= " GROUP BY source ORDER BY c DESC";
        $st = $pdo->prepare($sql); $st->execute($params);
        while ($r = $st->fetch(PDO::FETCH_ASSOC)) { $sources[] = [$r['source'] ?: 'Unknown', (int)$r['c']]; }
    }
}catch(Exception $e){}
?>
<div class="container-fluid py-4">
    <div class="d-flex align-items-center justify-content-between mb-3">
        <h2 class="mb-0">Performance & Analytics</h2>
    </div>
    <div class="row g-3">
        <div class="col-md-8">
            <div class="card shadow-sm">
                <div class="card-header">Monthly Revenue Trend</div>
                <div class="card-body"><canvas id="revChart" height="110"></canvas></div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card shadow-sm">
                <div class="card-header">Allocation Trend</div>
                <div class="card-body"><canvas id="allocChart" height="110"></canvas></div>
            </div>
        </div>
    </div>
    <div class="row g-3 mt-1">
        <div class="col-md-6">
            <div class="card shadow-sm">
                <div class="card-header">Client Acquisition Sources</div>
                <div class="card-body">
                    <?php if (empty($sources)): ?>
                        <div class="text-muted">No source data available.</div>
                    <?php else: ?>
                        <canvas id="sourceChart" height="140"></canvas>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function(){
    try {
        new Chart(document.getElementById('revChart').getContext('2d'), {
            type: 'line',
            data: { labels: <?= json_encode($labels) ?>, datasets: [{ label: 'Revenue', data: <?= json_encode($revSeries) ?>, borderColor: '#111827', fill:false, tension:.25 }]},
            options: { responsive:true, maintainAspectRatio:false }
        });
        new Chart(document.getElementById('allocChart').getContext('2d'), {
            type: 'bar',
            data: { labels: <?= json_encode($labels) ?>, datasets: [{ label: 'Allocations', data: <?= json_encode($allocSeries) ?>, backgroundColor: '#111827' }]},
            options: { responsive:true, maintainAspectRatio:false }
        });
        <?php if (!empty($sources)): ?>
        new Chart(document.getElementById('sourceChart').getContext('2d'), {
            type: 'doughnut',
            data: { labels: <?= json_encode(array_column($sources,0)) ?>, datasets: [{ data: <?= json_encode(array_column($sources,1)) ?>, backgroundColor: ['#111827','#0ea5e9','#22c55e','#f59e0b','#ef4444','#8b5cf6'] }]},
            options: { responsive:true, maintainAspectRatio:false }
        });
        <?php endif; ?>
    } catch (e) {}
    let t; const logoutAfter=15*60*1000; const reset=()=>{clearTimeout(t);t=setTimeout(()=>location.href='logout.php?reason=idle',logoutAfter);};
    ['click','mousemove','keydown','scroll','touchstart'].forEach(ev=>window.addEventListener(ev,reset,{passive:true}));
    reset();
});
</script>
<?php include 'includes/footer.php'; ?>

Hry