Commit 40ac2d17ed62e23edc6d5afaed3621e36668ff11
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
agrego decimales See merge request !2
Showing
3 changed files
Show diff stats
package.json
| 1 | { | 1 | { |
| 2 | "name": "foca-modal-cotizacion", | 2 | "name": "foca-modal-cotizacion", |
| 3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
| 4 | "description": "Modal de búsqueda de cotizaciones", | 4 | "description": "Modal de búsqueda de cotizaciones", |
| 5 | "main": "index.js", | 5 | "main": "index.js", |
| 6 | "scripts": { | 6 | "scripts": { |
| 7 | "test": "echo \"Error: no test specified\" && exit 1", | 7 | "test": "echo \"Error: no test specified\" && exit 1", |
| 8 | "gulp-pre-commit": "gulp pre-commit", | 8 | "gulp-pre-commit": "gulp pre-commit", |
| 9 | "compile": "gulp uglify", | 9 | "compile": "gulp uglify", |
| 10 | "postinstall": "npm run compile && gulp clean-post-install", | 10 | "postinstall": "npm run compile && gulp clean-post-install", |
| 11 | "install-dev": "npm install -D angular font-awesome pump jquery bootstrap ui-bootstrap4 jshint gulp gulp-uglify gulp-concat gulp-htmlmin gulp-rename gulp-uglify gulp-jshint gulp-replace gulp-connect gulp-clean gulp-angular-templatecache git+https://debo.suite.repo/modulos-npm/foca-directivas.git" | 11 | "install-dev": "npm install -D angular font-awesome pump jquery bootstrap ui-bootstrap4 jshint gulp gulp-uglify gulp-concat gulp-htmlmin gulp-rename gulp-uglify gulp-jshint gulp-replace gulp-connect gulp-clean gulp-angular-templatecache git+http://git.focasoftware.com/npm/foca-directivas.git" |
| 12 | }, | 12 | }, |
| 13 | "pre-commit": [ | 13 | "pre-commit": [ |
| 14 | "gulp-pre-commit" | 14 | "gulp-pre-commit" |
| 15 | ], | 15 | ], |
| 16 | "repository": { | 16 | "repository": { |
| 17 | "type": "git", | 17 | "type": "git", |
| 18 | "url": "https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.git" | 18 | "url": "https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.git" |
| 19 | }, | 19 | }, |
| 20 | "author": "Foca Software", | 20 | "author": "Foca Software", |
| 21 | "license": "ISC", | 21 | "license": "ISC", |
| 22 | "devDependencies": { | 22 | "devDependencies": { |
| 23 | "angular": "^1.7.5", | 23 | "angular": "^1.7.5", |
| 24 | "bootstrap": "^4.1.3", | 24 | "bootstrap": "^4.1.3", |
| 25 | "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git", | 25 | "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", |
| 26 | "font-awesome": "^4.7.0", | 26 | "font-awesome": "^4.7.0", |
| 27 | "gulp": "^3.9.1", | 27 | "gulp": "^3.9.1", |
| 28 | "gulp-angular-templatecache": "^2.2.3", | 28 | "gulp-angular-templatecache": "^2.2.3", |
| 29 | "gulp-clean": "^0.4.0", | 29 | "gulp-clean": "^0.4.0", |
| 30 | "gulp-concat": "^2.6.1", | 30 | "gulp-concat": "^2.6.1", |
| 31 | "gulp-connect": "^5.6.1", | 31 | "gulp-connect": "^5.6.1", |
| 32 | "gulp-htmlmin": "^5.0.1", | 32 | "gulp-htmlmin": "^5.0.1", |
| 33 | "gulp-jshint": "^2.1.0", | 33 | "gulp-jshint": "^2.1.0", |
| 34 | "gulp-rename": "^1.4.0", | 34 | "gulp-rename": "^1.4.0", |
| 35 | "gulp-replace": "^1.0.0", | 35 | "gulp-replace": "^1.0.0", |
| 36 | "gulp-uglify": "^3.0.1", | 36 | "gulp-uglify": "^3.0.1", |
| 37 | "jquery": "^3.3.1", | 37 | "jquery": "^3.3.1", |
| 38 | "jshint": "^2.9.6", | 38 | "jshint": "^2.9.6", |
| 39 | "pump": "^3.0.0", | 39 | "pump": "^3.0.0", |
| 40 | "ui-bootstrap4": "^3.0.5" | 40 | "ui-bootstrap4": "^3.0.5" |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | 43 |
src/js/controller.js
| 1 | angular.module('focaModalCotizacion') | 1 | angular.module('focaModalCotizacion') |
| 2 | .controller('focaModalCotizacionController', | 2 | .controller('focaModalCotizacionController', |
| 3 | [ | 3 | [ |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaModalCotizacionService', | 7 | 'focaModalCotizacionService', |
| 8 | 'idMoneda', | 8 | 'idMoneda', |
| 9 | function($filter, $scope, $uibModalInstance, focaModalCotizacionService, idMoneda) { | 9 | function($filter, $scope, $uibModalInstance, focaModalCotizacionService, idMoneda) { |
| 10 | focaModalCotizacionService.getCotizaciones(idMoneda).then( | 10 | focaModalCotizacionService.getCotizaciones(idMoneda).then( |
| 11 | function(res) {console.log(res.data); | 11 | function(res) { |
| 12 | $scope.moneda = res.data[0]; | 12 | $scope.moneda = res.data[0]; |
| 13 | $scope.cotizacion = res.data[0].cotizaciones; | 13 | $scope.cotizacion = res.data[0].cotizaciones; |
| 14 | $scope.search(); | 14 | $scope.search(); |
| 15 | } | 15 | } |
| 16 | ); | 16 | ); |
| 17 | 17 | ||
| 18 | // pagination | 18 | // pagination |
| 19 | $scope.numPerPage = 10; | 19 | $scope.numPerPage = 10; |
| 20 | $scope.currentPage = 1; | 20 | $scope.currentPage = 1; |
| 21 | $scope.filteredCotizacion = []; | 21 | $scope.filteredCotizacion = []; |
| 22 | $scope.currentPageCotizacion = []; | 22 | $scope.currentPageCotizacion = []; |
| 23 | $scope.selectedCotizacion = 0; | 23 | $scope.selectedCotizacion = 0; |
| 24 | 24 | ||
| 25 | //METODOS | 25 | //METODOS |
| 26 | $scope.search = function() { | 26 | $scope.search = function() { |
| 27 | $scope.filteredCotizacion = $filter('filter')( | 27 | $scope.filteredCotizacion = $filter('filter')( |
| 28 | $scope.cotizacion, | 28 | $scope.cotizacion, |
| 29 | {$: $scope.filters} | 29 | {$: $scope.filters} |
| 30 | ); | 30 | ); |
| 31 | 31 | ||
| 32 | $scope.lastPage = Math.ceil( | 32 | $scope.lastPage = Math.ceil( |
| 33 | $scope.filteredCotizacion.length / $scope.numPerPage | 33 | $scope.filteredCotizacion.length / $scope.numPerPage |
| 34 | ); | 34 | ); |
| 35 | 35 | ||
| 36 | $scope.resetPage(); | 36 | $scope.resetPage(); |
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | $scope.resetPage = function() { | 39 | $scope.resetPage = function() { |
| 40 | $scope.currentPage = 1; | 40 | $scope.currentPage = 1; |
| 41 | $scope.selectPage(1); | 41 | $scope.selectPage(1); |
| 42 | }; | 42 | }; |
| 43 | 43 | ||
| 44 | $scope.selectPage = function(page) { | 44 | $scope.selectPage = function(page) { |
| 45 | var start = (page - 1) * $scope.numPerPage; | 45 | var start = (page - 1) * $scope.numPerPage; |
| 46 | var end = start + $scope.numPerPage; | 46 | var end = start + $scope.numPerPage; |
| 47 | $scope.paginas = []; | 47 | $scope.paginas = []; |
| 48 | $scope.paginas = calcularPages(page); | 48 | $scope.paginas = calcularPages(page); |
| 49 | $scope.currentPageCotizacion = | 49 | $scope.currentPageCotizacion = |
| 50 | $scope.filteredCotizacion.slice(start, end); | 50 | $scope.filteredCotizacion.slice(start, end); |
| 51 | $scope.currentPage = page; | 51 | $scope.currentPage = page; |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | $scope.select = function(cotizacion) { | 54 | $scope.select = function(cotizacion) { |
| 55 | $uibModalInstance.close(cotizacion); | 55 | $uibModalInstance.close(cotizacion); |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | $scope.cancel = function() { | 58 | $scope.cancel = function() { |
| 59 | $uibModalInstance.dismiss('cancel'); | 59 | $uibModalInstance.dismiss('cancel'); |
| 60 | }; | 60 | }; |
| 61 | 61 | ||
| 62 | $scope.busquedaDown = function(key) { | 62 | $scope.busquedaDown = function(key) { |
| 63 | if (key === 40) { | 63 | if (key === 40) { |
| 64 | primera(key); | 64 | primera(key); |
| 65 | } | 65 | } |
| 66 | }; | 66 | }; |
| 67 | 67 | ||
| 68 | $scope.busquedaPress = function(key) { | 68 | $scope.busquedaPress = function(key) { |
| 69 | if (key === 13) { | 69 | if (key === 13) { |
| 70 | primera(key); | 70 | primera(key); |
| 71 | } | 71 | } |
| 72 | }; | 72 | }; |
| 73 | 73 | ||
| 74 | $scope.itemProducto = function(key) { | 74 | $scope.itemProducto = function(key) { |
| 75 | if (key === 38) { | 75 | if (key === 38) { |
| 76 | anterior(key); | 76 | anterior(key); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | if (key === 40) { | 79 | if (key === 40) { |
| 80 | siguiente(key); | 80 | siguiente(key); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | if (key === 37) { | 83 | if (key === 37) { |
| 84 | retrocederPagina(); | 84 | retrocederPagina(); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | if (key === 39) { | 87 | if (key === 39) { |
| 88 | avanzarPagina(); | 88 | avanzarPagina(); |
| 89 | } | 89 | } |
| 90 | }; | 90 | }; |
| 91 | 91 | ||
| 92 | function calcularPages(paginaActual) { | 92 | function calcularPages(paginaActual) { |
| 93 | var paginas = []; | 93 | var paginas = []; |
| 94 | paginas.push(paginaActual); | 94 | paginas.push(paginaActual); |
| 95 | 95 | ||
| 96 | if (paginaActual - 1 > 1) { | 96 | if (paginaActual - 1 > 1) { |
| 97 | 97 | ||
| 98 | paginas.unshift(paginaActual - 1); | 98 | paginas.unshift(paginaActual - 1); |
| 99 | if (paginaActual - 2 > 1) { | 99 | if (paginaActual - 2 > 1) { |
| 100 | paginas.unshift(paginaActual - 2); | 100 | paginas.unshift(paginaActual - 2); |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | if (paginaActual + 1 < $scope.lastPage) { | 104 | if (paginaActual + 1 < $scope.lastPage) { |
| 105 | paginas.push(paginaActual + 1); | 105 | paginas.push(paginaActual + 1); |
| 106 | if (paginaActual + 2 < $scope.lastPage) { | 106 | if (paginaActual + 2 < $scope.lastPage) { |
| 107 | paginas.push(paginaActual + 2); | 107 | paginas.push(paginaActual + 2); |
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | if (paginaActual !== 1) { | 111 | if (paginaActual !== 1) { |
| 112 | paginas.unshift(1); | 112 | paginas.unshift(1); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | if (paginaActual !== $scope.lastPage) { | 115 | if (paginaActual !== $scope.lastPage) { |
| 116 | paginas.push($scope.lastPage); | 116 | paginas.push($scope.lastPage); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | return paginas; | 119 | return paginas; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | function primera() { | 122 | function primera() { |
| 123 | $scope.selectedCotizacion = 0; | 123 | $scope.selectedCotizacion = 0; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | function anterior() { | 126 | function anterior() { |
| 127 | if ($scope.selectedCotizacion === 0 && $scope.currentPage > 1) { | 127 | if ($scope.selectedCotizacion === 0 && $scope.currentPage > 1) { |
| 128 | retrocederPagina(); | 128 | retrocederPagina(); |
| 129 | } else { | 129 | } else { |
| 130 | $scope.selectedCotizacion--; | 130 | $scope.selectedCotizacion--; |
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | function siguiente() { | 134 | function siguiente() { |
| 135 | if ($scope.selectedCotizacion < | 135 | if ($scope.selectedCotizacion < |
| 136 | $scope.currentPageCotizacion.length - 1 ) { | 136 | $scope.currentPageCotizacion.length - 1 ) { |
| 137 | $scope.selectedCotizacion++; | 137 | $scope.selectedCotizacion++; |
| 138 | } else { | 138 | } else { |
| 139 | avanzarPagina(); | 139 | avanzarPagina(); |
| 140 | } | 140 | } |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | function retrocederPagina() { | 143 | function retrocederPagina() { |
| 144 | if ($scope.currentPage > 1) { | 144 | if ($scope.currentPage > 1) { |
| 145 | $scope.selectPage($scope.currentPage - 1); | 145 | $scope.selectPage($scope.currentPage - 1); |
| 146 | $scope.selectedCotizacion = $scope.numPerPage - 1; | 146 | $scope.selectedCotizacion = $scope.numPerPage - 1; |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | function avanzarPagina() { | 150 | function avanzarPagina() { |
| 151 | if ($scope.currentPage < $scope.lastPage) { | 151 | if ($scope.currentPage < $scope.lastPage) { |
| 152 | $scope.selectPage($scope.currentPage + 1); | 152 | $scope.selectPage($scope.currentPage + 1); |
| 153 | $scope.selectedCotizacion = 0; | 153 | $scope.selectedCotizacion = 0; |
| 154 | } | 154 | } |
| 155 | } | 155 | } |
| 156 | } | 156 | } |
| 157 | ] | 157 | ] |
| 158 | ); | 158 | ); |
| 159 | 159 |
src/views/modal-cotizacion.html
| 1 | <div class="modal-header py-1"> | 1 | <div class="modal-header py-1"> |
| 2 | <h5 class="modal-title">Seleccione Cotización <span ng-bind="moneda.SIMBOLO"></span></h5> | 2 | <h5 class="modal-title">Seleccione Cotización <span ng-bind="moneda.SIMBOLO"></span></h5> |
| 3 | </div> | 3 | </div> |
| 4 | <div class="modal-body" id="modal-body"> | 4 | <div class="modal-body" id="modal-body"> |
| 5 | <div class="input-group"> | 5 | <div class="input-group"> |
| 6 | <table class="table table-striped table-sm"> | 6 | <table class="table table-striped table-sm"> |
| 7 | <thead> | 7 | <thead> |
| 8 | <tr> | 8 | <tr> |
| 9 | <th>Fecha</th> | 9 | <th>Fecha</th> |
| 10 | <th>Compra</th> | 10 | <th class="text-right">Compra</th> |
| 11 | <th>Venta</th> | 11 | <th class="text-right">Venta</th> |
| 12 | <th></th> | 12 | <th></th> |
| 13 | </tr> | 13 | </tr> |
| 14 | </thead> | 14 | </thead> |
| 15 | <tbody> | 15 | <tbody> |
| 16 | <tr | 16 | <tr |
| 17 | class="selectable" | 17 | class="selectable" |
| 18 | ng-repeat="(key,cotizacion) in currentPageCotizacion" | 18 | ng-repeat="(key,cotizacion) in currentPageCotizacion" |
| 19 | ng-click="select(cotizacion)" | 19 | ng-click="select(cotizacion)" |
| 20 | > | 20 | > |
| 21 | <td ng-bind="cotizacion.FECHA | date:'dd/MM/yyyy HH:mm'"></td> | 21 | <td ng-bind="cotizacion.FECHA | date:'dd/MM/yyyy HH:mm'"></td> |
| 22 | <td ng-bind="cotizacion.COTIZACION"></td> | 22 | <td ng-bind="cotizacion.COTIZACION | number: 2" class="text-right"></td> |
| 23 | <td ng-bind="cotizacion.VENDEDOR | number:2"></td> | 23 | <td ng-bind="cotizacion.VENDEDOR | number: 2" class="text-right"></td> |
| 24 | <td> | 24 | <td> |
| 25 | <button | 25 | <button |
| 26 | type="button" | 26 | type="button" |
| 27 | class="btn btn-xs p-1 float-right" | 27 | class="btn btn-xs p-1 float-right" |
| 28 | ng-class="{ | 28 | ng-class="{ |
| 29 | 'btn-secondary': selectedCotizacion != key, | 29 | 'btn-secondary': selectedCotizacion != key, |
| 30 | 'btn-primary': selectedCotizacion == key | 30 | 'btn-primary': selectedCotizacion == key |
| 31 | }" | 31 | }" |
| 32 | foca-focus="selectedCotizacion == {{key}}" | 32 | foca-focus="selectedCotizacion == {{key}}" |
| 33 | ng-keydown="itemProducto($event.keyCode)" | 33 | ng-keydown="itemProducto($event.keyCode)" |
| 34 | > | 34 | > |
| 35 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 35 | <i class="fa fa-circle-thin" aria-hidden="true"></i> |
| 36 | </button> | 36 | </button> |
| 37 | </td> | 37 | </td> |
| 38 | </tr> | 38 | </tr> |
| 39 | </tbody> | 39 | </tbody> |
| 40 | </table> | 40 | </table> |
| 41 | 41 | ||
| 42 | </div> | 42 | </div> |
| 43 | </div> | 43 | </div> |
| 44 | <div class="modal-footer py-1"> | 44 | <div class="modal-footer py-1"> |
| 45 | <nav class="mr-auto"> | 45 | <nav class="mr-auto"> |
| 46 | <ul class="pagination pagination-sm justify-content-end mb-0"> | 46 | <ul class="pagination pagination-sm justify-content-end mb-0"> |
| 47 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 47 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> |
| 48 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage - 1)"> | 48 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage - 1)"> |
| 49 | <span aria-hidden="true">«</span> | 49 | <span aria-hidden="true">«</span> |
| 50 | <span class="sr-only">Anterior</span> | 50 | <span class="sr-only">Anterior</span> |
| 51 | </a> | 51 | </a> |
| 52 | </li> | 52 | </li> |
| 53 | <li | 53 | <li |
| 54 | class="page-item" | 54 | class="page-item" |
| 55 | ng-repeat="pagina in paginas" | 55 | ng-repeat="pagina in paginas" |
| 56 | ng-class="{'active': pagina == currentPage}" | 56 | ng-class="{'active': pagina == currentPage}" |
| 57 | > | 57 | > |
| 58 | <a | 58 | <a |
| 59 | class="page-link" | 59 | class="page-link" |
| 60 | href="javascript:void()" | 60 | href="javascript:void()" |
| 61 | ng-click="selectPage(pagina)" | 61 | ng-click="selectPage(pagina)" |
| 62 | ng-bind="pagina" | 62 | ng-bind="pagina" |
| 63 | ></a> | 63 | ></a> |
| 64 | </li> | 64 | </li> |
| 65 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 65 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> |
| 66 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage + 1)"> | 66 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage + 1)"> |
| 67 | <span aria-hidden="true">»</span> | 67 | <span aria-hidden="true">»</span> |
| 68 | <span class="sr-only">Siguiente</span> | 68 | <span class="sr-only">Siguiente</span> |
| 69 | </a> | 69 | </a> |
| 70 | </li> | 70 | </li> |
| 71 | </ul> | 71 | </ul> |
| 72 | </nav> | 72 | </nav> |
| 73 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 73 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> |
| 74 | </div> | 74 | </div> |
| 75 | 75 |