feat(reportes): rediseño Estado de Resultados vertical con drill-down, análisis horizontal/vertical y export Excel
- 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
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { apiClient } from './client';
|
||||
import type { EstadoResultados, FlujoEfectivo, ComparativoPeriodos, ConcentradoRfc } from '@horux/shared';
|
||||
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();
|
||||
@@ -10,6 +10,71 @@ export async function getEstadoResultados(fechaInicio?: string, fechaFin?: strin
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user