Commit da52effd8e345adfbf78a3de34de2c08beb10ae6
1 parent
6dbcfd4910
Exists in
master
mejora sugerencia
Showing
2 changed files
with
33 additions
and
11 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -56,6 +56,7 @@ angular.module('focaModalDetalleCisternas') |
| 56 | 56 | $uibModalInstance.dismiss(); |
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | + | |
| 59 | 60 | $scope.seleccionarArticulo($scope.articulos[0]); |
| 60 | 61 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { |
| 61 | 62 | if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { |
| ... | ... | @@ -89,10 +90,8 @@ angular.module('focaModalDetalleCisternas') |
| 89 | 90 | } |
| 90 | 91 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) |
| 91 | 92 | .then(function() { |
| 92 | - focaModalService.alert('Cisternas cargadas con éxito').then(function() { | |
| 93 | - $scope.cargando = false; | |
| 94 | - $uibModalInstance.close(); | |
| 95 | - }); | |
| 93 | + $scope.cargando = false; | |
| 94 | + $uibModalInstance.close(); | |
| 96 | 95 | }).catch(function(error) { |
| 97 | 96 | $scope.cargando = false; |
| 98 | 97 | $uibModalInstance.close(); |
| ... | ... | @@ -167,12 +166,14 @@ angular.module('focaModalDetalleCisternas') |
| 167 | 166 | elementHtml.style.width = porcentaje; |
| 168 | 167 | } |
| 169 | 168 | }; |
| 169 | + | |
| 170 | 170 | $scope.seleccionarArticulo = function(articulo) { |
| 171 | 171 | $scope.articuloSeleccionado = articulo; |
| 172 | 172 | $scope.cisternaDisponible(); |
| 173 | 173 | $scope.autoCompletar(); |
| 174 | 174 | $scope.actualizarArticulo(); |
| 175 | 175 | }; |
| 176 | + | |
| 176 | 177 | $scope.actualizarArticulo = function() { |
| 177 | 178 | $scope.articuloSeleccionado.cantidadCargada = 0; |
| 178 | 179 | for(var i = 0; i < $scope.aCargar.length; i++) { |
| ... | ... | @@ -180,18 +181,39 @@ angular.module('focaModalDetalleCisternas') |
| 180 | 181 | parseFloat($scope.aCargar[i]) || 0; |
| 181 | 182 | } |
| 182 | 183 | }; |
| 184 | + | |
| 183 | 185 | $scope.autoCompletar = function() { |
| 186 | + var arrayMismoProducto = []; | |
| 187 | + var arrayVacioProducto = []; | |
| 184 | 188 | for(var i = 0; i < $scope.cisternas.length; i++) { |
| 185 | - if($scope.cisternas[i].disabled) { | |
| 186 | - continue; | |
| 189 | + var cisterna = $scope.cisternas[i]; | |
| 190 | + cisterna.posicion = i; | |
| 191 | + console.info(i, cisterna.posicion); | |
| 192 | + if (!cisterna.disabled && cisterna.disponible > 0) { | |
| 193 | + if (cisterna.cisternaCarga) { | |
| 194 | + arrayMismoProducto.push(cisterna); | |
| 195 | + } else { | |
| 196 | + arrayVacioProducto.push(cisterna); | |
| 197 | + } | |
| 187 | 198 | } |
| 199 | + } | |
| 200 | + | |
| 201 | + arrayMismoProducto.sort(function(a,b) { | |
| 202 | + return a.disponible - b.disponible; | |
| 203 | + }); | |
| 204 | + | |
| 205 | + var cisternas = arrayMismoProducto.concat(arrayVacioProducto); | |
| 206 | + | |
| 207 | + for (var j = 0; j < cisternas.length; j++) { | |
| 188 | 208 | var aCargar = $scope.articuloSeleccionado.cantidad - |
| 189 | 209 | ($scope.articuloSeleccionado.cantidadCargada || 0); |
| 190 | - if(aCargar > $scope.cisternas[i].disponible) { | |
| 191 | - aCargar = $scope.cisternas[i].disponible; | |
| 210 | + | |
| 211 | + if(aCargar > cisternas[j].disponible) { | |
| 212 | + aCargar = cisternas[j].disponible; | |
| 192 | 213 | } |
| 193 | - if(aCargar) { | |
| 194 | - $scope.aCargar[i] = aCargar; | |
| 214 | + | |
| 215 | + if(aCargar > 0) { | |
| 216 | + $scope.aCargar[cisternas[j].posicion] = aCargar; | |
| 195 | 217 | $scope.actualizarArticulo(); |
| 196 | 218 | } |
| 197 | 219 | } |
src/views/foca-detalle-vehiculo.html