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