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') | 1 | angular.module('focaModalPuntoDescarga') |
2 | .controller('focaModalPuntoDescargaController', [ | 2 | .controller('focaModalPuntoDescargaController', [ |
3 | '$timeout', | 3 | '$timeout', |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'focaModalPuntoDescargaService', | 7 | 'focaModalPuntoDescargaService', |
8 | 'filters', | 8 | 'filters', |
9 | 'focaModalService', | 9 | 'focaModalService', |
10 | function($timeout, $filter, $scope, $uibModalInstance, | 10 | function($timeout, $filter, $scope, $uibModalInstance, |
11 | focaModalPuntoDescargaService, filters, focaModalService) { | 11 | focaModalPuntoDescargaService, filters, focaModalService) { |
12 | 12 | ||
13 | $scope.cantidadArticulo = 0; | 13 | $scope.cantidadArticulo = 0; |
14 | $scope.articuloSeleccionado = 0; | 14 | $scope.articuloSeleccionado = 0; |
15 | $scope.ivas = []; | 15 | $scope.ivas = []; |
16 | $scope.puntosSeleccionados = []; | 16 | $scope.puntosSeleccionados = []; |
17 | $scope.editando = false; | 17 | $scope.editando = false; |
18 | $scope.puntoDescarga = { | 18 | $scope.puntoDescarga = { |
19 | id: 0, | 19 | id: 0, |
20 | id_cliente: filters.idCliente, | 20 | id_cliente: filters.idCliente, |
21 | id_da_config_0: filters.idDomicilio, | 21 | id_da_config_0: filters.idDomicilio, |
22 | latitud: -32.89214159952345, | 22 | latitud: filters.domicilio.Latitud , |
23 | longitud: -68.84572999101856 | 23 | longitud: filters.domicilio.Longitud |
24 | }; | 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); | ||
31 | 25 | ||
32 | $scope.cancel = function() { | 26 | $scope.articulos = angular.copy(filters.articulos); |
33 | if($scope.ingreso) { | 27 | $scope.articulos.map(function(articulo) { |
34 | $scope.ingreso = false; | 28 | articulo.restante = articulo.cantidad; |
35 | $scope.puntoDescarga = { | 29 | }); |
36 | id: 0, | 30 | actualizarTabla(); |
37 | id_cliente: filters.idCliente, | 31 | cargarPuntos(filters.puntosDescarga); |
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 | }; | ||
57 | 32 | ||
58 | $scope.guardar = function(key) { | 33 | $scope.cancel = function() { |
59 | if(key === 13) { | 34 | if ($scope.ingreso) { |
60 | focaModalPuntoDescargaService | ||
61 | .guardarPuntoDescarga($scope.puntoDescarga) | ||
62 | .then(function() { | ||
63 | actualizarTabla(); | ||
64 | $scope.ingreso = false; | 35 | $scope.ingreso = false; |
65 | $scope.puntoDescarga = { | 36 | $scope.puntoDescarga = { |
66 | id: 0, | 37 | id: 0, |
67 | id_cliente: filters.idCliente, | 38 | id_cliente: filters.idCliente, |
68 | id_da_config_0: filters.idDomicilio, | 39 | id_da_config_0: filters.idDomicilio, |
69 | latitud: -32.89214159952345, | 40 | latitud: filters.domicilio.Latitud, |
70 | longitud: -68.84572999101856 | 41 | longitud: filters.domicilio.Longitud |
71 | }; | 42 | }; |
72 | $scope.editando = false; | 43 | $scope.editando = false; |
73 | }); | 44 | } else { |
74 | } | 45 | $uibModalInstance.dismiss('cancel'); |
75 | }; | 46 | } |
47 | }; | ||
76 | 48 | ||
77 | $scope.editar = function(id) { | 49 | $scope.aceptar = function() { |
78 | focaModalPuntoDescargaService.getPuntoDescargaById(id).then(function(res) { | 50 | if ($scope.cargaArticulos) { |
79 | $scope.puntoDescarga = res.data; | 51 | cargarArticulos(); |
80 | $scope.ingreso = true; | 52 | } else if(!$scope.puntosSeleccionados.length) { |
81 | $scope.editando = true; | 53 | $uibModalInstance.dismiss('cancel'); |
82 | }); | 54 | } else { |
83 | }; | 55 | enviarPuntos(); |
56 | } | ||
57 | }; | ||
84 | 58 | ||
85 | $scope.eliminar = function(idx, puntoDescarga) { | 59 | $scope.guardar = function(key) { |
86 | focaModalService.confirm('¿Está seguro que desea borrar el punto de descarga '+ | 60 | if(key === 13) { |
87 | puntoDescarga.descripcion + '?').then(function(data) { | 61 | focaModalPuntoDescargaService |
88 | if(data) { | 62 | .guardarPuntoDescarga($scope.puntoDescarga) |
89 | focaModalPuntoDescargaService | 63 | .then(function() { |
90 | .eliminarPuntoDescarga(puntoDescarga.id) | 64 | actualizarTabla(); |
91 | .then(function() { | 65 | $scope.ingreso = false; |
92 | $scope.puntosDescarga.splice(idx, 1); | 66 | $scope.puntoDescarga = { |
93 | }); | 67 | id: 0, |
94 | } | 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) { | 86 | $scope.eliminar = function(idx, puntoDescarga) { |
99 | var indexPunto = $scope.puntosSeleccionados.indexOf(idx); | 87 | focaModalService.confirm('¿Está seguro que desea borrar el punto de descarga '+ |
100 | if(indexPunto !== -1) { | 88 | puntoDescarga.descripcion + '?').then(function(data) { |
101 | if(!esCheckbox){ | 89 | if (data) { |
102 | $scope.puntosDescarga[idx].seleccionado = false; | 90 | focaModalPuntoDescargaService |
103 | } | 91 | .eliminarPuntoDescarga(puntoDescarga.id) |
104 | $scope.puntosSeleccionados.splice(indexPunto, 1); | 92 | .then(function() { |
105 | }else { | 93 | $scope.puntosDescarga.splice(idx, 1); |
106 | if(!esCheckbox){ | 94 | }); |
107 | $scope.puntosDescarga[idx].seleccionado = true; | 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); | 112 | }; |
110 | } | ||
111 | }; | ||
112 | 113 | ||
113 | $scope.agregarArticulo = function(punto, key) { | 114 | $scope.agregarArticulo = function(punto, key) { |
114 | key = (typeof key === 'undefined') ? 13 : key; | 115 | key = (typeof key === 'undefined') ? 13 : key; |
115 | 116 | ||
116 | if(key === 13){ | 117 | if (key === 13) { |
117 | var articulo = $scope.articulos[$scope.articuloSeleccionado], | 118 | var articulo = $scope.articulos[$scope.articuloSeleccionado], |
118 | cantidadRestante = articulo.restante - punto.cantidadACargar; | 119 | cantidadRestante = articulo.restante - punto.cantidadACargar; |
119 | 120 | ||
120 | if(cantidadRestante < 0) { | 121 | if (cantidadRestante < 0) { |
121 | focaModalService | 122 | focaModalService |
122 | .alert('La cantidad a cargar debe ser menor o igual al restante'); | 123 | .alert('La cantidad a cargar debe ser menor o igual al restante'); |
123 | }else if(punto.cantidadACargar <= 0) { | 124 | } else if (punto.cantidadACargar <= 0) { |
124 | focaModalService | 125 | focaModalService |
125 | .alert('La cantidad a cargar debe ser mayor que cero'); | 126 | .alert('La cantidad a cargar debe ser mayor que cero'); |
126 | }else { | 127 | } else { |
127 | punto.cargado += parseInt(punto.cantidadACargar); | 128 | punto.cargado += parseInt(punto.cantidadACargar); |
128 | articulo.restante = cantidadRestante; | 129 | articulo.restante = cantidadRestante; |
129 | var existeArticulo = punto.articulosAgregados.filter( | 130 | var existeArticulo = punto.articulosAgregados.filter( |
130 | function (articuloAAgregar) { | 131 | function (articuloAAgregar) { |
131 | return articuloAAgregar.id === articulo.idArticulo; | 132 | return articuloAAgregar.id === articulo.idArticulo; |
132 | }); | 133 | }); |
133 | //Si el articulo ya fue agregado | 134 | //Si el articulo ya fue agregado |
134 | if(existeArticulo.length) { | 135 | if (existeArticulo.length) { |
135 | //Solo sumo cantidad | 136 | //Solo sumo cantidad |
136 | var total = parseInt(existeArticulo[0].cantidad) + | 137 | var total = parseInt(existeArticulo[0].cantidad) + |
137 | parseInt(punto.cantidadACargar); | 138 | parseInt(punto.cantidadACargar); |
138 | existeArticulo[0].cantidad = total; | 139 | existeArticulo[0].cantidad = total; |
139 | }else { | 140 | } else { |
140 | //Agrego el articulo con la cantidad | 141 | //Agrego el articulo con la cantidad |
141 | punto.articulosAgregados.push({ | 142 | punto.articulosAgregados.push({ |
142 | id: articulo.idArticulo, | 143 | id: articulo.idArticulo, |
143 | descripcion: articulo.descripcion, | 144 | descripcion: articulo.descripcion, |
144 | cantidad: punto.cantidadACargar, | 145 | cantidad: punto.cantidadACargar, |
145 | index: $scope.articuloSeleccionado | 146 | index: $scope.articuloSeleccionado |
146 | }); | 147 | }); |
148 | } | ||
149 | punto.cantidadACargar = 0; | ||
147 | } | 150 | } |
148 | punto.cantidadACargar = 0; | ||
149 | } | 151 | } |
150 | } | 152 | }; |
151 | }; | ||
152 | 153 | ||
153 | $scope.quitarArticulo = function(articulo, idx, punto) { | 154 | $scope.quitarArticulo = function(articulo, idx, punto) { |
154 | var articuloAEliminar = $scope.articulos.filter(function(art) { | 155 | var articuloAEliminar = $scope.articulos.filter(function(art) { |
155 | return art.id === articulo.id; | 156 | return art.id === articulo.id; |
156 | }); | 157 | }); |
157 | var restante = parseInt(articuloAEliminar[0].restante); | 158 | var restante = parseInt(articuloAEliminar[0].restante); |
158 | restante += parseInt(articulo.cantidad); | 159 | restante += parseInt(articulo.cantidad); |
159 | articuloAEliminar[0].restante = restante; | 160 | articuloAEliminar[0].restante = restante; |
160 | 161 | ||
161 | punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); | 162 | punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); |
162 | punto.articulosAgregados.splice(idx, 1); | 163 | punto.articulosAgregados.splice(idx, 1); |
163 | }; | 164 | }; |
164 | 165 | ||
165 | function actualizarTabla() { | 166 | function actualizarTabla() { |
166 | focaModalPuntoDescargaService | 167 | focaModalPuntoDescargaService |
167 | .getPuntosDescargaByClienDom(filters.idDomicilio, filters.idCliente) | 168 | .getPuntosDescargaByClienDom(filters.idDomicilio, filters.idCliente) |
168 | .then(function(res) { | 169 | .then(function(res) { |
169 | $scope.puntosDescarga = res.data; | 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 | $scope.puntosACargar.map(function(punto) { |
180 | punto.articulosAgregados = []; | 181 | punto.articulosAgregados = []; |
181 | punto.cantidadACargar = 0; | 182 | punto.cantidadACargar = 0; |
182 | punto.cargado = 0; | 183 | punto.cargado = 0; |
183 | }); | 184 | }); |
184 | } | 185 | } |
185 | function cargarArticulos() { | 186 | function cargarArticulos() { |
186 | $uibModalInstance.close($scope.puntosACargar); | 187 | $uibModalInstance.close($scope.puntosACargar); |
187 | } | 188 | } |
188 | function cargarPuntos(puntosDescarga) { | 189 | function cargarPuntos(puntosDescarga) { |
189 | //Si existen puntos ya cargados | 190 | //Si existen puntos ya cargados |