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