Commit d3953b4029d0fcf75c8e0b287c5f78c6cb52193d
1 parent
6016af2682
Exists in
master
and in
1 other branch
boton obtener cotizacion
Showing
4 changed files
with
68 additions
and
11 deletions
Show diff stats
src/js/app.js
src/js/controller.js
... | ... | @@ -6,14 +6,11 @@ angular.module('focaModalCotizacion') |
6 | 6 | '$uibModalInstance', |
7 | 7 | 'focaModalCotizacionService', |
8 | 8 | 'idMoneda', |
9 | - function($filter, $scope, $uibModalInstance, focaModalCotizacionService, idMoneda) { | |
10 | - focaModalCotizacionService.getCotizaciones(idMoneda).then( | |
11 | - function(res) { | |
12 | - $scope.moneda = res.data[0]; | |
13 | - $scope.cotizacion = res.data[0].cotizaciones; | |
14 | - $scope.search(); | |
15 | - } | |
16 | - ); | |
9 | + 'focaModalService', | |
10 | + function($filter, $scope, $uibModalInstance, | |
11 | + focaModalCotizacionService, idMoneda, focaModalService) { | |
12 | + | |
13 | + actualizarTabla(); | |
17 | 14 | |
18 | 15 | // pagination |
19 | 16 | $scope.numPerPage = 10; |
... | ... | @@ -36,6 +33,43 @@ angular.module('focaModalCotizacion') |
36 | 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 | 73 | $scope.resetPage = function() { |
40 | 74 | $scope.currentPage = 1; |
41 | 75 | $scope.selectPage(1); |
... | ... | @@ -153,6 +187,16 @@ angular.module('focaModalCotizacion') |
153 | 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 | } |
157 | 201 | ] |
158 | 202 | ); |
src/js/service.js
... | ... | @@ -6,6 +6,12 @@ angular.module('focaModalCotizacion') |
6 | 6 | return { |
7 | 7 | getCotizaciones: function(idMoneda) { |
8 | 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 | } |
src/views/modal-cotizacion.html
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 | 10 | </div> |
4 | 11 | <div class="modal-body" id="modal-body"> |
5 | 12 | <div class="input-group"> |
... | ... | @@ -18,7 +25,7 @@ |
18 | 25 | ng-repeat="(key,cotizacion) in currentPageCotizacion" |
19 | 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 | 29 | <td ng-bind="cotizacion.COTIZACION | number: 2" class="text-right"></td> |
23 | 30 | <td ng-bind="cotizacion.VENDEDOR | number: 2" class="text-right"></td> |
24 | 31 | <td> |