Private
Public Access
1 parent
bc0db6dbee
commit
fcf16df5d3
21 files changed
+728
-3
No files matched your search
@@ -0,0 +1,111 @@
|
||||
<script lang="ts">
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import { Button, DataTableSkeleton, InlineNotification, Table, TableBody, TableCell, TableContainer, TableHead, TableHeader, TableRow } from 'carbon-components-svelte';
|
||||
import { Add, ArrowUp, Edit, TrashCan } from 'carbon-icons-svelte';
|
||||
import type { FormaDePago } from '../../types';
|
||||
import CrearFormaDePagoForm from './CrearFormaDePagoForm.svelte';
|
||||
import EditarFormaDePagoForm from './EditarFormaDePagoForm.svelte';
|
||||
import EliminarFormaDePagoForm from './EliminarFormaDePagoForm.svelte';
|
||||
import AltaFormaDePagoForm from './AltaFormaDePagoForm.svelte';
|
||||
|
||||
let error = $state("");
|
||||
|
||||
let { data }: {data: {formasPago: string | Array<FormaDePago>}} = $props();
|
||||
|
||||
let formasPago = $derived(Array.isArray(data.formasPago) ? data.formasPago : []);
|
||||
|
||||
$effect(()=>{
|
||||
if (typeof data.formasPago === "string"){
|
||||
error = data.formasPago
|
||||
}
|
||||
});
|
||||
|
||||
const headers: { key: keyof FormaDePago; value: string }[] = [
|
||||
{ key: 'ID', value: 'ID' },
|
||||
{ key: 'descripcion', value: 'Descripción' },
|
||||
{ key: 'CreatedAt', value: 'Creado' },
|
||||
{ key: 'UpdatedAt', value: 'Actualizado' },
|
||||
{ key: 'DeletedAt', value: 'Estado' }
|
||||
];
|
||||
|
||||
let openCrear = $state(false);
|
||||
let openEdit = $state(false);
|
||||
let openDelete = $state(false);
|
||||
let formaSeleccionada: FormaDePago | null = $state(null);
|
||||
let formaAEliminar: FormaDePago | null = $state(null);
|
||||
let openAlta = $state(false);
|
||||
let formaAAlta: FormaDePago | null = $state(null);
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
<div class="page-container">
|
||||
<div class="flex justify-between">
|
||||
<h1 class="page-title">Gestión de Formas de Pago</h1>
|
||||
<Button onclick={() => {openCrear = true}} icon={Add}>Nueva Forma de Pago</Button>
|
||||
</div>
|
||||
{#if error}
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||
{/if}
|
||||
{#if typeof data.formasPago === "undefined" || data.formasPago === null}
|
||||
<DataTableSkeleton />
|
||||
{:else if formasPago.length === 0}
|
||||
<TableContainer title="Formas de Pago">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
{#each headers as header}
|
||||
<TableHeader>{header.value}</TableHeader>
|
||||
{/each}
|
||||
<TableHeader>Acciones</TableHeader>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
<TableRow>
|
||||
<TableCell colspan={headers.length+1}>No hay formas de pago para mostrar, registre una</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{:else}
|
||||
<TableContainer title="Listado de Formas de Pago">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
{#each headers as header}
|
||||
<TableHeader>{header.value}</TableHeader>
|
||||
{/each}
|
||||
<TableHeader>Acciones</TableHeader>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{#each formasPago as p}
|
||||
<TableRow>
|
||||
{#each headers as header}
|
||||
<TableCell>{header.key === 'DeletedAt' ? (p.DeletedAt ? '✖' : '✔') : String(p[header.key] ?? '-')}</TableCell>
|
||||
{/each}
|
||||
<TableCell>
|
||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => { formaSeleccionada = p; openEdit = true; }}>Editar</Button>
|
||||
{#if p.DeletedAt}
|
||||
<Button kind="ghost" size="small" icon={ArrowUp} onclick={() => { formaAAlta = p; openAlta = true; }}>Alta</Button>
|
||||
{:else}
|
||||
<Button kind="ghost" size="small" icon={TrashCan} onclick={() => { formaAEliminar = p; openDelete = true; }}>Eliminar</Button>
|
||||
{/if}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
<CrearFormaDePagoForm bind:open={openCrear} onClose={() => openCrear = false} />
|
||||
|
||||
<EliminarFormaDePagoForm bind:open={openDelete} forma={formaAEliminar} onClose={() => { openDelete = false; formaAEliminar = null; }} />
|
||||
|
||||
<AltaFormaDePagoForm bind:open={openAlta} forma={formaAAlta} onClose={()=> openAlta = false} />
|
||||
|
||||
<EditarFormaDePagoForm bind:open={openEdit} forma={formaSeleccionada} onClose={() => { openEdit = false; formaSeleccionada = null; }} />
|
||||
Reference in new issue
Block a user