Commit 8c7af258fcf0178e2d16b3c54a33af019fa741c3
Exists in
master
and in
2 other branches
Merge branch 'develop' into 'master'
Develop See merge request !21
Showing
1 changed file
Show diff stats
src/js/controller.js
... | ... | @@ -29,14 +29,16 @@ angular.module('focaModalDetalleCisternas') |
29 | 29 | var promesaVehiculo = focaModalDetalleCisternasService.obtenerVehiculoById(idVehiculo); |
30 | 30 | var promesaCisternas = focaModalDetalleCisternasService |
31 | 31 | .obtenerCisternasPorFecha(idVehiculo); |
32 | + | |
32 | 33 | if(idRemito !== -1) { |
33 | 34 | promesaRemito = focaModalDetalleCisternasService.obtenerRemitoById(idRemito); |
34 | 35 | } |
36 | + | |
35 | 37 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { |
36 | 38 | if (idRemito !== -1 && !validarCargas(res[1].data, res[2].data)) { |
37 | - focaModalService.alert('Los artículos del remito exceden ' + | |
38 | - 'la cantidad disponible del vehiculo'); | |
39 | - $uibModalInstance.close(true); | |
39 | + var error = 'Los artículos del remito exceden la cantidad disponible del ' + | |
40 | + 'vehiculo'; | |
41 | + $uibModalInstance.dismiss(error); | |
40 | 42 | return; |
41 | 43 | } |
42 | 44 | $scope.cargandoDatos = false; |
... | ... | @@ -76,7 +78,9 @@ angular.module('focaModalDetalleCisternas') |
76 | 78 | } |
77 | 79 | $scope.$digest(); |
78 | 80 | }); |
81 | + | |
79 | 82 | $scope.aceptar = function() { |
83 | + | |
80 | 84 | $scope.cargando = true; |
81 | 85 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { |
82 | 86 | $scope.cisternasCarga[i].idUsuarioProceso = |
... | ... | @@ -84,55 +88,70 @@ angular.module('focaModalDetalleCisternas') |
84 | 88 | delete $scope.cisternasCarga[i].articulo; |
85 | 89 | delete $scope.cisternasCarga[i].remitos; |
86 | 90 | } |
91 | + | |
87 | 92 | var cisterna = { |
88 | 93 | cisternaMovimientos: cisternaMovimientos, |
89 | 94 | cisternaCargas: $scope.cisternasCarga, |
90 | 95 | idVehiculo: $scope.vehiculo.id, |
91 | 96 | fechaReparto: focaModalDetalleCisternasService.fecha |
92 | 97 | }; |
98 | + | |
93 | 99 | if(!focaModalDetalleCisternasService.idUsuario) { |
94 | 100 | focaModalService.alert('No logeado como vendedor'); |
95 | 101 | $scope.cargando = false; |
96 | 102 | return; |
97 | 103 | } |
104 | + | |
98 | 105 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) |
99 | 106 | .then(function() { |
107 | + | |
100 | 108 | $scope.cargando = false; |
101 | 109 | $uibModalInstance.close(); |
110 | + | |
102 | 111 | }).catch(function(error) { |
112 | + | |
103 | 113 | $scope.cargando = false; |
104 | 114 | $uibModalInstance.close(); |
115 | + | |
105 | 116 | if (error.status === 403) { |
106 | 117 | focaModalService.alert('ERROR: ' + error.data); |
107 | 118 | return; |
108 | 119 | } |
120 | + | |
109 | 121 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
110 | 122 | }); |
111 | 123 | }; |
124 | + | |
112 | 125 | $scope.cancelar = function() { |
113 | 126 | $uibModalInstance.dismiss(); |
114 | 127 | }; |
128 | + | |
115 | 129 | $scope.cargarACisternas = function() { |
130 | + | |
116 | 131 | for(var i = 0; i < $scope.cisternas.length; i++) { |
117 | 132 | var cisterna = $scope.cisternas[i]; |
118 | 133 | var aCargar = parseFloat($scope.aCargar[i]); |
119 | 134 | var fechaReparto = focaModalDetalleCisternasService.fecha; |
135 | + | |
120 | 136 | //validaciones |
121 | - if(!aCargar) { | |
137 | + if (!aCargar || cisterna.disabled) { | |
122 | 138 | continue; |
123 | 139 | } |
140 | + | |
124 | 141 | //cargar |
125 | - if(cisterna.cisternaCarga.cantidad) { | |
142 | + if (cisterna.cisternaCarga.cantidad) { | |
126 | 143 | cisterna.cisternaCarga.cantidad += aCargar; |
127 | - }else { | |
144 | + } else { | |
128 | 145 | cisterna.cisternaCarga.cantidad = aCargar; |
129 | 146 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
130 | 147 | } |
148 | + | |
131 | 149 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
132 | - | |
150 | + | |
133 | 151 | cisterna.cisternaCarga.articulo = { |
134 | 152 | DetArt: $scope.articuloSeleccionado.descripcion |
135 | 153 | }; |
154 | + | |
136 | 155 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
137 | 156 | .cargado = true; |
138 | 157 | |
... | ... | @@ -151,11 +170,13 @@ angular.module('focaModalDetalleCisternas') |
151 | 170 | $scope.cisternasCarga.push(cisterna.cisternaCarga); |
152 | 171 | cisternaMovimientos.push(cisternaMovimiento); |
153 | 172 | } |
173 | + | |
154 | 174 | var articuloSiguiente = $scope.articulos.filter( |
155 | 175 | function(filter) { |
156 | 176 | return filter.cargado !== true; |
157 | 177 | } |
158 | 178 | ); |
179 | + | |
159 | 180 | if(articuloSiguiente.length > 0) { |
160 | 181 | $scope.seleccionarArticulo(articuloSiguiente[0]); |
161 | 182 | } |
... | ... | @@ -178,21 +199,26 @@ angular.module('focaModalDetalleCisternas') |
178 | 199 | $scope.articuloSeleccionado = articulo; |
179 | 200 | $scope.cisternaDisponible(); |
180 | 201 | $scope.autoCompletar(); |
181 | - $scope.actualizarArticulo(); | |
202 | + // $scope.actualizarArticulo(); | |
182 | 203 | }; |
183 | 204 | |
184 | 205 | $scope.actualizarArticulo = function() { |
185 | 206 | $scope.articuloSeleccionado.cantidadCargada = 0; |
186 | - for(var i = 0; i < $scope.aCargar.length; i++) { | |
187 | - $scope.articuloSeleccionado.cantidadCargada += | |
207 | + for (var i = 0; i < $scope.aCargar.length; i++) { | |
208 | + if (!$scope.cisternas[i].disabled) { | |
209 | + | |
210 | + $scope.articuloSeleccionado.cantidadCargada += | |
188 | 211 | parseFloat($scope.aCargar[i]) || 0; |
212 | + } | |
189 | 213 | } |
190 | 214 | }; |
191 | 215 | |
192 | 216 | $scope.autoCompletar = function() { |
217 | + | |
193 | 218 | var arrayMismoProducto = []; |
194 | 219 | var arrayVacioProducto = []; |
195 | - for(var i = 0; i < $scope.cisternas.length; i++) { | |
220 | + | |
221 | + for (var i = 0; i < $scope.cisternas.length; i++) { | |
196 | 222 | var cisterna = $scope.cisternas[i]; |
197 | 223 | cisterna.posicion = i; |
198 | 224 | console.info(i, cisterna.posicion); |
... | ... | @@ -214,12 +240,12 @@ angular.module('focaModalDetalleCisternas') |
214 | 240 | for (var j = 0; j < cisternas.length; j++) { |
215 | 241 | var aCargar = $scope.articuloSeleccionado.cantidad - |
216 | 242 | ($scope.articuloSeleccionado.cantidadCargada || 0); |
217 | - | |
218 | - if(aCargar > cisternas[j].disponible) { | |
243 | + | |
244 | + if (aCargar > cisternas[j].disponible) { | |
219 | 245 | aCargar = cisternas[j].disponible; |
220 | 246 | } |
221 | - | |
222 | - if(aCargar > 0) { | |
247 | + | |
248 | + if (aCargar > 0) { | |
223 | 249 | $scope.aCargar[cisternas[j].posicion] = aCargar; |
224 | 250 | $scope.actualizarArticulo(); |
225 | 251 | } |
... | ... | @@ -232,7 +258,7 @@ angular.module('focaModalDetalleCisternas') |
232 | 258 | // $scope.cisternas[i].disabled = true; |
233 | 259 | // continue; |
234 | 260 | // } |
235 | - if($scope.cisternas[i].cisternaCarga && | |
261 | + if ($scope.cisternas[i].cisternaCarga && | |
236 | 262 | $scope.cisternas[i].cisternaCarga.idProducto && |
237 | 263 | $scope.articuloSeleccionado.idArticulo !== |
238 | 264 | $scope.cisternas[i].cisternaCarga.idProducto) |
... | ... | @@ -333,6 +359,7 @@ angular.module('focaModalDetalleCisternas') |
333 | 359 | |
334 | 360 | articulos.forEach(function(articulo) { |
335 | 361 | cisternas.forEach(function(cisterna) { |
362 | + if(!cisterna.cisternaCarga) cisterna.cisternaCarga = {}; | |
336 | 363 | //SI LA CISTERNA ESTA VACIA O |
337 | 364 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO |
338 | 365 | //Y AUN TIENE LUGAR |