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