Private
Public Access
hecha funcionalidad de reportes y exportacion de reportes
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
61baaf14f8
commit
298f3c699c
7 files changed
+338
-7
No files matched your search
@@ -11,10 +11,14 @@
|
||||
SelectItem
|
||||
} from 'carbon-components-svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { exportarReporteStock } from '$lib/hooks/stock/exportarReporteStock';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let error = $state('');
|
||||
let exportError = $state('');
|
||||
let exportando = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if (data.error) error = data.error;
|
||||
});
|
||||
@@ -24,6 +28,7 @@
|
||||
let resumen = $derived(Array.isArray(reporte.resumen) ? reporte.resumen : []);
|
||||
|
||||
let filtros = $state({
|
||||
repuestoId: 0,
|
||||
almacenId: 0,
|
||||
tipo: '',
|
||||
desde: '',
|
||||
@@ -31,6 +36,7 @@
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
filtros.repuestoId = data.filtros?.repuestoId ?? 0;
|
||||
filtros.almacenId = data.filtros?.almacenId ?? 0;
|
||||
filtros.tipo = data.filtros?.tipo ?? '';
|
||||
filtros.desde = data.filtros?.desde ?? '';
|
||||
@@ -42,22 +48,25 @@
|
||||
{ key: 'tipo', value: 'Tipo' },
|
||||
{ key: 'repuesto', value: 'Repuesto' },
|
||||
{ key: 'almacen', value: 'Almacén' },
|
||||
{ key: 'cantidad', value: 'Cantidad' }
|
||||
{ key: 'cantidad', value: 'Cantidad' },
|
||||
{ key: 'saldo', value: 'Saldo posterior' }
|
||||
];
|
||||
|
||||
const rows = $derived(
|
||||
movimientos.map((m: any, i: number) => ({
|
||||
id: m.id ?? i,
|
||||
fecha: m.fecha,
|
||||
fecha: m.fecha ? new Date(m.fecha).toLocaleString() : '',
|
||||
tipo: m.tipo,
|
||||
repuesto: m.repuesto?.nombre ?? m.repuestoId,
|
||||
almacen: m.almacenId,
|
||||
cantidad: m.cantidad
|
||||
cantidad: m.cantidad,
|
||||
saldo: m.saldoPosterior
|
||||
}))
|
||||
);
|
||||
|
||||
function aplicarFiltros() {
|
||||
const params = new URLSearchParams();
|
||||
if (filtros.repuestoId) params.set('repuestoId', String(filtros.repuestoId));
|
||||
if (filtros.almacenId) params.set('almacenId', String(filtros.almacenId));
|
||||
if (filtros.tipo) params.set('tipo', filtros.tipo);
|
||||
if (filtros.desde) params.set('desde', filtros.desde);
|
||||
@@ -66,9 +75,24 @@
|
||||
}
|
||||
|
||||
function limpiarFiltros() {
|
||||
filtros = { almacenId: 0, tipo: '', desde: '', hasta: '' };
|
||||
filtros = { repuestoId: 0, almacenId: 0, tipo: '', desde: '', hasta: '' };
|
||||
void goto('/stock/reportes', { replaceState: true });
|
||||
}
|
||||
|
||||
async function exportar(formato: 'csv' | 'xlsx') {
|
||||
exportError = '';
|
||||
exportando = true;
|
||||
const filtrosExport = {
|
||||
repuestoId: filtros.repuestoId || undefined,
|
||||
almacenId: filtros.almacenId || undefined,
|
||||
tipo: filtros.tipo || undefined,
|
||||
desde: filtros.desde || undefined,
|
||||
hasta: filtros.hasta || undefined
|
||||
};
|
||||
const resultado = await exportarReporteStock(formato, filtrosExport);
|
||||
exportando = false;
|
||||
if (resultado) exportError = resultado;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
@@ -86,6 +110,13 @@
|
||||
}}
|
||||
>
|
||||
<div class="flex flex-wrap gap-4 items-end mb-4!">
|
||||
<Select labelText="Repuesto" bind:selected={filtros.repuestoId}>
|
||||
<SelectItem value={0} text="Todos" />
|
||||
{#each data.repuestos as r (r.ID)}
|
||||
<SelectItem value={r.ID} text={r.nombre ?? r.ID} />
|
||||
{/each}
|
||||
</Select>
|
||||
|
||||
<Select labelText="Almacén" bind:selected={filtros.almacenId}>
|
||||
<SelectItem value={0} text="Todos" />
|
||||
{#each data.almacenes as a (a.id)}
|
||||
@@ -123,7 +154,37 @@
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton class="mb-4" />
|
||||
{/if}
|
||||
|
||||
{#if exportError}
|
||||
<InlineNotification kind="error" title="Exportación" subtitle={exportError} hideCloseButton class="mb-4" />
|
||||
{/if}
|
||||
|
||||
<div class="flex gap-2 mb-4!">
|
||||
<Button kind="secondary" disabled={exportando} onclick={() => exportar('csv')}>
|
||||
{exportando ? 'Exportando...' : 'Exportar CSV'}
|
||||
</Button>
|
||||
<Button kind="secondary" disabled={exportando} onclick={() => exportar('xlsx')}>
|
||||
{exportando ? 'Exportando...' : 'Exportar Excel'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<DataTable {headers} {rows} />
|
||||
</div>
|
||||
{#if movimientos.length === 0}
|
||||
<InlineNotification kind="info" title="Sin datos" subtitle="No hay movimientos para los filtros seleccionados." hideCloseButton class="mb-4" />
|
||||
{:else}
|
||||
<DataTable {headers} {rows} />
|
||||
{/if}
|
||||
|
||||
{#if resumen.length > 0}
|
||||
<h2 class="mt-6 mb-2">Totales por tipo</h2>
|
||||
<DataTable
|
||||
headers={[
|
||||
{ key: 'tipo', value: 'Tipo' },
|
||||
{ key: 'cantidad', value: 'Cantidad' }
|
||||
]}
|
||||
rows={resumen.map((r: any, i: number) => ({
|
||||
id: i,
|
||||
tipo: r.tipo,
|
||||
cantidad: r.cantidad
|
||||
}))}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
Reference in new issue
Block a user