48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import * as dashboardApi from '../api/dashboard';
|
|
import { useTenantViewStore } from '@/stores/tenant-view-store';
|
|
import { useContribuyenteStore } from '@/stores/contribuyente-store';
|
|
|
|
function useTenantKey() {
|
|
const { viewingTenantId } = useTenantViewStore();
|
|
return viewingTenantId || 'own';
|
|
}
|
|
|
|
export function useKpis(fechaInicio: string, fechaFin: string, conciliacion?: boolean) {
|
|
const tenantKey = useTenantKey();
|
|
const { selectedContribuyenteId } = useContribuyenteStore();
|
|
return useQuery({
|
|
queryKey: ['kpis', tenantKey, fechaInicio, fechaFin, conciliacion, selectedContribuyenteId],
|
|
queryFn: () => dashboardApi.getKpis(fechaInicio, fechaFin, conciliacion, selectedContribuyenteId),
|
|
enabled: !!fechaInicio && !!fechaFin,
|
|
});
|
|
}
|
|
|
|
export function useIngresosEgresos(año?: number, conciliacion?: boolean) {
|
|
const tenantKey = useTenantKey();
|
|
const { selectedContribuyenteId } = useContribuyenteStore();
|
|
return useQuery({
|
|
queryKey: ['ingresos-egresos', tenantKey, año, conciliacion, selectedContribuyenteId],
|
|
queryFn: () => dashboardApi.getIngresosEgresos(año, conciliacion, selectedContribuyenteId),
|
|
});
|
|
}
|
|
|
|
export function useRegimenesDelPeriodo(fechaInicio: string, fechaFin: string, conciliacion?: boolean) {
|
|
const tenantKey = useTenantKey();
|
|
const { selectedContribuyenteId } = useContribuyenteStore();
|
|
return useQuery({
|
|
queryKey: ['regimenes-periodo', tenantKey, fechaInicio, fechaFin, conciliacion, selectedContribuyenteId],
|
|
queryFn: () => dashboardApi.getRegimenesDelPeriodo(fechaInicio, fechaFin, conciliacion, selectedContribuyenteId),
|
|
enabled: !!fechaInicio && !!fechaFin,
|
|
});
|
|
}
|
|
|
|
export function useAlertas(limit = 5) {
|
|
const tenantKey = useTenantKey();
|
|
const { selectedContribuyenteId } = useContribuyenteStore();
|
|
return useQuery({
|
|
queryKey: ['alertas', tenantKey, limit, selectedContribuyenteId],
|
|
queryFn: () => dashboardApi.getAlertas(limit, selectedContribuyenteId),
|
|
});
|
|
}
|