[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: representatives.php
<?php require_once '../config/database.php'; require_once '../config/functions.php'; requireAuth('accountant'); // Get date range (default to current month) $date_from = $_GET['date_from'] ?? date('Y-m-01'); $date_to = $_GET['date_to'] ?? date('Y-m-d'); $representative_id = $_GET['representative_id'] ?? ''; // Get all representatives $stmt = $pdo->prepare("SELECT id, full_name FROM users WHERE role = 'representative' ORDER BY full_name ASC"); $stmt->execute(); $representatives = $stmt->fetchAll(); // Build query conditions $where_conditions = ["DATE(i.created_at) BETWEEN ? AND ?"]; $params = [$date_from, $date_to]; if ($representative_id) { $where_conditions[] = "i.representative_id = ?"; $params[] = $representative_id; } $where_clause = implode(' AND ', $where_conditions); // Get detailed sales data by representative and product $stmt = $pdo->prepare(" SELECT u.full_name as representative_name, p.name as product_name, p.unit, SUM(ii.quantity) as total_quantity, SUM(ii.line_total) as total_value, COUNT(DISTINCT i.id) as invoice_count FROM invoice_items ii JOIN invoices i ON ii.invoice_id = i.id JOIN users u ON i.representative_id = u.id JOIN products p ON ii.product_id = p.id WHERE $where_clause GROUP BY u.id, u.full_name, p.id, p.name, p.unit ORDER BY u.full_name ASC, total_value DESC "); $stmt->execute($params); $sales_data = $stmt->fetchAll(); // Get summary by representative $stmt = $pdo->prepare(" SELECT u.full_name as representative_name, COUNT(DISTINCT i.id) as total_invoices, SUM(i.invoice_total) as total_sales, SUM(i.amount_paid_at_creation) as cash_collected FROM invoices i JOIN users u ON i.representative_id = u.id WHERE $where_clause GROUP BY u.id, u.full_name ORDER BY total_sales DESC "); $stmt->execute($params); $summary_data = $stmt->fetchAll(); // Group sales data by representative $grouped_data = []; foreach ($sales_data as $row) { $rep_name = $row['representative_name']; if (!isset($grouped_data[$rep_name])) { $grouped_data[$rep_name] = []; } $grouped_data[$rep_name][] = $row; } ?> <!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> .report-header { background: linear-gradient(135deg, #198754, #20c997); color: white; border-radius: 15px; } .rep-card { border-radius: 10px; border-left: 4px solid #0d6efd; transition: all 0.3s ease; } .rep-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); } .product-row { background: #f8f9fa; border-radius: 5px; margin: 2px 0; padding: 8px; } @media print { .no-print { display: none !important; } } </style> </head> <body class="bg-light"> <div class="container-fluid mt-4"> <div class="d-flex justify-content-between align-items-center mb-4 no-print"> <h2><i class="fas fa-users me-2"></i>تقرير أداء المندوبين</h2> <div> <button class="btn btn-success me-2" onclick="window.print()"> <i class="fas fa-print me-1"></i>طباعة التقرير </button> <a href="/reports/index.php" class="btn btn-outline-secondary"> <i class="fas fa-arrow-left me-1"></i>العودة </a> </div> </div> <!-- Filter Section --> <div class="report-header p-4 mb-4 no-print"> <h5 class="mb-3"><i class="fas fa-filter me-2"></i>تصفية التقرير</h5> <form method="GET" class="row align-items-end"> <div class="col-md-3"> <label class="form-label">من تاريخ</label> <input type="date" class="form-control" name="date_from" value="<?= htmlspecialchars($date_from) ?>"> </div> <div class="col-md-3"> <label class="form-label">إلى تاريخ</label> <input type="date" class="form-control" name="date_to" value="<?= htmlspecialchars($date_to) ?>"> </div> <div class="col-md-3"> <label class="form-label">المندوب</label> <select class="form-select" name="representative_id"> <option value="">جميع المندوبين</option> <?php foreach ($representatives as $rep): ?> <option value="<?= $rep['id'] ?>" <?= $representative_id == $rep['id'] ? 'selected' : '' ?>> <?= htmlspecialchars($rep['full_name']) ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-3"> <button type="submit" class="btn btn-light"> <i class="fas fa-search me-1"></i>تحديث التقرير </button> </div> </form> </div> <!-- Summary Cards --> <div class="row mb-4"> <?php foreach ($summary_data as $summary): ?> <div class="col-md-4 mb-3"> <div class="rep-card card p-3"> <h5 class="text-primary"><?= htmlspecialchars($summary['representative_name']) ?></h5> <div class="row text-center"> <div class="col-4"> <small class="text-muted">الفواتير</small> <div class="fw-bold"><?= $summary['total_invoices'] ?></div> </div> <div class="col-4"> <small class="text-muted">المبيعات</small> <div class="fw-bold text-success"><?= formatCurrency($summary['total_sales']) ?></div> </div> <div class="col-4"> <small class="text-muted">النقد</small> <div class="fw-bold text-info"><?= formatCurrency($summary['cash_collected']) ?></div> </div> </div> </div> </div> <?php endforeach; ?> </div> <!-- Detailed Report --> <div class="card"> <div class="card-header bg-primary text-white"> <h5 class="mb-0"> <i class="fas fa-chart-bar me-2"></i> تفاصيل المبيعات حسب المنتج (<?= $date_from ?> إلى <?= $date_to ?>) </h5> </div> <div class="card-body"> <?php if (empty($grouped_data)): ?> <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: ?> <?php foreach ($grouped_data as $rep_name => $products): ?> <div class="mb-4"> <h6 class="text-primary border-bottom pb-2"> <i class="fas fa-user me-2"></i><?= htmlspecialchars($rep_name) ?> </h6> <?php $rep_total_quantity = 0; $rep_total_value = 0; ?> <?php foreach ($products as $product): ?> <?php $rep_total_quantity += $product['total_quantity']; $rep_total_value += $product['total_value']; ?> <div class="product-row"> <div class="row align-items-center"> <div class="col-md-4"> <strong><?= htmlspecialchars($product['product_name']) ?></strong> </div> <div class="col-md-2 text-center"> <span class="badge bg-info"> <?= $product['total_quantity'] ?> <?= htmlspecialchars($product['unit']) ?> </span> </div> <div class="col-md-2 text-center"> <span class="badge bg-success"> <?= formatCurrency($product['total_value']) ?> </span> </div> <div class="col-md-2 text-center"> <small class="text-muted"><?= $product['invoice_count'] ?> فاتورة</small> </div> <div class="col-md-2 text-center"> <small class="text-muted"> متوسط: <?= formatCurrency($product['total_value'] / $product['invoice_count']) ?> </small> </div> </div> </div> <?php endforeach; ?> <div class="mt-2 p-2 bg-light rounded"> <div class="row"> <div class="col-md-6"> <strong>إجمالي الكميات: <?= $rep_total_quantity ?></strong> </div> <div class="col-md-6 text-end"> <strong>إجمالي القيمة: <?= formatCurrency($rep_total_value) ?></strong> </div> </div> </div> </div> <?php endforeach; ?> <?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