Filtro de choferes pertenecientes a transportista en solicitudes de importación

This commit is contained in:
2025-07-04 17:00:08 -06:00
parent 8434121efc
commit a3e2f8e45e
4 changed files with 620 additions and 241 deletions

View File

@@ -35,8 +35,8 @@
.card-hover:hover { transform: translateY(-8px) scale(1.02); box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.15) !important; }
.btn-pulse { animation: pulse 2s infinite; }
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.fade-in-up { animation: fadeInUp 0.8s ease-out; }
@@ -63,10 +63,16 @@
<body>
<?php if (!isset($_SESSION['id_agencia_en_uso']) || !$_SESSION['id_agencia_en_uso']): ?>
<div class="alert alert-warning mt-4">
<h5>⚠️ No tienes una agencia activa vinculada.</h5>
<p>Para poder gestionar tus solicitudes de importación, primero debes <strong>vincularte a una agencia</strong>.</p>
<a href="/IMPORTADORES/vinculaciones/nuevaVinculacion" class="btn btn-primary mt-auto w-auto btn-animated">Ir a Vinculaciones</a>
<div class="container mt-4">
<div class="row">
<div class="col-12">
<div class="alert alert-warning mt-4">
<h5>⚠️ No tienes una agencia activa vinculada.</h5>
<p>Para poder gestionar tus solicitudes de importación, primero debes <strong>vincularte a una agencia</strong>.</p>
<a href="/IMPORTADORES/vinculaciones/nuevaVinculacion" class="btn btn-primary btn-animated">Ir a Vinculaciones</a>
</div>
</div>
</div>
</div>
<?php return; ?>
<?php endif; ?>
@@ -399,6 +405,113 @@
}
});
}
document.addEventListener('DOMContentLoaded', function() {
const transportistaSelect = document.getElementById('transportista_id');
const choferSelect = document.getElementById('chofer_id');
// Inicializar Choices.js si está disponible
let choferChoices = null;
if (typeof Choices !== 'undefined') {
choferChoices = new Choices(choferSelect, {
searchEnabled: true,
placeholderValue: '-- Selecciona Transportista primero --',
noResultsText: 'No se encontraron resultados',
itemSelectText: '',
searchPlaceholderValue: 'Buscar chofer...'
});
}
transportistaSelect.addEventListener('change', function() {
const transportistaId = this.value;
// Limpiar opciones del chofer
if (choferChoices) {
choferChoices.clearStore();
choferChoices.setChoices([{
value: '',
label: transportistaId ? '-- Cargando choferes... --' : '-- Selecciona Transportista primero --',
disabled: true
}], 'value', 'label', true);
} else {
choferSelect.innerHTML = '<option value="">' +
(transportistaId ? '-- Cargando choferes... --' : '-- Selecciona Transportista primero --') +
'</option>';
}
if (!transportistaId) {
return;
}
// Hacer petición AJAX para obtener choferes
fetch(`/IMPORTADORES/solicitud_importacion/obtenerChoferesPorTransportista?transportista_id=${transportistaId}`)
.then(response => {
console.log('Response status:', response.status);
console.log('Response headers:', response.headers.get('content-type'));
if (!response.ok) {
return response.text().then(text => {
console.error('Error response:', text);
throw new Error(`Error ${response.status}: ${text}`);
});
}
// Verificar que la respuesta sea JSON
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
return response.text().then(text => {
console.error('Non-JSON response:', text);
throw new Error('La respuesta no es JSON válido');
});
}
return response.json();
})
.then(choferes => {
const opciones = [{
value: '',
label: '-- Selecciona Chofer --',
disabled: false
}];
choferes.forEach(chofer => {
opciones.push({
value: chofer.id_chofer,
label: chofer.nombre,
disabled: false
});
});
if (choferChoices) {
choferChoices.clearStore();
choferChoices.setChoices(opciones, 'value', 'label', true);
} else {
choferSelect.innerHTML = '';
opciones.forEach(opcion => {
const option = document.createElement('option');
option.value = opcion.value;
option.textContent = opcion.label;
if (opcion.disabled) option.disabled = true;
choferSelect.appendChild(option);
});
}
})
.catch(error => {
console.error('Error al cargar choferes:', error);
const errorMessage = '-- Error al cargar choferes --';
if (choferChoices) {
choferChoices.clearStore();
choferChoices.setChoices([{
value: '',
label: errorMessage,
disabled: true
}], 'value', 'label', true);
} else {
choferSelect.innerHTML = `<option value="">${errorMessage}</option>`;
}
});
});
});
</script>
</body>