|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/assetradar.outerorbittech.com/admin/ | |
|
Path: /home2/outerorb/assetradar.outerorbittech.com/admin/dashboard.php
Size: 6.08 KB
Permissions: 0666
<?php
require_once __DIR__ . '/../inc/auth.php';
require_login();
// check role
$u = current_user();
if ($u['role_slug'] !== 'admin') {
header('Location: ' . BASE_URL . '/index.php');
exit;
}
define('ADMIN_PAGE', true);
include __DIR__ . '/../inc/header.php';
include __DIR__ . '/admin_menu.php';
// fetch counts
$counts = [];
$counts['total'] = $mysqli->query('SELECT COUNT(*) as c FROM items')->fetch_assoc()['c'];
$counts['issued'] = $mysqli->query("SELECT COUNT(*) as c FROM items WHERE assigned_to IS NOT NULL")->fetch_assoc()['c'];
$counts['available'] = $mysqli->query("SELECT COUNT(*) as c FROM items WHERE assigned_to IS NULL AND condition_status='Working'")->fetch_assoc()['c'];
$counts['damaged'] = $mysqli->query("SELECT COUNT(*) as c FROM items WHERE condition_status='Damaged'")->fetch_assoc()['c'];
$counts['pending_issues'] = $mysqli->query("SELECT COUNT(*) as c FROM tickets WHERE status='Pending'")->fetch_assoc()['c'];
// Recent tickets (last 5)
$recent_tickets = $mysqli->query("SELECT t.id, t.item_name, t.issue_type, t.status FROM tickets t ORDER BY t.created_at DESC LIMIT 5");
// Items needing attention (damaged or warranty expiring soon)
$attention_items = $mysqli->query("SELECT id, asset_tag, item_name, condition_status, warranty_to AS warranty_expiry FROM items WHERE condition_status='Damaged' OR (warranty_to IS NOT NULL AND warranty_to <= DATE_ADD(CURDATE(), INTERVAL 30 DAY)) ORDER BY warranty_to ASC LIMIT 5");
?>
<div class="row g-3">
<div class="col-6 col-md-3">
<div class="card p-3 card-hero text-center mb-2 mb-md-0">
<h6 class="mb-1">Total Inventory</h6>
<h2 class="fw-bold mb-0"><?php echo $counts['total']; ?></h2>
</div>
</div>
<div class="col-6 col-md-3">
<div class="card p-3 card-hero text-center mb-2 mb-md-0">
<h6 class="mb-1">Issued</h6>
<h2 class="fw-bold mb-0"><?php echo $counts['issued']; ?></h2>
</div>
</div>
<div class="col-6 col-md-3">
<div class="card p-3 card-hero text-center mb-2 mb-md-0">
<h6 class="mb-1">Available</h6>
<h2 class="fw-bold mb-0"><?php echo $counts['available']; ?></h2>
</div>
</div>
<div class="col-6 col-md-3">
<div class="card p-3 card-hero text-center mb-2 mb-md-0">
<h6 class="mb-1">Damaged</h6>
<h2 class="fw-bold mb-0"><?php echo $counts['damaged']; ?></h2>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-6 mb-4">
<div class="card p-3 h-100">
<h6 class="mb-3">Recent Tickets</h6>
<table class="table table-sm mb-0">
<thead><tr><th>ID</th><th>Item</th><th>Issue</th><th>Status</th></tr></thead>
<tbody>
<?php while($t = $recent_tickets->fetch_assoc()): ?>
<tr>
<td><a href="tickets.php?id=<?php echo $t['id']; ?>" class="btn btn-link btn-sm">#<?php echo $t['id']; ?></a></td>
<td><?php echo esc($t['item_name']); ?></td>
<td><?php echo esc($t['issue_type']); ?></td>
<td><?php echo esc($t['status']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6 mb-4">
<div class="card p-3 h-100">
<h6 class="mb-3">Items Needing Attention</h6>
<table class="table table-sm mb-0">
<thead><tr><th>Tag</th><th>Name</th><th>Status</th><th>Warranty Expiry</th></tr></thead>
<tbody>
<?php while($i = $attention_items->fetch_assoc()): ?>
<tr>
<td><?php echo esc($i['asset_tag']); ?></td>
<td><?php echo esc($i['item_name']); ?></td>
<td><?php echo esc($i['condition_status']); ?></td>
<td><?php echo $i['warranty_expiry'] ? esc($i['warranty_expiry']) : '-'; ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="mt-4">
<h5>Quick Links</h5>
<div class="d-flex flex-wrap gap-2">
<a class="btn btn-outline-primary flex-fill" href="inventory.php">Manage Inventory</a>
<a class="btn btn-outline-success flex-fill" href="assign_item.php">Assign Item</a>
<a class="btn btn-outline-warning flex-fill" href="reports.php">Reports</a>
<a class="btn btn-outline-danger flex-fill" href="tickets.php">View Tickets</a>
<a class="btn btn-outline-info flex-fill" href="master_data.php">Master Data Panel</a>
<a class="btn btn-outline-secondary flex-fill" href="alerts.php">Alerts & Warranties</a>
<a class="btn btn-outline-dark flex-fill" href="team_audit.php">Team Audit</a>
<a class="btn btn-outline-success flex-fill" href="bulk_upload.php">Bulk Upload</a>
</div>
</div>
<!-- Chart.js CDN -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div class="row mt-4">
<div class="col-md-6 mb-4">
<div class="card p-3">
<h6 class="mb-3">Asset Status Overview</h6>
<canvas id="assetStatusChart" height="180"></canvas>
</div>
</div>
<div class="col-md-6 mb-4">
<div class="card p-3">
<h6 class="mb-3">Ticket Status Overview</h6>
<canvas id="ticketStatusChart" height="180"></canvas>
</div>
</div>
</div>
<script>
// Asset status chart data
const assetStatusData = {
labels: ['Issued', 'Available', 'Damaged'],
datasets: [{
data: [<?php echo $counts['issued']; ?>, <?php echo $counts['available']; ?>, <?php echo $counts['damaged']; ?>],
backgroundColor: ['#4f46e5', '#06b6d4', '#ef4444'],
borderWidth: 1
}]
};
new Chart(document.getElementById('assetStatusChart'), {
type: 'pie',
data: assetStatusData,
options: {
responsive: true,
plugins: { legend: { position: 'bottom' } }
}
});
// Ticket status chart data (fetch from DB)
fetch('reports.php?chart_status=1')
.then(res => res.json())
.then(data => {
new Chart(document.getElementById('ticketStatusChart'), {
type: 'doughnut',
data: {
labels: data.labels,
datasets: [{
data: data.counts,
backgroundColor: ['#f59e42', '#4f46e5', '#10b981', '#ef4444'],
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: { legend: { position: 'bottom' } }
}
});
});
</script>
<?php include __DIR__ . '/../inc/footer.php'; ?>