UPDATE SOLICITUDES DE IMPO
SE AGREGARON CAMBIOS EN PROVEEDORES Y PARTIDAS EN LA SECCION DE SOLICITUDES DE IMPO
@@ -1,6 +1,70 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../../config/database.php';
|
require_once __DIR__ . '/../../config/database.php';
|
||||||
|
// 1) Composer autoload (phpdotenv y demás libs)
|
||||||
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
|
||||||
|
// 2) Carga nuestro helper de entorno y dispara la carga de .env
|
||||||
|
require_once __DIR__ . '/../helpers/env.php';
|
||||||
|
loadEnv();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene (y cachea en sesión) el JWT de la API usando las credenciales de $_ENV
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Obtiene (y cachea) el JWT de la API usando credenciales de $_ENV
|
||||||
|
* Gestiona expiración: asume 1 hora de vida y renueva si ha pasado.
|
||||||
|
*/
|
||||||
|
function getApiToken(): ?string
|
||||||
|
{
|
||||||
|
// Duración en segundos del token (60 min)
|
||||||
|
$ttl = 3600;
|
||||||
|
|
||||||
|
// 1) Si ya tenemos token y no ha expirado, lo devolvemos
|
||||||
|
if (!empty($_SESSION['api_token']) && !empty($_SESSION['api_token_time'])) {
|
||||||
|
$age = time() - $_SESSION['api_token_time'];
|
||||||
|
if ($age < $ttl) {
|
||||||
|
error_log("[getApiToken] Usando token en caché (edad: {$age}s)");
|
||||||
|
return $_SESSION['api_token'];
|
||||||
|
}
|
||||||
|
error_log("[getApiToken] Token expirado (edad: {$age}s), obteniendo uno nuevo");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) Sí o sí hacemos login en la API
|
||||||
|
$url = rtrim($_ENV['API_URL'] ?? '', '/') . '/auth/login';
|
||||||
|
$user = $_ENV['API_USER'] ?? '';
|
||||||
|
$pass = $_ENV['API_PASS'] ?? '';
|
||||||
|
$body = json_encode(['username' => $user, 'password' => $pass]);
|
||||||
|
|
||||||
|
error_log("[getApiToken] POST $url → $body");
|
||||||
|
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||||
|
CURLOPT_POSTFIELDS => $body,
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_TIMEOUT => 5,
|
||||||
|
]);
|
||||||
|
$resp = curl_exec($ch);
|
||||||
|
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
error_log("[getApiToken] HTTP $http → $resp");
|
||||||
|
|
||||||
|
if ($http === 200 && ($data = json_decode($resp, true)) && !empty($data['token'])) {
|
||||||
|
// 3) Guardamos token y tiempo actual
|
||||||
|
$_SESSION['api_token'] = $data['token'];
|
||||||
|
$_SESSION['api_token_time'] = time();
|
||||||
|
return $data['token'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4) Si no se pudo obtener, devolvemos null
|
||||||
|
error_log('[getApiToken] No se pudo obtener token de la API');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listado de solicitudes de importación (facturas) del importador logueado
|
* Listado de solicitudes de importación (facturas) del importador logueado
|
||||||
@@ -76,6 +140,13 @@ function crear() {
|
|||||||
$stmtI = sqlsrv_query($conn, "SELECT INCOTERM,DESCESPANOL FROM dbo.gIncoterms ORDER BY INCOTERM");
|
$stmtI = sqlsrv_query($conn, "SELECT INCOTERM,DESCESPANOL FROM dbo.gIncoterms ORDER BY INCOTERM");
|
||||||
while ($r = sqlsrv_fetch_array($stmtI, SQLSRV_FETCH_ASSOC)) { $incoterms[] = $r; }
|
while ($r = sqlsrv_fetch_array($stmtI, SQLSRV_FETCH_ASSOC)) { $incoterms[] = $r; }
|
||||||
|
|
||||||
|
$unidades_medida = [];
|
||||||
|
$stmtU = sqlsrv_query($conn, "SELECT id, descripcion FROM dbo.unidades_medida_apendice7 ORDER BY id");
|
||||||
|
while ($r = sqlsrv_fetch_array($stmtU, SQLSRV_FETCH_ASSOC)) {
|
||||||
|
$unidades_medida[] = $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
include __DIR__ . '/../../views/solicitud_importacion/crear.php';
|
include __DIR__ . '/../../views/solicitud_importacion/crear.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,11 +186,7 @@ function guardar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$conn = getConnection();
|
$conn = getConnection();
|
||||||
$sql = "INSERT INTO dbo.solicitud_importacion_factura
|
|
||||||
(id_importador,aduana,anexo22_apendice,numero_factura,fecha_factura,
|
|
||||||
numero_pedimento,incoterm,pais_proveedor,tipo_moneda,
|
|
||||||
valor_factura,vinculacion,transportista_id,chofer_id,foto_solicitud_url,status)
|
|
||||||
VALUES(?,?,?,?,?,NULL,?,?,?,?,?,?,?,?,?)";
|
|
||||||
$params=[
|
$params=[
|
||||||
$id_importador,
|
$id_importador,
|
||||||
$aduana_seccion,
|
$aduana_seccion,
|
||||||
@@ -136,25 +203,69 @@ function guardar() {
|
|||||||
$fotoUrl,
|
$fotoUrl,
|
||||||
$status
|
$status
|
||||||
];
|
];
|
||||||
$stmt=sqlsrv_query($conn,$sql,$params);
|
|
||||||
if($stmt===false) die("Error en guardar():".print_r(sqlsrv_errors(),true));
|
|
||||||
|
|
||||||
// Obtener nuevo ID
|
$sql = "INSERT INTO dbo.solicitud_importacion_factura
|
||||||
$idRow=sqlsrv_query($conn,'SELECT SCOPE_IDENTITY() AS id');
|
(id_importador, aduana, anexo22_apendice, numero_factura, fecha_factura,
|
||||||
$new=sqlsrv_fetch_array($idRow,SQLSRV_FETCH_ASSOC);
|
numero_pedimento, incoterm, pais_proveedor, tipo_moneda,
|
||||||
$id_solicitud=(int)$new['id'];
|
valor_factura, vinculacion, transportista_id, chofer_id, foto_solicitud_url, status)
|
||||||
|
OUTPUT INSERTED.id_solicitud
|
||||||
|
VALUES (?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
// Partidas
|
$stmt = sqlsrv_query($conn, $sql, $params, ['Scrollable' => SQLSRV_CURSOR_KEYSET]);
|
||||||
if(!empty($_POST['partidas'])&&is_array($_POST['partidas'])){
|
if ($stmt === false) {
|
||||||
$sqlP="INSERT INTO dbo.solicitud_importacion_partidas
|
die("❌ Error ejecutando INSERT con OUTPUT: " . print_r(sqlsrv_errors(), true));
|
||||||
(id_solicitud,descripcion,precio_unitario)
|
}
|
||||||
VALUES(?,?,?)";
|
|
||||||
foreach($_POST['partidas'] as $p){
|
$new = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
|
||||||
$d=trim($p['descripcion']??'');
|
if (!$new || empty($new['id_solicitud'])) {
|
||||||
$u=floatval($p['precio_unitario']??0);
|
die("❌ No se pudo recuperar el ID insertado de la factura.");
|
||||||
if($d!==''&&$u>0) sqlsrv_query($conn,$sqlP,[$id_solicitud,$d,$u]);
|
}
|
||||||
|
|
||||||
|
$id_solicitud = (int)$new['id_solicitud'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Partidas
|
||||||
|
if(!empty($_POST['partidas'])&&is_array($_POST['partidas'])){
|
||||||
|
|
||||||
|
$sqlP = "INSERT INTO dbo.solicitud_importacion_partidas
|
||||||
|
(id_solicitud, descripcion, cantidad_comercial, cantidad_tarifa, valor_factura, peso_bruto, unidad_comercial_id, tasa_preferencial)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
|
$partidas_insertadas = 0; // ← contador
|
||||||
|
|
||||||
|
foreach ($_POST['partidas'] as $i => $p) {
|
||||||
|
error_log("Partida $i: " . print_r($p, true));
|
||||||
|
$params = [
|
||||||
|
$id_solicitud,
|
||||||
|
trim($p['descripcion'] ?? ''),
|
||||||
|
|
||||||
|
floatval($p['cantidad_comercial'] ?? 0),
|
||||||
|
floatval($p['cantidad_tarifa'] ?? 0),
|
||||||
|
floatval($p['valor_factura'] ?? 0),
|
||||||
|
floatval($p['peso_bruto'] ?? 0),
|
||||||
|
intval($p['unidad_comercial_id'] ?? 0) ?: null,
|
||||||
|
|
||||||
|
trim($p['tasa_preferencial'] ?? '')
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($params[1] !== '' && $params[2] > 0) {
|
||||||
|
$stmtPartida = sqlsrv_query($conn, $sqlP, $params);
|
||||||
|
if ($stmtPartida === false) {
|
||||||
|
die("❌ Error insertando partida $i: " . print_r(sqlsrv_errors(), true));
|
||||||
|
} else {
|
||||||
|
$partidas_insertadas++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($partidas_insertadas === 0) {
|
||||||
|
///header('Location: /IMPORTADORES/solicitud_importacion/crear?error_partidas=1');
|
||||||
|
// exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
header('Location: /IMPORTADORES/solicitud_importacion/lista?created=ok');
|
header('Location: /IMPORTADORES/solicitud_importacion/lista?created=ok');
|
||||||
exit;
|
exit;
|
||||||
@@ -243,3 +354,110 @@ function eliminar() {
|
|||||||
header('Location: /IMPORTADORES/solicitud_importacion/lista?deleted=ok'); exit;
|
header('Location: /IMPORTADORES/solicitud_importacion/lista?deleted=ok'); exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /IMPORTADORES/solicitud_importacion/ajax_proveedores
|
||||||
|
* Devuelve JSON para poblar el select de Proveedor
|
||||||
|
*/
|
||||||
|
function ajax_proveedores()
|
||||||
|
{
|
||||||
|
// 1) Asegura que la respuesta sea JSON
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
// 2) Obtén o renueva tu token (usa tu función existente)
|
||||||
|
$token = getApiToken();
|
||||||
|
if (!$token) {
|
||||||
|
echo json_encode(['results' => []]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) Llama al endpoint de la API de proveedores
|
||||||
|
$apiBase = rtrim($_ENV['API_URL'] ?? '', '/');
|
||||||
|
$url = $apiBase . '/proveedores';
|
||||||
|
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_HTTPHEADER => ["Authorization: $token", 'Accept: application/json'],
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_TIMEOUT => 5,
|
||||||
|
]);
|
||||||
|
$resp = curl_exec($ch);
|
||||||
|
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// 4) Parsear y transformar al formato { results: [ {id,text}, … ] }
|
||||||
|
$out = ['results' => []];
|
||||||
|
if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) {
|
||||||
|
foreach ($json as $p) {
|
||||||
|
$out['results'][] = [
|
||||||
|
'id' => $p['Clave'] ?? '',
|
||||||
|
'text' => $p['Nombre'] ?? ''
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5) Devolver JSON
|
||||||
|
echo json_encode($out);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function ajax_lista()
|
||||||
|
{
|
||||||
|
// 1) Fijamos el header JSON
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
// 2) Obtener o renovar token
|
||||||
|
$token = getApiToken();
|
||||||
|
if (!$token) {
|
||||||
|
error_log('[ajax_lista] Sin token válido');
|
||||||
|
// Devolvemos estructura vacía
|
||||||
|
echo json_encode(['data' => []]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) Construimos la URL de la API
|
||||||
|
$apiBase = rtrim($_ENV['API_URL'] ?? '', '/');
|
||||||
|
$url = $apiBase . '/proveedores';
|
||||||
|
error_log("[ajax_lista] GET $url");
|
||||||
|
|
||||||
|
// 4) Ejecutamos cURL
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_HTTPHEADER => ["Authorization: $token", 'Accept: application/json'],
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_TIMEOUT => 5,
|
||||||
|
]);
|
||||||
|
$resp = curl_exec($ch);
|
||||||
|
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
error_log("[ajax_lista] HTTP $status → $resp");
|
||||||
|
|
||||||
|
// 5) Parseamos y formateamos
|
||||||
|
$dataList = [];
|
||||||
|
if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) {
|
||||||
|
foreach ($json as $p) {
|
||||||
|
$clave = htmlspecialchars($p['Clave'] ?? '', ENT_QUOTES);
|
||||||
|
$dataList[] = [
|
||||||
|
$clave,
|
||||||
|
htmlspecialchars($p['Nombre'] ?? '', ENT_QUOTES),
|
||||||
|
htmlspecialchars($p['RFC'] ?? '', ENT_QUOTES),
|
||||||
|
htmlspecialchars($p['Ciudad'] ?? '', ENT_QUOTES),
|
||||||
|
htmlspecialchars($p['Telefono']?? '', ENT_QUOTES),
|
||||||
|
// Acciones
|
||||||
|
"<a href=\"/IMPORTADORES/proveedores/editar?clave=" . rawurlencode($clave) . "\" class=\"btn btn-sm btn-primary\">✏️</a>
|
||||||
|
<button class=\"btn btn-sm btn-danger\" onclick=\"confirmDelete('{$clave}')\">🗑️</button>"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error_log('[ajax_lista] Respuesta inválida o status != 200');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6) Devolvemos siempre HTTP 200 con data (posiblemente vacío)
|
||||||
|
echo json_encode(['data' => $dataList]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
public/uploads/solicitud_682607050f254.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_682607fbdea70.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_682608ae85f77.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260955a3f7b.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260a67a7fd4.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260a7b905c2.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260ac172d75.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260aefd6a6b.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260b16ee0a6.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260b2f44292.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260b60d499f.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260b6866ad9.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68260baf2f4b2.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_68260c1ea84f6.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_68260c44c38af.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_68260fbd4b1e6.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_68260fdb457a6.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_6826249518e99.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_682624b518655.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_682625c0e0410.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_6826269a8efe0.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_682627a1f0f18.JPG
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/uploads/solicitud_68263deebe4d9.jpg
Normal file
|
After Width: | Height: | Size: 172 KiB |
BIN
public/uploads/solicitud_68263f38bc87e.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
public/uploads/solicitud_6826405aebfcc.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
public/uploads/solicitud_682640ff866b3.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
public/uploads/solicitud_6826414b95919.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
public/uploads/solicitud_682642069dcf8.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
public/uploads/solicitud_682643cc087e9.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
public/uploads/solicitud_682644c1ecc4d.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
@@ -5,6 +5,7 @@
|
|||||||
<title>➕ Nueva Solicitud de Importación</title>
|
<title>➕ Nueva Solicitud de Importación</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css"/>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||||
<style>
|
<style>
|
||||||
@@ -16,59 +17,34 @@
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
padding-top: 56px; /* Alineado con la altura de la navbar */
|
padding-top: 56px;
|
||||||
z-index: 1040; /* Asegura que esté por encima del contenido */
|
z-index: 1040;
|
||||||
}
|
}
|
||||||
.sidebar .nav-link {
|
.sidebar .nav-link {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: white;
|
color: white;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
}
|
}
|
||||||
.sidebar .nav-link:hover,
|
.sidebar .nav-link:hover, .sidebar .nav-link.active {
|
||||||
.sidebar .nav-link.active {
|
|
||||||
background-color: #495057;
|
background-color: #495057;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
.content {
|
.content {
|
||||||
margin-top: 56px; /* Ajusta debajo de navbar */
|
margin-top: 56px;
|
||||||
padding: 40px 20px;
|
padding: 40px 20px;
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
background-color: #f4f6f9; /* Asegura fondo uniforme */
|
background-color: #f4f6f9;
|
||||||
transition: margin-left 0.3s ease;
|
transition: margin-left 0.3s ease;
|
||||||
}
|
}
|
||||||
.navbar {
|
@media (min-width: 768px) { .content { margin-left: 250px; } }
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
width: 100%;
|
|
||||||
z-index: 1050;
|
|
||||||
}
|
|
||||||
/* A partir de dispositivos medianos (>=768px), deja espacio lateral */
|
|
||||||
@media (min-width: 768px) {
|
|
||||||
.content {
|
|
||||||
margin-left: 250px; /* Ancho del sidebar */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* En móviles, sin margen lateral */
|
|
||||||
@media (max-width: 767.98px) {
|
@media (max-width: 767.98px) {
|
||||||
.content {
|
.content { margin-left: 0; }
|
||||||
margin-left: 0;
|
.sidebar .nav-link { font-weight: normal; color: #343a40; background-color: transparent; }
|
||||||
}
|
.sidebar .nav-link:hover, .sidebar .nav-link.active { background-color: #e9ecef; color: #212529; }
|
||||||
.sidebar .nav-link {
|
|
||||||
font-weight: normal;
|
|
||||||
color: #343a40;
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
.sidebar .nav-link:hover,
|
|
||||||
.sidebar .nav-link.active {
|
|
||||||
background-color: #e9ecef;
|
|
||||||
color: #212529;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.card {
|
|
||||||
border-radius: 12px;
|
|
||||||
}
|
}
|
||||||
|
.card { border-radius: 12px; }
|
||||||
|
.hide { display: none !important; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -77,24 +53,32 @@
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<h4>➕ Nueva Solicitud de Importación</h4>
|
<h4>➕ Nueva Solicitud de Importación</h4>
|
||||||
<div class="card p-4 bg-white shadow-sm">
|
<div class="card p-4 bg-white shadow-sm">
|
||||||
<form action="/IMPORTADORES/solicitud_importacion/guardar" method="POST" enctype="multipart/form-data">
|
<form id="solicitudForm" action="/IMPORTADORES/solicitud_importacion/guardar" method="POST" enctype="multipart/form-data">
|
||||||
|
|
||||||
<!-- Sección principal -->
|
<!-- Sección principal -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-3 mb-3">
|
||||||
<label for="numero_factura" class="form-label">Número de Factura</label>
|
<label for="numero_factura" class="form-label">Número de Factura</label>
|
||||||
<input id="numero_factura" name="numero_factura" type="text" class="form-control" required>
|
<input id="numero_factura" name="numero_factura" type="text" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-3 mb-3">
|
||||||
<label for="fecha_factura" class="form-label">Fecha de Factura</label>
|
<label for="fecha_factura" class="form-label">Fecha de Factura</label>
|
||||||
<input id="fecha_factura" name="fecha_factura" type="date" class="form-control" required>
|
<input id="fecha_factura" name="fecha_factura" type="date" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-3 mb-3">
|
||||||
|
<label for="proveedor_id" class="form-label">Proveedor</label>
|
||||||
|
<select id="proveedor_id" name="proveedor_id" class="form-select searchable" required>
|
||||||
|
<option value="">Cargando proveedores…</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 mb-3">
|
||||||
<label for="anexo22_apendice" class="form-label">Anexo 22 – Apéndice</label>
|
<label for="anexo22_apendice" class="form-label">Anexo 22 – Apéndice</label>
|
||||||
<select id="anexo22_apendice" name="anexo22_apendice" class="form-select" required>
|
<select id="anexo22_apendice" name="anexo22_apendice" class="form-select searchable" required>
|
||||||
<option value="">-- Selecciona Aduana --</option>
|
<option value="">-- Selecciona Aduana --</option>
|
||||||
<?php foreach($aduanas as $a): ?>
|
<?php foreach($aduanas as $a): ?>
|
||||||
<option value="<?= $a['aduana_seccion'] ?>"><?= htmlspecialchars($a['aduana_seccion'].' – '.$a['nombre']) ?></option>
|
<option value="<?= htmlspecialchars($a['aduana_seccion']) ?>">
|
||||||
|
<?= htmlspecialchars($a['aduana_seccion'].' – '.$a['nombre']) ?>
|
||||||
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -104,25 +88,27 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="incoterm" class="form-label">INCOTERM</label>
|
<label for="incoterm" class="form-label">INCOTERM</label>
|
||||||
<select id="incoterm" name="incoterm" class="form-select" required>
|
<select id="incoterm" name="incoterm" class="form-select searchable" required>
|
||||||
<option value="">-- Selecciona Incoterm --</option>
|
<option value="">-- Selecciona Incoterm --</option>
|
||||||
<?php foreach($incoterms as $inc): ?>
|
<?php foreach($incoterms as $inc): ?>
|
||||||
<option value="<?= htmlspecialchars($inc['INCOTERM']) ?>"><?= htmlspecialchars($inc['INCOTERM'].' - '.$inc['DESCESPANOL']) ?></option>
|
<option value="<?= htmlspecialchars($inc['INCOTERM']) ?>">
|
||||||
|
<?= htmlspecialchars($inc['INCOTERM'].' - '.$inc['DESCESPANOL']) ?>
|
||||||
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="pais_proveedor" class="form-label">País (Proveedor)</label>
|
<label for="pais_proveedor" class="form-label">País (Proveedor)</label>
|
||||||
<select id="pais_proveedor" name="pais_proveedor" class="form-select">
|
<select id="pais_proveedor" name="pais_proveedor" class="form-select searchable">
|
||||||
<option value="">-- Selecciona País --</option>
|
<option value="">-- Selecciona País --</option>
|
||||||
<?php foreach($paises as $p): ?>
|
<?php foreach($paises as $p): ?>
|
||||||
<option value="<?= $p['id_pais'] ?>"><?= htmlspecialchars($p['nombre']) ?></option>
|
<option value="<?= htmlspecialchars($p['id_pais']) ?>"><?= htmlspecialchars($p['nombre']) ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="tipo_moneda" class="form-label">Moneda</label>
|
<label for="tipo_moneda" class="form-label">Moneda</label>
|
||||||
<select id="tipo_moneda" name="tipo_moneda" class="form-select">
|
<select id="tipo_moneda" name="tipo_moneda" class="form-select searchable">
|
||||||
<?php foreach(['MXN'=>'Peso Mexicano','USD'=>'Dólar USD','EUR'=>'Euro','CNY'=>'Yuan','GBP'=>'Libra GBP','JPY'=>'Yen'] as $code=>$label): ?>
|
<?php foreach(['MXN'=>'Peso Mexicano','USD'=>'Dólar USD','EUR'=>'Euro','CNY'=>'Yuan','GBP'=>'Libra GBP','JPY'=>'Yen'] as $code=>$label): ?>
|
||||||
<option value="<?= $code ?>"><?= "$label ($code)" ?></option>
|
<option value="<?= $code ?>"><?= "$label ($code)" ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -134,11 +120,11 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8 mb-3">
|
<div class="col-md-8 mb-3">
|
||||||
<label for="valor_factura" class="form-label">Valor Factura</label>
|
<label for="valor_factura" class="form-label">Valor Factura</label>
|
||||||
<input id="valor_factura" name="valor_factura" type="number" step="0.01" class="form-control">
|
<input id="valor_factura" name="valor_factura" type="number" step="0.01" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="vinculacion" class="form-label">Vinculación</label>
|
<label for="vinculacion" class="form-label">Vinculación</label>
|
||||||
<select id="vinculacion" name="vinculacion" class="form-select">
|
<select id="vinculacion" name="vinculacion" class="form-select searchable">
|
||||||
<option value="0">No existe</option>
|
<option value="0">No existe</option>
|
||||||
<option value="1">Existe, no afecta</option>
|
<option value="1">Existe, no afecta</option>
|
||||||
<option value="2">Existe y afecta</option>
|
<option value="2">Existe y afecta</option>
|
||||||
@@ -150,19 +136,19 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="transportista_id" class="form-label">Transportista</label>
|
<label for="transportista_id" class="form-label">Transportista</label>
|
||||||
<select id="transportista_id" name="transportista_id" class="form-select" required>
|
<select id="transportista_id" name="transportista_id" class="form-select searchable" required>
|
||||||
<option value="">-- Selecciona --</option>
|
<option value="">-- Selecciona --</option>
|
||||||
<?php foreach($transportistas as $t): ?>
|
<?php foreach($transportistas as $t): ?>
|
||||||
<option value="<?= $t['id_transportista'] ?>"><?= htmlspecialchars($t['nombre']) ?></option>
|
<option value="<?= htmlspecialchars($t['id_transportista']) ?>"><?= htmlspecialchars($t['nombre']) ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="chofer_id" class="form-label">Chofer</label>
|
<label for="chofer_id" class="form-label">Chofer</label>
|
||||||
<select id="chofer_id" name="chofer_id" class="form-select" required>
|
<select id="chofer_id" name="chofer_id" class="form-select searchable" required>
|
||||||
<option value="">-- Selecciona Chofer --</option>
|
<option value="">-- Selecciona Chofer --</option>
|
||||||
<?php foreach($choferes as $c): ?>
|
<?php foreach($choferes as $c): ?>
|
||||||
<option value="<?= $c['id_chofer'] ?>"><?= htmlspecialchars($c['nombre']) ?></option>
|
<option value="<?= htmlspecialchars($c['id_chofer']) ?>"><?= htmlspecialchars($c['nombre']) ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -177,12 +163,42 @@
|
|||||||
<h5>📦 Partidas</h5>
|
<h5>📦 Partidas</h5>
|
||||||
<table class="table table-sm" id="tabla-partidas">
|
<table class="table table-sm" id="tabla-partidas">
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th>Descripción</th><th>Precio Unitario</th><th></th></tr>
|
<tr>
|
||||||
|
<th>Descripción</th>
|
||||||
|
<th>Cantidad Comercial</th>
|
||||||
|
<th>Cantidad de Tarifa</th>
|
||||||
|
<th>Unidad Comercial</th>
|
||||||
|
<th>Valor Factura</th>
|
||||||
|
<th>Peso Bruto</th>
|
||||||
|
<th>Tasa Preferencial</th>
|
||||||
|
<th class="hide">Precio Unitario</th>
|
||||||
|
<th class="hide">OMA (Factura)</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><input name="partidas[0][descripcion]" class="form-control"></td>
|
<td><input name="partidas[0][descripcion]" class="form-control"></td>
|
||||||
<td><input name="partidas[0][precio_unitario]" type="number" step="0.01" class="form-control"></td>
|
<td><input name="partidas[0][cantidad_comercial]" type="number" step="0.0001" class="form-control"></td>
|
||||||
|
<td><input name="partidas[0][cantidad_tarifa]" type="number" step="0.0001" class="form-control"></td>
|
||||||
|
<td>
|
||||||
|
<select name="partidas[0][unidad_comercial_id]" class="form-select searchable">
|
||||||
|
<option value="">-- Unidad --</option>
|
||||||
|
<?php foreach($unidades_medida as $um): ?>
|
||||||
|
<option value="<?= htmlspecialchars($um['id']) ?>"><?= htmlspecialchars($um['descripcion']) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td><input name="partidas[0][valor_factura]" type="number" step="0.01" class="form-control valor-partida"></td>
|
||||||
|
<td><input name="partidas[0][peso_bruto]" type="number" step="0.0001" class="form-control"></td>
|
||||||
|
<td>
|
||||||
|
<select name="partidas[0][tasa_preferencial]" class="form-select searchable">
|
||||||
|
<option value="">-- Selecciona --</option>
|
||||||
|
<option>General</option><option>TLC</option><option>PROSEC</option><option>ALADI</option><option>COMERCIALIZADORA</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td class="hide"><input name="partidas[0][precio_unitario]" type="number" class="form-control"></td>
|
||||||
|
<td class="hide"><input name="partidas[0][oma_factura]" class="form-control"></td>
|
||||||
<td><button type="button" class="btn btn-danger btn-sm remove-row">✖️</button></td>
|
<td><button type="button" class="btn btn-danger btn-sm remove-row">✖️</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -202,21 +218,93 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Choices.js JS -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0/dist/js/select2.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// add-partida & validation script
|
||||||
document.getElementById('add-partida').addEventListener('click', () => {
|
document.getElementById('add-partida').addEventListener('click', () => {
|
||||||
const tbody = document.querySelector('#tabla-partidas tbody');
|
const tbody = document.querySelector('#tabla-partidas tbody');
|
||||||
const idx = tbody.querySelectorAll('tr').length;
|
const idx = tbody.querySelectorAll('tr').length;
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td><input name="partidas[\${idx}][descripcion]" class="form-control"></td>
|
<td><input name="partidas[${idx}][descripcion]" class="form-control"></td>
|
||||||
<td><input name="partidas[\${idx}][precio_unitario]" type="number" step="0.01" class="form-control"></td>
|
<td><input name="partidas[${idx}][cantidad_comercial]" type="number" step="0.0001" class="form-control"></td>
|
||||||
|
<td><input name="partidas[${idx}][cantidad_tarifa]" type="number" step="0.0001" class="form-control"></td>
|
||||||
|
<td>
|
||||||
|
<select name="partidas[${idx}][unidad_comercial_id]" class="form-select searchable">
|
||||||
|
<option value="">-- Unidad --</option>
|
||||||
|
<?php foreach($unidades_medida as $um): ?>
|
||||||
|
<option value="<?= htmlspecialchars($um['id']) ?>"><?= htmlspecialchars($um['descripcion']) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td><input name="partidas[${idx}][valor_factura]" type="number" step="0.01" class="form-control valor-partida"></td>
|
||||||
|
<td><input name="partidas[${idx}][peso_bruto]" type="number" step="0.0001" class="form-control"></td>
|
||||||
|
<td>
|
||||||
|
<select name="partidas[${idx}][tasa_preferencial]" class="form-select searchable">
|
||||||
|
<option value="">-- Selecciona --</option>
|
||||||
|
<option>General</option><option>TLC</option><option>PROSEC</option><option>ALADI</option><option>COMERCIALIZADORA</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td class="hide"><input name="partidas[${idx}][precio_unitario]" type="number" class="form-control"></td>
|
||||||
|
<td class="hide"><input name="partidas[${idx}][oma_factura]" class="form-control"></td>
|
||||||
<td><button type="button" class="btn btn-danger btn-sm remove-row">✖️</button></td>
|
<td><button type="button" class="btn btn-danger btn-sm remove-row">✖️</button></td>
|
||||||
`;
|
`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
|
// re-init Choices on new selects
|
||||||
|
row.querySelectorAll('.searchable').forEach(el => {
|
||||||
|
new Choices(el, { searchEnabled: true, itemSelectText: '', shouldSort: false });
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.querySelector('#tabla-partidas tbody').addEventListener('click', e => {
|
document.querySelector('#tabla-partidas tbody').addEventListener('click', e => {
|
||||||
if (e.target.matches('.remove-row')) e.target.closest('tr').remove();
|
if (e.target.matches('.remove-row')) e.target.closest('tr').remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// validate suma partidas == valor_factura
|
||||||
|
$('#solicitudForm').submit(function(e){
|
||||||
|
const total = parseFloat($('#valor_factura').val())||0;
|
||||||
|
let sum = 0;
|
||||||
|
$('.valor-partida').each(function(){ sum += parseFloat($(this).val())||0; });
|
||||||
|
if(Math.abs(sum - total) > 0.001){
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire({
|
||||||
|
icon:'error',
|
||||||
|
title:'Error de validación',
|
||||||
|
text:`La suma de partidas (${sum.toFixed(2)}) no coincide con Valor Factura (${total.toFixed(2)}).`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// proveedores script (no modificado)
|
||||||
|
document.querySelectorAll('.searchable').forEach(el => {
|
||||||
|
if (el.id !== 'proveedor_id') {
|
||||||
|
new Choices(el, { searchEnabled: true, itemSelectText: '', shouldSort: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const proveedorEl = document.getElementById('proveedor_id');
|
||||||
|
fetch('/IMPORTADORES/solicitud_importacion/ajax_proveedores')
|
||||||
|
.then(res => { if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json(); })
|
||||||
|
.then(json => {
|
||||||
|
proveedorEl.innerHTML = '<option value="">-- Selecciona Proveedor --</option>';
|
||||||
|
json.results.forEach(item => {
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = item.id; opt.text = item.text;
|
||||||
|
proveedorEl.add(opt);
|
||||||
|
});
|
||||||
|
if (proveedorEl._choice) proveedorEl._choice.destroy();
|
||||||
|
new Choices(proveedorEl, { searchEnabled: true, itemSelectText: '', shouldSort: false });
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error('Error cargando proveedores:', err);
|
||||||
|
proveedorEl.innerHTML = '<option value="">No fue posible cargar proveedores</option>';
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||