Private
Public Access
121 lines
3.0 KiB
Svelte
121 lines
3.0 KiB
Svelte
<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"
|
|
danger
|
|
modalHeading="Liberar reserva"
|
|
primaryButtonText={enviando ? 'Liberando…' : 'Confirmar liberación'}
|
|
primaryButtonDisabled={enviando}
|
|
secondaryButtonText="Cancelar"
|
|
secondaryButtonDisabled={enviando}
|
|
on:click:button--secondary={handleClose}
|
|
>
|
|
{#if error}
|
|
<div class="mb-4">
|
|
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
|
</div>
|
|
{/if}
|
|
|
|
<p class="mb-4 text-sm">
|
|
¿Confirmás que querés liberar esta reserva? La reserva pasará a estado
|
|
<span class="font-semibold">liberada</span>.
|
|
</p>
|
|
|
|
<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">Almacén</p>
|
|
<p class="font-semibold">{reserva?.almacen?.codigo ?? reserva?.almacen_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={`Se liberarán ${formatearCantidad(
|
|
reserva?.cantidad ?? 0
|
|
)} unidades reservadas. El stock volverá a estar disponible para la venta.`}
|
|
hideCloseButton
|
|
/>
|
|
</Modal>
|
|
</form>
|