Commit 5f474b7ad36999591efbdd8d9f215182cd842c06
1 parent
b511f92175
Exists in
master
and in
1 other branch
Remplazo de Latitud y Longitud por los valores previamente ingresados
Showing
1 changed file
with
197 additions
and
196 deletions
Show diff stats
src/js/controller.js
1 | -angular.module('focaModalPuntoDescarga') | |
2 | - .controller('focaModalPuntoDescargaController', [ | |
3 | - '$timeout', | |
4 | - '$filter', | |
5 | - '$scope', | |
6 | - '$uibModalInstance', | |
7 | - 'focaModalPuntoDescargaService', | |
8 | - 'filters', | |
9 | - 'focaModalService', | |
10 | - function($timeout, $filter, $scope, $uibModalInstance, | |
11 | - focaModalPuntoDescargaService, filters, focaModalService) { | |
1 | + angular.module('focaModalPuntoDescarga') | |
2 | + .controller('focaModalPuntoDescargaController', [ | |
3 | + '$timeout', | |
4 | + '$filter', | |
5 | + '$scope', | |
6 | + '$uibModalInstance', | |
7 | + 'focaModalPuntoDescargaService', | |
8 | + 'filters', | |
9 | + 'focaModalService', | |
10 | + function($timeout, $filter, $scope, $uibModalInstance, | |
11 | + focaModalPuntoDescargaService, filters, focaModalService) { | |
12 | 12 | |
13 | - $scope.cantidadArticulo = 0; | |
14 | - $scope.articuloSeleccionado = 0; | |
15 | - $scope.ivas = []; | |
16 | - $scope.puntosSeleccionados = []; | |
17 | - $scope.editando = false; | |
18 | - $scope.puntoDescarga = { | |
19 | - id: 0, | |
20 | - id_cliente: filters.idCliente, | |
21 | - id_da_config_0: filters.idDomicilio, | |
22 | - latitud: -32.89214159952345, | |
23 | - longitud: -68.84572999101856 | |
24 | - }; | |
25 | - $scope.articulos = angular.copy(filters.articulos); | |
26 | - $scope.articulos.map(function(articulo) { | |
27 | - articulo.restante = articulo.cantidad; | |
28 | - }); | |
29 | - actualizarTabla(); | |
30 | - cargarPuntos(filters.puntosDescarga); | |
13 | + $scope.cantidadArticulo = 0; | |
14 | + $scope.articuloSeleccionado = 0; | |
15 | + $scope.ivas = []; | |
16 | + $scope.puntosSeleccionados = []; | |
17 | + $scope.editando = false; | |
18 | + $scope.puntoDescarga = { | |
19 | + id: 0, | |
20 | + id_cliente: filters.idCliente, | |
21 | + id_da_config_0: filters.idDomicilio, | |
22 | + latitud: filters.domicilio.Latitud , | |
23 | + longitud: filters.domicilio.Longitud | |
24 | + }; | |
31 | 25 | |
32 | - $scope.cancel = function() { | |
33 | - if($scope.ingreso) { | |
34 | - $scope.ingreso = false; | |
35 | - $scope.puntoDescarga = { | |
36 | - id: 0, | |
37 | - id_cliente: filters.idCliente, | |
38 | - id_da_config_0: filters.idDomicilio, | |
39 | - latitud: -32.89214159952345, | |
40 | - longitud: -68.84572999101856 | |
41 | - }; | |
42 | - $scope.editando = false; | |
43 | - }else { | |
44 | - $uibModalInstance.dismiss('cancel'); | |
45 | - } | |
46 | - }; | |
47 | - | |
48 | - $scope.aceptar = function() { | |
49 | - if($scope.cargaArticulos) { | |
50 | - cargarArticulos(); | |
51 | - }else if(!$scope.puntosSeleccionados.length) { | |
52 | - $uibModalInstance.dismiss('cancel'); | |
53 | - }else { | |
54 | - enviarPuntos(); | |
55 | - } | |
56 | - }; | |
26 | + $scope.articulos = angular.copy(filters.articulos); | |
27 | + $scope.articulos.map(function(articulo) { | |
28 | + articulo.restante = articulo.cantidad; | |
29 | + }); | |
30 | + actualizarTabla(); | |
31 | + cargarPuntos(filters.puntosDescarga); | |
57 | 32 | |
58 | - $scope.guardar = function(key) { | |
59 | - if(key === 13) { | |
60 | - focaModalPuntoDescargaService | |
61 | - .guardarPuntoDescarga($scope.puntoDescarga) | |
62 | - .then(function() { | |
63 | - actualizarTabla(); | |
33 | + $scope.cancel = function() { | |
34 | + if ($scope.ingreso) { | |
64 | 35 | $scope.ingreso = false; |
65 | 36 | $scope.puntoDescarga = { |
66 | 37 | id: 0, |
67 | 38 | id_cliente: filters.idCliente, |
68 | 39 | id_da_config_0: filters.idDomicilio, |
69 | - latitud: -32.89214159952345, | |
70 | - longitud: -68.84572999101856 | |
40 | + latitud: filters.domicilio.Latitud, | |
41 | + longitud: filters.domicilio.Longitud | |
71 | 42 | }; |
72 | 43 | $scope.editando = false; |
73 | - }); | |
74 | - } | |
75 | - }; | |
44 | + } else { | |
45 | + $uibModalInstance.dismiss('cancel'); | |
46 | + } | |
47 | + }; | |
76 | 48 | |
77 | - $scope.editar = function(id) { | |
78 | - focaModalPuntoDescargaService.getPuntoDescargaById(id).then(function(res) { | |
79 | - $scope.puntoDescarga = res.data; | |
80 | - $scope.ingreso = true; | |
81 | - $scope.editando = true; | |
82 | - }); | |
83 | - }; | |
49 | + $scope.aceptar = function() { | |
50 | + if ($scope.cargaArticulos) { | |
51 | + cargarArticulos(); | |
52 | + } else if(!$scope.puntosSeleccionados.length) { | |
53 | + $uibModalInstance.dismiss('cancel'); | |
54 | + } else { | |
55 | + enviarPuntos(); | |
56 | + } | |
57 | + }; | |
84 | 58 | |
85 | - $scope.eliminar = function(idx, puntoDescarga) { | |
86 | - focaModalService.confirm('ยฟEstรก seguro que desea borrar el punto de descarga '+ | |
87 | - puntoDescarga.descripcion + '?').then(function(data) { | |
88 | - if(data) { | |
89 | - focaModalPuntoDescargaService | |
90 | - .eliminarPuntoDescarga(puntoDescarga.id) | |
91 | - .then(function() { | |
92 | - $scope.puntosDescarga.splice(idx, 1); | |
93 | - }); | |
94 | - } | |
59 | + $scope.guardar = function(key) { | |
60 | + if(key === 13) { | |
61 | + focaModalPuntoDescargaService | |
62 | + .guardarPuntoDescarga($scope.puntoDescarga) | |
63 | + .then(function() { | |
64 | + actualizarTabla(); | |
65 | + $scope.ingreso = false; | |
66 | + $scope.puntoDescarga = { | |
67 | + id: 0, | |
68 | + id_cliente: filters.idCliente, | |
69 | + id_da_config_0: filters.idDomicilio, | |
70 | + latitud: filters.domicilio.Latitud, | |
71 | + longitud: filters.domicilio.Longitud | |
72 | + }; | |
73 | + $scope.editando = false; | |
74 | + }); | |
75 | + } | |
76 | + }; | |
77 | + | |
78 | + $scope.editar = function(id) { | |
79 | + focaModalPuntoDescargaService.getPuntoDescargaById(id).then(function(res) { | |
80 | + $scope.puntoDescarga = res.data; | |
81 | + $scope.ingreso = true; | |
82 | + $scope.editando = true; | |
95 | 83 | }); |
96 | - }; | |
84 | + }; | |
97 | 85 | |
98 | - $scope.seleccionarPunto = function(idx, esCheckbox) { | |
99 | - var indexPunto = $scope.puntosSeleccionados.indexOf(idx); | |
100 | - if(indexPunto !== -1) { | |
101 | - if(!esCheckbox){ | |
102 | - $scope.puntosDescarga[idx].seleccionado = false; | |
103 | - } | |
104 | - $scope.puntosSeleccionados.splice(indexPunto, 1); | |
105 | - }else { | |
106 | - if(!esCheckbox){ | |
107 | - $scope.puntosDescarga[idx].seleccionado = true; | |
86 | + $scope.eliminar = function(idx, puntoDescarga) { | |
87 | + focaModalService.confirm('ยฟEstรก seguro que desea borrar el punto de descarga '+ | |
88 | + puntoDescarga.descripcion + '?').then(function(data) { | |
89 | + if (data) { | |
90 | + focaModalPuntoDescargaService | |
91 | + .eliminarPuntoDescarga(puntoDescarga.id) | |
92 | + .then(function() { | |
93 | + $scope.puntosDescarga.splice(idx, 1); | |
94 | + }); | |
95 | + } | |
96 | + }); | |
97 | + }; | |
98 | + | |
99 | + $scope.seleccionarPunto = function(idx, esCheckbox) { | |
100 | + var indexPunto = $scope.puntosSeleccionados.indexOf(idx); | |
101 | + if (indexPunto !== -1) { | |
102 | + if (!esCheckbox) { | |
103 | + $scope.puntosDescarga[idx].seleccionado = false; | |
104 | + } | |
105 | + $scope.puntosSeleccionados.splice(indexPunto, 1); | |
106 | + } else { | |
107 | + if (!esCheckbox) { | |
108 | + $scope.puntosDescarga[idx].seleccionado = true; | |
109 | + } | |
110 | + $scope.puntosSeleccionados.push(idx); | |
108 | 111 | } |
109 | - $scope.puntosSeleccionados.push(idx); | |
110 | - } | |
111 | - }; | |
112 | + }; | |
112 | 113 | |
113 | - $scope.agregarArticulo = function(punto, key) { | |
114 | - key = (typeof key === 'undefined') ? 13 : key; | |
114 | + $scope.agregarArticulo = function(punto, key) { | |
115 | + key = (typeof key === 'undefined') ? 13 : key; | |
115 | 116 | |
116 | - if(key === 13){ | |
117 | - var articulo = $scope.articulos[$scope.articuloSeleccionado], | |
118 | - cantidadRestante = articulo.restante - punto.cantidadACargar; | |
117 | + if (key === 13) { | |
118 | + var articulo = $scope.articulos[$scope.articuloSeleccionado], | |
119 | + cantidadRestante = articulo.restante - punto.cantidadACargar; | |
119 | 120 | |
120 | - if(cantidadRestante < 0) { | |
121 | - focaModalService | |
122 | - .alert('La cantidad a cargar debe ser menor o igual al restante'); | |
123 | - }else if(punto.cantidadACargar <= 0) { | |
124 | - focaModalService | |
125 | - .alert('La cantidad a cargar debe ser mayor que cero'); | |
126 | - }else { | |
127 | - punto.cargado += parseInt(punto.cantidadACargar); | |
128 | - articulo.restante = cantidadRestante; | |
129 | - var existeArticulo = punto.articulosAgregados.filter( | |
130 | - function (articuloAAgregar) { | |
131 | - return articuloAAgregar.id === articulo.idArticulo; | |
132 | - }); | |
133 | - //Si el articulo ya fue agregado | |
134 | - if(existeArticulo.length) { | |
135 | - //Solo sumo cantidad | |
136 | - var total = parseInt(existeArticulo[0].cantidad) + | |
137 | - parseInt(punto.cantidadACargar); | |
138 | - existeArticulo[0].cantidad = total; | |
139 | - }else { | |
140 | - //Agrego el articulo con la cantidad | |
141 | - punto.articulosAgregados.push({ | |
142 | - id: articulo.idArticulo, | |
143 | - descripcion: articulo.descripcion, | |
144 | - cantidad: punto.cantidadACargar, | |
145 | - index: $scope.articuloSeleccionado | |
146 | - }); | |
121 | + if (cantidadRestante < 0) { | |
122 | + focaModalService | |
123 | + .alert('La cantidad a cargar debe ser menor o igual al restante'); | |
124 | + } else if (punto.cantidadACargar <= 0) { | |
125 | + focaModalService | |
126 | + .alert('La cantidad a cargar debe ser mayor que cero'); | |
127 | + } else { | |
128 | + punto.cargado += parseInt(punto.cantidadACargar); | |
129 | + articulo.restante = cantidadRestante; | |
130 | + var existeArticulo = punto.articulosAgregados.filter( | |
131 | + function (articuloAAgregar) { | |
132 | + return articuloAAgregar.id === articulo.idArticulo; | |
133 | + }); | |
134 | + //Si el articulo ya fue agregado | |
135 | + if (existeArticulo.length) { | |
136 | + //Solo sumo cantidad | |
137 | + var total = parseInt(existeArticulo[0].cantidad) + | |
138 | + parseInt(punto.cantidadACargar); | |
139 | + existeArticulo[0].cantidad = total; | |
140 | + } else { | |
141 | + //Agrego el articulo con la cantidad | |
142 | + punto.articulosAgregados.push({ | |
143 | + id: articulo.idArticulo, | |
144 | + descripcion: articulo.descripcion, | |
145 | + cantidad: punto.cantidadACargar, | |
146 | + index: $scope.articuloSeleccionado | |
147 | + }); | |
148 | + } | |
149 | + punto.cantidadACargar = 0; | |
147 | 150 | } |
148 | - punto.cantidadACargar = 0; | |
149 | 151 | } |
150 | - } | |
151 | - }; | |
152 | + }; | |
152 | 153 | |
153 | - $scope.quitarArticulo = function(articulo, idx, punto) { | |
154 | - var articuloAEliminar = $scope.articulos.filter(function(art) { | |
155 | - return art.id === articulo.id; | |
156 | - }); | |
157 | - var restante = parseInt(articuloAEliminar[0].restante); | |
158 | - restante += parseInt(articulo.cantidad); | |
159 | - articuloAEliminar[0].restante = restante; | |
154 | + $scope.quitarArticulo = function(articulo, idx, punto) { | |
155 | + var articuloAEliminar = $scope.articulos.filter(function(art) { | |
156 | + return art.id === articulo.id; | |
157 | + }); | |
158 | + var restante = parseInt(articuloAEliminar[0].restante); | |
159 | + restante += parseInt(articulo.cantidad); | |
160 | + articuloAEliminar[0].restante = restante; | |
160 | 161 | |
161 | - punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); | |
162 | - punto.articulosAgregados.splice(idx, 1); | |
163 | - }; | |
162 | + punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); | |
163 | + punto.articulosAgregados.splice(idx, 1); | |
164 | + }; | |
164 | 165 | |
165 | - function actualizarTabla() { | |
166 | - focaModalPuntoDescargaService | |
167 | - .getPuntosDescargaByClienDom(filters.idDomicilio, filters.idCliente) | |
168 | - .then(function(res) { | |
169 | - $scope.puntosDescarga = res.data; | |
166 | + function actualizarTabla() { | |
167 | + focaModalPuntoDescargaService | |
168 | + .getPuntosDescargaByClienDom(filters.idDomicilio, filters.idCliente) | |
169 | + .then(function(res) { | |
170 | + $scope.puntosDescarga = res.data; | |
171 | + }); | |
172 | + } | |
173 | + function verCargaArticulos() { | |
174 | + $scope.puntosACargar = []; | |
175 | + $scope.cargaArticulos = true; | |
176 | + $scope.puntosSeleccionados.forEach(function(idx) { | |
177 | + $scope.puntosACargar.push($scope.puntosDescarga[idx]); | |
170 | 178 | }); |
171 | - } | |
172 | - function verCargaArticulos() { | |
173 | - $scope.puntosACargar = []; | |
174 | - $scope.cargaArticulos = true; | |
175 | - $scope.puntosSeleccionados.forEach(function(idx) { | |
176 | - $scope.puntosACargar.push($scope.puntosDescarga[idx]); | |
177 | - }); | |
178 | 179 | |
179 | - $scope.puntosACargar.map(function(punto) { | |
180 | - punto.articulosAgregados = []; | |
181 | - punto.cantidadACargar = 0; | |
182 | - punto.cargado = 0; | |
183 | - }); | |
184 | - } | |
185 | - function cargarArticulos() { | |
186 | - $uibModalInstance.close($scope.puntosACargar); | |
187 | - } | |
188 | - function cargarPuntos(puntosDescarga) { | |
189 | - //Si existen puntos ya cargados | |
190 | - if(puntosDescarga) { | |
191 | - if(!puntosDescarga[0].cargado) { | |
192 | - agregarTotalCargado(puntosDescarga); | |
180 | + $scope.puntosACargar.map(function(punto) { | |
181 | + punto.articulosAgregados = []; | |
182 | + punto.cantidadACargar = 0; | |
183 | + punto.cargado = 0; | |
184 | + }); | |
185 | + } | |
186 | + function cargarArticulos() { | |
187 | + $uibModalInstance.close($scope.puntosACargar); | |
188 | + } | |
189 | + function cargarPuntos(puntosDescarga) { | |
190 | + //Si existen puntos ya cargados | |
191 | + if (puntosDescarga) { | |
192 | + if (!puntosDescarga[0].cargado) { | |
193 | + agregarTotalCargado(puntosDescarga); | |
194 | + } | |
195 | + $scope.puntosACargar = puntosDescarga; | |
196 | + $scope.cargaArticulos = true; | |
197 | + //Recorro los puntos | |
198 | + puntosDescarga.forEach(function(punto) { | |
199 | + //Recorro los articulos cargados en cada punto | |
200 | + punto.articulosAgregados.forEach(function(articulo) { | |
201 | + var articuloARestar = $scope.articulos.filter(function(art) { | |
202 | + return art.idArticulo === articulo.id; | |
203 | + }); | |
204 | + articuloARestar[0].restante -= articulo.cantidad; | |
205 | + }); | |
206 | + }); | |
193 | 207 | } |
194 | - $scope.puntosACargar = puntosDescarga; | |
195 | - $scope.cargaArticulos = true; | |
196 | - //Recorro los puntos | |
208 | + } | |
209 | + function agregarTotalCargado(puntosDescarga) { | |
210 | + puntosDescarga.map(function(punto) { | |
211 | + punto.cantidadACargar = 0; | |
212 | + punto.cargado = 0; | |
213 | + }); | |
214 | + //Agrego cantidad de combustible cargada en los puntos de descarga | |
197 | 215 | puntosDescarga.forEach(function(punto) { |
198 | - //Recorro los articulos cargados en cada punto | |
199 | 216 | punto.articulosAgregados.forEach(function(articulo) { |
200 | - var articuloARestar = $scope.articulos.filter(function(art) { | |
201 | - return art.idArticulo === articulo.id; | |
202 | - }); | |
203 | - articuloARestar[0].restante -= articulo.cantidad; | |
217 | + punto.cargado += articulo.cantidad; | |
204 | 218 | }); |
205 | 219 | }); |
206 | 220 | } |
207 | - } | |
208 | - function agregarTotalCargado(puntosDescarga) { | |
209 | - puntosDescarga.map(function(punto) { | |
210 | - punto.cantidadACargar = 0; | |
211 | - punto.cargado = 0; | |
212 | - }); | |
213 | - //Agrego cantidad de combustible cargada en los puntos de descarga | |
214 | - puntosDescarga.forEach(function(punto) { | |
215 | - punto.articulosAgregados.forEach(function(articulo) { | |
216 | - punto.cargado += articulo.cantidad; | |
221 | + function enviarPuntos() { | |
222 | + var result = []; | |
223 | + $scope.puntosSeleccionados.forEach(function(idx) { | |
224 | + result.push($scope.puntosDescarga[idx]); | |
217 | 225 | }); |
218 | - }); | |
219 | - } | |
220 | - function enviarPuntos() { | |
221 | - var result = []; | |
222 | - $scope.puntosSeleccionados.forEach(function(idx) { | |
223 | - result.push($scope.puntosDescarga[idx]); | |
224 | - }); | |
225 | - $uibModalInstance.close(result); | |
226 | - } | |
227 | - }] | |
228 | - ); | |
226 | + $uibModalInstance.close(result); | |
227 | + } | |
228 | + }] | |
229 | + ); |