Files
MVE/public/debug_partidas.php

152 lines
5.8 KiB
PHP

<?php
session_start();
require_once '../config/database.php';
if (!isset($_SESSION['usuario_id'])) {
die("Error: No hay sesión activa");
}
echo "<!DOCTYPE html>
<html lang='es'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Debug - Partidas de Pedimentos</title>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
<div class='container mt-4'>
<h2>Debug - Últimas Partidas Insertadas</h2>";
try {
$conn = conectarBD();
// Obtener las últimas partidas con información del pedimento
$sql = "SELECT TOP 20
pp.id,
pp.secuencia,
pp.fraccion_arancelaria,
pp.descripcion,
pp.cantidad,
pp.unidad,
pp.valor_unitario,
pp.valor_total,
pp.peso_neto,
pp.peso_bruto,
pp.fecha_creacion,
p.numero_pedimento
FROM pedimento_partidas pp
INNER JOIN pedimentos p ON pp.pedimento_id = p.id
ORDER BY pp.fecha_creacion DESC";
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false) {
throw new Exception("Error en consulta: " . print_r(sqlsrv_errors(), true));
}
echo "<div class='table-responsive'>
<table class='table table-striped table-hover'>
<thead class='table-dark'>
<tr>
<th>ID</th>
<th>Pedimento</th>
<th>Secuencia</th>
<th>Fracción</th>
<th>Descripción</th>
<th>Cantidad</th>
<th>Unidad</th>
<th>Valor Unit.</th>
<th>Valor Total</th>
<th>Peso Neto</th>
<th>Peso Bruto</th>
<th>Fecha</th>
</tr>
</thead>
<tbody>";
$contador = 0;
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$contador++;
echo "<tr>
<td>{$row['id']}</td>
<td><strong>{$row['numero_pedimento']}</strong></td>
<td>{$row['secuencia']}</td>
<td><code>{$row['fraccion_arancelaria']}</code></td>
<td>" . (strlen($row['descripcion']) > 50 ? substr($row['descripcion'], 0, 50) . '...' : $row['descripcion']) . "</td>
<td>" . number_format($row['cantidad'], 4) . "</td>
<td>{$row['unidad']}</td>
<td>" . number_format($row['valor_unitario'], 4) . "</td>
<td>" . number_format($row['valor_total'], 4) . "</td>
<td>" . ($row['peso_neto'] ? number_format($row['peso_neto'], 4) : 'NULL') . "</td>
<td>" . ($row['peso_bruto'] ? number_format($row['peso_bruto'], 4) : 'NULL') . "</td>
<td>{$row['fecha_creacion']->format('Y-m-d H:i:s')}</td>
</tr>";
}
echo "</tbody></table></div>";
if ($contador == 0) {
echo "<div class='alert alert-warning'>No se encontraron partidas en la base de datos.</div>";
} else {
echo "<div class='alert alert-info'>Se encontraron $contador partidas.</div>";
}
// Estadísticas adicionales
$sql_stats = "SELECT
COUNT(*) as total_partidas,
COUNT(DISTINCT pedimento_id) as total_pedimentos,
AVG(cantidad) as promedio_cantidad,
AVG(valor_unitario) as promedio_valor_unitario
FROM pedimento_partidas";
$stmt_stats = sqlsrv_query($conn, $sql_stats);
if ($stmt_stats && $stats = sqlsrv_fetch_array($stmt_stats, SQLSRV_FETCH_ASSOC)) {
echo "<div class='row mt-4'>
<div class='col-md-3'>
<div class='card text-center'>
<div class='card-body'>
<h5 class='card-title'>Total Partidas</h5>
<p class='card-text display-6'>{$stats['total_partidas']}</p>
</div>
</div>
</div>
<div class='col-md-3'>
<div class='card text-center'>
<div class='card-body'>
<h5 class='card-title'>Total Pedimentos</h5>
<p class='card-text display-6'>{$stats['total_pedimentos']}</p>
</div>
</div>
</div>
<div class='col-md-3'>
<div class='card text-center'>
<div class='card-body'>
<h5 class='card-title'>Promedio Cantidad</h5>
<p class='card-text display-6'>" . number_format($stats['promedio_cantidad'], 2) . "</p>
</div>
</div>
</div>
<div class='col-md-3'>
<div class='card text-center'>
<div class='card-body'>
<h5 class='card-title'>Promedio Valor Unit.</h5>
<p class='card-text display-6'>" . number_format($stats['promedio_valor_unitario'], 2) . "</p>
</div>
</div>
</div>
</div>";
}
sqlsrv_close($conn);
} catch (Exception $e) {
echo "<div class='alert alert-danger'>Error: " . $e->getMessage() . "</div>";
}
echo "</div>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js'></script>
</body>
</html>";
?>