Revisión 2.1

This commit is contained in:
2025-06-16 14:36:01 -06:00
parent c576ab5b3b
commit 4365919211
18 changed files with 601 additions and 290 deletions

View File

@@ -46,7 +46,7 @@
<?php foreach ($transportistas as $t): ?>
<option value="<?= $t['id_transportista'] ?>"
<?= $chofer['transportista_id'] == $t['id_transportista'] ? 'selected' : '' ?>>
<?= htmlspecialchars($t['nombre']) ?>
<?= htmlspecialchars($t['clave_identificador'] . ' - ' . $t['nombre'] . ' - ' . $t['ciudad_nombre'] . ' - ' . $t['domicilio']) ?>
</option>
<?php endforeach; ?>
</select>
@@ -76,6 +76,13 @@
value="<?= htmlspecialchars($chofer['numero_licencia']) ?>" required>
</div>
<!-- Gafete -->
<div class="col-md-6 mb-3">
<label for="numero_gafete" class="form-label">Número de Gafete</label>
<input name="numero_gafete" id="numero_gafete" type="text" maxlength="24" class="form-control"
value="<?= htmlspecialchars($chofer['numero_gafete']) ?>" required>
</div>
<!-- Teléfono -->
<div class="col-md-6 mb-3">
<label for="telefono" class="form-label">Teléfono</label>
@@ -138,6 +145,7 @@
const nombre = document.getElementById('nombre').value.trim();
const apellido = document.getElementById('apellido').value.trim();
const numero_licencia = document.getElementById('numero_licencia').value.trim();
const numero_gafete = document.getElementById('numero_gafete').value.trim();
const telefono = document.getElementById('telefono').value.trim();
const email = document.getElementById('email').value.trim();
const fecha_ingreso = document.getElementById('fecha_ingreso').value;
@@ -169,6 +177,11 @@
document.getElementById('numero_licencia').focus();
return;
}
if (!numero_gafete) {
Swal.fire({ icon: 'error', title: 'Número de Gafete requerido', text: 'Por favor ingresa el número de gafete.', confirmButtonColor: '#dc3545' });
document.getElementById('numero_gafete').focus();
return;
}
if (!soloNumerosRegex.test(numero_licencia)) {
Swal.fire({ icon: 'error', title: 'Número de Licencia inválido', text: 'El número de licencia solo puede contener números', confirmButtonColor: '#dc3545' });
document.getElementById('Clave').focus();
@@ -211,9 +224,24 @@
return;
}
}
// VALIDACIÓN ASÍNCRONA DE DUPLICADO DE GAFETE
const id_chofer = document.querySelector('input[name="id_chofer"]').value;
// SI TODAS LAS VALIDACIONES PASAN, ENVIAR EL FORMULARIO
this.submit();
fetch(`/IMPORTADORES/choferes/validarNumeroGafete?numero_gafete=${encodeURIComponent(numero_gafete)}&id_chofer={id_chofer}`)
.then(response => response.json())
.then(data => {
if (data.success && data.existe) {
Swal.fire({ icon: 'error', title: 'Número de Gafete duplicado', text: 'El número de gafete ya está en uso, por favor ingresa uno diferente.', confirmButtonColor: '#dc3545' });
document.getElementById('numero_gafete').focus();
} else {
// Si no existe, enviamos el formulario
e.target.submit();
}
})
.catch(error => {
console.error('Error validando el número de gafete:', error);
Swal.fire({ icon: 'error', title: 'Error de validación', text: 'No fue posible validar el número de gafete. Intenta de nuevo.', confirmButtonColor: '#dc3545' });
});
});
</script>