<?php
require 'config/database.php';
$pdo = getDBConnection();

$pid = 11; // Max Papel ID or let's search by name
$stmt = $pdo->prepare("SELECT id, NombreComercial FROM productos WHERE NombreComercial LIKE '%Max Papel%' LIMIT 1");
$stmt->execute();
$prod = $stmt->fetch();
if ($prod) {
    $pid = $prod['id'];
    echo "PRODUCT FOUND: {$prod['NombreComercial']} (ID: $pid)" . PHP_EOL . PHP_EOL;
} else {
    echo "Max Papel not found, checking all products in inventario_sucursal" . PHP_EOL;
}

echo "=== inventario_sucursal ===" . PHP_EOL;
$stmt = $pdo->prepare("SELECT * FROM inventario_sucursal WHERE producto_id = ?");
$stmt->execute([$pid]);
print_r($stmt->fetchAll());

echo "=== producto_lugares_compra ===" . PHP_EOL;
$stmt = $pdo->prepare("SELECT * FROM producto_lugares_compra WHERE producto_id = ?");
$stmt->execute([$pid]);
print_r($stmt->fetchAll());

echo "=== compras_detalle ===" . PHP_EOL;
$stmt = $pdo->prepare("SELECT * FROM compras_detalle WHERE producto_id = ?");
$stmt->execute([$pid]);
print_r($stmt->fetchAll());
