[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: history.php
<?php require_once '../config/database.php'; require_once '../config/functions.php'; requireAuth('accountant'); $client_id = $_GET['id'] ?? ''; if (!$client_id) { header("Location: /clients/manage.php"); exit; } // Get client details $stmt = $pdo->prepare("SELECT * FROM clients WHERE id = ?"); $stmt->execute([$client_id]); $client = $stmt->fetch(); if (!$client) { header("Location: /clients/manage.php?error=client_not_found"); exit; } // Get client invoices $stmt = $pdo->prepare(" SELECT i.*, u.full_name as representative_name FROM invoices i JOIN users u ON i.representative_id = u.id WHERE i.client_id = ? ORDER BY i.created_at DESC "); $stmt->execute([$client_id]); $invoices = $stmt->fetchAll(); // Get client payments $stmt = $pdo->prepare(" SELECT p.*, u.full_name as representative_name FROM payments p LEFT JOIN users u ON p.representative_id = u.id WHERE p.client_id = ? ORDER BY p.created_at DESC "); $stmt->execute([$client_id]); $payments = $stmt->fetchAll(); // Get client returns $stmt = $pdo->prepare(" SELECT r.*, u.full_name as representative_name, p.name as product_name FROM returns r JOIN users u ON r.representative_id = u.id JOIN products p ON r.product_id = p.id WHERE r.client_id = ? AND r.status = 'approved' ORDER BY r.processed_at DESC "); $stmt->execute([$client_id]); $returns = $stmt->fetchAll(); // Calculate totals $total_invoices = array_sum(array_column($invoices, 'invoice_total')); $total_payments = array_sum(array_column($payments, 'amount')); $total_returns = array_sum(array_column($returns, 'return_value')); ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>تاريخ العميل - <?= htmlspecialchars($client['name']) ?></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> .client-header { background: linear-gradient(135deg, #20c997, #0d6efd); color: white; border-radius: 15px; } .stat-card { border-radius: 10px; border-left: 4px solid; } .stat-invoices { border-left-color: #0d6efd; } .stat-payments { border-left-color: #198754; } .stat-returns { border-left-color: #fd7e14; } .stat-balance { border-left-color: #dc3545; } </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-history me-2"></i>تاريخ العميل</h2> <a href="/clients/manage.php" class="btn btn-outline-secondary"> <i class="fas fa-arrow-left me-1"></i>العودة </a> </div> <!-- Client Header --> <div class="client-header p-4 mb-4"> <div class="row"> <div class="col-md-6"> <h3><?= htmlspecialchars($client['name']) ?></h3> <p class="mb-1">الهاتف: <?= htmlspecialchars($client['phone']) ?></p> <?php if ($client['address']): ?> <p class="mb-0">العنوان: <?= htmlspecialchars($client['address']) ?></p> <?php endif; ?> </div> <div class="col-md-6 text-end"> <h4>الرصيد الحالي: <?= formatCurrency($client['balance']) ?></h4> <p class="mb-0">عضو منذ: <?= date('Y-m-d', strtotime($client['created_at'])) ?></p> </div> </div> </div> <!-- Statistics --> <div class="row mb-4"> <div class="col-md-3 mb-3"> <div class="stat-card stat-invoices 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"><?= count($invoices) ?></h4> <small><?= formatCurrency($total_invoices) ?></small> </div> <i class="fas fa-file-invoice fa-2x text-primary"></i> </div> </div> </div> <div class="col-md-3 mb-3"> <div class="stat-card stat-payments 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"><?= count($payments) ?></h4> <small><?= formatCurrency($total_payments) ?></small> </div> <i class="fas fa-money-bill fa-2x text-success"></i> </div> </div> </div> <div class="col-md-3 mb-3"> <div class="stat-card stat-returns 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"><?= count($returns) ?></h4> <small><?= formatCurrency($total_returns) ?></small> </div> <i class="fas fa-undo fa-2x text-warning"></i> </div> </div> </div> <div class="col-md-3 mb-3"> <div class="stat-card stat-balance 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 <?= $client['balance'] > 0 ? 'text-danger' : 'text-success' ?>"> <?= formatCurrency($client['balance']) ?> </h4> </div> <i class="fas fa-balance-scale fa-2x text-info"></i> </div> </div> </div> </div> <!-- Tabs --> <ul class="nav nav-tabs" id="historyTabs" role="tablist"> <li class="nav-item" role="presentation"> <button class="nav-link active" id="invoices-tab" data-bs-toggle="tab" data-bs-target="#invoices" type="button"> <i class="fas fa-file-invoice me-1"></i>الفواتير (<?= count($invoices) ?>) </button> </li> <li class="nav-item" role="presentation"> <button class="nav-link" id="payments-tab" data-bs-toggle="tab" data-bs-target="#payments" type="button"> <i class="fas fa-money-bill me-1"></i>المدفوعات (<?= count($payments) ?>) </button> </li> <li class="nav-item" role="presentation"> <button class="nav-link" id="returns-tab" data-bs-toggle="tab" data-bs-target="#returns" type="button"> <i class="fas fa-undo me-1"></i>المرتجعات (<?= count($returns) ?>) </button> </li> </ul> <div class="tab-content" id="historyTabsContent"> <!-- Invoices Tab --> <div class="tab-pane fade show active" id="invoices" role="tabpanel"> <div class="card"> <div class="card-body p-0"> <?php if (empty($invoices)): ?> <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> <th>إجراءات</th> </tr> </thead> <tbody> <?php foreach ($invoices as $invoice): ?> <tr> <td><?= htmlspecialchars($invoice['invoice_number']) ?></td> <td><?= date('Y-m-d', strtotime($invoice['created_at'])) ?></td> <td><?= htmlspecialchars($invoice['representative_name']) ?></td> <td><?= formatCurrency($invoice['invoice_total']) ?></td> <td><?= formatCurrency($invoice['amount_paid_at_creation']) ?></td> <td><?= formatCurrency($invoice['remaining_amount']) ?></td> <td> <?php $status_class = [ 'paid' => 'success', 'partially_paid' => 'warning', 'unpaid' => 'danger' ]; $status_text = [ 'paid' => 'مدفوعة', 'partially_paid' => 'جزئية', 'unpaid' => 'غير مدفوعة' ]; ?> <span class="badge bg-<?= $status_class[$invoice['status']] ?>"> <?= $status_text[$invoice['status']] ?> </span> </td> <td> <a href="/invoices/details.php?id=<?= $invoice['id'] ?>" class="btn btn-sm btn-outline-info"> <i class="fas fa-eye"></i> </a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> </div> </div> </div> <!-- Payments Tab --> <div class="tab-pane fade" id="payments" role="tabpanel"> <div class="card"> <div class="card-body p-0"> <?php if (empty($payments)): ?> <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 ($payments as $payment): ?> <tr> <td><?= htmlspecialchars($payment['receipt_number']) ?></td> <td><?= date('Y-m-d', strtotime($payment['created_at'])) ?></td> <td><?= htmlspecialchars($payment['representative_name'] ?: 'تعديل يدوي') ?></td> <td><?= formatCurrency($payment['amount']) ?></td> <td><?= formatCurrency($payment['previous_balance']) ?></td> <td><?= formatCurrency($payment['new_balance']) ?></td> <td> <span class="badge bg-<?= $payment['payment_type'] === 'linked_to_invoice' ? 'info' : 'success' ?>"> <?= $payment['payment_type'] === 'linked_to_invoice' ? 'مرتبط بفاتورة' : 'دفعة منفصلة' ?> </span> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> </div> </div> </div> <!-- Returns Tab --> <div class="tab-pane fade" id="returns" role="tabpanel"> <div class="card"> <div class="card-body p-0"> <?php if (empty($returns)): ?> <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 ($returns as $return): ?> <tr> <td><?= htmlspecialchars($return['return_number']) ?></td> <td><?= date('Y-m-d', strtotime($return['processed_at'])) ?></td> <td><?= htmlspecialchars($return['representative_name']) ?></td> <td><?= htmlspecialchars($return['product_name']) ?></td> <td><?= $return['quantity'] ?></td> <td><?= formatCurrency($return['return_value']) ?></td> <td><?= htmlspecialchars(substr($return['reason'], 0, 50)) ?>...</td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> </div> </div> </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