Merge pull request 'fixed/clientes_provedores_sellos' (#41) from fixed/clientes_provedores_sellos into feature/creacion_modulo_mercancias

Reviewed-on: ADUANASOFT/anexo76#41
This commit is contained in:
2026-01-06 20:17:45 +00:00
39 changed files with 770 additions and 2230 deletions

View File

@@ -1,170 +1,97 @@
/**
* API Client para Clientes y Proveedores
* Gestiona las operaciones CRUD para clientes y proveedores
*/
import { api } from '$lib/api';
// --- Interfaces para Tablas Hijas ---
export interface ClientProviderAddress {
id?: number;
street?: string | null;
neighborhood?: string | null;
city?: string | null;
state?: string | null;
country?: string | null;
zip_code?: string | null;
client_id?: number;
id?: number;
streets?: string | null;
exterior_number?: string | null;
interior_number?: string | null;
neighborhood?: string | null;
municipality?: string | null;
city?: string | null;
state?: string | null;
country?: string | null;
postal_code?: string | null;
email?: string | null;
phone?: string | null;
contact?: string | null;
}
export interface ClientProviderPrograms {
id?: number;
program_code?: string | null;
authorization_date?: string | null;
client_id?: number;
id?: number;
program?: string | null;
program_number?: string | null;
secon_auth_date?: number | null; // YYYYMMDD
prosec?: number | null;
manufacturer_id?: string | null;
tax_id?: string | null;
ctpat_svi?: string | null;
is_certified_company?: string | null;
}
// --- Interfaz Principal ---
export interface ClientProvider {
id: number;
rfc: string;
name: string;
curp?: string | null;
residence_country?: string | null;
domicile_fiscal?: string | null;
foreign_tax_id?: string | null;
client_or_provider?: string | null;
is_active?: boolean;
tenant_id: number;
address?: ClientProviderAddress | null;
programs?: ClientProviderPrograms | null;
}
export interface ClientProviderBasic {
id: number;
rfc: string;
name: string;
curp?: string | null;
residence_country?: string | null;
domicile_fiscal?: string | null;
foreign_tax_id?: string | null;
client_or_provider?: string | null;
is_active?: boolean;
tenant_id: number;
id: number;
rfc: string;
name: string;
short_name?: string | null;
curp?: string | null;
client_or_provider: 'client' | 'provider' | 'both';
// Campos planos de la tabla principal
type_nat_foreign?: string | null;
responsible?: string | null;
position?: string | null;
// Booleanos (Coincidiendo con la BD)
is_national_provider?: boolean | null;
is_active?: boolean;
// Relaciones Anidadas
address?: ClientProviderAddress | null;
programs?: ClientProviderPrograms | null;
}
export interface ClientProviderListResponse {
items: ClientProvider[];
total: number;
page: number;
page_size: number;
items: ClientProvider[];
total: number;
page: number;
page_size: number;
}
export interface CreateClientProviderData {
rfc: string;
name: string;
curp?: string | null;
residence_country?: string | null;
domicile_fiscal?: string | null;
foreign_tax_id?: string | null;
client_or_provider?: string | null;
is_active?: boolean;
address?: Omit<ClientProviderAddress, 'id' | 'client_id'> | null;
programs?: Omit<ClientProviderPrograms, 'id' | 'client_id'> | null;
// DTOs de Envío (excluyendo IDs automáticos)
export interface CreateClientProviderData extends Omit<ClientProvider, 'id' | 'address' | 'programs'> {
address?: ClientProviderAddress | null;
programs?: ClientProviderPrograms | null;
}
export interface UpdateClientProviderData {
rfc?: string;
name?: string;
curp?: string | null;
residence_country?: string | null;
domicile_fiscal?: string | null;
foreign_tax_id?: string | null;
client_or_provider?: string | null;
is_active?: boolean;
address?: Partial<ClientProviderAddress> | null;
programs?: Partial<ClientProviderPrograms> | null;
}
export interface UpdateClientProviderData extends Partial<CreateClientProviderData> {}
/**
* API para Clientes y Proveedores
*/
export const clientsProvidersApi = {
/**
* Lista todos los clientes y proveedores con paginación
* @param companyId - ID de la compañía
* @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: (companyId: number, page = 1, pageSize = 50, filters?: Record<string, any>) => {
const params = new URLSearchParams({
company_id: companyId.toString(),
page: page.toString(),
page_size: pageSize.toString()
});
list: (companyId: number, page = 1, pageSize = 50, filters?: Record<string, any>) => {
const params = new URLSearchParams({
company_id: companyId.toString(),
page: page.toString(),
page_size: pageSize.toString()
});
if (filters) {
Object.entries(filters).forEach(([key, value]) => {
if (value) params.append(key, value.toString());
});
}
return api.get<ClientProviderListResponse>(`/v1/a76/clients-providers?${params.toString()}`);
},
get: (id: number, companyId: number) =>
api.get<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`),
create: (companyId: number, data: any) =>
api.post<ClientProvider>(`/v1/a76/clients-providers?company_id=${companyId}`, data),
if (filters) {
Object.entries(filters).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
params.append(key, value.toString());
}
});
}
update: (id: number, companyId: number, data: any) =>
api.patch<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`, data),
return api.get<ClientProviderListResponse>(
`/v1/a76/clients-providers?${params.toString()}`
);
},
/**
* Obtiene un cliente/proveedor por ID
* @param id - ID del cliente/proveedor
* @param companyId - ID de la compañía
*/
get: (id: number, companyId: number) =>
api.get<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`),
/**
* Obtiene información básica de un cliente/proveedor
* @param id - ID del cliente/proveedor
* @param companyId - ID de la compañía
*/
getBasic: (id: number, companyId: number) =>
api.get<ClientProviderBasic>(
`/v1/a76/clients-providers/${id}/basic?company_id=${companyId}`
),
/**
* Crea un nuevo cliente/proveedor
* @param companyId - ID de la compañía
* @param data - Datos del cliente/proveedor a crear
*/
create: (companyId: number, data: CreateClientProviderData) =>
api.post<ClientProvider>(`/v1/a76/clients-providers?company_id=${companyId}`, data),
/**
* Actualiza un cliente/proveedor existente
* @param id - ID del cliente/proveedor a actualizar
* @param companyId - ID de la compañía
* @param data - Datos a actualizar
*/
update: (id: number, companyId: number, data: UpdateClientProviderData) =>
api.patch<ClientProvider>(`/v1/a76/clients-providers/${id}?company_id=${companyId}`, data),
/**
* Alterna el estado activo/inactivo de un cliente/proveedor
* @param id - ID del cliente/proveedor
* @param companyId - ID de la compañía
*/
toggleStatus: (id: number, companyId: number) =>
api.put<ClientProvider>(
`/v1/a76/clients-providers/${id}/toggle-status?company_id=${companyId}`,
{}
),
/**
* Elimina un cliente/proveedor
* @param id - ID del cliente/proveedor a eliminar
* @param companyId - ID de la compañía
*/
delete: (id: number, companyId: number) =>
api.delete(`/v1/a76/clients-providers/${id}?company_id=${companyId}`)
};
delete: (id: number, companyId: number) =>
api.delete(`/v1/a76/clients-providers/${id}?company_id=${companyId}`)
};