Commit 5ba7a885b0beefb4c099ed528f0dd852db723297
1 parent
bde16601c2
Exists in
master
Codigo reordenado.
Showing
1 changed file
with
61 additions
and
97 deletions
Show diff stats
src/js/controller.js
1 | 1 | angular.module('focaModalDetalleHojaRuta') |
2 | - .controller('focaModalDetalleHojaRutaController', | |
2 | + .controller('focaModalDetalleHojaRutaController', | |
3 | 3 | [ |
4 | - '$filter', | |
5 | - '$scope', | |
6 | - '$uibModalInstance', | |
7 | - 'parametros', | |
8 | - 'focaModalDetalleHojaRutaService', | |
9 | - 'focaModalService', | |
10 | - 'focaSeguimientoService', | |
11 | - '$uibModal', | |
12 | - function($filter, $scope, $uibModalInstance, parametros, focaModalDetalleHojaRutaService, | |
13 | - focaModalService, focaSeguimientoService, $uibModal) | |
14 | - { | |
15 | - //Seteo variables | |
4 | + '$filter', '$scope', '$uibModalInstance', 'parametros', 'focaModalDetalleHojaRutaService', | |
5 | + 'focaModalService', 'focaSeguimientoService', '$uibModal', | |
6 | + function ($filter, $scope, $uibModalInstance, parametros, focaModalDetalleHojaRutaService, | |
7 | + focaModalService, focaSeguimientoService, $uibModal) { | |
8 | + //#region SETEO VARIABLES | |
16 | 9 | $scope.remito = parametros.remito; |
17 | 10 | $scope.cisternas = parametros.remito.cisternas; |
18 | 11 | $scope.articuloSeleccionado = {}; |
19 | 12 | $scope.aDescargar = []; |
20 | 13 | $scope.cargando = false; |
14 | + //#endregion | |
21 | 15 | |
22 | - if ($scope.remito.rechazado) { | |
16 | + init(); | |
17 | + function init() { | |
18 | + if ($scope.remito.rechazado) { | |
19 | + $scope.readonly = true; | |
20 | + } | |
21 | + var articuloAChequear = $scope.remito.articulosRemito.filter( | |
22 | + function (articulo) { | |
23 | + return !articulo.descargado; | |
24 | + }); | |
23 | 25 | |
24 | - $scope.readonly = true; | |
26 | + if (!articuloAChequear.length || $scope.remito.rechazado) { | |
27 | + $scope.readonly = true; | |
28 | + $scope.cambio($scope.remito.articulosRemito[0]); | |
29 | + } else { | |
30 | + $scope.cambio(articuloAChequear[0]); | |
31 | + } | |
25 | 32 | } |
26 | 33 | |
27 | - //Datos | |
28 | - // var promesaRemito = focaModalDetalleHojaRutaService | |
29 | - // .getRemitoById(idRemito); | |
30 | - // var promesaCisternas = focaModalDetalleHojaRutaService | |
31 | - // .getCisternasByIdRemito(idRemito); | |
32 | - | |
33 | - // Promise.all([promesaRemito, promesaCisternas]).then(function(res) { | |
34 | - // $scope.cargando = false; | |
35 | - // $scope.remito = res[0].data; | |
36 | - // $scope.cisternas = res[1].data; | |
37 | - // var articuloAChequear = $scope.remito.articulosRemito.filter( | |
38 | - // function(articulo) { | |
39 | - // return !articulo.descargado; | |
40 | - // }); | |
41 | - // if(!articuloAChequear.length || $scope.remito.rechazado) { | |
42 | - // $scope.readonly = true; | |
43 | - // $scope.cambio($scope.remito.articulosRemito[0]); | |
44 | - // }else { | |
45 | - // $scope.cambio(articuloAChequear[0]); | |
46 | - // } | |
47 | - // $scope.$digest(); | |
48 | - // }, function() { | |
49 | - // focaModalService.alert('El servicio no responde intente más tarde'); | |
50 | - // $uibModalInstance.dismiss(); | |
51 | - // }); | |
52 | - $scope.cambio = function(articulo) { | |
53 | - if(!$scope.articuloSeleccionado.descargado) { | |
34 | + $scope.cambio = function (articulo) { | |
35 | + if (!$scope.articuloSeleccionado.descargado) { | |
54 | 36 | $scope.articuloSeleccionado.cantidadDescargada = 0; |
55 | 37 | } |
56 | 38 | $scope.aDescargar = []; |
57 | 39 | $scope.articuloSeleccionado = articulo; |
58 | 40 | }; |
59 | - $scope.descargar = function(key) { | |
60 | - if(key === 13) { | |
41 | + $scope.descargar = function (key) { | |
42 | + if (key === 13) { | |
61 | 43 | $scope.cargando = true; |
62 | 44 | var hojaRutaMovimientos = []; |
63 | 45 | var cisternaMovimientos = []; |
64 | 46 | var cisternaCargas = []; |
65 | 47 | var totalADescargar = 0; |
66 | - for(var i = 0; i < $scope.aDescargar.length; i++) { | |
48 | + for (var i = 0; i < $scope.aDescargar.length; i++) { | |
67 | 49 | totalADescargar += $scope.aDescargar[i] || 0; |
68 | 50 | } |
69 | 51 | focaModalService |
70 | 52 | .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' + |
71 | - $scope.articuloSeleccionado.descripcion + '?') | |
72 | - .then(descargar, function() { | |
53 | + $scope.articuloSeleccionado.descripcion + '?') | |
54 | + .then(descargar, function () { | |
73 | 55 | $scope.cargando = false; |
74 | 56 | }); |
75 | 57 | } |
76 | 58 | function descargar() { |
77 | - for(var i = 0; i < $scope.cisternas.length; i++) { | |
59 | + for (var i = 0; i < $scope.cisternas.length; i++) { | |
78 | 60 | var descarga = $scope.aDescargar[i]; |
79 | 61 | var cisternaCarga = $scope.cisternas[i].cisternaCarga; |
80 | - if(!descarga) continue; | |
81 | - if(descarga > cisternaCarga.cantidad) { | |
62 | + if (!descarga) continue; | |
63 | + if (descarga > cisternaCarga.cantidad) { | |
82 | 64 | focaModalService.alert('La cantidad a descargar no debe ser ' + |
83 | 65 | 'mayor a la cantidad de la cisterna'); |
84 | 66 | $scope.cargando = false; |
... | ... | @@ -117,13 +99,13 @@ angular.module('focaModalDetalleHojaRuta') |
117 | 99 | $scope.remito.observaciones = ''; |
118 | 100 | |
119 | 101 | if ($scope.articuloSeleccionado.cantidadDescargada === |
120 | - $scope.articuloSeleccionado.cantidad ) { | |
102 | + $scope.articuloSeleccionado.cantidad) { | |
121 | 103 | |
122 | - $scope.articuloSeleccionado.descargado = true; | |
104 | + $scope.articuloSeleccionado.descargado = true; | |
123 | 105 | } |
124 | 106 | |
125 | 107 | var siguienteArticulo = $scope.remito.articulosRemito.filter( |
126 | - function(articulo) { | |
108 | + function (articulo) { | |
127 | 109 | return articulo.id != $scope.articuloSeleccionado.id; |
128 | 110 | } |
129 | 111 | ); |
... | ... | @@ -132,7 +114,7 @@ angular.module('focaModalDetalleHojaRuta') |
132 | 114 | $scope.cambio(siguienteArticulo[0]); |
133 | 115 | } |
134 | 116 | |
135 | - success().then(function() { | |
117 | + success().then(function () { | |
136 | 118 | $uibModalInstance.close($scope.remito); |
137 | 119 | }); |
138 | 120 | //TODO: enviar puntos de descarga, se quita para la demo. |
... | ... | @@ -159,56 +141,51 @@ angular.module('focaModalDetalleHojaRuta') |
159 | 141 | } |
160 | 142 | } |
161 | 143 | }; |
162 | - | |
163 | - $scope.cancel = function() { | |
144 | + $scope.cancel = function () { | |
164 | 145 | $uibModalInstance.dismiss('cancel'); |
165 | 146 | }; |
166 | - | |
167 | - $scope.distribucionDisponible = function() { | |
168 | - return $scope.articuloSeleccionado.cantidadDescargada && | |
147 | + $scope.distribucionDisponible = function () { | |
148 | + return $scope.articuloSeleccionado.cantidadDescargada && | |
169 | 149 | $scope.articuloSeleccionado.cantidadDescargada <= |
170 | 150 | $scope.articuloSeleccionado.cantidad; |
171 | 151 | }; |
172 | - | |
173 | - $scope.actualizarArticulo = function() { | |
152 | + $scope.actualizarArticulo = function () { | |
174 | 153 | $scope.articuloSeleccionado.cantidadDescargada = 0; |
175 | - for(var i = 0; i < $scope.aDescargar.length; i++) { | |
154 | + for (var i = 0; i < $scope.aDescargar.length; i++) { | |
176 | 155 | $scope.articuloSeleccionado.cantidadDescargada += |
177 | 156 | parseFloat($scope.aDescargar[i]) || 0; |
178 | 157 | } |
179 | 158 | }; |
180 | - | |
181 | - $scope.actualizarPuntoDescarga = function() { | |
159 | + $scope.actualizarPuntoDescarga = function () { | |
182 | 160 | var modalInstance = $uibModal.open( |
183 | 161 | { |
184 | 162 | ariaLabelledBy: 'Actualizar punto de descarga', |
185 | 163 | templateUrl: 'modal-actualizar-punto-descarga.html', |
186 | 164 | controller: 'focaModalActualizarPuntoDescargaController', |
187 | 165 | resolve: { |
188 | - notaPedido: function() { | |
166 | + notaPedido: function () { | |
189 | 167 | return $scope.remito.notaPedido; |
190 | 168 | } |
191 | 169 | }, |
192 | 170 | size: 'lg' |
193 | 171 | } |
194 | 172 | ); |
195 | - modalInstance.result.then(function() { | |
196 | - success().then(function() { | |
173 | + modalInstance.result.then(function () { | |
174 | + success().then(function () { | |
197 | 175 | $uibModalInstance.close($scope.remito); |
198 | 176 | }); |
199 | - }, function() { | |
200 | - success().then(function() { | |
177 | + }, function () { | |
178 | + success().then(function () { | |
201 | 179 | $uibModalInstance.close($scope.remito); |
202 | 180 | }); |
203 | 181 | }); |
204 | 182 | }; |
205 | - | |
206 | - $scope.rechazar = function() { | |
183 | + $scope.rechazar = function () { | |
207 | 184 | focaModalService |
208 | 185 | .prompt({ |
209 | 186 | titulo: 'Aclare el motivo de rechazo' |
210 | 187 | }) |
211 | - .then(function(motivo) { | |
188 | + .then(function (motivo) { | |
212 | 189 | $scope.cargando = true; |
213 | 190 | var remitoRechazado = $.extend(true, {}, $scope.remito); |
214 | 191 | delete remitoRechazado.articulosRemito; |
... | ... | @@ -220,19 +197,19 @@ angular.module('focaModalDetalleHojaRuta') |
220 | 197 | remitoRechazado.fechaRemito.slice(0, 19).replace('T', ' '); |
221 | 198 | |
222 | 199 | focaModalDetalleHojaRutaService.rechazarRemito(remitoRechazado) |
223 | - .then(function(res) { | |
200 | + .then(function (res) { | |
224 | 201 | focaSeguimientoService.guardarPosicion( |
225 | 202 | 'Entrega de producto', |
226 | 203 | res.data[1].id, |
227 | 204 | motivo); |
228 | 205 | success(); |
229 | - }) | |
206 | + }) | |
230 | 207 | .catch(error); |
231 | 208 | $scope.readonly = true; |
232 | 209 | }); |
233 | 210 | }; |
234 | 211 | |
235 | - //funciones | |
212 | + //#region FUNCIONES | |
236 | 213 | function error(error) { |
237 | 214 | focaModalService.alert('Hubo un error ' + error); |
238 | 215 | } |
... | ... | @@ -240,22 +217,10 @@ angular.module('focaModalDetalleHojaRuta') |
240 | 217 | $scope.cargando = false; |
241 | 218 | return focaModalService.alert('Operación realizada con éxito'); |
242 | 219 | } |
243 | - | |
244 | - var articuloAChequear = $scope.remito.articulosRemito.filter( | |
245 | - function(articulo) { | |
246 | - return !articulo.descargado; | |
247 | - }); | |
248 | - | |
249 | - if (!articuloAChequear.length || $scope.remito.rechazado) { | |
250 | - $scope.readonly = true; | |
251 | - $scope.cambio($scope.remito.articulosRemito[0]); | |
252 | - } else { | |
253 | - $scope.cambio(articuloAChequear[0]); | |
254 | - } | |
255 | - | |
220 | + //#endregion | |
256 | 221 | } |
257 | 222 | ]) |
258 | - .controller('focaModalActualizarPuntoDescargaController', | |
223 | + .controller('focaModalActualizarPuntoDescargaController', | |
259 | 224 | [ |
260 | 225 | '$scope', |
261 | 226 | '$uibModalInstance', |
... | ... | @@ -263,16 +228,15 @@ angular.module('focaModalDetalleHojaRuta') |
263 | 228 | 'focaModalService', |
264 | 229 | 'notaPedido', |
265 | 230 | 'focaModalDetalleHojaRutaService', |
266 | - function($scope, $uibModalInstance, focaSeguimientoService, | |
267 | - focaModalService, notaPedido, focaModalDetalleHojaRutaService) | |
268 | - { | |
231 | + function ($scope, $uibModalInstance, focaSeguimientoService, | |
232 | + focaModalService, notaPedido, focaModalDetalleHojaRutaService) { | |
269 | 233 | $scope.notaPedido = notaPedido; |
270 | 234 | $scope.descripcion = ''; |
271 | - focaSeguimientoService.obtenerPosicion(function(res) { | |
235 | + focaSeguimientoService.obtenerPosicion(function (res) { | |
272 | 236 | $scope.posicion = res.coords; |
273 | 237 | }); |
274 | 238 | |
275 | - $scope.cancel = function() { | |
239 | + $scope.cancel = function () { | |
276 | 240 | if ($scope.ingreso) { |
277 | 241 | $scope.ingreso = false; |
278 | 242 | } else { |
... | ... | @@ -280,7 +244,7 @@ angular.module('focaModalDetalleHojaRuta') |
280 | 244 | } |
281 | 245 | }; |
282 | 246 | |
283 | - $scope.select = function(puntoDescarga) { | |
247 | + $scope.select = function (puntoDescarga) { | |
284 | 248 | if (!$scope.posicion) { |
285 | 249 | focaModalService.alert('No se pudo obtener la ubicación'); |
286 | 250 | return; |
... | ... | @@ -291,7 +255,7 @@ angular.module('focaModalDetalleHojaRuta') |
291 | 255 | $uibModalInstance.close(); |
292 | 256 | }; |
293 | 257 | |
294 | - $scope.guardar = function() { | |
258 | + $scope.guardar = function () { | |
295 | 259 | if (!$scope.posicion) { |
296 | 260 | focaModalService.alert('No se pudo obtener la ubicación'); |
297 | 261 | return; |
... | ... | @@ -305,7 +269,7 @@ angular.module('focaModalDetalleHojaRuta') |
305 | 269 | latitud: $scope.posicion.latitude, |
306 | 270 | longitud: $scope.posicion.longitude |
307 | 271 | }) |
308 | - .then(function(res) { | |
272 | + .then(function (res) { | |
309 | 273 | $uibModalInstance.close(res.data); |
310 | 274 | }); |
311 | 275 | }; |