108 lines
4.5 KiB
PHP
108 lines
4.5 KiB
PHP
<?php
|
|
require_once 'includes/header.php';
|
|
|
|
// Fetch Stats
|
|
$stats = [
|
|
'quotes_total' => 0,
|
|
'quotes_new' => 0,
|
|
'shipments_total' => 0,
|
|
'services_total' => 0
|
|
];
|
|
|
|
try {
|
|
$stats['quotes_total'] = $pdo->query("SELECT COUNT(*) FROM quotes")->fetchColumn();
|
|
$stats['quotes_new'] = $pdo->query("SELECT COUNT(*) FROM quotes WHERE status = 'new'")->fetchColumn();
|
|
$stats['shipments_total'] = $pdo->query("SELECT COUNT(*) FROM shipments")->fetchColumn(); // Might fail if table doesn't exist yet
|
|
$stats['services_total'] = $pdo->query("SELECT COUNT(*) FROM services")->fetchColumn();
|
|
|
|
// Fetch Recent Quotes
|
|
$stmt = $pdo->query("SELECT * FROM quotes ORDER BY created_at DESC LIMIT 5");
|
|
$recent_quotes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (Exception $e) {
|
|
// Graceful fallback if tables missing
|
|
$error = $e->getMessage();
|
|
}
|
|
?>
|
|
|
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:1.5rem;">
|
|
<h2 style="margin:0; color:var(--primary);">لوحة القيادة</h2>
|
|
<a href="quotes.php" class="btn btn-primary">عرض كل الطلبات</a>
|
|
</div>
|
|
|
|
<?php if (isset($error)): ?>
|
|
<div style="background:#fee2e2; color:#991b1b; padding:1rem; border-radius:8px; margin-bottom:1rem;">
|
|
خطأ في قاعدة البيانات: <?php echo htmlspecialchars($error); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="grid-3" style="margin-bottom:2rem;">
|
|
<!-- New Quotes Stat -->
|
|
<div class="admin-card" style="border-top: 4px solid #ef4444;">
|
|
<div class="stat-label">طلبات تسعير جديدة</div>
|
|
<div class="stat-value"><?php echo $stats['quotes_new']; ?></div>
|
|
<small style="color:var(--text-muted)">من أصل <?php echo $stats['quotes_total']; ?> طلب</small>
|
|
</div>
|
|
|
|
<!-- Active Shipments -->
|
|
<div class="admin-card" style="border-top: 4px solid var(--accent);">
|
|
<div class="stat-label">شحنات مسجلة</div>
|
|
<div class="stat-value"><?php echo $stats['shipments_total']; ?></div>
|
|
<small style="color:var(--text-muted)">في النظام</small>
|
|
</div>
|
|
|
|
<!-- Services -->
|
|
<div class="admin-card" style="border-top: 4px solid var(--primary);">
|
|
<div class="stat-label">الخدمات المفعلة</div>
|
|
<div class="stat-value"><?php echo $stats['services_total']; ?></div>
|
|
<small style="color:var(--text-muted)">خدمات معروضة للعملاء</small>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 style="margin-bottom:1rem; color:var(--primary);">آخر طلبات التسعير (Leads)</h3>
|
|
<div class="admin-card" style="padding:0; overflow:hidden;">
|
|
<table class="table-custom">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>العميل</th>
|
|
<th>رقم الهاتف</th>
|
|
<th>الخدمة المطلوبة</th>
|
|
<th>الحالة</th>
|
|
<th>التاريخ</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($recent_quotes)): ?>
|
|
<?php foreach ($recent_quotes as $q): ?>
|
|
<tr>
|
|
<td><?php echo $q['id']; ?></td>
|
|
<td><?php echo htmlspecialchars($q['customer_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($q['customer_phone']); ?></td>
|
|
<td>
|
|
<?php
|
|
// Fetch service name simply or join in query. For now, simple ID check
|
|
echo $q['service_id'] ? 'خدمة #' . $q['service_id'] : 'عام';
|
|
?>
|
|
</td>
|
|
<td>
|
|
<span class="badge badge-<?php echo $q['status']; ?>">
|
|
<?php echo $q['status'] == 'new' ? 'جديد' : ($q['status'] == 'contacted' ? 'تم التواصل' : 'مغلق'); ?>
|
|
</span>
|
|
</td>
|
|
<td><?php echo date('Y-m-d', strtotime($q['created_at'])); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<tr>
|
|
<td colspan="6" style="text-align:center; padding:2rem; color:var(--text-muted);">
|
|
لا توجد طلبات تسعير حتى الآن.
|
|
</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|