Update: nueva version Horux Despachos
This commit is contained in:
135
apps/web/lib/api/cfdi.ts
Normal file
135
apps/web/lib/api/cfdi.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
import { apiClient } from './client';
|
||||
import type { CfdiListResponse, CfdiFilters, Cfdi } from '@horux/shared';
|
||||
|
||||
export async function getCfdis(filters: CfdiFilters): Promise<CfdiListResponse> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (filters.tipo) params.set('tipo', filters.tipo);
|
||||
if (filters.tipoComprobante) params.set('tipoComprobante', filters.tipoComprobante);
|
||||
if (filters.estado) params.set('estado', filters.estado);
|
||||
if (filters.fechaInicio) params.set('fechaInicio', filters.fechaInicio);
|
||||
if (filters.fechaFin) params.set('fechaFin', filters.fechaFin);
|
||||
if (filters.rfc) params.set('rfc', filters.rfc);
|
||||
if (filters.emisor) params.set('emisor', filters.emisor);
|
||||
if (filters.receptor) params.set('receptor', filters.receptor);
|
||||
if (filters.search) params.set('search', filters.search);
|
||||
if (filters.page) params.set('page', filters.page.toString());
|
||||
if (filters.limit) params.set('limit', filters.limit.toString());
|
||||
if (filters.contribuyenteId) params.set('contribuyenteId', filters.contribuyenteId);
|
||||
|
||||
const response = await apiClient.get<CfdiListResponse>(`/cfdi?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getCfdiById(id: string): Promise<Cfdi> {
|
||||
const response = await apiClient.get<Cfdi>(`/cfdi/${id}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getResumenCfdi(año?: number, mes?: number, contribuyenteId?: string) {
|
||||
const params = new URLSearchParams();
|
||||
if (año) params.set('año', año.toString());
|
||||
if (mes) params.set('mes', mes.toString());
|
||||
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
||||
|
||||
const response = await apiClient.get(`/cfdi/resumen?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export interface CreateCfdiData {
|
||||
uuid: string;
|
||||
type: 'EMITIDO' | 'RECIBIDO';
|
||||
serie?: string;
|
||||
folio?: string;
|
||||
status?: string;
|
||||
fechaEmision: string;
|
||||
rfcEmisor: string;
|
||||
nombreEmisor: string;
|
||||
rfcReceptor: string;
|
||||
nombreReceptor: string;
|
||||
subtotal: number;
|
||||
subtotalMxn?: number;
|
||||
descuento?: number;
|
||||
descuentoMxn?: number;
|
||||
total: number;
|
||||
totalMxn?: number;
|
||||
moneda?: string;
|
||||
tipoCambio?: number;
|
||||
tipoComprobante?: string;
|
||||
metodoPago?: string;
|
||||
formaPago?: string;
|
||||
usoCfdi?: string;
|
||||
ivaTraslado?: number;
|
||||
ivaTrasladoMxn?: number;
|
||||
isrRetencion?: number;
|
||||
isrRetencionMxn?: number;
|
||||
ivaRetencion?: number;
|
||||
ivaRetencionMxn?: number;
|
||||
}
|
||||
|
||||
export async function createCfdi(data: CreateCfdiData): Promise<Cfdi> {
|
||||
const response = await apiClient.post<Cfdi>('/cfdi', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export interface BatchUploadResult {
|
||||
message: string;
|
||||
batchNumber: number;
|
||||
totalBatches: number;
|
||||
inserted: number;
|
||||
duplicates: number;
|
||||
errors: number;
|
||||
errorMessages?: string[];
|
||||
}
|
||||
|
||||
export async function createManyCfdis(
|
||||
cfdis: CreateCfdiData[],
|
||||
batchNumber?: number,
|
||||
totalBatches?: number,
|
||||
totalFiles?: number
|
||||
): Promise<BatchUploadResult> {
|
||||
const response = await apiClient.post<BatchUploadResult>('/cfdi/bulk', {
|
||||
cfdis,
|
||||
batchNumber: batchNumber || 1,
|
||||
totalBatches: totalBatches || 1,
|
||||
totalFiles: totalFiles || cfdis.length
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getCfdiConceptos(id: number | string): Promise<any[]> {
|
||||
const response = await apiClient.get<any[]>(`/cfdi/${id}/conceptos`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteCfdi(id: string): Promise<void> {
|
||||
await apiClient.delete(`/cfdi/${id}`);
|
||||
}
|
||||
|
||||
export async function getCfdiXml(id: string): Promise<string> {
|
||||
const response = await apiClient.get<string>(`/cfdi/${id}/xml`, {
|
||||
responseType: 'text'
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export interface EmisorReceptor {
|
||||
rfc: string;
|
||||
nombre: string;
|
||||
}
|
||||
|
||||
export async function searchEmisores(search: string, contribuyenteId?: string): Promise<EmisorReceptor[]> {
|
||||
if (search.length < 2) return [];
|
||||
const params = new URLSearchParams({ search });
|
||||
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
||||
const response = await apiClient.get<EmisorReceptor[]>(`/cfdi/emisores?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function searchReceptores(search: string, contribuyenteId?: string): Promise<EmisorReceptor[]> {
|
||||
if (search.length < 2) return [];
|
||||
const params = new URLSearchParams({ search });
|
||||
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
||||
const response = await apiClient.get<EmisorReceptor[]>(`/cfdi/receptores?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
Reference in New Issue
Block a user