From d0cd10de84d30c62ecf2050b6098e17b428604e2 Mon Sep 17 00:00:00 2001 From: hreyes Date: Tue, 21 Apr 2026 13:21:03 -0600 Subject: [PATCH] fix/pedimento-consolidado-DOF --- .../pedimentos/edit/general-tab-form.svelte | 12 +++- .../pedimentos/edit/[id]/+page.svelte | 55 +++++++++++++------ 2 files changed, 48 insertions(+), 19 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 e41e2ae1..d8ae6fa6 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 @@ -594,7 +594,12 @@
- + getCurrentLocalDate()} + + (Opcional por fecha futura en consolidado) + + {/if}

diff --git a/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte b/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte index 6a868691..b901a155 100644 --- a/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte +++ b/frontend/src/routes/dashboard/pedimentos/edit/[id]/+page.svelte @@ -87,6 +87,7 @@ import ExchangeRateDialog from '$lib/components/dashboard/exchange_rate/create-edit-dialog.svelte'; import { companyStore } from '$lib/stores/company.svelte'; import PrerequisitesModal from '$lib/components/dashboard/PrerequisitesModal.svelte'; + import { getCurrentLocalDate } from '$lib/date-utils'; let { data }: { data: ExtendedPageData } = $props(); @@ -417,12 +418,19 @@ // Verificar tipo de cambio según catalogo de transporte (E/P) if (generalTabInstance && generalFormData) { const exchangeRef = getExchangeDateForPedimento(generalFormData); - const rateExists = await generalTabInstance.checkPaymentDateRate(exchangeRef.date || ''); - if (!rateExists) { - saving = false; - // Asegurar que se muestre el tab general - activeTab = 'general'; - return; + const isConsolidated = generalFormData.pedimento_type === 'consolidated'; + const todayStr = getCurrentLocalDate(); + const isFutureDate = exchangeRef.date && exchangeRef.date > todayStr; + + // Solo verificar si NO es un consolidado con fecha futura + if (!(isConsolidated && isFutureDate)) { + const rateExists = await generalTabInstance.checkPaymentDateRate(exchangeRef.date || ''); + if (!rateExists) { + saving = false; + // Asegurar que se muestre el tab general + activeTab = 'general'; + return; + } } } @@ -454,25 +462,36 @@ if (generalFormData) { const exchangeRef = getExchangeDateForPedimento(generalFormData); const rate = generalFormData.exchange_rate; + const isConsolidated = generalFormData.pedimento_type === 'consolidated'; + const todayStr = getCurrentLocalDate(); + const isFutureDate = exchangeRef.date && exchangeRef.date > todayStr; + if ( rate === null || rate === undefined || String(rate).trim() === '' || Number(rate) <= 0 ) { - saving = false; - activeTab = 'general'; - const date = exchangeRef.date || ''; - toast.error( - Number(rate) <= 0 && rate !== null && rate !== undefined - ? `El tipo de cambio debe ser mayor a 0. Registra el tipo de cambio para la ${exchangeRef.label}.` - : `No hay tipo de cambio registrado para la ${exchangeRef.label}. Por favor, regístralo antes de guardar.` - ); - if (date) { - missingExchangeRateDate = date; - showExchangeRateDialog = true; + // Si es consolidado y fecha futura, permitimos continuar con un warning + if (isConsolidated && isFutureDate) { + toast.warning( + `Aviso: No hay tipo de cambio para la ${exchangeRef.label} (${exchangeRef.date}), pero se permite continuar por ser pedimento consolidado.` + ); + } else { + saving = false; + activeTab = 'general'; + const date = exchangeRef.date || ''; + toast.error( + Number(rate) <= 0 && rate !== null && rate !== undefined + ? `El tipo de cambio debe ser mayor a 0. Registra el tipo de cambio para la ${exchangeRef.label}.` + : `No hay tipo de cambio registrado para la ${exchangeRef.label}. Por favor, regístralo antes de guardar.` + ); + if (date) { + missingExchangeRateDate = date; + showExchangeRateDialog = true; + } + return; } - return; } }