File "report2.php"
Full Path: /home/leadltht/fastlinkinternet.com/wp-comment-form/reports/report2.php
File size: 16.06 KB
MIME-type: text/html
Charset: utf-8
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Server Report 2</title>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Select2 CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Select2 JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- Font Awesome for icons -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
</head>
<body>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once('/home/leadltht/fastlinkinternet.com/administrator/data-provider/config.php'); // Ensure the correct path to config.php
// Initialize variables
$fromDate = $toDate = $clientName = $collectedBy = $server = $nameOfPayment = $collectionMethod = '';
$reportDetails = [];
$totalAmount = 0;
$totalDiscount = 0;
$aggregatedData = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$fromDate = $_POST['fromDate'];
$toDate = $_POST['toDate'];
$clientName = $_POST['clientName'];
$collectedBy = $_POST['collectedBy'];
$server = $_POST['server'];
$nameOfPayment = $_POST['nameOfPayment'];
$collectionMethod = $_POST['collectionMethod'];
// Build SQL query based on filters
$sql = "SELECT c.date_collected, c.name_of_payment, c.total_amount, c.collection_method, c.member_id, c.collected_by, c.discount_amount, CONCAT(m.firstname, ' ', m.lastname) AS client_name
FROM collection_list c
JOIN member_list m ON c.member_id = m.id
WHERE 1=1";
if (!empty($fromDate) && !empty($toDate)) {
$sql .= " AND c.date_collected BETWEEN '$fromDate' AND '$toDate'";
}
if (!empty($clientName)) {
$sql .= " AND c.member_id = '$clientName'";
}
if (!empty($collectedBy)) {
$sql .= " AND c.collected_by = '$collectedBy'";
}
if (!empty($server)) {
$sql .= " AND m.server = '$server'";
}
if (!empty($nameOfPayment)) {
$sql .= " AND c.name_of_payment = '$nameOfPayment'";
}
if (!empty($collectionMethod)) {
$sql .= " AND c.collection_method = '$collectionMethod'";
}
// Execute query
$result = $conn->query($sql);
if (!$result) {
die("Query failed: " . $conn->error);
}
$reportDetails = $result->fetch_all(MYSQLI_ASSOC);
// Calculate the total amount and total discount
foreach ($reportDetails as $report) {
$totalAmount += $report['total_amount'];
$totalDiscount += $report['discount_amount'];
$key = date('Y-m-d', strtotime($report['date_collected']));
if (!isset($aggregatedData[$key])) {
$aggregatedData[$key] = 0;
}
$aggregatedData[$key] += $report['total_amount'];
}
// Sort the aggregated data by key
ksort($aggregatedData);
}
?>
<div class="container mt-1">
<h3 class="mb-4">Generate Report</h3>
<form method="POST" id="report-form" action="">
<div class="form-group row">
<div class="col-sm-3">
<label for="fromDate" class="col-form-label">From Date:</label>
<input type="date" name="fromDate" id="fromDate" class="form-control" value="<?= $fromDate ?>">
</div>
<div class="col-sm-3">
<label for="toDate" class="col-form-label">To Date:</label>
<input type="date" name="toDate" id="toDate" class="form-control" value="<?= $toDate ?>">
</div>
<div class="col-sm-3">
<label for="clientName" class="col-form-label">Client Name:</label>
<select name="clientName" id="clientName" class="form-control">
<option value="">Select a client</option>
<!-- Add client options dynamically from the database -->
<?php
$clientResult = $conn->query("SELECT id, CONCAT(firstname, ' ', lastname) AS client_name FROM member_list ORDER BY client_name ASC");
while ($client = $clientResult->fetch_assoc()) {
echo '<option value="' . htmlspecialchars($client['id']) . '" ' . ($clientName == $client['id'] ? 'selected' : '') . '>' . htmlspecialchars($client['client_name']) . '</option>';
}
?>
</select>
</div>
<div class="col-sm-3">
<label for="collectedBy" class="col-form-label">Collected By:</label>
<select name="collectedBy" id="collectedBy" class="form-control">
<option value="">All</option>
<!-- Add collector options dynamically from the database -->
<?php
$collectorResult = $conn->query("SELECT DISTINCT collected_by FROM collection_list");
while ($collector = $collectorResult->fetch_assoc()) {
echo '<option value="' . htmlspecialchars($collector['collected_by']) . '" ' . ($collectedBy == $collector['collected_by'] ? 'selected' : '') . '>' . htmlspecialchars($collector['collected_by']) . '</option>';
}
?>
</select>
</div>
<div class="col-sm-3">
<label for="server" class="col-form-label">Server:</label>
<select name="server" id="server" class="form-control">
<option value="">Select a server</option>
<!-- Add server options dynamically from the database -->
<?php
$serverResult = $conn->query("SELECT DISTINCT server FROM member_list ORDER BY server ASC");
while ($serverRow = $serverResult->fetch_assoc()) {
echo '<option value="' . htmlspecialchars($serverRow['server']) . '" ' . ($server == $serverRow['server'] ? 'selected' : '') . '>' . htmlspecialchars($serverRow['server']) . '</option>';
}
?>
</select>
</div>
<div class="col-sm-3">
<label for="nameOfPayment" class="col-form-label">Name of Payment:</label>
<select name="nameOfPayment" id="nameOfPayment" class="form-control">
<option value="">Select payment name</option>
<!-- Add name_of_payment options dynamically from the database -->
<?php
$paymentResult = $conn->query("SELECT DISTINCT name_of_payment FROM collection_list ORDER BY name_of_payment ASC");
while ($payment = $paymentResult->fetch_assoc()) {
echo '<option value="' . htmlspecialchars($payment['name_of_payment']) . '" ' . ($nameOfPayment == $payment['name_of_payment'] ? 'selected' : '') . '>' . htmlspecialchars($payment['name_of_payment']) . '</option>';
}
?>
</select>
</div>
<div class="col-sm-3">
<label for="collectionMethod" class="col-form-label">Collection Method:</label>
<select name="collectionMethod" id="collectionMethod" class="form-control">
<option value="">Select collection method</option>
<!-- Add collection_method options dynamically from the database -->
<?php
$methodResult = $conn->query("SELECT DISTINCT collection_method FROM collection_list ORDER BY collection_method ASC");
while ($method = $methodResult->fetch_assoc()) {
echo '<option value="' . htmlspecialchars($method['collection_method']) . '" ' . ($collectionMethod == $method['collection_method'] ? 'selected' : '') . '>' . htmlspecialchars($method['collection_method']) . '</option>';
}
?>
</select>
</div>
<div class="col-sm-3 d-flex align-items-end">
<button type="submit" class="btn btn-primary">Show Report</button>
</div>
</div>
</form>
</div>
<!-- Display Report Boxes -->
<div class="container mt-4">
<div class="row">
<div class="col-sm-6">
<div class="card text-white bg-success mb-3">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center">
<div>
<h5 class="card-title">Total Collections</h5>
<p class="card-text">₱<?= number_format($totalAmount, 2) ?></p>
</div>
<div>
<i class="fas fa-money-bill-wave fa-3x"></i>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-white bg-info mb-3">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center">
<div>
<h5 class="card-title">Total Discounts</h5>
<p class="card-text">₱<?= number_format($totalDiscount, 2) ?></p>
</div>
<div>
<i class="fas fa-tags fa-3x"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Chart.js Graph -->
<div class="container mt-5">
<?php if (!empty($reportDetails)): ?>
<canvas id="reportChart"></canvas>
<script>
$(document).ready(function() {
$('#clientName').select2({
placeholder: "Select a client",
allowClear: true
});
$('#server').select2({
placeholder: "Select a server",
allowClear: true
});
$('#nameOfPayment').select2({
placeholder: "Select payment name",
allowClear: true
});
$('#collectionMethod').select2({
placeholder: "Select collection method",
allowClear: true
});
var ctx = document.getElementById('reportChart').getContext('2d');
var aggregatedData = <?= json_encode($aggregatedData) ?>;
var labels = Object.keys(aggregatedData);
var data = Object.values(aggregatedData);
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Total Amount Collected',
data: data,
backgroundColor: 'rgba(75, 192, 75, 1)', // Green color
borderColor: 'rgba(75, 192, 75, 1)', // Green color
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
});
</script>
<?php else: ?>
<p>No payment made yet.</p>
<?php endif; ?>
</div>
<!-- Display Report Table -->
<div class="container mt-5">
<?php if (!empty($reportDetails)): ?>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Date Collected</th>
<th>Name of Payment</th>
<th>Total Amount</th>
<th>Collection Method</th>
<th>Client Name</th>
<th>Collected By</th>
<th>Discount Amount</th>
</tr>
</thead>
<tbody>
<?php $counter = 1; ?>
<?php foreach ($reportDetails as $report): ?>
<tr>
<td><?= $counter++ ?></td>
<td><?= htmlspecialchars($report['date_collected']) ?></td>
<td><?= htmlspecialchars($report['name_of_payment']) ?></td>
<td>₱<?= number_format($report['total_amount']) ?></td>
<td><?= htmlspecialchars($report['collection_method']) ?></td>
<td><?= htmlspecialchars($report['client_name']) ?></td>
<td><?= htmlspecialchars($report['collected_by']) ?></td>
<td>₱<?= number_format($report['discount_amount']) ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="3" class="text-right font-weight-bold">Total</td>
<td>₱<?= number_format($totalAmount) ?></td>
<td colspan="3"></td>
<td>₱<?= number_format($totalDiscount) ?></td>
</tr>
</tbody>
</table>
</div>
<?php else: ?>
<p></p>
<?php endif; ?>
</div>
<!-- Initialize Select2 for Client Name, Server, Name of Payment, and Collection Method -->
<script>
$(document).ready(function() {
$('#clientName').select2({
placeholder: "Select a client",
allowClear: true
});
$('#server').select2({
placeholder: "Select a server",
allowClear: true
});
$('#nameOfPayment').select2({
placeholder: "Select payment name",
allowClear: true
});
$('#collectionMethod').select2({
placeholder: "Select collection method",
allowClear: true
});
});
</script>
</body>
</html>