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