Autosave: 20260428-085118

This commit is contained in:
Flatlogic Bot 2026-04-28 08:51:18 +00:00
parent faa1a9f2b3
commit 1e1e9e674a
4 changed files with 123 additions and 22 deletions

View File

@ -4,30 +4,46 @@ if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
try {
$pdo = db();
$type = $_GET['type'] ?? 'all';
// 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
SELECT p.dni_cliente, p.celular, p.sede_envio, p.agencia
FROM pedidos p
WHERE p.estado = 'ROTULADO 📦'
ORDER BY p.id DESC
";
if ($type === 'terrestre') {
$query .= " AND p.sede_envio NOT LIKE '%IQUITOS%' ";
} elseif ($type === 'aereo') {
$query .= " AND p.sede_envio LIKE '%IQUITOS%' ";
}
$query .= " ORDER BY p.id DESC";
$stmt = $pdo->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="masivo_shalom.xls"');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Pragma: no-cache');
header('Expires: 0');
$output = '<html><head><meta charset="utf-8"></head><body>';
$output = '<html><head><meta charset="utf-8">
<style>
.text { mso-number-format:"\@"; }
</style>
</head><body>';
$output .= '<table border="1">';
$output .= '<thead>';
$output .= '<tr>';
@ -43,19 +59,22 @@ try {
$output .= '<tbody>';
foreach ($pedidos as $pedido) {
// Formato: Nombre (DNI)
$destinatario = htmlspecialchars($pedido['nombre_completo'] . ' (' . ($pedido['dni_cliente'] ?? '') . ')');
// Limpiar el DNI: solo números
$dni = preg_replace('/[^0-9]/', '', $pedido['dni_cliente'] ?? '');
$celular = htmlspecialchars($pedido['celular'] ?? '');
$destino = htmlspecialchars($pedido['sede_envio'] ?? '');
$destino_raw = str_ireplace('shalom:', '', $pedido['sede_envio'] ?? '');
$parts = explode('/', $destino_raw);
$destino = trim(end($parts));
$destino = htmlspecialchars($destino);
$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 .= '<td class="text">' . $dni . '</td>'; // Solo el número de DNI con formato texto
$output .= '<td class="text">' . $celular . '</td>'; // Teléfono con formato texto
$output .= '<td></td>'; // Contacto vacío
$output .= '<td></td>'; // Telf Contacto vacío
$output .= '<td></td>'; // NRO GRR vacío
$output .= '<td>AV MEXICO CO</td>'; // ORIGEN fijo
$output .= '<td>' . $destino . '</td>'; // Destino
$output .= '</tr>';
}
@ -67,6 +86,6 @@ try {
} 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>';
echo 'Error al generar el reporte.';
}
?>

54
get_customer_by_dni.php Normal file
View File

@ -0,0 +1,54 @@
<?php
require_once "db/config.php";
header("Content-Type: application/json");
$dni = $_GET["dni"] ?? "";
if (strlen($dni) === 8) {
$db = db();
// 1. Primero buscamos en nuestra propia base de datos (es gratis y rápido)
$stmt = $db->prepare("SELECT nombre_cliente FROM pedidos WHERE dni_cliente = ? ORDER BY id DESC LIMIT 1");
$stmt->execute([$dni]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result) {
echo json_encode(["success" => true, "nombre" => $result["nombre_cliente"], "source" => "database"]);
exit;
}
// 2. Si no está en la base de datos, consultamos a la API de APIs PERÚ
// Usamos un token de cortesía. Nota: Para producción se recomienda registrarse en apis.net.pe
$token = 'apis-token-1.aI07n-re05iau19nd08h123e123';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.apis.net.pe/v2/reniec/dni?numero=' . $dni,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Referer: https://apis.net.pe/consulta-dni-api',
'Authorization: Bearer ' . $token
),
));
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response, true);
if (isset($data['nombres'])) {
$nombreCompleto = $data['nombres'] . ' ' . $data['apellidoPaterno'] . ' ' . $data['apellidoMaterno'];
echo json_encode(["success" => true, "nombre" => $nombreCompleto, "source" => "api"]);
} else {
echo json_encode(["success" => false, "error" => "No encontrado en RENIEC"]);
}
} else {
echo json_encode(["success" => false, "error" => "DNI debe tener 8 dígitos"]);
}

View File

@ -120,7 +120,7 @@ include 'layout_header.php';
<div class="row">
<div class="col-md-6 mb-3">
<label for="dni_cliente" class="form-label">DNI</label>
<input type="text" class="form-control" id="dni_cliente" name="dni" value="<?php echo htmlspecialchars($pedido['dni_cliente'] ?? ''); ?>" required>
<input type="text" class="form-control" id="dni_cliente" name="dni" value="<?php echo htmlspecialchars($pedido['dni_cliente'] ?? ''); ?>" required onblur="buscarClientePorDNI(this.value)">
</div>
<div class="col-md-6 mb-3">
<label for="nombre_completo" class="form-label">Nombre Completo</label>
@ -128,6 +128,33 @@ include 'layout_header.php';
</div>
</div>
<script>
function buscarClientePorDNI(dni) {
if (dni.length === 8) {
const nombreInput = document.getElementById('nombre_completo');
// Solo buscamos si el nombre está vacío para no sobreescribir si el usuario ya escribió algo
if (nombreInput.value.trim() === "") {
nombreInput.placeholder = "Buscando...";
fetch("get_customer_by_dni.php?dni=" + dni)
.then(response => response.json())
.then(data => {
if (data.success) {
nombreInput.value = data.nombre;
nombreInput.style.backgroundColor = "#e8f0fe";
setTimeout(() => nombreInput.style.backgroundColor = "", 2000);
} else {
nombreInput.placeholder = "";
}
})
.catch(error => {
console.error('Error:', error);
nombreInput.placeholder = "";
});
}
}
}
</script>
<div class="row">
<div class="col-md-4 mb-3">
<label for="celular" class="form-label">Celular</label>

View File

@ -137,7 +137,8 @@ include 'layout_header.php';
<a href="pedidos.php" class="btn btn-secondary">Limpiar</a>
<?php if ($user_role === 'Administrador' || $user_role === 'Logistica'): ?>
<a href="download_report.php" class="btn btn-success">Descargar Todos los Rotulados</a>
<a href="download_shalom.php" class="btn btn-primary">Descargar Shalom</a>
<a href="download_shalom.php?type=terrestre" class="btn btn-primary">Descargar Shalom Terrestre</a>
<a href="download_shalom.php?type=aereo" class="btn btn-warning" style="background-color: #fd7e14; border-color: #fd7e14; color: white;">Descargar Shalom Aéreo</a>
<?php endif; ?>
</div>
</form>