Private
Public Access
commit parcial con la parte del front del crud almacenes
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
ea009e276f
commit
6f375cee45
13 files changed
+565
-4
No files matched your search
@@ -32,6 +32,7 @@ var permisosSemilla = []permisoSemilla{
|
|||||||
{14, "Generar Reporte de Stock", "stock/reportes", "Generar y consultar reportes de stock."},
|
{14, "Generar Reporte de Stock", "stock/reportes", "Generar y consultar reportes de stock."},
|
||||||
{15, "Gestión de Ventas y Facturación", "facturas", "Consultar y operar la facturación y ventas de la empresa."},
|
{15, "Gestión de Ventas y Facturación", "facturas", "Consultar y operar la facturación y ventas de la empresa."},
|
||||||
{16, "Gestión de Descuentos", "descuentos", "Crear, editar y eliminar descuentos."},
|
{16, "Gestión de Descuentos", "descuentos", "Crear, editar y eliminar descuentos."},
|
||||||
|
{17, "Administración de Almacenes", "almacenes_abm", "Crear, editar y eliminar almacenes."},
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitPermisos crea el catálogo global de permisos y garantiza que cada
|
// InitPermisos crea el catálogo global de permisos y garantiza que cada
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { API_URL } from '$lib/env';
|
||||||
|
import { getToken } from '../token';
|
||||||
|
import type { AlmacenDto } from './crearAlmacen';
|
||||||
|
|
||||||
|
export async function actualizarAlmacen(id: number, dto: AlmacenDto) {
|
||||||
|
try {
|
||||||
|
const req = await fetch(`${API_URL}/almacenes/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${getToken()}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify(dto)
|
||||||
|
});
|
||||||
|
if (req.ok) return 'ok';
|
||||||
|
const data = await req.json().catch(() => ({}));
|
||||||
|
return data.error ?? 'No se pudo actualizar el almacén';
|
||||||
|
} catch {
|
||||||
|
return 'No se pudo alcanzar el servidor';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { API_URL } from '$lib/env';
|
||||||
|
import { getToken } from '../token';
|
||||||
|
|
||||||
|
export async function altaAlmacen(id: number) {
|
||||||
|
try {
|
||||||
|
const req = await fetch(`${API_URL}/almacenes/${id}/alta`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${getToken()}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (req.ok) return 'ok';
|
||||||
|
const data = await req.json().catch(() => ({}));
|
||||||
|
return data.error ?? 'No se pudo reactivar el almacén';
|
||||||
|
} catch {
|
||||||
|
return 'No se pudo alcanzar el servidor';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { API_URL } from '$lib/env';
|
||||||
|
import { getToken } from '../token';
|
||||||
|
|
||||||
|
export interface AlmacenDto {
|
||||||
|
codigo: string;
|
||||||
|
ubicacion?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function crearAlmacen(dto: AlmacenDto) {
|
||||||
|
try {
|
||||||
|
const req = await fetch(`${API_URL}/almacenes/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${getToken()}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify(dto)
|
||||||
|
});
|
||||||
|
if (req.ok) return 'ok';
|
||||||
|
const data = await req.json().catch(() => ({}));
|
||||||
|
return data.error ?? 'No se pudo crear el almacén';
|
||||||
|
} catch {
|
||||||
|
return 'No se pudo alcanzar el servidor';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { API_URL } from '$lib/env';
|
||||||
|
import { getToken } from '../token';
|
||||||
|
|
||||||
|
export async function eliminarAlmacen(id: number) {
|
||||||
|
try {
|
||||||
|
const req = await fetch(`${API_URL}/almacenes/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${getToken()}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (req.ok) return 'Ok';
|
||||||
|
const data = await req.json().catch(() => ({}));
|
||||||
|
return data.error ?? 'No se pudo eliminar el almacén';
|
||||||
|
} catch {
|
||||||
|
return 'No se pudo alcanzar el servidor';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
import { API_URL } from '$lib/env';
|
import { API_URL } from '$lib/env';
|
||||||
|
import type { Almacen } from '../../../types';
|
||||||
import { getToken } from '../token';
|
import { getToken } from '../token';
|
||||||
|
|
||||||
export async function obtenerAlmacenes(fetch2?: Function) {
|
export async function obtenerAlmacenes(fetch2?: Function): Promise<Almacen[] | string> {
|
||||||
const fetchfn = fetch2 ? fetch2 : fetch;
|
const fetchfn = fetch2 ? fetch2 : fetch;
|
||||||
try {
|
try {
|
||||||
const req = await fetchfn(`${API_URL}/almacenes/`, {
|
const req = await fetchfn(`${API_URL}/almacenes/todos`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` }
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` }
|
||||||
});
|
});
|
||||||
const data = await req.json();
|
const data = await req.json();
|
||||||
if (req.ok) return data;
|
if (req.ok) return data;
|
||||||
return data.error ?? 'error';
|
return data.error ?? 'No se pudieron obtener los almacenes';
|
||||||
} catch {
|
} catch {
|
||||||
return 'no se pudo alcanzar el servidor';
|
return 'No se pudo alcanzar el servidor';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Header from '$lib/components/Header.svelte';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DataTableSkeleton,
|
||||||
|
InlineNotification,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableContainer,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
Tag
|
||||||
|
} from 'carbon-components-svelte';
|
||||||
|
import { Add, ArrowUp, Edit, TrashCan } from 'carbon-icons-svelte';
|
||||||
|
import type { Almacen } from '../../types';
|
||||||
|
import CrearAlmacenForm from './CrearAlmacenForm.svelte';
|
||||||
|
import EditarAlmacenForm from './EditarAlmacenForm.svelte';
|
||||||
|
import EliminarAlmacenForm from './EliminarAlmacenForm.svelte';
|
||||||
|
import AltaAlmacenForm from './AltaAlmacenForm.svelte';
|
||||||
|
|
||||||
|
let { data }: { data: { almacenes: Almacen[] | string } } = $props();
|
||||||
|
|
||||||
|
let almacenes = $derived<Almacen[]>(Array.isArray(data.almacenes) ? data.almacenes : []);
|
||||||
|
let errorCarga = $derived(
|
||||||
|
data.almacenes !== undefined && data.almacenes !== null && !Array.isArray(data.almacenes)
|
||||||
|
? String(data.almacenes)
|
||||||
|
: ''
|
||||||
|
);
|
||||||
|
|
||||||
|
let openCrear = $state(false);
|
||||||
|
let openEdit = $state(false);
|
||||||
|
let openDelete = $state(false);
|
||||||
|
let openAlta = $state(false);
|
||||||
|
|
||||||
|
let almacenSeleccionado = $state<Almacen | null>(null);
|
||||||
|
let almacenAEliminar = $state<Almacen | null>(null);
|
||||||
|
let almacenAAlta = $state<Almacen | null>(null);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Header />
|
||||||
|
<div class="page-container">
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<h1 class="page-title">Gestión de Almacenes</h1>
|
||||||
|
<Button
|
||||||
|
icon={Add}
|
||||||
|
onclick={() => {
|
||||||
|
openCrear = true;
|
||||||
|
}}>Nuevo Almacén</Button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if errorCarga}
|
||||||
|
<InlineNotification kind="error" title="Error" subtitle={errorCarga} hideCloseButton />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if typeof data.almacenes === 'undefined' || data.almacenes === null}
|
||||||
|
<DataTableSkeleton />
|
||||||
|
{:else if almacenes.length === 0}
|
||||||
|
<TableContainer title="Almacenes">
|
||||||
|
<Table>
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<TableHeader>ID</TableHeader>
|
||||||
|
<TableHeader>Código</TableHeader>
|
||||||
|
<TableHeader>Ubicación</TableHeader>
|
||||||
|
<TableHeader>Creado</TableHeader>
|
||||||
|
<TableHeader>Estado</TableHeader>
|
||||||
|
<TableHeader>Acciones</TableHeader>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colspan={6}>
|
||||||
|
No hay almacenes para mostrar, registrá uno.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
{:else}
|
||||||
|
<TableContainer title="Listado de Almacenes">
|
||||||
|
<Table>
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<TableHeader>ID</TableHeader>
|
||||||
|
<TableHeader>Código</TableHeader>
|
||||||
|
<TableHeader>Ubicación</TableHeader>
|
||||||
|
<TableHeader>Creado</TableHeader>
|
||||||
|
<TableHeader>Estado</TableHeader>
|
||||||
|
<TableHeader>Acciones</TableHeader>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
{#each almacenes as a (a.id)}
|
||||||
|
<TableRow>
|
||||||
|
<TableCell>{a.id}</TableCell>
|
||||||
|
<TableCell>{a.codigo}</TableCell>
|
||||||
|
<TableCell>{a.ubicacion || '-'}</TableCell>
|
||||||
|
<TableCell>{String(a.CreatedAt ?? '-')}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{#if a.DeletedAt}
|
||||||
|
<Tag type="red">Eliminado</Tag>
|
||||||
|
{:else}
|
||||||
|
<Tag type="green">Habilitado</Tag>
|
||||||
|
{/if}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{#if a.DeletedAt}
|
||||||
|
<Button
|
||||||
|
kind="ghost"
|
||||||
|
size="small"
|
||||||
|
icon={ArrowUp}
|
||||||
|
onclick={() => {
|
||||||
|
almacenAAlta = a;
|
||||||
|
openAlta = true;
|
||||||
|
}}>Alta</Button
|
||||||
|
>
|
||||||
|
{:else}
|
||||||
|
<Button
|
||||||
|
kind="ghost"
|
||||||
|
size="small"
|
||||||
|
icon={Edit}
|
||||||
|
onclick={() => {
|
||||||
|
almacenSeleccionado = a;
|
||||||
|
openEdit = true;
|
||||||
|
}}>Editar</Button
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
kind="danger-ghost"
|
||||||
|
size="small"
|
||||||
|
icon={TrashCan}
|
||||||
|
onclick={() => {
|
||||||
|
almacenAEliminar = a;
|
||||||
|
openDelete = true;
|
||||||
|
}}>Eliminar</Button
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
{/each}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CrearAlmacenForm bind:open={openCrear} onClose={() => (openCrear = false)} />
|
||||||
|
|
||||||
|
<EditarAlmacenForm
|
||||||
|
bind:open={openEdit}
|
||||||
|
almacen={almacenSeleccionado}
|
||||||
|
onClose={() => {
|
||||||
|
openEdit = false;
|
||||||
|
almacenSeleccionado = null;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<EliminarAlmacenForm
|
||||||
|
bind:open={openDelete}
|
||||||
|
almacen={almacenAEliminar}
|
||||||
|
onClose={() => {
|
||||||
|
openDelete = false;
|
||||||
|
almacenAEliminar = null;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<AltaAlmacenForm
|
||||||
|
bind:open={openAlta}
|
||||||
|
almacen={almacenAAlta}
|
||||||
|
onClose={() => {
|
||||||
|
openAlta = false;
|
||||||
|
almacenAAlta = null;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
EOF
|
||||||
|
echo done
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { obtenerAlmacenes } from '$lib/hooks/almacenes/obtenerAlmacenes';
|
||||||
|
|
||||||
|
export const ssr = false;
|
||||||
|
|
||||||
|
export async function load({ depends, fetch }) {
|
||||||
|
depends('almacenes:load');
|
||||||
|
const almacenes = await obtenerAlmacenes(fetch);
|
||||||
|
|
||||||
|
return { almacenes };
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { invalidate } from '$app/navigation';
|
||||||
|
import { InlineNotification, Modal } from 'carbon-components-svelte';
|
||||||
|
import type { Almacen } from '../../types';
|
||||||
|
import { altaAlmacen } from '$lib/hooks/almacenes/altaAlmacen';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(),
|
||||||
|
onClose,
|
||||||
|
almacen
|
||||||
|
}: { open?: boolean; onClose?: () => void; almacen?: Almacen | null } = $props();
|
||||||
|
|
||||||
|
let error = $state('');
|
||||||
|
let enviando = $state(false);
|
||||||
|
|
||||||
|
async function handleSubmit(e: Event) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (enviando) return;
|
||||||
|
enviando = true;
|
||||||
|
error = '';
|
||||||
|
if (!almacen?.id) {
|
||||||
|
error = 'No se pudo obtener el almacén. Recargá la página.';
|
||||||
|
enviando = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await altaAlmacen(almacen.id);
|
||||||
|
if (result !== 'ok') {
|
||||||
|
error = result;
|
||||||
|
enviando = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await invalidate('almacenes:load');
|
||||||
|
enviando = false;
|
||||||
|
onClose?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClose() {
|
||||||
|
error = '';
|
||||||
|
enviando = false;
|
||||||
|
onClose?.();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form id="altaAlmacenForm" onsubmit={handleSubmit}>
|
||||||
|
<Modal
|
||||||
|
formId="altaAlmacenForm"
|
||||||
|
bind:open
|
||||||
|
size="sm"
|
||||||
|
modalHeading="Dar de alta almacén"
|
||||||
|
primaryButtonText="Dar de alta"
|
||||||
|
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}
|
||||||
|
<p>
|
||||||
|
¿Dar de alta el almacén <strong>{almacen?.codigo ?? ''}</strong>?
|
||||||
|
</p>
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
|
EOF
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { invalidate } from '$app/navigation';
|
||||||
|
import { InlineNotification, Modal, TextInput } from 'carbon-components-svelte';
|
||||||
|
import { crearAlmacen } from '$lib/hooks/almacenes/crearAlmacen';
|
||||||
|
|
||||||
|
let { open = $bindable(), onClose }: { open?: boolean; onClose?: () => void } = $props();
|
||||||
|
|
||||||
|
let codigo = $state('');
|
||||||
|
let ubicacion = $state('');
|
||||||
|
let enviando = $state(false);
|
||||||
|
let error = $state('');
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (open) {
|
||||||
|
codigo = '';
|
||||||
|
ubicacion = '';
|
||||||
|
error = '';
|
||||||
|
enviando = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function enviar() {
|
||||||
|
if (enviando) return;
|
||||||
|
enviando = true;
|
||||||
|
error = '';
|
||||||
|
|
||||||
|
if (codigo.trim() === '') {
|
||||||
|
error = 'El código es obligatorio.';
|
||||||
|
enviando = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await crearAlmacen({
|
||||||
|
codigo: codigo.trim(),
|
||||||
|
ubicacion: ubicacion.trim()
|
||||||
|
});
|
||||||
|
if (result === 'ok') {
|
||||||
|
await invalidate('almacenes:load');
|
||||||
|
onClose?.();
|
||||||
|
} else {
|
||||||
|
error = result;
|
||||||
|
}
|
||||||
|
enviando = false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form
|
||||||
|
id="crearAlmacenForm"
|
||||||
|
onsubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
void enviar();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Modal
|
||||||
|
formId="crearAlmacenForm"
|
||||||
|
bind:open
|
||||||
|
size="sm"
|
||||||
|
modalHeading="Registrar almacén"
|
||||||
|
primaryButtonText="Registrar"
|
||||||
|
primaryButtonDisabled={enviando}
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
on:click:button--secondary={() => onClose?.()}
|
||||||
|
>
|
||||||
|
{#if error}
|
||||||
|
<div class="mb-4">
|
||||||
|
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<TextInput labelText="Código" bind:value={codigo} maxlength={5} required />
|
||||||
|
<div class="mt-4">
|
||||||
|
<TextInput labelText="Ubicación" bind:value={ubicacion} maxlength={40} />
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { invalidate } from '$app/navigation';
|
||||||
|
import { InlineNotification, Modal, TextInput } from 'carbon-components-svelte';
|
||||||
|
import type { Almacen } from '../../types';
|
||||||
|
import { actualizarAlmacen } from '$lib/hooks/almacenes/actualizarAlmacen';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(),
|
||||||
|
onClose,
|
||||||
|
almacen
|
||||||
|
}: { open?: boolean; onClose?: () => void; almacen?: Almacen | null } = $props();
|
||||||
|
|
||||||
|
let codigo = $state('');
|
||||||
|
let ubicacion = $state('');
|
||||||
|
let enviando = $state(false);
|
||||||
|
let error = $state('');
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (almacen) {
|
||||||
|
codigo = almacen.codigo ?? '';
|
||||||
|
ubicacion = almacen.ubicacion ?? '';
|
||||||
|
error = '';
|
||||||
|
enviando = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function enviar() {
|
||||||
|
if (enviando) return;
|
||||||
|
enviando = true;
|
||||||
|
error = '';
|
||||||
|
|
||||||
|
if (!almacen?.id) {
|
||||||
|
error = 'No se pudo obtener el almacén. Recargá la página.';
|
||||||
|
enviando = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (codigo.trim() === '') {
|
||||||
|
error = 'El código es obligatorio.';
|
||||||
|
enviando = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await actualizarAlmacen(almacen.id, {
|
||||||
|
codigo: codigo.trim(),
|
||||||
|
ubicacion: ubicacion.trim()
|
||||||
|
});
|
||||||
|
if (result === 'ok') {
|
||||||
|
await invalidate('almacenes:load');
|
||||||
|
onClose?.();
|
||||||
|
} else {
|
||||||
|
error = result;
|
||||||
|
}
|
||||||
|
enviando = false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form
|
||||||
|
id="editarAlmacenForm"
|
||||||
|
onsubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
void enviar();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Modal
|
||||||
|
formId="editarAlmacenForm"
|
||||||
|
bind:open
|
||||||
|
size="sm"
|
||||||
|
modalHeading="Editar almacén"
|
||||||
|
primaryButtonText="Guardar"
|
||||||
|
primaryButtonDisabled={enviando}
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
on:click:button--secondary={() => onClose?.()}
|
||||||
|
>
|
||||||
|
{#if error}
|
||||||
|
<div class="mb-4">
|
||||||
|
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<TextInput labelText="Código" bind:value={codigo} maxlength={5} required />
|
||||||
|
<div class="mt-4">
|
||||||
|
<TextInput labelText="Ubicación" bind:value={ubicacion} maxlength={40} />
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
|
EOF
|
||||||
|
echo done
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { invalidate } from '$app/navigation';
|
||||||
|
import { InlineNotification, Modal } from 'carbon-components-svelte';
|
||||||
|
import type { Almacen } from '../../types';
|
||||||
|
import { eliminarAlmacen } from '$lib/hooks/almacenes/eliminarAlmacen';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(),
|
||||||
|
onClose,
|
||||||
|
almacen
|
||||||
|
}: { open?: boolean; onClose?: () => void; almacen?: Almacen | null } = $props();
|
||||||
|
|
||||||
|
let error = $state('');
|
||||||
|
|
||||||
|
async function handleSubmit(e: Event) {
|
||||||
|
e.preventDefault();
|
||||||
|
error = '';
|
||||||
|
if (!almacen?.id) {
|
||||||
|
error = 'No se pudo obtener el almacén. Recargá la página.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await eliminarAlmacen(almacen.id);
|
||||||
|
if (result !== 'Ok') {
|
||||||
|
error = result;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await invalidate('almacenes:load');
|
||||||
|
onClose?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClose() {
|
||||||
|
error = '';
|
||||||
|
onClose?.();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form id="eliminarAlmacenForm" onsubmit={handleSubmit}>
|
||||||
|
<Modal
|
||||||
|
formId="eliminarAlmacenForm"
|
||||||
|
bind:open
|
||||||
|
size="sm"
|
||||||
|
modalHeading="Eliminar almacén"
|
||||||
|
primaryButtonText="Eliminar"
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
danger
|
||||||
|
on:click:button--secondary={handleClose}
|
||||||
|
>
|
||||||
|
{#if error}
|
||||||
|
<div class="mb-4">
|
||||||
|
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
<p>
|
||||||
|
¿Está seguro de que desea eliminar el almacén
|
||||||
|
<strong>{almacen?.codigo ?? ''}</strong>?
|
||||||
|
</p>
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
|
EOF
|
||||||
Vendored
+3
@@ -227,6 +227,9 @@ export interface Almacen {
|
|||||||
empresaId?: number;
|
empresaId?: number;
|
||||||
codigo: string;
|
codigo: string;
|
||||||
ubicacion?: string;
|
ubicacion?: string;
|
||||||
|
CreatedAt?: string;
|
||||||
|
UpdatedAt?: string;
|
||||||
|
DeletedAt?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StockItem {
|
export interface StockItem {
|
||||||
|
|||||||
Reference in new issue
Block a user