<?php
require_once 'conexao.php';
require_once 'config.php';

$usuario = (isset($_GET['id'])) ? $_GET['id'] : '';

$pdo  = Conexao::getInstance();
$sql = "SELECT DISTINCT i.hash_pedido, v.ven_024 as tipo, v.ven_025 as mesa, v.ven_026 as comanda, v.ven_027 as obs ";
$sql .= "FROM vendaitem i INNER JOIN venda v ON i.ven_001 = v.ven_001 ";
$sql .= "WHERE v.ven_024 IN ('M', 'C') AND i.sit_001 <> 2 AND v.sit_001 = 8 AND i.status_monitor = 1 AND i.celular_notificado = 0 AND i.gar_001 = {$usuario}";
$stm = $pdo->prepare($sql);
$stm->execute();
$pedidos = $stm->fetchAll(PDO::FETCH_OBJ);

if (empty($pedidos)):
    http_response_code(404);
    echo json_encode(['status' => 404, 'retorno' => 'Não existem pedidos']);
else:
    http_response_code(202);
    echo json_encode(['status' => 202, 'retorno' => $pedidos]);
endif;
?>