Private
Public Access
feat: hecha funcionalidad del cu-12
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
5a8d4bc2d6
commit
37d357357a
14 files changed
+672
-116
No files matched your search
@@ -0,0 +1,107 @@
|
||||
<script lang="ts">
|
||||
import { InlineNotification, Modal } from 'carbon-components-svelte';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { liberarReserva } from '$lib/hooks/stock/liberarReserva';
|
||||
import { formatearCantidad } from '../formatoCantidad';
|
||||
import type { ReservaStock } from '../../../types';
|
||||
|
||||
let {
|
||||
open = $bindable(),
|
||||
onClose,
|
||||
reserva = null
|
||||
}: {
|
||||
open?: boolean;
|
||||
onClose?: () => void;
|
||||
reserva?: ReservaStock | null;
|
||||
} = $props();
|
||||
|
||||
let error = $state('');
|
||||
let enviando = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if (open) {
|
||||
error = '';
|
||||
enviando = false;
|
||||
}
|
||||
});
|
||||
|
||||
function handleClose() {
|
||||
onClose?.();
|
||||
}
|
||||
|
||||
function fecha(valor?: string | null) {
|
||||
if (!valor) return '-';
|
||||
const d = new Date(valor);
|
||||
return Number.isNaN(d.getTime()) ? '-' : d.toLocaleDateString();
|
||||
}
|
||||
|
||||
async function confirmar() {
|
||||
if (enviando || !reserva) return;
|
||||
enviando = true;
|
||||
error = '';
|
||||
|
||||
const res = await liberarReserva(reserva.ID);
|
||||
if (typeof res === 'string') {
|
||||
error = res;
|
||||
} else {
|
||||
await invalidate('reservas:load');
|
||||
handleClose();
|
||||
}
|
||||
enviando = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
id="liberarReservaForm"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void confirmar();
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="liberarReservaForm"
|
||||
bind:open
|
||||
size="sm"
|
||||
modalHeading="Liberar reserva"
|
||||
primaryButtonText="Confirmar liberación"
|
||||
primaryButtonDisabled={enviando}
|
||||
secondaryButtonText="Cancelar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="mb-4">
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="mb-4 grid grid-cols-1 gap-3">
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">Producto</p>
|
||||
<p class="font-semibold">{reserva?.repuesto?.nombre ?? reserva?.repuesto_id ?? '-'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">Cantidad reservada</p>
|
||||
<p class="font-semibold">{formatearCantidad(reserva?.cantidad ?? 0)}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">Reservado para</p>
|
||||
<p class="font-semibold">{reserva?.cliente?.nombre ?? '-'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">Fecha de reserva</p>
|
||||
<p class="font-semibold">{fecha(reserva?.CreatedAt)}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">Vence</p>
|
||||
<p class="font-semibold">{fecha(reserva?.fecha_vencimiento)}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<InlineNotification
|
||||
kind="warning"
|
||||
title="Atención"
|
||||
subtitle="Esta acción liberará el stock reservado y quedará disponible nuevamente para la venta."
|
||||
hideCloseButton
|
||||
/>
|
||||
</Modal>
|
||||
</form>
|
||||
Reference in new issue
Block a user