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