diff --git a/frontend/src/routes/dashboard/goods/parts/edit/[[id]]/+page.svelte b/frontend/src/routes/dashboard/goods/parts/edit/[[id]]/+page.svelte index e31a139d..b0b6ae4f 100644 --- a/frontend/src/routes/dashboard/goods/parts/edit/[[id]]/+page.svelte +++ b/frontend/src/routes/dashboard/goods/parts/edit/[[id]]/+page.svelte @@ -10,8 +10,9 @@ import { Textarea } from '$lib/components/ui/textarea'; import * as Tabs from '$lib/components/ui/tabs'; import * as Card from '$lib/components/ui/card'; + import * as Select from "$lib/components/ui/select"; import { Switch } from "$lib/components/ui/switch"; - import { ArrowLeft, LoaderCircle, Save, CheckCircle2, XCircle, Package, DollarSign } from 'lucide-svelte'; + import { ArrowLeft, LoaderCircle, Save, Package, DollarSign, FileText, Settings, Image as ImageIcon } from 'lucide-svelte'; import { companyStore } from '$lib/stores/company.svelte'; import { partsApi, type PartCreate } from '$lib/api/dashboard/a76/parts'; @@ -35,27 +36,30 @@ part_class: '', country_of_origin: 'MEX', unit_of_measure: 'PZ', - // Opcionales 1 - fraction: '', - us_fraction: '', + // Costos y Pesos unit_weight: 0, weight_type: 'KG', - // Opcionales 2 + unit_cost: 0, + currency_key: 'USD', + added_value: 0, + us_fraction: '', + + // Opciones supplier: '', - fda_key: '', fcc_key: '', + part_photo: '', + + // Opcionales 2 + fda_key: '', + + // Otros + commercial_part_number: '', + fraction: '', // Fraccion MX eccn: '', license_code: '', export_code: '', exclusion_symbol: '', - // Costos - unit_cost: 0, - currency_key: 'USD', - added_value: 0, - commercial_part_number: '', - // Otros alternate_unit_measure: '', - part_photo: '', is_active: true }); @@ -121,18 +125,15 @@ } } - async function handleSubmit() { error = null; const activeCompanyId = companyStore.activeCompany?.id; if (!activeCompanyId) { error = 'No hay una compañía activa seleccionada'; return; } - if (!formData.client_id) { error = 'ID Cliente requerido'; return; } + if (!formData.client_id) { error = 'ID Cliente requerido (Pestaña Otros)'; return; } if (!formData.part_number.trim()) { error = 'Número de Parte requerido'; return; } - if (!formData.fraction.trim()) { error = 'Fracción MX requerida'; return; } - + loading = true; try { - const commonData = { description_spanish: formData.description_spanish || null, description_english: formData.description_english || null, @@ -165,60 +166,44 @@ if (isEdit && id) { const response = await partsApi.update(id, commonData, activeCompanyId); - if (response.error) throw new Error(response.error); - console.log("Registro actualizado con éxito"); - } else { - const createData: PartCreate = { ...commonData, company_id: activeCompanyId, client_id: Number(formData.client_id), part_number: formData.part_number }; - const response = await partsApi.create(createData, activeCompanyId); - if (response.error) throw new Error(response.error); - console.log("Registro creado con éxito"); } - goto('/dashboard/goods/parts'); } catch (e: any) { console.error("Error en el guardado:", e); if (e.message?.includes('already exists')) { error = `El número de parte ${formData.part_number} ya existe para este cliente.`; - } else if (e.message?.includes('foreign key constraint')) { - error = `Error: Uno de los datos (País, Moneda o Unidad) no existe en el sistema.`; + } else if (e.message?.includes('foreign key')) { + error = `Error: Uno de los catálogos (País, Moneda, UM) no es válido.`; } else { - error = e.message || 'Ocurrió un error inesperado al guardar'; + error = e.message || 'Error inesperado al guardar'; } } finally { loading = false; } } -
-
-
- -
-

{title}

-

{isEdit ? 'Modificando registro existente' : 'Creando nuevo registro'}

-
+
+ +
+

{title}

+

Gestión detallada de números de parte.

- {#if isEdit} -
- {#if formData.is_active} Activo {:else} Inactivo {/if} -
- {/if}
{#if error} @@ -227,210 +212,253 @@
{/if} - {#key id}
{ e.preventDefault(); handleSubmit(); }} class="space-y-6"> -
+
- -
-
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
+ +
- -