22 lines
765 B
PHP
22 lines
765 B
PHP
<?php
|
|
require_once("connection.php");
|
|
|
|
if (isset($_POST['tab_id'])) {
|
|
$tab_id = (int) $_POST['tab_id']; // Ensure it's an integer
|
|
|
|
// Get the total from the bar_transactions table
|
|
$query = "SELECT SUM(item_price) AS total FROM bar_transactions WHERE tab_id = '$tab_id'";
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if ($result) {
|
|
$row = mysqli_fetch_assoc($result);
|
|
$total = $row['total'] ? $row['total'] : 0; // If no transactions, total is 0
|
|
echo json_encode(['status' => 'success', 'total' => $total]);
|
|
} else {
|
|
echo json_encode(['status' => 'error', 'message' => 'Failed to fetch total.']);
|
|
}
|
|
} else {
|
|
echo json_encode(['status' => 'error', 'message' => 'Missing tab ID.']);
|
|
}
|
|
?>
|