Commit ba29d625c5bb40188bfc2a453ec1ae4a69cc6362
Exists in
master
Merge branch 'master' into 'master'
Mastersaco buscador, orden y data resultados ok See merge request !7
Showing
2 changed files
Show diff stats
src/js/controller.js
| 1 | angular.module('focaModalFactura') | 1 | angular.module('focaModalFactura') |
| 2 | .controller('focaModalFacturaController', | 2 | .controller('focaModalFacturaController', |
| 3 | [ | 3 | [ |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaModalFacturaService', | 7 | 'focaModalFacturaService', |
| 8 | 'parametrosFactura', | 8 | 'parametrosFactura', |
| 9 | function($filter, $scope, $uibModalInstance, | 9 | function($filter, $scope, $uibModalInstance, |
| 10 | focaModalFacturaService, parametrosFactura | 10 | focaModalFacturaService, parametrosFactura |
| 11 | ) { | 11 | ) { |
| 12 | var fecha = new Date(); | 12 | var fecha = new Date(); |
| 13 | $scope.fechaHasta = new Date(); | 13 | $scope.fechaHasta = new Date(); |
| 14 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | 14 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); |
| 15 | $scope.filters = ''; | 15 | $scope.filters = ''; |
| 16 | $scope.facturas = []; | 16 | $scope.facturas = []; |
| 17 | $scope.primerBusqueda = false; | 17 | $scope.primerBusqueda = false; |
| 18 | $scope.searchLoading = false; | 18 | $scope.searchLoading = false; |
| 19 | $scope.parametrosFactura = parametrosFactura; | 19 | $scope.parametrosFactura = parametrosFactura; |
| 20 | // pagination | 20 | // pagination |
| 21 | $scope.numPerPage = 10; | 21 | $scope.numPerPage = 10; |
| 22 | $scope.currentPage = 1; | 22 | $scope.currentPage = 1; |
| 23 | $scope.filteredFacturas = []; | 23 | $scope.filteredFacturas = []; |
| 24 | $scope.currentPageFacturas = []; | 24 | $scope.currentPageFacturas = []; |
| 25 | $scope.selectedFactura = -1; | 25 | $scope.selectedFactura = -1; |
| 26 | 26 | ||
| 27 | //METODOS | 27 | //METODOS |
| 28 | $scope.busquedaPress = function(key) { | 28 | $scope.busquedaPress = function(key) { |
| 29 | if (key === 13) { | 29 | if (key === 13) { |
| 30 | //TODO Validaciones con alertas | 30 | //TODO Validaciones con alertas |
| 31 | if(!$scope.fechaDesde) { | 31 | if(!$scope.fechaDesde) { |
| 32 | alert('INGRESE FECHA DESDE'); | 32 | alert('INGRESE FECHA DESDE'); |
| 33 | return; | 33 | return; |
| 34 | } | 34 | } |
| 35 | if(!$scope.fechaHasta) { | 35 | if(!$scope.fechaHasta) { |
| 36 | alert('INGRESE FECHA HASTA'); | 36 | alert('INGRESE FECHA HASTA'); |
| 37 | return; | 37 | return; |
| 38 | } | 38 | } |
| 39 | if($scope.fechaDesde > $scope.fechaHasta) { | 39 | if($scope.fechaDesde > $scope.fechaHasta) { |
| 40 | alert('La fecha desde no puede ser mayor a la fecha hasta'); | 40 | alert('La fecha desde no puede ser mayor a la fecha hasta'); |
| 41 | return; | 41 | return; |
| 42 | } | 42 | } |
| 43 | $scope.searchLoading = true; | 43 | $scope.searchLoading = true; |
| 44 | //TODO hacer filtro de fecha | 44 | //TODO hacer filtro de fecha |
| 45 | focaModalFacturaService | 45 | focaModalFacturaService |
| 46 | .getFacturasByIdCliente( | 46 | .getFacturasByIdCliente( |
| 47 | parametrosFactura.cliente, | 47 | parametrosFactura.cliente, |
| 48 | '2001-01-01', | 48 | '2001-01-01', |
| 49 | '2100-12-31' | 49 | '2100-12-31' |
| 50 | ) | 50 | ) |
| 51 | .then(llenarDatos); | 51 | .then(llenarDatos); |
| 52 | } | 52 | } |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | $scope.aceptar = function() { | 55 | $scope.aceptar = function() { |
| 56 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); | 56 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); |
| 57 | $uibModalInstance.close(result); | 57 | $uibModalInstance.close(result); |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | $scope.tieneAlMenosUno = function() { | 60 | $scope.tieneAlMenosUno = function() { |
| 61 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); | 61 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); |
| 62 | return !result.length; | 62 | return !result.length; |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | function llenarDatos(res) { | 65 | function llenarDatos(res) { |
| 66 | $scope.facturas = []; | 66 | $scope.facturas = []; |
| 67 | $scope.filteredFacturas = []; | 67 | $scope.filteredFacturas = []; |
| 68 | $scope.currentPageFacturas = []; | 68 | $scope.currentPageFacturas = []; |
| 69 | $scope.selectedFactura = -1; | 69 | $scope.selectedFactura = -1; |
| 70 | $scope.searchLoading = false; | 70 | $scope.searchLoading = false; |
| 71 | $scope.primerBusqueda = true; | 71 | $scope.primerBusqueda = true; |
| 72 | $scope.facturas = res.data; | 72 | $scope.facturas = calcularSaldos(res.data); |
| 73 | $scope.search(); | 73 | $scope.search(); |
| 74 | primera(); | 74 | primera(); |
| 75 | } | 75 | } |
| 76 | $scope.search = function() { | 76 | $scope.search = function() { |
| 77 | if($scope.facturas.length > 0) { | 77 | if($scope.facturas.length > 0) { |
| 78 | $scope.filteredFacturas = $filter('filter')( | 78 | $scope.filteredFacturas = $filter('filter')( |
| 79 | $scope.facturas, | 79 | $scope.facturas, |
| 80 | {$: $scope.filters} | 80 | {$: $scope.filters} |
| 81 | ); | 81 | ); |
| 82 | 82 | ||
| 83 | $scope.lastPage = Math.ceil( | 83 | $scope.lastPage = Math.ceil( |
| 84 | $scope.filteredFacturas.length / $scope.numPerPage | 84 | $scope.filteredFacturas.length / $scope.numPerPage |
| 85 | ); | 85 | ); |
| 86 | 86 | ||
| 87 | $scope.resetPage(); | 87 | $scope.resetPage(); |
| 88 | } | 88 | } |
| 89 | }; | 89 | }; |
| 90 | 90 | ||
| 91 | $scope.resetPage = function() { | 91 | $scope.resetPage = function() { |
| 92 | $scope.currentPage = 1; | 92 | $scope.currentPage = 1; |
| 93 | $scope.selectPage(1); | 93 | $scope.selectPage(1); |
| 94 | }; | 94 | }; |
| 95 | 95 | ||
| 96 | $scope.selectPage = function(page) { | 96 | $scope.selectPage = function(page) { |
| 97 | var start = (page - 1) * $scope.numPerPage; | 97 | var start = (page - 1) * $scope.numPerPage; |
| 98 | var end = start + $scope.numPerPage; | 98 | var end = start + $scope.numPerPage; |
| 99 | $scope.paginas = []; | 99 | $scope.paginas = []; |
| 100 | $scope.paginas = calcularPages(page); | 100 | $scope.paginas = calcularPages(page); |
| 101 | $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end); | 101 | $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end); |
| 102 | $scope.currentPage = page; | 102 | $scope.currentPage = page; |
| 103 | }; | 103 | }; |
| 104 | 104 | ||
| 105 | $scope.cancel = function() { | 105 | $scope.cancel = function() { |
| 106 | $uibModalInstance.dismiss('cancel'); | 106 | $uibModalInstance.dismiss('cancel'); |
| 107 | }; | 107 | }; |
| 108 | 108 | ||
| 109 | $scope.busquedaDown = function(key) { | 109 | $scope.busquedaDown = function(key) { |
| 110 | if (key === 40) { | 110 | if (key === 40) { |
| 111 | primera(key); | 111 | primera(key); |
| 112 | } | 112 | } |
| 113 | }; | 113 | }; |
| 114 | 114 | ||
| 115 | $scope.itemFactura = function(key) { | 115 | $scope.itemFactura = function(key) { |
| 116 | if (key === 38) { | 116 | if (key === 38) { |
| 117 | anterior(key); | 117 | anterior(key); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | if (key === 40) { | 120 | if (key === 40) { |
| 121 | siguiente(key); | 121 | siguiente(key); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | if (key === 37) { | 124 | if (key === 37) { |
| 125 | retrocederPagina(); | 125 | retrocederPagina(); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | if (key === 39) { | 128 | if (key === 39) { |
| 129 | avanzarPagina(); | 129 | avanzarPagina(); |
| 130 | } | 130 | } |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | function calcularPages(paginaActual) { | 133 | function calcularPages(paginaActual) { |
| 134 | var paginas = []; | 134 | var paginas = []; |
| 135 | paginas.push(paginaActual); | 135 | paginas.push(paginaActual); |
| 136 | 136 | ||
| 137 | if (paginaActual - 1 > 1) { | 137 | if (paginaActual - 1 > 1) { |
| 138 | 138 | ||
| 139 | paginas.unshift(paginaActual - 1); | 139 | paginas.unshift(paginaActual - 1); |
| 140 | if (paginaActual - 2 > 1) { | 140 | if (paginaActual - 2 > 1) { |
| 141 | paginas.unshift(paginaActual - 2); | 141 | paginas.unshift(paginaActual - 2); |
| 142 | } | 142 | } |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | if (paginaActual + 1 < $scope.lastPage) { | 145 | if (paginaActual + 1 < $scope.lastPage) { |
| 146 | paginas.push(paginaActual + 1); | 146 | paginas.push(paginaActual + 1); |
| 147 | if (paginaActual + 2 < $scope.lastPage) { | 147 | if (paginaActual + 2 < $scope.lastPage) { |
| 148 | paginas.push(paginaActual + 2); | 148 | paginas.push(paginaActual + 2); |
| 149 | } | 149 | } |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | if (paginaActual !== 1) { | 152 | if (paginaActual !== 1) { |
| 153 | paginas.unshift(1); | 153 | paginas.unshift(1); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | if (paginaActual !== $scope.lastPage) { | 156 | if (paginaActual !== $scope.lastPage) { |
| 157 | paginas.push($scope.lastPage); | 157 | paginas.push($scope.lastPage); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | return paginas; | 160 | return paginas; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | function primera() { | 163 | function primera() { |
| 164 | $scope.selectedFactura = 0; | 164 | $scope.selectedFactura = 0; |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | function anterior() { | 167 | function anterior() { |
| 168 | if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { | 168 | if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { |
| 169 | retrocederPagina(); | 169 | retrocederPagina(); |
| 170 | } else { | 170 | } else { |
| 171 | $scope.selectedFactura--; | 171 | $scope.selectedFactura--; |
| 172 | } | 172 | } |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | function siguiente() { | 175 | function siguiente() { |
| 176 | if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { | 176 | if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { |
| 177 | $scope.selectedFactura++; | 177 | $scope.selectedFactura++; |
| 178 | } else { | 178 | } else { |
| 179 | avanzarPagina(); | 179 | avanzarPagina(); |
| 180 | } | 180 | } |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | function retrocederPagina() { | 183 | function retrocederPagina() { |
| 184 | if ($scope.currentPage > 1) { | 184 | if ($scope.currentPage > 1) { |
| 185 | $scope.selectPage($scope.currentPage - 1); | 185 | $scope.selectPage($scope.currentPage - 1); |
| 186 | $scope.selectedFactura = $scope.numPerPage - 1; | 186 | $scope.selectedFactura = $scope.numPerPage - 1; |
| 187 | } | 187 | } |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | function avanzarPagina() { | 190 | function avanzarPagina() { |
| 191 | if ($scope.currentPage < $scope.lastPage) { | 191 | if ($scope.currentPage < $scope.lastPage) { |
| 192 | $scope.selectPage($scope.currentPage + 1); | 192 | $scope.selectPage($scope.currentPage + 1); |
| 193 | $scope.selectedFactura = 0; | 193 | $scope.selectedFactura = 0; |
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| 196 | |||
| 197 | function calcularSaldos(facturas) { | ||
| 198 | var saldo = 0; | ||
| 199 | |||
| 200 | facturas.forEach(function(factura) { | ||
| 201 | if (factura.TCO === 'CI' || | ||
| 202 | factura.TCO === 'FT' || | ||
| 203 | factura.TCO === 'ND'){ | ||
| 204 | factura.IPA = factura.IPA * -1; | ||
| 205 | }else{ | ||
| 206 | factura.IPA = factura.IPA; | ||
| 207 | } | ||
| 208 | saldo += factura.IPA; | ||
| 209 | factura.saldo = saldo; | ||
| 210 | }); | ||
| 211 | |||
| 212 | return facturas; | ||
| 213 | } | ||
| 214 | |||
| 215 | $scope.busquedaPress(13); | ||
| 196 | } | 216 | } |
| 197 | ] | 217 | ] |
| 198 | ); | 218 | ); |
| 199 | 219 |
src/views/foca-modal-factura.html
| 1 | <div class="modal-header py-1"> | 1 | <div class="modal-header py-1"> |
| 2 | <div class="row w-100"> | 2 | <div class="row w-100"> |
| 3 | <div class="col-lg-6"> | 3 | <div class="col-lg-6"> |
| 4 | <h5 class="modal-title">Búsqueda de Comprobantes</h5> | 4 | <h5 class="modal-title">Búsqueda de Comprobantes</h5> |
| 5 | </div> | 5 | </div> |
| 6 | <div class="input-group col-lg-6 pr-0 my-2"> | ||
| 7 | <input | ||
| 8 | ladda="searchLoading" | ||
| 9 | type="text" | ||
| 10 | class="form-control form-control-sm" | ||
| 11 | placeholder="Búsqueda" | ||
| 12 | ng-model="filters" | ||
| 13 | ng-change="search()" | ||
| 14 | ng-keydown="busquedaDown($event.keyCode)" | ||
| 15 | ng-keypress="busquedaPress($event.keyCode)" | ||
| 16 | foca-focus="selectedFactura == -1" | ||
| 17 | ng-focus="selectedFactura = -1" | ||
| 18 | teclado-virtual | ||
| 19 | /> | ||
| 20 | <div class="input-group-append"> | ||
| 21 | <button | ||
| 22 | ladda="searchLoading" | ||
| 23 | class="btn btn-outline-secondary" | ||
| 24 | type="button" | ||
| 25 | ng-click="busquedaPress(13)" | ||
| 26 | > | ||
| 27 | <i class="fa fa-search" aria-hidden="true"></i> | ||
| 28 | </button> | ||
| 29 | </div> | ||
| 30 | </div> | ||
| 31 | </div> | 6 | </div> |
| 32 | </div> | 7 | </div> |
| 33 | <div class="modal-body" id="modal-body"> | 8 | <div class="modal-body" id="modal-body"> |
| 34 | <div ng-show="!primerBusqueda"> | ||
| 35 | Debe realizar una primer búsqueda. | ||
| 36 | </div> | ||
| 37 | |||
| 38 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> | 9 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> |
| 39 | <thead> | 10 | <thead> |
| 40 | <tr> | 11 | <tr> |
| 41 | <th>Fecha</th> | 12 | <th>Comprobante</th> |
| 42 | <th>Nro</th> | 13 | <th>Vencimiento</th> |
| 43 | <th class="text-right">Importe</th> | 14 | <th class="text-right">Importe</th> |
| 15 | <th class="text-right">Saldo</th> | ||
| 44 | <th class="text-right"></th> | 16 | <th class="text-right"></th> |
| 45 | </tr> | 17 | </tr> |
| 46 | </thead> | 18 | </thead> |
| 47 | <tbody> | 19 | <tbody> |
| 48 | <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda"> | 20 | <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda"> |
| 49 | <td colspan="5"> | 21 | <td colspan="5"> |
| 50 | No se encontraron resultados. | 22 | No se encontraron resultados. |
| 51 | </td> | 23 | </td> |
| 52 | </tr> | 24 | </tr> |
| 53 | <tr class="selectable" | 25 | <tr class="selectable" |
| 54 | ng-repeat="(key,factura) in currentPageFacturas"> | 26 | ng-repeat="(key,factura) in currentPageFacturas" |
| 55 | <td ng-bind="factura.FEP | date : 'dd/MM/yyyy'"></td> | 27 | ng-click="factura.checked = !factura.checked"> |
| 56 | <td ng-bind= "factura.numeroFactura"></td> | 28 | <td>{{factura.numeroFactura}} {{factura.FEP | date : 'dd/MM/yyyy' : 'GMT'}}</td> |
| 57 | <td | 29 | <td>{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td> |
| 58 | class="text-right" | 30 | <td class="text-right"> |
| 59 | ng-bind="(factura.IPA / parametrosFactura.cotizacion) | | 31 | <span ng-if="factura.IPA >= 0">+</span>{{(factura.IPA / parametrosFactura.cotizacion) | number:2}} |
| 60 | currency: parametrosFactura.simbolo"></td> | 32 | </td> |
| 33 | <td class="text-right"> | ||
| 34 | <span ng-if="factura.saldo >= 0">+</span>{{factura.saldo | number:2}} | ||
| 35 | </td> | ||
| 61 | <td class="text-right"> | 36 | <td class="text-right"> |
| 62 | <input | 37 | <input |
| 63 | ng-class="{ | 38 | ng-class="{ |
| 64 | 'btn-secondary': selectedFactura != key, | 39 | 'btn-secondary': selectedFactura != key, |
| 65 | 'btn-primary': selectedFactura == key}" | 40 | 'btn-primary': selectedFactura == key}" |
| 66 | ng-keydown="itemFactura($event.keyCode)" | 41 | ng-keydown="itemFactura($event.keyCode)" |
| 67 | foca-focus="selectedFactura == {{key}}" | 42 | foca-focus="selectedFactura == {{key}}" |
| 68 | type="checkbox" | 43 | type="checkbox" |
| 69 | ng-model="factura.checked" | 44 | ng-model="factura.checked" |
| 70 | /> | 45 | /> |
| 71 | </td> | 46 | </td> |
| 72 | </tr> | 47 | </tr> |
| 73 | </tbody> | 48 | </tbody> |
| 74 | </table> | 49 | </table> |
| 75 | </div> | 50 | </div> |
| 76 | <div class="modal-footer py-1"> | 51 | <div class="modal-footer py-1"> |
| 77 | <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto"> | 52 | <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto"> |
| 78 | <ul class="pagination pagination-sm justify-content mb-0"> | 53 | <ul class="pagination pagination-sm justify-content mb-0"> |
| 79 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 54 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> |
| 80 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> | 55 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> |
| 81 | <span aria-hidden="true">«</span> | 56 | <span aria-hidden="true">«</span> |
| 82 | <span class="sr-only">Anterior</span> | 57 | <span class="sr-only">Anterior</span> |
| 83 | </a> | 58 | </a> |
| 84 | </li> | 59 | </li> |
| 85 | <li | 60 | <li |
| 86 | class="page-item" | 61 | class="page-item" |
| 87 | ng-repeat="pagina in paginas" | 62 | ng-repeat="pagina in paginas" |
| 88 | ng-class="{'active': pagina == currentPage}" | 63 | ng-class="{'active': pagina == currentPage}" |
| 89 | > | 64 | > |
| 90 | <a | 65 | <a |
| 91 | class="page-link" | 66 | class="page-link" |
| 92 | href="javascript:void();" | 67 | href="javascript:void();" |
| 93 | ng-click="selectPage(pagina)" | 68 | ng-click="selectPage(pagina)" |
| 94 | ng-bind="pagina" | 69 | ng-bind="pagina" |
| 95 | ></a> | 70 | ></a> |
| 96 | </li> | 71 | </li> |
| 97 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 72 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> |
| 98 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> | 73 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> |
| 99 | <span aria-hidden="true">»</span> | 74 | <span aria-hidden="true">»</span> |
| 100 | <span class="sr-only">Siguiente</span> | 75 | <span class="sr-only">Siguiente</span> |
| 101 | </a> | 76 | </a> |
| 102 | </li> | 77 | </li> |
| 103 | </ul> | 78 | </ul> |
| 104 | </nav> | 79 | </nav> |
| 105 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 80 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> |
| 106 | <button | 81 | <button |
| 107 | class="btn btn-sm btn-primary" | 82 | class="btn btn-sm btn-primary" |
| 108 | type="button" | 83 | type="button" |
| 109 | ng-click="aceptar()" | 84 | ng-click="aceptar()" |