Commit acb9dc7e2c45dcbdfac36e9f30c700c722f06343
1 parent
aaf537312e
Exists in
master
vehiculo y remito en promesa, cisternas no disponibles en funcion, auto completa…
…r cantidad en cisternas
Showing
1 changed file
with
63 additions
and
17 deletions
Show diff stats
src/js/controllerDetalleVehiculo.js
... | ... | @@ -11,30 +11,30 @@ angular.module('focaLogisticaPedidoRuta') |
11 | 11 | focaLogisticaPedidoRutaService |
12 | 12 | ) { |
13 | 13 | //seteo variables |
14 | + $scope.cargandoDatos = true; | |
14 | 15 | $scope.idRemito = idRemito; |
15 | 16 | $scope.articulos = []; |
16 | 17 | $scope.vehiculo = {}; |
17 | 18 | $scope.remito = {}; |
18 | 19 | $scope.aCargar = []; |
19 | 20 | var cisternaMovimientos = []; |
20 | - focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then( | |
21 | - function(res) { | |
22 | - $scope.vehiculo = res.data; | |
23 | - } | |
24 | - ); | |
21 | + var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); | |
22 | + var promesaRemito; | |
25 | 23 | if(idRemito !== -1) { |
26 | - focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito).then( | |
27 | - function(res) { | |
28 | - $scope.remito = res.data; | |
29 | - if($scope.remito.idUsuarioProceso) { | |
30 | - focaModalService.alert('Remito ya asignado'); | |
31 | - $uibModalInstance.close(); | |
32 | - } | |
33 | - $scope.articulos = res.data.articulosRemito; | |
34 | - $scope.cambioArticulo($scope.articulos[0]); | |
35 | - } | |
36 | - ); | |
24 | + promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); | |
37 | 25 | } |
26 | + Promise.all([promesaVehiculo, promesaRemito]).then(function(res) { | |
27 | + $scope.cargandoDatos = false; | |
28 | + $scope.vehiculo = res[0].data; | |
29 | + if(!res[1]) return; | |
30 | + $scope.remito = res[1].data; | |
31 | + if($scope.remito.idUsuarioProceso) { | |
32 | + focaModalService.alert('Remito ya asignado'); | |
33 | + $uibModalInstance.close(); | |
34 | + } | |
35 | + $scope.articulos = $scope.remito.articulosRemito; | |
36 | + $scope.cambioArticulo($scope.articulos[0]); | |
37 | + }); | |
38 | 38 | $scope.aceptar = function() { |
39 | 39 | $scope.cargando = true; |
40 | 40 | var cisternaCargas = []; |
... | ... | @@ -133,8 +133,17 @@ angular.module('focaLogisticaPedidoRuta') |
133 | 133 | } |
134 | 134 | }; |
135 | 135 | $scope.cambioArticulo = function(articulo) { |
136 | - articulo.checked = true; | |
136 | + $scope.aCargar = []; | |
137 | + $filter('filter')($scope.articulos, {id: articulo.id})[0].checked = true; | |
137 | 138 | $scope.articuloSeleccionado = articulo; |
139 | + for (var i = 0; i < $scope.vehiculo.cisternas.length; i++) { | |
1 |
|
|
140 | + $scope.vehiculo.cisternas[i] = | |
141 | + $scope.cisternaDisabled($scope.vehiculo.cisternas[i]); | |
142 | + } | |
143 | + var disponible = $filter('filter')($scope.vehiculo.cisternas, {disabled: false}); | |
144 | + var index = $scope.vehiculo.cisternas.indexOf(disponible[0]); | |
145 | + $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; | |
146 | + $scope.actualizarArticulo(); | |
138 | 147 | }; |
139 | 148 | $scope.actualizarArticulo = function () { |
140 | 149 | $scope.articuloSeleccionado.cantidadCargada = 0; |
... | ... | @@ -143,7 +152,44 @@ angular.module('focaLogisticaPedidoRuta') |
143 | 152 | parseFloat($scope.aCargar[i]) || 0; |
144 | 153 | } |
145 | 154 | }; |
155 | + $scope.cisternaDisabled = function(cisterna) { | |
156 | + if(!$scope.articuloSeleccionado || ($scope.articuloSeleccionado.idArticulo !== | |
157 | + cisterna.cisternaCarga.idProducto && cisterna.cisternaCarga.idProducto) || | |
158 | + !$scope.tieneArticulosPendientes()|| $scope.articuloSeleccionado.cantidad > | |
159 | + cisterna.disponible) { | |
160 | + cisterna.disabled = true; | |
161 | + }else { | |
162 | + cisterna.disabled = false; | |
163 | + } | |
164 | + return cisterna; | |
165 | + }; | |
166 | + $scope.rellenarInput = function(input = 0) { | |
167 | + if(!$scope.articuloSeleccionado) return; | |
168 | + input = parseFloat(input); | |
169 | + if(input === $scope.articuloSeleccionado.cantidad || | |
170 | + $scope.articuloSeleccionado.cantidad - | |
171 | + $scope.articuloSeleccionado.cantidadCargada === 0) { | |
172 | + return input; | |
173 | + } | |
174 | + input += parseFloat($scope.articuloSeleccionado.cantidad - | |
175 | + $scope.articuloSeleccionado.cantidadCargada); | |
176 | + return input; | |
177 | + }; | |
178 | + $scope.distribucionDisponible = function() { | |
179 | + if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - | |
180 | + $scope.articuloSeleccionado.cantidadCargada !== 0 || | |
181 | + !$scope.tieneArticulosPendientes()) { | |
182 | + return false; | |
183 | + } | |
184 | + return true; | |
185 | + }; | |
146 | 186 | $scope.tieneArticulosPendientes = function() { |
187 | + var algunValorNegativo = $scope.aCargar.filter(function(p) { | |
188 | + return p < 0; | |
189 | + }); | |
190 | + if(algunValorNegativo.length) { | |
191 | + return false; | |
192 | + } | |
147 | 193 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
148 | 194 | return filter.cargado === true; |
149 | 195 | }); |