Commit 4b9fa4fafe2a23b504c6a60464db63e66ec5d572

Authored by Jose Pinto
1 parent 84f372739f
Exists in master

busca por id lista precio

Showing 2 changed files with 32 additions and 27 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaModalPrecioCondicion') 1 angular.module('focaModalPrecioCondicion')
2 .controller('focaModalPrecioCondicionController', 2 .controller('focaModalPrecioCondicionController',
3 [ 3 [
4 '$timeout', 4 '$timeout',
5 '$filter', 5 '$filter',
6 '$scope', 6 '$scope',
7 '$uibModal', 7 '$uibModal',
8 '$uibModalInstance', 8 '$uibModalInstance',
9 'focaModalService', 9 'focaModalService',
10 'focaModalPrecioCondicionService', 10 'focaModalPrecioCondicionService',
11 'idListaPrecio',
11 function( 12 function(
12 $timeout, $filter, $scope, $uibModal, $uibModalInstance, 13 $timeout, $filter, $scope, $uibModal, $uibModalInstance,
13 focaModalService, focaModalPrecioCondicionService 14 focaModalService, focaModalPrecioCondicionService, idListaPrecio
14 ) { 15 ) {
15 16
16 focaModalPrecioCondicionService.getPreciosCondicionesPlazosPagos().then(
17 function(res) {
18 for(var i = 0; i < res.data.length; i++) {
19 var plazosTemp = '';
20 res.data[i].plazoPago.sort(function(a, b) {
21 return a.dias - b.dias;
22 });
23 for(var j = 0; j < res.data[i].plazoPago.length; j++) {
24 if(j + 1 === res.data[i].plazoPago.length) {
25 plazosTemp += res.data[i].plazoPago[j].dias;
26 }else {
27 plazosTemp += res.data[i].plazoPago[j].dias + ', ';
28 }
29 }
30 res.data[i].plazos = plazosTemp.trim();
31 }
32 $scope.precioCondicion = res.data;
33 $scope.search();
34 }
35 );
36 $scope.filters = ''; 17 $scope.filters = '';
37 $scope.ingreso = false; 18 $scope.ingreso = false;
38 $scope.plazosNuevos = []; 19 $scope.plazosNuevos = [];
39 $scope.plazoACargar = 20 $scope.plazoACargar =
40 { 21 {
41 item: 1 22 item: 1
42 }; 23 };
43 // pagination 24 // pagination
44 $scope.numPerPage = 10; 25 $scope.numPerPage = 10;
45 $scope.currentPage = 1; 26 $scope.currentPage = 1;
46 $scope.filteredPrecioCondicion = []; 27 $scope.filteredPrecioCondicion = [];
47 $scope.currentPagePrecioCondicion = []; 28 $scope.currentPagePrecioCondicion = [];
48 $scope.selectedPrecioCondicion = -1; 29 $scope.selectedPrecioCondicion = -1;
49 30
50 //METODOS 31 var funcionGet = idListaPrecio ? 'getPreciosCondicionesByIdListaPrecio' :
32 'getPreciosCondiciones';
33
34 focaModalPrecioCondicionService
35 [funcionGet](idListaPrecio)
36 .then(function(res) {
37 for (var i = 0; i < res.data.length; i++) {
38 var plazosTemp = '';
39 res.data[i].plazoPago.sort(function(a, b) {
40 return a.dias - b.dias;
41 });
42 for (var j = 0; j < res.data[i].plazoPago.length; j++) {
43 if (j + 1 === res.data[i].plazoPago.length) {
44 plazosTemp += res.data[i].plazoPago[j].dias;
45 } else {
46 plazosTemp += res.data[i].plazoPago[j].dias + ', ';
47 }
48 }
49 res.data[i].plazos = plazosTemp.trim();
50 }
51 $scope.precioCondicion = res.data;
52 $scope.search();
53 });
51 54
55 //METODOS
52 $scope.agregarPlazo = function(key) { 56 $scope.agregarPlazo = function(key) {
53 if(key === 13) { 57 if(key === 13) {
54 if(!$scope.plazoACargar.dias) { 58 if(!$scope.plazoACargar.dias) {
55 focaModalService.alert('Ingrese cantidad de días'); 59 focaModalService.alert('Ingrese cantidad de días');
56 return; 60 return;
57 } 61 }
58 var tieneEseDia = $scope.plazosNuevos.filter(function(a) { 62 var tieneEseDia = $scope.plazosNuevos.filter(function(a) {
59 return a.dias === $scope.plazoACargar.dias; 63 return a.dias === $scope.plazoACargar.dias;
60 }); 64 });
61 if(tieneEseDia.length > 0) { 65 if(tieneEseDia.length > 0) {
62 focaModalService.alert('Ya ha ingresado un plazo con esos días'); 66 focaModalService.alert('Ya ha ingresado un plazo con esos días');
63 return; 67 return;
64 } 68 }
65 $scope.plazosNuevos.push($scope.plazoACargar); 69 $scope.plazosNuevos.push($scope.plazoACargar);
66 $scope.plazoACargar = 70 $scope.plazoACargar =
67 { 71 {
68 item: $scope.plazosNuevos.length + 1 72 item: $scope.plazosNuevos.length + 1
69 }; 73 };
70 } 74 }
71 }; 75 };
72 76
73 $scope.volver = function() { 77 $scope.volver = function() {
74 $scope.ingreso = false; 78 $scope.ingreso = false;
75 $scope.plazosNuevos = []; 79 $scope.plazosNuevos = [];
76 $scope.plazoACargar = 80 $scope.plazoACargar =
77 { 81 {
78 item: $scope.plazosNuevos.length + 1 82 item: $scope.plazosNuevos.length + 1
79 }; 83 };
80 }; 84 };
81 85
82 $scope.quitarPlazo = function(key) { 86 $scope.quitarPlazo = function(key) {
83 $scope.plazosNuevos.splice(key, 1); 87 $scope.plazosNuevos.splice(key, 1);
84 $scope.plazoACargar = 88 $scope.plazoACargar =
85 { 89 {
86 item: $scope.plazosNuevos.length + 1 90 item: $scope.plazosNuevos.length + 1
87 }; 91 };
88 }; 92 };
89 93
90 $scope.search = function(pressed) { 94 $scope.search = function(pressed) {
91 $scope.filteredPrecioCondicion = $filter('filter')( 95 $scope.filteredPrecioCondicion = $filter('filter')(
92 $scope.precioCondicion, 96 $scope.precioCondicion,
93 {$: $scope.filters} 97 {$: $scope.filters}
94 ); 98 );
95 99
96 if(pressed) { 100 if(pressed) {
97 if($scope.filteredPrecioCondicion.length === 0) { 101 if($scope.filteredPrecioCondicion.length === 0) {
98 $timeout(function() { 102 $timeout(function() {
99 angular.element('#search')[0].focus(); 103 angular.element('#search')[0].focus();
100 $scope.filters = ''; 104 $scope.filters = '';
101 }); 105 });
102 }else { 106 }else {
103 primera(); 107 primera();
104 } 108 }
105 } 109 }
106 110
107 $scope.lastPage = Math.ceil( 111 $scope.lastPage = Math.ceil(
108 $scope.filteredPrecioCondicion.length / $scope.numPerPage 112 $scope.filteredPrecioCondicion.length / $scope.numPerPage
109 ); 113 );
110 114
111 $scope.resetPage(); 115 $scope.resetPage();
112 }; 116 };
113 117
114 $scope.resetPage = function() { 118 $scope.resetPage = function() {
115 $scope.currentPage = 1; 119 $scope.currentPage = 1;
116 $scope.selectPage(1); 120 $scope.selectPage(1);
117 }; 121 };
118 122
119 $scope.selectPage = function(page) { 123 $scope.selectPage = function(page) {
120 var start = (page - 1) * $scope.numPerPage; 124 var start = (page - 1) * $scope.numPerPage;
121 var end = start + $scope.numPerPage; 125 var end = start + $scope.numPerPage;
122 $scope.paginas = []; 126 $scope.paginas = [];
123 $scope.paginas = calcularPages(page); 127 $scope.paginas = calcularPages(page);
124 $scope.currentPagePrecioCondicion = 128 $scope.currentPagePrecioCondicion =
125 $scope.filteredPrecioCondicion.slice(start, end); 129 $scope.filteredPrecioCondicion.slice(start, end);
126 $scope.currentPage = page; 130 $scope.currentPage = page;
127 }; 131 };
128 132
129 $scope.select = function(precioCondicion) { 133 $scope.select = function(precioCondicion) {
130 $uibModalInstance.close(precioCondicion); 134 $uibModalInstance.close(precioCondicion);
131 }; 135 };
132 136
133 $scope.cancel = function() { 137 $scope.cancel = function() {
134 $uibModalInstance.dismiss('cancel'); 138 $uibModalInstance.dismiss('cancel');
135 }; 139 };
136 140
137 $scope.busquedaDown = function(key) { 141 $scope.busquedaDown = function(key) {
138 if (key === 40) { 142 if (key === 40) {
139 primera(key); 143 primera(key);
140 } 144 }
141 }; 145 };
142 146
143 $scope.busquedaPress = function(key) { 147 $scope.busquedaPress = function(key) {
144 if (key === 13) { 148 if (key === 13) {
145 $scope.search(true); 149 $scope.search(true);
146 } 150 }
147 }; 151 };
148 152
149 $scope.itemProducto = function(key) { 153 $scope.itemProducto = function(key) {
150 if (key === 38) { 154 if (key === 38) {
151 anterior(key); 155 anterior(key);
152 } 156 }
153 157
154 if (key === 40) { 158 if (key === 40) {
155 siguiente(key); 159 siguiente(key);
156 } 160 }
157 161
158 if (key === 37) { 162 if (key === 37) {
159 retrocederPagina(); 163 retrocederPagina();
160 } 164 }
161 165
162 if (key === 39) { 166 if (key === 39) {
163 avanzarPagina(); 167 avanzarPagina();
164 } 168 }
165 }; 169 };
166 170
167 $scope.verListaPrecio = function(id) { 171 $scope.verListaPrecio = function(id) {
168 $uibModal.open( 172 $uibModal.open(
169 { 173 {
170 ariaLabelledBy: 'Busqueda de Productos', 174 ariaLabelledBy: 'Busqueda de Productos',
171 templateUrl: 'modal-busqueda-productos.html', 175 templateUrl: 'modal-busqueda-productos.html',
172 controller: 'modalBusquedaProductosCtrl', 176 controller: 'modalBusquedaProductosCtrl',
173 resolve: { 177 resolve: {
174 parametroProducto: { 178 parametroProducto: {
175 idLista: id, 179 idLista: id,
176 cotizacion: 1, 180 cotizacion: 1,
177 simbolo: '$', 181 simbolo: '$',
178 soloMostrar: true 182 soloMostrar: true
179 } 183 }
180 }, 184 },
181 size: 'md' 185 size: 'md'
182 } 186 }
183 ); 187 );
184 }; 188 };
185 189
186 function calcularPages(paginaActual) { 190 function calcularPages(paginaActual) {
187 var paginas = []; 191 var paginas = [];
188 paginas.push(paginaActual); 192 paginas.push(paginaActual);
189 193
190 if (paginaActual - 1 > 1) { 194 if (paginaActual - 1 > 1) {
191 195
192 paginas.unshift(paginaActual - 1); 196 paginas.unshift(paginaActual - 1);
193 if (paginaActual - 2 > 1) { 197 if (paginaActual - 2 > 1) {
194 paginas.unshift(paginaActual - 2); 198 paginas.unshift(paginaActual - 2);
195 } 199 }
196 } 200 }
197 201
198 if (paginaActual + 1 < $scope.lastPage) { 202 if (paginaActual + 1 < $scope.lastPage) {
199 paginas.push(paginaActual + 1); 203 paginas.push(paginaActual + 1);
200 if (paginaActual + 2 < $scope.lastPage) { 204 if (paginaActual + 2 < $scope.lastPage) {
201 paginas.push(paginaActual + 2); 205 paginas.push(paginaActual + 2);
202 } 206 }
203 } 207 }
204 208
205 if (paginaActual !== 1) { 209 if (paginaActual !== 1) {
206 paginas.unshift(1); 210 paginas.unshift(1);
207 } 211 }
208 212
209 if (paginaActual !== $scope.lastPage) { 213 if (paginaActual !== $scope.lastPage) {
210 paginas.push($scope.lastPage); 214 paginas.push($scope.lastPage);
211 } 215 }
212 216
213 return paginas; 217 return paginas;
214 } 218 }
215 219
216 function primera() { 220 function primera() {
217 $scope.selectedPrecioCondicion = 0; 221 $scope.selectedPrecioCondicion = 0;
218 } 222 }
219 223
220 function anterior() { 224 function anterior() {
221 if ($scope.selectedPrecioCondicion === 0 && $scope.currentPage > 1) { 225 if ($scope.selectedPrecioCondicion === 0 && $scope.currentPage > 1) {
222 retrocederPagina(); 226 retrocederPagina();
223 } else { 227 } else {
224 $scope.selectedPrecioCondicion--; 228 $scope.selectedPrecioCondicion--;
225 } 229 }
226 } 230 }
227 231
228 function siguiente() { 232 function siguiente() {
229 if ($scope.selectedPrecioCondicion < 233 if ($scope.selectedPrecioCondicion <
230 $scope.currentPagePrecioCondicion.length ) { 234 $scope.currentPagePrecioCondicion.length ) {
231 $scope.selectedPrecioCondicion++; 235 $scope.selectedPrecioCondicion++;
232 } else { 236 } else {
233 avanzarPagina(); 237 avanzarPagina();
1 angular.module('focaModalPrecioCondicion') 1 angular.module('focaModalPrecioCondicion')
2 .service('focaModalPrecioCondicionService', [ 2 .service('focaModalPrecioCondicionService', [
3 '$http', 3 '$http',
4 'API_ENDPOINT', 4 'API_ENDPOINT',
5 function($http, API_ENDPOINT) { 5 function($http, API_ENDPOINT) {
6 return { 6 return {
7 getPreciosCondiciones: function() {
8 return $http.get(API_ENDPOINT.URL + '/precio-condicion');
9 },
10 getPlazosByIdPrecioCondicion: function(id) { 7 getPlazosByIdPrecioCondicion: function(id) {
11 return $http.get(API_ENDPOINT.URL + '/plazo-pago/precio-condicion/' + id); 8 return $http.get(API_ENDPOINT.URL + '/plazo-pago/precio-condicion/' + id);
12 }, 9 },
13 getPreciosCondicionesPlazosPagos: function() { 10 getPreciosCondiciones: function() {
14 return $http.get(API_ENDPOINT.URL + '/precio-condicion/plazo-pago'); 11 return $http.get(API_ENDPOINT.URL + '/precio-condicion/plazo-pago');
12 },
13 getPreciosCondicionesByIdListaPrecio: function(idListaPrecio) {
14 return $http.get(API_ENDPOINT.URL + '/precio-condicion/plazo-pago/' +
15 idListaPrecio);
15 } 16 }
16 }; 17 };