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;