From 0fd2d06db4428c1c20a4805e6cc4298d34047200 Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Mon, 5 Jan 2026 20:31:01 -0600 Subject: [PATCH] =?UTF-8?q?add:=20agregar=20campo=20de=20c=C3=B3digo=20de?= =?UTF-8?q?=20barras=20en=20formularios=20de=20creaci=C3=B3n=20y=20edici?= =?UTF-8?q?=C3=B3n=20de=20productos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/POS/Inventory/CreateModal.vue | 17 +++++++++- src/pages/POS/Inventory/EditModal.vue | 18 ++++++++++- src/pages/POS/Point.vue | 41 +++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/pages/POS/Inventory/CreateModal.vue b/src/pages/POS/Inventory/CreateModal.vue index 85f1b47..f9d3492 100644 --- a/src/pages/POS/Inventory/CreateModal.vue +++ b/src/pages/POS/Inventory/CreateModal.vue @@ -21,6 +21,7 @@ const categories = ref([]); const form = useForm({ name: '', sku: '', + barcode: '', category_id: '', stock: 0, cost: 0, @@ -121,8 +122,22 @@ watch(() => props.show, (newValue) => { - +
+ + + +
+ + +
diff --git a/src/pages/POS/Inventory/EditModal.vue b/src/pages/POS/Inventory/EditModal.vue index 978ce3d..f43ec1e 100644 --- a/src/pages/POS/Inventory/EditModal.vue +++ b/src/pages/POS/Inventory/EditModal.vue @@ -22,6 +22,7 @@ const categories = ref([]); const form = useForm({ name: '', sku: '', + barcode: '', category_id: '', stock: 0, cost: 0, @@ -70,6 +71,7 @@ watch(() => props.product, (newProduct) => { if (newProduct) { form.name = newProduct.name || ''; form.sku = newProduct.sku || ''; + form.barcode = newProduct.barcode || ''; form.category_id = newProduct.category_id || ''; form.stock = newProduct.stock || 0; form.cost = parseFloat(newProduct.price?.cost || 0); @@ -134,8 +136,22 @@ watch(() => props.show, (newValue) => {
- +
+ + + +
+ + +
diff --git a/src/pages/POS/Point.vue b/src/pages/POS/Point.vue index e4d6950..fad9618 100644 --- a/src/pages/POS/Point.vue +++ b/src/pages/POS/Point.vue @@ -47,6 +47,7 @@ const filteredProducts = computed(() => { return ( product.name?.toLowerCase().includes(query) || product.sku?.toLowerCase().includes(query) || + product.barcode?.toLowerCase().includes(query) || product.description?.toLowerCase().includes(query) ); }); @@ -90,6 +91,46 @@ const toggleScanMode = () => { } }; +const handleCodeDetected = async (barcode) => { + if (!barcode || barcode.trim() === '') { + window.Notify.error('Código de barras inválido'); + return; + } + + try { + window.Notify.info('Buscando producto...'); + + // Buscar producto por código de barras usando el API + const response = await fetch(apiURL(`inventario?q=${encodeURIComponent(barcode)}`), { + headers: { + 'Authorization': `Bearer ${sessionStorage.token}`, + 'Accept': 'application/json' + } + }); + + const result = await response.json(); + + // Verificar si se encontró el producto + if (result.data && result.data.products && result.data.products.data && result.data.products.data.length > 0) { + const product = result.data.products.data[0]; + + // Verificar si el producto tiene stock + if (product.stock <= 0) { + window.Notify.error(`${product.name} no tiene stock disponible`); + return; + } + + // Agregar producto al carrito + addToCart(product); + } else { + window.Notify.error('Producto no encontrado'); + } + } catch (error) { + console.error('Error buscando producto:', error); + window.Notify.error('Error al buscar el producto'); + } +}; + const handleConfirmSale = async (paymentData) => { processingPayment.value = true;