[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: index.php
<?php require_once '../config/config.php'; requirePermission(); $pageTitle = 'الفواتير'; $db = Database::getInstance(); $userRole = $_SESSION['user_role']; $userId = $_SESSION['user_id']; $search = cleanInput($_GET['search'] ?? ''); $status = cleanInput($_GET['status'] ?? ''); $page = max(1, intval($_GET['page'] ?? 1)); $offset = ($page - 1) * RECORDS_PER_PAGE; $whereClause = ''; $params = []; if ($userRole === 'representative') { $whereClause = "WHERE i.representative_id = ?"; $params[] = $userId; } if (!empty($search)) { $whereClause .= ($whereClause ? ' AND' : 'WHERE') . " (i.invoice_number LIKE ? OR c.name LIKE ?)"; $params[] = "%$search%"; $params[] = "%$search%"; } if (!empty($status)) { $whereClause .= ($whereClause ? ' AND' : 'WHERE') . " i.status = ?"; $params[] = $status; } $countSql = "SELECT COUNT(*) as total FROM invoices i LEFT JOIN customers c ON i.customer_id = c.id $whereClause"; $totalRecords = $db->query($countSql, $params)->fetch()['total']; $totalPages = ceil($totalRecords / RECORDS_PER_PAGE); $sql = "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 $whereClause ORDER BY i.created_at DESC LIMIT " . RECORDS_PER_PAGE . " OFFSET $offset"; $invoices = $db->query($sql, $params)->fetchAll(); $statusLabels = [ 'unpaid' => 'غير مدفوعة', 'partial' => 'مدفوعة جزئياً', 'paid' => 'مدفوعة' ]; $statusColors = [ 'unpaid' => 'danger', 'partial' => 'warning', 'paid' => 'success' ]; include '../includes/header.php'; ?> <div class="row"> <div class="col-12"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2><i class="bi bi-file-earmark-text"></i> الفواتير</h2> <a href="create.php" class="btn btn-primary"> <i class="bi bi-plus-lg"></i> فاتورة جديدة </a> </div> <?php if (isset($_GET['success'])): ?> <div class="alert alert-success alert-dismissible fade show" role="alert"> تمت العملية بنجاح <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <?php if (isset($_GET['error'])): ?> <div class="alert alert-danger alert-dismissible fade show" role="alert"> <?php $errors = [ 'no_active_shift' => 'لا توجد وردية نشطة. يجب طلب وردية جديدة أولاً' ]; echo $errors[$_GET['error']] ?? 'حدث خطأ أثناء العملية'; ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <div class="card shadow-sm"> <div class="card-body"> <form method="GET" class="row g-3 mb-4"> <div class="col-md-5"> <input type="text" name="search" class="form-control" placeholder="بحث برقم الفاتورة أو اسم العميل..." value="<?php echo htmlspecialchars($search); ?>"> </div> <div class="col-md-3"> <select name="status" class="form-select"> <option value="">جميع الحالات</option> <option value="unpaid" <?php echo $status === 'unpaid' ? 'selected' : ''; ?>>غير مدفوعة</option> <option value="partial" <?php echo $status === 'partial' ? 'selected' : ''; ?>>مدفوعة جزئياً</option> <option value="paid" <?php echo $status === 'paid' ? 'selected' : ''; ?>>مدفوعة</option> </select> </div> <div class="col-md-2"> <button type="submit" class="btn btn-primary w-100"> <i class="bi bi-search"></i> بحث </button> </div> <div class="col-md-2"> <a href="index.php" class="btn btn-secondary w-100"> <i class="bi bi-x-lg"></i> إلغاء </a> </div> </form> <div class="table-responsive"> <table class="table table-hover"> <thead class="table-light"> <tr> <th>#</th> <th>رقم الفاتورة</th> <th>العميل</th> <?php if ($userRole !== 'representative'): ?> <th>المندوب</th> <?php endif; ?> <th>القيمة</th> <th>المدفوع</th> <th>المتبقي</th> <th>الحالة</th> <th>التاريخ</th> <th>الإجراءات</th> </tr> </thead> <tbody> <?php if (empty($invoices)): ?> <tr> <td colspan="<?php echo $userRole !== 'representative' ? '10' : '9'; ?>" class="text-center text-muted py-4"> لا توجد فواتير </td> </tr> <?php else: ?> <?php foreach ($invoices as $index => $invoice): ?> <tr> <td><?php echo $offset + $index + 1; ?></td> <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 echo formatMoney($invoice['paid_amount']); ?></td> <td><?php echo formatMoney($invoice['remaining_amount']); ?></td> <td> <span class="badge bg-<?php echo $statusColors[$invoice['status']]; ?>"> <?php echo $statusLabels[$invoice['status']]; ?> </span> </td> <td><?php echo formatDate($invoice['created_at']); ?></td> <td> <a href="view.php?id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-info" title="عرض"> <i class="bi bi-eye"></i> </a> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> <?php if ($totalPages > 1): ?> <nav aria-label="الصفحات"> <ul class="pagination justify-content-center"> <?php for ($i = 1; $i <= $totalPages; $i++): ?> <li class="page-item <?php echo $i === $page ? 'active' : ''; ?>"> <a class="page-link" href="?page=<?php echo $i; ?>&search=<?php echo urlencode($search); ?>&status=<?php echo urlencode($status); ?>"> <?php echo $i; ?> </a> </li> <?php endfor; ?> </ul> </nav> <?php endif; ?> </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.85 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