Commit 93354f3ec589ce07f5b02b44ee14c5104a73a080
1 parent
577a371ed7
Exists in
develop
Fix
No encontraba remitos al buscar (Incidencia 52)
Showing
1 changed file
with
1 additions
and
1 deletions
 
Show diff stats
src/js/controller.js
| 1 | angular.module('focaModalRemito') | 1 | angular.module('focaModalRemito') | 
| 2 | .controller('focaModalRemitoController', | 2 | .controller('focaModalRemitoController', | 
| 3 | [ | 3 | [ | 
| 4 | '$timeout', | 4 | '$timeout', | 
| 5 | '$filter', | 5 | '$filter', | 
| 6 | '$scope', | 6 | '$scope', | 
| 7 | '$uibModalInstance', | 7 | '$uibModalInstance', | 
| 8 | 'focaModalRemitoService', | 8 | 'focaModalRemitoService', | 
| 9 | 'usadoPor', | 9 | 'usadoPor', | 
| 10 | 'focaModalService', | 10 | 'focaModalService', | 
| 11 | function ($timeout, $filter, $scope, $uibModalInstance, | 11 | function ($timeout, $filter, $scope, $uibModalInstance, | 
| 12 | focaModalRemitoService, usadoPor, focaModalService | 12 | focaModalRemitoService, usadoPor, focaModalService | 
| 13 | ) { | 13 | ) { | 
| 14 | var fecha = new Date(); | 14 | var fecha = new Date(); | 
| 15 | $scope.fechaHasta = new Date(); | 15 | $scope.fechaHasta = new Date(); | 
| 16 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | 16 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | 
| 17 | $scope.filtersCliente = ''; | 17 | $scope.filtersCliente = ''; | 
| 18 | $scope.filtersRemito = ''; | 18 | $scope.filtersRemito = ''; | 
| 19 | $scope.remitos = []; | 19 | $scope.remitos = []; | 
| 20 | $scope.isCollapsed = false; | 20 | $scope.isCollapsed = false; | 
| 21 | $scope.verProductos = {}; | 21 | $scope.verProductos = {}; | 
| 22 | $scope.primerBusqueda = false; | 22 | $scope.primerBusqueda = false; | 
| 23 | $scope.searchLoading = false; | 23 | $scope.searchLoading = false; | 
| 24 | // pagination | 24 | // pagination | 
| 25 | $scope.numPerPage = 10; | 25 | $scope.numPerPage = 10; | 
| 26 | $scope.currentPage = 1; | 26 | $scope.currentPage = 1; | 
| 27 | $scope.filteredRemitos = []; | 27 | $scope.filteredRemitos = []; | 
| 28 | $scope.currentPageRemitos = []; | 28 | $scope.currentPageRemitos = []; | 
| 29 | $scope.selectedRemito = -1; | 29 | $scope.selectedRemito = -1; | 
| 30 | 30 | ||
| 31 | //METODOS | 31 | //METODOS | 
| 32 | $scope.busquedaPress = function (key) { | 32 | $scope.busquedaPress = function (key) { | 
| 33 | if (key === 13) { | 33 | if (key === 13) { | 
| 34 | if (!$scope.fechaDesde) { | 34 | if (!$scope.fechaDesde) { | 
| 35 | focaModalService | 35 | focaModalService | 
| 36 | .alert('INGRESE FECHA DESDE'); | 36 | .alert('INGRESE FECHA DESDE'); | 
| 37 | return; | 37 | return; | 
| 38 | } | 38 | } | 
| 39 | if (!$scope.fechaHasta) { | 39 | if (!$scope.fechaHasta) { | 
| 40 | focaModalService | 40 | focaModalService | 
| 41 | .alert('INGRESE FECHA HASTA'); | 41 | .alert('INGRESE FECHA HASTA'); | 
| 42 | return; | 42 | return; | 
| 43 | } | 43 | } | 
| 44 | if ($scope.fechaDesde > $scope.fechaHasta) { | 44 | if ($scope.fechaDesde > $scope.fechaHasta) { | 
| 45 | focaModalService | 45 | focaModalService | 
| 46 | .alert('La fecha desde no puede ser mayor a la fecha hasta'); | 46 | .alert('La fecha desde no puede ser mayor a la fecha hasta'); | 
| 47 | return; | 47 | return; | 
| 48 | } | 48 | } | 
| 49 | $scope.searchLoading = true; | 49 | $scope.searchLoading = true; | 
| 50 | //TODO: usar filtros en vez de toISOString | 50 | //TODO: usar filtros en vez de toISOString | 
| 51 | focaModalRemitoService | 51 | focaModalRemitoService | 
| 52 | .getRemitos(usadoPor, $scope.fechaDesde.toISOString().split('.')[0], | 52 | .getRemitos(usadoPor, $scope.fechaDesde.toISOString().split('.')[0], | 
| 53 | $scope.fechaHasta.toISOString().split('.')[0]) | 53 | $scope.fechaHasta.toISOString().split('.')[0]) | 
| 54 | .then(llenarDatos); | 54 | .then(llenarDatos); | 
| 55 | } | 55 | } | 
| 56 | }; | 56 | }; | 
| 57 | 57 | ||
| 58 | function llenarDatos(res) { | 58 | function llenarDatos(res) { | 
| 59 | $scope.remitos = []; | 59 | $scope.remitos = []; | 
| 60 | $scope.filteredRemitos = []; | 60 | $scope.filteredRemitos = []; | 
| 61 | $scope.currentPageRemitos = []; | 61 | $scope.currentPageRemitos = []; | 
| 62 | $scope.selectedRemito = -1; | 62 | $scope.selectedRemito = -1; | 
| 63 | $scope.searchLoading = false; | 63 | $scope.searchLoading = false; | 
| 64 | $scope.primerBusqueda = true; | 64 | $scope.primerBusqueda = true; | 
| 65 | $scope.remitos = res.data; | 65 | $scope.remitos = res.data; | 
| 66 | $scope.search(true); | 66 | $scope.searchRemito(true); | 
| 67 | primera(); | 67 | primera(); | 
| 68 | } | 68 | } | 
| 69 | 69 | ||
| 70 | $scope.searchRemito = function (pressed) { | 70 | $scope.searchRemito = function (pressed) { | 
| 71 | if ($scope.remitos.length > 0) { | 71 | if ($scope.remitos.length > 0) { | 
| 72 | $scope.filteredRemitos = $filter('filter')( | 72 | $scope.filteredRemitos = $filter('filter')( | 
| 73 | $scope.remitos, | 73 | $scope.remitos, | 
| 74 | { numeroRemito: $scope.filtersRemito } | 74 | { numeroRemito: $scope.filtersRemito } | 
| 75 | ); | 75 | ); | 
| 76 | 76 | ||
| 77 | if (pressed && $scope.filteredRemitos.length === 0) { | 77 | if (pressed && $scope.filteredRemitos.length === 0) { | 
| 78 | $timeout(function () { | 78 | $timeout(function () { | 
| 79 | angular.element('#search')[0].focus(); | 79 | angular.element('#search')[0].focus(); | 
| 80 | $scope.filtersRemito = ''; | 80 | $scope.filtersRemito = ''; | 
| 81 | }); | 81 | }); | 
| 82 | } | 82 | } | 
| 83 | 83 | ||
| 84 | $scope.lastPage = Math.ceil( | 84 | $scope.lastPage = Math.ceil( | 
| 85 | $scope.filteredRemitos.length / $scope.numPerPage | 85 | $scope.filteredRemitos.length / $scope.numPerPage | 
| 86 | ); | 86 | ); | 
| 87 | 87 | ||
| 88 | $scope.resetPage(); | 88 | $scope.resetPage(); | 
| 89 | } | 89 | } | 
| 90 | } | 90 | } | 
| 91 | 91 | ||
| 92 | $scope.searchCliente = function (pressed) { | 92 | $scope.searchCliente = function (pressed) { | 
| 93 | if ($scope.remitos.length > 0) { | 93 | if ($scope.remitos.length > 0) { | 
| 94 | $scope.filteredRemitos = $filter('filter')( | 94 | $scope.filteredRemitos = $filter('filter')( | 
| 95 | $scope.remitos, | 95 | $scope.remitos, | 
| 96 | { nombreCliente: $scope.filtersCliente } | 96 | { nombreCliente: $scope.filtersCliente } | 
| 97 | ); | 97 | ); | 
| 98 | 98 | ||
| 99 | if (pressed && $scope.filteredRemitos.length === 0) { | 99 | if (pressed && $scope.filteredRemitos.length === 0) { | 
| 100 | $timeout(function () { | 100 | $timeout(function () { | 
| 101 | angular.element('#search')[0].focus(); | 101 | angular.element('#search')[0].focus(); | 
| 102 | $scope.filtersCliente = ''; | 102 | $scope.filtersCliente = ''; | 
| 103 | }); | 103 | }); | 
| 104 | } | 104 | } | 
| 105 | 105 | ||
| 106 | $scope.lastPage = Math.ceil( | 106 | $scope.lastPage = Math.ceil( | 
| 107 | $scope.filteredRemitos.length / $scope.numPerPage | 107 | $scope.filteredRemitos.length / $scope.numPerPage | 
| 108 | ); | 108 | ); | 
| 109 | 109 | ||
| 110 | $scope.resetPage(); | 110 | $scope.resetPage(); | 
| 111 | } | 111 | } | 
| 112 | }; | 112 | }; | 
| 113 | 113 | ||
| 114 | $scope.resetPage = function () { | 114 | $scope.resetPage = function () { | 
| 115 | $scope.currentPage = 1; | 115 | $scope.currentPage = 1; | 
| 116 | $scope.selectPage(1); | 116 | $scope.selectPage(1); | 
| 117 | }; | 117 | }; | 
| 118 | 118 | ||
| 119 | $scope.selectPage = function (page) { | 119 | $scope.selectPage = function (page) { | 
| 120 | var start = (page - 1) * $scope.numPerPage; | 120 | var start = (page - 1) * $scope.numPerPage; | 
| 121 | var end = start + $scope.numPerPage; | 121 | var end = start + $scope.numPerPage; | 
| 122 | $scope.paginas = []; | 122 | $scope.paginas = []; | 
| 123 | $scope.paginas = calcularPages(page); | 123 | $scope.paginas = calcularPages(page); | 
| 124 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); | 124 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); | 
| 125 | $scope.currentPage = page; | 125 | $scope.currentPage = page; | 
| 126 | }; | 126 | }; | 
| 127 | 127 | ||
| 128 | $scope.select = function (remito) { | 128 | $scope.select = function (remito) { | 
| 129 | $uibModalInstance.close(remito); | 129 | $uibModalInstance.close(remito); | 
| 130 | }; | 130 | }; | 
| 131 | 131 | ||
| 132 | $scope.cancel = function () { | 132 | $scope.cancel = function () { | 
| 133 | $uibModalInstance.dismiss('cancel'); | 133 | $uibModalInstance.dismiss('cancel'); | 
| 134 | }; | 134 | }; | 
| 135 | 135 | ||
| 136 | $scope.busquedaDown = function (key) { | 136 | $scope.busquedaDown = function (key) { | 
| 137 | if (key === 40) { | 137 | if (key === 40) { | 
| 138 | primera(key); | 138 | primera(key); | 
| 139 | } | 139 | } | 
| 140 | }; | 140 | }; | 
| 141 | 141 | ||
| 142 | $scope.itemRemito = function (key) { | 142 | $scope.itemRemito = function (key) { | 
| 143 | if (key === 38) { | 143 | if (key === 38) { | 
| 144 | anterior(key); | 144 | anterior(key); | 
| 145 | } | 145 | } | 
| 146 | 146 | ||
| 147 | if (key === 40) { | 147 | if (key === 40) { | 
| 148 | siguiente(key); | 148 | siguiente(key); | 
| 149 | } | 149 | } | 
| 150 | 150 | ||
| 151 | if (key === 37) { | 151 | if (key === 37) { | 
| 152 | retrocederPagina(); | 152 | retrocederPagina(); | 
| 153 | } | 153 | } | 
| 154 | 154 | ||
| 155 | if (key === 39) { | 155 | if (key === 39) { | 
| 156 | avanzarPagina(); | 156 | avanzarPagina(); | 
| 157 | } | 157 | } | 
| 158 | }; | 158 | }; | 
| 159 | 159 | ||
| 160 | function calcularPages(paginaActual) { | 160 | function calcularPages(paginaActual) { | 
| 161 | var paginas = []; | 161 | var paginas = []; | 
| 162 | paginas.push(paginaActual); | 162 | paginas.push(paginaActual); | 
| 163 | 163 | ||
| 164 | if (paginaActual - 1 > 1) { | 164 | if (paginaActual - 1 > 1) { | 
| 165 | 165 | ||
| 166 | paginas.unshift(paginaActual - 1); | 166 | paginas.unshift(paginaActual - 1); | 
| 167 | if (paginaActual - 2 > 1) { | 167 | if (paginaActual - 2 > 1) { | 
| 168 | paginas.unshift(paginaActual - 2); | 168 | paginas.unshift(paginaActual - 2); | 
| 169 | } | 169 | } | 
| 170 | } | 170 | } | 
| 171 | 171 | ||
| 172 | if (paginaActual + 1 < $scope.lastPage) { | 172 | if (paginaActual + 1 < $scope.lastPage) { | 
| 173 | paginas.push(paginaActual + 1); | 173 | paginas.push(paginaActual + 1); | 
| 174 | if (paginaActual + 2 < $scope.lastPage) { | 174 | if (paginaActual + 2 < $scope.lastPage) { | 
| 175 | paginas.push(paginaActual + 2); | 175 | paginas.push(paginaActual + 2); | 
| 176 | } | 176 | } | 
| 177 | } | 177 | } | 
| 178 | 178 | ||
| 179 | if (paginaActual !== 1) { | 179 | if (paginaActual !== 1) { | 
| 180 | paginas.unshift(1); | 180 | paginas.unshift(1); | 
| 181 | } | 181 | } | 
| 182 | 182 | ||
| 183 | if (paginaActual !== $scope.lastPage) { | 183 | if (paginaActual !== $scope.lastPage) { | 
| 184 | paginas.push($scope.lastPage); | 184 | paginas.push($scope.lastPage); | 
| 185 | } | 185 | } | 
| 186 | 186 | ||
| 187 | return paginas; | 187 | return paginas; | 
| 188 | } | 188 | } | 
| 189 | 189 | ||
| 190 | function primera() { | 190 | function primera() { | 
| 191 | $scope.selectedRemito = 0; | 191 | $scope.selectedRemito = 0; | 
| 192 | } | 192 | } | 
| 193 | 193 | ||
| 194 | function anterior() { | 194 | function anterior() { | 
| 195 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { | 195 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { | 
| 196 | retrocederPagina(); | 196 | retrocederPagina(); | 
| 197 | } else { | 197 | } else { | 
| 198 | $scope.selectedRemito--; | 198 | $scope.selectedRemito--; | 
| 199 | } | 199 | } | 
| 200 | } | 200 | } | 
| 201 | 201 | ||
| 202 | function siguiente() { | 202 | function siguiente() { | 
| 203 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1) { | 203 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1) { | 
| 204 | $scope.selectedRemito++; | 204 | $scope.selectedRemito++; | 
| 205 | } else { | 205 | } else { | 
| 206 | avanzarPagina(); | 206 | avanzarPagina(); | 
| 207 | } | 207 | } | 
| 208 | } | 208 | } | 
| 209 | 209 | ||
| 210 | function retrocederPagina() { | 210 | function retrocederPagina() { | 
| 211 | if ($scope.currentPage > 1) { | 211 | if ($scope.currentPage > 1) { | 
| 212 | $scope.selectPage($scope.currentPage - 1); | 212 | $scope.selectPage($scope.currentPage - 1); | 
| 213 | $scope.selectedRemito = $scope.numPerPage - 1; | 213 | $scope.selectedRemito = $scope.numPerPage - 1; | 
| 214 | } | 214 | } | 
| 215 | } | 215 | } | 
| 216 | 216 | ||
| 217 | function avanzarPagina() { | 217 | function avanzarPagina() { | 
| 218 | if ($scope.currentPage < $scope.lastPage) { | 218 | if ($scope.currentPage < $scope.lastPage) { | 
| 219 | $scope.selectPage($scope.currentPage + 1); | 219 | $scope.selectPage($scope.currentPage + 1); | 
| 220 | $scope.selectedRemito = 0; | 220 | $scope.selectedRemito = 0; | 
| 221 | } | 221 | } | 
| 222 | } | 222 | } | 
| 223 | } | 223 | } | 
| 224 | ] | 224 | ] | 
| 225 | ); | 225 | ); | 
| 226 | 226 |