Commit 375ff37aca79e49e5613ba4f38323ee43eb6cb45

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

Merge branch 'master' into 'master'

Master(mpuebla)

See merge request !48
src/app/components/home/home.component.html
1 <div class="container-fluid p-0"> 1 <div class="container-fluid p-0">
2 <img 2 <img
3 src="{{apiUrl}}/imagenes/homeBackground.jpg" 3 src="{{apiUrl}}/imagenes/homeBackground.jpg"
4 class="background-image vh-100 w-100"> 4 class="background-image vh-100 w-100">
5 <div class="row m-0"> 5 <div class="row m-0">
6 <div class="col p-0"> 6 <div class="col p-0">
7 <div 7 <div
8 class="vh-100 fade-in d-flex align-content-between flex-wrap disable-user-select" 8 class="vh-100 fade-in d-flex align-content-between flex-wrap disable-user-select"
9 [routerLink]="['/inicio']"> 9 [routerLink]="['/inicio']">
10 10
11 <!-- HEADER --> 11 <!-- HEADER -->
12 <div class="row m-0 w-100 bg-primary-gradient-horizontal"> 12 <div class="row m-0 w-100 bg-primary-gradient-horizontal">
13 <div class="col-6 bg-white p-3 rounded-bottom-right"> 13 <div class="col-6 bg-white p-3 rounded-bottom-right">
14 <img class="w-25 mx-auto d-block" src="{{apiUrl}}/imagenes/logoempresa.png"> 14 <img class="w-25 mx-auto d-block" src="{{apiUrl}}/imagenes/logoempresa.png">
15 </div> 15 </div>
16 </div> 16 </div>
17 17
18 <!-- INFO DE BIENVENIDA --> 18 <!-- INFO DE BIENVENIDA -->
19 <div class="row w-100"> 19 <div class="row w-100">
20 <div class="col-4 offset-2"> 20 <div class="col-4 offset-2">
21 21
22 <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel"> 22 <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
23 <div class="carousel-inner"> 23 <div class="carousel-inner">
24 <div class="carousel-item active"> 24 <div class="carousel-item active">
25 <img 25 <img
26 src="{{apiUrl}}/imagenes/coca1.jpg" 26 src="{{apiUrl}}/imagenes/coca1.jpg"
27 class="d-block rounded-sm shadow w-100"> 27 class="d-block rounded-sm shadow w-75">
28 </div> 28 </div>
29 <div class="carousel-item"> 29 <div class="carousel-item">
30 <img 30 <img
31 src="{{apiUrl}}/imagenes/coca2.jpg" 31 src="{{apiUrl}}/imagenes/coca2.jpg"
32 class="d-block rounded-sm shadow w-100"> 32 class="d-block rounded-sm shadow w-75">
33 </div> 33 </div>
34 <div class="carousel-item"> 34 <div class="carousel-item">
35 <img 35 <img
36 src="{{apiUrl}}/imagenes/coca3.jpg" 36 src="{{apiUrl}}/imagenes/coca3.jpg"
37 class="d-block rounded-sm shadow w-100"> 37 class="d-block rounded-sm shadow w-75">
38 </div> 38 </div>
39 </div> 39 </div>
40 </div> 40 </div>
41 41
42 </div> 42 </div>
43 <div class="col-6 text-center text-white my-auto"> 43 <div class="col-6 text-center text-white my-auto">
44 <p class="display-2 font-weight-bold mb-5">¡BIENVENIDO!</p> 44 <p class="display-2 font-weight-bold mb-5">¡BIENVENIDO!</p>
45 <p class="display-3 m-0 font-weight-bold">Toque la pantalla<br>para comenzar</p> 45 <p class="display-3 m-0 font-weight-bold">Toque la pantalla<br>para comenzar</p>
46 </div> 46 </div>
47 </div> 47 </div>
48 48
49 <!-- FOOTER --> 49 <!-- FOOTER -->
50 <div class="row m-0 w-100 bg-gray"> 50 <div class="row m-0 w-100 bg-gray">
51 <div class="col-6 bg-white offset-6 p-3 rounded-top-left"> 51 <div class="col-6 bg-white offset-6 p-3 rounded-top-left">
52 <img class="w-25 mx-auto d-block" src="{{apiUrl}}/imagenes/logodebo.png"> 52 <img class="w-25 mx-auto d-block" src="{{apiUrl}}/imagenes/logodebo.png">
53 </div> 53 </div>
54 </div> 54 </div>
55 55
56 </div> 56 </div>
57 </div> 57 </div>
58 </div> 58 </div>
59 </div> 59 </div>
60 60
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 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { 16 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) {
17 17
18 if (e.keyCode == 13) { 18 if (e.keyCode == 13) {
19 this.buscarByCodigoBarras(this.busqueda); 19 this.buscarByCodigoBarras(this.busqueda);
20 this.busqueda = ''; 20 this.busqueda = '';
21 } else { 21 } else {
22 this.busqueda += e.key; 22 this.busqueda += e.key;
23 } 23 }
24 24
25 }; 25 };
26 26
27 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; 27 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective;
28 private tienePromo = false; 28 private tienePromo = false;
29 private productoEsPromo = false; 29 private productoEsPromo = false;
30 private busqueda: string = ''; 30 private busqueda: string = '';
31 31
32 private productoAcargar: Producto; 32 private productoAcargar: Producto;
33 private promoAcargar: Producto; 33 private promoAcargar: Producto;
34 34
35 productos: Producto[] = []; 35 productos: Producto[] = [];
36 promociones: Producto[] = []; 36 promociones: Producto[] = [];
37 sinonimos: Sinonimo[] = []; 37 sinonimos: Sinonimo[] = [];
38 apiUrl: string = appSettings.apiUrl 38 apiUrl: string = appSettings.apiUrl
39 39
40 constructor( 40 constructor(
41 private router: Router, 41 private router: Router,
42 private productoService: ProductoService) { } 42 private productoService: ProductoService) { }
43 43
44 ngOnInit() { 44 ngOnInit() {
45 45
46 this.productoAcargar = this.productoService.productoAcargar; 46 this.productoAcargar = this.productoService.productoAcargar;
47 if (this.productoAcargar) { 47 if (this.productoAcargar) {
48 if (this.productoAcargar.PRO) { 48 if (this.productoAcargar.PRO) {
49 this.promociones.push(this.productoAcargar); 49 this.promociones.push(this.productoAcargar);
50 this.promoSeleccionada(this.productoAcargar); 50 this.promoSeleccionada(this.productoAcargar);
51 } 51 }
52 else 52 else
53 this.getPromociones(); 53 this.getPromociones();
54 } 54 }
55 this.getProductos(); 55 this.getProductos();
56 } 56 }
57 57
58 getPromociones() { 58 getPromociones() {
59 59
60 var sector = this.productoAcargar.CodSec; 60 var sector = this.productoAcargar.CodSec;
61 var codigo = this.productoAcargar.CodArt; 61 var codigo = this.productoAcargar.CodArt;
62 this.productoService.getPromociones(sector, codigo) 62 this.productoService.getPromociones(sector, codigo)
63 .subscribe((res: Producto[]) => { 63 .subscribe((res: Producto[]) => {
64 64
65 if (res.length === 0) { 65 if (res.length === 0) {
66 //Si no tiene promociones la cargará al carrito despues de un tiempo 66 //Si no tiene promociones la cargará al carrito despues de un tiempo
67 // setTimeout(() => { 67 // setTimeout(() => {
68 this.productoAcargar.cantidad = 1; 68 this.productoAcargar.cantidad = 1;
69 this.productoService.productos.push(this.productoAcargar); 69 this.productoService.productos.push(this.productoAcargar);
70 this.productoAcargar = this.productoService.productoAcargar = undefined; 70 this.productoAcargar = this.productoService.productoAcargar = undefined;
71 // }, 2000) 71 // }, 2000)
72 } else { 72 } else {
73 73
74 this.promociones = res; 74 this.promociones = res;
75 this.popoverDirective.show(); 75 this.popoverDirective.show();
76 } 76 }
77 }, error => { console.error(error); }) 77 }, error => { console.error(error); })
78 } 78 }
79 79
80 showPopover() {
81
82 this.popoverDirective.show();
83 }
84
85 getProductos() { 80 getProductos() {
86 this.productoService.getAll() 81 this.productoService.getAll()
87 .subscribe((productos: Producto[]) => { 82 .subscribe((productos: Producto[]) => {
88 this.productos = productos; 83 this.productos = productos;
89 }); 84 });
90 } 85 }
91 86
92 irBusquedaProductos(verPromociones) { 87 irBusquedaProductos(verPromociones) {
93 88
94 this.productoService.verCategoriasProductos = verPromociones; 89 this.productoService.verCategoriasProductos = verPromociones;
95 this.router.navigate(['busqueda-productos']); 90 this.router.navigate(['busqueda-productos']);
96 } 91 }
97 92
98 confirmarProducto() { 93 confirmarProducto() {
99 this.promoAcargar.cantidad = 1; 94 this.promoAcargar.cantidad = 1;
100 this.productoService.productos.push(this.promoAcargar); 95 this.productoService.productos.push(this.promoAcargar);
101 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; 96 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined;
102 this.promociones = []; 97 this.promociones = [];
103 this.popoverDirective.hide(); 98 this.popoverDirective.hide();
104 } 99 }
105 100
106 deshacerCarga() { 101 deshacerCarga() {
107 102
108 if (this.sinonimos.length > 0) { 103 if (this.sinonimos.length > 0) {
109 this.sinonimos = []; 104 this.sinonimos = [];
110 this.popoverDirective.hide(); 105 this.popoverDirective.hide();
111 } 106 }
112 107
113 if (this.promoAcargar) { 108 if (this.promoAcargar) {
114 this.promoAcargar = undefined; 109 this.promoAcargar = undefined;
115 if (this.productoAcargar.PRO) { 110 if (this.productoAcargar.PRO) {
116 this.productoAcargar = undefined; 111 this.productoAcargar = undefined;
117 this.promociones = []; 112 this.promociones = [];
118 this.popoverDirective.hide(); 113 this.popoverDirective.hide();
119 } else { 114 } else {
120 this.popoverDirective.show(); 115 this.popoverDirective.show();
121 } 116 }
122 } else { 117 } else {
123 this.productoAcargar = undefined; 118 this.productoAcargar = undefined;
124 this.promociones = []; 119 this.promociones = [];
125 this.popoverDirective.hide(); 120 this.popoverDirective.hide();
126 } 121 }
127 } 122 }
128 123
129 promoSeleccionada($event: Producto) { 124 promoSeleccionada($event: Producto) {
130 125
131 this.promoAcargar = $event; 126 this.promoAcargar = $event;
132 this.promoAcargar.tieneSinonimos = true;
133 if (this.promoAcargar.tieneSinonimos) { 127 if (this.promoAcargar.tieneSinonimos) {
134 var sector = this.promoAcargar.CodSec; 128 var sector = this.promoAcargar.CodSec;
135 var codigo = this.promoAcargar.CodArt; 129 var codigo = this.promoAcargar.CodArt;
136 this.productoService.getPromocionSinonimos(sector, codigo) 130 this.getSinonimos(sector, codigo);
137 .subscribe((res: Sinonimo[]) => { 131
132 } else if (this.popoverDirective) {
133 this.popoverDirective.hide();
134 }
135 }
136
137 getSinonimos(sector, codigo) {
138 138
139 res.forEach(sinonimo => { 139 this.productoService.getPromocionSinonimos(sector, codigo)
140 .subscribe((res: Sinonimo[]) => {
140 141
141 sinonimo.productos.forEach(productoSinonimo => { 142 res.forEach(sinonimo => {
142 143
143 this.promoAcargar.productos.forEach(productoPromo => { 144 sinonimo.productos.forEach(productoSinonimo => {
144 145
145 if (productoSinonimo.id === productoPromo.id) { 146 this.promoAcargar.productos.forEach(productoPromo => {
146 sinonimo.cantidad = productoPromo.cantidad; 147
147 sinonimo.productoPadre = productoPromo.id; 148 if (productoSinonimo.id === productoPromo.id) {
148 } 149 sinonimo.cantidad = productoPromo.cantidad;
149 }) 150 sinonimo.productoPadre = productoPromo.id;
151 }
150 }) 152 })
151 }) 153 })
152
153 this.sinonimos = res;
154 if (res.length > 0)
155 this.showPopover();
156 else
157 this.popoverDirective.hide();
158 }) 154 })
159 } else { 155
160 this.popoverDirective.hide(); 156 this.sinonimos = res;
161 } 157 if (res.length > 0)
158 this.popoverDirective.show();
159 else
160 this.popoverDirective.hide();
161 })
162 } 162 }
163 163
164 productosPersonalizados($event: Producto[]) { 164 productosPersonalizados($event: Producto[]) {
165 165
166 var productosPersonalizados = $event; 166 var productosPersonalizados = $event;
167 167
168 this.promoAcargar.productos.forEach(productoPromo => { 168 this.promoAcargar.productos.forEach(productoPromo => {
169 169
170 if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); 170 if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo);
171 }) 171 })
172 172
173 this.promoAcargar.productos = productosPersonalizados; 173 this.promoAcargar.productos = productosPersonalizados;
174 this.confirmarProducto(); 174 this.confirmarProducto();
175 } 175 }
176 176
177 buscarByCodigoBarras(busqueda) { 177 buscarByCodigoBarras(busqueda) {
178 178
179 let producto = this.productos.filter(producto => { 179 let producto = this.productos.filter(producto => {
180 return producto.codigoBarra == busqueda; 180 return producto.codigoBarra == busqueda;
181 }); 181 });
182 182
183 if (producto.length) { 183 if (producto.length) {