Commit 3dad63391746baf0b8a83d97756417c7ed2a03c7

Authored by Marcelo Puebla
Exists in master and in 1 other branch validar_pve

Merge branch 'master' into 'master'

Master

See merge request !52
src/app/components/pago/pago.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { appSettings } from 'src/etc/AppSettings'; 2 import { appSettings } from 'src/etc/AppSettings';
3 import { Location } from '@angular/common'; 3 import { Location } from '@angular/common';
4 import { ProductoService } from 'src/app/services/producto.service'; 4 import { ProductoService } from 'src/app/services/producto.service';
5 import { RouterLink, Router } from '@angular/router'; 5 import { RouterLink, Router } from '@angular/router';
6 import { Producto } from 'src/app/wrappers/producto'; 6 import { Producto } from 'src/app/wrappers/producto';
7 7
8 @Component({ 8 @Component({
9 selector: 'app-pago', 9 selector: 'app-pago',
10 templateUrl: './pago.component.html', 10 templateUrl: './pago.component.html',
11 styleUrls: ['./pago.component.scss'] 11 styleUrls: ['./pago.component.scss']
12 }) 12 })
13 export class PagoComponent implements OnInit { 13 export class PagoComponent implements OnInit {
14 14
15 private apiUrl: string = appSettings.apiUrl; 15 private apiUrl: string = appSettings.apiUrl;
16 private verQR: boolean = false; 16 private verQR: boolean = false;
17 private productos: Producto[] = []; 17 private productos: Producto[] = [];
18 private total: number = 0; 18 private total: number = 0;
19 19
20 private compraConQRfinalizada: boolean = false; 20 private compraConQRfinalizada: boolean = false;
21 private compraConEfectivofinalizada: boolean = false; 21 private compraConEfectivofinalizada: boolean = false;
22 22
23 constructor( 23 constructor(
24 private productoService: ProductoService, 24 private productoService: ProductoService,
25 private location: Location, 25 private location: Location,
26 private router: Router, 26 private router: Router,
27 ) { } 27 ) { }
28 28
29 ngOnInit() { 29 ngOnInit() {
30 30
31 this.productos = this.productoService.productos; 31 this.productos = this.productoService.productos;
32 } 32 }
33 33
34 pagar() { 34 pagar() {
35 35
36 this.verQR = true;
37 alert('Procesando Pago'); 36 this.verQR = true;
38 37
39 this.productoService.pagar() 38 this.productoService.pagar()
40 .subscribe(() => { 39 .subscribe(() => {
41 40
42 // alert('Compra finalizada'); 41 // alert('Compra finalizada');
43 this.compraConQRfinalizada = true; 42 this.compraConQRfinalizada = true;
44 setTimeout(() => { 43 setTimeout(() => {
45 44
46 this.router.navigate(['mensaje-final']); 45 this.router.navigate(['mensaje-final']);
47 }, 3000); 46 }, 3000);
48 }, err => { 47 }, err => {
49 console.log(err); 48 console.log(err);
50 alert('algo salió mal'); 49 alert('algo salió mal');
51 }) 50 })
52 } 51 }
53 52
54 volverPreviousPage() { 53 volverPreviousPage() {
55 54
56 if (this.verQR) { 55 if (this.verQR) {
57 this.verQR = false; 56 this.verQR = false;
58 return; 57 return;
59 } 58 }
60 this.location.back(); 59 this.location.back();
61 } 60 }
62 61
63 getTotal() { 62 getTotal() {
64 63
65 var subTotal = 0; 64 var subTotal = 0;
66 this.productos.forEach(producto => { 65 this.productos.forEach(producto => {
67 66
68 subTotal = subTotal + (producto.PreVen * producto.cantidad); 67 subTotal = subTotal + (producto.PreVen * producto.cantidad);
69 }); 68 });
70 return this.total = subTotal; 69 return this.total = subTotal;
71 } 70 }
72 71
73 } 72 }
74 73