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