From 1e1e9e674a2c63331dbb8675c9748d0e3b84cffe Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 28 Apr 2026 08:51:18 +0000 Subject: [PATCH] Autosave: 20260428-085118 --- download_shalom.php | 59 +++++++++++++++++++++++++++-------------- get_customer_by_dni.php | 54 +++++++++++++++++++++++++++++++++++++ pedido_form.php | 29 +++++++++++++++++++- pedidos.php | 3 ++- 4 files changed, 123 insertions(+), 22 deletions(-) create mode 100644 get_customer_by_dni.php diff --git a/download_shalom.php b/download_shalom.php index 217eee9..a233c02 100644 --- a/download_shalom.php +++ b/download_shalom.php @@ -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 - FROM pedidos p - WHERE p.estado = 'ROTULADO 📦' - ORDER BY p.id DESC + SELECT p.dni_cliente, p.celular, p.sede_envio, p.agencia + FROM pedidos p + WHERE p.estado = 'ROTULADO 📦' "; + 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 = ''; + $output = ' + + '; $output .= ''; $output .= ''; $output .= ''; @@ -43,19 +59,22 @@ try { $output .= ''; 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 .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; // NRO GRR - $output .= ''; // ORIGEN - $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 .= ''; } @@ -67,6 +86,6 @@ try { } catch (Exception $e) { header('HTTP/1.1 500 Internal Server Error'); - echo ''; + echo 'Error al generar el reporte.'; } ?> \ No newline at end of file diff --git a/get_customer_by_dni.php b/get_customer_by_dni.php new file mode 100644 index 0000000..8f80545 --- /dev/null +++ b/get_customer_by_dni.php @@ -0,0 +1,54 @@ +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"]); +} diff --git a/pedido_form.php b/pedido_form.php index 5a39938..7e2b971 100644 --- a/pedido_form.php +++ b/pedido_form.php @@ -120,7 +120,7 @@ include 'layout_header.php';
- +
@@ -128,6 +128,33 @@ include 'layout_header.php';
+ +
diff --git a/pedidos.php b/pedidos.php index 1edd031..c2bbd0a 100644 --- a/pedidos.php +++ b/pedidos.php @@ -137,7 +137,8 @@ include 'layout_header.php'; Limpiar Descargar Todos los Rotulados - Descargar Shalom + Descargar Shalom Terrestre + Descargar Shalom Aéreo
' . $destinatario . '' . $celular . '' . $destinatario . '' . $celular . '' . $destino . '' . $dni . '' . $celular . 'AV MEXICO CO' . $destino . '