[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: dashboard.php
<?php require_once 'config/config.php'; requirePermission(); $pageTitle = 'لوحة التحكم'; $db = Database::getInstance(); $userId = $_SESSION['user_id']; $userRole = $_SESSION['user_role']; if ($userRole === 'representative') { $totalSalesSql = "SELECT COALESCE(SUM(invoice_total), 0) as total FROM invoices WHERE representative_id = ?"; $totalSales = $db->query($totalSalesSql, [$userId])->fetch()['total']; $totalCollectionsSql = "SELECT COALESCE(SUM(amount), 0) as total FROM payments WHERE representative_id = ?"; $totalCollections = $db->query($totalCollectionsSql, [$userId])->fetch()['total']; $activeShiftSql = "SELECT * FROM shifts WHERE representative_id = ? AND status = 'active' LIMIT 1"; $activeShift = $db->query($activeShiftSql, [$userId])->fetch(); } else { $totalSalesSql = "SELECT COALESCE(SUM(invoice_total), 0) as total FROM invoices"; $totalSales = $db->query($totalSalesSql)->fetch()['total']; $totalCollectionsSql = "SELECT COALESCE(SUM(amount), 0) as total FROM payments"; $totalCollections = $db->query($totalCollectionsSql)->fetch()['total']; $activeShift = null; } $totalDebtSql = "SELECT COALESCE(SUM(current_debt), 0) as total FROM customers"; $totalDebt = $db->query($totalDebtSql)->fetch()['total']; $pendingShiftsSql = "SELECT COUNT(*) as total FROM shifts WHERE status IN ('pending_start', 'pending_end')"; $pendingShifts = $db->query($pendingShiftsSql)->fetch()['total']; $pendingReturnsSql = "SELECT COUNT(*) as total FROM returns WHERE status = 'pending'"; $pendingReturns = $db->query($pendingReturnsSql)->fetch()['total']; $recentInvoicesSql = "SELECT i.*, c.name as customer_name, u.name as representative_name FROM invoices i LEFT JOIN customers c ON i.customer_id = c.id LEFT JOIN users u ON i.representative_id = u.id"; if ($userRole === 'representative') { $recentInvoicesSql .= " WHERE i.representative_id = ?"; $recentInvoices = $db->query($recentInvoicesSql . " ORDER BY i.created_at DESC LIMIT 5", [$userId])->fetchAll(); } else { $recentInvoices = $db->query($recentInvoicesSql . " ORDER BY i.created_at DESC LIMIT 5")->fetchAll(); } include 'includes/header.php'; ?> <div class="row"> <div class="col-12 mb-4"> <h2>مرحباً، <?php echo $_SESSION['user_name']; ?></h2> <p class="text-muted"> <?php $roles = [ 'manager' => 'مدير النظام', 'accountant' => 'محاسب', 'representative' => 'مندوب مبيعات' ]; echo $roles[$userRole] ?? $userRole; ?> </p> </div> </div> <?php if ($userRole === 'representative' && !$activeShift): ?> <div class="alert alert-warning" role="alert"> <i class="bi bi-exclamation-triangle"></i> <strong>تنبيه:</strong> لا توجد وردية نشطة حالياً. يجب عليك طلب وردية جديدة للبدء في البيع والتحصيل. <a href="shifts/request.php" class="btn btn-sm btn-primary ms-2">طلب وردية جديدة</a> </div> <?php endif; ?> <?php if (hasPermission(['manager', 'accountant']) && $pendingShifts > 0): ?> <div class="alert alert-info" role="alert"> <i class="bi bi-clock-history"></i> <strong>طلبات ورديات معلقة:</strong> يوجد <?php echo $pendingShifts; ?> طلب وردية في انتظار الموافقة. <a href="shifts/index.php" class="btn btn-sm btn-info ms-2">عرض الطلبات</a> </div> <?php endif; ?> <?php if (hasPermission(['manager', 'accountant']) && $pendingReturns > 0): ?> <div class="alert alert-warning" role="alert"> <i class="bi bi-arrow-return-left"></i> <strong>مرتجعات معلقة:</strong> يوجد <?php echo $pendingReturns; ?> مرتجع في انتظار الموافقة. <a href="returns/index.php" class="btn btn-sm btn-warning ms-2">عرض المرتجعات</a> </div> <?php endif; ?> <div class="row mb-4"> <div class="col-md-3"> <div class="card text-white bg-primary shadow"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">إجمالي المبيعات</h6> <h3 class="mb-0"><?php echo formatMoney($totalSales); ?></h3> </div> <div> <i class="bi bi-cart-check" style="font-size: 3rem; opacity: 0.3;"></i> </div> </div> </div> </div> </div> <div class="col-md-3"> <div class="card text-white bg-success shadow"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">إجمالي التحصيلات</h6> <h3 class="mb-0"><?php echo formatMoney($totalCollections); ?></h3> </div> <div> <i class="bi bi-cash-coin" style="font-size: 3rem; opacity: 0.3;"></i> </div> </div> </div> </div> </div> <div class="col-md-3"> <div class="card text-white bg-danger shadow"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">إجمالي المديونيات</h6> <h3 class="mb-0"><?php echo formatMoney($totalDebt); ?></h3> </div> <div> <i class="bi bi-exclamation-triangle" style="font-size: 3rem; opacity: 0.3;"></i> </div> </div> </div> </div> </div> <div class="col-md-3"> <div class="card text-white bg-info shadow"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="card-title">الطلبات المعلقة</h6> <h3 class="mb-0"><?php echo $pendingShifts + $pendingReturns; ?></h3> </div> <div> <i class="bi bi-hourglass-split" style="font-size: 3rem; opacity: 0.3;"></i> </div> </div> </div> </div> </div> </div> <?php if ($activeShift): ?> <div class="row mb-4"> <div class="col-12"> <div class="card border-success shadow-sm"> <div class="card-header bg-success text-white"> <h5 class="mb-0"><i class="bi bi-clock-history"></i> الوردية النشطة</h5> </div> <div class="card-body"> <div class="row"> <div class="col-md-3"> <p class="mb-1"><strong>المخزون الأولي:</strong></p> <h4><?php echo $activeShift['start_stock']; ?> وحدة</h4> </div> <div class="col-md-3"> <p class="mb-1"><strong>الرصيد الأولي:</strong></p> <h4><?php echo formatMoney($activeShift['start_cash']); ?></h4> </div> <div class="col-md-3"> <p class="mb-1"><strong>وقت البداية:</strong></p> <h5><?php echo formatDate($activeShift['start_time']); ?></h5> </div> <div class="col-md-3"> <a href="shifts/view.php?id=<?php echo $activeShift['id']; ?>" class="btn btn-success"> عرض تفاصيل الوردية </a> </div> </div> </div> </div> </div> </div> <?php endif; ?> <div class="row"> <div class="col-12"> <div class="card shadow-sm"> <div class="card-header bg-light"> <h5 class="mb-0"><i class="bi bi-file-earmark-text"></i> آخر الفواتير</h5> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>رقم الفاتورة</th> <th>العميل</th> <?php if ($userRole !== 'representative'): ?> <th>المندوب</th> <?php endif; ?> <th>القيمة</th> <th>الحالة</th> <th>التاريخ</th> <th>الإجراءات</th> </tr> </thead> <tbody> <?php if (empty($recentInvoices)): ?> <tr> <td colspan="<?php echo $userRole !== 'representative' ? '7' : '6'; ?>" class="text-center text-muted py-4"> لا توجد فواتير </td> </tr> <?php else: ?> <?php foreach ($recentInvoices as $invoice): ?> <tr> <td><strong><?php echo htmlspecialchars($invoice['invoice_number']); ?></strong></td> <td><?php echo htmlspecialchars($invoice['customer_name']); ?></td> <?php if ($userRole !== 'representative'): ?> <td><?php echo htmlspecialchars($invoice['representative_name']); ?></td> <?php endif; ?> <td><?php echo formatMoney($invoice['invoice_total']); ?></td> <td> <?php $statusLabels = [ 'unpaid' => '<span class="badge bg-danger">غير مدفوعة</span>', 'partial' => '<span class="badge bg-warning">مدفوعة جزئياً</span>', 'paid' => '<span class="badge bg-success">مدفوعة</span>' ]; echo $statusLabels[$invoice['status']]; ?> </td> <td><?php echo formatDate($invoice['created_at']); ?></td> <td> <a href="invoices/view.php?id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-info"> <i class="bi bi-eye"></i> عرض </a> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> <div class="text-center mt-3"> <a href="invoices/index.php" class="btn btn-primary">عرض جميع الفواتير</a> </div> </div> </div> </div> </div> <?php include 'includes/footer.php'; ?>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285