Commit 2452de534d32f4a9b55999110f5cf95958d47cf0
1 parent
f5040c914a
Exists in
master
and in
1 other branch
bug's
Showing
2 changed files
with
28 additions
and
9 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 | if(idRemito !== -1) { | 33 | if(idRemito !== -1) { |
33 | promesaRemito = focaModalDetalleCisternasService.obtenerRemitoById(idRemito); | 34 | promesaRemito = focaModalDetalleCisternasService.obtenerRemitoById(idRemito); |
34 | } | 35 | } |
36 | |||
35 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { | 37 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { |
36 | if (idRemito !== -1 && !validarCargas(res[1].data, res[2].data)) { | 38 | if (idRemito !== -1 && !validarCargas(res[1].data, res[2].data)) { |
37 | 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 ' + |
38 | 'vehiculo'; | 40 | 'vehiculo'; |
39 | $uibModalInstance.dismiss(error); | 41 | $uibModalInstance.dismiss(error); |
40 | return; | 42 | return; |
41 | } | 43 | } |
42 | $scope.cargandoDatos = false; | 44 | $scope.cargandoDatos = false; |
43 | $scope.vehiculo = res[0].data; | 45 | $scope.vehiculo = res[0].data; |
44 | $scope.cisternas = res[1].data; | 46 | $scope.cisternas = res[1].data; |
45 | if(!$scope.cisternas.length) { | 47 | if(!$scope.cisternas.length) { |
46 | focaModalService.alert('El vehículo no tiene cisternas'); | 48 | focaModalService.alert('El vehículo no tiene cisternas'); |
47 | $uibModalInstance.dismiss(); | 49 | $uibModalInstance.dismiss(); |
48 | return; | 50 | return; |
49 | } | 51 | } |
50 | if(!res[2]) { | 52 | if(!res[2]) { |
51 | $scope.$digest(); | 53 | $scope.$digest(); |
52 | return; | 54 | return; |
53 | } | 55 | } |
54 | $scope.remito = res[2].data; | 56 | $scope.remito = res[2].data; |
55 | if($scope.remito.idUsuarioProceso) { | 57 | if($scope.remito.idUsuarioProceso) { |
56 | focaModalService.alert('Remito ya asignado'); | 58 | focaModalService.alert('Remito ya asignado'); |
57 | $uibModalInstance.close(); | 59 | $uibModalInstance.close(); |
58 | } | 60 | } |
59 | $scope.articulos = $scope.remito.articulosRemito; | 61 | $scope.articulos = $scope.remito.articulosRemito; |
60 | if(!$scope.articulos.length) { | 62 | if(!$scope.articulos.length) { |
61 | focaModalService.alert('El remito no tiene articulos'); | 63 | focaModalService.alert('El remito no tiene articulos'); |
62 | $uibModalInstance.dismiss(); | 64 | $uibModalInstance.dismiss(); |
63 | return; | 65 | return; |
64 | } | 66 | } |
65 | 67 | ||
66 | $scope.seleccionarArticulo($scope.articulos[0]); | 68 | $scope.seleccionarArticulo($scope.articulos[0]); |
67 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { | 69 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { |
68 | if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { | 70 | if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { |
69 | return cisterna.cisternaCarga.idUsuarioProceso !== | 71 | return cisterna.cisternaCarga.idUsuarioProceso !== |
70 | focaModalDetalleCisternasService.idUsuario; | 72 | focaModalDetalleCisternasService.idUsuario; |
71 | } | 73 | } |
72 | }); | 74 | }); |
73 | if(tieneUsuario.length) { | 75 | if(tieneUsuario.length) { |
74 | focaModalService.alert('Otro usario esta usando este vehículo'); | 76 | focaModalService.alert('Otro usario esta usando este vehículo'); |
75 | $uibModalInstance.close(); | 77 | $uibModalInstance.close(); |
76 | } | 78 | } |
77 | $scope.$digest(); | 79 | $scope.$digest(); |
78 | }); | 80 | }); |
81 | |||
79 | $scope.aceptar = function() { | 82 | $scope.aceptar = function() { |
83 | |||
80 | $scope.cargando = true; | 84 | $scope.cargando = true; |
81 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { | 85 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { |
82 | $scope.cisternasCarga[i].idUsuarioProceso = | 86 | $scope.cisternasCarga[i].idUsuarioProceso = |
83 | focaModalDetalleCisternasService.idUsuario; | 87 | focaModalDetalleCisternasService.idUsuario; |
84 | delete $scope.cisternasCarga[i].articulo; | 88 | delete $scope.cisternasCarga[i].articulo; |
85 | delete $scope.cisternasCarga[i].remitos; | 89 | delete $scope.cisternasCarga[i].remitos; |
86 | } | 90 | } |
91 | |||
87 | var cisterna = { | 92 | var cisterna = { |
88 | cisternaMovimientos: cisternaMovimientos, | 93 | cisternaMovimientos: cisternaMovimientos, |
89 | cisternaCargas: $scope.cisternasCarga, | 94 | cisternaCargas: $scope.cisternasCarga, |
90 | idVehiculo: $scope.vehiculo.id, | 95 | idVehiculo: $scope.vehiculo.id, |
91 | fechaReparto: focaModalDetalleCisternasService.fecha | 96 | fechaReparto: focaModalDetalleCisternasService.fecha |
92 | }; | 97 | }; |
98 | |||
93 | if(!focaModalDetalleCisternasService.idUsuario) { | 99 | if(!focaModalDetalleCisternasService.idUsuario) { |
94 | focaModalService.alert('No logeado como vendedor'); | 100 | focaModalService.alert('No logeado como vendedor'); |
95 | $scope.cargando = false; | 101 | $scope.cargando = false; |
96 | return; | 102 | return; |
97 | } | 103 | } |
104 | |||
98 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) | 105 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) |
99 | .then(function() { | 106 | .then(function() { |
107 | |||
100 | $scope.cargando = false; | 108 | $scope.cargando = false; |
101 | $uibModalInstance.close(); | 109 | $uibModalInstance.close(); |
110 | |||
102 | }).catch(function(error) { | 111 | }).catch(function(error) { |
112 | |||
103 | $scope.cargando = false; | 113 | $scope.cargando = false; |
104 | $uibModalInstance.close(); | 114 | $uibModalInstance.close(); |
115 | |||
105 | if (error.status === 403) { | 116 | if (error.status === 403) { |
106 | focaModalService.alert('ERROR: ' + error.data); | 117 | focaModalService.alert('ERROR: ' + error.data); |
107 | return; | 118 | return; |
108 | } | 119 | } |
120 | |||
109 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 121 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
110 | }); | 122 | }); |
111 | }; | 123 | }; |
124 | |||
112 | $scope.cancelar = function() { | 125 | $scope.cancelar = function() { |
113 | $uibModalInstance.dismiss(); | 126 | $uibModalInstance.dismiss(); |
114 | }; | 127 | }; |
128 | |||
115 | $scope.cargarACisternas = function() { | 129 | $scope.cargarACisternas = function() { |
116 | for(var i = 0; i < $scope.cisternas.length; i++) { | 130 | for(var i = 0; i < $scope.cisternas.length; i++) { |
117 | var cisterna = $scope.cisternas[i]; | 131 | var cisterna = $scope.cisternas[i]; |
118 | var aCargar = parseFloat($scope.aCargar[i]); | 132 | var aCargar = parseFloat($scope.aCargar[i]); |
119 | var fechaReparto = focaModalDetalleCisternasService.fecha; | 133 | var fechaReparto = focaModalDetalleCisternasService.fecha; |
120 | //validaciones | 134 | //validaciones |
121 | if(!aCargar) { | 135 | if(!aCargar || cisterna.disabled) { |
122 | continue; | 136 | continue; |
123 | } | 137 | } |
124 | //cargar | 138 | //cargar |
125 | if(cisterna.cisternaCarga.cantidad) { | 139 | if(cisterna.cisternaCarga.cantidad) { |
126 | cisterna.cisternaCarga.cantidad += aCargar; | 140 | cisterna.cisternaCarga.cantidad += aCargar; |
127 | }else { | 141 | }else { |
128 | cisterna.cisternaCarga.cantidad = aCargar; | 142 | cisterna.cisternaCarga.cantidad = aCargar; |
129 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 143 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
130 | } | 144 | } |
131 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 145 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
132 | 146 | ||
133 | cisterna.cisternaCarga.articulo = { | 147 | cisterna.cisternaCarga.articulo = { |
134 | DetArt: $scope.articuloSeleccionado.descripcion | 148 | DetArt: $scope.articuloSeleccionado.descripcion |
135 | }; | 149 | }; |
136 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 150 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
137 | .cargado = true; | 151 | .cargado = true; |
138 | 152 | ||
139 | $scope.calcularPorcentaje(cisterna); | 153 | $scope.calcularPorcentaje(cisterna); |
140 | //Guardar | 154 | //Guardar |
141 | var now = new Date(); | 155 | var now = new Date(); |
142 | var cisternaMovimiento = { | 156 | var cisternaMovimiento = { |
143 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 157 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
144 | cantidad: aCargar, | 158 | cantidad: aCargar, |
145 | metodo: 'carga', | 159 | metodo: 'carga', |
146 | idCisternaCarga: cisterna.cisternaCarga.id, | 160 | idCisternaCarga: cisterna.cisternaCarga.id, |
147 | idRemito: $scope.remito.id | 161 | idRemito: $scope.remito.id |
148 | }; | 162 | }; |
149 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 163 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
150 | cisterna.cisternaCarga.idCisterna = cisterna.id; | 164 | cisterna.cisternaCarga.idCisterna = cisterna.id; |
151 | $scope.cisternasCarga.push(cisterna.cisternaCarga); | 165 | $scope.cisternasCarga.push(cisterna.cisternaCarga); |
152 | cisternaMovimientos.push(cisternaMovimiento); | 166 | cisternaMovimientos.push(cisternaMovimiento); |
153 | } | 167 | } |
154 | var articuloSiguiente = $scope.articulos.filter( | 168 | var articuloSiguiente = $scope.articulos.filter( |
155 | function(filter) { | 169 | function(filter) { |
156 | return filter.cargado !== true; | 170 | return filter.cargado !== true; |
157 | } | 171 | } |
158 | ); | 172 | ); |
159 | if(articuloSiguiente.length > 0) { | 173 | if(articuloSiguiente.length > 0) { |
160 | $scope.seleccionarArticulo(articuloSiguiente[0]); | 174 | $scope.seleccionarArticulo(articuloSiguiente[0]); |
161 | } | 175 | } |
162 | }; | 176 | }; |
163 | $scope.calcularPorcentaje = function(cisterna) { | 177 | $scope.calcularPorcentaje = function(cisterna) { |
164 | if(!cisterna.cisternaCarga) { | 178 | if(!cisterna.cisternaCarga) { |
165 | cisterna.cisternaCarga = { | 179 | cisterna.cisternaCarga = { |
166 | cantidad: 0 | 180 | cantidad: 0 |
167 | }; | 181 | }; |
168 | } | 182 | } |
169 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 183 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
170 | cisterna.capacidad) + '%'; | 184 | cisterna.capacidad) + '%'; |
171 | var elementHtml = document.getElementById(cisterna.id); | 185 | var elementHtml = document.getElementById(cisterna.id); |
172 | if(elementHtml) { | 186 | if(elementHtml) { |
173 | elementHtml.style.width = porcentaje; | 187 | elementHtml.style.width = porcentaje; |
174 | } | 188 | } |
175 | }; | 189 | }; |
176 | 190 | ||
177 | $scope.seleccionarArticulo = function(articulo) { | 191 | $scope.seleccionarArticulo = function(articulo) { |
178 | $scope.articuloSeleccionado = articulo; | 192 | $scope.articuloSeleccionado = articulo; |
179 | $scope.cisternaDisponible(); | 193 | $scope.cisternaDisponible(); |
180 | $scope.autoCompletar(); | 194 | $scope.autoCompletar(); |
181 | $scope.actualizarArticulo(); | 195 | // $scope.actualizarArticulo(); |
182 | }; | 196 | }; |
183 | 197 | ||
184 | $scope.actualizarArticulo = function() { | 198 | $scope.actualizarArticulo = function() { |
185 | $scope.articuloSeleccionado.cantidadCargada = 0; | 199 | $scope.articuloSeleccionado.cantidadCargada = 0; |
186 | for(var i = 0; i < $scope.aCargar.length; i++) { | 200 | for(var i = 0; i < $scope.aCargar.length; i++) { |
187 | $scope.articuloSeleccionado.cantidadCargada += | 201 | if (!$scope.cisternas[i].disabled) { |
202 | |||
203 | $scope.articuloSeleccionado.cantidadCargada += | ||
188 | parseFloat($scope.aCargar[i]) || 0; | 204 | parseFloat($scope.aCargar[i]) || 0; |
205 | } | ||
189 | } | 206 | } |
190 | }; | 207 | }; |
191 | 208 | ||
192 | $scope.autoCompletar = function() { | 209 | $scope.autoCompletar = function() { |
210 | |||
193 | var arrayMismoProducto = []; | 211 | var arrayMismoProducto = []; |
194 | var arrayVacioProducto = []; | 212 | var arrayVacioProducto = []; |
213 | |||
195 | for(var i = 0; i < $scope.cisternas.length; i++) { | 214 | for(var i = 0; i < $scope.cisternas.length; i++) { |
196 | var cisterna = $scope.cisternas[i]; | 215 | var cisterna = $scope.cisternas[i]; |
197 | cisterna.posicion = i; | 216 | cisterna.posicion = i; |
198 | console.info(i, cisterna.posicion); | 217 | console.info(i, cisterna.posicion); |
199 | if (!cisterna.disabled && cisterna.disponible > 0) { | 218 | if (!cisterna.disabled && cisterna.disponible > 0) { |
200 | if (cisterna.cisternaCarga) { | 219 | if (cisterna.cisternaCarga) { |
201 | arrayMismoProducto.push(cisterna); | 220 | arrayMismoProducto.push(cisterna); |
202 | } else { | 221 | } else { |
203 | arrayVacioProducto.push(cisterna); | 222 | arrayVacioProducto.push(cisterna); |
204 | } | 223 | } |
205 | } | 224 | } |
206 | } | 225 | } |
207 | 226 | ||
208 | arrayMismoProducto.sort(function(a,b) { | 227 | arrayMismoProducto.sort(function(a,b) { |
209 | return a.disponible - b.disponible; | 228 | return a.disponible - b.disponible; |
210 | }); | 229 | }); |
211 | 230 | ||
212 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); | 231 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); |
213 | 232 | ||
214 | for (var j = 0; j < cisternas.length; j++) { | 233 | for (var j = 0; j < cisternas.length; j++) { |
215 | var aCargar = $scope.articuloSeleccionado.cantidad - | 234 | var aCargar = $scope.articuloSeleccionado.cantidad - |
216 | ($scope.articuloSeleccionado.cantidadCargada || 0); | 235 | ($scope.articuloSeleccionado.cantidadCargada || 0); |
217 | 236 | ||
218 | if(aCargar > cisternas[j].disponible) { | 237 | if (aCargar > cisternas[j].disponible) { |
219 | aCargar = cisternas[j].disponible; | 238 | aCargar = cisternas[j].disponible; |
220 | } | 239 | } |
221 | 240 | ||
222 | if(aCargar > 0) { | 241 | if (aCargar > 0) { |
223 | $scope.aCargar[cisternas[j].posicion] = aCargar; | 242 | $scope.aCargar[cisternas[j].posicion] = aCargar; |
224 | $scope.actualizarArticulo(); | 243 | $scope.actualizarArticulo(); |
225 | } | 244 | } |
226 | } | 245 | } |
227 | }; | 246 | }; |
228 | $scope.cisternaDisponible = function() { | 247 | $scope.cisternaDisponible = function() { |
229 | for(var i = 0; i < $scope.cisternas.length; i++) { | 248 | for(var i = 0; i < $scope.cisternas.length; i++) { |
230 | //Puede meter un porcentaje del total | 249 | //Puede meter un porcentaje del total |
231 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { | 250 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { |
232 | // $scope.cisternas[i].disabled = true; | 251 | // $scope.cisternas[i].disabled = true; |
233 | // continue; | 252 | // continue; |
234 | // } | 253 | // } |
235 | if($scope.cisternas[i].cisternaCarga && | 254 | if ($scope.cisternas[i].cisternaCarga && |
236 | $scope.cisternas[i].cisternaCarga.idProducto && | 255 | $scope.cisternas[i].cisternaCarga.idProducto && |
237 | $scope.articuloSeleccionado.idArticulo !== | 256 | $scope.articuloSeleccionado.idArticulo !== |
238 | $scope.cisternas[i].cisternaCarga.idProducto) | 257 | $scope.cisternas[i].cisternaCarga.idProducto) |
239 | { | 258 | { |
240 | $scope.cisternas[i].disabled = true; | 259 | $scope.cisternas[i].disabled = true; |
241 | continue; | 260 | continue; |
242 | } | 261 | } |
243 | $scope.cisternas[i].disabled = false; | 262 | $scope.cisternas[i].disabled = false; |
244 | } | 263 | } |
245 | }; | 264 | }; |
246 | $scope.rellenarInput = function(input, cisterna) { | 265 | $scope.rellenarInput = function(input, cisterna) { |
247 | if(!$scope.articuloSeleccionado) return; | 266 | if(!$scope.articuloSeleccionado) return; |
248 | if($scope.articuloSeleccionado.cantidad - | 267 | if($scope.articuloSeleccionado.cantidad - |
249 | $scope.articuloSeleccionado.cantidadCargada === 0) { | 268 | $scope.articuloSeleccionado.cantidadCargada === 0) { |
250 | return input; | 269 | return input; |
251 | } | 270 | } |
252 | if(!input) input = 0; | 271 | if(!input) input = 0; |
253 | input = parseFloat(input); | 272 | input = parseFloat(input); |
254 | input += parseFloat($scope.articuloSeleccionado.cantidad - | 273 | input += parseFloat($scope.articuloSeleccionado.cantidad - |
255 | $scope.articuloSeleccionado.cantidadCargada); | 274 | $scope.articuloSeleccionado.cantidadCargada); |
256 | if(input <= 0) return; | 275 | if(input <= 0) return; |
257 | if(input > cisterna.disponible) { | 276 | if(input > cisterna.disponible) { |
258 | input = cisterna.disponible; | 277 | input = cisterna.disponible; |
259 | } | 278 | } |
260 | return input; | 279 | return input; |
261 | }; | 280 | }; |
262 | $scope.distribucionDisponible = function() { | 281 | $scope.distribucionDisponible = function() { |
263 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - | 282 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - |
264 | $scope.articuloSeleccionado.cantidadCargada !== 0 || | 283 | $scope.articuloSeleccionado.cantidadCargada !== 0 || |
265 | !$scope.tieneArticulosPendientes()) { | 284 | !$scope.tieneArticulosPendientes()) { |
266 | return false; | 285 | return false; |
267 | } | 286 | } |
268 | for(var i = 0; i < $scope.cisternas.length; i++) { | 287 | for(var i = 0; i < $scope.cisternas.length; i++) { |
269 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { | 288 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { |
270 | return false; | 289 | return false; |
271 | } | 290 | } |
272 | } | 291 | } |
273 | return true; | 292 | return true; |
274 | }; | 293 | }; |
275 | $scope.tieneArticulosPendientes = function() { | 294 | $scope.tieneArticulosPendientes = function() { |
276 | var algunValorNegativo = $scope.aCargar.filter(function(p) { | 295 | var algunValorNegativo = $scope.aCargar.filter(function(p) { |
277 | return p < 0; | 296 | return p < 0; |
278 | }); | 297 | }); |
279 | if(algunValorNegativo.length) { | 298 | if(algunValorNegativo.length) { |
280 | return false; | 299 | return false; |
281 | } | 300 | } |
282 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 301 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
283 | return filter.cargado === true; | 302 | return filter.cargado === true; |
284 | }); | 303 | }); |
285 | if(articulosDescargados.length === $scope.articulos.length) { | 304 | if(articulosDescargados.length === $scope.articulos.length) { |
286 | $scope.aCargar = []; | 305 | $scope.aCargar = []; |
287 | return false; | 306 | return false; |
288 | } | 307 | } |
289 | return true; | 308 | return true; |
290 | }; | 309 | }; |
291 | 310 | ||
292 | $scope.verRemitos = function(data) { | 311 | $scope.verRemitos = function(data) { |
293 | var parametrosModal = { | 312 | var parametrosModal = { |
294 | titulo: 'Remitos cargados', | 313 | titulo: 'Remitos cargados', |
295 | data: data, | 314 | data: data, |
296 | soloMostrar: true, | 315 | soloMostrar: true, |
297 | columnas: [ | 316 | columnas: [ |
298 | { | 317 | { |
299 | nombre: 'Fecha', | 318 | nombre: 'Fecha', |
300 | propiedad: 'fechaRemito', | 319 | propiedad: 'fechaRemito', |
301 | filtro: { | 320 | filtro: { |
302 | nombre: 'date', | 321 | nombre: 'date', |
303 | parametro:'dd/MM/yyyy' | 322 | parametro:'dd/MM/yyyy' |
304 | } | 323 | } |
305 | }, | 324 | }, |
306 | { | 325 | { |
307 | nombre: 'Cliente', | 326 | nombre: 'Cliente', |
308 | propiedad: 'nombreCliente' | 327 | propiedad: 'nombreCliente' |
309 | }, | 328 | }, |
310 | { | 329 | { |
311 | nombre: 'Comprobante', | 330 | nombre: 'Comprobante', |
312 | propiedad: ['sucursal', 'numeroRemito'], | 331 | propiedad: ['sucursal', 'numeroRemito'], |
313 | filtro: { | 332 | filtro: { |
314 | nombre: 'comprobante' | 333 | nombre: 'comprobante' |
315 | } | 334 | } |
316 | }, | 335 | }, |
317 | { | 336 | { |
318 | nombre: 'Importe', | 337 | nombre: 'Importe', |
319 | propiedad: 'total' | 338 | propiedad: 'total' |
320 | } | 339 | } |
321 | ] | 340 | ] |
322 | }; | 341 | }; |
323 | focaModalService.modal(parametrosModal).then(function(transportista) { | 342 | focaModalService.modal(parametrosModal).then(function(transportista) { |
324 | $scope.selectVehiculo(transportista.COD, transportista.NOM); | 343 | $scope.selectVehiculo(transportista.COD, transportista.NOM); |
325 | }); | 344 | }); |
326 | }; | 345 | }; |
327 | function validarCargas(cis, remito) { | 346 | function validarCargas(cis, remito) { |
328 | var result = true; | 347 | var result = true; |
329 | var cisternas = angular.copy(cis); | 348 | var cisternas = angular.copy(cis); |
330 | var articulos = angular.copy(remito.articulosRemito); | 349 | var articulos = angular.copy(remito.articulosRemito); |
331 | 350 | ||
332 | cisternas.sort(ordenarCisternas); | 351 | cisternas.sort(ordenarCisternas); |
333 | 352 | ||
334 | articulos.forEach(function(articulo) { | 353 | articulos.forEach(function(articulo) { |
335 | cisternas.forEach(function(cisterna) { | 354 | cisternas.forEach(function(cisterna) { |
336 | if(!cisterna.cisternaCarga) cisterna.cisternaCarga = {}; | 355 | if(!cisterna.cisternaCarga) cisterna.cisternaCarga = {}; |
337 | //SI LA CISTERNA ESTA VACIA O | 356 | //SI LA CISTERNA ESTA VACIA O |
338 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO | 357 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO |
339 | //Y AUN TIENE LUGAR | 358 | //Y AUN TIENE LUGAR |
340 | if(cisterna.capacidad === cisterna.disponible || | 359 | if(cisterna.capacidad === cisterna.disponible || |
341 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && | 360 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && |
342 | cisterna.disponible > 0)){ | 361 | cisterna.disponible > 0)){ |
343 | var restante = articulo.cantidad - cisterna.disponible; | 362 | var restante = articulo.cantidad - cisterna.disponible; |
344 | 363 | ||
345 | if (restante > 0) { | 364 | if (restante > 0) { |
346 | cisterna.disponible = 0; | 365 | cisterna.disponible = 0; |
347 | articulo.cantidad = restante; | 366 | articulo.cantidad = restante; |
348 | } else { | 367 | } else { |
349 | cisterna.disponible = restante * -1; | 368 | cisterna.disponible = restante * -1; |
350 | articulo.cantidad = 0; | 369 | articulo.cantidad = 0; |
351 | } | 370 | } |
352 | 371 | ||
353 | } | 372 | } |
354 | }); | 373 | }); |
355 | //SI AUN RESTA CANTIDAD EN EL ARTICULO | 374 | //SI AUN RESTA CANTIDAD EN EL ARTICULO |
356 | if (articulo.cantidad > 0) result = false; | 375 | if (articulo.cantidad > 0) result = false; |
357 | }); | 376 | }); |
358 | return result; | 377 | return result; |
359 | } | 378 | } |
360 | function ordenarCisternas(a, b) { | 379 | function ordenarCisternas(a, b) { |
361 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE | 380 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE |
362 | if (a.cisternaCarga && !b.cisternaCarga) { | 381 | if (a.cisternaCarga && !b.cisternaCarga) { |
363 | return -1; | 382 | return -1; |
364 | } else if (!a.cisternaCarga && b.cisternaCarga) { | 383 | } else if (!a.cisternaCarga && b.cisternaCarga) { |
365 | return 1; | 384 | return 1; |
366 | } else { | 385 | } else { |
367 | return 0; | 386 | return 0; |
368 | } | 387 | } |
369 | } | 388 | } |
370 | }]); | 389 | }]); |
371 | 390 |
src/views/foca-detalle-vehiculo.html
1 | <div class="modal-header"> | 1 | <div class="modal-header"> |
2 | <h4>Detalle de carga</h4> | 2 | <h4>Detalle de carga</h4> |
3 | Transportista | 3 | Transportista |
4 | <strong ng-bind="vehiculo.transportista.COD"></strong> | 4 | <strong ng-bind="vehiculo.transportista.COD"></strong> |
5 | <strong ng-bind="vehiculo.transportista.NOM"></strong> | 5 | <strong ng-bind="vehiculo.transportista.NOM"></strong> |
6 | Unidad <strong ng-bind="vehiculo.codigo"></strong> | 6 | Unidad <strong ng-bind="vehiculo.codigo"></strong> |
7 | Tractor <strong ng-bind="vehiculo.tractor"></strong> | 7 | Tractor <strong ng-bind="vehiculo.tractor"></strong> |
8 | <br> | 8 | <br> |
9 | <div ng-show="idRemito !== -1"> | 9 | <div ng-show="idRemito !== -1"> |
10 | <span>Remito Nº</span> | 10 | <span>Remito Nº</span> |
11 | <strong ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></strong> | 11 | <strong ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></strong> |
12 | <span>, Fecha</span> | 12 | <span>, Fecha</span> |
13 | <strong ng-bind="remito.fechaRemito | date: 'dd/MM/yyyy HH:mm'"></strong> | 13 | <strong ng-bind="remito.fechaRemito | date: 'dd/MM/yyyy HH:mm'"></strong> |
14 | <span>, Cliente</span> | 14 | <span>, Cliente</span> |
15 | <strong ng-bind="remito.nombreCliente"></strong> | 15 | <strong ng-bind="remito.nombreCliente"></strong> |
16 | <span>, Domicilio entrega</span> | 16 | <span>, Domicilio entrega</span> |
17 | <strong ng-bind="remito.domicilioStamp"></strong> | 17 | <strong ng-bind="remito.domicilioStamp"></strong> |
18 | </div> | 18 | </div> |
19 | </div> | 19 | </div> |
20 | <div class="modal-body"> | 20 | <div class="modal-body"> |
21 | <div> | 21 | <div> |
22 | <table class="table table-sm" ng-show="idRemito !== -1"> | 22 | <table class="table table-sm" ng-show="idRemito !== -1"> |
23 | <thead> | 23 | <thead> |
24 | <tr> | 24 | <tr> |
25 | <th></th> | 25 | <th></th> |
26 | <th>Articulo</th> | 26 | <th>Articulo</th> |
27 | <th>Cantidad</th> | 27 | <th>Cantidad</th> |
28 | <th>Cargado</th> | 28 | <th>Cargado</th> |
29 | <th>Resta asignar</th> | 29 | <th>Resta asignar</th> |
30 | </tr> | 30 | </tr> |
31 | </thead> | 31 | </thead> |
32 | <tbody> | 32 | <tbody> |
33 | <tr ng-repeat="(key, articulo) in articulos"> | 33 | <tr ng-repeat="(key, articulo) in articulos"> |
34 | <td><input | 34 | <td><input |
35 | type="radio" | 35 | type="radio" |
36 | name="articuloRadio" | 36 | name="articuloRadio" |
37 | id="{{'articulo' + articulo.id}}" | 37 | id="{{'articulo' + articulo.id}}" |
38 | ng-checked="articuloSeleccionado.id === articulo.id" | 38 | ng-checked="articuloSeleccionado.id === articulo.id" |
39 | ng-disabled="articulo.cargado" | 39 | ng-disabled="articulo.cargado" |
40 | ng-click="seleccionarArticulo(articulo)" | 40 | ng-click="seleccionarArticulo(articulo)" |
41 | ></td> | 41 | ></td> |
42 | <td ng-bind="articulo.descripcion"></td> | 42 | <td ng-bind="articulo.descripcion"></td> |
43 | <td ng-bind="articulo.cantidad"></td> | 43 | <td ng-bind="articulo.cantidad"></td> |
44 | <td ng-bind="articulo.cantidadCargada || 0"></td> | 44 | <td ng-bind="articulo.cantidadCargada || 0"></td> |
45 | <td ng-bind="articulo.cantidad - articulo.cantidadCargada"></td> | 45 | <td ng-bind="articulo.cantidad - articulo.cantidadCargada"></td> |
46 | </tr> | 46 | </tr> |
47 | </tbody> | 47 | </tbody> |
48 | </table> | 48 | </table> |
49 | <table class="table table-sm" ladda="cargandoDatos" data-spinner-color="#FF0000"> | 49 | <table class="table table-sm" ladda="cargandoDatos" data-spinner-color="#FF0000"> |
50 | <thead> | 50 | <thead> |
51 | <tr> | 51 | <tr> |
52 | <th width="10%">Cisterna</th> | 52 | <th width="10%">Cisterna</th> |
53 | <th>Capacidad</th> | 53 | <th>Capacidad</th> |
54 | <th>Articulo cargado</th> | 54 | <th>Articulo cargado</th> |
55 | <th width="20%">Por asignar</th> | 55 | <th width="20%">Por asignar</th> |
56 | <th>Cargado / Capacidad Disponible</th> | 56 | <th>Cargado / Capacidad Disponible</th> |
57 | <th></th> | 57 | <th></th> |
58 | </tr> | 58 | </tr> |
59 | </thead> | 59 | </thead> |
60 | <tbody> | 60 | <tbody> |
61 | <tr ng-repeat="(key, cisterna) in cisternas"> | 61 | <tr ng-repeat="(key, cisterna) in cisternas"> |
62 | <td class="py-3" ng-bind="cisterna.codigo"></td> | 62 | <td class="py-3" ng-bind="cisterna.codigo"></td> |
63 | <td class="py-3" ng-bind="cisterna.capacidad"></td> | 63 | <td class="py-3" ng-bind="cisterna.capacidad"></td> |
64 | <td class="py-3" ng-bind="cisterna.cisternaCarga.articulo.DetArt || 'Sin asignar'"></td> | 64 | <td class="py-3" ng-bind="cisterna.cisternaCarga.articulo.DetArt || 'Sin asignar'"></td> |
65 | <td ng-if="idRemito != -1"> | 65 | <td ng-if="idRemito != -1"> |
66 | <input | 66 | <input |
67 | class="form-control" | 67 | class="form-control" |
68 | foca-tipo-input | 68 | foca-tipo-input |
69 | foca-teclado | 69 | foca-teclado |
70 | placeholder="A cargar..." | 70 | placeholder="A cargar..." |
71 | ng-model="aCargar[key]" | 71 | ng-model="aCargar[key]" |
72 | ng-disabled="cisterna.disabled || !tieneArticulosPendientes()" | 72 | ng-disabled="cisterna.disabled || !tieneArticulosPendientes()" |
73 | ng-focus="aCargar[key] = rellenarInput(aCargar[key], cisterna); actualizarArticulo()" | 73 | ng-focus="aCargar[key] = rellenarInput(aCargar[key], cisterna); actualizarArticulo()" |
74 | ng-change="actualizarArticulo()" | 74 | ng-change="actualizarArticulo()" |
75 | > | 75 | > |
76 | </td> | 76 | </td> |
77 | <td ng-if="idRemito == -1"> | 77 | <td ng-if="idRemito == -1"> |
78 | <input | 78 | <input |
79 | class="form-control" | 79 | class="form-control" |
80 | placeholder="A cargar..." | 80 | placeholder="A cargar..." |
81 | readonly> | 81 | readonly> |
82 | </td> | 82 | </td> |
83 | <td><div class="progress foca-alto-progress pl-0 pr-0 mt-1"> | 83 | <td><div class="progress foca-alto-progress pl-0 pr-0 mt-1"> |
84 | <strong | 84 | <strong |
85 | class="mt-2 col-4 text-center position-absolute" | 85 | class="mt-2 col-4 text-center position-absolute" |
86 | ng-bind="(cisterna.cisternaCarga.cantidad || 0) + '/' + | 86 | ng-bind="(cisterna.cisternaCarga.cantidad || 0) + '/' + |
87 | (cisterna.capacidad - cisterna.cisternaCarga.cantidad)"> | 87 | (cisterna.capacidad - cisterna.cisternaCarga.cantidad)"> |
88 | </strong> | 88 | </strong> |
89 | <div | 89 | <div |
90 | id="{{cisterna.id}}" | 90 | id="{{cisterna.id}}" |
91 | class="progress-bar" | 91 | class="progress-bar" |
92 | role="progressbar" | 92 | role="progressbar" |
93 | aria-valuemin="0" | 93 | aria-valuemin="0" |
94 | aria-valuemax="{{cisterna.capacidad}}" | 94 | aria-valuemax="{{cisterna.capacidad}}" |
95 | ng-style="{'width':'{{calcularPorcentaje(cisterna)}}'}"> | 95 | ng-style="{'width':'{{calcularPorcentaje(cisterna)}}'}"> |
96 | </div> | 96 | </div> |
97 | </div> | 97 | </div> |
98 | </td> | 98 | </td> |
99 | <td> | 99 | <td> |
100 | <button | 100 | <button |
101 | class="btn btn-outline-secondary" | 101 | class="btn btn-outline-secondary" |
102 | ng-disabled="!cisterna.cisternaCarga.remitos.length" | 102 | ng-disabled="!cisterna.cisternaCarga.remitos.length" |
103 | ng-click="verRemitos(cisterna.cisternaCarga.remitos)"> | 103 | ng-click="verRemitos(cisterna.cisternaCarga.remitos)"> |
104 | <i class="fa fa-info" aria-hidden="true"></i> | 104 | <i class="fa fa-eye" aria-hidden="true"></i> |
105 | </button> | 105 | </button> |
106 | </td> | 106 | </td> |
107 | </tr> | 107 | </tr> |
108 | </tbody> | 108 | </tbody> |
109 | </table> | 109 | </table> |
110 | <div class="col-12"> | 110 | <div class="col-12"> |
111 | <button | 111 | <button |
112 | class="form-control btn btn-success" | 112 | class="form-control btn btn-success" |
113 | ladda="cargando" | 113 | ladda="cargando" |
114 | data-spinner-color="#FF0000" | 114 | data-spinner-color="#FF0000" |
115 | type="button" | 115 | type="button" |
116 | ng-disabled="!distribucionDisponible()" | 116 | ng-disabled="!distribucionDisponible()" |
117 | ng-class="{'btn-light': !distribucionDisponible()}" | 117 | ng-class="{'btn-light': !distribucionDisponible()}" |
118 | ng-click="cargarACisternas(vehiculo)" | 118 | ng-click="cargarACisternas(vehiculo)" |
119 | foca-focus="distribucionDisponible()"> | 119 | foca-focus="distribucionDisponible()"> |
120 | Aplicar distribución de cargas | 120 | Aplicar distribución de cargas |
121 | </button> | 121 | </button> |
122 | </div> | 122 | </div> |
123 | </div> | 123 | </div> |
124 | </div> | 124 | </div> |
125 | <div class="modal-footer py-1"> | 125 | <div class="modal-footer py-1"> |
126 | <button | 126 | <button |
127 | class="btn btn-sm btn-secondary" | 127 | class="btn btn-sm btn-secondary" |
128 | ladda="cargando" | 128 | ladda="cargando" |
129 | type="button" | 129 | type="button" |
130 | ng-click="cancelar()">Cancelar</button> | 130 | ng-click="cancelar()">Cancelar</button> |
131 | <button | 131 | <button |
132 | class="btn btn-sm btn-primary" | 132 | class="btn btn-sm btn-primary" |
133 | ladda="cargando" | 133 | ladda="cargando" |
134 | type="button" | 134 | type="button" |
135 | ng-click="aceptar()" | 135 | ng-click="aceptar()" |
136 | ng-disabled="tieneArticulosPendientes() || idRemito === -1" | 136 | ng-disabled="tieneArticulosPendientes() || idRemito === -1" |
137 | foca-focus="!tieneArticulosPendientes() && idRemito !== -1">Cargar</button> | 137 | foca-focus="!tieneArticulosPendientes() && idRemito !== -1">Cargar</button> |
138 | </div> | 138 | </div> |
139 | 139 |