From 3043be4624354ce5c4fd6a4aee4cb826b24c1cc3 Mon Sep 17 00:00:00 2001 From: acazares Date: Tue, 18 Nov 2025 19:00:13 -0600 Subject: [PATCH] feat: Integrate pedimento codes into the edit form and update data loading --- .../pedimentos/edit/general-tab-form.svelte | 87 +++++++++++++------ .../pedimentos/edit/[id]/+page.server.ts | 21 ++++- .../pedimentos/edit/[id]/+page.svelte | 1 + 3 files changed, 80 insertions(+), 29 deletions(-) diff --git a/frontend/src/lib/components/dashboard/pedimentos/edit/general-tab-form.svelte b/frontend/src/lib/components/dashboard/pedimentos/edit/general-tab-form.svelte index 02123c1b..7f8fed59 100644 --- a/frontend/src/lib/components/dashboard/pedimentos/edit/general-tab-form.svelte +++ b/frontend/src/lib/components/dashboard/pedimentos/edit/general-tab-form.svelte @@ -2,16 +2,25 @@ import * as Card from '$lib/components/ui/card'; import { Input } from '$lib/components/ui/input'; import { Label } from '$lib/components/ui/label'; + import * as Select from '$lib/components/ui/select'; import type { Pedimento } from '$lib/api/dashboard/a76/pedimentos'; + import type { PedimentoCode } from '$lib/api/dashboard/refrence_data/pedimento_codes'; let { pedimento, - formData = $bindable() + formData = $bindable(), + pedimentoCodes = [] }: { pedimento: Pedimento | null; formData?: any; + pedimentoCodes?: PedimentoCode[]; } = $props(); + // Debug: verificar que los datos llegan + $effect(() => { + console.log('pedimentoCodes:', pedimentoCodes.length, 'items'); + }); + // Inicializar formData con los valores del pedimento (o vacío si es null) if (!formData) { formData = { @@ -32,6 +41,11 @@ }; } + const operationOptions = [ + { value: 1, label: 'Exportación' }, + { value: 2, label: 'Importación' }, + ]; + const statusOptions = [ { value: 'MODIFICABLE', label: 'Modificable' }, { value: 'ESPERA FIRMA PREVIO', label: 'Espera de firma previo' }, @@ -135,12 +149,20 @@
- + formData.operation_type = v ? Number(v) : null} + > + + {operationOptions.find(o => o.value === formData.operation_type)?.label || 'Seleccionar...'} + + + {#each operationOptions as option} + + {/each} + +
@@ -154,17 +176,24 @@ /> - -
- - -
- - + +
+ + formData.pedimento_code = v ?? ''} + > + + {pedimentoCodes.find(o => o.code === formData.pedimento_code)?.description || 'Seleccionar...'} + + + {#each pedimentoCodes as code} + + {/each} + + +
- + + {statusOptions.find(o => o.value === formData.status)?.label || 'Seleccionar...'} + + + {#each statusOptions as option} + + {/each} + +
diff --git a/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.server.ts b/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.server.ts index c011c52c..7c17e4c9 100644 --- a/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.server.ts +++ b/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.server.ts @@ -9,12 +9,24 @@ export const load: PageServerLoad = async ({ params, cookies, fetch }) => { throw redirect(302, '/login'); } + // Cargar pedimento_codes (datos de referencia) + const pedimentoCodesPromise = authenticatedFetch( + 'v1/public/refrence_data/pedimento-codes?page=1&page_size=100', + {}, + cookies, + fetch + ); + // Si el ID es "new", es una creación if (params.id === 'new') { + const pedimentoCodesResponse = await pedimentoCodesPromise; + const pedimentoCodes = pedimentoCodesResponse.ok ? await pedimentoCodesResponse.json() : { items: [] }; + return { pedimento: null, pedimentoId: null, - isCreate: true + isCreate: true, + pedimentoCodes: pedimentoCodes.items || [] }; } @@ -51,10 +63,15 @@ export const load: PageServerLoad = async ({ params, cookies, fetch }) => { const pedimento = await response.json(); + // Cargar pedimento_codes + const pedimentoCodesResponse = await pedimentoCodesPromise; + const pedimentoCodes = pedimentoCodesResponse.ok ? await pedimentoCodesResponse.json() : { items: [] }; + return { pedimento, pedimentoId, - isCreate: false + isCreate: false, + pedimentoCodes: pedimentoCodes.items || [] }; } catch (e) { console.error('Error loading pedimento:', e); diff --git a/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte b/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte index 5bb8adf1..7cfc49ba 100644 --- a/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte +++ b/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte @@ -446,6 +446,7 @@