| Server IP : 198.54.126.135 / Your IP : 216.73.216.217 Web Server : Apache System : Linux host11.registrar-servers.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : linearpo ( 12988) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/linearpo/public_html/app/ |
Upload File : |
<?php
// reports.php - Transaction Reports
require_once 'config.php';
checkAuth();
// Get filter parameters
$date_from = $_GET['date_from'] ?? date('Y-m-d');
$date_to = $_GET['date_to'] ?? date('Y-m-d');
$trans_type = $_GET['type'] ?? 'all';
// Build query
$where = "user_id = {$_SESSION['user_id']}";
$where .= " AND DATE(created_at) BETWEEN '$date_from' AND '$date_to'";
if ($trans_type != 'all') {
$where .= " AND transaction_type = '$trans_type'";
}
$sql = "SELECT * FROM transactions WHERE $where ORDER BY created_at DESC";
$result = $conn->query($sql);
// Calculate totals
$total_deposits = 0;
$total_withdrawals = 0;
$deposit_count = 0;
$withdrawal_count = 0;
if ($result->num_rows > 0) {
$result->data_seek(0);
while ($row = $result->fetch_assoc()) {
if ($row['transaction_type'] == 'deposit') {
$total_deposits += $row['amount'];
$deposit_count++;
} else {
$total_withdrawals += $row['amount'];
$withdrawal_count++;
}
}
$result->data_seek(0);
}
$page_title = "Transaction Reports";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $page_title; ?> - M-Pesa Agent System</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<style>
:root { --mpesa-green: #00a650; }
body { background-color: #f8f9fa; }
.navbar { background: linear-gradient(135deg, var(--mpesa-green) 0%, #008f43 100%); }
.sidebar { min-height: calc(100vh - 56px); background: white; box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
.sidebar .nav-link { color: #333; padding: 15px 20px; }
.sidebar .nav-link:hover, .sidebar .nav-link.active { background-color: rgba(0, 166, 80, 0.1); color: var(--mpesa-green); border-right: 3px solid var(--mpesa-green); }
.sidebar .nav-link i { margin-right: 10px; width: 20px; }
.report-card { background: white; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.08); }
.stat-summary { background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); border-radius: 10px; padding: 20px; }
.table-container { max-height: 600px; overflow-y: auto; }
.export-btn { background: var(--mpesa-green); color: white; }
.export-btn:hover { background: #008f43; color: white; }
@media print {
.sidebar, .navbar, .no-print { display: none !important; }
.col-md-10 { width: 100% !important; margin: 0 !important; }
}
</style>
</head>
<body>
<nav class="navbar navbar-dark no-print">
<div class="container-fluid">
<a class="navbar-brand" href="dashboard.php"><i class="bi bi-phone-fill me-2"></i><strong>M-Pesa Agent</strong> System</a>
<div class="d-flex align-items-center text-white">
<span class="me-3"><i class="bi bi-person-circle me-1"></i> <?php echo $_SESSION['full_name']; ?></span>
<a href="logout.php" class="btn btn-outline-light btn-sm"><i class="bi bi-box-arrow-right"></i> Logout</a>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-2 sidebar p-0 no-print">
<nav class="nav flex-column">
<a class="nav-link" href="dashboard.php"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a class="nav-link" href="transactions.php"><i class="bi bi-cash-coin"></i> Transactions</a>
<a class="nav-link" href="float_management.php"><i class="bi bi-wallet2"></i> Float Management</a>
<a class="nav-link active" href="reports.php"><i class="bi bi-graph-up"></i> Reports</a>
<?php if ($_SESSION['role'] == 'admin'): ?>
<a class="nav-link" href="users.php"><i class="bi bi-people"></i> User Management</a>
<?php endif; ?>
<a class="nav-link" href="change_password.php"><i class="bi bi-key"></i> Change Password</a>
</nav>
</div>
<div class="col-md-10 p-4">
<div class="d-flex justify-content-between align-items-center mb-4 no-print">
<h2><i class="bi bi-graph-up me-2"></i>Transaction Reports</h2>
<button onclick="window.print()" class="btn btn-outline-primary">
<i class="bi bi-printer me-2"></i>Print Report
</button>
</div>
<!-- Filters -->
<div class="report-card p-4 mb-4 no-print">
<form method="GET" action="" class="row g-3 align-items-end">
<div class="col-md-3">
<label class="form-label fw-bold">From Date</label>
<input type="date" class="form-control" name="date_from" value="<?php echo $date_from; ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-bold">To Date</label>
<input type="date" class="form-control" name="date_to" value="<?php echo $date_to; ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-bold">Transaction Type</label>
<select class="form-select" name="type">
<option value="all" <?php echo $trans_type == 'all' ? 'selected' : ''; ?>>All Transactions</option>
<option value="deposit" <?php echo $trans_type == 'deposit' ? 'selected' : ''; ?>>Deposits Only</option>
<option value="withdrawal" <?php echo $trans_type == 'withdrawal' ? 'selected' : ''; ?>>Withdrawals Only</option>
</select>
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-primary w-100">
<i class="bi bi-funnel me-2"></i>Generate Report
</button>
</div>
</form>
</div>
<!-- Summary Cards -->
<div class="row g-4 mb-4">
<div class="col-md-3">
<div class="stat-summary text-center border-start border-4 border-success">
<h4 class="text-success mb-1">KES <?php echo number_format($total_deposits, 2); ?></h4>
<small class="text-muted text-uppercase">Total Deposits</small>
<div class="mt-1"><span class="badge bg-success"><?php echo $deposit_count; ?> transactions</span></div>
</div>
</div>
<div class="col-md-3">
<div class="stat-summary text-center border-start border-4 border-danger">
<h4 class="text-danger mb-1">KES <?php echo number_format($total_withdrawals, 2); ?></h4>
<small class="text-muted text-uppercase">Total Withdrawals</small>
<div class="mt-1"><span class="badge bg-danger"><?php echo $withdrawal_count; ?> transactions</span></div>
</div>
</div>
<div class="col-md-3">
<div class="stat-summary text-center border-start border-4 border-primary">
<h4 class="text-primary mb-1"><?php echo $deposit_count + $withdrawal_count; ?></h4>
<small class="text-muted text-uppercase">Total Transactions</small>
</div>
</div>
<div class="col-md-3">
<div class="stat-summary text-center border-start border-4 border-info">
<h4 class="text-info mb-1">KES <?php echo number_format($total_deposits - $total_withdrawals, 2); ?></h4>
<small class="text-muted text-uppercase">Net Position</small>
</div>
</div>
</div>
<!-- Transactions Table -->
<div class="report-card p-4">
<h5 class="mb-3">Transaction Details</h5>
<div class="table-container">
<table class="table table-hover table-striped">
<thead class="table-light sticky-top">
<tr>
<th>#</th>
<th>Date & Time</th>
<th>Customer</th>
<th>Phone</th>
<th>Type</th>
<th>Amount</th>
<th>Reference</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
$counter = 1;
while ($row = $result->fetch_assoc()) {
$badge = $row['transaction_type'] == 'deposit'
? '<span class="badge bg-success"><i class="bi bi-arrow-down me-1"></i>Deposit</span>'
: '<span class="badge bg-danger"><i class="bi bi-arrow-up me-1"></i>Withdrawal</span>';
echo "<tr>";
echo "<td>{$counter}</td>";
echo "<td>" . date('M d, Y H:i', strtotime($row['created_at'])) . "</td>";
echo "<td>" . htmlspecialchars($row['customer_name']) . "</td>";
echo "<td>" . $row['customer_phone'] . "</td>";
echo "<td>{$badge}</td>";
echo "<td class='fw-bold'>KES " . number_format($row['amount'], 2) . "</td>";
echo "<td>" . ($row['reference_number'] ? '<code>' . $row['reference_number'] . '</code>' : '-') . "</td>";
echo "<td><small>" . htmlspecialchars($row['notes'] ?: '-') . "</small></td>";
echo "</tr>";
$counter++;
}
} else {
echo "<tr><td colspan='8' class='text-center text-muted py-4'>No transactions found for selected period</td></tr>";
}
?>
</tbody>
<tfoot class="table-light fw-bold">
<tr>
<td colspan="5" class="text-end">TOTALS:</td>
<td colspan="3">
<span class="text-success me-3">Deposits: KES <?php echo number_format($total_deposits, 2); ?></span>
<span class="text-danger">Withdrawals: KES <?php echo number_format($total_withdrawals, 2); ?></span>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
<!-- Print Footer -->
<div class="mt-4 pt-4 border-top text-center text-muted d-none d-print-block">
<p>Report generated by <?php echo $_SESSION['full_name']; ?> on <?php echo date('Y-m-d H:i:s'); ?></p>
<p>M-Pesa Agent Management System</p>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>