Commit 0dec5ade08a232fc428db67c688d44c4274cce2a
1 parent
5f474b7ad3
Exists in
master
and in
1 other branch
error identación
Showing
1 changed file
with
194 additions
and
194 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: filters.domicilio.Latitud , | |
23 | - longitud: filters.domicilio.Longitud | |
24 | - }; | |
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 | + }; | |
25 | 25 | |
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); | |
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); | |
32 | + | |
33 | + $scope.cancel = function() { | |
34 | + if ($scope.ingreso) { | |
35 | + $scope.ingreso = false; | |
36 | + $scope.puntoDescarga = { | |
37 | + id: 0, | |
38 | + id_cliente: filters.idCliente, | |
39 | + id_da_config_0: filters.idDomicilio, | |
40 | + latitud: filters.domicilio.Latitud, | |
41 | + longitud: filters.domicilio.Longitud | |
42 | + }; | |
43 | + $scope.editando = false; | |
44 | + } else { | |
45 | + $uibModalInstance.dismiss('cancel'); | |
46 | + } | |
47 | + }; | |
48 | + | |
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 | + }; | |
32 | 58 | |
33 | - $scope.cancel = function() { | |
34 | - if ($scope.ingreso) { | |
59 | + $scope.guardar = function(key) { | |
60 | + if(key === 13) { | |
61 | + focaModalPuntoDescargaService | |
62 | + .guardarPuntoDescarga($scope.puntoDescarga) | |
63 | + .then(function() { | |
64 | + actualizarTabla(); | |
35 | 65 | $scope.ingreso = false; |
36 | 66 | $scope.puntoDescarga = { |
37 | 67 | id: 0, |
... | ... | @@ -41,189 +71,159 @@ |
41 | 71 | longitud: filters.domicilio.Longitud |
42 | 72 | }; |
43 | 73 | $scope.editando = false; |
44 | - } else { | |
45 | - $uibModalInstance.dismiss('cancel'); | |
46 | - } | |
47 | - }; | |
48 | - | |
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 | - }; | |
58 | - | |
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; | |
83 | 74 | }); |
84 | - }; | |
75 | + } | |
76 | + }; | |
85 | 77 | |
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 | - }; | |
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; | |
83 | + }); | |
84 | + }; | |
98 | 85 | |
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; | |
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 | + }); | |
109 | 95 | } |
110 | - $scope.puntosSeleccionados.push(idx); | |
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; | |
111 | 109 | } |
112 | - }; | |
110 | + $scope.puntosSeleccionados.push(idx); | |
111 | + } | |
112 | + }; | |
113 | 113 | |
114 | - $scope.agregarArticulo = function(punto, key) { | |
115 | - key = (typeof key === 'undefined') ? 13 : key; | |
114 | + $scope.agregarArticulo = function(punto, key) { | |
115 | + key = (typeof key === 'undefined') ? 13 : key; | |
116 | 116 | |
117 | - if (key === 13) { | |
118 | - var articulo = $scope.articulos[$scope.articuloSeleccionado], | |
119 | - cantidadRestante = articulo.restante - punto.cantidadACargar; | |
117 | + if (key === 13) { | |
118 | + var articulo = $scope.articulos[$scope.articuloSeleccionado], | |
119 | + cantidadRestante = articulo.restante - punto.cantidadACargar; | |
120 | 120 | |
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'); | |
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; | |
127 | 140 | } 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; | |
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 | + }); | |
150 | 148 | } |
149 | + punto.cantidadACargar = 0; | |
151 | 150 | } |
152 | - }; | |
151 | + } | |
152 | + }; | |
153 | 153 | |
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; | |
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; | |
161 | 161 | |
162 | - punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); | |
163 | - punto.articulosAgregados.splice(idx, 1); | |
164 | - }; | |
162 | + punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); | |
163 | + punto.articulosAgregados.splice(idx, 1); | |
164 | + }; | |
165 | 165 | |
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]); | |
166 | + function actualizarTabla() { | |
167 | + focaModalPuntoDescargaService | |
168 | + .getPuntosDescargaByClienDom(filters.idDomicilio, filters.idCliente) | |
169 | + .then(function(res) { | |
170 | + $scope.puntosDescarga = res.data; | |
178 | 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]); | |
178 | + }); | |
179 | 179 | |
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 | - }); | |
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); | |
207 | 194 | } |
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 | |
195 | + $scope.puntosACargar = puntosDescarga; | |
196 | + $scope.cargaArticulos = true; | |
197 | + //Recorro los puntos | |
215 | 198 | puntosDescarga.forEach(function(punto) { |
199 | + //Recorro los articulos cargados en cada punto | |
216 | 200 | punto.articulosAgregados.forEach(function(articulo) { |
217 | - punto.cargado += articulo.cantidad; | |
201 | + var articuloARestar = $scope.articulos.filter(function(art) { | |
202 | + return art.idArticulo === articulo.id; | |
203 | + }); | |
204 | + articuloARestar[0].restante -= articulo.cantidad; | |
218 | 205 | }); |
219 | 206 | }); |
220 | 207 | } |
221 | - function enviarPuntos() { | |
222 | - var result = []; | |
223 | - $scope.puntosSeleccionados.forEach(function(idx) { | |
224 | - result.push($scope.puntosDescarga[idx]); | |
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 | |
215 | + puntosDescarga.forEach(function(punto) { | |
216 | + punto.articulosAgregados.forEach(function(articulo) { | |
217 | + punto.cargado += articulo.cantidad; | |
225 | 218 | }); |
226 | - $uibModalInstance.close(result); | |
227 | - } | |
228 | - }] | |
229 | - ); | |
219 | + }); | |
220 | + } | |
221 | + function enviarPuntos() { | |
222 | + var result = []; | |
223 | + $scope.puntosSeleccionados.forEach(function(idx) { | |
224 | + result.push($scope.puntosDescarga[idx]); | |
225 | + }); | |
226 | + $uibModalInstance.close(result); | |
227 | + } | |
228 | + }] | |
229 | + ); |