MINI
C:
/
xampp
/
htdocs
/
cek
/
Upload File:
files >> C:/xampp/htdocs/cek/print_report.php
<?php session_start(); include 'db.php'; // Check if user is logged in if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit(); } // Get current user info $current_user_id = $_SESSION['user_id']; $stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?"); $stmt->execute([$current_user_id]); $current_user = $stmt->fetch(); // Check if admin $is_admin = ($current_user['role'] ?? '') == 'admin'; // Get filter values $filter_user_id = $is_admin ? ($_GET['user_id'] ?? '') : $current_user_id; $type_filter = $_GET['type'] ?? ''; $date_from = $_GET['date_from'] ?? ''; $date_to = $_GET['date_to'] ?? ''; // Build the query $query = "SELECT t.*, u.username FROM transactions t LEFT JOIN users u ON t.user_id = u.id WHERE 1=1"; $params = []; if (!empty($filter_user_id)) { $query .= " AND t.user_id = ?"; $params[] = $filter_user_id; } if (!empty($type_filter)) { $query .= " AND t.type = ?"; $params[] = $type_filter; } if (!empty($date_from)) { $query .= " AND DATE(t.created_at) >= ?"; $params[] = $date_from; } if (!empty($date_to)) { $query .= " AND DATE(t.created_at) <= ?"; $params[] = $date_to; } $query .= " ORDER BY t.created_at DESC"; // Get transactions $stmt = $pdo->prepare($query); $stmt->execute($params); $transactions = $stmt->fetchAll(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Print Transaction Report</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> body { font-family: Arial, sans-serif; margin: 20px; } table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } @media print { @page { margin: 0; size: auto; } body { margin: 20px; } } </style> </head> <body> <h1>Transaction Report</h1> <p>Generated on: <?= date('Y-m-d H:i:s') ?></p> <table> <thead> <tr> <?php if ($is_admin && !$filter_user_id): ?> <th>User</th> <?php endif; ?> <th>Date</th> <th>Voucher Code</th> <th>Amount</th> <th>Type</th> </tr> </thead> <tbody> <?php if (empty($transactions)): ?> <tr> <td colspan="<?= $is_admin && !$filter_user_id ? 5 : 4 ?>" class="text-center">No transactions found</td> </tr> <?php else: ?> <?php foreach ($transactions as $transaction): ?> <tr> <?php if ($is_admin && !$filter_user_id): ?> <td><?= htmlspecialchars($transaction['username']) ?></td> <?php endif; ?> <td><?= date('d M Y H:i', strtotime($transaction['created_at'])) ?></td> <td><?= htmlspecialchars($transaction['voucher_code']) ?></td> <td>Rp <?= number_format($transaction['amount'], 2) ?></td> <td><?= $transaction['type'] == 'in' ? 'Masuk' : 'Keluar' ?></td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> <button onclick="window.print();" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700"> <i class="fas fa-print"></i> Print Report </button> <!-- Back to Menu Button --> <a href="index.php" class="bg-gray-600 text-white px-4 py-2 rounded-md hover:bg-gray-700 mt-4 inline-block"> <i class="fas fa-arrow-left"></i> Back to Menu </a> </body> </html>
Copyright ©2021 || Defacer Indonesia