Commit 4b33337761e148f03f1ff4ab1e22bb55d395d5de
1 parent
e9ef0b2eaf
Exists in
master
Arreglo de alerta en capacidad de vehiculo
Showing
1 changed file
with
15 additions
and
4 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalDetalleCisternas') | 1 | angular.module('focaModalDetalleCisternas') |
2 | .controller('focaDetalleVehiculo', | 2 | .controller('focaDetalleVehiculo', |
3 | ['$scope', | 3 | ['$scope', |
4 | '$uibModalInstance', | 4 | '$uibModalInstance', |
5 | 'idVehiculo', | 5 | 'idVehiculo', |
6 | 'idRemito', | 6 | 'idRemito', |
7 | 'focaModalService', | 7 | 'focaModalService', |
8 | '$filter', | 8 | '$filter', |
9 | 'focaModalDetalleCisternasService', | 9 | 'focaModalDetalleCisternasService', |
10 | 'fechaReparto', | 10 | 'fechaReparto', |
11 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, | 11 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, |
12 | focaModalDetalleCisternasService, fechaReparto | 12 | focaModalDetalleCisternasService, fechaReparto |
13 | ) { | 13 | ) { |
14 | //seteo variables | 14 | //seteo variables |
15 | $scope.cargandoDatos = true; | 15 | $scope.cargandoDatos = true; |
16 | $scope.idRemito = idRemito; | 16 | $scope.idRemito = idRemito; |
17 | $scope.articulos = []; | 17 | $scope.articulos = []; |
18 | $scope.vehiculo = {}; | 18 | $scope.vehiculo = {}; |
19 | $scope.cisternas = []; | 19 | $scope.cisternas = []; |
20 | $scope.cisternasCarga = []; | 20 | $scope.cisternasCarga = []; |
21 | $scope.remito = {}; | 21 | $scope.remito = {}; |
22 | $scope.aCargar = []; | 22 | $scope.aCargar = []; |
23 | var cisternaMovimientos = []; | 23 | var cisternaMovimientos = []; |
24 | var promesaRemito; | 24 | var promesaRemito; |
25 | 25 | ||
26 | if(fechaReparto) { | 26 | if(fechaReparto) { |
27 | focaModalDetalleCisternasService.fecha = fechaReparto; | 27 | focaModalDetalleCisternasService.fecha = fechaReparto; |
28 | } | 28 | } |
29 | var promesaVehiculo = focaModalDetalleCisternasService.obtenerVehiculoById(idVehiculo); | 29 | var promesaVehiculo = focaModalDetalleCisternasService.obtenerVehiculoById(idVehiculo); |
30 | var promesaCisternas = focaModalDetalleCisternasService | 30 | var promesaCisternas = focaModalDetalleCisternasService |
31 | .obtenerCisternasPorFecha(idVehiculo); | 31 | .obtenerCisternasPorFecha(idVehiculo); |
32 | 32 | ||
33 | if(idRemito !== -1) { | 33 | if(idRemito !== -1) { |
34 | promesaRemito = focaModalDetalleCisternasService.obtenerRemitoById(idRemito); | 34 | promesaRemito = focaModalDetalleCisternasService.obtenerRemitoById(idRemito); |
35 | } | 35 | } |
36 | 36 | ||
37 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { | 37 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { |
38 | if (idRemito !== -1 && !validarCargas(res[1].data, res[2].data)) { | 38 | if (idRemito !== -1 && !validarCargas(res[1].data, res[2].data)) { |
39 | var alerta = focaModalService.alert('Los artículos del remito exceden la cantidad disponible del ' + | 39 | focaModalService |
40 | 'vehiculo'); | 40 | .alert('Los artículos del remito exceden la capacidad disponible del ' + |
41 | $uibModalInstance.dismiss(alerta); | 41 | 'vehiculo') |
42 | .then(function() { | ||
43 | $uibModalInstance.dismiss(); | ||
44 | }, function() { | ||
45 | $uibModalInstance.dismiss(); | ||
46 | }); | ||
42 | return; | 47 | return; |
43 | } | 48 | } |
49 | |||
44 | $scope.cargandoDatos = false; | 50 | $scope.cargandoDatos = false; |
45 | $scope.vehiculo = res[0].data; | 51 | $scope.vehiculo = res[0].data; |
46 | $scope.cisternas = res[1].data; | 52 | $scope.cisternas = res[1].data; |
47 | 53 | ||
48 | if(!$scope.cisternas.length) { | 54 | if(!$scope.cisternas.length) { |
49 | $uibModalInstance.dismiss(focaModalService.alert('El vehículo no tiene cisternas')); | 55 | focaModalService.alert('El vehículo no tiene cisternas') |
56 | .then(function () { | ||
57 | $uibModalInstance.dismiss(); | ||
58 | }, function() { | ||
59 | $uibModalInstance.dismiss(); | ||
60 | }); | ||
50 | return; | 61 | return; |
51 | } | 62 | } |
52 | 63 | ||
53 | if(!res[2]) { | 64 | if(!res[2]) { |
54 | $scope.$digest(); | 65 | $scope.$digest(); |
55 | return; | 66 | return; |
56 | } | 67 | } |
57 | 68 | ||
58 | $scope.remito = res[2].data; | 69 | $scope.remito = res[2].data; |
59 | 70 | ||
60 | if($scope.remito.idUsuarioProceso) { | 71 | if($scope.remito.idUsuarioProceso) { |
61 | 72 | ||
62 | $uibModalInstance.dismiss(focaModalService.alert('Remito ya asignado')); | 73 | $uibModalInstance.dismiss(focaModalService.alert('Remito ya asignado')); |
63 | } | 74 | } |
64 | 75 | ||
65 | $scope.articulos = $scope.remito.articulosRemito; | 76 | $scope.articulos = $scope.remito.articulosRemito; |
66 | if(!$scope.articulos.length) { | 77 | if(!$scope.articulos.length) { |
67 | $uibModalInstance.dismiss(focaModalService.alert('El remito no tiene articulos')); | 78 | $uibModalInstance.dismiss(focaModalService.alert('El remito no tiene articulos')); |
68 | return; | 79 | return; |
69 | } | 80 | } |
70 | 81 | ||
71 | $scope.seleccionarArticulo($scope.articulos[0]); | 82 | $scope.seleccionarArticulo($scope.articulos[0]); |
72 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { | 83 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { |
73 | if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { | 84 | if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { |
74 | return cisterna.cisternaCarga.idUsuarioProceso !== | 85 | return cisterna.cisternaCarga.idUsuarioProceso !== |
75 | focaModalDetalleCisternasService.idUsuario; | 86 | focaModalDetalleCisternasService.idUsuario; |
76 | } | 87 | } |
77 | }); | 88 | }); |
78 | if(tieneUsuario.length) { | 89 | if(tieneUsuario.length) { |
79 | focaModalService.alert('Otro usario esta usando este vehículo'); | 90 | focaModalService.alert('Otro usario esta usando este vehículo'); |
80 | $uibModalInstance.close(); | 91 | $uibModalInstance.close(); |
81 | } | 92 | } |
82 | $scope.$digest(); | 93 | $scope.$digest(); |
83 | }); | 94 | }); |
84 | 95 | ||
85 | $scope.aceptar = function() { | 96 | $scope.aceptar = function() { |
86 | 97 | ||
87 | $scope.cargando = true; | 98 | $scope.cargando = true; |
88 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { | 99 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { |
89 | $scope.cisternasCarga[i].idUsuarioProceso = | 100 | $scope.cisternasCarga[i].idUsuarioProceso = |
90 | focaModalDetalleCisternasService.idUsuario; | 101 | focaModalDetalleCisternasService.idUsuario; |
91 | delete $scope.cisternasCarga[i].articulo; | 102 | delete $scope.cisternasCarga[i].articulo; |
92 | delete $scope.cisternasCarga[i].remitos; | 103 | delete $scope.cisternasCarga[i].remitos; |
93 | } | 104 | } |
94 | 105 | ||
95 | var cisterna = { | 106 | var cisterna = { |
96 | cisternaMovimientos: cisternaMovimientos, | 107 | cisternaMovimientos: cisternaMovimientos, |
97 | cisternaCargas: $scope.cisternasCarga, | 108 | cisternaCargas: $scope.cisternasCarga, |
98 | idVehiculo: $scope.vehiculo.id, | 109 | idVehiculo: $scope.vehiculo.id, |
99 | fechaReparto: focaModalDetalleCisternasService.fecha | 110 | fechaReparto: focaModalDetalleCisternasService.fecha |
100 | }; | 111 | }; |
101 | 112 | ||
102 | if(!focaModalDetalleCisternasService.idUsuario) { | 113 | if(!focaModalDetalleCisternasService.idUsuario) { |
103 | focaModalService.alert('No logeado como vendedor'); | 114 | focaModalService.alert('No logeado como vendedor'); |
104 | $scope.cargando = false; | 115 | $scope.cargando = false; |
105 | return; | 116 | return; |
106 | } | 117 | } |
107 | 118 | ||
108 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) | 119 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) |
109 | .then(function() { | 120 | .then(function() { |
110 | 121 | ||
111 | $scope.cargando = false; | 122 | $scope.cargando = false; |
112 | $uibModalInstance.close(); | 123 | $uibModalInstance.close(); |
113 | 124 | ||
114 | }).catch(function(error) { | 125 | }).catch(function(error) { |
115 | 126 | ||
116 | $scope.cargando = false; | 127 | $scope.cargando = false; |
117 | $uibModalInstance.close(); | 128 | $uibModalInstance.close(); |
118 | 129 | ||
119 | if (error.status === 403) { | 130 | if (error.status === 403) { |
120 | focaModalService.alert('ERROR: ' + error.data); | 131 | focaModalService.alert('ERROR: ' + error.data); |
121 | return; | 132 | return; |
122 | } | 133 | } |
123 | 134 | ||
124 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 135 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
125 | }); | 136 | }); |
126 | }; | 137 | }; |
127 | 138 | ||
128 | $scope.cancelar = function() { | 139 | $scope.cancelar = function() { |
129 | $uibModalInstance.dismiss(); | 140 | $uibModalInstance.dismiss(); |
130 | }; | 141 | }; |
131 | 142 | ||
132 | $scope.cargarACisternas = function() { | 143 | $scope.cargarACisternas = function() { |
133 | 144 | ||
134 | for(var i = 0; i < $scope.cisternas.length; i++) { | 145 | for(var i = 0; i < $scope.cisternas.length; i++) { |
135 | var cisterna = $scope.cisternas[i]; | 146 | var cisterna = $scope.cisternas[i]; |
136 | var aCargar = parseFloat($scope.aCargar[i]); | 147 | var aCargar = parseFloat($scope.aCargar[i]); |
137 | var fechaReparto = focaModalDetalleCisternasService.fecha; | 148 | var fechaReparto = focaModalDetalleCisternasService.fecha; |
138 | 149 | ||
139 | //validaciones | 150 | //validaciones |
140 | if (!aCargar || cisterna.disabled) { | 151 | if (!aCargar || cisterna.disabled) { |
141 | continue; | 152 | continue; |
142 | } | 153 | } |
143 | 154 | ||
144 | //cargar | 155 | //cargar |
145 | if (cisterna.cisternaCarga.cantidad) { | 156 | if (cisterna.cisternaCarga.cantidad) { |
146 | cisterna.cisternaCarga.cantidad += aCargar; | 157 | cisterna.cisternaCarga.cantidad += aCargar; |
147 | } else { | 158 | } else { |
148 | cisterna.cisternaCarga.cantidad = aCargar; | 159 | cisterna.cisternaCarga.cantidad = aCargar; |
149 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 160 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
150 | } | 161 | } |
151 | 162 | ||
152 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 163 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
153 | 164 | ||
154 | cisterna.cisternaCarga.articulo = { | 165 | cisterna.cisternaCarga.articulo = { |
155 | DetArt: $scope.articuloSeleccionado.descripcion | 166 | DetArt: $scope.articuloSeleccionado.descripcion |
156 | }; | 167 | }; |
157 | 168 | ||
158 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 169 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
159 | .cargado = true; | 170 | .cargado = true; |
160 | 171 | ||
161 | $scope.calcularPorcentaje(cisterna); | 172 | $scope.calcularPorcentaje(cisterna); |
162 | //Guardar | 173 | //Guardar |
163 | var now = new Date(); | 174 | var now = new Date(); |
164 | var cisternaMovimiento = { | 175 | var cisternaMovimiento = { |
165 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 176 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
166 | cantidad: aCargar, | 177 | cantidad: aCargar, |
167 | metodo: 'carga', | 178 | metodo: 'carga', |
168 | idCisternaCarga: cisterna.cisternaCarga.id, | 179 | idCisternaCarga: cisterna.cisternaCarga.id, |
169 | idRemito: $scope.remito.id | 180 | idRemito: $scope.remito.id |
170 | }; | 181 | }; |
171 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 182 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
172 | cisterna.cisternaCarga.idCisterna = cisterna.id; | 183 | cisterna.cisternaCarga.idCisterna = cisterna.id; |
173 | $scope.cisternasCarga.push(cisterna.cisternaCarga); | 184 | $scope.cisternasCarga.push(cisterna.cisternaCarga); |
174 | cisternaMovimientos.push(cisternaMovimiento); | 185 | cisternaMovimientos.push(cisternaMovimiento); |
175 | } | 186 | } |
176 | 187 | ||
177 | var articuloSiguiente = $scope.articulos.filter( | 188 | var articuloSiguiente = $scope.articulos.filter( |
178 | function(filter) { | 189 | function(filter) { |
179 | return filter.cargado !== true; | 190 | return filter.cargado !== true; |
180 | } | 191 | } |
181 | ); | 192 | ); |
182 | 193 | ||
183 | if(articuloSiguiente.length > 0) { | 194 | if(articuloSiguiente.length > 0) { |
184 | $scope.seleccionarArticulo(articuloSiguiente[0]); | 195 | $scope.seleccionarArticulo(articuloSiguiente[0]); |
185 | } | 196 | } |
186 | }; | 197 | }; |
187 | $scope.calcularPorcentaje = function(cisterna) { | 198 | $scope.calcularPorcentaje = function(cisterna) { |
188 | if(!cisterna.cisternaCarga) { | 199 | if(!cisterna.cisternaCarga) { |
189 | cisterna.cisternaCarga = { | 200 | cisterna.cisternaCarga = { |
190 | cantidad: 0 | 201 | cantidad: 0 |
191 | }; | 202 | }; |
192 | } | 203 | } |
193 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 204 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
194 | cisterna.capacidad) + '%'; | 205 | cisterna.capacidad) + '%'; |
195 | var elementHtml = document.getElementById(cisterna.id); | 206 | var elementHtml = document.getElementById(cisterna.id); |
196 | if(elementHtml) { | 207 | if(elementHtml) { |
197 | elementHtml.style.width = porcentaje; | 208 | elementHtml.style.width = porcentaje; |
198 | } | 209 | } |
199 | }; | 210 | }; |
200 | 211 | ||
201 | $scope.seleccionarArticulo = function(articulo) { | 212 | $scope.seleccionarArticulo = function(articulo) { |
202 | $scope.articuloSeleccionado = articulo; | 213 | $scope.articuloSeleccionado = articulo; |
203 | $scope.cisternaDisponible(); | 214 | $scope.cisternaDisponible(); |
204 | $scope.autoCompletar(); | 215 | $scope.autoCompletar(); |
205 | // $scope.actualizarArticulo(); | 216 | // $scope.actualizarArticulo(); |
206 | }; | 217 | }; |
207 | 218 | ||
208 | $scope.actualizarArticulo = function() { | 219 | $scope.actualizarArticulo = function() { |
209 | $scope.articuloSeleccionado.cantidadCargada = 0; | 220 | $scope.articuloSeleccionado.cantidadCargada = 0; |
210 | for (var i = 0; i < $scope.aCargar.length; i++) { | 221 | for (var i = 0; i < $scope.aCargar.length; i++) { |
211 | if (!$scope.cisternas[i].disabled) { | 222 | if (!$scope.cisternas[i].disabled) { |
212 | 223 | ||
213 | $scope.articuloSeleccionado.cantidadCargada += | 224 | $scope.articuloSeleccionado.cantidadCargada += |
214 | parseFloat($scope.aCargar[i]) || 0; | 225 | parseFloat($scope.aCargar[i]) || 0; |
215 | } | 226 | } |
216 | } | 227 | } |
217 | }; | 228 | }; |
218 | 229 | ||
219 | $scope.autoCompletar = function() { | 230 | $scope.autoCompletar = function() { |
220 | 231 | ||
221 | var arrayMismoProducto = []; | 232 | var arrayMismoProducto = []; |
222 | var arrayVacioProducto = []; | 233 | var arrayVacioProducto = []; |
223 | 234 | ||
224 | for (var i = 0; i < $scope.cisternas.length; i++) { | 235 | for (var i = 0; i < $scope.cisternas.length; i++) { |
225 | var cisterna = $scope.cisternas[i]; | 236 | var cisterna = $scope.cisternas[i]; |
226 | cisterna.posicion = i; | 237 | cisterna.posicion = i; |
227 | console.info(i, cisterna.posicion); | 238 | console.info(i, cisterna.posicion); |
228 | if (!cisterna.disabled && cisterna.disponible > 0) { | 239 | if (!cisterna.disabled && cisterna.disponible > 0) { |
229 | if (cisterna.cisternaCarga) { | 240 | if (cisterna.cisternaCarga) { |
230 | arrayMismoProducto.push(cisterna); | 241 | arrayMismoProducto.push(cisterna); |
231 | } else { | 242 | } else { |
232 | arrayVacioProducto.push(cisterna); | 243 | arrayVacioProducto.push(cisterna); |
233 | } | 244 | } |
234 | } | 245 | } |
235 | } | 246 | } |
236 | 247 | ||
237 | arrayMismoProducto.sort(function(a,b) { | 248 | arrayMismoProducto.sort(function(a,b) { |
238 | return a.disponible - b.disponible; | 249 | return a.disponible - b.disponible; |
239 | }); | 250 | }); |
240 | 251 | ||
241 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); | 252 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); |
242 | 253 | ||
243 | for (var j = 0; j < cisternas.length; j++) { | 254 | for (var j = 0; j < cisternas.length; j++) { |
244 | var aCargar = $scope.articuloSeleccionado.cantidad - | 255 | var aCargar = $scope.articuloSeleccionado.cantidad - |
245 | ($scope.articuloSeleccionado.cantidadCargada || 0); | 256 | ($scope.articuloSeleccionado.cantidadCargada || 0); |
246 | 257 | ||
247 | if (aCargar > cisternas[j].disponible) { | 258 | if (aCargar > cisternas[j].disponible) { |
248 | aCargar = cisternas[j].disponible; | 259 | aCargar = cisternas[j].disponible; |
249 | } | 260 | } |
250 | 261 | ||
251 | if (aCargar > 0) { | 262 | if (aCargar > 0) { |
252 | $scope.aCargar[cisternas[j].posicion] = aCargar; | 263 | $scope.aCargar[cisternas[j].posicion] = aCargar; |
253 | $scope.actualizarArticulo(); | 264 | $scope.actualizarArticulo(); |
254 | } | 265 | } |
255 | } | 266 | } |
256 | }; | 267 | }; |
257 | $scope.cisternaDisponible = function() { | 268 | $scope.cisternaDisponible = function() { |
258 | for(var i = 0; i < $scope.cisternas.length; i++) { | 269 | for(var i = 0; i < $scope.cisternas.length; i++) { |
259 | //Puede meter un porcentaje del total | 270 | //Puede meter un porcentaje del total |
260 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { | 271 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { |
261 | // $scope.cisternas[i].disabled = true; | 272 | // $scope.cisternas[i].disabled = true; |
262 | // continue; | 273 | // continue; |
263 | // } | 274 | // } |
264 | if ($scope.cisternas[i].cisternaCarga && | 275 | if ($scope.cisternas[i].cisternaCarga && |
265 | $scope.cisternas[i].cisternaCarga.idProducto && | 276 | $scope.cisternas[i].cisternaCarga.idProducto && |
266 | $scope.articuloSeleccionado.idArticulo !== | 277 | $scope.articuloSeleccionado.idArticulo !== |
267 | $scope.cisternas[i].cisternaCarga.idProducto) | 278 | $scope.cisternas[i].cisternaCarga.idProducto) |
268 | { | 279 | { |
269 | $scope.cisternas[i].disabled = true; | 280 | $scope.cisternas[i].disabled = true; |
270 | continue; | 281 | continue; |
271 | } | 282 | } |
272 | $scope.cisternas[i].disabled = false; | 283 | $scope.cisternas[i].disabled = false; |
273 | } | 284 | } |
274 | }; | 285 | }; |
275 | $scope.rellenarInput = function(input, cisterna) { | 286 | $scope.rellenarInput = function(input, cisterna) { |
276 | if(!$scope.articuloSeleccionado) return; | 287 | if(!$scope.articuloSeleccionado) return; |
277 | if($scope.articuloSeleccionado.cantidad - | 288 | if($scope.articuloSeleccionado.cantidad - |
278 | $scope.articuloSeleccionado.cantidadCargada === 0) { | 289 | $scope.articuloSeleccionado.cantidadCargada === 0) { |
279 | return input; | 290 | return input; |
280 | } | 291 | } |
281 | if(!input) input = 0; | 292 | if(!input) input = 0; |
282 | input = parseFloat(input); | 293 | input = parseFloat(input); |
283 | input += parseFloat($scope.articuloSeleccionado.cantidad - | 294 | input += parseFloat($scope.articuloSeleccionado.cantidad - |
284 | $scope.articuloSeleccionado.cantidadCargada); | 295 | $scope.articuloSeleccionado.cantidadCargada); |
285 | if(input <= 0) return; | 296 | if(input <= 0) return; |
286 | if(input > cisterna.disponible) { | 297 | if(input > cisterna.disponible) { |
287 | input = cisterna.disponible; | 298 | input = cisterna.disponible; |
288 | } | 299 | } |
289 | return input; | 300 | return input; |
290 | }; | 301 | }; |
291 | $scope.distribucionDisponible = function() { | 302 | $scope.distribucionDisponible = function() { |
292 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - | 303 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - |
293 | $scope.articuloSeleccionado.cantidadCargada !== 0 || | 304 | $scope.articuloSeleccionado.cantidadCargada !== 0 || |
294 | !$scope.tieneArticulosPendientes()) { | 305 | !$scope.tieneArticulosPendientes()) { |
295 | return false; | 306 | return false; |
296 | } | 307 | } |
297 | for(var i = 0; i < $scope.cisternas.length; i++) { | 308 | for(var i = 0; i < $scope.cisternas.length; i++) { |
298 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { | 309 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { |
299 | return false; | 310 | return false; |
300 | } | 311 | } |
301 | } | 312 | } |
302 | return true; | 313 | return true; |
303 | }; | 314 | }; |
304 | $scope.tieneArticulosPendientes = function() { | 315 | $scope.tieneArticulosPendientes = function() { |
305 | var algunValorNegativo = $scope.aCargar.filter(function(p) { | 316 | var algunValorNegativo = $scope.aCargar.filter(function(p) { |
306 | return p < 0; | 317 | return p < 0; |
307 | }); | 318 | }); |
308 | if(algunValorNegativo.length) { | 319 | if(algunValorNegativo.length) { |
309 | return false; | 320 | return false; |
310 | } | 321 | } |
311 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 322 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
312 | return filter.cargado === true; | 323 | return filter.cargado === true; |
313 | }); | 324 | }); |
314 | if(articulosDescargados.length === $scope.articulos.length) { | 325 | if(articulosDescargados.length === $scope.articulos.length) { |
315 | $scope.aCargar = []; | 326 | $scope.aCargar = []; |
316 | return false; | 327 | return false; |
317 | } | 328 | } |
318 | return true; | 329 | return true; |
319 | }; | 330 | }; |
320 | 331 | ||
321 | $scope.verRemitos = function(data) { | 332 | $scope.verRemitos = function(data) { |
322 | var parametrosModal = { | 333 | var parametrosModal = { |
323 | titulo: 'Remitos cargados', | 334 | titulo: 'Remitos cargados', |
324 | data: data, | 335 | data: data, |
325 | soloMostrar: true, | 336 | soloMostrar: true, |
326 | columnas: [ | 337 | columnas: [ |
327 | { | 338 | { |
328 | nombre: 'Fecha', | 339 | nombre: 'Fecha', |
329 | propiedad: 'fechaRemito', | 340 | propiedad: 'fechaRemito', |
330 | filtro: { | 341 | filtro: { |
331 | nombre: 'date', | 342 | nombre: 'date', |
332 | parametro:'dd/MM/yyyy' | 343 | parametro:'dd/MM/yyyy' |
333 | } | 344 | } |
334 | }, | 345 | }, |
335 | { | 346 | { |
336 | nombre: 'Cliente', | 347 | nombre: 'Cliente', |
337 | propiedad: 'nombreCliente' | 348 | propiedad: 'nombreCliente' |
338 | }, | 349 | }, |
339 | { | 350 | { |
340 | nombre: 'Comprobante', | 351 | nombre: 'Comprobante', |
341 | propiedad: ['sucursal', 'numeroRemito'], | 352 | propiedad: ['sucursal', 'numeroRemito'], |
342 | filtro: { | 353 | filtro: { |
343 | nombre: 'comprobante' | 354 | nombre: 'comprobante' |
344 | } | 355 | } |
345 | }, | 356 | }, |
346 | { | 357 | { |
347 | nombre: 'Importe', | 358 | nombre: 'Importe', |
348 | propiedad: 'total' | 359 | propiedad: 'total' |
349 | } | 360 | } |
350 | ] | 361 | ] |
351 | }; | 362 | }; |
352 | focaModalService.modal(parametrosModal).then(function(transportista) { | 363 | focaModalService.modal(parametrosModal).then(function(transportista) { |
353 | $scope.selectVehiculo(transportista.COD, transportista.NOM); | 364 | $scope.selectVehiculo(transportista.COD, transportista.NOM); |
354 | }); | 365 | }); |
355 | }; | 366 | }; |
356 | function validarCargas(cis, remito) { | 367 | function validarCargas(cis, remito) { |
357 | var result = true; | 368 | var result = true; |
358 | var cisternas = angular.copy(cis); | 369 | var cisternas = angular.copy(cis); |
359 | var articulos = angular.copy(remito.articulosRemito); | 370 | var articulos = angular.copy(remito.articulosRemito); |
360 | 371 | ||
361 | cisternas.sort(ordenarCisternas); | 372 | cisternas.sort(ordenarCisternas); |
362 | 373 | ||
363 | articulos.forEach(function(articulo) { | 374 | articulos.forEach(function(articulo) { |
364 | cisternas.forEach(function(cisterna) { | 375 | cisternas.forEach(function(cisterna) { |
365 | if(!cisterna.cisternaCarga) cisterna.cisternaCarga = {}; | 376 | if(!cisterna.cisternaCarga) cisterna.cisternaCarga = {}; |
366 | //SI LA CISTERNA ESTA VACIA O | 377 | //SI LA CISTERNA ESTA VACIA O |
367 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO | 378 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO |
368 | //Y AUN TIENE LUGAR | 379 | //Y AUN TIENE LUGAR |
369 | if(cisterna.capacidad === cisterna.disponible || | 380 | if(cisterna.capacidad === cisterna.disponible || |
370 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && | 381 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && |
371 | cisterna.disponible > 0)){ | 382 | cisterna.disponible > 0)){ |
372 | var restante = articulo.cantidad - cisterna.disponible; | 383 | var restante = articulo.cantidad - cisterna.disponible; |
373 | 384 | ||
374 | if (restante > 0) { | 385 | if (restante > 0) { |
375 | cisterna.disponible = 0; | 386 | cisterna.disponible = 0; |
376 | articulo.cantidad = restante; | 387 | articulo.cantidad = restante; |
377 | } else { | 388 | } else { |
378 | cisterna.disponible = restante * -1; | 389 | cisterna.disponible = restante * -1; |
379 | articulo.cantidad = 0; | 390 | articulo.cantidad = 0; |
380 | } | 391 | } |
381 | 392 | ||
382 | } | 393 | } |
383 | }); | 394 | }); |
384 | //SI AUN RESTA CANTIDAD EN EL ARTICULO | 395 | //SI AUN RESTA CANTIDAD EN EL ARTICULO |
385 | if (articulo.cantidad > 0) result = false; | 396 | if (articulo.cantidad > 0) result = false; |
386 | }); | 397 | }); |
387 | return result; | 398 | return result; |
388 | } | 399 | } |
389 | function ordenarCisternas(a, b) { | 400 | function ordenarCisternas(a, b) { |
390 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE | 401 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE |
391 | if (a.cisternaCarga && !b.cisternaCarga) { | 402 | if (a.cisternaCarga && !b.cisternaCarga) { |
392 | return -1; | 403 | return -1; |
393 | } else if (!a.cisternaCarga && b.cisternaCarga) { | 404 | } else if (!a.cisternaCarga && b.cisternaCarga) { |
394 | return 1; | 405 | return 1; |
395 | } else { | 406 | } else { |
396 | return 0; | 407 | return 0; |
397 | } | 408 | } |
398 | } | 409 | } |
399 | }]); | 410 | }]); |
400 | 411 |