Commit 3a86ac77de103172f68c206b821205c90756b43c

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master(mpuebla)

See merge request !55
src/app/components/confirmacion-carrito/confirmacion-carrito.component.html
1 <div class="row m-0 fade-in bg-primary-gradient disable-user-select"> 1 <div
2 class="row m-0 fade-in bg-primary-gradient disable-user-select"
3 (click)="reiniciarTimer">
2 <div class="col-12 p-0 vh-100"> 4 <div class="col-12 p-0 vh-100">
3 5
4 <!-- TOP HEADER --> 6 <!-- TOP HEADER -->
5 <app-header></app-header> 7 <app-header></app-header>
6 8
7 <!-- NOMBRE DE SECCION --> 9 <!-- NOMBRE DE SECCION -->
8 <div class="row m-0"> 10 <div class="row m-0">
9 <div class="col-12 p-0"> 11 <div class="col-12 p-0">
10 <p class="h5 py-1 bg-gray text-muted text-center m-0"> 12 <p class="h5 py-1 bg-gray text-muted text-center m-0">
11 Pagar 13 Pagar
12 <i class="fa fa-usd"></i> 14 <i class="fa fa-usd"></i>
13 </p> 15 </p>
14 </div> 16 </div>
15 </div> 17 </div>
16 18
17 <div class="row m-0"> 19 <div class="row m-0">
18 <div class="col-12"> 20 <div class="col-12">
19 21
20 <!-- TEXTO DE IZQUIERDA --> 22 <!-- TEXTO DE IZQUIERDA -->
21 <div class="row mx-2 mt-4 text-white"> 23 <div class="row mx-2 mt-4 text-white">
22 <div class="col-sm-2 my-auto"> 24 <div class="col-sm-auto my-auto">
23 <p class="h2">Mi Compra 25 <p class="h2">Mi Compra
24 <i class="fa fa-shopping-cart "></i> 26 <i class="fa fa-shopping-cart "></i>
25 </p> 27 </p>
26 </div> 28 </div>
27 <div class="col-sm-4 my-auto"> 29 <div class="col-sm-4 my-auto">
28 <p class="h3">¿Desea finalizar su compra?</p> 30 <p class="h3">¿Desea finalizar su compra?</p>
29 <p class="h4">Por favor, controle y confirme su compra.</p> 31 <p class="h4">Por favor, controle y confirme su compra.</p>
30 </div> 32 </div>
31 </div> 33 </div>
32 34
33 <div class="row"> 35 <div class="row">
34 <!-- GRILLA DE PRODUCTOS DE MI COMPRA --> 36 <!-- GRILLA DE PRODUCTOS DE MI COMPRA -->
35 <div class="col-sm-7"> 37 <div class="col-sm-7">
36 <div class="row ml-4 pr-3 vh-70 overflow-scroll text-dark"> 38 <div class="row ml-4 pr-3 vh-70 overflow-scroll text-dark">
37 <div class="col-4 p-2" *ngFor="let producto of productos"> 39 <div class="col-4 p-2" *ngFor="let producto of productos">
38 <div class="bg-white rounded-sm shadow border-0"> 40 <div class="bg-white rounded-sm shadow border-0">
39 <img src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}" class="rounded-sm w-100 m-auto"> 41 <img
42 src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}"
43 class="shadow rounded-sm w-100 m-auto">
40 <div class="p-2"> 44 <div class="p-2">
41 <p class="h6 text-left m-0">{{producto.DetArt}}</p> 45 <p class="h6 text-left m-0">{{producto.DetArt}}</p>
42 <div class="row justify-content-between m-0"> 46 <div class="row justify-content-between m-0">
43 <div class="col-12 p-0"> 47 <div class="col-12 p-0">
44 <div class="text-left"> 48 <div class="text-left">
45 <p class="m-0 h6"><small>{{producto.DET_LAR}}</small></p> 49 <p class="m-0 h6"><small>{{producto.DET_LAR}}</small></p>
46 <p class="m-0 h6"><small>{{producto.CodSec}}-{{producto.CodArt}}</small></p>
47 </div> 50 </div>
48 </div> 51 </div>
49 <div class="col-12 my-auto pt-2 pr-2 p-0"> 52 <div class="col-12 my-auto pt-2 pr-2 p-0">
50 <p class="text-right m-0 h6">{{producto.PreVen | currency}}</p> 53 <p class="text-right m-0 h6">{{producto.PreVen | currency}}</p>
51 </div> 54 </div>
52 </div> 55 </div>
53 </div> 56 </div>
54 </div> 57 </div>
55 </div> 58 </div>
56 </div> 59 </div>
57 </div> 60 </div>
58 61
59 <div class="col-sm-5 pl-0"> 62 <div class="col-sm-5 pl-0">
60 <div class="row ml-3"> 63 <div class="row ml-3">
61 <!-- TICKET --> 64 <!-- TICKET -->
62 <div class="col-sm-7 p-0"> 65 <div class="col-sm-7 p-0">
63 <div class="card rounded-sm shadow"> 66 <div class="card rounded-sm shadow">
64 <div class="card-body"> 67 <div class="card-body">
65 <p class="h5 card-title">Su Ticket</p> 68 <p class="h5 card-title">Su Ticket</p>
66 <div class="row mt-4 m-0"> 69 <div class="row mt-4 m-0">
67 <div class="col-12 p-0 mb-2"> 70 <div class="col-12 p-0 mb-2">
68 <p class="h6 m-0 card-text text-left"> 71 <p class="h6 m-0 card-text text-left">
69 <small class="font-weight-bold">DESCRIPCIÓN</small> 72 <small class="font-weight-bold">DESCRIPCIÓN</small>
70 </p> 73 </p>
71 <p class="h6 m-0 card-text text-left"> 74 <p class="h6 m-0 card-text text-left">
72 <small class="font-weight-bold">CANTIDAD X PRECIO UNITARIO</small> 75 <small class="font-weight-bold">CANTIDAD X PRECIO UNITARIO</small>
73 </p> 76 </p>
74 </div> 77 </div>
75 </div> 78 </div>
76 <div class="row vh-50 px-2 overflow-scroll m-0"> 79 <div class="row vh-50 px-2 overflow-scroll m-0">
77 <div class="col-12 p-0 mb-2" *ngFor="let producto of productos"> 80 <div class="col-12 p-0 mb-2" *ngFor="let producto of productos">
78 <p class="h6 m-0 card-text text-left"> 81 <p class="h6 m-0 card-text text-left">
79 <small>{{producto.DetArt}}</small> 82 <small>{{producto.DetArt}}</small>
80 </p> 83 </p>
81 <div class="row d-flex justify-content-between m-0"> 84 <div class="row d-flex justify-content-between m-0">
82 <div class="col p-0"> 85 <div class="col p-0">
83 <p class="h6 m-0 card-text text-left"> 86 <p class="h6 m-0 card-text text-left">
84 <small>{{producto.cantidad}} x {{producto.PreVen | currency}}</small> 87 <small>{{producto.cantidad}} x {{producto.PreVen | currency}}</small>
85 </p> 88 </p>
86 </div> 89 </div>
87 <div class="col p-0"> 90 <div class="col p-0">
88 <p class="h6 m-0 card-text text-right"> 91 <p class="h6 m-0 card-text text-right">
89 <small>{{(producto.PreVen) * (producto.cantidad) | currency}}</small> 92 <small>{{(producto.PreVen) * (producto.cantidad) | currency}}</small>
90 </p> 93 </p>
91 </div> 94 </div>
92 </div> 95 </div>
93 </div> 96 </div>
94 </div> 97 </div>
95 <p class="h4 font-weight-bold card-text text-right mt-3 mb-0"> 98 <p class="h4 font-weight-bold card-text text-right mt-3 mb-0">
96 Total {{getTotal() | currency}} 99 Total {{getTotal() | currency}}
97 </p> 100 </p>
98 </div> 101 </div>
99 </div> 102 </div>
100 </div> 103 </div>
101 </div> 104 </div>
102 </div> 105 </div>
103 </div> 106 </div>
104 107
105 <!-- OPCIONES ABAJO DERECHA --> 108 <!-- OPCIONES ABAJO DERECHA -->
106 <div class="row m-0 fixed-bottom"> 109 <div class="row m-0 fixed-bottom">
107 <div class="col-sm-2 offset-sm-10 p-0 mt-auto"> 110 <div class="col-sm-2 offset-sm-10 p-0 mt-auto">
108 <div class="card m-2 rounded-top-sm mt-auto blue-gradient border-0"> 111 <div class="card m-2 rounded-top-sm mt-auto blue-gradient border-0">
109 <div class="card-body row m-0"> 112 <div class="card-body row m-0">
110 <div class="col-12 p-3"> 113 <div class="col-12 p-3">
111 <button 114 <button
112 type="button" 115 type="button"
113 class="btn btn-block btn-light shadow btn-sm shadow" 116 class="btn btn-block btn-light shadow btn-sm shadow"
114 (click)="volverPreviousPage()"> 117 (click)="volverPreviousPage()">
115 <span class="pr-2">Volver</span> 118 <span class="pr-2">Volver</span>
116 <i class="fa fa-undo text-warning"></i> 119 <i class="fa fa-undo text-warning"></i>
117 </button> 120 </button>
118 <button [routerLink]="['/pago']" type="button" class="btn btn-block btn-light btn-lg shadow mb-2 p-1"> 121 <button [routerLink]="['/pago']" type="button" class="btn btn-block btn-light btn-lg shadow mb-2 p-1">
119 <span class="font-weight-bold pr-2">Finalizar y Pagar</span> 122 <span class="font-weight-bold pr-2">Finalizar y Pagar</span>
120 <i class="fa fa-check text-success"></i> 123 <i class="fa fa-check text-success"></i>
121 </button> 124 </button>
122 <button 125 <button
123 type="button" 126 type="button"
124 class="btn btn-block btn-light shadow btn-sm shadow" 127 class="btn btn-block btn-light shadow btn-sm shadow"
125 [routerLink]="['/cancelar-compra']"> 128 [routerLink]="['/cancelar-compra']">
126 <span class="pr-2">Cancelar</span> 129 <span class="pr-2">Cancelar</span>
127 <i class="fa fa-times text-danger"></i> 130 <i class="fa fa-times text-danger"></i>
128 </button> 131 </button>
129 </div> 132 </div>
130 </div> 133 </div>
131 </div> 134 </div>
132 </div> 135 </div>
133 </div> 136 </div>
134 137
135 </div> 138 </div>
136 </div> 139 </div>
137 140
138 </div> 141 </div>
139 142
140 </div> 143 </div>
src/app/components/confirmacion-carrito/confirmacion-carrito.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit, OnDestroy } 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 { Producto } from 'src/app/wrappers/producto'; 5 import { Producto } from 'src/app/wrappers/producto';
6 import { Router } from '@angular/router';
6 7
7 @Component({ 8 @Component({
8 selector: 'app-confirmacion-carrito', 9 selector: 'app-confirmacion-carrito',
9 templateUrl: './confirmacion-carrito.component.html', 10 templateUrl: './confirmacion-carrito.component.html',
10 styleUrls: ['./confirmacion-carrito.component.scss'] 11 styleUrls: ['./confirmacion-carrito.component.scss']
11 }) 12 })
12 export class ConfirmacionCarritoComponent implements OnInit { 13 export class ConfirmacionCarritoComponent implements OnInit, OnDestroy {
13 14
14 productos: Producto[] = []; 15 private productos: Producto[] = [];
15 total: number = 0; 16 private total: number = 0;
16 private apiUrl: string = appSettings.apiUrl; 17 private apiUrl: string = appSettings.apiUrl;
18 private timerReposo: any;
17 19
18 constructor( 20 constructor(
19 private location: Location, 21 private location: Location,
20 private productoService: ProductoService 22 private productoService: ProductoService,
23 private router: Router
21 ) { } 24 ) { }
22 25
23 ngOnInit() { 26 ngOnInit() {
24 27
28 this.timerReposo = setTimeout(() => {
29
30 this.router.navigate(['cancelar-compra']);
31 }, 90000)
25 this.productos = this.productoService.productos; 32 this.productos = this.productoService.productos;
26 } 33 }
27 34
35 ngOnDestroy() {
36
37 clearTimeout(this.timerReposo);
38 }
39
28 volverPreviousPage() { 40 volverPreviousPage() {
29 41
30 this.location.back(); 42 this.location.back();
31 } 43 }
32 44
33 getTotal() { 45 getTotal() {
34 46
35 var subTotal = 0; 47 var subTotal = 0;
36 this.productos.forEach(producto => { 48 this.productos.forEach(producto => {
37 49
38 subTotal = subTotal + (producto.PreVen * producto.cantidad); 50 subTotal = subTotal + (producto.PreVen * producto.cantidad);
39 }); 51 });
40 return this.total = subTotal; 52 return this.total = subTotal;
41 } 53 }
42 54
55 reiniciarTimer() {
56
57 clearTimeout(this.timerReposo);
58 this.timerReposo = setTimeout(() => {
59
60 this.router.navigate(['cancelar-compra']);
61 }, 90000)
62 }
63
43 } 64 }
44 65
src/app/components/inicio/inicio.component.ts
1 import { Component, OnInit, ViewChild, HostListener } from '@angular/core'; 1 import { Component, OnInit, ViewChild, HostListener } from '@angular/core';
2 import { PopoverDirective } from 'ngx-bootstrap'; 2 import { PopoverDirective } from 'ngx-bootstrap';
3 import { appSettings } from 'src/etc/AppSettings'; 3 import { appSettings } from 'src/etc/AppSettings';
4 import { Router } from '@angular/router'; 4 import { Router } from '@angular/router';
5 import { ProductoService } from 'src/app/services/producto.service'; 5 import { ProductoService } from 'src/app/services/producto.service';
6 import { Producto } from 'src/app/wrappers/producto'; 6 import { Producto } from 'src/app/wrappers/producto';
7 import { Sinonimo } from 'src/app/wrappers/sinonimo'; 7 import { Sinonimo } from 'src/app/wrappers/sinonimo';
8 8
9 @Component({ 9 @Component({
10 selector: 'app-inicio', 10 selector: 'app-inicio',
11 templateUrl: './inicio.component.html', 11 templateUrl: './inicio.component.html',
12 styleUrls: ['./inicio.component.scss'] 12 styleUrls: ['./inicio.component.scss']
13 }) 13 })
14 export class InicioComponent implements OnInit { 14 export class InicioComponent implements OnInit {
15 15
16 private tienePromo = false;
17 private productoEsPromo = false;
18 private busqueda: string = '';
19 private productoAcargar: Producto;
20 private promoAcargar: Producto;
21 private productos: Producto[] = [];
22 private promociones: Producto[] = [];
23 private sinonimos: Sinonimo[] = [];
24 private apiUrl: string = appSettings.apiUrl
25
26 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective;
27
16 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { 28 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) {
17 29
18 if (e.keyCode == 13) { 30 if (e.keyCode == 13) {
19 this.buscarByCodigoBarras(this.busqueda); 31 this.buscarByCodigoBarras(this.busqueda);
20 this.busqueda = ''; 32 this.busqueda = '';
21 } else { 33 } else {
22 this.busqueda += e.key; 34 this.busqueda += e.key;
23 } 35 }
24 36
25 }; 37 };
26 38
27 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective;
28 private tienePromo = false;
29 private productoEsPromo = false;
30 private busqueda: string = '';
31
32 private productoAcargar: Producto;
33 private promoAcargar: Producto;
34
35 productos: Producto[] = [];
36 promociones: Producto[] = [];
37 sinonimos: Sinonimo[] = [];
38 apiUrl: string = appSettings.apiUrl
39
40 constructor( 39 constructor(
41 private router: Router, 40 private router: Router,
42 private productoService: ProductoService) { } 41 private productoService: ProductoService) { }
43 42
44 ngOnInit() { 43 ngOnInit() {
45 44
46 this.productoAcargar = this.productoService.productoAcargar; 45 this.productoAcargar = this.productoService.productoAcargar;
47 if (this.productoAcargar) { 46 if (this.productoAcargar) {
48 if (this.productoAcargar.PRO) { 47 if (this.productoAcargar.PRO) {
49 this.promociones.push(this.productoAcargar); 48 this.promociones.push(this.productoAcargar);
50 this.promoSeleccionada(this.productoAcargar); 49 this.promoSeleccionada(this.productoAcargar);
51 } 50 }
52 else 51 else
53 this.getPromociones(); 52 this.getPromociones();
54 } 53 }
55 this.getProductos(); 54 this.getProductos();
56 } 55 }
57 56
58 getPromociones() { 57 getPromociones() {
59 58
60 var sector = this.productoAcargar.CodSec; 59 var sector = this.productoAcargar.CodSec;
61 var codigo = this.productoAcargar.CodArt; 60 var codigo = this.productoAcargar.CodArt;
62 this.productoService.getPromociones(sector, codigo) 61 this.productoService.getPromociones(sector, codigo)
63 .subscribe((res: Producto[]) => { 62 .subscribe((res: Producto[]) => {
64 63
65 if (res.length === 0) { 64 if (res.length === 0) {
66 //Si no tiene promociones la cargará al carrito despues de un tiempo 65 //Si no tiene promociones la cargará al carrito despues de un tiempo
67 // setTimeout(() => { 66 // setTimeout(() => {
68 this.productoAcargar.cantidad = 1; 67 this.productoAcargar.cantidad = 1;
69 this.productoService.productos.push(this.productoAcargar); 68 this.productoService.productos.push(this.productoAcargar);
70 this.productoAcargar = this.productoService.productoAcargar = undefined; 69 this.productoAcargar = this.productoService.productoAcargar = undefined;
71 // }, 2000) 70 // }, 2000)
72 } else { 71 } else {
73 72
74 this.promociones = res; 73 this.promociones = res;
75 this.popoverDirective.show(); 74 this.popoverDirective.show();
76 } 75 }
77 }, error => { console.error(error); }) 76 }, error => { console.error(error); })
78 } 77 }
79 78
80 getProductos() { 79 getProductos() {
81 80
82 this.productoService.getAll() 81 this.productoService.getAll()
83 .subscribe((productos: Producto[]) => { 82 .subscribe((productos: Producto[]) => {
84 this.productos = productos; 83 this.productos = productos;
85 }); 84 });
86 } 85 }
87 86
88 irBusquedaProductos(value) { 87 irBusquedaProductos(value) {
89 88
90 this.productoService.mostrar = value; 89 this.productoService.mostrar = value;
91 this.router.navigate(['busqueda-productos']); 90 this.router.navigate(['busqueda-productos']);
92 } 91 }
93 92
94 confirmarProducto() { 93 confirmarProducto() {
95 var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; 94 var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar;
96 producto.cantidad = 1; 95 producto.cantidad = 1;
97 this.productoService.productos.push(producto); 96 this.productoService.productos.push(producto);
98 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; 97 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined;
99 this.promociones = []; 98 this.promociones = [];
100 this.popoverDirective.hide(); 99 this.popoverDirective.hide();
101 } 100 }
102 101
103 deshacerCarga() { 102 deshacerCarga() {
104 103
105 if (this.sinonimos.length > 0) { 104 if (this.sinonimos.length > 0) {
106 this.sinonimos = []; 105 this.sinonimos = [];
107 this.popoverDirective.hide(); 106 this.popoverDirective.hide();
108 } 107 }
109 108
110 if (this.promoAcargar) { 109 if (this.promoAcargar) {
111 this.promoAcargar = undefined; 110 this.promoAcargar = undefined;
112 if (this.productoAcargar.PRO) { 111 if (this.productoAcargar.PRO) {
113 this.productoAcargar = undefined; 112 this.productoAcargar = undefined;
114 this.promociones = []; 113 this.promociones = [];
115 this.popoverDirective.hide(); 114 this.popoverDirective.hide();
116 } else { 115 } else {
117 this.popoverDirective.show(); 116 this.popoverDirective.show();
118 } 117 }
119 } else { 118 } else {
120 this.productoAcargar = undefined; 119 this.productoAcargar = undefined;
121 this.promociones = []; 120 this.promociones = [];
122 this.popoverDirective.hide(); 121 this.popoverDirective.hide();
123 } 122 }
124 } 123 }
125 124
126 promoSeleccionada($event: Producto) { 125 promoSeleccionada($event: Producto) {
127 126
128 if ($event.tieneSinonimos) { 127 if ($event.tieneSinonimos) {
129 128
130 this.productoService.getProductoById($event.id) 129 this.productoService.getProductoById($event.id)
131 .subscribe((res : Producto) => { 130 .subscribe((res: Producto) => {
132 131
133 $event.imagenes = res.imagenes; 132 $event.imagenes = res.imagenes;
134 this.promoAcargar = $event; 133 this.promoAcargar = $event;
135 this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); 134 this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt);
136 }, 135 },
137 error => { console.log(error); }) 136 error => { console.log(error); })
138 137
139 138
140 } else if (this.popoverDirective) { 139 } else if (this.popoverDirective) {
141 this.popoverDirective.hide(); 140 this.popoverDirective.hide();
142 } 141 }
143 } 142 }
144 143
145 getSinonimos(sector, codigo) { 144 getSinonimos(sector, codigo) {
146 145
147 this.productoService.getPromocionSinonimos(sector, codigo) 146 this.productoService.getPromocionSinonimos(sector, codigo)
148 .subscribe((res: Sinonimo[]) => { 147 .subscribe((res: Sinonimo[]) => {
149 148
150 res.forEach(sinonimo => { 149 res.forEach(sinonimo => {
151 150
152 sinonimo.productos.forEach(productoSinonimo => { 151 sinonimo.productos.forEach(productoSinonimo => {
153 152
154 this.promoAcargar.productos.forEach(productoPromo => { 153 this.promoAcargar.productos.forEach(productoPromo => {
155 154
156 if (productoSinonimo.id === productoPromo.id) { 155 if (productoSinonimo.id === productoPromo.id) {
157 sinonimo.cantidad = productoPromo.cantidad; 156 sinonimo.cantidad = productoPromo.cantidad;
158 sinonimo.productoPadre = productoPromo.id; 157 sinonimo.productoPadre = productoPromo.id;
159 } 158 }
160 }) 159 })
161 }) 160 })
162 }) 161 })
163 162
164 this.sinonimos = res; 163 this.sinonimos = res;
165 if (res.length > 0) 164 if (res.length > 0)
166 this.popoverDirective.show(); 165 this.popoverDirective.show();
167 else 166 else
168 this.popoverDirective.hide(); 167 this.popoverDirective.hide();
169 }) 168 })
170 } 169 }
171 170
172 productosPersonalizados($event: Producto[]) { 171 productosPersonalizados($event: Producto[]) {
173 172
174 var productosPersonalizados = $event; 173 var productosPersonalizados = $event;
175 174
176 this.promoAcargar.productos.forEach(productoPromo => { 175 this.promoAcargar.productos.forEach(productoPromo => {
177 176
178 if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); 177 if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo);
179 }) 178 })
180 179
181 this.promoAcargar.productos = productosPersonalizados; 180 this.promoAcargar.productos = productosPersonalizados;
182 this.confirmarProducto(); 181 this.confirmarProducto();
183 } 182 }
184 183
185 buscarByCodigoBarras(busqueda) { 184 buscarByCodigoBarras(busqueda) {
186 185
187 let producto = this.productos.filter(producto => { 186 let producto = this.productos.filter(producto => {
188 return producto.codigoBarra == busqueda; 187 return producto.codigoBarra == busqueda;
189 }); 188 });
190 189
191 if (producto.length) { 190 if (producto.length) {
src/app/components/master/master.component.ts
1 import { Component, OnInit, OnDestroy } from '@angular/core'; 1 import { Component, OnInit, OnDestroy } from '@angular/core';
2 import { Router } from '@angular/router'; 2 import { Router } from '@angular/router';
3 3
4 @Component({ 4 @Component({
5 selector: 'app-master', 5 selector: 'app-master',
6 templateUrl: './master.component.html', 6 templateUrl: './master.component.html',
7 styleUrls: ['./master.component.scss'] 7 styleUrls: ['./master.component.scss']
8 }) 8 })
9 export class MasterComponent implements OnInit, OnDestroy { 9 export class MasterComponent implements OnInit, OnDestroy {
10 10
11 private timerReposo: any 11 private timerReposo: any;
12 12
13 constructor( 13 constructor(
14 private router: Router 14 private router: Router
15 ) { } 15 ) { }
16 16
17 ngOnInit() { 17 ngOnInit() {
18 18
19 this.timerReposo = setTimeout(() => { 19 this.timerReposo = setTimeout(() => {
20 20
21 this.router.navigate(['cancelar-compra']); 21 this.router.navigate(['cancelar-compra']);
22 }, 90000) 22 }, 90000)
23 } 23 }
24 24
25 ngOnDestroy() { 25 ngOnDestroy() {
26 26
27 clearTimeout(this.timerReposo); 27 clearTimeout(this.timerReposo);
28 } 28 }
29 29
30 reiniciarTimer() { 30 reiniciarTimer() {
31 31
32 clearTimeout(this.timerReposo); 32 clearTimeout(this.timerReposo);
33 this.timerReposo = setTimeout(() => { 33 this.timerReposo = setTimeout(() => {
34 34
35 this.router.navigate(['cancelar-compra']); 35 this.router.navigate(['cancelar-compra']);
36 }, 90000) 36 }, 90000)
37
38 } 37 }
39 38
40 } 39 }
41 40
src/app/components/pago/pago.component.html
1 <div 1 <div
2 *ngIf="!compraConEfectivofinalizada && !compraConQRfinalizada" 2 *ngIf="!compraConEfectivofinalizada && !compraConQRfinalizada"
3 class="row m-0 fade-in bg-primary-gradient disable-user-select"> 3 class="row m-0 fade-in bg-primary-gradient disable-user-select"
4 (click)="reiniciarTimer()">
4 5
5 <div class="col-12 p-0 vh-100"> 6 <div class="col-12 p-0 vh-100">
6 7
7 <app-header></app-header> 8 <app-header></app-header>
8 9
9 <!-- NOMBRE DE SECCION --> 10 <!-- NOMBRE DE SECCION -->
10 <div class="row m-0"> 11 <div class="row m-0">
11 <div class="col-12 p-0"> 12 <div class="col-12 p-0">
12 <p class="h5 py-1 bg-gray text-muted text-center m-0"> 13 <p class="h5 py-1 bg-gray text-muted text-center m-0">
13 Pagar 14 Pagar
14 <i class="fa fa-usd"></i> 15 <i class="fa fa-usd"></i>
15 </p> 16 </p>
16 </div> 17 </div>
17 </div> 18 </div>
18 19
19 <div *ngIf="!verQR" class="row mt-4 m-3 d-flex align-items-center"> 20 <div *ngIf="!verQR" class="row mt-4 m-3 d-flex align-items-center">
20 <div class="col-7 text-center"> 21 <div class="col-7 text-center">
21 <p class="text-white h2" *ngIf="!verQR">Elija forma de pago</p> 22 <p class="text-white h2" *ngIf="!verQR">Elija forma de pago</p>
22 </div> 23 </div>
23 </div> 24 </div>
24 25
25 <div *ngIf="!verQR" class="row fade-in mt-3"> 26 <div *ngIf="!verQR" class="row fade-in mt-3">
26 <!-- GRILLA DE PRODUCTOS DE MI COMPRA --> 27 <!-- GRILLA DE PRODUCTOS DE MI COMPRA -->
27 <div class="col-sm-7"> 28 <div class="col-sm-7">
28 <div class="row ml-4 pr-3 vh-70 overflow-scroll text-dark"> 29 <div class="row ml-4 pr-3 vh-70 overflow-scroll text-dark">
29 <div class="col-4 p-2"> 30 <div class="col-4 p-2">
30 <div 31 <div
31 class="bg-white rounded-sm shadow border-0" 32 class="bg-white rounded-sm shadow border-0"
32 (click)="pagoEfectivo()"> 33 (click)="pagoEfectivo()">
33 <img src="{{apiUrl}}/imagenes/efectivo.png" class="rounded-sm w-75 py-2 mx-auto d-block"> 34 <img src="{{apiUrl}}/imagenes/efectivo.png" class="rounded-sm w-75 py-2 mx-auto d-block">
34 <div class="p-2 card-text text-center"> 35 <div class="p-2 card-text text-center">
35 <p class="h6 text-center m-0">Efectivo</p> 36 <p class="h6 text-center m-0">Efectivo</p>
36 </div> 37 </div>
37 </div> 38 </div>
38 </div> 39 </div>
39 <div class="col-4 p-2"> 40 <div class="col-4 p-2">
40 <div class="bg-white rounded-sm shadow border-0"> 41 <div class="bg-white rounded-sm shadow border-0">
41 <img src="{{apiUrl}}/imagenes/tarjeta.png" class="rounded-sm w-75 py-2 mx-auto d-block"> 42 <img src="{{apiUrl}}/imagenes/tarjeta.png" class="rounded-sm w-75 py-2 mx-auto d-block">
42 <div class="p-2 card-text text-center"> 43 <div class="p-2 card-text text-center">
43 <p class="h6 text-center m-0">Tarjeta</p> 44 <p class="h6 text-center m-0">Tarjeta</p>
44 </div> 45 </div>
45 </div> 46 </div>
46 </div> 47 </div>
47 <div class="col-4 p-2"> 48 <div class="col-4 p-2">
48 <div 49 <div
49 class="bg-white rounded-sm shadow border-0" 50 class="bg-white rounded-sm shadow border-0"
50 (click)="pagar()"> 51 (click)="pagar()">
51 <img src="{{apiUrl}}/imagenes/qr.png" class="rounded-sm w-75 py-2 mx-auto d-block"> 52 <img src="{{apiUrl}}/imagenes/qr.png" class="rounded-sm w-75 py-2 mx-auto d-block">
52 <div class="p-2 card-text text-center"> 53 <div class="p-2 card-text text-center">
53 <p class="h6 text-center m-0">Pago Electrónico</p> 54 <p class="h6 text-center m-0">Pago Electrónico</p>
54 </div> 55 </div>
55 </div> 56 </div>
56 </div> 57 </div>
57 </div> 58 </div>
58 </div> 59 </div>
59 60
60 <div class="col-sm-5 pl-0"> 61 <div class="col-sm-5 pl-0">
61 <div class="row ml-3"> 62 <div class="row ml-3">
62 <!-- TICKET --> 63 <!-- TICKET -->
63 <div class="col-sm-7 p-0"> 64 <div class="col-sm-7 p-0">
64 <div class="card rounded-sm shadow"> 65 <div class="card rounded-sm shadow">
65 <div class="card-body"> 66 <div class="card-body">
66 <p class="h5 card-title">Su Ticket</p> 67 <p class="h5 card-title">Su Ticket</p>
67 <div class="row mt-4 m-0"> 68 <div class="row mt-4 m-0">
68 <div class="col-12 p-0 mb-2"> 69 <div class="col-12 p-0 mb-2">
69 <p class="h6 m-0 card-text text-left"> 70 <p class="h6 m-0 card-text text-left">
70 <small class="font-weight-bold">DESCRIPCIÓN</small> 71 <small class="font-weight-bold">DESCRIPCIÓN</small>
71 </p> 72 </p>
72 <p class="h6 m-0 card-text text-left"> 73 <p class="h6 m-0 card-text text-left">
73 <small class="font-weight-bold">CANTIDAD X PRECIO UNITARIO</small> 74 <small class="font-weight-bold">CANTIDAD X PRECIO UNITARIO</small>
74 </p> 75 </p>
75 </div> 76 </div>
76 </div> 77 </div>
77 <div class="row px-2 vh-50 overflow-scroll m-0"> 78 <div class="row px-2 vh-50 overflow-scroll m-0">
78 <div class="col-12 p-0 mb-2" *ngFor="let producto of productos"> 79 <div class="col-12 p-0 mb-2" *ngFor="let producto of productos">
79 <p class="h6 m-0 card-text text-left"> 80 <p class="h6 m-0 card-text text-left">
80 <small>{{producto.DetArt}}</small> 81 <small>{{producto.DetArt}}</small>
81 </p> 82 </p>
82 <div class="row d-flex justify-content-between m-0"> 83 <div class="row d-flex justify-content-between m-0">
83 <div class="col p-0"> 84 <div class="col p-0">
84 <p class="h6 m-0 card-text text-left"> 85 <p class="h6 m-0 card-text text-left">
85 <small>{{producto.cantidad}} x {{producto.PreVen | currency}}</small> 86 <small>{{producto.cantidad}} x {{producto.PreVen | currency}}</small>
86 </p> 87 </p>
87 </div> 88 </div>
88 <div class="col p-0"> 89 <div class="col p-0">
89 <p class="h6 m-0 card-text text-right"> 90 <p class="h6 m-0 card-text text-right">
90 <small>{{(producto.PreVen) * (producto.cantidad) | currency}}</small> 91 <small>{{(producto.PreVen) * (producto.cantidad) | currency}}</small>
91 </p> 92 </p>
92 </div> 93 </div>
93 </div> 94 </div>
94 </div> 95 </div>
95 </div> 96 </div>
96 <p class="h4 font-weight-bold card-text text-right mt-3 mb-0"> 97 <p class="h4 font-weight-bold card-text text-right mt-3 mb-0">
97 Total {{getTotal() | currency}} 98 Total {{getTotal() | currency}}
98 </p> 99 </p>
99 </div> 100 </div>
100 </div> 101 </div>
101 </div> 102 </div>
102 </div> 103 </div>
103 </div> 104 </div>
104 </div> 105 </div>
105 106
106 <div *ngIf="verQR" class="row fade-in mt-5"> 107 <div *ngIf="verQR" class="row fade-in mt-5">
107 <div class="col-6 offset-3 border-0 mb-auto"> 108 <div class="col-6 offset-3 border-0 mb-auto">
108 <img src="{{apiUrl}}/imagenes/qrmp.jpg" class="w-50 mx-auto d-block shadow rounded-sm"> 109 <img src="{{apiUrl}}/imagenes/qrmp.jpg" class="w-50 mx-auto d-block shadow rounded-sm">
109 </div> 110 </div>
110 </div> 111 </div>
111 112
112 <!-- OPCIONES ABAJO DERECHA --> 113 <!-- OPCIONES ABAJO DERECHA -->
113 <div class="row m-0 fixed-bottom" > 114 <div class="row m-0 fixed-bottom" >
114 <div class="col-sm-2 offset-sm-10 p-0 mt-auto"> 115 <div class="col-sm-2 offset-sm-10 p-0 mt-auto">
115 <div class="card m-2 rounded-top-sm mt-auto blue-gradient border-0"> 116 <div class="card m-2 rounded-top-sm mt-auto blue-gradient border-0">
116 <div class="card-body row m-0"> 117 <div class="card-body row m-0">
117 <div class="col-12 p-3"> 118 <div class="col-12 p-3">
118 <button 119 <button
119 type="button" 120 type="button"
120 class="btn btn-block btn-light shadow btn-sm shadow" 121 class="btn btn-block btn-light shadow btn-sm shadow"
121 (click)="volverPreviousPage()"> 122 (click)="volverPreviousPage()">
122 <span class="pr-2">Volver</span> 123 <span class="pr-2">Volver</span>
123 <i class="fa fa-undo text-warning"></i> 124 <i class="fa fa-undo text-warning"></i>
124 </button> 125 </button>
125 <button 126 <button
126 type="button" 127 type="button"
127 class="btn btn-block btn-light shadow btn-sm shadow" 128 class="btn btn-block btn-light shadow btn-sm shadow"
128 [routerLink]="['/cancelar-compra']"> 129 [routerLink]="['/cancelar-compra']">
129 <span class="pr-2">Cancelar</span> 130 <span class="pr-2">Cancelar</span>
130 <i class="fa fa-times text-danger"></i> 131 <i class="fa fa-times text-danger"></i>
131 </button> 132 </button>
132 </div> 133 </div>
133 </div> 134 </div>
134 </div> 135 </div>
135 </div> 136 </div>
136 </div> 137 </div>
137 138
138 </div> 139 </div>
139 140
140 </div> 141 </div>
141 142
142 <div 143 <div
143 *ngIf="compraConQRfinalizada" 144 *ngIf="compraConQRfinalizada"
144 class="row m-0 fade-in bg-primary-gradient disable-user-select vh-100"> 145 class="row m-0 fade-in bg-primary-gradient disable-user-select vh-100">
145 <div class="col-12 text-center text-white my-auto"> 146 <div class="col-12 text-center text-white my-auto">
146 <p class="font-weight-bold display-4"> 147 <p class="font-weight-bold display-4">
147 Su pago fue<br> 148 Su pago fue<br>
148 acreditado 149 acreditado
149 exitosamente 150 exitosamente
150 </p> 151 </p>
151 <p class="font-weight-bold display-4">Recuerde retirar su ticket</p> 152 <p class="font-weight-bold display-4">Recuerde retirar su ticket</p>
152 </div> 153 </div>
153 </div> 154 </div>
154 155
155 <div 156 <div
156 *ngIf="compraConEfectivofinalizada" 157 *ngIf="compraConEfectivofinalizada"
157 class="row m-0 fade-in bg-primary-gradient disable-user-select vh-100"> 158 class="row m-0 fade-in bg-primary-gradient disable-user-select vh-100">
158 <div class="col-12 text-center text-white my-auto"> 159 <div class="col-12 text-center text-white my-auto">
159 <p class="font-weight-bold display-4"> 160 <p class="font-weight-bold display-4">
160 Retire su ticket<br> 161 Retire su ticket<br>
161 y diríjase a caja para<br> 162 y diríjase a caja para<br>
162 efectuar el pago. 163 efectuar el pago.
163 </p> 164 </p>
164 </div> 165 </div>
165 </div> 166 </div>
166 167
src/app/components/pago/pago.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit, OnDestroy } 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 { 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, OnDestroy {
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 private timerReposo: any;
22 23
23 constructor( 24 constructor(
24 private productoService: ProductoService, 25 private productoService: ProductoService,
25 private location: Location, 26 private location: Location,
26 private router: Router, 27 private router: Router,
27 ) { } 28 ) { }
28 29
29 ngOnInit() { 30 ngOnInit() {
30 31
32 this.timerReposo = setTimeout(() => {
33
34 this.router.navigate(['cancelar-compra']);
35 }, 90000)
31 this.productos = this.productoService.productos; 36 this.productos = this.productoService.productos;
32 } 37 }
33 38
39 ngOnDestroy() {
40
41 clearTimeout(this.timerReposo);
42 }
43
34 pagoEfectivo() { 44 pagoEfectivo() {
35 45
36 this.compraConEfectivofinalizada = true; 46 this.compraConEfectivofinalizada = true;
47 clearTimeout(this.timerReposo);
37 setTimeout(() => { 48 setTimeout(() => {
38 49
39 this.router.navigate(['mensaje-final']); 50 this.router.navigate(['mensaje-final']);
40 }, 3000); 51 }, 3000);
41 } 52 }
42 53
43 pagar() { 54 pagar() {
44 55
45 this.verQR = true; 56 this.verQR = true;
46 57
47 this.productoService.pagar() 58 this.productoService.pagar()
48 .subscribe(() => { 59 .subscribe(() => {
49 60
50 // alert('Compra finalizada'); 61 clearTimeout(this.timerReposo);
51 this.compraConQRfinalizada = true; 62 this.compraConQRfinalizada = true;
52 setTimeout(() => { 63 setTimeout(() => {
53 64
54 this.router.navigate(['mensaje-final']); 65 this.router.navigate(['mensaje-final']);
55 }, 3000); 66 }, 3000);
56 }, err => { 67 }, err => {
57 console.log(err); 68 console.log(err);
58 alert('algo salió mal'); 69 alert('algo salió mal');
59 }) 70 })
60 } 71 }
61 72
62 volverPreviousPage() { 73 volverPreviousPage() {
63 74
64 if (this.verQR) { 75 if (this.verQR) {
65 this.verQR = false; 76 this.verQR = false;
66 return; 77 return;
67 } 78 }
68 this.location.back(); 79 this.location.back();
69 } 80 }
70 81
71 getTotal() { 82 getTotal() {
72 83
73 var subTotal = 0; 84 var subTotal = 0;
74 this.productos.forEach(producto => { 85 this.productos.forEach(producto => {
75 86
76 subTotal = subTotal + (producto.PreVen * producto.cantidad); 87 subTotal = subTotal + (producto.PreVen * producto.cantidad);
77 }); 88 });
78 return this.total = subTotal; 89 return this.total = subTotal;
79 } 90 }
80 91
92 reiniciarTimer() {
93
94 clearTimeout(this.timerReposo);
95 this.timerReposo = setTimeout(() => {
96
97 this.router.navigate(['cancelar-compra']);
98 }, 90000)
99 }
100
81 } 101 }
82 102