Commit 5962f7dea6014988c2e8344066b3c3f669c3b013

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

Merge branch 'master' into 'master'

Master(mpuebla)

See merge request !72
src/app/components/inicio/inicio.component.ts
1 import { Component, OnInit, ViewChild, HostListener, AfterViewInit } from '@angular/core'; 1 import { Component, OnInit, ViewChild, HostListener, AfterViewInit } 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, AfterViewInit { 14 export class InicioComponent implements OnInit, AfterViewInit {
15 15
16 private tienePromo = false; 16 private tienePromo = false;
17 private productoEsPromo = false; 17 private productoEsPromo = false;
18 private busqueda: string = ''; 18 private busqueda: string = '';
19 private productoAcargar: Producto; 19 private productoAcargar: Producto;
20 private promoAcargar: Producto; 20 private promoAcargar: Producto;
21 private productos: Producto[] = []; 21 private productos: Producto[] = [];
22 private promociones: Producto[] = []; 22 private promociones: Producto[] = [];
23 private sinonimos: Sinonimo[] = []; 23 private sinonimos: Sinonimo[] = [];
24 private apiImagenes: string = appSettings.apiImagenes; 24 private apiImagenes: string = appSettings.apiImagenes;
25 25
26 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; 26 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective;
27 27
28 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { 28 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) {
29 29
30 if (e.keyCode == 13) { 30 if (e.keyCode == 13) {
31 this.buscarByCodigoBarras(this.busqueda); 31 this.buscarByCodigoBarras(this.busqueda);
32 this.busqueda = ''; 32 this.busqueda = '';
33 } else { 33 } else {
34 this.busqueda += e.key; 34 this.busqueda += e.key;
35 } 35 }
36 36
37 }; 37 };
38 38
39 constructor( 39 constructor(
40 private router: Router, 40 private router: Router,
41 private productoService: ProductoService 41 private productoService: ProductoService
42 ) { } 42 ) { }
43 43
44 ngOnInit() { 44 ngOnInit() {
45 45
46 this.productoAcargar = this.productoService.productoAcargar; 46 this.productoAcargar = this.productoService.productoAcargar;
47 this.getProductos(); 47 this.getProductos();
48 } 48 }
49 49
50 ngAfterViewInit() { 50 ngAfterViewInit() {
51 51
52 setTimeout(() => { 52 setTimeout(() => {
53 if (!this.productoAcargar) return; 53 if (!this.productoAcargar) return;
54 54
55 if (this.productoAcargar.PRO) { 55 if (this.productoAcargar.PRO) {
56 this.promociones.push(this.productoAcargar); 56 this.promociones.push(this.productoAcargar);
57 this.promoSeleccionada(this.productoAcargar, true); 57 this.promoSeleccionada(this.productoAcargar, true);
58 } 58 }
59 else { 59 else {
60 this.getPromociones(); 60 this.getPromociones();
61 } 61 }
62 }) 62 })
63 } 63 }
64 64
65 getProductos() { 65 getProductos() {
66 66
67 this.productoService.getAll() 67 this.productoService.getAll()
68 .subscribe((productos: Producto[]) => { 68 .subscribe((productos: Producto[]) => {
69 this.productos = productos; 69 this.productos = productos;
70 }); 70 });
71 } 71 }
72 72
73 getPromociones() { 73 getPromociones() {
74 74
75 var sector = this.productoAcargar.CodSec; 75 var sector = this.productoAcargar.CodSec;
76 var codigo = this.productoAcargar.CodArt; 76 var codigo = this.productoAcargar.CodArt;
77 this.productoService.getPromociones(sector, codigo) 77 this.productoService.getPromociones(sector, codigo)
78 .subscribe((res: Producto[]) => { 78 .subscribe((res: Producto[]) => {
79 79
80 if (res.length === 0) { 80 if (res.length === 0) {
81 81
82 this.productoAcargar.cantidad = 1; 82 this.productoAcargar.cantidad = 1;
83 this.productoService.setProductos(this.productoAcargar); 83 this.productoService.setProductos(this.productoAcargar);
84 this.productoAcargar = this.productoService.productoAcargar = undefined; 84 this.productoAcargar = this.productoService.productoAcargar = undefined;
85 } else { 85 } else {
86 86
87 this.promociones = res; 87 this.promociones = res;
88 this.popoverDirective.show(); 88 this.popoverDirective.show();
89 } 89 }
90 }, error => { console.error(error); }) 90 }, error => { console.error(error); })
91 } 91 }
92 92
93 confirmarProducto() { 93 confirmarProducto() {
94 94
95 var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; 95 var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar;
96 producto.cantidad = 1; 96 producto.cantidad = 1;
97 this.productoService.setProductos(producto); 97 this.productoService.setProductos(producto);
98 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; 98 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined;
99 this.productoService.esPromoPersonalizada = false;
99 this.promociones = []; 100 this.promociones = [];
100 this.popoverDirective.hide(); 101 this.popoverDirective.hide();
101 } 102 }
102 103
103 promoSeleccionada($event: Producto, showPopover: boolean) { 104 promoSeleccionada($event: Producto, showPopover: boolean) {
104 105
105 this.productoService.getProductoById($event.id) 106 this.productoService.getProductoById($event.id)
106 .subscribe((res: Producto) => { 107 .subscribe((res: Producto) => {
107 108
108 $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes; 109 $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes;
109 this.promoAcargar = $event; 110 this.promoAcargar = $event;
110 111
111 if ($event.tieneSinonimos) { 112 if ($event.tieneSinonimos) {
112 this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); 113 this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt);
113 } else if (showPopover) { 114 } else if (showPopover) {
114 this.popoverDirective.show(); 115 this.popoverDirective.show();
115 } else { 116 } else {
116 this.popoverDirective.hide(); 117 this.popoverDirective.hide();
117 } 118 }
118 119
119 }, 120 },
120 error => { console.log(error); }) 121 error => { console.log(error); })
121 } 122 }
122 123
123 getSinonimos(sector, codigo) { 124 getSinonimos(sector, codigo) {
124 125
125 this.productoService.getPromocionSinonimos(sector, codigo) 126 this.productoService.getPromocionSinonimos(sector, codigo)
126 .subscribe((res: Sinonimo[]) => { 127 .subscribe((res: Sinonimo[]) => {
127 128
128 res.forEach(sinonimo => { 129 res.forEach(sinonimo => {
129 130
130 sinonimo.cantidad = 0; 131 sinonimo.cantidad = 0;
131 this.promoAcargar.productos.forEach(productoPromo => { 132 this.promoAcargar.productos.forEach(productoPromo => {
132 133
133 sinonimo.productos.forEach(productoSinonimo => { 134 sinonimo.productos.forEach(productoSinonimo => {
134 135
135 if (productoSinonimo.id === productoPromo.id) { 136 if (productoSinonimo.id === productoPromo.id) {
136 productoSinonimo.cantidad = productoPromo.cantidad; 137 productoSinonimo.cantidad = productoPromo.cantidad;
137 sinonimo.cantidad += productoPromo.cantidad; 138 sinonimo.cantidad += productoPromo.cantidad;
138 } 139 }
139 }) 140 })
140 }) 141 })
141 }) 142 })
142 this.sinonimos = res; 143 this.sinonimos = res;
143 (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide(); 144 (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide();
144 }) 145 })
145 } 146 }
146 147
147 productosPersonalizados($event: Producto[]) { 148 productosPersonalizados($event: Producto[]) {
148 149
149 var productosPersonalizados = $event; 150 var productosPersonalizados = $event;
150 151
151 this.promoAcargar.productos.forEach(productoPromo => { 152 this.promoAcargar.productos.forEach(productoPromo => {
152 153
153 if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo); 154 if (!productoPromo.idSinonimo) productosPersonalizados.push(productoPromo);
154 }) 155 })
155 156
156 this.promoAcargar.productos = productosPersonalizados; 157 this.promoAcargar.productos = productosPersonalizados;
157 this.confirmarProducto(); 158 this.confirmarProducto();
158 } 159 }
159 160
160 buscarByCodigoBarras(busqueda) { 161 buscarByCodigoBarras(busqueda) {
161 162
162 let producto = this.productos.filter(producto => { 163 let producto = this.productos.filter(producto => {
163 return producto.codigoBarra == busqueda; 164 return producto.codigoBarra == busqueda;
164 }); 165 });
165 166
166 if (producto.length) { 167 if (producto.length) {
167 168
168 this.productoAcargar = producto[0]; 169 this.productoAcargar = producto[0];
169 this.getPromociones(); 170 this.getPromociones();
170 171
171 } else { 172 } else {
172 alert('No se encuentra el producto'); 173 alert('No se encuentra el producto');
173 } 174 }
174 175
175 } 176 }
176 177
177 irBusquedaProductos(value) { 178 irBusquedaProductos(value) {
178 179
179 this.productoService.mostrar = value; 180 this.productoService.mostrar = value;
180 this.router.navigate(['busqueda-productos']); 181 this.router.navigate(['busqueda-productos']);
181 } 182 }
182 183
183 deshacerCarga() { 184 deshacerCarga() {
184 185
185 if (this.sinonimos.length > 0) { 186 if (this.sinonimos.length > 0) {
186 this.sinonimos = []; 187 this.sinonimos = [];
188 this.productoService.esPromoPersonalizada = false;
187 this.popoverDirective.hide(); 189 this.popoverDirective.hide();
188 } 190 }
189 191
190 if (this.promoAcargar) { 192 if (this.promoAcargar) {
191 this.promoAcargar = undefined; 193 this.promoAcargar = undefined;
192 if (this.productoAcargar.PRO) { 194 if (this.productoAcargar.PRO) {
193 this.productoAcargar = undefined; 195 this.productoAcargar = undefined;
194 this.promociones = []; 196 this.promociones = [];
195 this.popoverDirective.hide(); 197 this.popoverDirective.hide();
196 } else { 198 } else {
197 this.popoverDirective.show(); 199 this.popoverDirective.show();
198 } 200 }
199 } else { 201 } else {
200 this.productoAcargar = undefined; 202 this.productoAcargar = undefined;
201 this.promociones = []; 203 this.promociones = [];
202 this.popoverDirective.hide(); 204 this.popoverDirective.hide();
203 } 205 }
204 } 206 }
205 207
206 } 208 }
207 209
src/app/components/popover-sinonimos/popover-sinonimos.component.html
1 <div class="card-body fade-left"> 1 <div class="card-body fade-left">
2 2
3 <div class="row m-0"> 3 <div class="row m-0">
4 <div class="col text-left"> 4 <div class="col text-left">
5 <p class="h4 card-title"> 5 <p class="h4 card-title">
6 Personalice su pedido 6 Personalice su pedido
7 </p> 7 </p>
8 </div> 8 </div>
9 </div> 9 </div>
10 10
11 <div class="row m-0 pr-2 my-2"> 11 <div class="row m-0 pr-2 my-2">
12 <div class="col"> 12 <div class="col">
13 <div class="row mb-2" *ngFor="let sinonimo of popoverContent; let i = index"> 13 <div class="row mb-2" *ngFor="let sinonimo of popoverContent; let i = index">
14 <div class="col p-0"> 14 <div class="col p-0">
15 15
16 <div class="row m-0"> 16 <div class="row bg-white text-dark m-0 py-1 shadow">
17 <div class="col text-left"> 17 <div class="col text-left">
18 <p class="h5 card-title"> 18 <p class="h5 m-0 card-title">
19 Elija opción - Cantidad Restante {{cantidadRestanteSinonimos[i]}} 19 Elija opción -
20 <span [ngClass]="
21 {
22 'text-success': cantidadRestanteSinonimos == 0,
23 'text-danger': cantidadRestanteSinonimos > 0
24 }">
25 Cantidad Restante {{cantidadRestanteSinonimos}}
26 </span>
20 </p> 27 </p>
21 </div> 28 </div>
22 </div> 29 </div>
23 30
24 <div class="row m-0 popover-size overflow-scroll"> 31 <div class="row m-0 popover-size overflow-scroll">
25 <div class="col-12 p-0"> 32 <div class="col-12 p-0">
26 <div class="row m-0 my-3 d-flex justify-content-between" *ngFor="let producto of sinonimo.productos"> 33 <div class="row m-0 my-3 d-flex justify-content-between" *ngFor="let producto of sinonimo.productos">
27 <div class="col-7 p-0 h6 text-right"> 34 <div class="col-7 p-0 h6 text-right">
28 <p class="m-0 font-weight-normal"> 35 <p class="m-0 font-weight-normal">
29 {{producto.DetArt}} 36 {{producto.DetArt}}
30 </p> 37 </p>
31 </div> 38 </div>
32 <div class="col-5 pr-0"> 39 <div class="col-5 pr-0">
33 <div class="btn-group float-right my-auto" role="group"> 40 <div class="btn-group float-right my-auto" role="group">
34 <button 41 <button
35 type="button" 42 type="button"
36 class="btn btn-light my-auto border shadow" 43 class="btn btn-light my-auto border shadow"
37 (click)="sumarCantidad(producto, i)"> 44 (click)="sumarCantidad(producto, i)">
38 <i class="fa fa-plus" aria-hidden="true"></i> 45 <i class="fa fa-plus" aria-hidden="true"></i>
39 </button> 46 </button>
40 <div class="bg-white border border-white px-3 py-1 my-auto text-dark h5"> 47 <div class="bg-white border border-white px-3 py-1 my-auto text-dark h5">
41 <small 48 <small
42 [ngClass]="{'font-weight-bold': producto.cantidad > 0}"> 49 [ngClass]="{'font-weight-bold': producto.cantidad > 0}">
43 {{producto.cantidad}} 50 {{producto.cantidad}}
44 </small> 51 </small>
45 </div> 52 </div>
46 <button 53 <button
47 type="button" 54 type="button"
48 class="btn btn-light my-auto border shadow" 55 class="btn btn-light my-auto border shadow"
49 (click)="restarCantidad(producto, i)"> 56 (click)="restarCantidad(producto, i)">
50 <i class="fa fa-minus" aria-hidden="true"></i> 57 <i class="fa fa-minus" aria-hidden="true"></i>
51 </button> 58 </button>
52 </div> 59 </div>
53 </div> 60 </div>
54 </div> 61 </div>
55 </div> 62 </div>
56 </div> 63 </div>
57 64
58 </div> 65 </div>
59 </div> 66 </div>
60 </div> 67 </div>
61 </div> 68 </div>
62 69
63 <div class="row mt-3 justify-content-end"> 70 <div class="row mt-3 justify-content-end">
64 <div class="col"> 71 <div class="col">
65 <button 72 <button
66 type="button" 73 type="button"
67 class="btn btn-block btn-light shadow" 74 class="btn btn-block btn-light shadow"
68 (click)="continuar()"> 75 (click)="continuar()">
69 <span class="font-weight-bold pr-2">Continuar</span> 76 <span class="font-weight-bold pr-2">Continuar</span>
70 <i class="fa fa-check text-success" aria-hidden="true"></i> 77 <i class="fa fa-check text-success" aria-hidden="true"></i>
71 </button> 78 </button>
72 </div> 79 </div>
73 </div> 80 </div>
74 81
75 </div> 82 </div>
src/app/components/popover-sinonimos/popover-sinonimos.component.ts
1 import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; 1 import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
2 import { PopoverDirective } from 'ngx-bootstrap'; 2 import { PopoverDirective } from 'ngx-bootstrap';
3 import { Producto } from 'src/app/wrappers/producto'; 3 import { Producto } from 'src/app/wrappers/producto';
4 import { Sinonimo } from 'src/app/wrappers/sinonimo'; 4 import { Sinonimo } from 'src/app/wrappers/sinonimo';
5 import { ProductoService } from 'src/app/services/producto.service'; 5 import { ProductoService } from 'src/app/services/producto.service';
6 6
7 @Component({ 7 @Component({
8 selector: 'app-popover-sinonimos', 8 selector: 'app-popover-sinonimos',
9 templateUrl: './popover-sinonimos.component.html', 9 templateUrl: './popover-sinonimos.component.html',
10 styleUrls: ['./popover-sinonimos.component.scss'] 10 styleUrls: ['./popover-sinonimos.component.scss']
11 }) 11 })
12 export class PopoverSinonimosComponent implements OnInit { 12 export class PopoverSinonimosComponent implements OnInit {
13 13
14 //Directiva del popover, para poder cerrarlo desde este componente 14 //Directiva del popover, para poder cerrarlo desde este componente
15 @Input() popover: PopoverDirective; 15 @Input() popover: PopoverDirective;
16 @Input() popoverContent: Sinonimo[]; 16 @Input() popoverContent: Sinonimo[];
17 @Output() productosPersonalizados = new EventEmitter<Producto[]>(); 17 @Output() productosPersonalizados = new EventEmitter<Producto[]>();
18 // sinonimo: Sinonimo; 18 // sinonimo: Sinonimo;
19 19
20 private cantidadRestanteSinonimos: number[] = []; 20 private cantidadRestanteSinonimos: number = 0;
21 21
22 constructor(private productoService: ProductoService) { } 22 constructor(private productoService: ProductoService) { }
23 23
24 ngOnInit() { 24 ngOnInit() {
25 25
26 this.popoverContent.forEach(sinonimo => { 26 this.popoverContent.forEach(sinonimo => {
27 27
28 this.cantidadRestanteSinonimos.push(0);
29
30 sinonimo.productos.forEach((producto, index) => { 28 sinonimo.productos.forEach((producto, index) => {
31 29
32 if (producto.cantidad) { 30 if (this.productoService.esPromoPersonalizada) {
33 sinonimo.productos.splice(index, 1); 31 producto.cantidad = producto.cantidad ? producto.cantidad : 0;
34 sinonimo.productos.splice(0, 0, producto); 32 this.cantidadRestanteSinonimos = 0;
35 } else { 33 } else {
34 this.cantidadRestanteSinonimos += producto.cantidad ? producto.cantidad : 0;
36 producto.cantidad = 0; 35 producto.cantidad = 0;
37 } 36 }
38 37
39 }) 38 })
40 }) 39 })
41 } 40 }
42 41
43 continuar() { 42 continuar() {
44 43
45 //Si aún quedan articulos que agregar no deja continuar. 44 //Si aún quedan articulos que agregar no deja continuar.
46 for (let i = 0; i < this.cantidadRestanteSinonimos.length; i++) { 45 if (this.cantidadRestanteSinonimos > 0) return;
47
48 if (this.cantidadRestanteSinonimos[i] > 0) return;
49 }
50 46
51 var productosAenviar: Producto[] = []; 47 var productosAenviar: Producto[] = [];
52 48
53 this.popoverContent.forEach(sinonimo => { 49 this.popoverContent.forEach(sinonimo => {
54 50
55 sinonimo.productos.forEach(producto => { 51 sinonimo.productos.forEach(producto => {
56 52
57 if (producto.cantidad > 0) { 53 if (producto.cantidad > 0) {
58 producto.idSinonimo = sinonimo.ID_SIN; 54 producto.idSinonimo = sinonimo.ID_SIN;
59 productosAenviar.push(producto); 55 productosAenviar.push(producto);
60 } 56 }
61 }) 57 })
62 58
63 }) 59 })
64 60
65 this.productosPersonalizados.emit(productosAenviar); 61 this.productosPersonalizados.emit(productosAenviar);
66 this.popover.hide(); 62 this.popover.hide();
67 } 63 }
68 64
69 sumarCantidad(producto: Producto, i: number) { 65 sumarCantidad(producto: Producto, i: number) {
70 66
71 if (this.cantidadRestanteSinonimos[i] === 0) return; 67 if (this.cantidadRestanteSinonimos === 0) return;
72 producto.cantidad++; 68 producto.cantidad++;
73 this.cantidadRestanteSinonimos[i]--; 69 this.cantidadRestanteSinonimos--;
74 } 70 }
75 71
76 restarCantidad(producto: Producto, i: number) { 72 restarCantidad(producto: Producto, i: number) {
77 73
78 if (this.cantidadRestanteSinonimos[i] === this.popoverContent[i].cantidad) return; 74 if (this.cantidadRestanteSinonimos === this.popoverContent[i].cantidad) return;
79 if (producto.cantidad === 0) return; 75 if (producto.cantidad === 0) return;
80 producto.cantidad--; 76 producto.cantidad--;
81 this.cantidadRestanteSinonimos[i]++; 77 this.cantidadRestanteSinonimos++;
82 } 78 }
83 79
84 } 80 }
src/app/components/sidebar/sidebar.component.html
1 <div class="disable-user-select d-flex align-items-center flex-column h-100 pt-2 text-center"> 1 <div class="disable-user-select d-flex align-items-center flex-column h-100 pt-2 text-center">
2 2
3 <!-- ENCABEZADO --> 3 <!-- ENCABEZADO -->
4 <p class="h4 border-bottom border-white text-white mt-4 pb-2"> 4 <p class="h4 border-bottom border-white text-white mt-4 pb-2">
5 Mi compra 5 Mi compra
6 <i class="fa fa-shopping-cart" aria-hidden="true"></i> 6 <i class="fa fa-shopping-cart" aria-hidden="true"></i>
7 </p> 7 </p>
8 8
9 <div class="overflow-auto overflow-scroll mb-2 w-100"> 9 <div class="overflow-scroll px-1 mb-2 w-100">
10 <!-- PRODUCTOS CARRITO --> 10 <!-- PRODUCTOS CARRITO -->
11 <div 11 <div
12 class="slide-in-bl my-2 bg-white border-0 rounded-sm" 12 class="my-2 bg-white border-0 rounded-sm"
13 *ngFor="let producto of productosCarrito.slice().reverse(); let i = index"> 13 *ngFor="let producto of productosCarrito.slice().reverse(); let i = index">
14 <img class="w-100 m-auto rounded-sm shadow" src="{{apiImagenes}}/imagenes/{{producto.imagenes[0].imagen}}"> 14 <img class="w-100 m-auto rounded-sm shadow" src="{{apiImagenes}}/imagenes/{{producto.imagenes[0].imagen}}">
15 <div class="row m-0 p-0 px-1 py-1 shadow rounded-sm"> 15 <div class="row m-0 p-0 px-1 py-1 shadow rounded-sm">
16 <div class="col-12 p-0 pt-2 text-left my-auto"> 16 <div class="col-12 p-0 pt-2 text-left my-auto">
17 <p class="m-0 h6"><small>{{producto.DetArt}}</small></p> 17 <p class="m-0 h6"><small>{{producto.DetArt}}</small></p>
18 </div> 18 </div>
19 <div class="col-12 pr-1 text-right h6 my-auto "> 19 <div class="col-12 pr-1 text-right h6 my-auto ">
20 <p class="m-0">{{producto.PreVen | currency}}</p> 20 <p class="m-0">{{producto.PreVen | currency}}</p>
21 </div> 21 </div>
22 </div> 22 </div>
23 23
24 <!-- BOTONES --> 24 <!-- BOTONES -->
25 <div class="row m-0 d-flex justify-content-between"> 25 <div class="row m-0 d-flex justify-content-between">
26 26
27 <!-- SUMAR - RESTAR CANTIDAD --> 27 <!-- SUMAR - RESTAR CANTIDAD -->
28 <div class="col-auto px-1 my-2"> 28 <div class="col-auto px-1 my-2">
29 <div class="btn-group-sm btn-group float-left my-auto" role="group"> 29 <div class="btn-group-sm btn-group float-left my-auto" role="group">
30 <button 30 <button
31 type="button" 31 type="button"
32 class="btn btn-light btn-sm my-auto border shadow" 32 class="btn btn-light btn-sm my-auto border shadow"
33 (click)="aumentarCantidad(producto)"> 33 (click)="aumentarCantidad(producto)">
34 <i class="fa fa-plus" aria-hidden="true"></i> 34 <i class="fa fa-plus" aria-hidden="true"></i>
35 </button> 35 </button>
36 <div class="bg-white border border-white px-2 my-auto text-dark h5 shadow"> 36 <div class="bg-white border border-white px-2 my-auto text-dark h5 shadow">
37 <small>{{producto.cantidad}}</small> 37 <small>{{producto.cantidad}}</small>
38 </div> 38 </div>
39 <button 39 <button
40 type="button" 40 type="button"
41 class="btn btn-light btn-sm my-auto border shadow" 41 class="btn btn-light btn-sm my-auto border shadow"
42 (click)="restarCantidad(producto)"> 42 (click)="restarCantidad(producto)">
43 <i class="fa fa-minus" aria-hidden="true"></i> 43 <i class="fa fa-minus" aria-hidden="true"></i>
44 </button> 44 </button>
45 </div> 45 </div>
46 </div> 46 </div>
47 47
48 <!-- PERSONALIZAR --> 48 <!-- PERSONALIZAR -->
49 <div class="col-auto px-1 my-2"> 49 <div class="col-auto px-1 my-2">
50 <button 50 <button
51 *ngIf="producto.tieneSinonimos" 51 *ngIf="producto.tieneSinonimos"
52 type="button" 52 type="button"
53 class="btn btn-light btn-sm my-auto float-left border shadow" 53 class="btn btn-light btn-sm my-auto float-left border shadow"
54 (click)="personalizarPromo(producto, i)"> 54 (click)="personalizarPromo(producto, i)">
55 <i class="fa fa-refresh text-purple" aria-hidden="true"></i> 55 <i class="fa fa-refresh text-purple" aria-hidden="true"></i>
56 </button> 56 </button>
57 </div> 57 </div>
58 58
59 <!-- BORRAR --> 59 <!-- BORRAR -->
60 <div class="col-auto px-1 my-2"> 60 <div class="col-auto px-1 my-2">
61 <button 61 <button
62 type="button" 62 type="button"
63 class="btn btn-secondary btn-sm my-auto shadow" 63 class="btn btn-secondary btn-sm my-auto shadow"
64 (click)="deleteProducto(producto, i)"> 64 (click)="deleteProducto(producto, i)">
65 <i class="fa fa-trash" aria-hidden="true"></i> 65 <i class="fa fa-trash" aria-hidden="true"></i>
66 </button> 66 </button>
67 </div> 67 </div>
68 </div> 68 </div>
69 </div> 69 </div>
70 </div> 70 </div>
71 71
72 <!-- TOTAL --> 72 <!-- TOTAL -->
73 <div class="card rounded-top-sm mt-auto blue-gradient border-0"> 73 <div class="card rounded-top-sm mt-auto blue-gradient border-0">
74 <div class="card-body row"> 74 <div class="card-body row">
75 <div class="col-12"> 75 <div class="col-12">
76 <p 76 <p
77 class="h4 border-bottom border-secondary text-secondary pb-2"> 77 class="h4 border-bottom border-secondary text-secondary pb-2">
78 ({{getCantidadProductos()}}) artículos 78 ({{getCantidadProductos()}}) artículos
79 </p> 79 </p>
80 <p class="h3 text-secondary">Total</p> 80 <p class="h3 text-secondary">Total</p>
81 <p class="h3 font-weight-bold">{{getTotal() | currency}}</p> 81 <p class="h3 font-weight-bold">{{getTotal() | currency}}</p>
82 </div> 82 </div>
83 <div class="col-12"> 83 <div class="col-12">
84 <button 84 <button
85 *ngIf="getCantidadProductos() > 0" 85 *ngIf="getCantidadProductos() > 0"
86 type="button" 86 type="button"
87 class="btn btn-block btn-light btn-lg shadow mb-2 p-1" 87 class="btn btn-block btn-light btn-lg shadow mb-2 p-1"
88 routerLink="/confirmacion-carrito"> 88 routerLink="/confirmacion-carrito">
89 <span class="font-weight-bold pr-1">Finalizar y Pagar</span> 89 <span class="font-weight-bold pr-1">Finalizar y Pagar</span>
90 <i class="fa fa-check text-success" aria-hidden="true"></i> 90 <i class="fa fa-check text-success" aria-hidden="true"></i>
91 </button> 91 </button>
92 <button 92 <button
93 type="button" 93 type="button"
94 class="btn btn-block btn-light shadow btn-sm shadow" 94 class="btn btn-block btn-light shadow btn-sm shadow"
95 [routerLink]="['/cancelar-compra']"> 95 [routerLink]="['/cancelar-compra']">
96 <span class="pr-1">Cancelar</span> 96 <span class="pr-1">Cancelar</span>
97 <i class="fa fa-times text-danger" aria-hidden="true"></i> 97 <i class="fa fa-times text-danger" aria-hidden="true"></i>
98 </button> 98 </button>
99 </div> 99 </div>
100 </div> 100 </div>
101 </div> 101 </div>
102 </div> 102 </div>
103 103
src/app/components/sidebar/sidebar.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { Producto } from 'src/app/wrappers/producto'; 2 import { Producto } from 'src/app/wrappers/producto';
3 import { appSettings } from 'src/etc/AppSettings'; 3 import { appSettings } from 'src/etc/AppSettings';
4 import { ProductoService } from 'src/app/services/producto.service'; 4 import { ProductoService } from 'src/app/services/producto.service';
5 import { Router } from '@angular/router'; 5 import { Router } from '@angular/router';
6 6
7 @Component({ 7 @Component({
8 selector: 'app-sidebar', 8 selector: 'app-sidebar',
9 templateUrl: './sidebar.component.html', 9 templateUrl: './sidebar.component.html',
10 styleUrls: ['./sidebar.component.scss'], 10 styleUrls: ['./sidebar.component.scss'],
11 }) 11 })
12 export class SidebarComponent implements OnInit { 12 export class SidebarComponent implements OnInit {
13 13
14 private cantTotal: number = 0; 14 private cantTotal: number = 0;
15 private cantMin: number = 1; 15 private cantMin: number = 1;
16 private cantMax: number = 50; 16 private cantMax: number = 50;
17 private total: number = 0; 17 private total: number = 0;
18 private apiImagenes: string = appSettings.apiImagenes; 18 private apiImagenes: string = appSettings.apiImagenes;
19 19
20 public productosCarrito: Producto[] = []; 20 public productosCarrito: Producto[] = [];
21 21
22 constructor( 22 constructor(
23 private productoService: ProductoService, 23 private productoService: ProductoService,
24 private router: Router) { 24 private router: Router) {
25 this.router.routeReuseStrategy.shouldReuseRoute = function () { 25 this.router.routeReuseStrategy.shouldReuseRoute = function () {
26 return false; 26 return false;
27 } 27 }
28 } 28 }
29 29
30 ngOnInit() { 30 ngOnInit() {
31 31
32 this.productosCarrito = this.productoService.productos; 32 this.productosCarrito = this.productoService.productos;
33 } 33 }
34 34
35 getCantidadProductos() { 35 getCantidadProductos() {
36 36
37 var cantTotalAux = 0; 37 var cantTotalAux = 0;
38 this.productosCarrito.forEach(producto => { 38 this.productosCarrito.forEach(producto => {
39 39
40 cantTotalAux += producto.cantidad; 40 cantTotalAux += producto.cantidad;
41 }); 41 });
42 this.cantTotal = cantTotalAux; 42 this.cantTotal = cantTotalAux;
43 43
44 return this.cantTotal; 44 return this.cantTotal;
45 } 45 }
46 46
47 getTotal() { 47 getTotal() {
48 48
49 var subTotal = 0; 49 var subTotal = 0;
50 for (let i = 0; i < this.productosCarrito.length; i++) { 50 for (let i = 0; i < this.productosCarrito.length; i++) {
51 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); 51 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad);
52 } 52 }
53 return this.total = subTotal; 53 return this.total = subTotal;
54 } 54 }
55 55
56 aumentarCantidad(producto: Producto) { 56 aumentarCantidad(producto: Producto) {
57 57
58 if (producto.cantidad < this.cantMax) { 58 if (producto.cantidad < this.cantMax) {
59 producto.cantidad++; 59 producto.cantidad++;
60 this.cantTotal++ 60 this.cantTotal++
61 } 61 }
62 } 62 }
63 63
64 restarCantidad(producto: Producto) { 64 restarCantidad(producto: Producto) {
65 65
66 if (producto.cantidad > this.cantMin) { 66 if (producto.cantidad > this.cantMin) {
67 producto.cantidad--; 67 producto.cantidad--;
68 this.cantTotal--; 68 this.cantTotal--;
69 } 69 }
70 } 70 }
71 71
72 deleteProducto(producto: Producto, index: number) { 72 deleteProducto(producto: Producto, index: number) {
73 73
74 this.cantTotal -= producto.cantidad; 74 this.cantTotal -= producto.cantidad;
75 this.total -= producto.PreVen * producto.cantidad; 75 this.total -= producto.PreVen * producto.cantidad;
76 this.productosCarrito.reverse().splice(index, 1); 76 this.productosCarrito.reverse().splice(index, 1);
77 return; 77 return;
78 } 78 }
79 79
80 personalizarPromo(producto: Producto, index) { 80 personalizarPromo(producto: Producto, index) {
81 81
82 this.productoService.productoAcargar = producto; 82 this.productoService.productoAcargar = producto;
83 this.productoService.esPromoPersonalizada = true;
83 this.deleteProducto(producto, index); 84 this.deleteProducto(producto, index);
84 this.router.navigate(['inicio']); 85 this.router.navigate(['inicio']);
85 } 86 }
86 87
87 } 88 }
88 89
src/app/services/producto.service.ts
1 import { Injectable } from '@angular/core'; 1 import { Injectable } from '@angular/core';
2 import { HttpClient } from '@angular/common/http'; 2 import { HttpClient } from '@angular/common/http';
3 import { Observable } from 'rxjs'; 3 import { Observable } from 'rxjs';
4 import { appSettings } from 'src/etc/AppSettings'; 4 import { appSettings } from 'src/etc/AppSettings';
5 import { Producto } from '../wrappers/producto'; 5 import { Producto } from '../wrappers/producto';
6 6
7 @Injectable({ 7 @Injectable({
8 providedIn: 'root' 8 providedIn: 'root'
9 }) 9 })
10 export class ProductoService { 10 export class ProductoService {
11 11
12 productos: Producto[] = []; 12 productos: Producto[] = [];
13 productoAcargar: Producto; 13 productoAcargar: Producto;
14 promoAcargar: Producto; 14 promoAcargar: Producto;
15 mostrar: string; 15 mostrar: string;
16 esPromoPersonalizada: boolean = false;
16 17
17 constructor(private http: HttpClient) { } 18 constructor(private http: HttpClient) { }
18 19
19 getProductoById(id): Observable<any> { 20 getProductoById(id): Observable<any> {
20 21
21 return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); 22 return this.http.get(`${appSettings.apiUrl}/articulos/${id}`);
22 } 23 }
23 24
24 getAll(): Observable<any> { 25 getAll(): Observable<any> {
25 26
26 return this.http.get(`${appSettings.apiUrl}/articulos/`); 27 return this.http.get(`${appSettings.apiUrl}/articulos/`);
27 } 28 }
28 29
29 getAllWithPaginator(page: number = 1): Observable<any> { 30 getAllWithPaginator(page: number = 1): Observable<any> {
30 31
31 return this.http.get(`${appSettings.apiUrl}/articulos/${page}`); 32 return this.http.get(`${appSettings.apiUrl}/articulos/${page}`);
32 } 33 }
33 34
34 setProductos(producto: Producto) { 35 setProductos(producto: Producto) {
35 36
36 for (let i = 0; i < this.productos.length; i++) { 37 for (let i = 0; i < this.productos.length; i++) {
37 38
38 if (this.productos[i].id === producto.id) { 39 if (this.productos[i].id === producto.id) {
39 40
40 if (producto.PRO) { 41 if (producto.PRO) {
41 if (this.promosIdenticas(this.productos[i], producto)) { 42 if (this.promosIdenticas(this.productos[i], producto)) {
42 this.productos[i].cantidad++; 43 this.productos[i].cantidad++;
43 return; 44 return;
44 } else { 45 } else {
45 break; 46 break;
46 } 47 }
47 } 48 }
48 this.productos[i].cantidad++; 49 this.productos[i].cantidad++;
49 return; 50 return;
50 } 51 }
51 } 52 }
52 53
53 this.productos.push(producto); 54 this.productos.push(producto);
54 } 55 }
55 56
56 getPromocionByCodigos(sector, codigo): Observable<any> { 57 getPromocionByCodigos(sector, codigo): Observable<any> {
57 58
58 var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; 59 var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`;
59 // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; 60 // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`;
60 return this.http.get(url); 61 return this.http.get(url);
61 } 62 }
62 63
63 getPromociones(sector, codigo): Observable<any> { 64 getPromociones(sector, codigo): Observable<any> {
64 65
65 var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; 66 var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`;
66 // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; 67 // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`;
67 return this.http.get(url); 68 return this.http.get(url);
68 } 69 }
69 70
70 getPromocionSinonimos(sector, codigo): Observable<any> { 71 getPromocionSinonimos(sector, codigo): Observable<any> {
71 72
72 var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; 73 var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`;
73 // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; 74 // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`;
74 return this.http.get(url); 75 return this.http.get(url);
75 } 76 }
76 77
77 getCategorias() { 78 getCategorias() {
78 return this.http.get(`${appSettings.apiUrl}/categorias`); 79 return this.http.get(`${appSettings.apiUrl}/categorias`);
79 } 80 }
80 81
81 pagar(medioPago: string) { 82 pagar(medioPago: string) {
82 return this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${medioPago}`, { 83 return this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${medioPago}`, {
83 productos: this.productos 84 productos: this.productos
84 }); 85 });
85 } 86 }
86 87
87 private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { 88 private promosIdenticas(promoEnCarrito: Producto, promo: Producto) {
88 89
89 var sonIdenticas = true; 90 var sonIdenticas = true;
90 var productosPromoCarrito = promoEnCarrito.productos; 91 var productosPromoCarrito = promoEnCarrito.productos;
91 var productosPromoAcargar = promo.productos; 92 var productosPromoAcargar = promo.productos;
92 93
93 if (productosPromoCarrito.length !== productosPromoAcargar.length) { 94 if (productosPromoCarrito.length !== productosPromoAcargar.length) {
94 return false; 95 return false;
95 } 96 }
96 97
97 for (let i = 0; i < productosPromoCarrito.length; i++) { 98 for (let i = 0; i < productosPromoCarrito.length; i++) {
98 99
99 if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { 100 if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) {
100 return false; 101 return false;
101 } 102 }
102 } 103 }
103 104
104 return sonIdenticas; 105 return sonIdenticas;
105 } 106 }
106 107
107 } 108 }
108 109