Merge pull request 'pedimentos' (#36) from pedimentos into development
Reviewed-on: ADUANASOFT/anexo76#36
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { goto, invalidateAll } from '$app/navigation';
|
||||
import * as Tabs from '$lib/components/ui/tabs';
|
||||
import * as Alert from '$lib/components/ui/alert';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
@@ -27,14 +27,14 @@
|
||||
// Importar los componentes de cada pestaña (ahora sin botones de guardar propios)
|
||||
import GeneralTabForm from '$lib/components/dashboard/pedimentos/edit/general-tab-form.svelte';
|
||||
import DatesTabForm from '$lib/components/dashboard/pedimentos/edit/dates-tab-form.svelte';
|
||||
import FacturasTabForm from '$lib/components/dashboard/pedimentos/edit/facturas-tab-form.svelte';
|
||||
import PartidasTabForm from '$lib/components/dashboard/pedimentos/edit/partidas-tab-form.svelte';
|
||||
import BultosTransportesTabForm from '$lib/components/dashboard/pedimentos/edit/bultos-transportes-tab-form.svelte';
|
||||
import DescargasTabForm from '$lib/components/dashboard/pedimentos/edit/descargas-tab-form.svelte';
|
||||
import ContribucionesTabForm from '$lib/components/dashboard/pedimentos/edit/contribuciones-tab-form.svelte';
|
||||
import CuentasCompensacionTabForm from '$lib/components/dashboard/pedimentos/edit/cuentas-compensacion-tab-form.svelte';
|
||||
import DigitalizacionTabForm from '$lib/components/dashboard/pedimentos/edit/digitalizacion-tab-form.svelte';
|
||||
import OtrosDatosTabForm from '$lib/components/dashboard/pedimentos/edit/otros-datos-tab-form.svelte';
|
||||
import FacturasTabForm from '$lib/components/dashboard/pedimentos/edit/invoices-tab-form.svelte';
|
||||
import PartidasTabForm from '$lib/components/dashboard/pedimentos/edit/items-tab-form.svelte';
|
||||
import BultosTransportesTabForm from '$lib/components/dashboard/pedimentos/edit/package-transportation-tab-form.svelte';
|
||||
import DescargasTabForm from '$lib/components/dashboard/pedimentos/edit/discharge-tab-form.svelte';
|
||||
import ContribucionesTabForm from '$lib/components/dashboard/pedimentos/edit/contributions-tab-form.svelte';
|
||||
import CuentasCompensacionTabForm from '$lib/components/dashboard/pedimentos/edit/accounts-compensation-tab-form.svelte';
|
||||
import DigitalizacionTabForm from '$lib/components/dashboard/pedimentos/edit/digitization-tab-form.svelte';
|
||||
import OtrosDatosTabForm from '$lib/components/dashboard/pedimentos/edit/other-data-tab-form.svelte';
|
||||
import PaymentsTabForm from '$lib/components/dashboard/pedimentos/edit/payments-tab-form.svelte';
|
||||
import TransportTabForm from '$lib/components/dashboard/pedimentos/edit/transport-tab-form.svelte';
|
||||
import ValidationTabForm from '$lib/components/dashboard/pedimentos/edit/validation-tab-form.svelte';
|
||||
@@ -104,6 +104,9 @@
|
||||
let digitalizacionFormData = $state({
|
||||
digitalizaciones: []
|
||||
});
|
||||
let identificadoresFormData = $state({
|
||||
identificadores: []
|
||||
});
|
||||
let otrosDatosFormData = $state({
|
||||
tipo_calculo: 'ninguno',
|
||||
dta_por_operacion_ag_facturas: false,
|
||||
@@ -187,11 +190,8 @@
|
||||
license: 'Patente',
|
||||
pedimento_number: 'Número de Pedimento',
|
||||
client_id: 'ID del Cliente',
|
||||
operation_type: 'Tipo de Operación',
|
||||
pedimento_type: 'Tipo de Pedimento',
|
||||
pedimento_code: 'Clave',
|
||||
regime: 'Régimen',
|
||||
status: 'Estado'
|
||||
regime: 'Régimen'
|
||||
};
|
||||
|
||||
const missingFields: string[] = [];
|
||||
@@ -226,13 +226,28 @@
|
||||
exchange_rate: generalFormData?.exchange_rate || undefined
|
||||
};
|
||||
|
||||
// Fechas - enviar si hay al menos un campo con valor
|
||||
if (generalFormData) {
|
||||
const hasDatesValue = generalFormData.entry_date || generalFormData.pedimento_date ||
|
||||
generalFormData.extraction_date || generalFormData.rectification_payment_date ||
|
||||
generalFormData.original_date || generalFormData.payment_date;
|
||||
if (hasDatesValue) {
|
||||
payload.pedimento_dates = {
|
||||
entry_date: generalFormData.entry_date || null,
|
||||
pedimento_date: generalFormData.pedimento_date || null,
|
||||
payment_date: generalFormData.payment_date || null,
|
||||
rectification_payment_date: generalFormData.rectification_payment_date || null,
|
||||
extraction_date: generalFormData.extraction_date || null,
|
||||
original_date: generalFormData.original_date || null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Solo agregar sub-recursos en modo UPDATE (no en CREATE)
|
||||
// Y solo si tienen valores reales (no enviar objetos vacíos/null)
|
||||
|
||||
// Observaciones - solo enviar si hay valor
|
||||
if (observacionesFormData?.observaciones) {
|
||||
payload.observaciones = observacionesFormData.observaciones;
|
||||
}
|
||||
// Observaciones - siempre enviar (puede ser string vacío para borrar)
|
||||
payload.observations = observacionesFormData?.observaciones || '';
|
||||
|
||||
// Incrementables - solo enviar si hay al menos un campo con valor
|
||||
if (generalFormData) {
|
||||
@@ -246,8 +261,8 @@
|
||||
freight: generalFormData.fletes || null,
|
||||
deductibles: generalFormData.deducibles || null,
|
||||
currency: generalFormData.moneda_incrementables || null,
|
||||
not_affect_usd_value: generalFormData.no_afectar_valor_dolares_inc ? 1 : 0,
|
||||
not_affect_customs_value: generalFormData.no_afectar_valor_aduana ? 1 : 0
|
||||
not_affect_usd_value: generalFormData.no_afectar_valor_dolares_inc || false,
|
||||
not_affect_customs_value: generalFormData.no_afectar_valor_aduana || false
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -265,7 +280,7 @@
|
||||
unloading: generalFormData.descarga || null,
|
||||
others: generalFormData.otros || null,
|
||||
currency: generalFormData.moneda_decrementable || null,
|
||||
not_affect_usd_value: generalFormData.afectar_valor_dolares ? 1 : 0
|
||||
not_affect_usd_value: generalFormData.afectar_valor_dolares || false
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -286,7 +301,7 @@
|
||||
payload.pedimento_indexes = {
|
||||
update_factor_type: updateFactorType,
|
||||
update_factor: generalFormData.factor_actualizacion || null,
|
||||
manual_update_factor: generalFormData.factor_actualizacion_manual ? 1 : 0
|
||||
manual_update_factor: generalFormData.factor_actualizacion_manual || false
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -300,18 +315,153 @@
|
||||
if (hasConfigAdditionalValue) {
|
||||
payload.pedimento_config_additional = {
|
||||
manual_pedimento_year: generalFormData.anio_impresion || null,
|
||||
add_po_identifier: generalFormData.agregar_po_auto ? 1 : 0,
|
||||
do_not_exempt_norms_complement_x: generalFormData.no_eximir_normas ? 1 : 0,
|
||||
enable_import_invoice_recipient: generalFormData.activar_destinatario ? 1 : 0,
|
||||
send_502_validation_file_for_consolidated: generalFormData.agregar_registro_502 ? 1 : 0,
|
||||
add_remove_norms: generalFormData.agregar_quitar_normas ? 1 : 0
|
||||
add_po_identifier: generalFormData.agregar_po_auto || false,
|
||||
do_not_exempt_norms_complement_x: generalFormData.no_eximir_normas || false,
|
||||
enable_import_invoice_recipient: generalFormData.activar_destinatario || false,
|
||||
send_502_validation_file_for_consolidated: generalFormData.agregar_registro_502 || false,
|
||||
add_remove_norms: generalFormData.agregar_quitar_normas || false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Eliminar campos undefined para no enviarlos
|
||||
Object.keys(payload).forEach(key => {
|
||||
// Identificadores - enviar array de identificadores si existen
|
||||
if (identificadoresFormData?.identificadores && identificadoresFormData.identificadores.length > 0) {
|
||||
payload.identificadores = identificadoresFormData.identificadores;
|
||||
}
|
||||
|
||||
// Config Calculations - configuraciones de cálculo DTA, IVA, prevalidación
|
||||
if (otrosDatosFormData) {
|
||||
const hasCalculationsValue = otrosDatosFormData.tipo_calculo ||
|
||||
otrosDatosFormData.dta_por_operacion_ag_facturas !== undefined ||
|
||||
otrosDatosFormData.dta_por_numero_vehiculos !== undefined ||
|
||||
otrosDatosFormData.paga_iva !== undefined ||
|
||||
otrosDatosFormData.paga_prevalidacion !== undefined ||
|
||||
otrosDatosFormData.aplicar_dta_8_millar_partida !== undefined ||
|
||||
otrosDatosFormData.incluir_eci !== undefined ||
|
||||
otrosDatosFormData.cuota_fija_adicional_vehiculo !== undefined ||
|
||||
otrosDatosFormData.cuota_fija_adicional_fp;
|
||||
|
||||
if (hasCalculationsValue) {
|
||||
// Convertir tipo_calculo a dta_type
|
||||
let dtaTypeValue = null;
|
||||
if (otrosDatosFormData.tipo_calculo === 'Cuota fija') {
|
||||
dtaTypeValue = '1';
|
||||
} else if (otrosDatosFormData.tipo_calculo === '8 al millar') {
|
||||
dtaTypeValue = '2';
|
||||
} else if (otrosDatosFormData.tipo_calculo === '1.76 al millar') {
|
||||
dtaTypeValue = '3';
|
||||
} else if (otrosDatosFormData.tipo_calculo === 'Estados extranjeros') {
|
||||
dtaTypeValue = '4';
|
||||
}
|
||||
|
||||
payload.pedimento_config_calculations = {
|
||||
dta_type: dtaTypeValue,
|
||||
dta_operation: otrosDatosFormData.dta_por_operacion_ag_facturas || false,
|
||||
dta_vehicle_count: otrosDatosFormData.dta_por_numero_vehiculos || false,
|
||||
dta_mixed_rate_8permil: otrosDatosFormData.aplicar_dta_8_millar_partida || false,
|
||||
pays_vat: otrosDatosFormData.paga_iva || false,
|
||||
pays_prevalidation: otrosDatosFormData.paga_prevalidacion || false,
|
||||
include_sagar_certificate_fee: otrosDatosFormData.incluir_eci || false,
|
||||
fixed_vehicle_dta_fee: otrosDatosFormData.cuota_fija_adicional_vehiculo || false,
|
||||
additional_fixed_fee: otrosDatosFormData.cuota_fija_adicional_fp ? parseInt(otrosDatosFormData.cuota_fija_adicional_fp) : 0,
|
||||
additional_fixed_fee_payment_method: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Config Surcharges - configuraciones de recargos
|
||||
if (otrosDatosFormData) {
|
||||
const hasSurchargesValue = otrosDatosFormData.recargo_igi !== undefined ||
|
||||
otrosDatosFormData.deducible_recargos !== undefined ||
|
||||
otrosDatosFormData.recargo_iva !== undefined ||
|
||||
otrosDatosFormData.recargo_ieps !== undefined ||
|
||||
otrosDatosFormData.recargo_isan !== undefined ||
|
||||
otrosDatosFormData.recargo_cc !== undefined;
|
||||
|
||||
if (hasSurchargesValue) {
|
||||
payload.pedimento_config_surcharges = {
|
||||
surcharge_igi: otrosDatosFormData.recargo_igi || false,
|
||||
surcharge_dta: otrosDatosFormData.deducible_recargos || false,
|
||||
surcharge_vat: otrosDatosFormData.recargo_iva || false,
|
||||
surcharge_ieps: otrosDatosFormData.recargo_ieps || false,
|
||||
surcharge_isan: otrosDatosFormData.recargo_isan || false,
|
||||
surcharge_cc: otrosDatosFormData.recargo_cc || false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Config Parameters - parámetros de configuración del pedimento
|
||||
if (otrosDatosFormData) {
|
||||
const hasParametersValue = otrosDatosFormData.es_embajada !== undefined ||
|
||||
otrosDatosFormData.embajada_dta ||
|
||||
otrosDatosFormData.regla_3_1_21_factores !== undefined ||
|
||||
otrosDatosFormData.cambio_tarifa_anterior ||
|
||||
otrosDatosFormData.agregar_entidad_federativa_proveedor !== undefined ||
|
||||
otrosDatosFormData.calculo_valor_aduana_v2 !== undefined ||
|
||||
otrosDatosFormData.calculo_2_decimales_valor_unitario !== undefined ||
|
||||
otrosDatosFormData.calcular_valor_aduana_base_partidas !== undefined ||
|
||||
otrosDatosFormData.proveedor_nacional_modifico_dta !== undefined;
|
||||
|
||||
if (hasParametersValue) {
|
||||
payload.pedimento_config_parameters = {
|
||||
is_embassy: otrosDatosFormData.es_embajada || false,
|
||||
embassy_dta: otrosDatosFormData.embajada_dta || '0.00',
|
||||
rule_3121_section_ii: otrosDatosFormData.regla_3_1_21_factores || false,
|
||||
use_previous_tariff: !!otrosDatosFormData.cambio_tarifa_anterior,
|
||||
use_payment_date_fi: null,
|
||||
add_state_supplier_record_505: otrosDatosFormData.agregar_entidad_federativa_proveedor || false,
|
||||
customs_value_calculation: otrosDatosFormData.calculo_valor_aduana_v2 || false,
|
||||
two_decimals_unit_value: otrosDatosFormData.calculo_2_decimales_valor_unitario || false,
|
||||
customs_value_per_item: otrosDatosFormData.calcular_valor_aduana_base_partidas || false,
|
||||
is_national_supplier: otrosDatosFormData.proveedor_nacional_modifico_dta || false,
|
||||
is_consolidated: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Config Updates - configuraciones de actualización de valores
|
||||
if (otrosDatosFormData) {
|
||||
const hasUpdatesValue = otrosDatosFormData.actualizar_iva !== undefined ||
|
||||
otrosDatosFormData.actualizar_advalorem !== undefined ||
|
||||
otrosDatosFormData.actualizar_cc !== undefined ||
|
||||
otrosDatosFormData.actualizar_ieps !== undefined;
|
||||
|
||||
if (hasUpdatesValue) {
|
||||
payload.pedimento_config_updates = {
|
||||
update_vat: otrosDatosFormData.actualizar_iva || false,
|
||||
update_advalorem: otrosDatosFormData.actualizar_advalorem || false,
|
||||
update_dta: otrosDatosFormData.actualizar_dta || false,
|
||||
update_cc: otrosDatosFormData.actualizar_cc || false,
|
||||
update_ieps: otrosDatosFormData.actualizar_ieps || false
|
||||
};
|
||||
console.log('📤 Enviando pedimento_config_updates:', payload.pedimento_config_updates);
|
||||
}
|
||||
}
|
||||
|
||||
// Config Update Rectification - configuraciones de actualización en rectificación
|
||||
if (otrosDatosFormData) {
|
||||
const hasUpdateRectValue = otrosDatosFormData.actualizar_iva_rect !== undefined ||
|
||||
otrosDatosFormData.actualizar_advalorem_rect !== undefined ||
|
||||
otrosDatosFormData.actualizar_dta_rect !== undefined ||
|
||||
otrosDatosFormData.actualizar_cc_rect !== undefined ||
|
||||
otrosDatosFormData.actualizar_ieps_rect !== undefined ||
|
||||
otrosDatosFormData.calcular_recargos_diferencias !== undefined;
|
||||
|
||||
if (hasUpdateRectValue) {
|
||||
payload.pedimento_config_update_rectification = {
|
||||
update_vat: otrosDatosFormData.actualizar_iva_rect || false,
|
||||
update_advalorem: otrosDatosFormData.actualizar_advalorem_rect || false,
|
||||
update_dta: otrosDatosFormData.actualizar_dta_rect || false,
|
||||
update_cc: otrosDatosFormData.actualizar_cc_rect || false,
|
||||
update_ieps: otrosDatosFormData.actualizar_ieps_rect || false,
|
||||
calculate_surcharge: otrosDatosFormData.calcular_recargos_diferencias || false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Eliminar campos undefined para no enviarlos
|
||||
Object.keys(payload).forEach(key => {
|
||||
if (payload[key as keyof typeof payload] === undefined) {
|
||||
delete payload[key as keyof typeof payload];
|
||||
}
|
||||
@@ -319,7 +469,10 @@
|
||||
|
||||
let newPedimentoId = pedimentoId;
|
||||
|
||||
if (data.isCreate) {
|
||||
// Determinar si es creación o actualización basándose en si tenemos un ID
|
||||
const isCreating = !pedimentoId || data.isCreate;
|
||||
|
||||
if (isCreating) {
|
||||
// Crear nuevo pedimento con todos sus sub-recursos
|
||||
const response = await pedimentosApi.create(payload as CreatePedimentoData);
|
||||
if (response.error) {
|
||||
@@ -336,6 +489,9 @@
|
||||
// Actualizar pedimento existente con todos sus sub-recursos
|
||||
const response = await pedimentosApi.update(pedimentoId!, payload as UpdatePedimentoData);
|
||||
if (response.error) throw new Error(response.error);
|
||||
|
||||
// Recargar los datos del pedimento desde el servidor
|
||||
await invalidateAll();
|
||||
}
|
||||
|
||||
success = true;
|
||||
@@ -420,6 +576,7 @@
|
||||
<GeneralTabForm
|
||||
pedimento={data.pedimento}
|
||||
bind:formData={generalFormData}
|
||||
bind:identificadoresFormData={identificadoresFormData}
|
||||
pedimentoCodes={data.pedimentoCodes || []}
|
||||
customsSections={data.customsSections || []}
|
||||
customsBrokers={data.customsBrokers || []}
|
||||
@@ -458,32 +615,32 @@
|
||||
|
||||
<Tabs.Content value="bultos-transportes">
|
||||
<BultosTransportesTabForm
|
||||
pedimento={data.pedimento}
|
||||
bind:formData={bultosTransportesFormData}
|
||||
/>
|
||||
</Tabs.Content>
|
||||
<!-- <Tabs.Content value="descargas">
|
||||
<!-- <Tabs.Content value="descargas">
|
||||
<DescargasTabForm
|
||||
bind:formData={descargasFormData}
|
||||
/>
|
||||
</Tabs.Content> -->
|
||||
<Tabs.Content value="contribuciones">
|
||||
<Tabs.Content value="contribuciones">
|
||||
<ContribucionesTabForm
|
||||
bind:formData={contribucionesFormData}
|
||||
/>
|
||||
</Tabs.Content>
|
||||
<Tabs.Content value="cuentas-compensacion">
|
||||
<Tabs.Content value="cuentas-compensacion">
|
||||
<CuentasCompensacionTabForm
|
||||
bind:formData={cuentasCompensacionFormData}
|
||||
/>
|
||||
</Tabs.Content>
|
||||
<Tabs.Content value="otros-datos">
|
||||
<OtrosDatosTabForm bind:formData={otrosDatosFormData} />
|
||||
</Tabs.Content>
|
||||
|
||||
<Tabs.Content value="digitalizacion">
|
||||
<DigitalizacionTabForm bind:formData={digitalizacionFormData} />
|
||||
</Tabs.Content>
|
||||
</Tabs.Root>
|
||||
<Tabs.Content value="otros-datos">
|
||||
<OtrosDatosTabForm pedimento={data.pedimento} bind:formData={otrosDatosFormData} />
|
||||
</Tabs.Content>
|
||||
<Tabs.Content value="digitalizacion">
|
||||
<DigitalizacionTabForm bind:formData={digitalizacionFormData} />
|
||||
</Tabs.Content>
|
||||
</Tabs.Root>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -528,8 +685,8 @@
|
||||
<Tabs.Trigger value="cuentas-compensacion" class="flex items-center gap-1.5 px-2.5 py-1.5 text-sm">
|
||||
<Wallet size={14} />
|
||||
<span>Cuentas/Comp.</span>
|
||||
</Tabs.Trigger>
|
||||
<Tabs.Trigger value="otros-datos" class="flex items-center gap-1.5 px-2.5 py-1.5 text-sm">
|
||||
</Tabs.Trigger>
|
||||
<Tabs.Trigger value="otros-datos" class="flex items-center gap-1.5 px-2.5 py-1.5 text-sm">
|
||||
<FileStack size={14} />
|
||||
<span>Otros</span>
|
||||
</Tabs.Trigger>
|
||||
|
||||
Reference in New Issue
Block a user