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 .= '| ' . $destinatario . ' | ';
- $output .= '' . $celular . ' | ';
- $output .= '' . $destinatario . ' | ';
- $output .= '' . $celular . ' | ';
- $output .= ' | '; // NRO GRR
- $output .= ' | '; // ORIGEN
- $output .= '' . $destino . ' | ';
+ $output .= '' . $dni . ' | '; // Solo el número de DNI con formato texto
+ $output .= '' . $celular . ' | '; // Teléfono con formato texto
+ $output .= ' | '; // Contacto vacío
+ $output .= ' | '; // Telf Contacto vacío
+ $output .= ' | '; // NRO GRR vacío
+ $output .= 'AV MEXICO CO | '; // ORIGEN fijo
+ $output .= '' . $destino . ' | '; // 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';
+
+