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