prepare($query); $stmt->execute(); $pedidos = $stmt->fetchAll(PDO::FETCH_ASSOC); $filename = "masivo_shalom"; if ($type === 'terrestre') $filename .= "_terrestre"; if ($type === 'aereo') $filename .= "_aereo"; $filename .= ".xls"; header('Content-Type: application/vnd.ms-excel; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Pragma: no-cache'); header('Expires: 0'); $output = ' '; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; foreach ($pedidos as $pedido) { // Limpiar el DNI: solo números $dni = preg_replace('/[^0-9]/', '', $pedido['dni_cliente'] ?? ''); $celular = htmlspecialchars($pedido['celular'] ?? ''); $destino_raw = str_ireplace('shalom:', '', $pedido['sede_envio'] ?? ''); $parts = explode('/', $destino_raw); $destino = trim(end($parts)); $destino = htmlspecialchars($destino); $output .= ''; $output .= ''; // Solo el número de DNI con formato texto $output .= ''; // Teléfono con formato texto $output .= ''; // Contacto vacío $output .= ''; // Telf Contacto vacío $output .= ''; // NRO GRR vacío $output .= ''; // ORIGEN fijo $output .= ''; // Destino $output .= ''; } $output .= ''; $output .= '
DESTINATARIO (DOC)TELF. DESTINATARIOCONTACTO (DOC)TELF. CONTACTONRO GRRORIGENDESTINO
' . $dni . '' . $celular . 'AV MEXICO CO' . $destino . '
'; $output .= ''; echo $output; } catch (Exception $e) { header('HTTP/1.1 500 Internal Server Error'); echo 'Error al generar el reporte.'; } ?>