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