diff --git a/src/js/controller.js b/src/js/controller.js index 4415b65..cad1cbf 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -228,6 +228,13 @@ angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl', console.info(error); }); }; + $scope.setTempCantidadArticulo = function (articulo) { + articulo.tmpCantidad = articulo.cantidad; + }; + + $scope.setTempPrecioArticulo = function (articulo) { + articulo.tmpPrecio = articulo.precio; + }; $scope.seleccionarNotaPedido = function () { var modalInstance = $uibModal.open( @@ -823,19 +830,24 @@ angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl', } }; - $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { + $scope.editarArticulo = function (key, articulo, bandera) { if (key === 13) { - if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { + var valorAEditar = bandera === 'precio' ? articulo.precio : articulo.cantidad; + var tempValor = bandera === 'precio' ? articulo.tmpPrecio + : articulo.tmpCantidad; + if (tempValor === '') { focaModalService.alert('Los valores deben ser al menos 1'); return; - } else if (articulo.cantidad < 0 || articulo.precio < 0) { + } else if (tempValor === '0') { + focaModalService.alert('Esta ingresando un producto con valor 0'); + } else if (valorAEditar < 0) { focaModalService.alert('Los valores no pueden ser negativos'); return; } - articulo.cantidad = tmpCantidad; - articulo.precio = tmpPrecio; + articulo[bandera] = parseFloat(tempValor); $scope.getTotal(); - articulo.editCantidad = articulo.editPrecio = false; + var propiedad = 'edit' + bandera.charAt(0).toUpperCase() + bandera.slice(1); + articulo[propiedad] = false; } }; diff --git a/src/views/nota-pedido.html b/src/views/nota-pedido.html index 06541a2..a4c10d6 100644 --- a/src/views/nota-pedido.html +++ b/src/views/nota-pedido.html @@ -69,16 +69,14 @@