feature/T2026-05-031-y-T2026-05-030 #25
@@ -198,6 +198,7 @@ export default function Reports() {
|
|||||||
|
|
||||||
const [organizaciones, setOrganizaciones] = useState([]);
|
const [organizaciones, setOrganizaciones] = useState([]);
|
||||||
const [importadores, setImportadores] = useState([]);
|
const [importadores, setImportadores] = useState([]);
|
||||||
|
const [rfcOptions, setRfcOptions] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchOrganizaciones = async () => {
|
const fetchOrganizaciones = async () => {
|
||||||
@@ -241,6 +242,27 @@ export default function Reports() {
|
|||||||
pedimento: ''
|
pedimento: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Cargar RFCs cuando cambia la organización seleccionada en filtros globales
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchRfcs = async () => {
|
||||||
|
if (!globalFilters.organizacion) {
|
||||||
|
setRfcOptions([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const url = `${import.meta.env.VITE_EFC_API_URL}/reports/exportmodel/datastage/?organizacion=${globalFilters.organizacion}`;
|
||||||
|
const res = await fetchWithAuth(url);
|
||||||
|
if (!res.ok) throw new Error('Error al obtener RFCs');
|
||||||
|
const data = await res.json();
|
||||||
|
setRfcOptions(data.rfcs || []);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching RFCs:', err);
|
||||||
|
setRfcOptions([]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchRfcs();
|
||||||
|
}, [globalFilters.organizacion]);
|
||||||
|
|
||||||
const renderGlobalFilters = () => (
|
const renderGlobalFilters = () => (
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<div className="bg-white rounded-xl shadow-lg overflow-hidden border border-blue-100">
|
<div className="bg-white rounded-xl shadow-lg overflow-hidden border border-blue-100">
|
||||||
@@ -269,16 +291,17 @@ export default function Reports() {
|
|||||||
value={globalFilters.organizacion || ''}
|
value={globalFilters.organizacion || ''}
|
||||||
onChange={(e) => setGlobalFilters(prev => ({
|
onChange={(e) => setGlobalFilters(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
organizacion: e.target.value
|
organizacion: e.target.value,
|
||||||
|
rfc: ''
|
||||||
}))}
|
}))}
|
||||||
className="block w-full rounded-lg border-gray-300 pl-3 pr-10 py-2.5 text-gray-900 placeholder-gray-500
|
className="block w-full rounded-lg border-gray-300 pl-3 pr-10 py-2.5 text-gray-900 placeholder-gray-500
|
||||||
focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm
|
focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm
|
||||||
transition-all duration-200 bg-white appearance-none"
|
transition-all duration-200 bg-white appearance-none"
|
||||||
>
|
>
|
||||||
<option value="">Todas las organizaciones</option>
|
<option value="" disabled>Selecciona una organización</option>
|
||||||
{organizaciones.results && organizaciones.results.map(org => (
|
{organizaciones.results && organizaciones.results.map(org => (
|
||||||
<option key={org.id} value={org.id}>
|
<option key={org.id} value={org.id}>
|
||||||
{org.nombre} {/* Usar el campo 'nombre' que sí existe */}
|
{org.nombre}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
@@ -318,13 +341,11 @@ export default function Reports() {
|
|||||||
}))}
|
}))}
|
||||||
className="w-full px-3 py-2 border border-green-300 rounded-md shadow-sm focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-all duration-200 bg-white text-slate-900 text-sm font-mono uppercase"
|
className="w-full px-3 py-2 border border-green-300 rounded-md shadow-sm focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-all duration-200 bg-white text-slate-900 text-sm font-mono uppercase"
|
||||||
style={{ textTransform: 'uppercase' }}
|
style={{ textTransform: 'uppercase' }}
|
||||||
|
disabled={!globalFilters.organizacion}
|
||||||
>
|
>
|
||||||
<option value="" >Selecciona un RFC</option>
|
<option value="">Todos los RFC</option>
|
||||||
{importadores.filter(imp => {
|
{rfcOptions.map(rfc => (
|
||||||
if (!globalFilters.organizacion) return true;
|
<option key={rfc} value={rfc}>{rfc}</option>
|
||||||
return imp.organizacion === globalFilters.organizacion;
|
|
||||||
}).map(imp => (
|
|
||||||
<option key={imp.rfc} value={imp.rfc}>{imp.rfc}</option>
|
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
<div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
|
<div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
|
||||||
@@ -807,7 +828,12 @@ export default function Reports() {
|
|||||||
.map(([modelo]) => modelo);
|
.map(([modelo]) => modelo);
|
||||||
|
|
||||||
if (modelosConCampos.length === 0) {
|
if (modelosConCampos.length === 0) {
|
||||||
alert('Por favor selecciona al menos un campo en algún modelo');
|
showMessage('Por favor selecciona al menos un campo en algún modelo', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!globalFilters.organizacion) {
|
||||||
|
showMessage('Debes seleccionar una organización antes de generar el reporte', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user