Commit 32851bf3651fc912ff25614b58486e76f6dec0ec
1 parent
19fa3b55c5
Exists in
master
Trae transportistas bien, codigo con 5 caracteres
Showing
3 changed files
with
6 additions
and
2 deletions
 
Show diff stats
src/js/controller.js
| 1 | angular.module('focaModalProveedor') | 1 | angular.module('focaModalProveedor') | 
| 2 | .controller('focaModalProveedorCtrl', [ | 2 | .controller('focaModalProveedorCtrl', [ | 
| 3 | '$timeout', | 3 | '$timeout', | 
| 4 | '$filter', | 4 | '$filter', | 
| 5 | '$scope', | 5 | '$scope', | 
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', | 
| 7 | 'focaModalProveedorService', | 7 | 'focaModalProveedorService', | 
| 8 | 'transportista', | 8 | 'transportista', | 
| 9 | function ($timeout, $filter, $scope, $uibModalInstance, | 9 | function ($timeout, $filter, $scope, $uibModalInstance, | 
| 10 | focaModalProveedorService, transportista) { | 10 | focaModalProveedorService, transportista) { | 
| 11 | 11 | ||
| 12 | $scope.filters = ''; | 12 | $scope.filters = ''; | 
| 13 | $scope.primerBusqueda = false; | 13 | $scope.primerBusqueda = false; | 
| 14 | // pagination | 14 | // pagination | 
| 15 | $scope.numPerPage = 10; | 15 | $scope.numPerPage = 10; | 
| 16 | $scope.currentPage = 1; | 16 | $scope.currentPage = 1; | 
| 17 | $scope.filteredProveedores = []; | 17 | $scope.filteredProveedores = []; | 
| 18 | $scope.currentPageProveedores = []; | 18 | $scope.currentPageProveedores = []; | 
| 19 | $scope.selectedProveedores = -1; | 19 | $scope.selectedProveedores = -1; | 
| 20 | $scope.transportista = transportista | false; | 20 | $scope.transportista = transportista | false; | 
| 21 | 21 | ||
| 22 | $scope.busquedaPress = function(key) { | 22 | $scope.busquedaPress = function(key) { | 
| 23 | if (key === 13) { | 23 | if (key === 13) { | 
| 24 | $scope.searchLoading = true; | 24 | $scope.searchLoading = true; | 
| 25 | var json = { | 25 | var json = { | 
| 26 | razonCuitCod: $scope.filters | 26 | razonCuitCod: $scope.filters | 
| 27 | }; | 27 | }; | 
| 28 | focaModalProveedorService.getProveedores(json).then( | 28 | var funcion = transportista ? 'getTransportistas' : 'getProveedores'; | 
| 29 | focaModalProveedorService[funcion](json).then( | ||
| 29 | function(res) { | 30 | function(res) { | 
| 30 | for (var i = res.data.length - 1; i >= 0; i--) { | 31 | for (var i = res.data.length - 1; i >= 0; i--) { | 
| 31 | if (res.data[i].COD === 0) { | 32 | if (res.data[i].COD === 0) { | 
| 32 | delete res.data[i]; | 33 | delete res.data[i]; | 
| 33 | } | 34 | } | 
| 34 | } | 35 | } | 
| 35 | $scope.primerBusqueda = true; | 36 | $scope.primerBusqueda = true; | 
| 36 | $scope.proveedores = res.data; | 37 | $scope.proveedores = res.data; | 
| 37 | $scope.search(true); | 38 | $scope.search(true); | 
| 38 | primera(); | 39 | primera(); | 
| 39 | $scope.searchLoading = false; | 40 | $scope.searchLoading = false; | 
| 40 | }); | 41 | }); | 
| 41 | } | 42 | } | 
| 42 | }; | 43 | }; | 
| 43 | $scope.busquedaPress(13); | 44 | $scope.busquedaPress(13); | 
| 44 | $scope.search = function (pressed) { | 45 | $scope.search = function (pressed) { | 
| 45 | if($scope.primerBusqueda) { | 46 | if($scope.primerBusqueda) { | 
| 46 | $scope.filteredProveedores = $filter('filter')( | 47 | $scope.filteredProveedores = $filter('filter')( | 
| 47 | $scope.proveedores, {$: $scope.filters} | 48 | $scope.proveedores, {$: $scope.filters} | 
| 48 | ); | 49 | ); | 
| 49 | 50 | ||
| 50 | if(pressed && $scope.filteredProveedores.length === 0){ | 51 | if(pressed && $scope.filteredProveedores.length === 0){ | 
| 51 | $timeout(function() { | 52 | $timeout(function() { | 
| 52 | angular.element('#search')[0].focus(); | 53 | angular.element('#search')[0].focus(); | 
| 53 | $scope.filters = ''; | 54 | $scope.filters = ''; | 
| 54 | }); | 55 | }); | 
| 55 | } | 56 | } | 
| 56 | 57 | ||
| 57 | $scope.lastPage = Math.ceil( | 58 | $scope.lastPage = Math.ceil( | 
| 58 | $scope.filteredProveedores.length / $scope.numPerPage | 59 | $scope.filteredProveedores.length / $scope.numPerPage | 
| 59 | ); | 60 | ); | 
| 60 | 61 | ||
| 61 | $scope.resetPage(); | 62 | $scope.resetPage(); | 
| 62 | } | 63 | } | 
| 63 | }; | 64 | }; | 
| 64 | 65 | ||
| 65 | $scope.resetPage = function () { | 66 | $scope.resetPage = function () { | 
| 66 | $scope.currentPage = 1; | 67 | $scope.currentPage = 1; | 
| 67 | $scope.selectPage(1); | 68 | $scope.selectPage(1); | 
| 68 | }; | 69 | }; | 
| 69 | 70 | ||
| 70 | $scope.selectPage = function (page) { | 71 | $scope.selectPage = function (page) { | 
| 71 | console.info(page); | 72 | console.info(page); | 
| 72 | var start = (page - 1) * $scope.numPerPage; | 73 | var start = (page - 1) * $scope.numPerPage; | 
| 73 | var end = start + $scope.numPerPage; | 74 | var end = start + $scope.numPerPage; | 
| 74 | $scope.paginas = []; | 75 | $scope.paginas = []; | 
| 75 | $scope.paginas = calcularPages(page); | 76 | $scope.paginas = calcularPages(page); | 
| 76 | $scope.currentPageProveedores = $scope.filteredProveedores.slice(start, end); | 77 | $scope.currentPageProveedores = $scope.filteredProveedores.slice(start, end); | 
| 77 | $scope.currentPage = page; | 78 | $scope.currentPage = page; | 
| 78 | }; | 79 | }; | 
| 79 | 80 | ||
| 80 | $scope.select = function(proveedor) { | 81 | $scope.select = function(proveedor) { | 
| 81 | $uibModalInstance.close(proveedor); | 82 | $uibModalInstance.close(proveedor); | 
| 82 | }; | 83 | }; | 
| 83 | 84 | ||
| 84 | $scope.cancel = function() { | 85 | $scope.cancel = function() { | 
| 85 | $uibModalInstance.dismiss('cancel'); | 86 | $uibModalInstance.dismiss('cancel'); | 
| 86 | }; | 87 | }; | 
| 87 | 88 | ||
| 88 | $scope.busquedaDown = function(key) { | 89 | $scope.busquedaDown = function(key) { | 
| 89 | if (key === 40) { | 90 | if (key === 40) { | 
| 90 | primera(key); | 91 | primera(key); | 
| 91 | } | 92 | } | 
| 92 | }; | 93 | }; | 
| 93 | 94 | ||
| 94 | $scope.itemProveedor = function(key) { | 95 | $scope.itemProveedor = function(key) { | 
| 95 | if (key === 38) { | 96 | if (key === 38) { | 
| 96 | anterior(key); | 97 | anterior(key); | 
| 97 | } | 98 | } | 
| 98 | 99 | ||
| 99 | if (key === 40) { | 100 | if (key === 40) { | 
| 100 | siguiente(key); | 101 | siguiente(key); | 
| 101 | } | 102 | } | 
| 102 | 103 | ||
| 103 | if (key === 37) { | 104 | if (key === 37) { | 
| 104 | retrocederPagina(); | 105 | retrocederPagina(); | 
| 105 | } | 106 | } | 
| 106 | 107 | ||
| 107 | if (key === 39) { | 108 | if (key === 39) { | 
| 108 | avanzarPagina(); | 109 | avanzarPagina(); | 
| 109 | } | 110 | } | 
| 110 | }; | 111 | }; | 
| 111 | 112 | ||
| 112 | function calcularPages(paginaActual) { | 113 | function calcularPages(paginaActual) { | 
| 113 | var paginas = []; | 114 | var paginas = []; | 
| 114 | paginas.push(paginaActual); | 115 | paginas.push(paginaActual); | 
| 115 | 116 | ||
| 116 | if (paginaActual - 1 > 1) { | 117 | if (paginaActual - 1 > 1) { | 
| 117 | 118 | ||
| 118 | paginas.unshift(paginaActual - 1); | 119 | paginas.unshift(paginaActual - 1); | 
| 119 | if (paginaActual - 2 > 1) { | 120 | if (paginaActual - 2 > 1) { | 
| 120 | paginas.unshift(paginaActual - 2); | 121 | paginas.unshift(paginaActual - 2); | 
| 121 | } | 122 | } | 
| 122 | } | 123 | } | 
| 123 | 124 | ||
| 124 | if (paginaActual + 1 < $scope.lastPage) { | 125 | if (paginaActual + 1 < $scope.lastPage) { | 
| 125 | paginas.push(paginaActual + 1); | 126 | paginas.push(paginaActual + 1); | 
| 126 | if (paginaActual + 2 < $scope.lastPage) { | 127 | if (paginaActual + 2 < $scope.lastPage) { | 
| 127 | paginas.push(paginaActual + 2); | 128 | paginas.push(paginaActual + 2); | 
| 128 | } | 129 | } | 
| 129 | } | 130 | } | 
| 130 | 131 | ||
| 131 | if (paginaActual !== 1) { | 132 | if (paginaActual !== 1) { | 
| 132 | paginas.unshift(1); | 133 | paginas.unshift(1); | 
| 133 | } | 134 | } | 
| 134 | 135 | ||
| 135 | if (paginaActual !== $scope.lastPage) { | 136 | if (paginaActual !== $scope.lastPage) { | 
| 136 | paginas.push($scope.lastPage); | 137 | paginas.push($scope.lastPage); | 
| 137 | } | 138 | } | 
| 138 | 139 | ||
| 139 | return paginas; | 140 | return paginas; | 
| 140 | } | 141 | } | 
| 141 | 142 | ||
| 142 | function primera() { | 143 | function primera() { | 
| 143 | $scope.selectedProveedores = 0; | 144 | $scope.selectedProveedores = 0; | 
| 144 | } | 145 | } | 
| 145 | 146 | ||
| 146 | function anterior() { | 147 | function anterior() { | 
| 147 | if ($scope.selectedProveedores === 0 && $scope.currentPage > 1) { | 148 | if ($scope.selectedProveedores === 0 && $scope.currentPage > 1) { | 
| 148 | retrocederPagina(); | 149 | retrocederPagina(); | 
| 149 | } else { | 150 | } else { | 
| 150 | $scope.selectedProveedores--; | 151 | $scope.selectedProveedores--; | 
| 151 | } | 152 | } | 
| 152 | } | 153 | } | 
| 153 | 154 | ||
| 154 | function siguiente() { | 155 | function siguiente() { | 
| 155 | if ($scope.selectedProveedores < $scope.currentPageProveedores.length - 1 ) { | 156 | if ($scope.selectedProveedores < $scope.currentPageProveedores.length - 1 ) { | 
| 156 | $scope.selectedProveedores++; | 157 | $scope.selectedProveedores++; | 
| 157 | } else { | 158 | } else { | 
| 158 | avanzarPagina(); | 159 | avanzarPagina(); | 
| 159 | } | 160 | } | 
| 160 | } | 161 | } | 
| 161 | 162 | ||
| 162 | function retrocederPagina() { | 163 | function retrocederPagina() { | 
| 163 | if ($scope.currentPage > 1) { | 164 | if ($scope.currentPage > 1) { | 
| 164 | $scope.selectPage($scope.currentPage - 1); | 165 | $scope.selectPage($scope.currentPage - 1); | 
| 165 | $scope.selectedProveedores = $scope.numPerPage - 1; | 166 | $scope.selectedProveedores = $scope.numPerPage - 1; | 
| 166 | } | 167 | } | 
| 167 | } | 168 | } | 
| 168 | 169 | ||
| 169 | function avanzarPagina() { | 170 | function avanzarPagina() { | 
| 170 | if ($scope.currentPage < $scope.lastPage) { | 171 | if ($scope.currentPage < $scope.lastPage) { | 
| 171 | $scope.selectPage($scope.currentPage + 1); | 172 | $scope.selectPage($scope.currentPage + 1); | 
| 172 | $scope.selectedProveedores = 0; | 173 | $scope.selectedProveedores = 0; | 
| 173 | } | 174 | } | 
| 174 | } | 175 | } | 
| 175 | }] | 176 | }] | 
| 176 | ); | 177 | ); | 
| 177 | 178 | 
src/js/service.js
| 1 | angular.module('focaModalProveedor') | 1 | angular.module('focaModalProveedor') | 
| 2 | .service('focaModalProveedorService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .service('focaModalProveedorService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 
| 3 | return { | 3 | return { | 
| 4 | getProveedores: function(json) { | 4 | getProveedores: function(json) { | 
| 5 | return $http.post(API_ENDPOINT.URL + '/proveedor', json); | 5 | return $http.post(API_ENDPOINT.URL + '/proveedor', json); | 
| 6 | }, | ||
| 7 | getTransportistas: function(json) { | ||
| 8 | return $http.get(API_ENDPOINT.URL + '/transportista', json); | ||
| 6 | } | 9 | } | 
| 7 | }; | 10 | }; | 
| 8 | }]); | 11 | }]); | 
| 9 | 12 | 
src/views/modal-proveedor.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 my-1" ng-hide="transportista">Búsqueda de Proveedor</h5> | 4 | <h5 class="modal-title my-1" ng-hide="transportista">Búsqueda de Proveedor</h5> | 
| 5 | <h5 class="modal-title my-1" ng-show="transportista">Búsqueda de Transportista</h5> | 5 | <h5 class="modal-title my-1" ng-show="transportista">Búsqueda de Transportista</h5> | 
| 6 | </div> | 6 | </div> | 
| 7 | <div class="input-group col-lg-6 pr-0 my-2"> | 7 | <div class="input-group col-lg-6 pr-0 my-2"> | 
| 8 | <input | 8 | <input | 
| 9 | ladda="searchLoading" | 9 | ladda="searchLoading" | 
| 10 | type="text" | 10 | type="text" | 
| 11 | class="form-control form-control-sm" | 11 | class="form-control form-control-sm" | 
| 12 | id="search" | 12 | id="search" | 
| 13 | placeholder="Busqueda" | 13 | placeholder="Busqueda" | 
| 14 | ng-model="filters" | 14 | ng-model="filters" | 
| 15 | ng-change="search()" | 15 | ng-change="search()" | 
| 16 | ng-keydown="busquedaDown($event.keyCode)" | 16 | ng-keydown="busquedaDown($event.keyCode)" | 
| 17 | ng-keypress="busquedaPress($event.keyCode)" | 17 | ng-keypress="busquedaPress($event.keyCode)" | 
| 18 | foca-focus="selectedProveedores == -1" | 18 | foca-focus="selectedProveedores == -1" | 
| 19 | ng-focus="selectedProveedores = -1" | 19 | ng-focus="selectedProveedores = -1" | 
| 20 | teclado-virtual | 20 | teclado-virtual | 
| 21 | > | 21 | > | 
| 22 | <div class="input-group-append"> | 22 | <div class="input-group-append"> | 
| 23 | <button | 23 | <button | 
| 24 | ladda="searchLoading" | 24 | ladda="searchLoading" | 
| 25 | data-spinner-color="#FF0000" | 25 | data-spinner-color="#FF0000" | 
| 26 | class="btn btn-outline-secondary" | 26 | class="btn btn-outline-secondary" | 
| 27 | type="button" | 27 | type="button" | 
| 28 | ng-click="busquedaPress(13)"> | 28 | ng-click="busquedaPress(13)"> | 
| 29 | <i class="fa fa-search" aria-hidden="true"></i> | 29 | <i class="fa fa-search" aria-hidden="true"></i> | 
| 30 | </button> | 30 | </button> | 
| 31 | </div> | 31 | </div> | 
| 32 | </div> | 32 | </div> | 
| 33 | </div> | 33 | </div> | 
| 34 | </div> | 34 | </div> | 
| 35 | <div class="modal-body" id="modal-body"> | 35 | <div class="modal-body" id="modal-body"> | 
| 36 | 36 | ||
| 37 | <div ng-show="!primerBusqueda"> | 37 | <div ng-show="!primerBusqueda"> | 
| 38 | Debe realizar una primer búsqueda. | 38 | Debe realizar una primer búsqueda. | 
| 39 | </div> | 39 | </div> | 
| 40 | 40 | ||
| 41 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> | 41 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> | 
| 42 | <thead> | 42 | <thead> | 
| 43 | <tr> | 43 | <tr> | 
| 44 | <th>Código</th> | 44 | <th>Código</th> | 
| 45 | <th>Nombre</th> | 45 | <th>Nombre</th> | 
| 46 | <th>CUIT</th> | 46 | <th>CUIT</th> | 
| 47 | <th></th> | 47 | <th></th> | 
| 48 | </tr> | 48 | </tr> | 
| 49 | </thead> | 49 | </thead> | 
| 50 | <tbody> | 50 | <tbody> | 
| 51 | <tr ng-show="currentPageProveedores.length == 0 && primerBusqueda"> | 51 | <tr ng-show="currentPageProveedores.length == 0 && primerBusqueda"> | 
| 52 | <td colspan="4"> | 52 | <td colspan="4"> | 
| 53 | No se encontraron resultados. | 53 | No se encontraron resultados. | 
| 54 | </td> | 54 | </td> | 
| 55 | </tr> | 55 | </tr> | 
| 56 | <tr | 56 | <tr | 
| 57 | class="selectable" | 57 | class="selectable" | 
| 58 | ng-repeat="(key, proveedor) in currentPageProveedores" | 58 | ng-repeat="(key, proveedor) in currentPageProveedores" | 
| 59 | ng-click="select(proveedor)"> | 59 | ng-click="select(proveedor)"> | 
| 60 | <td ng-bind="proveedor.COD"></td> | 60 | <td ng-bind="('00000' + proveedor.COD).slice(-5)"></td> | 
| 61 | <td ng-bind="proveedor.NOM"></td> | 61 | <td ng-bind="proveedor.NOM"></td> | 
| 62 | <td ng-bind="proveedor.CUIT"></td> | 62 | <td ng-bind="proveedor.CUIT"></td> | 
| 63 | <td> | 63 | <td> | 
| 64 | <button | 64 | <button | 
| 65 | type="button" | 65 | type="button" | 
| 66 | class="btn btn-xs p-1 float-right" | 66 | class="btn btn-xs p-1 float-right" | 
| 67 | ng-class="{ | 67 | ng-class="{ | 
| 68 | 'btn-secondary': selectedProveedores != key, | 68 | 'btn-secondary': selectedProveedores != key, | 
| 69 | 'btn-primary': selectedProveedores == key | 69 | 'btn-primary': selectedProveedores == key | 
| 70 | }" | 70 | }" | 
| 71 | ng-click="select(proveedor)" | 71 | ng-click="select(proveedor)" | 
| 72 | foca-focus="selectedProveedores == {{key}}" | 72 | foca-focus="selectedProveedores == {{key}}" | 
| 73 | ng-keydown="itemProveedor($event.keyCode)" | 73 | ng-keydown="itemProveedor($event.keyCode)" | 
| 74 | > | 74 | > | 
| 75 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 75 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 
| 76 | </button> | 76 | </button> | 
| 77 | </td> | 77 | </td> | 
| 78 | </tr> | 78 | </tr> | 
| 79 | </tbody> | 79 | </tbody> | 
| 80 | </table> | 80 | </table> | 
| 81 | 81 | ||
| 82 | </div> | 82 | </div> | 
| 83 | <div class="modal-footer py-1"> | 83 | <div class="modal-footer py-1"> | 
| 84 | <nav ng-show="currentPageProveedores.length > 0 && primerBusqueda" class="mr-auto"> | 84 | <nav ng-show="currentPageProveedores.length > 0 && primerBusqueda" class="mr-auto"> | 
| 85 | <ul class="pagination pagination-sm mb-0"> | 85 | <ul class="pagination pagination-sm mb-0"> | 
| 86 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 86 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 
| 87 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> | 87 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> | 
| 88 | <span aria-hidden="true">«</span> | 88 | <span aria-hidden="true">«</span> | 
| 89 | <span class="sr-only">Anterior</span> | 89 | <span class="sr-only">Anterior</span> | 
| 90 | </a> | 90 | </a> | 
| 91 | </li> | 91 | </li> | 
| 92 | <li | 92 | <li | 
| 93 | class="page-item" | 93 | class="page-item" | 
| 94 | ng-repeat="pagina in paginas" | 94 | ng-repeat="pagina in paginas" | 
| 95 | ng-class="{'active': pagina == currentPage}" | 95 | ng-class="{'active': pagina == currentPage}" | 
| 96 | > | 96 | > | 
| 97 | <a | 97 | <a | 
| 98 | class="page-link" | 98 | class="page-link" | 
| 99 | href="javascript:void();" | 99 | href="javascript:void();" | 
| 100 | ng-click="selectPage(pagina)" | 100 | ng-click="selectPage(pagina)" | 
| 101 | ng-bind="pagina" | 101 | ng-bind="pagina" | 
| 102 | ></a> | 102 | ></a> | 
| 103 | </li> | 103 | </li> | 
| 104 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 104 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 
| 105 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> | 105 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> | 
| 106 | <span aria-hidden="true">»</span> | 106 | <span aria-hidden="true">»</span> | 
| 107 | <span class="sr-only">Siguiente</span> | 107 | <span class="sr-only">Siguiente</span> | 
| 108 | </a> | 108 | </a> | 
| 109 | </li> | 109 | </li> | 
| 110 | </ul> | 110 | </ul> | 
| 111 | </nav> | 111 | </nav> | 
| 112 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 112 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 
| 113 | </div> | 113 | </div> | 
| 114 | 114 |