[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: manage.php
<?php require_once '../config/database.php'; require_once '../config/functions.php'; requireAuth('accountant'); // Get search parameters $search_name = $_GET['search_name'] ?? ''; $search_phone = $_GET['search_phone'] ?? ''; $balance_filter = $_GET['balance_filter'] ?? ''; // Build query $where_conditions = []; $params = []; if ($search_name) { $where_conditions[] = "name LIKE ?"; $params[] = "%$search_name%"; } if ($search_phone) { $where_conditions[] = "phone LIKE ?"; $params[] = "%$search_phone%"; } if ($balance_filter === 'with_debt') { $where_conditions[] = "balance > 0"; } elseif ($balance_filter === 'no_debt') { $where_conditions[] = "balance = 0"; } $where_clause = empty($where_conditions) ? '' : 'WHERE ' . implode(' AND ', $where_conditions); // Get clients $stmt = $pdo->prepare(" SELECT c.*, u.full_name as created_by_name FROM clients c LEFT JOIN users u ON c.created_by = u.id $where_clause ORDER BY c.name ASC "); $stmt->execute($params); $clients = $stmt->fetchAll(); // Get summary statistics $stmt = $pdo->prepare(" SELECT COUNT(*) as total_clients, COUNT(CASE WHEN balance > 0 THEN 1 END) as clients_with_debt, COALESCE(SUM(balance), 0) as total_debt FROM clients $where_clause "); $stmt->execute($params); $summary = $stmt->fetch(); $error = ''; $success = ''; // Handle balance adjustment if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['adjust_balance'])) { $client_id = $_POST['client_id'] ?? ''; $new_balance = floatval($_POST['new_balance'] ?? 0); $adjustment_reason = trim($_POST['adjustment_reason'] ?? ''); if (!$client_id || !$adjustment_reason) { $error = 'معرف العميل وسبب التعديل مطلوبان'; } else { try { // Get current balance $stmt = $pdo->prepare("SELECT * FROM clients WHERE id = ?"); $stmt->execute([$client_id]); $client = $stmt->fetch(); if (!$client) { throw new Exception('العميل غير موجود'); } $old_balance = $client['balance']; // Update balance $stmt = $pdo->prepare("UPDATE clients SET balance = ? WHERE id = ?"); $stmt->execute([$new_balance, $client_id]); // Add audit log addAuditLog($pdo, $_SESSION['user_id'], 'adjust_client_balance', 'client', $client_id, ['balance' => $old_balance], ['balance' => $new_balance], "تعديل رصيد العميل {$client['name']} من $old_balance إلى $new_balance - السبب: $adjustment_reason"); $success = 'تم تعديل رصيد العميل بنجاح'; // Refresh page header("Location: /clients/manage.php?success=" . urlencode($success)); exit; } catch (Exception $e) { $error = 'خطأ في تعديل الرصيد: ' . $e->getMessage(); } } } if (isset($_GET['success'])) { $success = $_GET['success']; } ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>إدارة العملاء - حسابات عربية بن فريش</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"> <style> .search-card { background: linear-gradient(135deg, #20c997 0%, #0d6efd 100%); color: white; border-radius: 15px; } .client-row { transition: all 0.3s ease; } .client-row:hover { background: #f8f9fa; } .debt-amount { font-weight: bold; } .debt-positive { color: #dc3545; } .debt-zero { color: #198754; } .summary-card { border-radius: 10px; border-left: 4px solid; } .summary-total { border-left-color: #0d6efd; } .summary-debt { border-left-color: #dc3545; } .summary-clean { border-left-color: #198754; } </style> </head> <body class="bg-light"> <div class="container-fluid mt-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2><i class="fas fa-users me-2"></i>إدارة العملاء</h2> <a href="/dashboard.php" class="btn btn-outline-secondary"> <i class="fas fa-arrow-left me-1"></i>العودة </a> </div> <?php if ($error): ?> <div class="alert alert-danger" role="alert"> <i class="fas fa-exclamation-triangle me-2"></i><?= htmlspecialchars($error) ?> </div> <?php endif; ?> <?php if ($success): ?> <div class="alert alert-success" role="alert"> <i class="fas fa-check-circle me-2"></i><?= htmlspecialchars($success) ?> </div> <?php endif; ?> <!-- Search Filters --> <div class="search-card p-4 mb-4"> <h5 class="mb-3"><i class="fas fa-search me-2"></i>البحث والتصفية</h5> <form method="GET"> <div class="row"> <div class="col-md-3 mb-3"> <label class="form-label">اسم العميل</label> <input type="text" class="form-control" name="search_name" value="<?= htmlspecialchars($search_name) ?>" placeholder="اسم العميل"> </div> <div class="col-md-3 mb-3"> <label class="form-label">رقم الهاتف</label> <input type="text" class="form-control" name="search_phone" value="<?= htmlspecialchars($search_phone) ?>" placeholder="+201..."> </div> <div class="col-md-3 mb-3"> <label class="form-label">حالة الرصيد</label> <select class="form-select" name="balance_filter"> <option value="">جميع العملاء</option> <option value="with_debt" <?= $balance_filter === 'with_debt' ? 'selected' : '' ?>>عليهم مديونية</option> <option value="no_debt" <?= $balance_filter === 'no_debt' ? 'selected' : '' ?>>بدون مديونية</option> </select> </div> <div class="col-md-3 mb-3 d-flex align-items-end"> <button type="submit" class="btn btn-light me-2"> <i class="fas fa-search me-1"></i>بحث </button> <a href="/clients/manage.php" class="btn btn-outline-light"> <i class="fas fa-refresh me-1"></i>إعادة تعيين </a> </div> </div> </form> </div> <!-- Summary Statistics --> <div class="row mb-4"> <div class="col-md-4 mb-3"> <div class="summary-card summary-total card p-3"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="text-muted mb-1">إجمالي العملاء</h6> <h4 class="mb-0"><?= $summary['total_clients'] ?></h4> </div> <i class="fas fa-users fa-2x text-primary"></i> </div> </div> </div> <div class="col-md-4 mb-3"> <div class="summary-card summary-debt card p-3"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="text-muted mb-1">عملاء عليهم مديونية</h6> <h4 class="mb-0"><?= $summary['clients_with_debt'] ?></h4> </div> <i class="fas fa-exclamation-triangle fa-2x text-danger"></i> </div> </div> </div> <div class="col-md-4 mb-3"> <div class="summary-card card p-3"> <div class="d-flex justify-content-between align-items-center"> <div> <h6 class="text-muted mb-1">إجمالي المديونية</h6> <h5 class="mb-0"><?= formatCurrency($summary['total_debt']) ?></h5> </div> <i class="fas fa-calculator fa-2x text-info"></i> </div> </div> </div> </div> <!-- Clients Table --> <div class="card"> <div class="card-header bg-primary text-white"> <h5 class="mb-0"> <i class="fas fa-list me-2"></i> قائمة العملاء (<?= count($clients) ?>) </h5> </div> <div class="card-body p-0"> <?php if (empty($clients)): ?> <div class="text-center py-5"> <i class="fas fa-inbox fa-3x text-muted mb-3"></i> <p class="text-muted">لا توجد عملاء تطابق معايير البحث</p> </div> <?php else: ?> <div class="table-responsive"> <table class="table table-hover mb-0"> <thead class="table-light"> <tr> <th>اسم العميل</th> <th>رقم الهاتف</th> <th>العنوان</th> <th>الرصيد</th> <th>أضيف بواسطة</th> <th>تاريخ الإضافة</th> <th>إجراءات</th> </tr> </thead> <tbody> <?php foreach ($clients as $client): ?> <tr class="client-row"> <td> <strong><?= htmlspecialchars($client['name']) ?></strong> </td> <td> <a href="tel:<?= htmlspecialchars($client['phone']) ?>" class="text-decoration-none"> <?= htmlspecialchars($client['phone']) ?> </a> </td> <td><?= htmlspecialchars($client['address'] ?: '-') ?></td> <td> <span class="debt-amount <?= $client['balance'] > 0 ? 'debt-positive' : 'debt-zero' ?>"> <?= formatCurrency($client['balance']) ?> </span> </td> <td><?= htmlspecialchars($client['created_by_name'] ?: 'غير محدد') ?></td> <td><?= date('Y-m-d', strtotime($client['created_at'])) ?></td> <td> <div class="btn-group btn-group-sm"> <button class="btn btn-outline-warning" data-bs-toggle="modal" data-bs-target="#adjustModal<?= $client['id'] ?>" title="تعديل الرصيد"> <i class="fas fa-edit"></i> </button> <a href="/clients/history.php?id=<?= $client['id'] ?>" class="btn btn-outline-info" title="تاريخ العميل"> <i class="fas fa-history"></i> </a> </div> </td> </tr> <!-- Balance Adjustment Modal --> <div class="modal fade" id="adjustModal<?= $client['id'] ?>" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">تعديل رصيد العميل</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST"> <div class="modal-body"> <input type="hidden" name="client_id" value="<?= $client['id'] ?>"> <div class="alert alert-info"> <strong>العميل:</strong> <?= htmlspecialchars($client['name']) ?><br> <strong>الرصيد الحالي:</strong> <?= formatCurrency($client['balance']) ?> </div> <div class="mb-3"> <label class="form-label">الرصيد الجديد *</label> <input type="number" class="form-control" name="new_balance" value="<?= $client['balance'] ?>" step="0.01" required> </div> <div class="mb-3"> <label class="form-label">سبب التعديل *</label> <textarea class="form-control" name="adjustment_reason" rows="3" placeholder="اكتب سبب تعديل الرصيد..." required></textarea> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" name="adjust_balance" class="btn btn-warning">حفظ التعديل</button> </div> </form> </div> </div> </div> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
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