74 lines
2.8 KiB
TypeScript
74 lines
2.8 KiB
TypeScript
|
|
import apiClient from '../apiClient';
|
||
|
|
import type { FacturaDto } from '../../models/dtos/Suscripciones/FacturaDto';
|
||
|
|
import type { GenerarFacturacionResponseDto } from '../../models/dtos/Suscripciones/GenerarFacturacionResponseDto';
|
||
|
|
import type { PagoDto } from '../../models/dtos/Suscripciones/PagoDto';
|
||
|
|
import type { CreatePagoDto } from '../../models/dtos/Suscripciones/CreatePagoDto';
|
||
|
|
import type { ProcesamientoLoteResponseDto } from '../../models/dtos/Suscripciones/ProcesamientoLoteResponseDto';
|
||
|
|
|
||
|
|
const API_URL = '/facturacion';
|
||
|
|
const DEBITOS_URL = '/debitos';
|
||
|
|
const PAGOS_URL = '/pagos';
|
||
|
|
const FACTURAS_URL = '/facturas';
|
||
|
|
|
||
|
|
const procesarArchivoRespuesta = async (archivo: File): Promise<ProcesamientoLoteResponseDto> => {
|
||
|
|
const formData = new FormData();
|
||
|
|
formData.append('archivo', archivo);
|
||
|
|
|
||
|
|
const response = await apiClient.post<ProcesamientoLoteResponseDto>(`${DEBITOS_URL}/procesar-respuesta`, formData, {
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'multipart/form-data',
|
||
|
|
},
|
||
|
|
});
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const getFacturasPorPeriodo = async (anio: number, mes: number): Promise<FacturaDto[]> => {
|
||
|
|
const response = await apiClient.get<FacturaDto[]>(`${API_URL}/${anio}/${mes}`);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const generarFacturacionMensual = async (anio: number, mes: number): Promise<GenerarFacturacionResponseDto> => {
|
||
|
|
const response = await apiClient.post<GenerarFacturacionResponseDto>(`${API_URL}/${anio}/${mes}`);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const generarArchivoDebito = async (anio: number, mes: number): Promise<{ fileContent: Blob, fileName: string }> => {
|
||
|
|
const response = await apiClient.post(`${DEBITOS_URL}/${anio}/${mes}/generar-archivo`, {}, {
|
||
|
|
responseType: 'blob',
|
||
|
|
});
|
||
|
|
|
||
|
|
const contentDisposition = response.headers['content-disposition'];
|
||
|
|
let fileName = `debito_${anio}_${mes}.txt`;
|
||
|
|
if (contentDisposition) {
|
||
|
|
const fileNameMatch = contentDisposition.match(/filename="(.+)"/);
|
||
|
|
if (fileNameMatch && fileNameMatch.length > 1) {
|
||
|
|
fileName = fileNameMatch[1];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return { fileContent: response.data, fileName: fileName };
|
||
|
|
};
|
||
|
|
|
||
|
|
const getPagosPorFactura = async (idFactura: number): Promise<PagoDto[]> => {
|
||
|
|
const response = await apiClient.get<PagoDto[]>(`${FACTURAS_URL}/${idFactura}/pagos`);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const registrarPagoManual = async (data: CreatePagoDto): Promise<PagoDto> => {
|
||
|
|
const response = await apiClient.post<PagoDto>(PAGOS_URL, data);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const enviarFacturaPorEmail = async (idFactura: number): Promise<void> => {
|
||
|
|
await apiClient.post(`${API_URL}/${idFactura}/enviar-email`);
|
||
|
|
};
|
||
|
|
|
||
|
|
export default {
|
||
|
|
procesarArchivoRespuesta,
|
||
|
|
getFacturasPorPeriodo,
|
||
|
|
generarFacturacionMensual,
|
||
|
|
generarArchivoDebito,
|
||
|
|
getPagosPorFactura,
|
||
|
|
registrarPagoManual,
|
||
|
|
enviarFacturaPorEmail,
|
||
|
|
};
|