Private
Public Access
hecha parte de reporte usando el decorator
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
67ca0c8222
commit
9fa5cf63f9
26 files changed
+680
-44
No files matched your search
@@ -0,0 +1,129 @@
|
||||
<script lang="ts">
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import {
|
||||
Button,
|
||||
DataTable,
|
||||
DatePicker,
|
||||
DatePickerInput,
|
||||
Form,
|
||||
InlineNotification,
|
||||
Select,
|
||||
SelectItem
|
||||
} from 'carbon-components-svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let error = $state('');
|
||||
$effect(() => {
|
||||
if (data.error) error = data.error;
|
||||
});
|
||||
|
||||
let reporte = $derived(data.reporte ?? {});
|
||||
let movimientos = $derived(Array.isArray(reporte.movimientos) ? reporte.movimientos : []);
|
||||
let resumen = $derived(Array.isArray(reporte.resumen) ? reporte.resumen : []);
|
||||
|
||||
let filtros = $state({
|
||||
almacenId: 0,
|
||||
tipo: '',
|
||||
desde: '',
|
||||
hasta: ''
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
filtros.almacenId = data.filtros?.almacenId ?? 0;
|
||||
filtros.tipo = data.filtros?.tipo ?? '';
|
||||
filtros.desde = data.filtros?.desde ?? '';
|
||||
filtros.hasta = data.filtros?.hasta ?? '';
|
||||
});
|
||||
|
||||
const headers = [
|
||||
{ key: 'fecha', value: 'Fecha' },
|
||||
{ key: 'tipo', value: 'Tipo' },
|
||||
{ key: 'repuesto', value: 'Repuesto' },
|
||||
{ key: 'almacen', value: 'Almacén' },
|
||||
{ key: 'cantidad', value: 'Cantidad' }
|
||||
];
|
||||
|
||||
const rows = $derived(
|
||||
movimientos.map((m: any, i: number) => ({
|
||||
id: m.id ?? i,
|
||||
fecha: m.fecha,
|
||||
tipo: m.tipo,
|
||||
repuesto: m.repuesto?.nombre ?? m.repuestoId,
|
||||
almacen: m.almacenId,
|
||||
cantidad: m.cantidad
|
||||
}))
|
||||
);
|
||||
|
||||
function aplicarFiltros() {
|
||||
const params = new URLSearchParams();
|
||||
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);
|
||||
if (filtros.hasta) params.set('hasta', filtros.hasta);
|
||||
void goto(`/stock/reportes${params.toString() ? `?${params.toString()}` : ''}`);
|
||||
}
|
||||
|
||||
function limpiarFiltros() {
|
||||
filtros = { almacenId: 0, tipo: '', desde: '', hasta: '' };
|
||||
void goto('/stock/reportes', { replaceState: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
|
||||
<div class="page-container">
|
||||
<div class="flex justify-between items-center mb-4!">
|
||||
<h1 class="page-title">Reporte de stock</h1>
|
||||
<Button kind="tertiary" onclick={() => goto('/stock')}>Volver</Button>
|
||||
</div>
|
||||
|
||||
<Form
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
aplicarFiltros();
|
||||
}}
|
||||
>
|
||||
<div class="flex flex-wrap gap-4 items-end mb-4!">
|
||||
<Select labelText="Almacén" bind:selected={filtros.almacenId}>
|
||||
<SelectItem value={0} text="Todos" />
|
||||
{#each data.almacenes as a (a.id)}
|
||||
<SelectItem value={a.id} text={a.nombre} />
|
||||
{/each}
|
||||
</Select>
|
||||
|
||||
<Select labelText="Tipo" bind:selected={filtros.tipo}>
|
||||
<SelectItem value="" text="Todos" />
|
||||
{#each (reporte.tipos ?? []) as t}
|
||||
<SelectItem value={t} text={t} />
|
||||
{/each}
|
||||
</Select>
|
||||
|
||||
<DatePicker
|
||||
datePickerType="range"
|
||||
on:change={(e) => {
|
||||
const dates = (e as CustomEvent).detail?.selectedDates ?? [];
|
||||
filtros.desde = dates[0]?.toISOString().slice(0, 10) ?? '';
|
||||
filtros.hasta = dates[1]?.toISOString().slice(0, 10) ?? '';
|
||||
}}
|
||||
>
|
||||
<DatePickerInput labelText="Desde" placeholder="mm/dd/yyyy" value={filtros.desde} />
|
||||
<DatePickerInput labelText="Hasta" placeholder="mm/dd/yyyy" value={filtros.hasta} />
|
||||
</DatePicker>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<Button type="submit">Generar</Button>
|
||||
<Button kind="ghost" onclick={limpiarFiltros}>Limpiar</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
{#if error}
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton class="mb-4" />
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
<DataTable {headers} {rows} />
|
||||
</div>
|
||||
Reference in new issue
Block a user