fix: se agrega nueva pestaña para visualizar los archivos de error que devuelve vucem en detalle pedimento.

This commit is contained in:
2026-01-29 08:07:52 -07:00
parent 07facb8ae2
commit 7c40275381

View File

@@ -2827,6 +2827,237 @@ const handleDeleteSelectedPedimentoDocuments = async () => {
const isPartida = selectedDocumentForUpload?.tab === 'partida'; const isPartida = selectedDocumentForUpload?.tab === 'partida';
const isCove = selectedDocumentForUpload?.tab === 'cove'; const isCove = selectedDocumentForUpload?.tab === 'cove';
const isEdoc = selectedDocumentForUpload?.tab === 'edoc'; const isEdoc = selectedDocumentForUpload?.tab === 'edoc';
// Estados para documentos de errores VU
const [errorDocuments, setErrorDocuments] = useState([]);
const [errorDocsCount, setErrorDocsCount] = useState(0);
const [errorDocsLoading, setErrorDocsLoading] = useState(true);
const [errorDocsError, setErrorDocsError] = useState('');
const [errorDocsPage, setErrorDocsPage] = useState(1);
const [errorDocsPageSize, setErrorDocsPageSize] = useState(10);
const [selectedErrorDocuments, setSelectedErrorDocuments] = useState([]);
const [isSelectAllErrorDocs, setIsSelectAllErrorDocs] = useState(false);
const [downloadingAllErrors, setDownloadingAllErrors] = useState(false);
// Filtros para errores VU
const [errorFilters, setErrorFilters] = useState({
name: '',
document_type: '',
extension: '',
date: '',
created_at__gte: '',
created_at__lte: '',
fuente: '',
pedimento_numero: '',
tipo_error: ''
});
// Estado para mostrar filtros de errores
const [showErrorFilters, setShowErrorFilters] = useState(false);
// Efecto para cargar documentos de errores VU
useEffect(() => {
// Función para obtener documentos de errores VU usando el endpoint específico
const fetchErrorDocuments = async (pedimentoId,page = 1, pageSize = 10, filters = {}) => {
try {
if (!id || !pedimento?.pedimento_app) return;
// Construir parámetros de filtros
const params = new URLSearchParams({
pedimento: pedimento.pedimento_app, // Usar pedimento_app como requiere el endpoint
pedimentoId: pedimentoId,
// document_type_id: [14,16,18,20,22,24,26], IDs de tipos de documentos de error VU
page: page,
page_size: pageSize
});
// Solo agregar filtros que tengan valores
Object.entries(filters).forEach(([key, value]) => {
if (value && value.toString().trim() !== '') {
params.append(key, value);
}
});
// Usar el endpoint específico para documentos de error VU
const response = await fetchWithAuth(
`${API_URL}/record/documents/vu-documentos-errores/?${params}`
);
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.error || `Error ${response.status} al obtener documentos de error VU`);
}
const data = await response.json();
// El endpoint devuelve un array directo, no un objeto paginado
// Aplicamos paginación manualmente en el frontend
if (Array.isArray(data)) {
const startIndex = (page - 1) * pageSize;
const endIndex = startIndex + pageSize;
const paginatedResults = data.slice(startIndex, endIndex);
return {
results: paginatedResults,
count: data.length,
next: endIndex < data.length ? page + 1 : null,
previous: page > 1 ? page - 1 : null
};
}
// Si por alguna razón devuelve un objeto paginado
return data;
} catch (error) {
console.error('Error fetching error documents:', error);
throw error;
}
};
if (!id || !pedimento || activeTab !== 'errores') return;
console.log('Fetching error documents for pedimento:', pedimento.pedimento_app);
setErrorDocsLoading(true);
setErrorDocsError('');
// Construir parámetros de filtros
const apiFilters = {};
if (errorFilters.name) apiFilters.archivo__icontains = errorFilters.name;
if (errorFilters.extension) apiFilters.extension = errorFilters.extension;
if (errorFilters.date) apiFilters.created_at__date = errorFilters.date;
if (errorFilters.created_at__gte) apiFilters.created_at__gte = errorFilters.created_at__gte;
if (errorFilters.created_at__lte) apiFilters.created_at__lte = errorFilters.created_at__lte;
if (errorFilters.fuente) apiFilters.fuente = errorFilters.fuente;
if (errorFilters.tipo_error) {
apiFilters.tipo_error = errorFilters.tipo_error;
}else{
apiFilters.tipo_error = [14,16,18,20,22,24,26];
}
// NOTA: No necesitamos document_type porque el endpoint ya filtra por documentos de error VU
// Tampoco necesitamos pedimento_numero porque ya estamos filtrando por pedimento
fetchErrorDocuments(id,errorDocsPage, errorDocsPageSize, apiFilters)
.then((data) => {
console.log('Error documents data:', data);
setErrorDocuments(data.results || []);
setErrorDocsCount(data.count || 0);
setErrorDocsLoading(false);
})
.catch(err => {
console.error('Error fetching error documents:', err);
if (err.message === 'SESSION_EXPIRED') {
showMessage('Tu sesión ha expirado, por favor inicia sesión de nuevo.', 'error');
} else {
setErrorDocsError(err.message || 'Error al cargar documentos de error VU');
}
setErrorDocsLoading(false);
});
}, [id, activeTab, errorDocsPage, errorDocsPageSize, errorFilters, showMessage, pedimento]);
// Resetear página cuando cambien los filtros de errores
useEffect(() => {
setErrorDocsPage(1);
}, [errorFilters]);
// Efecto para actualizar isSelectAllErrorDocs cuando cambia la selección
useEffect(() => {
if (errorDocuments.length > 0) {
const allSelected = errorDocuments.every(doc => selectedErrorDocuments.includes(doc.id));
setIsSelectAllErrorDocs(allSelected && selectedErrorDocuments.length > 0);
}
}, [selectedErrorDocuments, errorDocuments]);
// Efecto para limpiar selección cuando cambia de página
useEffect(() => {
setSelectedErrorDocuments([]);
setIsSelectAllErrorDocs(false);
}, [errorDocsPage]);
// Funciones para manejo de selección múltiple de documentos de error
const handleSelectErrorDocument = (documentId) => {
const isSelected = selectedErrorDocuments.includes(documentId);
if (isSelected) {
setSelectedErrorDocuments(prev => prev.filter(id => id !== documentId));
} else {
setSelectedErrorDocuments(prev => [...prev, documentId]);
}
};
const handleSelectAllErrorDocuments = () => {
if (isSelectAllErrorDocs) {
setSelectedErrorDocuments([]);
setIsSelectAllErrorDocs(false);
} else {
const allDocumentIds = errorDocuments.map(doc => doc.id);
setSelectedErrorDocuments(allDocumentIds);
setIsSelectAllErrorDocs(true);
}
};
// Función para eliminar documentos de error seleccionados
const handleDeleteSelectedErrorDocuments = async () => {
if (selectedErrorDocuments.length === 0) {
showMessage('No hay documentos seleccionados para eliminar', 'warning');
return;
}
try {
showMessage(`Eliminando ${selectedErrorDocuments.length} documento(s) de error...`, 'info');
const response = await fetchWithAuth(`${API_URL}/record/documents/bulk-delete/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
ids: selectedErrorDocuments
})
});
if (!response.ok) {
const errorData = await response.json().catch(() => null);
throw new Error(errorData?.detail || errorData?.message || `Error ${response.status}: ${response.statusText}`);
}
const result = await response.json();
showMessage(
`${result.deleted_count || selectedErrorDocuments.length} documento(s) de error eliminado(s) exitosamente`,
'success'
);
setSelectedErrorDocuments([]);
setIsSelectAllErrorDocs(false);
// Forzar recarga de documentos
const currentPage = errorDocsPage;
setErrorDocsPage(0);
setTimeout(() => setErrorDocsPage(currentPage), 100);
} catch (error) {
console.error('Error durante la eliminación masiva de documentos de error:', error);
showMessage(`Error durante la eliminación: ${error.message}`, 'error');
}
};
// Función para descargar todos los documentos de error
const downloadAllErrors = async () => {
setDownloadingAllErrors(true);
try {
const allErrorDocIds = errorDocuments.map(doc => doc.id);
await handleBulkDownload(allErrorDocIds);
} catch (error) {
console.error('Error downloading all error documents:', error);
showMessage('Error al descargar todos los documentos de error', 'error');
} finally {
setDownloadingAllErrors(false);
}
};
//----------------------------------------// //----------------------------------------//
// Estados de carga // Estados de carga
@@ -3044,6 +3275,28 @@ const isEdoc = selectedDocumentForUpload?.tab === 'edoc';
)} )}
</div> </div>
</button> </button>
{/* Pestaña Errores VU */}
<button
onClick={() => handleTabChange('errores')}
className={`whitespace-nowrap py-3 sm:py-4 px-2 sm:px-3 lg:px-1 border-b-2 font-medium text-xs sm:text-sm transition-all duration-200 ${
activeTab === 'errores'
? 'border-red-600 text-red-600 bg-red-50/50'
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
}`}
>
<div className="flex items-center space-x-1 sm:space-x-2">
<svg className="w-4 h-4 sm:w-5 sm:h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.664-.833-2.464 0L4.35 16.5c-.77.833.192 2.5 1.732 2.5z" />
</svg>
<span className="hidden sm:inline">Errores VU</span>
<span className="sm:hidden">Errores</span>
{activeTab === 'errores' && errorDocsCount > 0 && (
<span className="bg-red-100 text-red-600 text-xs font-semibold px-1.5 py-0.5 sm:px-2 sm:py-1 rounded-full">
{errorDocsCount}
</span>
)}
</div>
</button>
{/* Pestaña Auditor */} {/* Pestaña Auditor */}
<button <button
@@ -5394,8 +5647,6 @@ const isEdoc = selectedDocumentForUpload?.tab === 'edoc';
</div> </div>
)} )}
{activeTab === 'auditor' && ( {activeTab === 'auditor' && (
<div className="p-6"> <div className="p-6">
{/* Header de la sección */} {/* Header de la sección */}
@@ -5885,6 +6136,429 @@ const isEdoc = selectedDocumentForUpload?.tab === 'edoc';
</div> </div>
</div> </div>
)} )}
{/* NUEVO CONTENIDO PARA TAB DE ERRORES VU */}
{activeTab === 'errores' && (
<div className="p-6">
{/* Header de la sección */}
<div className="mb-4 space-y-3 sm:mb-6 sm:space-y-4">
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-4">
<h3 className="text-lg font-semibold text-gray-900 sm:text-xl">
Documentos de Error VU
</h3>
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800 w-fit">
{errorDocsCount} documentos
</span>
</div>
<div className="flex flex-col gap-2 sm:flex-row sm:gap-3">
{errorDocuments.length > 0 && (
<>
<button
onClick={downloadAllErrors}
disabled={downloadingAllErrors}
className="inline-flex items-center justify-center px-3 py-2 text-sm font-medium leading-4 text-white bg-red-600 border border-transparent rounded-md hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 disabled:opacity-50"
>
{downloadingAllErrors ? (
<>
<svg className="w-4 h-4 mr-2 -ml-1 text-white animate-spin" xmlns="http://www.w3.org/2000/svg" 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="hidden sm:inline">Descargando...</span>
<span className="sm:hidden">Descargando...</span>
</>
) : (
<>
<svg className="w-4 h-4 mr-1 sm:mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
<span className="hidden sm:inline">Descargar Todos</span>
<span className="sm:hidden">Descargar</span>
</>
)}
</button>
<button
onClick={() => setShowErrorFilters(!showErrorFilters)}
className="inline-flex items-center justify-center px-3 py-2 text-sm font-medium leading-4 text-gray-700 bg-white border border-gray-300 rounded-md shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500"
>
<svg className="w-4 h-4 mr-1 sm:mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.414A1 1 0 013 6.707V4z" />
</svg>
<span className="hidden sm:inline">{showErrorFilters ? 'Ocultar Filtros' : 'Mostrar Filtros'}</span>
<span className="sm:hidden">Filtros</span>
</button>
</>
)}
</div>
</div>
{/* Filtros expandibles para errores */}
{showErrorFilters && (
<div className="grid grid-cols-1 gap-4 p-4 border rounded-lg md:grid-cols-2 lg:grid-cols-4 bg-red-50">
<div>
<label className="block mb-1 text-sm font-medium text-gray-700">
Buscar por nombre
</label>
<input
type="text"
value={errorFilters.name}
onChange={(e) => setErrorFilters(prev => ({ ...prev, name: e.target.value }))}
placeholder="Nombre del archivo..."
className="w-full px-3 py-2 placeholder-gray-400 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm"
/>
</div>
<div>
<label className="block mb-1 text-sm font-medium text-gray-700">
Extensión
</label>
<select
value={errorFilters.extension}
onChange={(e) => setErrorFilters(prev => ({ ...prev, extension: e.target.value }))}
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm"
>
<option value="">Todas las extensiones</option>
<option value="pdf">PDF</option>
<option value="xml">XML</option>
<option value="jpg">JPG</option>
<option value="png">PNG</option>
<option value="doc">DOC</option>
<option value="docx">DOCX</option>
<option value="xls">XLS</option>
<option value="xlsx">XLSX</option>
<option value="txt">TXT</option>
<option value="csv">CSV</option>
</select>
</div>
<div>
<label className="block mb-1 text-sm font-medium text-gray-700">
Fuente
</label>
<select
value={errorFilters.fuente || ''}
onChange={(e) => setErrorFilters(prev => ({ ...prev, fuente: e.target.value }))}
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm"
>
<option value="">Todas las fuentes</option>
<option value="1">Manual</option>
<option value="2">VU</option>
<option value="3">Importación</option>
<option value="4">Sistema</option>
</select>
</div>
<div>
<label className="block mb-1 text-sm font-medium text-gray-700">
Tipo de Error
</label>
<select
value={errorFilters.tipo_error || ''}
onChange={(e) => setErrorFilters(prev => ({ ...prev, tipo_error: e.target.value }))}
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm"
>
<option value="">Todos los errores</option>
<option value="14">Error Pedimento Completo VU</option>
<option value="16">Error Remesa VU</option>
<option value="18">Error Partidas VU</option>
<option value="20">Error COVES VU</option>
<option value="22">Error Edocuments VU</option>
<option value="24">Error Acuse COVES VU</option>
<option value="26">Error Acuse Edocuments VU</option>
</select>
</div>
{/* <div>
<label className="block mb-1 text-sm font-medium text-gray-700">
Fecha de creación
</label>
<input
type="date"
value={errorFilters.date}
onChange={(e) => setErrorFilters(prev => ({ ...prev, date: e.target.value }))}
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm"
/>
</div> */}
<div className="flex items-end">
<button
onClick={() => setErrorFilters({
name: '',
document_type: '',
extension: '',
date: '',
created_at__gte: '',
created_at__lte: '',
fuente: '',
pedimento_numero: ''
})}
className="w-full px-3 py-2 text-sm font-medium text-gray-600 transition-colors bg-gray-100 rounded-md hover:bg-gray-200"
>
Limpiar filtros
</button>
</div>
</div>
)}
</div>
{/* Área de acciones para documentos de error seleccionados */}
{selectedErrorDocuments.length > 0 && (
<div className="mb-4 overflow-hidden border border-red-200 bg-gradient-to-r from-red-50 to-pink-50 rounded-2xl">
<div className="px-6 py-4 border-b border-red-200">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="p-2 bg-red-100 rounded-full">
<svg className="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<div>
<h3 className="text-lg font-semibold text-gray-900">
{selectedErrorDocuments.length} documento{selectedErrorDocuments.length !== 1 ? 's' : ''} de error seleccionado{selectedErrorDocuments.length !== 1 ? 's' : ''}
</h3>
<p className="text-sm text-gray-600">Selecciona una acción para continuar</p>
</div>
</div>
<button
onClick={() => {
setSelectedErrorDocuments([]);
setIsSelectAllErrorDocs(false);
}}
className="text-gray-400 transition-colors hover:text-gray-600"
title="Limpiar selección"
>
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
</div>
<div className="px-6 py-4">
<div className="flex flex-wrap gap-3">
<button
onClick={handleDeleteSelectedErrorDocuments}
className="inline-flex items-center px-4 py-2 font-medium text-white transition-colors duration-200 bg-red-600 rounded-lg shadow-sm hover:bg-red-700 hover:shadow-md"
>
<svg className="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
Eliminar seleccionados
</button>
</div>
</div>
</div>
)}
{errorDocsLoading ? (
<div className="flex items-center justify-center py-12">
<div className="w-8 h-8 border-b-2 border-red-600 rounded-full animate-spin"></div>
<span className="ml-2 text-gray-600">Cargando documentos de error...</span>
</div>
) : errorDocsError ? (
<div className="py-12 text-center">
<div className="mb-2 text-red-600">
<svg className="w-12 h-12 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.664-.833-2.464 0L4.35 16.5c-.77.833.192 2.5 1.732 2.5z" />
</svg>
</div>
<h3 className="mb-1 text-lg font-medium text-gray-900">Error al cargar documentos de error</h3>
<p className="text-gray-600">{errorDocsError}</p>
</div>
) : errorDocuments.length === 0 ? (
<div className="py-12 text-center">
<svg className="w-12 h-12 mx-auto text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<h3 className="mt-2 text-sm font-medium text-gray-900">No hay documentos de error</h3>
<p className="mt-1 text-sm text-gray-500">
No se encontraron documentos de error VU para este pedimento.
</p>
</div>
) : (
<div className="space-y-4">
{/* Tabla de documentos de error */}
<div className="overflow-hidden rounded-lg shadow ring-1 ring-black ring-opacity-5">
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-gray-300">
<thead className="bg-gray-50">
<tr>
<th scope="col" className="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
<input
type="checkbox"
checked={isSelectAllErrorDocs}
onChange={handleSelectAllErrorDocuments}
className="w-4 h-4 text-red-600 border-gray-300 rounded focus:ring-red-500"
/>
</th>
<th scope="col" className="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Documento
</th>
<th scope="col" className="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Tipo
</th>
<th scope="col" className="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Extensión
</th>
<th scope="col" className="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Tamaño
</th>
<th scope="col" className="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Fuente
</th>
<th scope="col" className="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Fecha de Creación
</th>
<th scope="col" className="relative px-6 py-3">
<span className="sr-only">Acciones</span>
</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{errorDocuments.map((doc, index) => (
<tr key={`${doc.id}-${index}`} className="hover:bg-gray-50">
<td className="px-6 py-4 whitespace-nowrap">
<input
type="checkbox"
checked={selectedErrorDocuments.includes(doc.id)}
onChange={() => handleSelectErrorDocument(doc.id)}
className="w-4 h-4 text-red-600 border-gray-300 rounded focus:ring-red-500"
/>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<div className="flex items-center">
<div className="flex-shrink-0 w-10 h-10">
<div className="flex items-center justify-center w-10 h-10 bg-red-100 rounded-lg">
<svg className="w-6 h-6 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.664-.833-2.464 0L4.35 16.5c-.77.833.192 2.5 1.732 2.5z" />
</svg>
</div>
</div>
<div className="ml-4">
<div className="text-sm font-medium text-gray-900" title={doc.archivo}>
{doc.archivo ? doc.archivo.split('/').pop() : 'Sin nombre'}
</div>
<div className="text-sm text-gray-500">
Pedimento: {doc.pedimento_numero || 'N/A'}
</div>
</div>
</div>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
{getDocumentTypeName(doc.document_type)}
</span>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
{doc.extension ? doc.extension.toUpperCase() : 'N/A'}
</span>
</td>
<td className="px-6 py-4 text-sm text-gray-900 whitespace-nowrap">
{formatFileSize(doc.size)}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
{doc.fuente_nombre}
</span>
</td>
<td className="px-6 py-4 text-sm text-gray-500 whitespace-nowrap">
{formatDate(doc.created_at)}
</td>
<td className="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
<div className="flex items-center space-x-2">
<button
onClick={() => previewDocument(doc)}
className="p-1 text-blue-600 rounded hover:text-blue-900"
title="Vista previa"
>
<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.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
</svg>
</button>
<button
onClick={() => downloadDocument(doc)}
className="p-1 text-green-600 rounded hover:text-green-900"
title="Descargar"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
</button>
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
)}
{/* Paginación para documentos de error */}
{errorDocsCount > 0 && (
<div className="flex flex-col gap-4 mt-6 sm:flex-row sm:items-center sm:justify-between">
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-4">
<span className="text-sm text-gray-700">
<span className="hidden sm:inline">Mostrando </span>
<span className="font-medium">{((errorDocsPage - 1) * errorDocsPageSize) + 1}</span>-
<span className="font-medium">{Math.min(errorDocsPage * errorDocsPageSize, errorDocsCount)}</span>
<span className="hidden sm:inline">de </span>
<span className="sm:hidden">/</span>
<span className="font-medium">{errorDocsCount}</span>
<span className="hidden sm:inline"> documentos</span>
</span>
<select
value={errorDocsPageSize}
onChange={(e) => {
setErrorDocsPageSize(Number(e.target.value));
setErrorDocsPage(1);
}}
className="w-full text-sm border-gray-300 rounded-md focus:ring-red-500 focus:border-red-500 sm:w-auto"
>
<option value={10}>10 por página</option>
<option value={25}>25 por página</option>
<option value={50}>50 por página</option>
<option value={100}>100 por página</option>
</select>
</div>
<div className="flex items-center justify-center space-x-1 sm:justify-end sm:space-x-2">
<button
onClick={() => setErrorDocsPage(Math.max(1, errorDocsPage - 1))}
disabled={errorDocsPage === 1}
className="relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-l-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed"
>
<span className="sr-only">Anterior</span>
<svg className="w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fillRule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clipRule="evenodd" />
</svg>
</button>
<span className="relative inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300">
Página {errorDocsPage} de {Math.ceil(errorDocsCount / errorDocsPageSize)}
</span>
<button
onClick={() => setErrorDocsPage(Math.min(Math.ceil(errorDocsCount / errorDocsPageSize), errorDocsPage + 1))}
disabled={errorDocsPage >= Math.ceil(errorDocsCount / errorDocsPageSize)}
className="relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-r-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed"
>
<span className="sr-only">Siguiente</span>
<svg className="w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fillRule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clipRule="evenodd" />
</svg>
</button>
</div>
</div>
)}
</div>
)}
</div> </div>
</div> </div>