- Nuevo endpoint GET /reportes/estado-resultados-detallado con cálculo contable:
* Ventas, Devoluciones, Ventas netas, Costo de ventas, Utilidad bruta,
Gastos operativos, Utilidad de la operación
* Fórmula: subtotal_mxn - descuento_mxn (sin impuestos), nómina usa total_mxn
* Excluye anticipos (uso_cfdi=P01 o clave_prod_serv=84111506)
* Filtro por régimen fiscal opcional
* Año anterior calculado automáticamente
- Nuevo endpoint GET /reportes/estado-resultados/drill-down:
* Nivel 1: resumen agrupado por RFC
* Nivel 2: CFDIs individuales filtrados por categoría
* Categorías: ventas, devoluciones, costo-ventas, gastos-operativos
- Nuevo endpoint GET /reportes/estado-resultados/export:
* Genera Excel con formato condicional (verde/rojo, negritas)
- Frontend:
* Tabla vertical con % vertical, año anterior y variación %
* Filas clickeables para drill-down modal de 2 niveles
* Top 10 Clientes/Proveedores mantenidos debajo
* Selector de régimen conectado al reporte
- Fix: NaN en total de drill-down nivel 2 por numeric como string en pg
* Agregado ::float en queries SQL de CFDIs individuales
135 lines
5.4 KiB
TypeScript
135 lines
5.4 KiB
TypeScript
import { apiClient } from './client';
|
|
import type { EstadoResultados, EstadoResultadosDetallado, FlujoEfectivo, ComparativoPeriodos, ConcentradoRfc } from '@horux/shared';
|
|
|
|
export async function getEstadoResultados(fechaInicio?: string, fechaFin?: string, contribuyenteId?: string): Promise<EstadoResultados> {
|
|
const params = new URLSearchParams();
|
|
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
|
if (fechaFin) params.set('fechaFin', fechaFin);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const response = await apiClient.get<EstadoResultados>(`/reportes/estado-resultados?${params}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getEstadoResultadosDetallado(
|
|
fechaInicio?: string,
|
|
fechaFin?: string,
|
|
regimen?: string,
|
|
contribuyenteId?: string,
|
|
): Promise<EstadoResultadosDetallado> {
|
|
const params = new URLSearchParams();
|
|
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
|
if (fechaFin) params.set('fechaFin', fechaFin);
|
|
if (regimen) params.set('regimen', regimen);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const response = await apiClient.get<EstadoResultadosDetallado>(`/reportes/estado-resultados-detallado?${params}`);
|
|
return response.data;
|
|
}
|
|
|
|
export interface DrillDownResumenItem {
|
|
rfc: string;
|
|
nombre: string;
|
|
cantidad: number;
|
|
monto: number;
|
|
}
|
|
|
|
export interface DrillDownCfdiItem {
|
|
id: number;
|
|
uuid: string;
|
|
tipoComprobante: string;
|
|
fechaEmision: string;
|
|
rfcEmisor: string;
|
|
nombreEmisor: string;
|
|
rfcReceptor: string;
|
|
nombreReceptor: string;
|
|
monto: number;
|
|
metodoPago: string | null;
|
|
regimenFiscalEmisor: string | null;
|
|
regimenFiscalReceptor: string | null;
|
|
}
|
|
|
|
export async function getEstadoResultadosDrillDown(
|
|
categoria: string,
|
|
fechaInicio?: string,
|
|
fechaFin?: string,
|
|
regimen?: string,
|
|
rfc?: string,
|
|
contribuyenteId?: string,
|
|
): Promise<DrillDownResumenItem[] | DrillDownCfdiItem[]> {
|
|
const params = new URLSearchParams();
|
|
params.set('categoria', categoria);
|
|
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
|
if (fechaFin) params.set('fechaFin', fechaFin);
|
|
if (regimen) params.set('regimen', regimen);
|
|
if (rfc) params.set('rfc', rfc);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const response = await apiClient.get<DrillDownResumenItem[] | DrillDownCfdiItem[]>(`/reportes/estado-resultados/drill-down?${params}`);
|
|
return response.data;
|
|
}
|
|
|
|
export function getExportEstadoResultadosUrl(fechaInicio?: string, fechaFin?: string, regimen?: string, contribuyenteId?: string): string {
|
|
const params = new URLSearchParams();
|
|
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
|
if (fechaFin) params.set('fechaFin', fechaFin);
|
|
if (regimen) params.set('regimen', regimen);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
return `/reportes/estado-resultados/export?${params}`;
|
|
}
|
|
|
|
export async function getFlujoEfectivo(fechaInicio?: string, fechaFin?: string, contribuyenteId?: string): Promise<FlujoEfectivo> {
|
|
const params = new URLSearchParams();
|
|
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
|
if (fechaFin) params.set('fechaFin', fechaFin);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const response = await apiClient.get<FlujoEfectivo>(`/reportes/flujo-efectivo?${params}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getComparativo(año?: number, contribuyenteId?: string): Promise<ComparativoPeriodos> {
|
|
const params = new URLSearchParams();
|
|
if (año) params.set('año', String(año));
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const qs = params.toString();
|
|
const response = await apiClient.get<ComparativoPeriodos>(`/reportes/comparativo${qs ? `?${qs}` : ''}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getConcentradoRfc(
|
|
tipo: 'cliente' | 'proveedor',
|
|
fechaInicio?: string,
|
|
fechaFin?: string,
|
|
contribuyenteId?: string,
|
|
): Promise<ConcentradoRfc[]> {
|
|
const params = new URLSearchParams({ tipo });
|
|
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
|
if (fechaFin) params.set('fechaFin', fechaFin);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const response = await apiClient.get<ConcentradoRfc[]>(`/reportes/concentrado-rfc?${params}`);
|
|
return response.data;
|
|
}
|
|
|
|
export interface CuentasPendientes {
|
|
cantidadCfdis: number;
|
|
saldoTotal: number;
|
|
detalle: { rfc: string; nombre: string; cantidad: number; saldo: number }[];
|
|
}
|
|
|
|
export async function getCuentasXPagar(fechaInicio: string, fechaFin: string, regimen?: string, contribuyenteId?: string): Promise<CuentasPendientes> {
|
|
const params = new URLSearchParams();
|
|
params.set('fechaInicio', fechaInicio);
|
|
params.set('fechaFin', fechaFin);
|
|
if (regimen) params.set('regimen', regimen);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const response = await apiClient.get<CuentasPendientes>(`/reportes/cuentas-x-pagar?${params}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getCuentasXCobrar(fechaInicio: string, fechaFin: string, regimen?: string, contribuyenteId?: string): Promise<CuentasPendientes> {
|
|
const params = new URLSearchParams();
|
|
params.set('fechaInicio', fechaInicio);
|
|
params.set('fechaFin', fechaFin);
|
|
if (regimen) params.set('regimen', regimen);
|
|
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
|
|
const response = await apiClient.get<CuentasPendientes>(`/reportes/cuentas-x-cobrar?${params}`);
|
|
return response.data;
|
|
}
|