Commit dc8ce4a6c192ae08d89f155def4a045dcd34b2df
1 parent
522d6b028e
Exists in
master
and in
1 other branch
Alerta de valores en editar producto
Showing
2 changed files
with
24 additions
and
16 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -228,6 +228,13 @@ angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl', |
| 228 | 228 | console.info(error); |
| 229 | 229 | }); |
| 230 | 230 | }; |
| 231 | + $scope.setTempCantidadArticulo = function (articulo) { | |
| 232 | + articulo.tmpCantidad = articulo.cantidad; | |
| 233 | + }; | |
| 234 | + | |
| 235 | + $scope.setTempPrecioArticulo = function (articulo) { | |
| 236 | + articulo.tmpPrecio = articulo.precio; | |
| 237 | + }; | |
| 231 | 238 | |
| 232 | 239 | $scope.seleccionarNotaPedido = function () { |
| 233 | 240 | var modalInstance = $uibModal.open( |
| ... | ... | @@ -823,19 +830,24 @@ angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl', |
| 823 | 830 | } |
| 824 | 831 | }; |
| 825 | 832 | |
| 826 | - $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { | |
| 833 | + $scope.editarArticulo = function (key, articulo, bandera) { | |
| 827 | 834 | if (key === 13) { |
| 828 | - if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { | |
| 835 | + var valorAEditar = bandera === 'precio' ? articulo.precio : articulo.cantidad; | |
| 836 | + var tempValor = bandera === 'precio' ? articulo.tmpPrecio | |
| 837 | + : articulo.tmpCantidad; | |
| 838 | + if (tempValor === '') { | |
| 829 | 839 | focaModalService.alert('Los valores deben ser al menos 1'); |
| 830 | 840 | return; |
| 831 | - } else if (articulo.cantidad < 0 || articulo.precio < 0) { | |
| 841 | + } else if (tempValor === '0') { | |
| 842 | + focaModalService.alert('Esta ingresando un producto con valor 0'); | |
| 843 | + } else if (valorAEditar < 0) { | |
| 832 | 844 | focaModalService.alert('Los valores no pueden ser negativos'); |
| 833 | 845 | return; |
| 834 | 846 | } |
| 835 | - articulo.cantidad = tmpCantidad; | |
| 836 | - articulo.precio = tmpPrecio; | |
| 847 | + articulo[bandera] = parseFloat(tempValor); | |
| 837 | 848 | $scope.getTotal(); |
| 838 | - articulo.editCantidad = articulo.editPrecio = false; | |
| 849 | + var propiedad = 'edit' + bandera.charAt(0).toUpperCase() + bandera.slice(1); | |
| 850 | + articulo[propiedad] = false; | |
| 839 | 851 | } |
| 840 | 852 | }; |
| 841 | 853 |
src/views/nota-pedido.html
| ... | ... | @@ -69,16 +69,14 @@ |
| 69 | 69 | <td class="col text-right"> |
| 70 | 70 | <input |
| 71 | 71 | ng-show="articulo.editCantidad && notaPedido.idRemito !== -1" |
| 72 | - ng-model="tmpCantidad" | |
| 72 | + ng-model="articulo.tmpCantidad" | |
| 73 | 73 | class="form-control" |
| 74 | 74 | foca-tipo-input |
| 75 | 75 | min="1" |
| 76 | 76 | foca-focus="articulo.editCantidad" |
| 77 | - ng-keypress="editarArticulo($event.keyCode, articulo, tmpCantidad, tmpPrecio);" | |
| 77 | + ng-keypress="editarArticulo($event.keyCode, articulo, 'cantidad');" | |
| 78 | 78 | esc-key="cancelarEditar(articulo)" |
| 79 | - ng-focus="selectFocus($event); | |
| 80 | - tmpCantidad = articulo.cantidad; | |
| 81 | - tmpPrecio = articulo.precio" | |
| 79 | + ng-focus="selectFocus($event);setTempCantidadArticulo(articulo);" | |
| 82 | 80 | teclado-virtual |
| 83 | 81 | > |
| 84 | 82 | <i |
| ... | ... | @@ -91,17 +89,15 @@ |
| 91 | 89 | <td class="col text-right"> |
| 92 | 90 | <input |
| 93 | 91 | ng-show="articulo.editPrecio && notaPedido.idRemito !== -1" |
| 94 | - ng-model="tmpPrecio" | |
| 92 | + ng-model="articulo.tmpPrecio" | |
| 95 | 93 | class="form-control" |
| 96 | 94 | foca-tipo-input |
| 97 | 95 | min="0" |
| 98 | 96 | step="0.0001" |
| 99 | 97 | foca-focus="articulo.editPrecio" |
| 100 | - ng-keypress="editarArticulo($event.keyCode, articulo, tmpCantidad, tmpPrecio);" | |
| 98 | + ng-keypress="editarArticulo($event.keyCode, articulo, 'precio');" | |
| 101 | 99 | esc-key="cancelarEditar(articulo)" |
| 102 | - ng-focus="selectFocus($event); | |
| 103 | - tmpCantidad = articulo.cantidad; | |
| 104 | - tmpPrecio = articulo.precio" | |
| 100 | + ng-focus="selectFocus($event); setTempPrecioArticulo(articulo);" | |
| 105 | 101 | teclado-virtual |
| 106 | 102 | > |
| 107 | 103 | <i |
-
mentioned in commit 4fadda