feat: Implement create/edit dialog for pedimentos management
- Added create-edit-dialog component for creating and editing pedimentos. - Integrated dialog with data table actions for editing existing pedimentos. - Implemented infinite scroll functionality in the data table for loading more pedimentos. - Enhanced server-side loading of pedimentos with authentication checks. - Added filtering options for pedimentos based on status, client ID, and year. - Improved error handling and user feedback for actions like creating, editing, and deleting pedimentos.
This commit is contained in:
126
frontend/src/lib/api/dashboard/a76/pedimentos.ts
Normal file
126
frontend/src/lib/api/dashboard/a76/pedimentos.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* API Client para Pedimentos
|
||||
* Gestiona las operaciones CRUD para pedimentos
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export interface Pedimento {
|
||||
id: number;
|
||||
tenant_id: number;
|
||||
year?: string | null;
|
||||
customs_office?: string | null;
|
||||
license?: string | null;
|
||||
pedimento_number?: string | null;
|
||||
client_id?: number | null;
|
||||
operation_type?: number | null;
|
||||
pedimento_type?: number | null;
|
||||
pedimento_key?: string | null;
|
||||
regime?: string | null;
|
||||
status?: string | null;
|
||||
usd_value?: number | null;
|
||||
paid_price?: number | null;
|
||||
gross_weight?: number | null;
|
||||
exchange_rate?: number | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface PedimentoListResponse {
|
||||
items: Pedimento[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export interface CreatePedimentoData {
|
||||
year?: string | null;
|
||||
customs_office?: string | null;
|
||||
license?: string | null;
|
||||
pedimento_number?: string | null;
|
||||
client_id?: number | null;
|
||||
operation_type?: number | null;
|
||||
pedimento_type?: number | null;
|
||||
pedimento_key?: string | null;
|
||||
regime?: string | null;
|
||||
status?: string | null;
|
||||
usd_value?: number | null;
|
||||
paid_price?: number | null;
|
||||
gross_weight?: number | null;
|
||||
exchange_rate?: number | null;
|
||||
}
|
||||
|
||||
export interface UpdatePedimentoData {
|
||||
year?: string | null;
|
||||
customs_office?: string | null;
|
||||
license?: string | null;
|
||||
pedimento_number?: string | null;
|
||||
client_id?: number | null;
|
||||
operation_type?: number | null;
|
||||
pedimento_type?: number | null;
|
||||
pedimento_key?: string | null;
|
||||
regime?: string | null;
|
||||
status?: string | null;
|
||||
usd_value?: number | null;
|
||||
paid_price?: number | null;
|
||||
gross_weight?: number | null;
|
||||
exchange_rate?: number | null;
|
||||
}
|
||||
|
||||
export interface PedimentoFilters {
|
||||
status?: string;
|
||||
client_id?: number;
|
||||
year?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* API para Pedimentos
|
||||
*/
|
||||
export const pedimentosApi = {
|
||||
/**
|
||||
* Lista todos los pedimentos con paginación y filtros
|
||||
* @param page - Número de página (por defecto 1)
|
||||
* @param pageSize - Tamaño de página (por defecto 50)
|
||||
* @param filters - Filtros opcionales
|
||||
*/
|
||||
list: (page = 1, pageSize = 50, filters?: PedimentoFilters) => {
|
||||
let url = `/v1/a76/pedimentos?page=${page}&page_size=${pageSize}`;
|
||||
|
||||
if (filters?.status) {
|
||||
url += `&status=${encodeURIComponent(filters.status)}`;
|
||||
}
|
||||
if (filters?.client_id) {
|
||||
url += `&client_id=${filters.client_id}`;
|
||||
}
|
||||
if (filters?.year) {
|
||||
url += `&year=${encodeURIComponent(filters.year)}`;
|
||||
}
|
||||
|
||||
return api.get<PedimentoListResponse>(url);
|
||||
},
|
||||
|
||||
/**
|
||||
* Obtiene un pedimento por ID
|
||||
* @param id - ID del pedimento
|
||||
*/
|
||||
get: (id: number) => api.get<Pedimento>(`/v1/a76/pedimentos/${id}`),
|
||||
|
||||
/**
|
||||
* Crea un nuevo pedimento
|
||||
* @param data - Datos del pedimento a crear
|
||||
*/
|
||||
create: (data: CreatePedimentoData) =>
|
||||
api.post<Pedimento>('/v1/a76/pedimentos', data),
|
||||
|
||||
/**
|
||||
* Actualiza un pedimento existente
|
||||
* @param id - ID del pedimento a actualizar
|
||||
* @param data - Datos a actualizar
|
||||
*/
|
||||
update: (id: number, data: UpdatePedimentoData) =>
|
||||
api.put<Pedimento>(`/v1/a76/pedimentos/${id}`, data),
|
||||
|
||||
/**
|
||||
* Elimina un pedimento
|
||||
* @param id - ID del pedimento a eliminar
|
||||
*/
|
||||
delete: (id: number) => api.delete(`/v1/a76/pedimentos/${id}`)
|
||||
};
|
||||
Reference in New Issue
Block a user