File: /home/bigisxfd/public_html/cowork/remittance.php
<?php
// Include necessary files
include_once("header.php");
include_once("sidebar.php");
?>
<style>
h1, h2, h3 {
text-align: left;
margin-bottom: 10px;
}
h2 {
text-align: right;
margin-bottom: 10px;
}
p {
text-align: left;
}
@media print
{
.no-print, .no-print *
{
display: none !important;
}
}
</style>
<section>
<div class="column">
<?php
// Initialize variables
$selectedDate = isset($_GET['selected_date']) ? $_GET['selected_date'] : date("Y-m-d");
// Query to fetch payment summary for the selected date
$sql = "SELECT mode, SUM(amount) as total_amount FROM Payments WHERE DATE(date) = '$selectedDate' GROUP BY mode";
$result = $conn->query($sql);
// Check for errors
if (!$result) {
die("Query failed: " . $conn->error);
}
// Display date filter form
echo "<form action='' method='get' class='no-print'>";
echo "Selected Date: <input type='date' name='selected_date' value='$selectedDate'>";
echo "<input type='submit' value='Generate Report'>";
echo "</form>";
// Display payment summary
echo "<h2>Remittance Report for $selectedDate</h2>"; ?>
<div>
<p>Big Ideas Cowork and Study</p>
<p>Address: 3rd floor Jomafer Building Dolores, San Fernando</p>
<p>Phone: 0917 134 1749</p>
<p>Email: pmsicat@bigideascowork.ph</p>
</div>
<br>
<h3>Payment Summary</h3>
<?php
// Check if there are any results
if ($result->num_rows > 0) {
echo "<table border='1'>";
echo "<tr><th>Mode</th><th>Total Amount</th></tr>";
$grandTotal = 0;
while ($row = $result->fetch_assoc()) {
$mode = $row['mode'];
$totalAmount = $row['total_amount'];
// Format the number with commas
$formattedTotalAmount = number_format($totalAmount);
echo "<tr><td>$mode</td><td>$formattedTotalAmount</td></tr>";
$grandTotal += $totalAmount;
}
// Format the grand total with commas
$formattedGrandTotal = number_format($grandTotal);
echo "<tr><td><b>Grand Total</b></td><td><b>$formattedGrandTotal</b></td></tr>";
echo "</table>";
} else {
echo "No payment data found for $selectedDate.";
}
?>
</div>
<div class="column">
<?php
// Initialize variables
$selectedDate = isset($_GET['selected_date']) ? $_GET['selected_date'] : date("Y-m-d");
// Query to fetch orders for the selected date
// Make sure we select o.bookingid and o.balance if they exist in Orders
$orderSql = "
SELECT
o.orderid,
o.items,
o.paymentid,
o.bookingid, -- Make sure we select this
o.balance, -- Make sure we select this
o.amount,
m.firstname,
m.lastname,
p.mode,
p.amount AS payment_amount,
p.date AS payment_date
FROM Orders o
JOIN Payments p ON o.paymentid = p.paymentid
JOIN Members m ON o.memberid = m.memberid
WHERE DATE(o.date) = '$selectedDate'
";
$orderResult = $conn->query($orderSql);
// Check for errors
if (!$orderResult) {
die("Query failed: " . $conn->error);
}
echo "<h3>Orders Summary</h3>";
if ($orderResult->num_rows > 0) {
echo "<table border='1'>";
echo "<tr>
<th>Order ID</th>
<th>Items</th>
<th>Payment ID</th>
<th>Payment Mode</th>
<th>Payment Date</th>
<th>Member Name</th>
<th>Amount</th>
</tr>";
$orderTotal = 0;
while ($orderRow = $orderResult->fetch_assoc()) {
$orderId = $orderRow['orderid'];
$items = $orderRow['items'];
$paymentId = $orderRow['paymentid'];
$paymentMode = $orderRow['mode'];
$paymentDate = $orderRow['payment_date'];
$memberName = $orderRow['firstname'] . ' ' . $orderRow['lastname'];
// Original amount from Orders
$amount = $orderRow['payment_amount'];
// Check if there's a non-zero balance
$balance = isset($orderRow['balance']) ? $orderRow['balance'] : 0;
// If user still has a non-zero balance, append partial info to Payment Mode
if ($balance > 0) {
// Insert the bookingid in the string
$paymentMode .= " (Partial for Booking ID " . $orderRow['bookingid'] . ")";
}
// If the mode is 'Voucher', set amount = 0
if ($paymentMode === 'Voucher') {
$amount = 0;
}
// Format the amount with commas
$formattedAmount = number_format($amount);
echo "<tr>
<td>$orderId</td>
<td>$items</td>
<td>$paymentId</td>
<td>$paymentMode</td>
<td>$paymentDate</td>
<td>$memberName</td>
<td>$formattedAmount</td>
</tr>";
$orderTotal += $amount;
}
$formattedOrderTotal = number_format($orderTotal);
echo "<tr>
<td colspan='6'><b>Total</b></td>
<td><b>$formattedOrderTotal</b></td>
</tr>";
echo "</table>";
} else {
echo "No orders found for $selectedDate.";
}
?>
</div>
<div class="column">
<?php
// Initialize variables
$selectedDate = isset($_GET['selected_date']) ? $_GET['selected_date'] : date("Y-m-d");
// Query to fetch usage report for members who logged in on the selected date with active status=1
$usageSql = "SELECT b.bookingid, m.firstname, m.lastname, b.startdate, b.enddate, b.paymentid, p.mode, p.date AS payment_date, b.login, mship.packagename
FROM Bookings b
JOIN Members m ON b.memberid = m.memberid
LEFT JOIN Payments p ON b.paymentid = p.paymentid
LEFT JOIN Memberships mship ON b.packageid = mship.packageid
WHERE DATE(b.login) = '$selectedDate' AND b.login IS NOT NULL";
$usageResult = $conn->query($usageSql);
// Check for errors
if (!$usageResult) {
die("Query failed: " . $conn->error);
}
// Display usage report
echo "<h3>Usage Summary</h3>";
// Check if there are any results
if ($usageResult->num_rows > 0) {
echo "<table border='1'>";
echo "<tr><th>Booking ID</th><th>Member Name</th><th>Start Date</th><th>End Date</th><th>Payment ID</th><th>Payment Mode</th><th>Payment Date</th><th>Package Name</th><th>Login Date</th></tr>";
while ($usageRow = $usageResult->fetch_assoc()) {
$bookingId = $usageRow['bookingid'];
$memberName = $usageRow['firstname'] . ' ' . $usageRow['lastname'];
$startDate = $usageRow['startdate'];
$endDate = $usageRow['enddate'];
$paymentId = $usageRow['paymentid'];
$paymentMode = $usageRow['mode'];
$paymentDate = $usageRow['payment_date'];
$packageName = $usageRow['packagename'];
$loginDate = $usageRow['login'];
echo "<tr><td>$bookingId</td><td>$memberName</td><td>$startDate</td><td>$endDate</td><td>$paymentId</td><td>$paymentMode</td><td>$paymentDate</td><td>$packageName</td><td>$loginDate</td></tr>";
}
echo "</table>";
} else {
echo "No usage data found for $selectedDate with active=1 and login date not null.";
}
?>
</div>
</section>
</body>
</html>