fix
This commit is contained in:
165
admin/purchases.php
Normal file
165
admin/purchases.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Visualizza Acquisti
|
||||
*
|
||||
* Lista di tutti gli acquisti effettuati sulla piattaforma
|
||||
*/
|
||||
|
||||
require_once '../includes/config.php';
|
||||
require_once '../includes/functions.php';
|
||||
|
||||
session_start();
|
||||
check_session_timeout();
|
||||
require_admin();
|
||||
|
||||
// Ottieni tutti gli acquisti
|
||||
$pdo = get_db_connection();
|
||||
$stmt = $pdo->query("
|
||||
SELECT p.*,
|
||||
u.first_name, u.last_name, u.email,
|
||||
l.title as lesson_title, l.type as lesson_type
|
||||
FROM purchases p
|
||||
INNER JOIN users u ON p.user_id = u.id
|
||||
INNER JOIN lessons l ON p.lesson_id = l.id
|
||||
ORDER BY p.created_at DESC
|
||||
");
|
||||
$purchases = $stmt->fetchAll();
|
||||
|
||||
// Statistiche
|
||||
$stmt = $pdo->query("
|
||||
SELECT
|
||||
COUNT(*) as total_purchases,
|
||||
SUM(CASE WHEN status = 'completed' THEN amount ELSE 0 END) as total_revenue,
|
||||
SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending_count,
|
||||
SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) as failed_count
|
||||
FROM purchases
|
||||
");
|
||||
$stats = $stmt->fetch();
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Acquisti - Admin</title>
|
||||
<link rel="stylesheet" href="../assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="header">
|
||||
<div class="container">
|
||||
<div class="header-content">
|
||||
<h1 class="logo">Pilates Studio - Admin</h1>
|
||||
<nav class="nav">
|
||||
<a href="../index.php" class="btn btn-outline">Vedi Sito</a>
|
||||
<a href="../includes/logout.php" class="btn btn-secondary">Logout</a>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container">
|
||||
<div class="dashboard">
|
||||
<!-- Sidebar -->
|
||||
<aside class="sidebar">
|
||||
<ul class="sidebar-menu">
|
||||
<li><a href="dashboard.php">📊 Dashboard</a></li>
|
||||
<li><a href="lessons.php">🎥 Gestione Lezioni</a></li>
|
||||
<li><a href="users.php">👥 Gestione Utenti</a></li>
|
||||
<li><a href="purchases.php" class="active">💰 Acquisti</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<h2 class="section-title" style="text-align: left;">Storico Acquisti</h2>
|
||||
|
||||
<!-- Statistiche rapide -->
|
||||
<div class="stats-grid" style="grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));">
|
||||
<div class="stat-card">
|
||||
<div class="stat-value"><?php echo $stats['total_purchases']; ?></div>
|
||||
<div class="stat-label">Totale Transazioni</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card" style="background: linear-gradient(135deg, #2ECC71, #27AE60);">
|
||||
<div class="stat-value"><?php echo format_price($stats['total_revenue']); ?></div>
|
||||
<div class="stat-label">Incassi Totali</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card" style="background: linear-gradient(135deg, #F39C12, #E67E22);">
|
||||
<div class="stat-value"><?php echo $stats['pending_count']; ?></div>
|
||||
<div class="stat-label">In Attesa</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card" style="background: linear-gradient(135deg, #E74C3C, #C0392B);">
|
||||
<div class="stat-value"><?php echo $stats['failed_count']; ?></div>
|
||||
<div class="stat-label">Falliti</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<?php if (!empty($purchases)): ?>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data</th>
|
||||
<th>Utente</th>
|
||||
<th>Lezione</th>
|
||||
<th>Tipo</th>
|
||||
<th>Importo</th>
|
||||
<th>Status</th>
|
||||
<th>PayPal ID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($purchases as $purchase): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
echo $purchase['purchased_at']
|
||||
? format_datetime($purchase['purchased_at'])
|
||||
: format_datetime($purchase['created_at']);
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo htmlspecialchars($purchase['first_name'] . ' ' . $purchase['last_name']); ?>
|
||||
<br>
|
||||
<small class="text-muted"><?php echo htmlspecialchars($purchase['email']); ?></small>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($purchase['lesson_title']); ?></td>
|
||||
<td><?php echo ucfirst($purchase['lesson_type']); ?></td>
|
||||
<td><strong><?php echo format_price($purchase['amount']); ?></strong></td>
|
||||
<td>
|
||||
<?php
|
||||
$status_colors = [
|
||||
'completed' => 'text-success',
|
||||
'pending' => 'text-warning',
|
||||
'failed' => 'text-danger',
|
||||
'refunded' => 'text-muted'
|
||||
];
|
||||
$color = $status_colors[$purchase['status']] ?? '';
|
||||
?>
|
||||
<span class="<?php echo $color; ?>">
|
||||
<?php echo ucfirst($purchase['status']); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<small class="text-muted">
|
||||
<?php echo $purchase['paypal_order_id'] ? htmlspecialchars($purchase['paypal_order_id']) : '-'; ?>
|
||||
</small>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php else: ?>
|
||||
<p class="text-muted text-center">Nessun acquisto ancora.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../assets/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user