Merge branch 'main' of https://github.com/AduanaSoft/IMPORTADORES
This commit is contained in:
2
.env
2
.env
@@ -1,4 +1,4 @@
|
||||
DB_HOST=DESKTOP-22T88B6
|
||||
DB_HOST=localhost
|
||||
DB_DATABASE=Importaciones_HC
|
||||
DB_USERNAME=sa
|
||||
DB_PASSWORD=Soluciones01
|
||||
|
||||
@@ -310,7 +310,21 @@ function editar() {
|
||||
|
||||
// Partidas existentes
|
||||
$partidas=[];
|
||||
$stmtPar=sqlsrv_query($conn,"SELECT id_partida,descripcion,precio_unitario FROM dbo.solicitud_importacion_partidas WHERE id_solicitud=? ORDER BY id_partida",[(int)$id_solicitud]);
|
||||
$stmtPar = sqlsrv_query($conn,
|
||||
"SELECT
|
||||
id_partida,
|
||||
descripcion,
|
||||
cantidad_comercial,
|
||||
cantidad_tarifa,
|
||||
valor_factura,
|
||||
peso_bruto,
|
||||
unidad_comercial_id,
|
||||
tasa_preferencial
|
||||
FROM dbo.solicitud_importacion_partidas
|
||||
WHERE id_solicitud=?
|
||||
ORDER BY id_partida",
|
||||
[(int)$id_solicitud]
|
||||
);
|
||||
while($r=sqlsrv_fetch_array($stmtPar,SQLSRV_FETCH_ASSOC)) $partidas[]=$r;
|
||||
|
||||
include __DIR__ . '/../../views/solicitud_importacion/editar.php';
|
||||
@@ -320,27 +334,158 @@ function editar() {
|
||||
* Procesa la actualización de una factura y sus partidas
|
||||
*/
|
||||
function actualizar() {
|
||||
if (!($_SESSION['usuario_id'] ?? false)) die("⚠️ No autorizado.");
|
||||
$id_solicitud=(int)($_POST['id_solicitud']??0);
|
||||
// Validaciones similares a guardar()
|
||||
// ... omito por brevedad, copia de guardar() + UPDATE ...
|
||||
|
||||
$conn=getConnection();
|
||||
// Actualizar factura
|
||||
$sqlU = "UPDATE dbo.solicitud_importacion_factura SET
|
||||
aduana=?,anexo22_apendice=?,numero_factura=?,fecha_factura=?,incoterm=?,pais_proveedor=?,tipo_moneda=?,valor_factura=?,vinculacion=?,transportista_id=?,chofer_id=?,foto_solicitud_url=?,status=?,updated_at=GETDATE()
|
||||
WHERE id_solicitud=? AND id_importador=?";
|
||||
// Ejecutar UPDATE con parámetros
|
||||
// ...
|
||||
|
||||
// Borrar partidas previas
|
||||
sqlsrv_query($conn,"DELETE FROM dbo.solicitud_importacion_partidas WHERE id_solicitud=?",[$id_solicitud]);
|
||||
// Reinsertar partidas igual que guardar()
|
||||
// ...
|
||||
|
||||
header('Location: /IMPORTADORES/solicitud_importacion/lista?updated=ok'); exit;
|
||||
session_start();
|
||||
if (!($_SESSION['usuario_id'] ?? false)) {
|
||||
die("⚠️ No autorizado.");
|
||||
}
|
||||
|
||||
$id_solicitud = (int)($_POST['id_solicitud'] ?? 0);
|
||||
if ($id_solicitud <= 0) {
|
||||
die("❌ ID inválido.");
|
||||
}
|
||||
|
||||
// 1) Conexión
|
||||
$conn = getConnection();
|
||||
|
||||
// 2) Obtener URL de foto actual desde BD para conservar si no suben nueva
|
||||
$fotoUrl = null;
|
||||
$stmtFoto = sqlsrv_query(
|
||||
$conn,
|
||||
"SELECT foto_solicitud_url
|
||||
FROM dbo.solicitud_importacion_factura
|
||||
WHERE id_solicitud = ? AND id_importador = ?",
|
||||
[ $id_solicitud, $_SESSION['usuario_id'] ]
|
||||
);
|
||||
if ($stmtFoto !== false && ($row = sqlsrv_fetch_array($stmtFoto, SQLSRV_FETCH_ASSOC))) {
|
||||
$fotoUrl = $row['foto_solicitud_url'];
|
||||
}
|
||||
|
||||
// 3) Procesar posible nueva foto
|
||||
if (!empty($_FILES['foto_solicitud']['tmp_name'])
|
||||
&& $_FILES['foto_solicitud']['error'] === UPLOAD_ERR_OK) {
|
||||
$ext = pathinfo($_FILES['foto_solicitud']['name'], PATHINFO_EXTENSION);
|
||||
$dest = __DIR__ . '/../../public/uploads/solicitud_' . uniqid() . ".$ext";
|
||||
if (!is_dir(dirname($dest))) {
|
||||
mkdir(dirname($dest), 0755, true);
|
||||
}
|
||||
if (move_uploaded_file($_FILES['foto_solicitud']['tmp_name'], $dest)) {
|
||||
$fotoUrl = "/IMPORTADORES/public/uploads/" . basename($dest);
|
||||
}
|
||||
}
|
||||
|
||||
// 4) Extraer campos del formulario
|
||||
$aduana_seccion = $_POST['anexo22_apendice'] ?? null;
|
||||
$num_factura = trim($_POST['numero_factura'] ?? '');
|
||||
$fecha = $_POST['fecha_factura'] ?? null;
|
||||
$incoterm = $_POST['incoterm'] ?? null;
|
||||
$pais_proveedor = $_POST['pais_proveedor'] ?? null;
|
||||
$tipo_moneda = $_POST['tipo_moneda'] ?? null;
|
||||
$valor_factura = $_POST['valor_factura'] ?? null;
|
||||
$vinculacion = $_POST['vinculacion'] ?? 0;
|
||||
$transportista_id = (int)($_POST['transportista_id'] ?? 0);
|
||||
$chofer_id = (int)($_POST['chofer_id'] ?? 0);
|
||||
$status = isset($_POST['status']) ? 1 : 0;
|
||||
|
||||
// 5) Validar obligatorios
|
||||
if (empty($num_factura) || empty($fecha) || $transportista_id <= 0 || $chofer_id <= 0) {
|
||||
die("❌ Faltan campos obligatorios.");
|
||||
}
|
||||
|
||||
// 6) UPDATE de la cabecera
|
||||
$sqlU = "
|
||||
UPDATE dbo.solicitud_importacion_factura
|
||||
SET aduana = ?,
|
||||
anexo22_apendice = ?,
|
||||
numero_factura = ?,
|
||||
fecha_factura = ?,
|
||||
incoterm = ?,
|
||||
pais_proveedor = ?,
|
||||
tipo_moneda = ?,
|
||||
valor_factura = ?,
|
||||
vinculacion = ?,
|
||||
transportista_id = ?,
|
||||
chofer_id = ?,
|
||||
foto_solicitud_url = ?,
|
||||
status = ?,
|
||||
updated_at = GETDATE()
|
||||
WHERE id_solicitud = ?
|
||||
AND id_importador = ?
|
||||
";
|
||||
$paramsU = [
|
||||
$aduana_seccion,
|
||||
$aduana_seccion,
|
||||
$num_factura,
|
||||
$fecha,
|
||||
$incoterm,
|
||||
$pais_proveedor,
|
||||
$tipo_moneda,
|
||||
$valor_factura,
|
||||
$vinculacion,
|
||||
$transportista_id,
|
||||
$chofer_id,
|
||||
$fotoUrl,
|
||||
$status,
|
||||
$id_solicitud,
|
||||
$_SESSION['usuario_id']
|
||||
];
|
||||
$stmtU = sqlsrv_query($conn, $sqlU, $paramsU);
|
||||
if ($stmtU === false) {
|
||||
die("❌ Error ejecutando UPDATE: " . print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
// 7) Borrar partidas anteriores
|
||||
$del = sqlsrv_query(
|
||||
$conn,
|
||||
"DELETE FROM dbo.solicitud_importacion_partidas WHERE id_solicitud = ?",
|
||||
[ $id_solicitud ]
|
||||
);
|
||||
if ($del === false) {
|
||||
die("❌ Error borrando partidas previas: " . print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
// 8) Reinsertar partidas desde el formulario
|
||||
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 (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
";
|
||||
foreach ($_POST['partidas'] as $i => $p) {
|
||||
$desc = trim($p['descripcion'] ?? '');
|
||||
$cantCom = floatval($p['cantidad_comercial'] ?? 0);
|
||||
$cantTar = floatval($p['cantidad_tarifa'] ?? 0);
|
||||
$valPart = floatval($p['valor_factura'] ?? 0);
|
||||
$peso = floatval($p['peso_bruto'] ?? 0);
|
||||
$umId = intval($p['unidad_comercial_id'] ?? 0) ?: null;
|
||||
$tasaPref = trim($p['tasa_preferencial'] ?? '');
|
||||
|
||||
// Sólo inserta si descripción y cantidad comercial válidos
|
||||
if ($desc !== '' && $cantCom > 0) {
|
||||
$paramsP = [
|
||||
$id_solicitud,
|
||||
$desc,
|
||||
$cantCom,
|
||||
$cantTar,
|
||||
$valPart,
|
||||
$peso,
|
||||
$umId,
|
||||
$tasaPref
|
||||
];
|
||||
$stmtP = sqlsrv_query($conn, $sqlP, $paramsP);
|
||||
if ($stmtP === false) {
|
||||
die("❌ Error insertando partida #$i: " . print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 9) Redirigir
|
||||
header('Location: /IMPORTADORES/solicitud_importacion/lista?updated=ok');
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* “Soft-delete” de una factura
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ CREATE TABLE verificaciones (
|
||||
FOREIGN KEY (id_usuario) REFERENCES usuarios_sistema(id_usuario)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE correo_extra (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
id_usuario INT NOT NULL,
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>📤 Subir Archivos</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<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>
|
||||
<style>
|
||||
body { font-family: 'Segoe UI', sans-serif; background-color: #f4f6f9; }
|
||||
.content { margin-top: 56px; padding: 40px 20px; background-color: #f4f6f9; }
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>📂 Ver Expediente</title>
|
||||
<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">
|
||||
<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>
|
||||
@@ -21,7 +20,10 @@
|
||||
|
||||
<div class="card p-4 bg-white shadow-sm">
|
||||
<?php if (empty($archivos)): ?>
|
||||
|
||||
<p>No hay archivos subidos para esta solicitud.</p>
|
||||
<a href="/IMPORTADORES/expediente/subir/<?= $id_solicitud ?>" class="btn btn-success">➕ Subir archivos</a>
|
||||
|
||||
<?php else: ?>
|
||||
<div class="mb-3">
|
||||
<a href="/IMPORTADORES/expediente/descargar_zip/<?= $id_solicitud ?>" class="btn btn-outline-dark">📦 Descargar todo en ZIP</a>
|
||||
|
||||
@@ -89,6 +89,7 @@ $dos_factores_estado = obtenerEstadoDosFactores();
|
||||
<div class="col-md-7">
|
||||
<div class="card shadow-sm p-3">
|
||||
<h4 class="mb-4 text-dark">Autenticación de dos factores</h4>
|
||||
<p>Al activar esta funcionalidad, blindas el acceso a tu cuenta, recibiras un código de acceso a tu correo electrónico para confirmar identidad</p>
|
||||
<form method="post" action="/IMPORTADORES/seguridad/autenticacionDosFactores">
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input type="checkbox" name="dos_factores" id="dos_factores" class="form-check-input"
|
||||
|
||||
@@ -4,71 +4,26 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>✏️ Editar Solicitud #<?= (int)$factura['id_solicitud'] ?></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- Choices.js CSS -->
|
||||
<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/sweetalert2@11"></script>
|
||||
<style>
|
||||
body { font-family: 'Segoe UI', sans-serif; background-color: #f4f6f9; }
|
||||
.sidebar {
|
||||
width: 220px;
|
||||
height: 100vh;
|
||||
background-color: #343a40;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding-top: 56px; /* Alineado con la altura de la navbar */
|
||||
z-index: 1040; /* Asegura que esté por encima del contenido */
|
||||
}
|
||||
.sidebar .nav-link {
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
.sidebar .nav-link:hover,
|
||||
.sidebar .nav-link.active {
|
||||
background-color: #495057;
|
||||
color: #fff;
|
||||
}
|
||||
.content {
|
||||
margin-top: 56px; /* Ajusta debajo de navbar */
|
||||
padding: 40px 20px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
background-color: #f4f6f9; /* Asegura fondo uniforme */
|
||||
transition: margin-left 0.3s ease;
|
||||
}
|
||||
.navbar {
|
||||
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 */
|
||||
.sidebar { width: 220px; height: 100vh; background-color: #343a40; position: fixed; top: 0; left: 0; padding-top: 56px; z-index: 1040; }
|
||||
.sidebar .nav-link { font-weight: bold; color: white; transition: all 0.3s ease; }
|
||||
.sidebar .nav-link:hover, .sidebar .nav-link.active { background-color: #495057; color: #fff; }
|
||||
.content { margin-top: 56px; padding: 40px 20px; position: relative; z-index: 1; background-color: #f4f6f9; transition: margin-left 0.3s ease; }
|
||||
@media (min-width: 768px) { .content { margin-left: 250px; } }
|
||||
@media (max-width: 767.98px) {
|
||||
.content {
|
||||
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;
|
||||
}
|
||||
}
|
||||
.card {
|
||||
border-radius: 12px;
|
||||
.content { 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; }
|
||||
}
|
||||
.card { border-radius: 12px; }
|
||||
.hide { display: none !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -77,32 +32,33 @@
|
||||
<div class="content">
|
||||
<h4>✏️ Editar Solicitud #<?= (int)$factura['id_solicitud'] ?></h4>
|
||||
<div class="card p-4 bg-white shadow-sm">
|
||||
<form action="/IMPORTADORES/solicitud_importacion/actualizar" method="POST" enctype="multipart/form-data">
|
||||
<form id="solicitudForm" action="/IMPORTADORES/solicitud_importacion/actualizar" method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="id_solicitud" value="<?= (int)$factura['id_solicitud'] ?>">
|
||||
|
||||
<!-- Datos principales -->
|
||||
<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>
|
||||
<input id="numero_factura" name="numero_factura" type="text" class="form-control"
|
||||
value="<?= htmlspecialchars($factura['numero_factura']) ?>" required>
|
||||
<input id="numero_factura" name="numero_factura" type="text" class="form-control" required
|
||||
value="<?= htmlspecialchars($factura['numero_factura']) ?>">
|
||||
</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>
|
||||
<input id="fecha_factura" name="fecha_factura" type="date" class="form-control"
|
||||
value="<?=
|
||||
($factura['fecha_factura'] instanceof DateTime)
|
||||
? htmlspecialchars($factura['fecha_factura']->format('Y-m-d'))
|
||||
: htmlspecialchars($factura['fecha_factura'])
|
||||
?>" required>
|
||||
<input id="fecha_factura" name="fecha_factura" type="date" class="form-control" required
|
||||
value="<?= htmlspecialchars($factura['fecha_factura']) ?>">
|
||||
</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>
|
||||
<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>
|
||||
<?php foreach($aduanas as $a): ?>
|
||||
<option value="<?= $a['aduana_seccion'] ?>"
|
||||
<?= $factura['anexo22_apendice'] == $a['aduana_seccion'] ? 'selected' : '' ?>>
|
||||
<option value="<?= htmlspecialchars($a['aduana_seccion']) ?>" <?= $factura['anexo22_apendice']==$a['aduana_seccion']?'selected':'' ?>>
|
||||
<?= htmlspecialchars($a['aduana_seccion'].' – '.$a['nombre']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
@@ -110,14 +66,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Incoterm, País, Moneda -->
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="incoterm" class="form-label">INCOTERM</label>
|
||||
<select id="incoterm" name="incoterm" class="form-select">
|
||||
<select id="incoterm" name="incoterm" class="form-select searchable" required>
|
||||
<option value="">-- Selecciona Incoterm --</option>
|
||||
<?php foreach($incoterms as $inc): ?>
|
||||
<option value="<?= htmlspecialchars($inc['INCOTERM']) ?>"
|
||||
<?= $factura['incoterm'] === $inc['INCOTERM'] ? 'selected' : '' ?>>
|
||||
<option value="<?= htmlspecialchars($inc['INCOTERM']) ?>" <?= $factura['incoterm']==$inc['INCOTERM']?'selected':'' ?>>
|
||||
<?= htmlspecialchars($inc['INCOTERM'].' - '.$inc['DESCESPANOL']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
@@ -125,11 +81,10 @@
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<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>
|
||||
<?php foreach($paises as $p): ?>
|
||||
<option value="<?= $p['id_pais'] ?>"
|
||||
<?= $factura['pais_proveedor'] == $p['id_pais'] ? 'selected' : '' ?>>
|
||||
<option value="<?= htmlspecialchars($p['id_pais']) ?>" <?= $factura['pais_proveedor']==$p['id_pais']?'selected':'' ?>>
|
||||
<?= htmlspecialchars($p['nombre']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
@@ -137,12 +92,9 @@
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="tipo_moneda" class="form-label">Moneda</label>
|
||||
<select id="tipo_moneda" name="tipo_moneda" class="form-select">
|
||||
<?php
|
||||
$currs = ['MXN'=>'Peso Mexicano','USD'=>'Dólar USD','EUR'=>'Euro','CNY'=>'Yuan','GBP'=>'Libra GBP','JPY'=>'Yen'];
|
||||
foreach ($currs as $code => $label): ?>
|
||||
<option value="<?= $code ?>"
|
||||
<?= $factura['tipo_moneda']==$code ? 'selected' : '' ?>>
|
||||
<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): ?>
|
||||
<option value="<?= $code ?>" <?= $factura['tipo_moneda']==$code?'selected':'' ?>>
|
||||
<?= "$label ($code)" ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
@@ -150,15 +102,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Valor y Vinculación -->
|
||||
<div class="row">
|
||||
<div class="col-md-8 mb-3">
|
||||
<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 valor-total" required
|
||||
value="<?= htmlspecialchars($factura['valor_factura']) ?>">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<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" <?= $factura['vinculacion']==0?'selected':'' ?>>No existe</option>
|
||||
<option value="1" <?= $factura['vinculacion']==1?'selected':'' ?>>Existe, no afecta</option>
|
||||
<option value="2" <?= $factura['vinculacion']==2?'selected':'' ?>>Existe y afecta</option>
|
||||
@@ -166,13 +119,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Transporte y Foto -->
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<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>
|
||||
<?php foreach($transportistas as $t): ?>
|
||||
<option value="<?= $t['id_transportista'] ?>"
|
||||
<?= $factura['transportista_id']==$t['id_transportista']?'selected':'' ?>>
|
||||
<option value="<?= htmlspecialchars($t['id_transportista']) ?>" <?= $factura['transportista_id']==$t['id_transportista']?'selected':'' ?>>
|
||||
<?= htmlspecialchars($t['nombre']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
@@ -180,46 +134,100 @@
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<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>
|
||||
<?php foreach($choferes as $c): ?>
|
||||
<option value="<?= $c['id_chofer'] ?>"
|
||||
<?= $factura['chofer_id']==$c['id_chofer']?'selected':'' ?>>
|
||||
<option value="<?= htmlspecialchars($c['id_chofer']) ?>" <?= $factura['chofer_id']==$c['id_chofer']?'selected':'' ?>>
|
||||
<?= htmlspecialchars($c['nombre']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="foto_solicitud" class="form-label">Nueva Foto de la solicitud</label>
|
||||
<label for="foto_solicitud" class="form-label">Foto de la solicitud</label>
|
||||
<input id="foto_solicitud" name="foto_solicitud" type="file" class="form-control" accept="image/*">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Partidas dinámicas -->
|
||||
<!-- Partidas Dinámicas -->
|
||||
<hr>
|
||||
<h5>📦 Partidas</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm" id="tabla-partidas">
|
||||
<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>
|
||||
<tbody>
|
||||
<?php if (!empty($partidas)): ?>
|
||||
<?php foreach ($partidas as $i => $p): ?>
|
||||
<?php if (!empty($partidas)): foreach($partidas as $i=>$p): ?>
|
||||
<tr>
|
||||
<td><input name="partidas[<?= $i ?>][descripcion]" class="form-control" value="<?= htmlspecialchars($p['descripcion']) ?>"></td>
|
||||
<td><input name="partidas[<?= $i ?>][precio_unitario]" type="number" step="0.01" class="form-control" value="<?= htmlspecialchars($p['precio_unitario']) ?>"></td>
|
||||
<td><input name="partidas[<?= $i ?>][cantidad_comercial]" type="number" step="0.0001" class="form-control" value="<?= htmlspecialchars($p['cantidad_comercial']) ?>"></td>
|
||||
<td><input name="partidas[<?= $i ?>][cantidad_tarifa]" type="number" step="0.0001" class="form-control" value="<?= htmlspecialchars($p['cantidad_tarifa']) ?>"></td>
|
||||
<td>
|
||||
<select name="partidas[<?= $i ?>][unidad_comercial_id]" class="form-select searchable">
|
||||
<option value="">-- Unidad --</option>
|
||||
<?php foreach($unidades_medida as $um): ?>
|
||||
<option value="<?= htmlspecialchars($um['id']) ?>" <?= $p['unidad_comercial_id']==$um['id']?'selected':'' ?>>
|
||||
<?= htmlspecialchars($um['descripcion']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<td><input name="partidas[<?= $i ?>][valor_factura]" type="number" step="0.01" class="form-control valor-partida" value="<?= htmlspecialchars($p['valor_factura']) ?>"></td>
|
||||
<td><input name="partidas[<?= $i ?>][peso_bruto]" type="number" step="0.0001" class="form-control" value="<?= htmlspecialchars($p['peso_bruto']) ?>"></td>
|
||||
<td>
|
||||
<select name="partidas[<?= $i ?>][tasa_preferencial]" class="form-select searchable">
|
||||
<option value="">-- Selecciona --</option>
|
||||
<?php foreach(['General','TLC','PROSEC','ALADI','COMERCIALIZADORA'] as $tp): ?>
|
||||
<option <?= $p['tasa_preferencial']==$tp?'selected':'' ?>><?= $tp ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<td class="hide"><input name="partidas[<?= $i ?>][precio_unitario]" type="number" class="form-control" value="<?= htmlspecialchars($p['precio_unitario'] ?? '') ?>"></td>
|
||||
<td class="hide"><input name="partidas[<?= $i ?>][oma_factura]" class="form-control" value="<?= htmlspecialchars($p['oma_factura'] ?? '') ?>"></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm remove-row">✖️</button></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<?php endforeach; else: ?>
|
||||
<tr>
|
||||
<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>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button type="button" class="btn btn-secondary btn-sm mb-3" id="add-partida">➕ Agregar partida</button>
|
||||
|
||||
<!-- Activo -->
|
||||
@@ -228,27 +236,111 @@
|
||||
<label for="status" class="form-check-label">Activo</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Actualizar</button>
|
||||
<button type="submit" class="btn btn-success">Actualizar</button>
|
||||
<a href="/IMPORTADORES/solicitud_importacion/lista" class="btn btn-secondary ms-2">Cancelar</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Choices.js & jQuery -->
|
||||
<!-- 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>
|
||||
document.getElementById('add-partida').addEventListener('click', function() {
|
||||
var tbody = document.querySelector('#tabla-partidas tbody');
|
||||
var idx = tbody.querySelectorAll('tr').length;
|
||||
var row = document.createElement('tr');
|
||||
row.innerHTML = '<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><button type="button" class="btn btn-danger btn-sm remove-row">✖️</button></td>';
|
||||
tbody.appendChild(row);
|
||||
// 1) Inicializar Choices para todos los selects excepto proveedor_id
|
||||
document.querySelectorAll('.searchable:not(#proveedor_id)').forEach(el => {
|
||||
new Choices(el, { searchEnabled: true, itemSelectText: '', shouldSort: false });
|
||||
});
|
||||
document.querySelector('#tabla-partidas tbody').addEventListener('click', function(e) {
|
||||
|
||||
// 2) Cargar proveedores dinámicamente
|
||||
const proveedorEl = document.getElementById('proveedor_id');
|
||||
let proveedorChoices = null;
|
||||
|
||||
fetch('/IMPORTADORES/solicitud_importacion/ajax_proveedores')
|
||||
.then(res => res.ok ? res.json() : Promise.reject(res.status))
|
||||
.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);
|
||||
});
|
||||
// destruir instancia previa si existe
|
||||
if (proveedorChoices) proveedorChoices.destroy();
|
||||
proveedorChoices = new Choices(proveedorEl, {
|
||||
searchEnabled: true,
|
||||
itemSelectText: '',
|
||||
shouldSort: false
|
||||
});
|
||||
// seleccionar valor actual
|
||||
const current = '<?= htmlspecialchars($factura['proveedor_id'], ENT_QUOTES) ?>';
|
||||
if (current) {
|
||||
proveedorChoices.setChoiceByValue(current);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Error cargando proveedores:', err);
|
||||
proveedorEl.innerHTML = '<option value="">No fue posible cargar proveedores</option>';
|
||||
});
|
||||
|
||||
// 3) Agregar partida dinámica
|
||||
document.getElementById('add-partida').addEventListener('click', () => {
|
||||
const tbody = document.querySelector('#tabla-partidas tbody');
|
||||
const idx = tbody.querySelectorAll('tr').length;
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td><input name="partidas[\${idx}][descripcion]" 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>
|
||||
`;
|
||||
tbody.appendChild(row);
|
||||
// re-init Choices para nuevos selects
|
||||
row.querySelectorAll('.searchable').forEach(el => {
|
||||
new Choices(el, { searchEnabled: true, itemSelectText: '', shouldSort: false });
|
||||
});
|
||||
});
|
||||
|
||||
// 4) Remover partida
|
||||
document.querySelector('#tabla-partidas tbody').addEventListener('click', e => {
|
||||
if (e.target.matches('.remove-row')) {
|
||||
e.target.closest('tr').remove();
|
||||
}
|
||||
});
|
||||
|
||||
// 5) Validar suma de partidas
|
||||
$('#solicitudForm').submit(function(e) {
|
||||
const total = parseFloat($('.valor-total').val()) || 0;
|
||||
let sum = 0;
|
||||
$('.valor-partida').each(function() {
|
||||
sum += parseFloat($(this).val()) || 0;
|
||||
});
|
||||
if (Math.abs(sum - total) > 0.01) {
|
||||
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>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user