107 lines
3.0 KiB
JavaScript
107 lines
3.0 KiB
JavaScript
import { fetchWithAuth } from '../fetchWithAuth';
|
|
|
|
const API_BASE_URL = import.meta.env.VITE_EFC_API_URL;
|
|
|
|
export const fetchPedimentoProcesos = async (pedimentoId, page = 1, pageSize = 10, filters = {}) => {
|
|
try {
|
|
const params = new URLSearchParams({
|
|
pedimento: pedimentoId,
|
|
page: page.toString(),
|
|
page_size: pageSize.toString(),
|
|
});
|
|
|
|
// Agregar filtros si existen
|
|
if (filters.estado !== undefined && filters.estado !== '') {
|
|
params.append('estado', filters.estado);
|
|
}
|
|
if (filters.servicio !== undefined && filters.servicio !== '') {
|
|
params.append('servicio', filters.servicio);
|
|
}
|
|
if (filters.organizacion_name) {
|
|
params.append('organizacion_name__icontains', filters.organizacion_name);
|
|
}
|
|
if (filters.date_from) {
|
|
params.append('created_at__gte', filters.date_from);
|
|
}
|
|
if (filters.date_to) {
|
|
params.append('created_at__lte', filters.date_to);
|
|
}
|
|
if (filters.updated_from) {
|
|
params.append('updated_at__gte', filters.updated_from);
|
|
}
|
|
if (filters.updated_to) {
|
|
params.append('updated_at__lte', filters.updated_to);
|
|
}
|
|
|
|
const response = await fetchWithAuth(`${API_BASE_URL}/customs/procesamientopedimentos/?${params}`);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Error ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
return {
|
|
results: data.results,
|
|
count: data.count,
|
|
next: data.next,
|
|
previous: data.previous
|
|
};
|
|
} catch (error) {
|
|
console.error('Error fetching Procesos:', error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
// Mapeo de estados
|
|
export const getEstadoLabel = (estado) => {
|
|
const estados = {
|
|
1: 'Pendiente',
|
|
2: 'En Proceso',
|
|
3: 'Completado',
|
|
4: 'Error',
|
|
5: 'Cancelado'
|
|
};
|
|
return estados[estado] || `Estado ${estado}`;
|
|
};
|
|
|
|
export const getEstadoColor = (estado) => {
|
|
const colores = {
|
|
1: 'bg-yellow-100 text-yellow-800',
|
|
2: 'bg-blue-100 text-blue-800',
|
|
3: 'bg-green-100 text-green-800',
|
|
4: 'bg-red-100 text-red-800',
|
|
5: 'bg-gray-100 text-gray-800'
|
|
};
|
|
return colores[estado] || 'bg-gray-100 text-gray-800';
|
|
};
|
|
|
|
// Mapeo de servicios
|
|
export const getServicioLabel = (servicio) => {
|
|
const servicios = {
|
|
1: 'Digitalización',
|
|
2: 'Validación',
|
|
3: 'Procesamiento SAT',
|
|
4: 'Generación COVEs',
|
|
5: 'Generación EDocs',
|
|
6: 'Envío VUCEM',
|
|
7: 'Clasificación',
|
|
8: 'Archivo Digital',
|
|
9: 'Notificaciones'
|
|
};
|
|
return servicios[servicio] || `Servicio ${servicio}`;
|
|
};
|
|
|
|
export const getServicioColor = (servicio) => {
|
|
const colores = {
|
|
1: 'bg-purple-100 text-purple-800',
|
|
2: 'bg-indigo-100 text-indigo-800',
|
|
3: 'bg-blue-100 text-blue-800',
|
|
4: 'bg-cyan-100 text-cyan-800',
|
|
5: 'bg-teal-100 text-teal-800',
|
|
6: 'bg-green-100 text-green-800',
|
|
7: 'bg-yellow-100 text-yellow-800',
|
|
8: 'bg-orange-100 text-orange-800',
|
|
9: 'bg-pink-100 text-pink-800'
|
|
};
|
|
return colores[servicio] || 'bg-gray-100 text-gray-800';
|
|
}; |