Code restructure push
This commit is contained in:
24
src/api/get_tab_total.php
Normal file
24
src/api/get_tab_total.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
$rootPath = dirname(dirname(__DIR__));
|
||||
require_once($rootPath . "/src/config/env.php");
|
||||
require_once($rootPath . "/src/config/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.']);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user