File: /home/bigisxfd/public_html/cowork/advanced-booking.php
<?php $resource_bind='';
// Include necessary files
include_once("header.php");
include_once("sidebar.php");
/**
* Fetch advanced (active=4) bookings along with balance from the Orders table.
* Adjust the SELECT fields & table names to match your schema exactly.
*/
function getAOnlineBookings() {
global $conn;
// Example query:
// - B = Bookings
// - M = Members
// - Ms = Memberships
// - O = Orders (left join to get 'balance')
// - Show only Bookings where active=4
// - If there's guaranteed 1 order per booking, you can use INNER JOIN instead of LEFT JOIN
$sql = "
SELECT
B.bookingid,
B.memberid,
B.startdate,
B.packageid,
B.active,
M.firstname,
M.lastname,
Ms.packagename,
Ms.price,
O.balance
FROM Bookings AS B
JOIN Members AS M ON B.memberid = M.memberid
JOIN Memberships AS Ms ON B.packageid = Ms.packageid
LEFT JOIN Orders AS O ON O.bookingid = B.bookingid
WHERE B.active = 4
ORDER BY B.bookingid DESC
";
$result = $conn->query($sql);
$bookings = [];
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$bookings[] = $row;
}
}
return $bookings;
}
// Fetch all active=4 (advanced) bookings
$onlineBookings = getAOnlineBookings();
?>
<section>
<div class="column">
<div style="display: flex; align-items: center; justify-content: space-between;">
<h2>Advanced Bookings</h2>
<button class="add-button" onclick="location.href='advance_booking.php'">Add New Booking</button>
</div>
<table>
<thead>
<tr>
<th>Booking ID</th>
<th>Member Name</th>
<th>Package Name</th>
<th>Start Date</th>
<th>Amount</th>
<th>Balance</th> <!-- New column for balance -->
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($onlineBookings as $booking): ?>
<tr>
<td><?php echo $booking['bookingid']; ?></td>
<td><?php echo $booking['firstname'] . ' ' . $booking['lastname']; ?></td>
<td><?php echo $booking['packagename']; ?></td>
<td><?php echo date("F j, Y H:i", strtotime($booking['startdate'])); ?></td>
<td><?php echo $booking['price']; ?></td>
<td>
<!-- If balance is NULL, display 0 or a message -->
<?php echo (isset($booking['balance'])) ? $booking['balance'] : '0'; ?>
</td>
<td>
<!-- Existing Confirm Button -->
<a class="checkout-link"
href="confirm-online.php?bookingId=<?php echo $booking['bookingid']; ?>
&PackageId=<?php echo $booking['packageid']; ?>
&packagename=<?php echo urlencode($booking['packagename']); ?>
&memberid=<?php echo $booking['memberid']; ?>"
style="background-color: lightgreen; padding: 6px; border-radius: 15px; font-size: 12px; margin-right:4px;">
Confirm
</a>
<!-- Conditionally show 'Add Payment' only if balance is greater than 0 -->
<?php if (isset($booking['balance']) && $booking['balance'] > 0): ?>
<a class="checkout-link"
href="partial_payment.php?bookingId=<?php echo $booking['bookingid']; ?>
&memberId=<?php echo $booking['memberid']; ?>"
style="background-color: lightblue; padding: 6px; border-radius: 15px; font-size: 12px;">
Add Payment
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($onlineBookings)): ?>
<tr>
<td colspan="7">No advance bookings found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</section>
</body>
</html>