Files
MVE/public/verificar_pedimentos.php

46 lines
1.4 KiB
PHP

<?php
require_once __DIR__ . '/../config/database.php';
header('Content-Type: application/json; charset=utf-8');
try {
$conn = getConnection();
// Obtener todos los pedimentos existentes
$sql = "SELECT numero_pedimento, fecha_creacion, usuario_id FROM pedimentos ORDER BY fecha_creacion DESC";
$stmt = sqlsrv_query($conn, $sql);
$pedimentos_existentes = [];
if ($stmt !== false) {
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$pedimentos_existentes[] = $row;
}
sqlsrv_free_stmt($stmt);
}
// Obtener estadísticas
$sql_stats = "SELECT
COUNT(*) as total_pedimentos,
COUNT(DISTINCT usuario_id) as usuarios_distintos,
MIN(fecha_creacion) as primer_pedimento,
MAX(fecha_creacion) as ultimo_pedimento
FROM pedimentos";
$stmt_stats = sqlsrv_query($conn, $sql_stats);
$stats = sqlsrv_fetch_array($stmt_stats, SQLSRV_FETCH_ASSOC);
sqlsrv_free_stmt($stmt_stats);
sqlsrv_close($conn);
echo json_encode([
'success' => true,
'pedimentos_existentes' => $pedimentos_existentes,
'estadisticas' => $stats,
'total_encontrados' => count($pedimentos_existentes)
], JSON_PRETTY_PRINT);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}
?>