<?php
// ajax/consultar_totales_mesas.php
require '../conexion.php';

$totales = [
  'efectivo' => 0,
  'transferencia' => 0,
  'total' => 0
];

$query = "SELECT SUM(efectivo) as efectivo, SUM(transferencia) as transferencia FROM caja_mesa";
$result = $con->query($query);
if ($row = $result->fetch_assoc()) {
  $totales['efectivo'] = floatval($row['efectivo']);
  $totales['transferencia'] = floatval($row['transferencia']);
  $totales['total'] = $totales['efectivo'] + $totales['transferencia'];
}

header('Content-Type: application/json');
echo json_encode($totales);
?>
