Private
Public Access
cocinado cu-01
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
31f8b493d0
commit
3c4bc5c008
15 files changed
+510
-32
No files matched your search
@@ -1,10 +1,34 @@
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from '../token';
|
||||
|
||||
export async function obtenerFacturas(fetch2?: Function) {
|
||||
export interface FiltrosFactura {
|
||||
numero?: string;
|
||||
cliente?: string;
|
||||
clienteId?: number;
|
||||
estado?: string;
|
||||
desde?: string;
|
||||
hasta?: string;
|
||||
pagina?: number;
|
||||
porPagina?: number;
|
||||
}
|
||||
|
||||
export async function obtenerFacturas(fetch2?: Function, filtros?: FiltrosFactura) {
|
||||
const fetchfn = fetch2 ? fetch2 : fetch;
|
||||
const params = new URLSearchParams();
|
||||
if (filtros) {
|
||||
if (filtros.numero) params.set('numero', filtros.numero);
|
||||
if (filtros.cliente) params.set('cliente', filtros.cliente);
|
||||
if (filtros.clienteId) params.set('clienteId', String(filtros.clienteId));
|
||||
if (filtros.estado) params.set('estado', filtros.estado);
|
||||
if (filtros.desde) params.set('desde', filtros.desde);
|
||||
if (filtros.hasta) params.set('hasta', filtros.hasta);
|
||||
if (filtros.pagina) params.set('pagina', String(filtros.pagina));
|
||||
if (filtros.porPagina) params.set('porPagina', String(filtros.porPagina));
|
||||
}
|
||||
const qs = params.toString();
|
||||
const url = `${API_URL}/facturas/${qs ? `?${qs}` : ''}`;
|
||||
try {
|
||||
const req = await fetchfn(`${API_URL}/facturas/`, {
|
||||
const req = await fetchfn(url, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` }
|
||||
});
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
<script lang="ts">
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import {
|
||||
Button,
|
||||
DataTableSkeleton,
|
||||
InlineNotification,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableContainer,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
Tag,
|
||||
TextInput,
|
||||
Select,
|
||||
SelectItem,
|
||||
Modal
|
||||
} from 'carbon-components-svelte';
|
||||
import { Add, View, Edit, Money, Close, Search } from 'carbon-icons-svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { getPermissions } from '$lib/hooks/token';
|
||||
import type { Factura } from '../../types';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let error = $state('');
|
||||
let info = $state('');
|
||||
$effect(() => {
|
||||
if (data.error) error = data.error;
|
||||
});
|
||||
|
||||
let facturas = $derived<Factura[]>(Array.isArray(data.facturas) ? data.facturas : []);
|
||||
let filtros = $derived(data.filtros ?? { numero: '', cliente: '', estado: '', desde: '', hasta: '' });
|
||||
let cargando = $derived(data.facturas === undefined || data.facturas === null);
|
||||
|
||||
let puedeVentas = $derived(getPermissions().includes(13));
|
||||
|
||||
let numero = $state('');
|
||||
let cliente = $state('');
|
||||
let estado = $state('');
|
||||
let desde = $state('');
|
||||
let hasta = $state('');
|
||||
|
||||
$effect(() => {
|
||||
numero = filtros.numero ?? '';
|
||||
cliente = filtros.cliente ?? '';
|
||||
estado = filtros.estado ?? '';
|
||||
desde = filtros.desde ?? '';
|
||||
hasta = filtros.hasta ?? '';
|
||||
});
|
||||
|
||||
let facturaVer: Factura | null = $state(null);
|
||||
let openVer = $state(false);
|
||||
|
||||
function buscar() {
|
||||
const params = new URLSearchParams();
|
||||
if (numero) params.set('numero', numero);
|
||||
if (cliente) params.set('cliente', cliente);
|
||||
if (estado) params.set('estado', estado);
|
||||
if (desde) params.set('desde', desde);
|
||||
if (hasta) params.set('hasta', hasta);
|
||||
const q = params.toString();
|
||||
void goto(`/facturas${q ? `?${q}` : ''}`, { keepFocus: true, noScroll: true });
|
||||
}
|
||||
|
||||
function limpiar() {
|
||||
void goto('/facturas', { keepFocus: true, noScroll: true });
|
||||
}
|
||||
|
||||
function estadoTagKind(estado: string): 'green' | 'blue' | 'red' | 'gray' | 'warm-gray' {
|
||||
switch (estado) {
|
||||
case 'PAGADA':
|
||||
return 'green';
|
||||
case 'PARCIAL':
|
||||
return 'blue';
|
||||
case 'CANCELADA':
|
||||
return 'red';
|
||||
case 'EMITIDA':
|
||||
return 'warm-gray';
|
||||
default:
|
||||
return 'gray';
|
||||
}
|
||||
}
|
||||
|
||||
function formatFecha(iso?: string): string {
|
||||
if (!iso) return '-';
|
||||
try {
|
||||
return new Date(iso).toLocaleDateString('es-AR');
|
||||
} catch {
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
|
||||
function formatMonto(n?: number): string {
|
||||
if (n === undefined || n === null) return '-';
|
||||
return n.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' });
|
||||
}
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
|
||||
<div class="page-container">
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-2">
|
||||
<h1 class="page-title">Gestión de Facturas</h1>
|
||||
{#if puedeVentas}
|
||||
<Button icon={Add} onclick={() => (info = 'La creación de facturas se implementa en CU-02.')}>
|
||||
Nueva Factura
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if !puedeVentas}
|
||||
<InlineNotification kind="warning" title="Sin permisos" subtitle="No tenés permiso para gestionar ventas y facturación." hideCloseButton />
|
||||
{:else}
|
||||
<form class="mb-6 flex flex-wrap items-end gap-4" onsubmit={(e) => { e.preventDefault(); buscar(); }}>
|
||||
<div class="min-w-56 flex-1">
|
||||
<TextInput labelText="Buscar" placeholder="N° factura o cliente" bind:value={numero} />
|
||||
</div>
|
||||
<div class="min-w-40">
|
||||
<TextInput labelText="Cliente" placeholder="Nombre del cliente" bind:value={cliente} />
|
||||
</div>
|
||||
<Select labelText="Estado" bind:selected={estado}>
|
||||
<SelectItem value="" text="Todos" />
|
||||
<SelectItem value="EMITIDA" text="Emitida" />
|
||||
<SelectItem value="PARCIAL" text="Parcial" />
|
||||
<SelectItem value="PAGADA" text="Pagada" />
|
||||
<SelectItem value="CANCELADA" text="Cancelada" />
|
||||
</Select>
|
||||
<div class="min-w-36">
|
||||
<TextInput labelText="Desde" placeholder="YYYY-MM-DD" bind:value={desde} />
|
||||
</div>
|
||||
<div class="min-w-36">
|
||||
<TextInput labelText="Hasta" placeholder="YYYY-MM-DD" bind:value={hasta} />
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<Button type="submit" icon={Search}>Buscar</Button>
|
||||
<Button kind="ghost" icon={Close} onclick={limpiar}>Limpiar</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{#if error}
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||
{/if}
|
||||
{#if info}
|
||||
<InlineNotification kind="info" title="Info" subtitle={info} hideCloseButton />
|
||||
{/if}
|
||||
|
||||
{#if cargando}
|
||||
<DataTableSkeleton headers={[{ key: 'numero', value: 'N° Factura' }, { key: 'cliente', value: 'Cliente' }, { key: 'fecha', value: 'Fecha' }, { key: 'total', value: 'Total' }, { key: 'estado', value: 'Estado' }]} rows={5} size="compact" showHeader={false} showToolbar={false} />
|
||||
{:else if facturas.length === 0}
|
||||
<TableContainer title="Facturas">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableHeader>N° Factura</TableHeader>
|
||||
<TableHeader>Cliente</TableHeader>
|
||||
<TableHeader>Fecha</TableHeader>
|
||||
<TableHeader>Total</TableHeader>
|
||||
<TableHeader>Estado</TableHeader>
|
||||
<TableHeader>Acciones</TableHeader>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
<TableRow>
|
||||
<TableCell colspan={6}>No existen facturas registradas</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{:else}
|
||||
<TableContainer title="Listado de Facturas">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableHeader>N° Factura</TableHeader>
|
||||
<TableHeader>Cliente</TableHeader>
|
||||
<TableHeader>Fecha</TableHeader>
|
||||
<TableHeader>Total</TableHeader>
|
||||
<TableHeader>Estado</TableHeader>
|
||||
<TableHeader>Acciones</TableHeader>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{#each facturas as f (f.ID)}
|
||||
<TableRow>
|
||||
<TableCell>{f.numero ?? `F-${f.ID}`}</TableCell>
|
||||
<TableCell>{f.cliente?.nombre ?? '-'}</TableCell>
|
||||
<TableCell>{formatFecha(f.CreatedAt)}</TableCell>
|
||||
<TableCell>{formatMonto(f.total)}</TableCell>
|
||||
<TableCell>
|
||||
<Tag type={estadoTagKind(f.estado)}>{f.estado}</Tag>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<Button kind="ghost" size="small" icon={View} onclick={() => { facturaVer = f; openVer = true; }}>Ver</Button>
|
||||
<Button kind="ghost" size="small" icon={Edit} disabled={f.estado === 'CANCELADA' || f.estado === 'PAGADA'}>Modificar</Button>
|
||||
<Button kind="ghost" size="small" icon={Money} disabled={f.estado === 'CANCELADA' || f.estado === 'PAGADA'}>Registrar Pago</Button>
|
||||
<Button kind="danger-ghost" size="small" icon={Close} disabled={f.estado === 'CANCELADA'}>Cancelar</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<Modal bind:open={openVer} modalHeading={`Comprobante ${facturaVer?.numero ?? ''}`} passiveModal>
|
||||
{#if facturaVer}
|
||||
<div class="space-y-2">
|
||||
<p><strong>Cliente:</strong> {facturaVer.cliente?.nombre ?? '-'}</p>
|
||||
<p><strong>CUIT:</strong> {facturaVer.cliente?.cuit ?? '-'}</p>
|
||||
<p><strong>Fecha:</strong> {formatFecha(facturaVer.CreatedAt)}</p>
|
||||
<p><strong>Total:</strong> {formatMonto(facturaVer.total)}</p>
|
||||
<p><strong>Estado:</strong> {facturaVer.estado}</p>
|
||||
{#if facturaVer.detalles && facturaVer.detalles.length > 0}
|
||||
<div class="mt-4">
|
||||
<p class="mb-2 font-semibold">Ítems</p>
|
||||
<ul class="list-disc pl-5">
|
||||
{#each facturaVer.detalles as d (d.repuestoId)}
|
||||
<li>Repuesto {d.repuestoId} — cant. {d.cantidad} × {formatMonto(d.precioUnitario)} = {formatMonto(d.subtotal)}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</Modal>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { obtenerFacturas } from '$lib/hooks/facturas/obtenerFacturas';
|
||||
|
||||
export let ssr = false;
|
||||
|
||||
export async function load({ fetch, depends, url }) {
|
||||
depends('facturas:load');
|
||||
|
||||
const filtros = {
|
||||
numero: url.searchParams.get('numero') ?? '',
|
||||
cliente: url.searchParams.get('cliente') ?? '',
|
||||
estado: url.searchParams.get('estado') ?? '',
|
||||
desde: url.searchParams.get('desde') ?? '',
|
||||
hasta: url.searchParams.get('hasta') ?? ''
|
||||
};
|
||||
|
||||
const facturas = await obtenerFacturas(fetch, filtros);
|
||||
|
||||
return {
|
||||
facturas,
|
||||
filtros,
|
||||
error: typeof facturas === 'string' ? facturas : ''
|
||||
};
|
||||
}
|
||||
Vendored
+28
@@ -276,6 +276,34 @@ export interface Proveedor {
|
||||
telefono?: string;
|
||||
}
|
||||
|
||||
export interface FacturaDetalle {
|
||||
repuestoId: number;
|
||||
cantidad: number;
|
||||
descuentoId?: number;
|
||||
descuento?: number;
|
||||
precioUnitario: number;
|
||||
subtotal: number;
|
||||
}
|
||||
|
||||
export interface Factura {
|
||||
ID: number;
|
||||
CreatedAt?: string;
|
||||
UpdatedAt?: string;
|
||||
DeletedAt?: string | null;
|
||||
EmpresaID?: number;
|
||||
numero?: string;
|
||||
estado: string;
|
||||
total: number;
|
||||
ClienteID?: number;
|
||||
cliente?: Cliente;
|
||||
ProveedorID?: number | null;
|
||||
proveedor?: Proveedor | null;
|
||||
seAviso?: boolean;
|
||||
detalles?: FacturaDetalle[];
|
||||
ResponsableID?: number;
|
||||
responsable?: Usuario | null;
|
||||
}
|
||||
|
||||
export interface FacturaResumen {
|
||||
ID: number;
|
||||
numero?: string;
|
||||
|
||||
Reference in new issue
Block a user