diff --git a/frontend/src/routes/dashboard/goods/classes/edit/[[id]]/+page.svelte b/frontend/src/routes/dashboard/goods/classes/edit/[[id]]/+page.svelte index d85acfcf..90d0803a 100644 --- a/frontend/src/routes/dashboard/goods/classes/edit/[[id]]/+page.svelte +++ b/frontend/src/routes/dashboard/goods/classes/edit/[[id]]/+page.svelte @@ -22,13 +22,9 @@ type A76ClassCreate, type A76ClassUpdate } from '$lib/api/dashboard/a76/classes'; - - // APIs para recuperar nombres al editar import { materialTypesApi } from "$lib/api/dashboard/a76/material-types"; import { clientsProvidersApi } from '$lib/api/dashboard/a76/clients-providers'; - // Nota: Asumo que tienes una API para obtener una unidad por código o lista, - // si no, usaremos la descripción del modal. - + // --- MODALES IMPORTADOS --- import MaterialTypeSelectorDialog from '$lib/components/dashboard/goods/modales/material-type-selector-dialog.svelte'; import UnitMeasureSelectorDialog from '$lib/components/dashboard/goods/modales/unit-measure-dialog.svelte'; @@ -43,12 +39,10 @@ let loading = $state(false); let error = $state(null); - // Estados de Modales let showClientModal = $state(false); let showMaterialModal = $state(false); let showUnitModal = $state(false); - // Descripciones Visuales (Para que el usuario sepa qué seleccionó) let selectedClientName = $state(""); let selectedMaterialDesc = $state(""); let selectedUnitDesc = $state(""); @@ -62,7 +56,7 @@ description_es: '', description_en: '', material_key: '', - unit_of_measure: '', // Ahora vacío para obligar selección + unit_of_measure: '', fraction: '', us_fraction: '', sub_key: '', @@ -83,7 +77,7 @@ } }); - // Carga del Registro a Editar y sus descripciones visuales + async function loadClassData(classId: number, companyId: number) { loading = true; try { @@ -111,10 +105,9 @@ iva_exempt_fraction: data.iva_exempt_fraction }; - // Recuperar descripciones visuales para que no se vean solo códigos if (data.client_id) await fetchClientName(data.client_id, companyId); if (data.material_key) await fetchMaterialName(data.material_key); - if (data.unit_of_measure) selectedUnitDesc = data.unit_of_measure; // O buscar descripción si tienes API + if (data.unit_of_measure) selectedUnitDesc = data.unit_of_measure; } } catch (e) { error = "No se pudo cargar la información de la Clase"; @@ -135,8 +128,6 @@ async function fetchMaterialName(key: string) { try { - // Asumiendo que list devuelve items y podemos buscar ahí, - // o si tienes un get(key) mejor. const res = await materialTypesApi.list(1, 100); const list = (res as any).data?.items || []; const found = list.find((m: any) => m.key === key); @@ -158,7 +149,6 @@ } function handleUnitSelect(item: any) { - // Asumiendo que el modal devuelve { code: 'KG', description: 'Kilogramos' } formData.unit_of_measure = item.code; selectedUnitDesc = item.description || item.code; } diff --git a/frontend/src/routes/dashboard/goods/parts/+page.svelte b/frontend/src/routes/dashboard/goods/parts/+page.svelte index 821e8d02..25ea479f 100644 --- a/frontend/src/routes/dashboard/goods/parts/+page.svelte +++ b/frontend/src/routes/dashboard/goods/parts/+page.svelte @@ -6,26 +6,29 @@ import * as Card from '$lib/components/ui/card'; import { Button } from '$lib/components/ui/button'; import { Input } from '$lib/components/ui/input'; - import { Label } from '$lib/components/ui/label'; import { companyStore } from '$lib/stores/company.svelte'; - import { Plus, Search, Trash2, RefreshCw } from 'lucide-svelte'; + import { Plus, Search, RefreshCw, Loader2, Trash2 } from 'lucide-svelte'; // 1. ESTADOS let partsList = $state([]); let listLoading = $state(false); let listError = $state(null); + // Estado Búsqueda let searchCode = $state(''); - let searchedPart = $state(null); + let searchResults = $state([]); // Array para guardar los resultados let searchLoading = $state(false); + let isSearching = $state(false); // Para saber si estamos viendo resultados de búsqueda - // 2. CARGA DE DATOS + // 2. CARGA DE DATOS (Lista Completa) async function loadParts() { const companyId = companyStore.activeCompany?.id; if (!companyId) return; listLoading = true; listError = null; + isSearching = false; // Reseteamos modo búsqueda + searchResults = []; try { const response = await partsApi.list({ @@ -35,10 +38,7 @@ }); if (response.data) { - partsList = response.data.items || response.data.parts || []; - - console.log("Datos recibidos:", response.data); } else if (response.error) { listError = response.error; } @@ -56,10 +56,14 @@ } }); + // 4. BÚSQUEDA MANUAL async function handleSearch() { if (!searchCode.trim()) return; + searchLoading = true; + listError = null; // Limpiamos errores previos const companyId = companyStore.activeCompany?.id; + if (!companyId) return; try { @@ -71,9 +75,12 @@ const results = response.data.items || response.data.parts || []; if (results.length > 0) { - searchedPart = results[0]; + searchResults = results; // Guardamos TODOS los resultados + isSearching = true; // Activamos modo búsqueda } else { - listError = "No se encontró la parte"; + listError = "No se encontraron partes con ese criterio"; + searchResults = []; + isSearching = true; // Aún en modo búsqueda, pero vacía } } catch (e) { listError = "Error en la búsqueda"; @@ -84,12 +91,16 @@ function clearSearch() { searchCode = ''; - searchedPart = null; - loadParts(); + searchResults = []; + isSearching = false; + listError = null; + loadParts(); // Recargamos la lista completa } const columns = createColumns(loadParts); - const tableData = $derived(searchedPart ? [searchedPart] : partsList); + + // Si estamos buscando, mostramos searchResults, si no, la lista completa + const tableData = $derived(isSearching ? searchResults : partsList);
@@ -111,17 +122,32 @@
- + + Búsqueda Rápida + Ingresa el número de parte o descripción para filtrar. + +
-
- +
+ e.key === 'Enter' && handleSearch()} + />
- {#if searchedPart || searchCode} + + {#if isSearching || searchCode} {/if} @@ -131,16 +157,22 @@ - {searchedPart ? 'Resultado' : 'Listado General'} + + {#if isSearching} + Resultados de la búsqueda ({searchResults.length}) + {:else} + Listado General ({partsList.length} registros) + {/if} + {#if listError} -
+
{listError}
- {:else} - {/if} + +
\ No newline at end of file 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 0c28e94f..442e7bdb 100644 --- a/frontend/src/routes/dashboard/goods/parts/edit/[[id]]/+page.svelte +++ b/frontend/src/routes/dashboard/goods/parts/edit/[[id]]/+page.svelte @@ -545,7 +545,7 @@ placeholder="Seleccione un cliente..." readonly onclick={() => showClientModal = true} - /> + />