diff --git a/app/controllers/patente.php b/app/controllers/patente.php
index 5343775..9055ec5 100644
--- a/app/controllers/patente.php
+++ b/app/controllers/patente.php
@@ -69,25 +69,26 @@ function guardar()
$mf_paterno = trim($_POST['mf_paterno'] ?? '');
$mf_materno = trim($_POST['mf_materno'] ?? '');
- $vp_inicio = (int)($_POST['vp_inicio'] ?? 0);
- $vp_final = (int)($_POST['vp_final'] ?? 0);
- $vp_siguiente = (int)($_POST['vp_siguiente'] ?? 0);
+ // Ahora manejamos como VARCHAR - permitir vacío o valor válido
+ $vp_inicio = trim($_POST['vp_inicio'] ?? '');
+ $vp_final = trim($_POST['vp_final'] ?? '');
+ $vp_siguiente = trim($_POST['vp_siguiente'] ?? '');
- $vpe_inicio = (int)($_POST['vpe_inicio'] ?? 0);
- $vpe_final = (int)($_POST['vpe_final'] ?? 0);
- $vpe_siguiente = (int)($_POST['vpe_siguiente'] ?? 0);
+ $vpe_inicio = trim($_POST['vpe_inicio'] ?? '');
+ $vpe_final = trim($_POST['vpe_final'] ?? '');
+ $vpe_siguiente = trim($_POST['vpe_siguiente'] ?? '');
- $vat_pb_inicio = (int)($_POST['vat_pb_inicio'] ?? 0);
- $vat_pb_final = (int)($_POST['vat_pb_final'] ?? 0);
- $vat_pb_siguiente = (int)($_POST['vat_pb_siguiente'] ?? 0);
+ $vat_pb_inicio = trim($_POST['vat_pb_inicio'] ?? '');
+ $vat_pb_final = trim($_POST['vat_pb_final'] ?? '');
+ $vat_pb_siguiente = trim($_POST['vat_pb_siguiente'] ?? '');
- $vcc_inicio = (int)($_POST['vcc_inicio'] ?? 0);
- $vcc_final = (int)($_POST['vcc_final'] ?? 0);
- $vcc_siguiente = (int)($_POST['vcc_siguiente'] ?? 0);
+ $vcc_inicio = trim($_POST['vcc_inicio'] ?? '');
+ $vcc_final = trim($_POST['vcc_final'] ?? '');
+ $vcc_siguiente = trim($_POST['vcc_siguiente'] ?? '');
- $vae_inicio = (int)($_POST['vae_inicio'] ?? 0);
- $vae_final = (int)($_POST['vae_final'] ?? 0);
- $vae_siguiente = (int)($_POST['vae_siguiente'] ?? 0);
+ $vae_inicio = trim($_POST['vae_inicio'] ?? '');
+ $vae_final = trim($_POST['vae_final'] ?? '');
+ $vae_siguiente = trim($_POST['vae_siguiente'] ?? '');
// Validaciones generales
if (empty($aduana) || empty($patente) || empty($agente_aduanal) || empty($rfc) || empty($curp) || empty($razon_social)) {
@@ -99,6 +100,32 @@ function guardar()
if (strlen($rfc) > 13) die("❌ El RFC no puede exceder 13 caracteres.");
if (strlen($curp) > 18) die("❌ El CURP no puede exceder 18 caracteres.");
+ // Validaciones para campos de folios - ahora son VARCHAR(10)
+ function validarFolio($valor, $campo) {
+ if (!empty($valor)) {
+ if (strlen($valor) > 10) die("❌ El campo {$campo} no puede exceder 10 caracteres.");
+ // Opcional: Si quieres mantener solo números, descomenta la siguiente línea
+ // if (!is_numeric($valor)) die("❌ El campo {$campo} debe ser numérico.");
+ }
+ }
+
+ // Validar todos los campos de folios
+ validarFolio($vp_inicio, 'VP Inicio');
+ validarFolio($vp_final, 'VP Final');
+ validarFolio($vp_siguiente, 'VP Siguiente');
+ validarFolio($vpe_inicio, 'VPE Inicio');
+ validarFolio($vpe_final, 'VPE Final');
+ validarFolio($vpe_siguiente, 'VPE Siguiente');
+ validarFolio($vat_pb_inicio, 'VAT PB Inicio');
+ validarFolio($vat_pb_final, 'VAT PB Final');
+ validarFolio($vat_pb_siguiente, 'VAT PB Siguiente');
+ validarFolio($vcc_inicio, 'VCC Inicio');
+ validarFolio($vcc_final, 'VCC Final');
+ validarFolio($vcc_siguiente, 'VCC Siguiente');
+ validarFolio($vae_inicio, 'VAE Inicio');
+ validarFolio($vae_final, 'VAE Final');
+ validarFolio($vae_siguiente, 'VAE Siguiente');
+
// Validar duplicado para este usuario
$sqlCheck = "SELECT COUNT(*) as count FROM dbo.agentes_aduanales WHERE aduana = ? AND patente = ? AND id_usuario = ?";
$stmtCheck = sqlsrv_query($conn, $sqlCheck, [$aduana, $patente, $id_usuario]);
@@ -110,6 +137,23 @@ function guardar()
sqlsrv_free_stmt($stmtCheck);
+ // Convertir valores vacíos a NULL para la base de datos
+ $vp_inicio = empty($vp_inicio) ? null : $vp_inicio;
+ $vp_final = empty($vp_final) ? null : $vp_final;
+ $vp_siguiente = empty($vp_siguiente) ? null : $vp_siguiente;
+ $vpe_inicio = empty($vpe_inicio) ? null : $vpe_inicio;
+ $vpe_final = empty($vpe_final) ? null : $vpe_final;
+ $vpe_siguiente = empty($vpe_siguiente) ? null : $vpe_siguiente;
+ $vat_pb_inicio = empty($vat_pb_inicio) ? null : $vat_pb_inicio;
+ $vat_pb_final = empty($vat_pb_final) ? null : $vat_pb_final;
+ $vat_pb_siguiente = empty($vat_pb_siguiente) ? null : $vat_pb_siguiente;
+ $vcc_inicio = empty($vcc_inicio) ? null : $vcc_inicio;
+ $vcc_final = empty($vcc_final) ? null : $vcc_final;
+ $vcc_siguiente = empty($vcc_siguiente) ? null : $vcc_siguiente;
+ $vae_inicio = empty($vae_inicio) ? null : $vae_inicio;
+ $vae_final = empty($vae_final) ? null : $vae_final;
+ $vae_siguiente = empty($vae_siguiente) ? null : $vae_siguiente;
+
// Insertar registro
$sql = "INSERT INTO dbo.agentes_aduanales
(aduana, patente, agente_aduanal, rfc, curp, razon_social, id_usuario, activo,
@@ -187,6 +231,7 @@ function actualizar()
$conn = getConnection();
+ // Capturar campos del formulario - Datos generales
$id_agente = (int)($_POST['id_agente'] ?? 0);
$aduana = trim($_POST['aduana'] ?? '');
$patente = trim($_POST['patente'] ?? '');
@@ -200,25 +245,26 @@ function actualizar()
$mf_paterno = trim($_POST['mf_paterno'] ?? '');
$mf_materno = trim($_POST['mf_materno'] ?? '');
- $vp_inicio = (int)($_POST['vp_inicio'] ?? 0);
- $vp_final = (int)($_POST['vp_final'] ?? 0);
- $vp_siguiente = (int)($_POST['vp_siguiente'] ?? 0);
+ // Ahora manejamos como VARCHAR - permitir vacío o valor válido
+ $vp_inicio = trim($_POST['vp_inicio'] ?? '');
+ $vp_final = trim($_POST['vp_final'] ?? '');
+ $vp_siguiente = trim($_POST['vp_siguiente'] ?? '');
- $vpe_inicio = (int)($_POST['vpe_inicio'] ?? 0);
- $vpe_final = (int)($_POST['vpe_final'] ?? 0);
- $vpe_siguiente = (int)($_POST['vpe_siguiente'] ?? 0);
+ $vpe_inicio = trim($_POST['vpe_inicio'] ?? '');
+ $vpe_final = trim($_POST['vpe_final'] ?? '');
+ $vpe_siguiente = trim($_POST['vpe_siguiente'] ?? '');
- $vat_pb_inicio = (int)($_POST['vat_pb_inicio'] ?? 0);
- $vat_pb_final = (int)($_POST['vat_pb_final'] ?? 0);
- $vat_pb_siguiente = (int)($_POST['vat_pb_siguiente'] ?? 0);
+ $vat_pb_inicio = trim($_POST['vat_pb_inicio'] ?? '');
+ $vat_pb_final = trim($_POST['vat_pb_final'] ?? '');
+ $vat_pb_siguiente = trim($_POST['vat_pb_siguiente'] ?? '');
- $vcc_inicio = (int)($_POST['vcc_inicio'] ?? 0);
- $vcc_final = (int)($_POST['vcc_final'] ?? 0);
- $vcc_siguiente = (int)($_POST['vcc_siguiente'] ?? 0);
+ $vcc_inicio = trim($_POST['vcc_inicio'] ?? '');
+ $vcc_final = trim($_POST['vcc_final'] ?? '');
+ $vcc_siguiente = trim($_POST['vcc_siguiente'] ?? '');
- $vae_inicio = (int)($_POST['vae_inicio'] ?? 0);
- $vae_final = (int)($_POST['vae_final'] ?? 0);
- $vae_siguiente = (int)($_POST['vae_siguiente'] ?? 0);
+ $vae_inicio = trim($_POST['vae_inicio'] ?? '');
+ $vae_final = trim($_POST['vae_final'] ?? '');
+ $vae_siguiente = trim($_POST['vae_siguiente'] ?? '');
if (!$id_agente || empty($aduana) || empty($patente) || empty($agente_aduanal) || empty($rfc) || empty($curp) || empty($razon_social)) {
die("❌ Datos inválidos o incompletos.");
@@ -241,6 +287,23 @@ function actualizar()
sqlsrv_free_stmt($stmtCheck);
+ // Convertir valores vacíos a NULL para la base de datos
+ $vp_inicio = empty($vp_inicio) ? null : $vp_inicio;
+ $vp_final = empty($vp_final) ? null : $vp_final;
+ $vp_siguiente = empty($vp_siguiente) ? null : $vp_siguiente;
+ $vpe_inicio = empty($vpe_inicio) ? null : $vpe_inicio;
+ $vpe_final = empty($vpe_final) ? null : $vpe_final;
+ $vpe_siguiente = empty($vpe_siguiente) ? null : $vpe_siguiente;
+ $vat_pb_inicio = empty($vat_pb_inicio) ? null : $vat_pb_inicio;
+ $vat_pb_final = empty($vat_pb_final) ? null : $vat_pb_final;
+ $vat_pb_siguiente = empty($vat_pb_siguiente) ? null : $vat_pb_siguiente;
+ $vcc_inicio = empty($vcc_inicio) ? null : $vcc_inicio;
+ $vcc_final = empty($vcc_final) ? null : $vcc_final;
+ $vcc_siguiente = empty($vcc_siguiente) ? null : $vcc_siguiente;
+ $vae_inicio = empty($vae_inicio) ? null : $vae_inicio;
+ $vae_final = empty($vae_final) ? null : $vae_final;
+ $vae_siguiente = empty($vae_siguiente) ? null : $vae_siguiente;
+
// UPDATE
$sql = "UPDATE dbo.agentes_aduanales SET
aduana = ?, patente = ?, agente_aduanal = ?, rfc = ?, curp = ?, razon_social = ?,
diff --git a/app/controllers/solicitud_importacion.php b/app/controllers/solicitud_importacion.php
index a3740d7..db2561b 100644
--- a/app/controllers/solicitud_importacion.php
+++ b/app/controllers/solicitud_importacion.php
@@ -663,10 +663,14 @@ function actualizar() {
/** “Soft-delete” de una factura **/
function eliminar() {
- if (!($_SESSION['usuario_id'] ?? false)) { header('Location: /IMPORTADORES/login'); exit; }
- $id=(int)($_GET['id']??0);
- $conn=getConnection();
- sqlsrv_query($conn,"UPDATE dbo.solicitud_importacion_factura SET status=0,updated_at=GETDATE() WHERE id_solicitud=? AND id_importador=?",[$id,$_SESSION['usuario_id']]);
+ if (!($_SESSION['usuario_id'] ?? false)) {
+ header('Location: /IMPORTADORES/login');
+ exit;
+ }
+ $id = (int) ($_GET['id'] ?? 0);
+ $conn = getConnection();
+ sqlsrv_query($conn, "UPDATE dbo.solicitud_importacion_factura SET status = 0, updated_at = GETDATE() WHERE id_solicitud = ? AND id_importador = ?",[$id,$_SESSION['usuario_id']]);
+
header('Location: /IMPORTADORES/solicitud_importacion/lista?deleted=ok'); exit;
}
diff --git a/patentes.txt b/patentes.txt
index ecc8e02..94b7125 100644
--- a/patentes.txt
+++ b/patentes.txt
@@ -12,20 +12,20 @@ CREATE TABLE agentes_aduanales (
mf_nombre VARCHAR(50),
mf_paterno VARCHAR(50),
mf_materno VARCHAR(50),
- vp_inicio INT DEFAULT 0,
- vp_final INT DEFAULT 0,
- vp_siguiente INT DEFAULT 0,
- vpe_inicio INT DEFAULT 0,
- vpe_final INT DEFAULT 0,
- vpe_siguiente INT DEFAULT 0,
- vat_pb_inicio INT DEFAULT 0,
- vat_pb_final INT DEFAULT 0,
- vat_pb_siguiente INT DEFAULT 0,
- vcc_inicio INT DEFAULT 0,
- vcc_final INT DEFAULT 0,
- vcc_siguiente INT DEFAULT 0,
- vae_inicio INT DEFAULT 0,
- vae_final INT DEFAULT 0,
- vae_siguiente INT DEFAULT 0
+ vp_inicio VARCHAR(10) NULL DEFAULT '000',
+ vp_final VARCHAR(10) NULL DEFAULT '000',
+ vp_siguiente VARCHAR(10) NULL DEFAULT '000',
+ vpe_inicio VARCHAR(10) NULL DEFAULT '000',
+ vpe_final VARCHAR(10) NULL DEFAULT '000',
+ vpe_siguiente VARCHAR(10) NULL DEFAULT '000',
+ vat_pb_inicio VARCHAR(10) NULL DEFAULT '000',
+ vat_pb_final VARCHAR(10) NULL DEFAULT '000',
+ vat_pb_siguiente VARCHAR(10) NULL DEFAULT '000',
+ vcc_inicio VARCHAR(10) NULL DEFAULT '000',
+ vcc_final VARCHAR(10) NULL DEFAULT '000',
+ vcc_siguiente VARCHAR(10) NULL DEFAULT '000',
+ vae_inicio VARCHAR(10) NULL DEFAULT '000',
+ vae_final VARCHAR(10) NULL DEFAULT '000',
+ vae_siguiente VARCHAR(10) NULL DEFAULT '000'
FOREIGN KEY (id_usuario) REFERENCES usuarios_sistema(id_usuario)
)
\ No newline at end of file
diff --git a/views/patente/alta_patente.php b/views/patente/alta_patente.php
index 8687229..641890b 100644
--- a/views/patente/alta_patente.php
+++ b/views/patente/alta_patente.php
@@ -154,17 +154,17 @@
-
+
-
+
-
+
@@ -174,17 +174,17 @@
-
+
-
+
-
+
@@ -194,17 +194,17 @@
-
+
-
+
-
+
@@ -214,17 +214,17 @@
-
+
-
+
-
+
@@ -234,17 +234,17 @@
-
+
-
+
-
+
@@ -327,105 +327,55 @@
return;
}
- const vp_inicio = document.getElementById('vp_inicio').value;
- const vp_final = document.getElementById('vp_final').value;
- const vp_siguiente = document.getElementById('vp_siguiente').value;
- const vpe_inicio = document.getElementById('vpe_inicio').value;
- const vpe_final = document.getElementById('vpe_final').value;
- const vpe_siguiente = document.getElementById('vpe_siguiente').value;
- const vat_pb_inicio = document.getElementById('vat_pb_inicio').value;
- const vat_pb_final = document.getElementById('vat_pb_final').value;
- const vat_pb_siguiente = document.getElementById('vat_pb_siguiente').value;
- const vcc_inicio = document.getElementById('vcc_inicio').value;
- const vcc_final = document.getElementById('vcc_final').value;
- const vcc_siguiente = document.getElementById('vcc_siguiente').value;
- const vae_inicio = document.getElementById('vae_inicio').value;
- const vae_final = document.getElementById('vae_final').value;
- const vae_siguiente = document.getElementById('vae_siguiente').value;
+ // Obtener campos de folios (ahora VARCHAR)
+ const folios = [
+ { id: 'vp_inicio', nombre: 'VP Inicio' },
+ { id: 'vp_final', nombre: 'VP Final' },
+ { id: 'vp_siguiente', nombre: 'VP Siguiente' },
+ { id: 'vpe_inicio', nombre: 'VPE Inicio' },
+ { id: 'vpe_final', nombre: 'VPE Final' },
+ { id: 'vpe_siguiente', nombre: 'VPE Siguiente' },
+ { id: 'vat_pb_inicio', nombre: 'VAT PB Inicio' },
+ { id: 'vat_pb_final', nombre: 'VAT PB Final' },
+ { id: 'vat_pb_siguiente', nombre: 'VAT PB Siguiente' },
+ { id: 'vcc_inicio', nombre: 'VCC Inicio' },
+ { id: 'vcc_final', nombre: 'VCC Final' },
+ { id: 'vcc_siguiente', nombre: 'VCC Siguiente' },
+ { id: 'vae_inicio', nombre: 'VAE Inicio' },
+ { id: 'vae_final', nombre: 'VAE Final' },
+ { id: 'vae_siguiente', nombre: 'VAE Siguiente' }
+ ];
- // Validaciones Números de Validación y Folios
- if (vp_inicio !== '' && !soloNumerosRegex.test(vp_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vp_inicio').focus();
- return;
- }
- if (vp_final !== '' && !soloNumerosRegex.test(vp_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vp_final').focus();
- return;
- }
- if (vp_siguiente !== '' && !soloNumerosRegex.test(vp_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vp_siguiente').focus();
- return;
- }
- if (vpe_inicio !== '' && !soloNumerosRegex.test(vpe_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vpe_inicio').focus();
- return;
- }
- if (vpe_final !== '' && !soloNumerosRegex.test(vpe_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vpe_final').focus();
- return;
- }
- if (vpe_siguiente !== '' && !soloNumerosRegex.test(vpe_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vpe_siguiente').focus();
- return;
- }
- if (vat_pb_inicio !== '' && !soloNumerosRegex.test(vat_pb_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vat_pb_inicio').focus();
- return;
- }
- if (vat_pb_final !== '' && !soloNumerosRegex.test(vat_pb_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vat_pb_final').focus();
- return;
- }
- if (vat_pb_siguiente !== '' && !soloNumerosRegex.test(vat_pb_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vat_pb_siguiente').focus();
- return;
- }
- if (vcc_inicio !== '' && !soloNumerosRegex.test(vcc_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vcc_inicio').focus();
- return;
- }
- if (vcc_final !== '' && !soloNumerosRegex.test(vcc_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vcc_final').focus();
- return;
- }
- if (vcc_siguiente !== '' && !soloNumerosRegex.test(vcc_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vcc_siguiente').focus();
- return;
- }
- if (vae_inicio !== '' && !soloNumerosRegex.test(vae_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vae_inicio').focus();
- return;
- }
- if (vae_final !== '' && !soloNumerosRegex.test(vae_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vae_final').focus();
- return;
- }
- if (vae_siguiente !== '' && !soloNumerosRegex.test(vae_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vae_siguiente').focus();
- return;
+ // Validar campos de folios
+ for (let folio of folios) {
+ const valor = document.getElementById(folio.id).value.trim();
+
+ if (valor !== '') {
+ // Validar longitud máxima
+ if (valor.length > 10) {
+ Swal.fire({ icon: 'error', title: 'Campo demasiado largo', text: `${folio.nombre} no puede exceder 10 caracteres.`, confirmButtonColor: '#dc3545' });
+ document.getElementById(folio.id).focus();
+ return;
+ }
+
+ // Opcional: Si quieres mantener solo números, descomenta estas líneas
+ /*
+ if (!soloNumerosRegex.test(valor)) {
+ Swal.fire({
+ icon: 'error',
+ title: 'Campo inválido',
+ text: `${folio.nombre} solo puede contener números.`,
+ confirmButtonColor: '#dc3545'
+ });
+ document.getElementById(folio.id).focus();
+ return;
+ }
+ */
+ }
}
- // ✅ SI TODAS LAS VALIDACIONES PASAN, ENVIAR EL FORMULARIO
- // Mostrar indicador de carga
- Swal.fire({
- title: 'Guardando...', text: 'Por favor espere', allowOutsideClick: false, showConfirmButton: false,
- willOpen: () => { Swal.showLoading(); }
- });
+ // Si todas las validaciones pasan, mostrar carga y enviar
+ Swal.fire({ title: 'Guardando...', text: 'Por favor espere', allowOutsideClick: false, showConfirmButton: false, willOpen: () => { Swal.showLoading(); } });
// SI TODAS LAS VALIDACIONES PASAN, ENVIAR EL FORMULARIO
this.submit();
diff --git a/views/patente/editar.php b/views/patente/editar.php
index 4d3ac16..e088ca0 100644
--- a/views/patente/editar.php
+++ b/views/patente/editar.php
@@ -163,19 +163,19 @@
+ value="= htmlspecialchars(sprintf('%03d', $agente['vp_inicio'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vp_final'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vp_siguiente'] ?? '')) ?>">
@@ -186,19 +186,19 @@
+ value="= htmlspecialchars(sprintf('%03d', $agente['vpe_inicio'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vpe_final'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vpe_siguiente'] ?? '')) ?>">
@@ -209,19 +209,19 @@
+ value="= htmlspecialchars(sprintf('%03d', $agente['vat_pb_inicio'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vat_pb_final'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vat_pb_siguiente'] ?? '')) ?>">
@@ -232,19 +232,19 @@
+ value="= htmlspecialchars(sprintf('%03d', $agente['vcc_inicio'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vcc_final'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vcc_siguiente'] ?? '')) ?>">
@@ -255,19 +255,19 @@
+ value="= htmlspecialchars(sprintf('%03d', $agente['vae_inicio'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vae_final'] ?? '')) ?>">
+ value="= htmlspecialchars(sprintf('%03d', $agente['vae_siguiente'] ?? '')) ?>">
@@ -350,105 +350,55 @@
return;
}
- const vp_inicio = document.getElementById('vp_inicio').value;
- const vp_final = document.getElementById('vp_final').value;
- const vp_siguiente = document.getElementById('vp_siguiente').value;
- const vpe_inicio = document.getElementById('vpe_inicio').value;
- const vpe_final = document.getElementById('vpe_final').value;
- const vpe_siguiente = document.getElementById('vpe_siguiente').value;
- const vat_pb_inicio = document.getElementById('vat_pb_inicio').value;
- const vat_pb_final = document.getElementById('vat_pb_final').value;
- const vat_pb_siguiente = document.getElementById('vat_pb_siguiente').value;
- const vcc_inicio = document.getElementById('vcc_inicio').value;
- const vcc_final = document.getElementById('vcc_final').value;
- const vcc_siguiente = document.getElementById('vcc_siguiente').value;
- const vae_inicio = document.getElementById('vae_inicio').value;
- const vae_final = document.getElementById('vae_final').value;
- const vae_siguiente = document.getElementById('vae_siguiente').value;
+ // Obtener campos de folios (ahora VARCHAR)
+ const folios = [
+ { id: 'vp_inicio', nombre: 'VP Inicio' },
+ { id: 'vp_final', nombre: 'VP Final' },
+ { id: 'vp_siguiente', nombre: 'VP Siguiente' },
+ { id: 'vpe_inicio', nombre: 'VPE Inicio' },
+ { id: 'vpe_final', nombre: 'VPE Final' },
+ { id: 'vpe_siguiente', nombre: 'VPE Siguiente' },
+ { id: 'vat_pb_inicio', nombre: 'VAT PB Inicio' },
+ { id: 'vat_pb_final', nombre: 'VAT PB Final' },
+ { id: 'vat_pb_siguiente', nombre: 'VAT PB Siguiente' },
+ { id: 'vcc_inicio', nombre: 'VCC Inicio' },
+ { id: 'vcc_final', nombre: 'VCC Final' },
+ { id: 'vcc_siguiente', nombre: 'VCC Siguiente' },
+ { id: 'vae_inicio', nombre: 'VAE Inicio' },
+ { id: 'vae_final', nombre: 'VAE Final' },
+ { id: 'vae_siguiente', nombre: 'VAE Siguiente' }
+ ];
- // Validaciones Números de Validación y Folios
- if (!soloNumerosRegex.test(vp_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vp_inicio').focus();
- return;
- }
- if (!soloNumerosRegex.test(vp_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vp_final').focus();
- return;
- }
- if (!soloNumerosRegex.test(vp_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vp_siguiente').focus();
- return;
- }
- if (!soloNumerosRegex.test(vpe_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vpe_inicio').focus();
- return;
- }
- if (!soloNumerosRegex.test(vpe_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vpe_final').focus();
- return;
- }
- if (!soloNumerosRegex.test(vpe_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vpe_siguiente').focus();
- return;
- }
- if (!soloNumerosRegex.test(vat_pb_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vat_pb_inicio').focus();
- return;
- }
- if (!soloNumerosRegex.test(vat_pb_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vat_pb_final').focus();
- return;
- }
- if (!soloNumerosRegex.test(vat_pb_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vat_pb_siguiente').focus();
- return;
- }
- if (!soloNumerosRegex.test(vcc_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vcc_inicio').focus();
- return;
- }
- if (!soloNumerosRegex.test(vcc_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vcc_final').focus();
- return;
- }
- if (!soloNumerosRegex.test(vcc_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vcc_siguiente').focus();
- return;
- }
- if (!soloNumerosRegex.test(vae_inicio)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Inicio solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vae_inicio').focus();
- return;
- }
- if (!soloNumerosRegex.test(vae_final)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Final solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vae_final').focus();
- return;
- }
- if (!soloNumerosRegex.test(vae_siguiente)) {
- Swal.fire({ icon: 'error', title: 'Campo inválido', text: 'Siguiente solo puede contener números.', confirmButtonColor: '#dc3545' });
- document.getElementById('vae_siguiente').focus();
- return;
+ // Validar campos de folios
+ for (let folio of folios) {
+ const valor = document.getElementById(folio.id).value.trim();
+
+ if (valor !== '') {
+ // Validar longitud máxima
+ if (valor.length > 10) {
+ Swal.fire({ icon: 'error', title: 'Campo demasiado largo', text: `${folio.nombre} no puede exceder 10 caracteres.`, confirmButtonColor: '#dc3545' });
+ document.getElementById(folio.id).focus();
+ return;
+ }
+
+ // Opcional: Si quieres mantener solo números, descomenta estas líneas
+ /*
+ if (!soloNumerosRegex.test(valor)) {
+ Swal.fire({
+ icon: 'error',
+ title: 'Campo inválido',
+ text: `${folio.nombre} solo puede contener números.`,
+ confirmButtonColor: '#dc3545'
+ });
+ document.getElementById(folio.id).focus();
+ return;
+ }
+ */
+ }
}
- // ✅ SI TODAS LAS VALIDACIONES PASAN, ENVIAR EL FORMULARIO
- // Mostrar indicador de carga
- Swal.fire({
- title: 'Guardando...', text: 'Por favor espere', allowOutsideClick: false, showConfirmButton: false,
- willOpen: () => { Swal.showLoading(); }
- });
+ // Si todas las validaciones pasan, mostrar carga y enviar
+ Swal.fire({ title: 'Guardando...', text: 'Por favor espere', allowOutsideClick: false, showConfirmButton: false, willOpen: () => { Swal.showLoading(); } });
// SI TODAS LAS VALIDACIONES PASAN, ENVIAR EL FORMULARIO
this.submit();