Update: nueva version Horux Despachos
This commit is contained in:
53
apps/web/lib/hooks/use-facturacion.ts
Normal file
53
apps/web/lib/hooks/use-facturacion.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import * as facturacionApi from '../api/facturacion';
|
||||
import * as catalogosApi from '../api/catalogos';
|
||||
import { useTenantViewStore } from '@/stores/tenant-view-store';
|
||||
|
||||
function useTenantKey() {
|
||||
const { viewingTenantId } = useTenantViewStore();
|
||||
return viewingTenantId || 'own';
|
||||
}
|
||||
|
||||
// Facturación
|
||||
export function useOrgStatus() {
|
||||
const tk = useTenantKey();
|
||||
return useQuery({ queryKey: ['facturapi-org', tk], queryFn: facturacionApi.getOrgStatus });
|
||||
}
|
||||
|
||||
export function useTimbres() {
|
||||
const tk = useTenantKey();
|
||||
return useQuery({ queryKey: ['facturapi-timbres', tk], queryFn: facturacionApi.getTimbres });
|
||||
}
|
||||
|
||||
export function useEmitirFactura() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: facturacionApi.emitirFactura,
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['facturapi-timbres'] });
|
||||
qc.invalidateQueries({ queryKey: ['cfdi'] });
|
||||
qc.invalidateQueries({ queryKey: ['kpis'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Catálogos (se cachean globalmente, no dependen del tenant)
|
||||
export function useFormasPago() {
|
||||
return useQuery({ queryKey: ['cat-forma-pago'], queryFn: catalogosApi.getFormasPago, staleTime: Infinity });
|
||||
}
|
||||
|
||||
export function useMetodosPago() {
|
||||
return useQuery({ queryKey: ['cat-metodo-pago'], queryFn: catalogosApi.getMetodosPago, staleTime: Infinity });
|
||||
}
|
||||
|
||||
export function useUsosCfdi() {
|
||||
return useQuery({ queryKey: ['cat-uso-cfdi'], queryFn: catalogosApi.getUsosCfdi, staleTime: Infinity });
|
||||
}
|
||||
|
||||
export function useMonedas() {
|
||||
return useQuery({ queryKey: ['cat-moneda'], queryFn: catalogosApi.getMonedas, staleTime: Infinity });
|
||||
}
|
||||
|
||||
export function useClavesUnidad() {
|
||||
return useQuery({ queryKey: ['cat-clave-unidad'], queryFn: catalogosApi.getClavesUnidad, staleTime: Infinity });
|
||||
}
|
||||
Reference in New Issue
Block a user