34849-vm/download_shalom.php
2026-04-28 08:20:31 +00:00

72 lines
2.2 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
try {
$pdo = db();
// Filtramos solo los pedidos que están en estado 'ROTULADO 📦'
$query = "
SELECT p.dni_cliente, p.nombre_completo, p.celular, p.sede_envio, p.agencia
FROM pedidos p
WHERE p.estado = 'ROTULADO 📦'
ORDER BY p.id DESC
";
$stmt = $pdo->prepare($query);
$stmt->execute();
$pedidos = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/vnd.ms-excel; charset=utf-8');
header('Content-Disposition: attachment; filename="masivo_shalom.xls"');
header('Pragma: no-cache');
header('Expires: 0');
$output = '<html><head><meta charset="utf-8"></head><body>';
$output .= '<table border="1">';
$output .= '<thead>';
$output .= '<tr>';
$output .= '<th>DESTINATARIO (DOC)</th>';
$output .= '<th>TELF. DESTINATARIO</th>';
$output .= '<th>CONTACTO (DOC)</th>';
$output .= '<th>TELF. CONTACTO</th>';
$output .= '<th>NRO GRR</th>';
$output .= '<th>ORIGEN</th>';
$output .= '<th>DESTINO</th>';
$output .= '</tr>';
$output .= '</thead>';
$output .= '<tbody>';
foreach ($pedidos as $pedido) {
// Formato: Nombre (DNI)
$destinatario = htmlspecialchars($pedido['nombre_completo'] . ' (' . ($pedido['dni_cliente'] ?? '') . ')');
$celular = htmlspecialchars($pedido['celular'] ?? '');
$destino = htmlspecialchars($pedido['sede_envio'] ?? '');
$output .= '<tr>';
$output .= '<td>' . $destinatario . '</td>';
$output .= '<td>' . $celular . '</td>';
$output .= '<td>' . $destinatario . '</td>';
$output .= '<td>' . $celular . '</td>';
$output .= '<td></td>'; // NRO GRR
$output .= '<td></td>'; // ORIGEN
$output .= '<td>' . $destino . '</td>';
$output .= '</tr>';
}
$output .= '</tbody>';
$output .= '</table>';
$output .= '</body></html>';
echo $output;
} catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
echo '<script>alert("Ocurrió un error al generar el reporte para Shalom."); window.history.back();</script>';
}
?>