Commit 13d19c8087fd0d8830a419a1d2866c33c9f8d290
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master See merge request !6
Showing
2 changed files
Show diff stats
src/js/controller.js
| ... | ... | @@ -50,6 +50,13 @@ angular.module('focaModalPuntoDescarga') |
| 50 | 50 | .then(function() { |
| 51 | 51 | actualizarTabla(); |
| 52 | 52 | $scope.ingreso = false; |
| 53 | + $scope.puntoDescarga = { | |
| 54 | + id: 0, | |
| 55 | + id_cliente: filters.idCliente, | |
| 56 | + id_da_config_0: filters.idDomicilio, | |
| 57 | + latitud: -32.89214159952345, | |
| 58 | + longitud: -68.84572999101856 | |
| 59 | + }; | |
| 53 | 60 | }); |
| 54 | 61 | }; |
| 55 | 62 | |
| ... | ... | @@ -75,36 +82,40 @@ angular.module('focaModalPuntoDescarga') |
| 75 | 82 | } |
| 76 | 83 | }; |
| 77 | 84 | |
| 78 | - $scope.agregarArticulo = function(punto) { | |
| 79 | - var articulo = $scope.articulos[$scope.articuloSeleccionado], | |
| 85 | + $scope.agregarArticulo = function(punto, key) { | |
| 86 | + key = (typeof key === 'undefined') ? 13 : key; | |
| 87 | + | |
| 88 | + if(key === 13){ | |
| 89 | + var articulo = $scope.articulos[$scope.articuloSeleccionado], | |
| 80 | 90 | cantidadRestante = articulo.restante - punto.cantidadACargar; |
| 81 | 91 | |
| 82 | - if(cantidadRestante < 0) { | |
| 83 | - focaModalService.alert('La cantidad a cargar debe ser menor o igual al restante'); | |
| 84 | - }else if(punto.cantidadACargar <= 0) { | |
| 85 | - focaModalService.alert('La cantidad a cargar debe ser mayor que cero'); | |
| 86 | - }else { | |
| 87 | - punto.cargado += parseInt(punto.cantidadACargar); | |
| 88 | - articulo.restante = cantidadRestante; | |
| 89 | - var existeArticulo = punto.articulosAgregados.filter( | |
| 90 | - function (articuloAAgregar) { | |
| 91 | - return articuloAAgregar.id === articulo.id; | |
| 92 | - }); | |
| 93 | - //Si el articulo ya fue agregado | |
| 94 | - if(existeArticulo.length) { | |
| 95 | - //Solo sumo cantidad | |
| 96 | - var total = parseInt(existeArticulo[0].cantidad) + parseInt(punto.cantidadACargar); | |
| 97 | - existeArticulo[0].cantidad = total; | |
| 92 | + if(cantidadRestante < 0) { | |
| 93 | + focaModalService.alert('La cantidad a cargar debe ser menor o igual al restante'); | |
| 94 | + }else if(punto.cantidadACargar <= 0) { | |
| 95 | + focaModalService.alert('La cantidad a cargar debe ser mayor que cero'); | |
| 98 | 96 | }else { |
| 99 | - //Agrego el articulo con la cantidad | |
| 100 | - punto.articulosAgregados.push({ | |
| 101 | - id: articulo.id, | |
| 102 | - descripcion: articulo.descripcion, | |
| 103 | - cantidad: punto.cantidadACargar, | |
| 104 | - index: $scope.articuloSeleccionado | |
| 105 | - }); | |
| 97 | + punto.cargado += parseInt(punto.cantidadACargar); | |
| 98 | + articulo.restante = cantidadRestante; | |
| 99 | + var existeArticulo = punto.articulosAgregados.filter( | |
| 100 | + function (articuloAAgregar) { | |
| 101 | + return articuloAAgregar.id === articulo.idArticulo; | |
| 102 | + }); | |
| 103 | + //Si el articulo ya fue agregado | |
| 104 | + if(existeArticulo.length) { | |
| 105 | + //Solo sumo cantidad | |
| 106 | + var total = parseInt(existeArticulo[0].cantidad) + parseInt(punto.cantidadACargar); | |
| 107 | + existeArticulo[0].cantidad = total; | |
| 108 | + }else { | |
| 109 | + //Agrego el articulo con la cantidad | |
| 110 | + punto.articulosAgregados.push({ | |
| 111 | + id: articulo.idArticulo, | |
| 112 | + descripcion: articulo.descripcion, | |
| 113 | + cantidad: punto.cantidadACargar, | |
| 114 | + index: $scope.articuloSeleccionado | |
| 115 | + }); | |
| 116 | + } | |
| 117 | + punto.cantidadACargar = 0; | |
| 106 | 118 | } |
| 107 | - punto.cantidadACargar = 0; | |
| 108 | 119 | } |
| 109 | 120 | }; |
| 110 | 121 | |
| ... | ... | @@ -156,7 +167,7 @@ angular.module('focaModalPuntoDescarga') |
| 156 | 167 | //Recorro los articulos cargados en cada punto |
| 157 | 168 | punto.articulosAgregados.forEach(function(articulo) { |
| 158 | 169 | var articuloARestar = $scope.articulos.filter(function(art) { |
| 159 | - return art.id == articulo.id; | |
| 170 | + return art.idArticulo == articulo.id; | |
| 160 | 171 | }); |
| 161 | 172 | articuloARestar[0].restante -= articulo.cantidad; |
| 162 | 173 | }); |