import React, { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import { getWithAuth, postWithAuth } from '../fetchWithAuth'; const API_URL = import.meta.env.VITE_EFC_API_URL; function Auditor() { const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [pedimentos, setPedimentos] = useState([]); const [showInstructions, setShowInstructions] = useState(false); const [count, setCount] = useState(0); const [page, setPage] = useState(1); const [itemsPerPage] = useState(10); const [auditando, setAuditando] = useState(false); const [auditandoPartidas, setAuditandoPartidas] = useState(false); const [auditandoRemesas, setAuditandoRemesas] = useState(false); const [procesandoPedimento, setProcesandoPedimento] = useState(null); const [procesandoRemesa, setProcesandoRemesa] = useState(null); const [procesandoAcuse, setProcesandoAcuse] = useState(null); const [procesandoCove, setProcesandoCove] = useState(null); const [auditandoAcusesCove, setAuditandoAcusesCove] = useState(false); const [pedimentoFilter, setPedimentoFilter] = useState(''); const [auditandoEDocuments, setAuditandoEDocuments] = useState(false); const [auditandoAcuses, setAuditandoAcuses] = useState(false); // Handler para auditar acuses (general) const handleAuditarAcuses = async () => { if (auditandoAcuses) return; try { setAuditandoAcuses(true); const organizacionId = pedimentos[0]?.organizacion; if (!organizacionId) { throw new Error('No hay organización disponible para auditar'); } const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-acuse/`, { organizacion_id: organizacionId }); if (!response.ok) { throw new Error('Error al iniciar la auditoría de acuses'); } alert('La auditoría de acuses se ha iniciado correctamente'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setAuditandoAcuses(false); } }; // Handler para auditar EDocuments (general) const handleAuditarEDocuments = async () => { if (auditandoEDocuments) return; try { setAuditandoEDocuments(true); const organizacionId = pedimentos[0]?.organizacion; if (!organizacionId) { throw new Error('No hay organización disponible para auditar'); } const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-edocuments/`, { organizacion_id: organizacionId }); if (!response.ok) { throw new Error('Error al iniciar la auditoría de EDocuments'); } alert('La auditoría de EDocuments se ha iniciado correctamente'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setAuditandoEDocuments(false); } }; // Handler para auditar acuses cove (general) const handleAuditarAcusesCove = async () => { if (auditandoAcusesCove) return; try { setAuditandoAcusesCove(true); // Obtener el organizacion_id del primer pedimento const organizacionId = pedimentos[0]?.organizacion; if (!organizacionId) { throw new Error('No hay organización disponible para auditar'); } const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-acuse-cove/`, { organizacion_id: organizacionId }); if (!response.ok) { throw new Error('Error al iniciar la auditoría de acuses cove'); } alert('La auditoría de acuses cove se ha iniciado correctamente'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setAuditandoAcusesCove(false); } }; const handleAuditarRemesaPedimento = async (pedimentoId) => { if (procesandoRemesa) return; try { setProcesandoRemesa(pedimentoId); const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-procesamiento-remesa/pedimento/`, { pedimento_id: pedimentoId }); if (!response.ok) { throw new Error('Error al procesar las remesas del pedimento'); } // Mostrar mensaje de éxito alert('Las remesas del pedimento se están procesando'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setProcesandoRemesa(null); } }; const handleAuditarRemesas = async () => { if (auditandoRemesas) return; try { setAuditandoRemesas(true); // Obtener el organizacion_id del primer pedimento const organizacionId = pedimentos[0]?.organizacion; if (!organizacionId) { throw new Error('No hay organización disponible para auditar'); } const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-procesamiento-remesas/`, { organizacion_id: organizacionId }); if (!response.ok) { throw new Error('Error al iniciar la auditoría de remesas'); } // Mostrar mensaje de éxito alert('La auditoría de remesas se ha iniciado correctamente'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setAuditandoRemesas(false); } }; const handleAuditarPartidasPedimento = async (pedimentoId) => { if (procesandoPedimento) return; try { setProcesandoPedimento(pedimentoId); const response = await postWithAuth(`${API_URL}/customs/auditor/crear-partidas/pedimento/`, { pedimento_id: pedimentoId }); if (!response.ok) { throw new Error('Error al procesar las partidas del pedimento'); } // Mostrar mensaje de éxito alert('Las partidas del pedimento se están procesando'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setProcesandoPedimento(null); } }; const handleAuditarPartidas = async () => { if (auditandoPartidas) return; try { setAuditandoPartidas(true); // Obtener el organizacion_id del primer pedimento const organizacionId = pedimentos[0]?.organizacion; if (!organizacionId) { throw new Error('No hay organización disponible para auditar'); } const response = await postWithAuth(`${API_URL}/customs/auditor/crear-partidas/organizacion/`, { organizacion_id: organizacionId }); if (!response.ok) { throw new Error('Error al iniciar la auditoría de partidas'); } // Mostrar mensaje de éxito alert('La auditoría de partidas se ha iniciado correctamente'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setAuditandoPartidas(false); } }; const handleAuditarTodos = async () => { if (auditando) return; try { setAuditando(true); // Obtener el organizacion_id del primer pedimento const organizacionId = pedimentos[0]?.organizacion; if (!organizacionId) { throw new Error('No hay organización disponible para auditar'); } const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-pedimentos/`, { organizacion_id: organizacionId }); if (!response.ok) { throw new Error('Error al iniciar la auditoría'); } // Mostrar mensaje de éxito alert('La auditoría se ha iniciado correctamente'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setAuditando(false); } }; const handleAuditarAcusePedimento = async (pedimentoId) => { if (procesandoAcuse) return; try { setProcesandoAcuse(pedimentoId); const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-acuse/pedimento/`, { pedimento_id: pedimentoId }); if (!response.ok) { throw new Error('Error al auditar acuse del pedimento'); } alert('El acuse del pedimento se está auditando'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setProcesandoAcuse(null); } }; const handleAuditarCovePedimento = async (pedimentoId) => { if (procesandoCove) return; try { setProcesandoCove(pedimentoId); const response = await postWithAuth(`${API_URL}/customs/auditor/auditar-cove/pedimento/`, { pedimento_id: pedimentoId }); if (!response.ok) { throw new Error('Error al auditar COVE del pedimento'); } alert('El COVE del pedimento se está auditando'); } catch (error) { console.error('Error:', error); alert(error.message); } finally { setProcesandoCove(null); } }; useEffect(() => { const fetchPedimentos = async () => { setLoading(true); try { const queryParams = new URLSearchParams({ page: page.toString(), page_size: itemsPerPage.toString(), ...(pedimentoFilter && { pedimento_app: pedimentoFilter }) }); const response = await getWithAuth(`${API_URL}/customs/pedimentos/?${queryParams}`); if (!response.ok) throw new Error('Error al cargar los pedimentos'); const data = await response.json(); setPedimentos(data.results); setCount(data.count); } catch (err) { setError(err.message); } finally { setLoading(false); } }; // Aplicar debounce al fetchPedimentos const timeoutId = setTimeout(() => { fetchPedimentos(); }, 300); return () => clearTimeout(timeoutId); }, [page, itemsPerPage, pedimentoFilter]); return (
Monitoreo y control de operaciones
Cargando datos...
{error}
| Pedimento | PC Pedimento Completo | RM Remesas | PT Partidas | AC Acuse | COVE Cove | AC_COVE Acuse de Cove | EDoc EDocument |
|---|---|---|---|---|---|---|---|
| {pedimento.pedimento_app} | {/* PC - Pedimento Completo */}{/* RM - Remesas */} | {/* PT - Partidas */} | {/* AC - Acuse */} | {/* COVE */} | {/* AC_COVE */} | {/* EDoc */} |
Mostrando {((page - 1) * itemsPerPage) + 1} a{' '} {Math.min(page * itemsPerPage, count)} de{' '} {count} resultados
Este proceso revisará uno a uno cada XML del pedimento completo y agregará los campos restantes en nuestra tabla de pedimentos. Si el documento tiene COVEs y E-Docs, también los subirá a nuestra base de datos.
Creará todas las partidas de cada uno de los pedimentos, extrayendo la información detallada de cada una.
Obtendrá y agregará todos los COVEs existentes en el documento a nuestra base de datos.