Commit aed3856bece53cb6f71e7a1c2798106e057f8db7

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master

See merge request !3
1 const templateCache = require('gulp-angular-templatecache'); 1 const templateCache = require('gulp-angular-templatecache');
2 const concat = require('gulp-concat'); 2 const concat = require('gulp-concat');
3 const htmlmin = require('gulp-htmlmin'); 3 const htmlmin = require('gulp-htmlmin');
4 const rename = require('gulp-rename'); 4 const rename = require('gulp-rename');
5 const uglify = require('gulp-uglify'); 5 const uglify = require('gulp-uglify');
6 const gulp = require('gulp'); 6 const gulp = require('gulp');
7 const pump = require('pump'); 7 const pump = require('pump');
8 const jshint = require('gulp-jshint'); 8 const jshint = require('gulp-jshint');
9 const replace = require('gulp-replace'); 9 const replace = require('gulp-replace');
10 const connect = require('gulp-connect'); 10 const connect = require('gulp-connect');
11 const clean = require('gulp-clean'); 11 const clean = require('gulp-clean');
12 12
13 var paths = { 13 var paths = {
14 srcJS: 'src/js/*.js', 14 srcJS: 'src/js/*.js',
15 srcViews: 'src/views/*.html', 15 srcViews: 'src/views/*.html',
16 tmp: 'tmp', 16 tmp: 'tmp',
17 dist: 'dist/' 17 dist: 'dist/'
18 }; 18 };
19 19
20 gulp.task('clean', function() { 20 gulp.task('clean', function() {
21 return gulp.src(['tmp', 'dist'], {read: false}) 21 return gulp.src(['tmp', 'dist'], {read: false})
22 .pipe(clean()); 22 .pipe(clean());
23 }); 23 });
24 24
25 gulp.task('templates', ['clean'], function() { 25 gulp.task('templates', ['clean'], function() {
26 return pump( 26 return pump(
27 [ 27 [
28 gulp.src(paths.srcViews), 28 gulp.src(paths.srcViews),
29 htmlmin(), 29 htmlmin(),
30 templateCache('views.js', { 30 templateCache('views.js', {
31 module: 'focaModalCotizacion', 31 module: 'focaModalCotizacion',
32 root: '' 32 root: ''
33 }), 33 }),
34 gulp.dest(paths.tmp) 34 gulp.dest(paths.tmp)
35 ] 35 ]
36 ); 36 );
37 }); 37 });
38 38
39 gulp.task('uglify', ['templates'], function() { 39 gulp.task('uglify', ['templates'], function() {
40 return pump( 40 return pump(
41 [ 41 [
42 gulp.src([ 42 gulp.src([
43 paths.srcJS, 43 paths.srcJS,
44 'tmp/views.js' 44 'tmp/views.js'
45 ]), 45 ]),
46 concat('foca-modal-cotizacion.js'), 46 concat('foca-modal-cotizacion.js'),
47 replace('src/views/', ''), 47 replace('src/views/', ''),
48 replace("['ui.bootstrap', 'focaDirectivas']", '[]'), 48 replace("['ui.bootstrap', 'focaDirectivas', 'focaModal']", '[]'),
49 gulp.dest(paths.tmp), 49 gulp.dest(paths.tmp),
50 rename('foca-modal-cotizacion.min.js'), 50 rename('foca-modal-cotizacion.min.js'),
51 uglify(), 51 uglify(),
52 gulp.dest(paths.dist) 52 gulp.dest(paths.dist)
53 ] 53 ]
54 ); 54 );
55 }); 55 });
56 56
57 gulp.task('pre-commit', function() { 57 gulp.task('pre-commit', function() {
58 return pump( 58 return pump(
59 [ 59 [
60 gulp.src(paths.srcJS), 60 gulp.src(paths.srcJS),
61 jshint('.jshintrc'), 61 jshint('.jshintrc'),
62 jshint.reporter('default'), 62 jshint.reporter('default'),
63 jshint.reporter('fail') 63 jshint.reporter('fail')
64 ] 64 ]
65 ); 65 );
66 }); 66 });
67 67
68 gulp.task('webserver', function() { 68 gulp.task('webserver', function() {
69 pump [ 69 pump [
70 connect.server({port: 3000}) 70 connect.server({port: 3000})
71 ] 71 ]
72 }); 72 });
73 73
74 gulp.task('clean-post-install', function(){ 74 gulp.task('clean-post-install', function(){
75 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 75 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
76 'index.html'], {read: false}) 76 'index.html'], {read: false})
77 .pipe(clean()); 77 .pipe(clean());
78 }); 78 });
79 79
80 gulp.task('default', ['webserver']); 80 gulp.task('default', ['webserver']);
81 81
82 gulp.task('watch', function() { 82 gulp.task('watch', function() {
83 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 83 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
84 }); 84 });
85 85
1 angular.module('focaModalCotizacion', ['ui.bootstrap', 'focaDirectivas']); 1 angular.module('focaModalCotizacion', ['ui.bootstrap', 'focaDirectivas', 'focaModal']);
2 2
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 'focaModalService',
10 focaModalCotizacionService.getCotizaciones(idMoneda).then( 10 function($filter, $scope, $uibModalInstance,
11 function(res) { 11 focaModalCotizacionService, idMoneda, focaModalService) {
12 $scope.moneda = res.data[0]; 12
13 $scope.cotizacion = res.data[0].cotizaciones; 13 actualizarTabla();
14 $scope.search();
15 }
16 );
17 14
18 // pagination 15 // pagination
19 $scope.numPerPage = 10; 16 $scope.numPerPage = 10;
20 $scope.currentPage = 1; 17 $scope.currentPage = 1;
21 $scope.filteredCotizacion = []; 18 $scope.filteredCotizacion = [];
22 $scope.currentPageCotizacion = []; 19 $scope.currentPageCotizacion = [];
23 $scope.selectedCotizacion = 0; 20 $scope.selectedCotizacion = 0;
24 21
25 //METODOS 22 //METODOS
26 $scope.search = function() { 23 $scope.search = function() {
27 $scope.filteredCotizacion = $filter('filter')( 24 $scope.filteredCotizacion = $filter('filter')(
28 $scope.cotizacion, 25 $scope.cotizacion,
29 {$: $scope.filters} 26 {$: $scope.filters}
30 ); 27 );
31 28
32 $scope.lastPage = Math.ceil( 29 $scope.lastPage = Math.ceil(
33 $scope.filteredCotizacion.length / $scope.numPerPage 30 $scope.filteredCotizacion.length / $scope.numPerPage
34 ); 31 );
35 32
36 $scope.resetPage(); 33 $scope.resetPage();
37 }; 34 };
38 35
36 $scope.obtenerCotizacion = function() {
37 $scope.obteniendoCotizacion = true;
38 focaModalCotizacionService.getCotizacionesActuales()
39 .then(function(res) {
40 var moneda = ($scope.moneda.CODIGO_AFIP === 'DOL') ? 'DBNA' : 'EURPES';
41 var precio = res.data.filter(function(cotizacion) {
42 return cotizacion.papel === moneda;
43 });
44 //CONVIERTO FECHAS A UTC-3
45 var fecha = new Date(precio[0].fecha);
46 var ultimaFecha = new Date($scope.cotizacion[0].FECHA);
47
48 //SI LA ULTIMA COTIZACION YA FUE AGREGADA
49 if(fecha.getTime() === ultimaFecha.getTime()) {
50 focaModalService
51 .alert('Ya se encuentra la ultima cotización en la tabla');
52 $scope.obteniendoCotizacion = false;
53 return;
54 }
55 //CONVIERTO FECHA A STRING PARA GUARDAR
56 fecha = fecha.toJSON().replace('.000Z', '');
57
58 return focaModalCotizacionService.guardarCotizacion({
59 ID_MONEDA: idMoneda,
60 FECHA: fecha,
61 //REEMPLAZO COMA POR PUNTO ASI PUEDO PARSEAR A FLOAT
62 COTIZACION: parseFloat(precio[0].compra.replace(',', '.')),
63 //REEMPLAZO COMA POR PUNTO ASI PUEDO PARSEAR A FLOAT
64 VENDEDOR: parseFloat(precio[0].venta.replace(',', '.'))
65 });
66 })
67 .then(function() {
68 actualizarTabla();
69 $scope.obteniendoCotizacion = false;
70 });
71 };
72
39 $scope.resetPage = function() { 73 $scope.resetPage = function() {
40 $scope.currentPage = 1; 74 $scope.currentPage = 1;
41 $scope.selectPage(1); 75 $scope.selectPage(1);
42 }; 76 };
43 77
44 $scope.selectPage = function(page) { 78 $scope.selectPage = function(page) {
45 var start = (page - 1) * $scope.numPerPage; 79 var start = (page - 1) * $scope.numPerPage;
46 var end = start + $scope.numPerPage; 80 var end = start + $scope.numPerPage;
47 $scope.paginas = []; 81 $scope.paginas = [];
48 $scope.paginas = calcularPages(page); 82 $scope.paginas = calcularPages(page);
49 $scope.currentPageCotizacion = 83 $scope.currentPageCotizacion =
50 $scope.filteredCotizacion.slice(start, end); 84 $scope.filteredCotizacion.slice(start, end);
51 $scope.currentPage = page; 85 $scope.currentPage = page;
52 }; 86 };
53 87
54 $scope.select = function(cotizacion) { 88 $scope.select = function(cotizacion) {
55 $uibModalInstance.close(cotizacion); 89 $uibModalInstance.close(cotizacion);
56 }; 90 };
57 91
58 $scope.cancel = function() { 92 $scope.cancel = function() {
59 $uibModalInstance.dismiss('cancel'); 93 $uibModalInstance.dismiss('cancel');
60 }; 94 };
61 95
62 $scope.busquedaDown = function(key) { 96 $scope.busquedaDown = function(key) {
63 if (key === 40) { 97 if (key === 40) {
64 primera(key); 98 primera(key);
65 } 99 }
66 }; 100 };
67 101
68 $scope.busquedaPress = function(key) { 102 $scope.busquedaPress = function(key) {
69 if (key === 13) { 103 if (key === 13) {
70 primera(key); 104 primera(key);
71 } 105 }
72 }; 106 };
73 107
74 $scope.itemProducto = function(key) { 108 $scope.itemProducto = function(key) {
75 if (key === 38) { 109 if (key === 38) {
76 anterior(key); 110 anterior(key);
77 } 111 }
78 112
79 if (key === 40) { 113 if (key === 40) {
80 siguiente(key); 114 siguiente(key);
81 } 115 }
82 116
83 if (key === 37) { 117 if (key === 37) {
84 retrocederPagina(); 118 retrocederPagina();
85 } 119 }
86 120
87 if (key === 39) { 121 if (key === 39) {
88 avanzarPagina(); 122 avanzarPagina();
89 } 123 }
90 }; 124 };
91 125
92 function calcularPages(paginaActual) { 126 function calcularPages(paginaActual) {
93 var paginas = []; 127 var paginas = [];
94 paginas.push(paginaActual); 128 paginas.push(paginaActual);
95 129
96 if (paginaActual - 1 > 1) { 130 if (paginaActual - 1 > 1) {
97 131
98 paginas.unshift(paginaActual - 1); 132 paginas.unshift(paginaActual - 1);
99 if (paginaActual - 2 > 1) { 133 if (paginaActual - 2 > 1) {
100 paginas.unshift(paginaActual - 2); 134 paginas.unshift(paginaActual - 2);
101 } 135 }
102 } 136 }
103 137
104 if (paginaActual + 1 < $scope.lastPage) { 138 if (paginaActual + 1 < $scope.lastPage) {
105 paginas.push(paginaActual + 1); 139 paginas.push(paginaActual + 1);
106 if (paginaActual + 2 < $scope.lastPage) { 140 if (paginaActual + 2 < $scope.lastPage) {
107 paginas.push(paginaActual + 2); 141 paginas.push(paginaActual + 2);
108 } 142 }
109 } 143 }
110 144
111 if (paginaActual !== 1) { 145 if (paginaActual !== 1) {
112 paginas.unshift(1); 146 paginas.unshift(1);
113 } 147 }
114 148
115 if (paginaActual !== $scope.lastPage) { 149 if (paginaActual !== $scope.lastPage) {
116 paginas.push($scope.lastPage); 150 paginas.push($scope.lastPage);
117 } 151 }
118 152
119 return paginas; 153 return paginas;
120 } 154 }
121 155
122 function primera() { 156 function primera() {
123 $scope.selectedCotizacion = 0; 157 $scope.selectedCotizacion = 0;
124 } 158 }
125 159
126 function anterior() { 160 function anterior() {
127 if ($scope.selectedCotizacion === 0 && $scope.currentPage > 1) { 161 if ($scope.selectedCotizacion === 0 && $scope.currentPage > 1) {
128 retrocederPagina(); 162 retrocederPagina();
129 } else { 163 } else {
130 $scope.selectedCotizacion--; 164 $scope.selectedCotizacion--;
131 } 165 }
132 } 166 }
133 167
134 function siguiente() { 168 function siguiente() {
135 if ($scope.selectedCotizacion < 169 if ($scope.selectedCotizacion <
136 $scope.currentPageCotizacion.length - 1 ) { 170 $scope.currentPageCotizacion.length - 1 ) {
137 $scope.selectedCotizacion++; 171 $scope.selectedCotizacion++;
138 } else { 172 } else {
139 avanzarPagina(); 173 avanzarPagina();
140 } 174 }
141 } 175 }
142 176
143 function retrocederPagina() { 177 function retrocederPagina() {
144 if ($scope.currentPage > 1) { 178 if ($scope.currentPage > 1) {
145 $scope.selectPage($scope.currentPage - 1); 179 $scope.selectPage($scope.currentPage - 1);
146 $scope.selectedCotizacion = $scope.numPerPage - 1; 180 $scope.selectedCotizacion = $scope.numPerPage - 1;
147 } 181 }
148 } 182 }
149 183
150 function avanzarPagina() { 184 function avanzarPagina() {
151 if ($scope.currentPage < $scope.lastPage) { 185 if ($scope.currentPage < $scope.lastPage) {
152 $scope.selectPage($scope.currentPage + 1); 186 $scope.selectPage($scope.currentPage + 1);
153 $scope.selectedCotizacion = 0; 187 $scope.selectedCotizacion = 0;
154 } 188 }
155 } 189 }
190
191 function actualizarTabla() {
192 focaModalCotizacionService.getCotizaciones(idMoneda).then(
193 function(res) {
194 $scope.moneda = res.data[0];
195 $scope.cotizacion = res.data[0].cotizaciones;
196 $scope.search();
197 }
198 );
199 }
156 } 200 }
1 angular.module('focaModalCotizacion') 1 angular.module('focaModalCotizacion')
2 .service('focaModalCotizacionService', [ 2 .service('focaModalCotizacionService', [
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 getCotizaciones: function(idMoneda) { 7 getCotizaciones: function(idMoneda) {
8 return $http.get(API_ENDPOINT.URL + '/moneda/' + idMoneda); 8 return $http.get(API_ENDPOINT.URL + '/moneda/' + idMoneda);
9 },
10 getCotizacionesActuales: function() {
11 return $http.get(API_ENDPOINT.URL + '/cotizacion');
12 },
13 guardarCotizacion: function(cotizacion) {
14 return $http.post(API_ENDPOINT.URL + '/cotizacion', {cotizacion: cotizacion});
9 } 15 }
10 }; 16 };
11 } 17 }
12 ]); 18 ]);
13 19
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 <div class="row">
3 <h5 class="modal-title">Seleccione Cotización <span ng-bind="moneda.SIMBOLO"></span></h5>
4 <button
5 class="btn btn-sm btn-primary ml-auto"
6 ng-click="obtenerCotizacion()"
7 ng-hide="moneda.CODIGO_AFIP == 'PES'"
8 ladda="obteniendoCotizacion">Obtener cotización</button>
9 </div>
3 </div> 10 </div>
4 <div class="modal-body" id="modal-body"> 11 <div class="modal-body" id="modal-body">
5 <div class="input-group"> 12 <div class="input-group">
6 <table class="table table-striped table-sm"> 13 <table class="table table-striped table-sm">
7 <thead> 14 <thead>
8 <tr> 15 <tr>
9 <th>Fecha</th> 16 <th>Fecha</th>
10 <th class="text-right">Compra</th> 17 <th class="text-right">Compra</th>
11 <th class="text-right">Venta</th> 18 <th class="text-right">Venta</th>
12 <th></th> 19 <th></th>
13 </tr> 20 </tr>
14 </thead> 21 </thead>
15 <tbody> 22 <tbody>
16 <tr 23 <tr
17 class="selectable" 24 class="selectable"
18 ng-repeat="(key,cotizacion) in currentPageCotizacion" 25 ng-repeat="(key,cotizacion) in currentPageCotizacion"
19 ng-click="select(cotizacion)" 26 ng-click="select(cotizacion)"
20 > 27 >
21 <td ng-bind="cotizacion.FECHA | date:'dd/MM/yyyy HH:mm'"></td> 28 <td ng-bind="cotizacion.FECHA | date:'dd/MM/yyyy HH:mm': 'UTC-3'"></td>
22 <td ng-bind="cotizacion.COTIZACION | number: 2" class="text-right"></td> 29 <td ng-bind="cotizacion.COTIZACION | number: 2" class="text-right"></td>
23 <td ng-bind="cotizacion.VENDEDOR | number: 2" class="text-right"></td> 30 <td ng-bind="cotizacion.VENDEDOR | number: 2" class="text-right"></td>
24 <td> 31 <td>
25 <button 32 <button
26 type="button" 33 type="button"
27 class="btn btn-xs p-1 float-right" 34 class="btn btn-xs p-1 float-right"
28 ng-class="{ 35 ng-class="{
29 'btn-secondary': selectedCotizacion != key, 36 'btn-secondary': selectedCotizacion != key,
30 'btn-primary': selectedCotizacion == key 37 'btn-primary': selectedCotizacion == key
31 }" 38 }"
32 foca-focus="selectedCotizacion == {{key}}" 39 foca-focus="selectedCotizacion == {{key}}"
33 ng-keydown="itemProducto($event.keyCode)" 40 ng-keydown="itemProducto($event.keyCode)"
34 > 41 >
35 <i class="fa fa-circle-thin" aria-hidden="true"></i> 42 <i class="fa fa-circle-thin" aria-hidden="true"></i>
36 </button> 43 </button>
37 </td> 44 </td>
38 </tr> 45 </tr>
39 </tbody> 46 </tbody>
40 </table> 47 </table>
41 48
42 </div> 49 </div>
43 </div> 50 </div>
44 <div class="modal-footer py-1"> 51 <div class="modal-footer py-1">
45 <nav class="mr-auto"> 52 <nav class="mr-auto">
46 <ul class="pagination pagination-sm justify-content-end mb-0"> 53 <ul class="pagination pagination-sm justify-content-end mb-0">
47 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 54 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
48 <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)">
49 <span aria-hidden="true">&laquo;</span> 56 <span aria-hidden="true">&laquo;</span>
50 <span class="sr-only">Anterior</span> 57 <span class="sr-only">Anterior</span>
51 </a> 58 </a>
52 </li> 59 </li>
53 <li 60 <li
54 class="page-item" 61 class="page-item"
55 ng-repeat="pagina in paginas" 62 ng-repeat="pagina in paginas"
56 ng-class="{'active': pagina == currentPage}" 63 ng-class="{'active': pagina == currentPage}"
57 > 64 >
58 <a 65 <a
59 class="page-link" 66 class="page-link"
60 href="javascript:void()" 67 href="javascript:void()"
61 ng-click="selectPage(pagina)" 68 ng-click="selectPage(pagina)"
62 ng-bind="pagina" 69 ng-bind="pagina"
63 ></a> 70 ></a>
64 </li> 71 </li>
65 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 72 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
66 <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)">
67 <span aria-hidden="true">&raquo;</span> 74 <span aria-hidden="true">&raquo;</span>
68 <span class="sr-only">Siguiente</span> 75 <span class="sr-only">Siguiente</span>
69 </a> 76 </a>
70 </li> 77 </li>
71 </ul> 78 </ul>
72 </nav> 79 </nav>
73 <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>
74 </div> 81 </div>
75 82