feature/T2026-05-030 modificar modulo auditorias para poder inicializar procesos de pedimentos

This commit is contained in:
Dulce
2026-05-18 11:39:46 -06:00
parent 06f2485336
commit 078297cd61
3 changed files with 1629 additions and 127 deletions

View File

@@ -334,6 +334,8 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
const [processingAcuseCove, setProcessingAcuseCove] = useState(null);
const [processingEdoc, setProcessingEdoc] = useState(null);
const [processingAcuseEdoc, setProcessingAcuseEdoc] = useState(null);
// Modal de advertencia por documentos con errores en EDocs
const [edocErrorModal, setEdocErrorModal] = useState({ open: false, edoc: null, tipo: null });
// Agregar estado para el modal de documentos
const [showDocumentsModal, setShowDocumentsModal] = useState(false);
@@ -568,6 +570,7 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
const [previewDoc, setPreviewDoc] = useState(null);
const [previewContent, setPreviewContent] = useState('');
const [imageZoom, setImageZoom] = useState(1);
const [previewIframeLoaded, setPreviewIframeLoaded] = useState(false);
// Refs
const focusKeeperRef = useRef(null);
@@ -650,6 +653,7 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
setPreviewDoc(doc);
setImageZoom(1);
setPreviewContent('');
setPreviewIframeLoaded(false);
setPreviewOpen(true);
try {
const res = await fetchWithAuth(`${API_URL}/record/documents/descargar/${doc.id}/`);
@@ -689,12 +693,17 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
setPreviewLoading(false);
} else {
const blob = await res.blob();
if (blob.size === 0) {
setPreviewError('El archivo está vacío o no está disponible en el servidor.');
setPreviewLoading(false);
return;
}
const url = window.URL.createObjectURL(blob);
setPreviewUrl(url);
setPreviewLoading(false);
}
} catch (err) {
console.error('Error in preview:', err);
console.error('Error en vista previa (VU):', err);
if (err.message === 'SESSION_EXPIRED') {
setPreviewError('Tu sesión ha expirado, por favor inicia sesión de nuevo.');
} else {
@@ -714,6 +723,7 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
setPreviewDoc(doc);
setImageZoom(1);
setPreviewContent('');
setPreviewIframeLoaded(false);
setPreviewOpen(true);
try {
const res = await fetchWithAuth(`${API_URL}/record/documents/descargar/${doc.id}/`);
@@ -753,12 +763,17 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
setPreviewLoading(false);
} else {
const blob = await res.blob();
if (blob.size === 0) {
setPreviewError('El archivo está vacío o no está disponible en el servidor.');
setPreviewLoading(false);
return;
}
const url = window.URL.createObjectURL(blob);
setPreviewUrl(url);
setPreviewLoading(false);
}
} catch (err) {
console.error('Error in preview:', err);
console.error('Error en vista previa:', err);
if (err.message === 'SESSION_EXPIRED') {
setPreviewError('Tu sesión ha expirado, por favor inicia sesión de nuevo.');
} else {
@@ -780,6 +795,7 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
setPreviewDoc(null);
setPreviewContent('');
setImageZoom(1);
setPreviewIframeLoaded(false);
};
// Funciones para el nuevo diseño de documentos
@@ -5422,7 +5438,7 @@ useEffect(() => {
) : (
<div className="space-y-4">
{/* Tabla de EDocs */}
<div className="overflow-hidden rounded-lg shadow ring-1 ring-black ring-opacity-5">
<div className="overflow-x-auto rounded-lg shadow ring-1 ring-black ring-opacity-5">
<table className="min-w-full divide-y divide-gray-300">
<thead className="bg-gray-50">
<tr>
@@ -5513,20 +5529,29 @@ useEffect(() => {
{edoc.acuse_descargado ? 'Descargado' : 'Pendiente'}
</span>
</td>
<td className="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
<div className="flex items-center justify-end space-x-2">
<td className="px-6 py-4 text-sm font-medium text-right whitespace-nowrap" style={{minWidth: '140px'}}>
<div className="flex items-center justify-end space-x-2 flex-nowrap">
{/* Botón EDoc */}
<button
onClick={() => handleEdocProcess(edoc)}
onClick={() => {
const tieneError = !edoc.edocument_descargado && edoc.documentos?.some(d => d.document_type === 22);
if (tieneError) {
setEdocErrorModal({ open: true, edoc, tipo: 'edoc' });
} else {
handleEdocProcess(edoc);
}
}}
disabled={edoc.edocument_descargado || processingEdoc === edoc.id}
className={`p-1 rounded transition-colors ${
edoc.edocument_descargado
? 'text-gray-400 cursor-not-allowed'
: processingEdoc === edoc.id
? 'text-blue-400 cursor-not-allowed'
: !edoc.edocument_descargado && edoc.documentos?.some(d => d.document_type === 22)
? 'text-yellow-500 hover:text-yellow-700 opacity-60'
: 'text-blue-600 hover:text-blue-900'
}`}
title={edoc.edocument_descargado ? 'EDoc ya descargado' : processingEdoc === edoc.id ? 'Procesando EDoc...' : 'Procesar EDoc'}
title={edoc.edocument_descargado ? 'EDoc ya descargado' : processingEdoc === edoc.id ? 'Procesando EDoc...' : !edoc.edocument_descargado && edoc.documentos?.some(d => d.document_type === 22) ? 'EDoc con errores — haz clic para más información' : 'Procesar EDoc'}
>
{processingEdoc === edoc.id ? (
<svg className="w-4 h-4 animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -5541,16 +5566,25 @@ useEffect(() => {
{/* Botón Acuse de EDoc */}
<button
onClick={() => handleAcuseEdocProcess(edoc)}
onClick={() => {
const tieneError = !edoc.acuse_descargado && edoc.documentos?.some(d => d.document_type === 26);
if (tieneError) {
setEdocErrorModal({ open: true, edoc, tipo: 'acuse' });
} else {
handleAcuseEdocProcess(edoc);
}
}}
disabled={edoc.acuse_descargado || processingAcuseEdoc === edoc.id}
className={`p-1 rounded transition-colors ${
edoc.acuse_descargado
? 'text-gray-400 cursor-not-allowed'
: processingAcuseEdoc === edoc.id
? 'text-green-400 cursor-not-allowed'
: !edoc.acuse_descargado && edoc.documentos?.some(d => d.document_type === 26)
? 'text-yellow-500 hover:text-yellow-700 opacity-60'
: 'text-green-600 hover:text-green-900'
}`}
title={edoc.acuse_descargado ? 'Acuse de EDoc ya descargado' : processingAcuseEdoc === edoc.id ? 'Procesando Acuse de EDoc...' : 'Procesar Acuse de EDoc'}
title={edoc.acuse_descargado ? 'Acuse de EDoc ya descargado' : processingAcuseEdoc === edoc.id ? 'Procesando Acuse de EDoc...' : !edoc.acuse_descargado && edoc.documentos?.some(d => d.document_type === 26) ? 'Acuse con errores — haz clic para más información' : 'Procesar Acuse de EDoc'}
>
{processingAcuseEdoc === edoc.id ? (
<svg className="w-4 h-4 animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -6694,20 +6728,42 @@ useEffect(() => {
<h4 className="mb-2 text-lg font-semibold">Error al cargar documento</h4>
<p className="text-sm text-gray-600">{previewError}</p>
<button
onClick={() => setPreviewError(null)}
onClick={() => { setPreviewError(null); if (previewDoc) handlePreview(previewDoc); }}
className="px-4 py-2 mt-4 text-red-800 transition-colors bg-red-100 rounded-lg hover:bg-red-200"
>
Reintentar
Volver a cargar
</button>
</div>
</div>
) : previewType === 'pdf' ? (
<div className="flex-1 bg-white">
<iframe
src={previewUrl}
title="PDF Preview"
<div className="relative flex-1 bg-white">
{/* Spinner hasta que el iframe confirme carga */}
{!previewIframeLoaded && (
<div className="absolute inset-0 z-10 flex items-center justify-center bg-white">
<div className="text-center">
<div className="inline-flex items-center space-x-3 text-blue-600">
<svg className="w-10 h-10 animate-spin" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span className="text-lg font-medium">Cargando documento...</span>
</div>
</div>
</div>
)}
<iframe
src={previewUrl}
title="PDF Preview"
className="w-full h-full border-0"
style={{ minHeight: '500px' }}
onLoad={() => {
setPreviewIframeLoaded(true);
setPreviewLoading(false);
}}
onError={() => {
setPreviewError('No se pudo cargar el documento PDF.');
setPreviewLoading(false);
}}
/>
</div>
) : previewType === 'img' ? (
@@ -7228,6 +7284,91 @@ useEffect(() => {
</div>
)}
{/* Modal de advertencia: EDoc/Acuse con documentos de error */}
{edocErrorModal.open && edocErrorModal.edoc && (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50 animate-fade-in">
<div className="w-full max-w-lg p-6 bg-white rounded-lg shadow-xl animate-modal-slide-up">
<div className="flex items-center mb-4 space-x-3">
<div className="flex items-center justify-center w-10 h-10 bg-yellow-100 rounded-full shrink-0">
<svg className="w-5 h-5 text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z" />
</svg>
</div>
<h3 className="text-lg font-semibold text-gray-900">
{edocErrorModal.tipo === 'acuse' ? 'Acuse de EDoc con errores' : 'EDoc con errores'}
</h3>
</div>
<p className="mb-1 text-sm text-gray-700">
Este EDocument (<span className="font-medium">{edocErrorModal.edoc.numero_edocument}</span>) cuenta con errores en la respuesta recibida.
Revisa el documento de error antes de volver a intentarlo.
</p>
<p className="mb-4 text-sm text-gray-500">
Puedes continuar con el flujo de trabajo, pero se recomienda corregir el error primero.
</p>
{/* Lista de documentos de error */}
{(() => {
const tipoFiltro = edocErrorModal.tipo === 'acuse' ? 26 : 22;
const docsError = edocErrorModal.edoc.documentos?.filter(d => d.document_type === tipoFiltro) || [];
return docsError.length > 0 ? (
<div className="mb-4">
<p className="mb-2 text-xs font-medium tracking-wide text-gray-500 uppercase">Documentos de error</p>
<ul className="space-y-2">
{docsError.map(doc => {
const nombreArchivo = (doc.archivo || '').split('/').pop() || 'Documento';
return (
<li key={doc.id} className="flex items-center justify-between p-2 rounded-md bg-gray-50">
<span className="text-sm text-gray-700 truncate max-w-xs" title={nombreArchivo}>
{nombreArchivo}
</span>
<button
onClick={() => {
setEdocErrorModal({ open: false, edoc: null, tipo: null });
handlePreviewVU(doc);
}}
className="p-1 ml-2 text-blue-600 rounded shrink-0 hover:text-blue-900 hover:bg-blue-50"
title="Ver documento"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.477 0 8.268 2.943 9.542 7-1.274 4.057-5.065 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
</svg>
</button>
</li>
);
})}
</ul>
</div>
) : null;
})()}
<div className="flex justify-end space-x-2">
<button
onClick={() => setEdocErrorModal({ open: false, edoc: null, tipo: null })}
className="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50"
>
Cancelar
</button>
<button
onClick={() => {
const { edoc, tipo } = edocErrorModal;
setEdocErrorModal({ open: false, edoc: null, tipo: null });
if (tipo === 'acuse') {
handleAcuseEdocProcess(edoc);
} else {
handleEdocProcess(edoc);
}
}}
className="px-4 py-2 text-sm font-medium text-white bg-yellow-600 rounded-md hover:bg-yellow-700"
>
Continuar de todas formas
</button>
</div>
</div>
</div>
)}
</div>
);
}