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