Commit ee3db70dc07f57d9a7223c3c2920cb7a57af9397
1 parent
60f20692e0
Exists in
master
fix
Showing
1 changed file
with
1 additions
and
0 deletions
Show diff stats
src/js/controllerDetalleVehiculo.js
1 | angular.module('focaLogisticaPedidoRuta') | 1 | angular.module('focaLogisticaPedidoRuta') |
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 | 'focaLogisticaPedidoRutaService', | 9 | 'focaLogisticaPedidoRutaService', |
10 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, | 10 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, |
11 | focaLogisticaPedidoRutaService | 11 | focaLogisticaPedidoRutaService |
12 | ) { | 12 | ) { |
13 | //seteo variables | 13 | //seteo variables |
14 | $scope.cargandoDatos = true; | 14 | $scope.cargandoDatos = true; |
15 | $scope.idRemito = idRemito; | 15 | $scope.idRemito = idRemito; |
16 | $scope.articulos = []; | 16 | $scope.articulos = []; |
17 | $scope.vehiculo = {}; | 17 | $scope.vehiculo = {}; |
18 | $scope.cisternas = []; | 18 | $scope.cisternas = []; |
19 | $scope.cisternasCarga = []; | 19 | $scope.cisternasCarga = []; |
20 | $scope.remito = {}; | 20 | $scope.remito = {}; |
21 | $scope.aCargar = []; | 21 | $scope.aCargar = []; |
22 | var cisternaMovimientos = []; | 22 | var cisternaMovimientos = []; |
23 | var promesaRemito; | 23 | var promesaRemito; |
24 | var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); | 24 | var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); |
25 | var promesaCisternas = focaLogisticaPedidoRutaService | 25 | var promesaCisternas = focaLogisticaPedidoRutaService |
26 | .obtenerCisternasPorFecha(idVehiculo); | 26 | .obtenerCisternasPorFecha(idVehiculo); |
27 | if(idRemito !== -1) { | 27 | if(idRemito !== -1) { |
28 | promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); | 28 | promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); |
29 | } | 29 | } |
30 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { | 30 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { |
31 | $scope.cargandoDatos = false; | 31 | $scope.cargandoDatos = false; |
32 | $scope.vehiculo = res[0].data; | 32 | $scope.vehiculo = res[0].data; |
33 | $scope.cisternas = res[1].data; | 33 | $scope.cisternas = res[1].data; |
34 | if(!res[2]) return; | 34 | if(!res[2]) return; |
35 | $scope.remito = res[2].data; | 35 | $scope.remito = res[2].data; |
36 | if($scope.remito.idUsuarioProceso) { | 36 | if($scope.remito.idUsuarioProceso) { |
37 | focaModalService.alert('Remito ya asignado'); | 37 | focaModalService.alert('Remito ya asignado'); |
38 | $uibModalInstance.close(); | 38 | $uibModalInstance.close(); |
39 | } | 39 | } |
40 | $scope.articulos = $scope.remito.articulosRemito; | 40 | $scope.articulos = $scope.remito.articulosRemito; |
41 | $scope.seleccionarArticulo($scope.articulos[0]); | 41 | $scope.seleccionarArticulo($scope.articulos[0]); |
42 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { | 42 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { |
43 | if(cisterna.cisternaCarga) { | 43 | if(cisterna.cisternaCarga) { |
44 | return cisterna.cisternaCarga.idUsuarioProceso !== | 44 | return cisterna.cisternaCarga.idUsuarioProceso !== |
45 | focaLogisticaPedidoRutaService.idUsuario; | 45 | focaLogisticaPedidoRutaService.idUsuario; |
46 | } | 46 | } |
47 | }); | 47 | }); |
48 | if(tieneUsuario.length) { | 48 | if(tieneUsuario.length) { |
49 | focaModalService.alert('Otro usario esta usando este vehículo'); | 49 | focaModalService.alert('Otro usario esta usando este vehículo'); |
50 | $uibModalInstance.close(); | 50 | $uibModalInstance.close(); |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | $scope.$digest(); | ||
53 | }); | 54 | }); |
54 | $scope.aceptar = function() { | 55 | $scope.aceptar = function() { |
55 | $scope.cargando = true; | 56 | $scope.cargando = true; |
56 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { | 57 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { |
57 | $scope.cisternasCarga[i].idUsuarioProceso = | 58 | $scope.cisternasCarga[i].idUsuarioProceso = |
58 | focaLogisticaPedidoRutaService.idUsuario; | 59 | focaLogisticaPedidoRutaService.idUsuario; |
59 | delete $scope.cisternasCarga[i].articulo; | 60 | delete $scope.cisternasCarga[i].articulo; |
60 | } | 61 | } |
61 | var cisterna = { | 62 | var cisterna = { |
62 | cisternaMovimientos: cisternaMovimientos, | 63 | cisternaMovimientos: cisternaMovimientos, |
63 | cisternaCargas: $scope.cisternasCarga, | 64 | cisternaCargas: $scope.cisternasCarga, |
64 | idVehiculo: $scope.vehiculo.id, | 65 | idVehiculo: $scope.vehiculo.id, |
65 | fechaReparto: focaLogisticaPedidoRutaService.fecha | 66 | fechaReparto: focaLogisticaPedidoRutaService.fecha |
66 | }; | 67 | }; |
67 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) | 68 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) |
68 | .then(function() { | 69 | .then(function() { |
69 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { | 70 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { |
70 | $scope.cargando = false; | 71 | $scope.cargando = false; |
71 | $uibModalInstance.close(); | 72 | $uibModalInstance.close(); |
72 | }); | 73 | }); |
73 | }).catch(function(error) { | 74 | }).catch(function(error) { |
74 | $scope.cargando = false; | 75 | $scope.cargando = false; |
75 | $uibModalInstance.close(); | 76 | $uibModalInstance.close(); |
76 | if (error.status === 403) { | 77 | if (error.status === 403) { |
77 | focaModalService.alert('ERROR: ' + error.data); | 78 | focaModalService.alert('ERROR: ' + error.data); |
78 | return; | 79 | return; |
79 | } | 80 | } |
80 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 81 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
81 | }); | 82 | }); |
82 | }; | 83 | }; |
83 | $scope.cancelar = function() { | 84 | $scope.cancelar = function() { |
84 | $uibModalInstance.close(); | 85 | $uibModalInstance.close(); |
85 | }; | 86 | }; |
86 | $scope.cargarACisternas = function() { | 87 | $scope.cargarACisternas = function() { |
87 | for(var i = 0; i < $scope.cisternas.length; i++) { | 88 | for(var i = 0; i < $scope.cisternas.length; i++) { |
88 | var cisterna = $scope.cisternas[i]; | 89 | var cisterna = $scope.cisternas[i]; |
89 | var aCargar = parseFloat($scope.aCargar[i]); | 90 | var aCargar = parseFloat($scope.aCargar[i]); |
90 | var fechaReparto = focaLogisticaPedidoRutaService.fecha; | 91 | var fechaReparto = focaLogisticaPedidoRutaService.fecha; |
91 | //validaciones | 92 | //validaciones |
92 | if(!aCargar) { | 93 | if(!aCargar) { |
93 | continue; | 94 | continue; |
94 | } | 95 | } |
95 | //cargar | 96 | //cargar |
96 | if(cisterna.cisternaCarga.cantidad) { | 97 | if(cisterna.cisternaCarga.cantidad) { |
97 | cisterna.cisternaCarga.cantidad += aCargar; | 98 | cisterna.cisternaCarga.cantidad += aCargar; |
98 | }else { | 99 | }else { |
99 | cisterna.cisternaCarga.cantidad = aCargar; | 100 | cisterna.cisternaCarga.cantidad = aCargar; |
100 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 101 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
101 | } | 102 | } |
102 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 103 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
103 | 104 | ||
104 | cisterna.cisternaCarga.articulo = { | 105 | cisterna.cisternaCarga.articulo = { |
105 | DetArt: $scope.articuloSeleccionado.descripcion | 106 | DetArt: $scope.articuloSeleccionado.descripcion |
106 | }; | 107 | }; |
107 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 108 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
108 | .cargado = true; | 109 | .cargado = true; |
109 | 110 | ||
110 | $scope.calcularPorcentaje(cisterna); | 111 | $scope.calcularPorcentaje(cisterna); |
111 | //Guardar | 112 | //Guardar |
112 | var now = new Date(); | 113 | var now = new Date(); |
113 | var cisternaMovimiento = { | 114 | var cisternaMovimiento = { |
114 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 115 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
115 | cantidad: aCargar, | 116 | cantidad: aCargar, |
116 | metodo: 'carga', | 117 | metodo: 'carga', |
117 | idCisternaCarga: cisterna.cisternaCarga.id, | 118 | idCisternaCarga: cisterna.cisternaCarga.id, |
118 | idRemito: $scope.remito.id | 119 | idRemito: $scope.remito.id |
119 | }; | 120 | }; |
120 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 121 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
121 | cisterna.cisternaCarga.idCisterna = cisterna.id; | 122 | cisterna.cisternaCarga.idCisterna = cisterna.id; |
122 | $scope.cisternasCarga.push(cisterna.cisternaCarga); | 123 | $scope.cisternasCarga.push(cisterna.cisternaCarga); |
123 | cisternaMovimientos.push(cisternaMovimiento); | 124 | cisternaMovimientos.push(cisternaMovimiento); |
124 | } | 125 | } |
125 | var articuloSiguiente = $scope.articulos.filter( | 126 | var articuloSiguiente = $scope.articulos.filter( |
126 | function(filter) { | 127 | function(filter) { |
127 | return filter.cargado !== true; | 128 | return filter.cargado !== true; |
128 | } | 129 | } |
129 | ); | 130 | ); |
130 | if(articuloSiguiente.length > 0) { | 131 | if(articuloSiguiente.length > 0) { |
131 | $scope.seleccionarArticulo(articuloSiguiente[0]); | 132 | $scope.seleccionarArticulo(articuloSiguiente[0]); |
132 | } | 133 | } |
133 | }; | 134 | }; |
134 | $scope.calcularPorcentaje = function(cisterna) { | 135 | $scope.calcularPorcentaje = function(cisterna) { |
135 | if(!cisterna.cisternaCarga) { | 136 | if(!cisterna.cisternaCarga) { |
136 | cisterna.cisternaCarga = { | 137 | cisterna.cisternaCarga = { |
137 | cantidad: 0 | 138 | cantidad: 0 |
138 | }; | 139 | }; |
139 | } | 140 | } |
140 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 141 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
141 | cisterna.capacidad) + '%'; | 142 | cisterna.capacidad) + '%'; |
142 | var elementHtml = document.getElementById(cisterna.id); | 143 | var elementHtml = document.getElementById(cisterna.id); |
143 | if(elementHtml) { | 144 | if(elementHtml) { |
144 | elementHtml.style.width = porcentaje; | 145 | elementHtml.style.width = porcentaje; |
145 | } | 146 | } |
146 | }; | 147 | }; |
147 | $scope.seleccionarArticulo = function(articulo) { | 148 | $scope.seleccionarArticulo = function(articulo) { |
148 | $scope.articuloSeleccionado = articulo; | 149 | $scope.articuloSeleccionado = articulo; |
149 | $scope.cisternaDisponible(); | 150 | $scope.cisternaDisponible(); |
150 | $scope.autoCompletar(); | 151 | $scope.autoCompletar(); |
151 | $scope.actualizarArticulo(); | 152 | $scope.actualizarArticulo(); |
152 | }; | 153 | }; |
153 | $scope.actualizarArticulo = function () { | 154 | $scope.actualizarArticulo = function () { |
154 | $scope.articuloSeleccionado.cantidadCargada = 0; | 155 | $scope.articuloSeleccionado.cantidadCargada = 0; |
155 | for (var i = 0; i < $scope.aCargar.length; i++) { | 156 | for (var i = 0; i < $scope.aCargar.length; i++) { |
156 | $scope.articuloSeleccionado.cantidadCargada += | 157 | $scope.articuloSeleccionado.cantidadCargada += |
157 | parseFloat($scope.aCargar[i]) || 0; | 158 | parseFloat($scope.aCargar[i]) || 0; |
158 | } | 159 | } |
159 | }; | 160 | }; |
160 | $scope.autoCompletar = function() { | 161 | $scope.autoCompletar = function() { |
161 | $scope.aCargar = []; | 162 | $scope.aCargar = []; |
162 | var disponible = $filter('filter')($scope.cisternas, {disabled: false}); | 163 | var disponible = $filter('filter')($scope.cisternas, {disabled: false}); |
163 | var index = $scope.cisternas.indexOf(disponible[0]); | 164 | var index = $scope.cisternas.indexOf(disponible[0]); |
164 | $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; | 165 | $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; |
165 | }; | 166 | }; |
166 | $scope.cisternaDisponible = function() { | 167 | $scope.cisternaDisponible = function() { |
167 | for(var i = 0; i < $scope.cisternas.length; i++) { | 168 | for(var i = 0; i < $scope.cisternas.length; i++) { |
168 | if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { | 169 | if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { |
169 | $scope.cisternas[i].disabled = true; | 170 | $scope.cisternas[i].disabled = true; |
170 | continue; | 171 | continue; |
171 | } | 172 | } |
172 | if($scope.cisternas[i].cisternaCarga && | 173 | if($scope.cisternas[i].cisternaCarga && |
173 | $scope.cisternas[i].cisternaCarga.idProducto && | 174 | $scope.cisternas[i].cisternaCarga.idProducto && |
174 | $scope.articuloSeleccionado.idArticulo !== | 175 | $scope.articuloSeleccionado.idArticulo !== |
175 | $scope.cisternas[i].cisternaCarga.idProducto) | 176 | $scope.cisternas[i].cisternaCarga.idProducto) |
176 | { | 177 | { |
177 | $scope.cisternas[i].disabled = true; | 178 | $scope.cisternas[i].disabled = true; |
178 | continue; | 179 | continue; |
179 | } | 180 | } |
180 | $scope.cisternas[i].disabled = false; | 181 | $scope.cisternas[i].disabled = false; |
181 | } | 182 | } |
182 | }; | 183 | }; |
183 | $scope.rellenarInput = function(input) { | 184 | $scope.rellenarInput = function(input) { |
184 | if(!$scope.articuloSeleccionado) return; | 185 | if(!$scope.articuloSeleccionado) return; |
185 | if($scope.articuloSeleccionado.cantidad - | 186 | if($scope.articuloSeleccionado.cantidad - |
186 | $scope.articuloSeleccionado.cantidadCargada === 0) { | 187 | $scope.articuloSeleccionado.cantidadCargada === 0) { |
187 | return input; | 188 | return input; |
188 | } | 189 | } |
189 | if(!input) input = 0; | 190 | if(!input) input = 0; |
190 | input = parseFloat(input); | 191 | input = parseFloat(input); |
191 | input += parseFloat($scope.articuloSeleccionado.cantidad - | 192 | input += parseFloat($scope.articuloSeleccionado.cantidad - |
192 | $scope.articuloSeleccionado.cantidadCargada); | 193 | $scope.articuloSeleccionado.cantidadCargada); |
193 | return input; | 194 | return input; |
194 | }; | 195 | }; |
195 | $scope.distribucionDisponible = function() { | 196 | $scope.distribucionDisponible = function() { |
196 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - | 197 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - |
197 | $scope.articuloSeleccionado.cantidadCargada !== 0 || | 198 | $scope.articuloSeleccionado.cantidadCargada !== 0 || |
198 | !$scope.tieneArticulosPendientes()) { | 199 | !$scope.tieneArticulosPendientes()) { |
199 | return false; | 200 | return false; |
200 | } | 201 | } |
201 | return true; | 202 | return true; |
202 | }; | 203 | }; |
203 | $scope.tieneArticulosPendientes = function() { | 204 | $scope.tieneArticulosPendientes = function() { |
204 | var algunValorNegativo = $scope.aCargar.filter(function(p) { | 205 | var algunValorNegativo = $scope.aCargar.filter(function(p) { |
205 | return p < 0; | 206 | return p < 0; |
206 | }); | 207 | }); |
207 | if(algunValorNegativo.length) { | 208 | if(algunValorNegativo.length) { |
208 | return false; | 209 | return false; |
209 | } | 210 | } |
210 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 211 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
211 | return filter.cargado === true; | 212 | return filter.cargado === true; |
212 | }); | 213 | }); |
213 | if(articulosDescargados.length === $scope.articulos.length) { | 214 | if(articulosDescargados.length === $scope.articulos.length) { |
214 | $scope.aCargar = []; | 215 | $scope.aCargar = []; |
215 | return false; | 216 | return false; |
216 | } | 217 | } |
217 | return true; | 218 | return true; |
218 | }; | 219 | }; |
219 | }]); | 220 | }]); |
220 | 221 |