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