diff --git a/templates/worker_dashboard.html b/templates/worker_dashboard.html index 86854ce..d3b7e97 100644 --- a/templates/worker_dashboard.html +++ b/templates/worker_dashboard.html @@ -202,47 +202,44 @@ function calcularVentaProductos() { let granTotal = 0; - const filas = document.querySelectorAll('tbody tr'); filas.forEach(fila => { const inputQty = fila.querySelector('input[name^="qty_"]'); if (inputQty) { - // Prevenir valores negativos visualmente if (parseInt(inputQty.value) < 0) { inputQty.value = 0; } - const cantidad = parseInt(inputQty.value) || 0; const precioTexto = fila.cells[1].innerText.replace(/\D/g, ''); const precio = parseInt(precioTexto) || 0; - granTotal += (cantidad * precio); } }); - displayTotalProductos.value = granTotal.toLocaleString('es-CL'); } inputsCantidad.forEach(input => { - // Bloquear tecla "-" y signos negativos input.addEventListener('keydown', function(e) { - if (e.key === '-' || e.key === 'Subtract') { + if (['Backspace', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete', 'Enter'].includes(e.key) || e.ctrlKey || e.metaKey) return; + if (e.key < '0' || e.key > '9') { e.preventDefault(); } }); - // Recalcular y validar al ingresar datos - input.addEventListener('input', calcularVentaProductos); + input.addEventListener('input', function() { + this.value = this.value.replace(/\D/g, ''); + calcularVentaProductos(); + }); }); +