Commit 5dcd31ce9a0cc3a1377341fe3b0dd7bcce624f7d

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

Agregada logica para manejar la cantidad de los sinonimos.

src/app/components/inicio/inicio.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core'; 1 import { Component, OnInit, ViewChild } 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 { Producto } from 'src/app/wrappers/producto'; 4 import { Producto } from 'src/app/wrappers/producto';
5 import { ProductoService } from 'src/app/services/producto.service'; 5 import { ProductoService } from 'src/app/services/producto.service';
6 import { Router } from '@angular/router'; 6 import { Router } from '@angular/router';
7 import { Promocion } from 'src/app/wrappers/promocion'; 7 import { Promocion } from 'src/app/wrappers/promocion';
8 import { Sinonimo } from 'src/app/wrappers/sinonimo'; 8 import { Sinonimo } from 'src/app/wrappers/sinonimo';
9 import { HostListener } from '@angular/core'; 9 import { HostListener } from '@angular/core';
10 10
11 @Component({ 11 @Component({
12 selector: 'app-inicio', 12 selector: 'app-inicio',
13 templateUrl: './inicio.component.html', 13 templateUrl: './inicio.component.html',
14 styleUrls: ['./inicio.component.scss'] 14 styleUrls: ['./inicio.component.scss']
15 }) 15 })
16 export class InicioComponent implements OnInit { 16 export class InicioComponent implements OnInit {
17 17
18 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { 18 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) {
19 19
20 if (e.keyCode == 13) { 20 if (e.keyCode == 13) {
21 this.buscarByCodigoBarras(this.busqueda); 21 this.buscarByCodigoBarras(this.busqueda);
22 this.busqueda = ''; 22 this.busqueda = '';
23 } else { 23 } else {
24 this.busqueda += e.key; 24 this.busqueda += e.key;
25 } 25 }
26 26
27 }; 27 };
28 28
29 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; 29 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective;
30 private productoAcargar: Producto; 30 private productoAcargar: Producto;
31 private productos: Producto[]; 31 private productos: Producto[];
32 private promoAcargar: Promocion; 32 private promoAcargar: Promocion;
33 private tienePromo = false; 33 private tienePromo = false;
34 private productoEsPromo = false; 34 private productoEsPromo = false;
35 private busqueda: string = ''; 35 private busqueda: string = '';
36 private sinonimoAcargar: Sinonimo; 36 private sinonimoAcargar: Sinonimo;
37 37
38 promociones: Promocion[] = []; 38 promociones: Promocion[] = [];
39 sinonimos: Sinonimo[] = []; 39 sinonimos: Sinonimo[] = [];
40 apiUrl: string = appSettings.apiUrl 40 apiUrl: string = appSettings.apiUrl
41 41
42 constructor( 42 constructor(
43 private router: Router, 43 private router: Router,
44 private productoService: ProductoService) { } 44 private productoService: ProductoService) { }
45 45
46 ngOnInit() { 46 ngOnInit() {
47 47
48 this.productoAcargar = this.productoService.productoAcargar; 48 this.productoAcargar = this.productoService.productoAcargar;
49 this.getPromociones(); 49 this.getPromociones();
50 this.getProductos(); 50 this.getProductos();
51 } 51 }
52 52
53 getPromociones() { 53 getPromociones() {
54 if (this.productoAcargar) { 54 if (this.productoAcargar) {
55 var sector = this.productoAcargar.CodSec; 55 var sector = this.productoAcargar.CodSec;
56 var codigo = this.productoAcargar.CodArt; 56 var codigo = this.productoAcargar.CodArt;
57 this.productoService.getPromocion(sector, codigo) 57 this.productoService.getPromocion(sector, codigo)
58 .subscribe((res: Promocion[]) => { 58 .subscribe((res: Promocion[]) => {
59 59
60 if (res.length === 0) { 60 if (res.length === 0) {
61 //Si no tiene promociones la cargará al carrito despues de un tiempo 61 //Si no tiene promociones la cargará al carrito despues de un tiempo
62 setTimeout(() => { 62 setTimeout(() => {
63 this.productoService.productos.push(this.productoAcargar); 63 this.productoService.productos.push(this.productoAcargar);
64 this.productoAcargar = undefined; 64 this.productoAcargar = undefined;
65 }, 2000) 65 }, 2000)
66 } else { 66 } else {
67 67
68 this.promociones = res; 68 this.promociones = res;
69 this.popoverDirective.show(); 69 this.popoverDirective.show();
70 } 70 }
71 }, error => { console.error(error); }) 71 }, error => { console.error(error); })
72 } 72 }
73 } 73 }
74 74
75 showPopover() { 75 showPopover() {
76 76
77 this.popoverDirective.show(); 77 this.popoverDirective.show();
78 } 78 }
79 79
80 getProductos() { 80 getProductos() {
81 this.productoService.getAll() 81 this.productoService.getAll()
82 .subscribe((productos: Producto[]) => { 82 .subscribe((productos: Producto[]) => {
83 this.productos = productos; 83 this.productos = productos;
84 }); 84 });
85 } 85 }
86 86
87 private irBusquedaProductos(verPromociones) { 87 private irBusquedaProductos(verPromociones) {
88 88
89 this.productoService.verCategoriasProductos = verPromociones; 89 this.productoService.verCategoriasProductos = verPromociones;
90 this.router.navigate(['busqueda-productos']); 90 this.router.navigate(['busqueda-productos']);
91 } 91 }
92 92
93 deshacerCarga() { 93 deshacerCarga() {
94 94
95 if (this.sinonimoAcargar || this.sinonimos.length > 0) { 95 if (this.sinonimoAcargar || this.sinonimos.length > 0) {
96 this.sinonimos = []; 96 this.sinonimos = [];
97 this.sinonimoAcargar = undefined; 97 this.sinonimoAcargar = undefined;
98 this.popoverDirective.hide(); 98 this.popoverDirective.hide();
99 } 99 }
100 100
101 if (this.promoAcargar) { 101 if (this.promoAcargar) {
102 this.promoAcargar = undefined; 102 this.promoAcargar = undefined;
103 this.popoverDirective.show(); 103 this.popoverDirective.show();
104 } else { 104 } else {
105 this.productoAcargar = undefined; 105 this.productoAcargar = undefined;
106 this.promociones = []; 106 this.promociones = [];
107 this.popoverDirective.hide(); 107 this.popoverDirective.hide();
108 } 108 }
109 } 109 }
110 110
111 promoSeleccionada($event: Promocion) { 111 promoSeleccionada($event: Promocion) {
112 112
113 this.promoAcargar = $event; 113 this.promoAcargar = $event;
114 this.popoverDirective.hide(); 114 this.popoverDirective.hide();
115 if (this.promoAcargar.sinonimos) { 115 if (this.promoAcargar.sinonimos) {
116 var sector = this.promoAcargar.sector; 116 var sector = this.promoAcargar.sector;
117 var codigo = this.promoAcargar.codigo; 117 var codigo = this.promoAcargar.codigo;
118 this.productoService.getPromocionSinonimos(sector, codigo) 118 this.productoService.getPromocionSinonimos(sector, codigo)
119 .subscribe((res: Sinonimo[]) => { 119 .subscribe((res: Sinonimo[]) => {
120
120 res.forEach(resSinonimo => { 121 res.forEach(resSinonimo => {
121 resSinonimo.productos.forEach(productoSinonimo => { 122
122 this.promoAcargar.productos.forEach(productoPromo => { 123 this.promoAcargar.productos.forEach(productoPromo => {
123 if (productoPromo.id === productoSinonimo.id) { 124
124 productoSinonimo.esPadre = true; 125 if (productoPromo.idSinonimo === resSinonimo.ID_SIN) {
125 } 126 resSinonimo.cantidad = productoPromo.cantidad;
126 }); 127 resSinonimo.productoPadre = productoPromo.id;
127 128 }
128 }) 129 });
130
129 }) 131 })
130 this.sinonimos = res; 132 this.sinonimos = res;
131 this.showPopover(); 133 this.showPopover();
132 }) 134 })
133 } 135 }
134 } 136 }
135 137
136 sinonimoSeleccionado($event: Sinonimo) { 138 sinonimoSeleccionado($event: Sinonimo) {
137 139
138 console.log($event); 140 console.log($event);
139 this.sinonimoAcargar = $event; 141 this.sinonimoAcargar = $event;
140 } 142 }
141 143
142 buscarByCodigoBarras(busqueda) { 144 buscarByCodigoBarras(busqueda) {
143 145
144 let producto = this.productos.filter(producto => { 146 let producto = this.productos.filter(producto => {
145 return producto.codigoBarra == busqueda; 147 return producto.codigoBarra == busqueda;
146 }); 148 });
147 149
148 if (producto.length) { 150 if (producto.length) {
149 151
150 this.productoAcargar = producto[0]; 152 this.productoAcargar = producto[0];
151 this.getPromociones(); 153 this.getPromociones();
152 154
153 } else { 155 } else {
154 alert('No se encuentra el producto'); 156 alert('No se encuentra el producto');
155 } 157 }
156 158
157 } 159 }
158 160
159 } 161 }
160 162
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 overflow-scroll popover-size pr-2 my-2"> 11 <div class="row m-0 overflow-scroll popover-size pr-2 my-2">
12 <div class="col"> 12 <div class="col">
13 <div class="row mb-2" *ngFor="let sinonimo of popoverContent"> 13 <div class="row mb-2" *ngFor="let sinonimo of popoverContent; let i = index">
14 <div class="col"> 14 <div class="col">
15 15
16 <div class="row m-0"> 16 <div class="row m-0">
17 <div class="col text-left"> 17 <div class="col text-left">
18 <p class="h5 card-title"> 18 <p class="h5 card-title">
19 Elija una opción 19 Elija una opción - Cantidad Restante {{cantidadRestanteSinonimos[i]}}
20 </p> 20 </p>
21 </div> 21 </div>
22 </div> 22 </div>
23 23
24 <div class="row my-3 d-flex justify-content-between" *ngFor="let producto of sinonimo.productos"> 24 <div class="row my-3 d-flex justify-content-between" *ngFor="let producto of sinonimo.productos">
25 <div class="col-8 pl-4 h6 m-0"> 25 <div class="col-7 pl-4 h6 text-right">
26 <div class="custom-control custom-radio"> 26 <p class="m-0 font-weight-normal">
27 <input 27 {{producto.DetArt}}
28 type="radio" 28 </p>
29 [id]="producto.id"
30 [checked]="producto.esPadre"
31 name="sinonimoOpciones"
32 class="custom-control-input"
33 (click)="setSinonimo(sinonimo)">
34 <label class="font-weight-normal custom-control-label" [for]="producto.id">
35 {{producto.DetArt}}
36 </label>
37 </div>
38 </div> 29 </div>
39 <div class="col-auto"> 30 <div class="col-auto">
40 <div class="btn-group-sm btn-group float-left my-auto" role="group"> 31 <div class="btn-group float-left my-auto" role="group">
41 <button type="button" class="btn btn-light btn-sm my-auto border"> 32 <button
33 type="button"
34 class="btn btn-light my-auto border"
35 (click)="sumarCantidad(producto, i)">
42 <i class="fa fa-plus" aria-hidden="true"></i> 36 <i class="fa fa-plus" aria-hidden="true"></i>
43 </button> 37 </button>
44 <div class="bg-white border border-white px-3 my-auto text-dark h5"> 38 <div class="bg-white border border-white px-3 py-1 my-auto text-dark h5">
45 <small>{{producto.cantidad}}</small> 39 <small
40 [ngClass]="{'font-weight-bold': producto.cantidad > 0}">
41 {{producto.cantidad}}
42 </small>
46 </div> 43 </div>
47 <button type="button" class="btn btn-light btn-sm my-auto border"> 44 <button
45 type="button"
46 class="btn btn-light my-auto border"
47 (click)="restarCantidad(producto, i)">
48 <i class="fa fa-minus" aria-hidden="true"></i> 48 <i class="fa fa-minus" aria-hidden="true"></i>
49 </button> 49 </button>
50 </div> 50 </div>
51 </div> 51 </div>
52 </div> 52 </div>
53 53
54 </div> 54 </div>
55 </div> 55 </div>
56 </div> 56 </div>
57 </div> 57 </div>
58 58
59 <div class="row mt-3 justify-content-end"> 59 <div class="row mt-3 justify-content-end">
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 5
6 @Component({ 6 @Component({
7 selector: 'app-popover-sinonimos', 7 selector: 'app-popover-sinonimos',
8 templateUrl: './popover-sinonimos.component.html', 8 templateUrl: './popover-sinonimos.component.html',
9 styleUrls: ['./popover-sinonimos.component.scss'] 9 styleUrls: ['./popover-sinonimos.component.scss']
10 }) 10 })
11 export class PopoverSinonimosComponent implements OnInit { 11 export class PopoverSinonimosComponent implements OnInit {
12 12
13 //Directiva del popover, para poder cerrarlo desde este componente 13 //Directiva del popover, para poder cerrarlo desde este componente
14 @Input() popover: PopoverDirective; 14 @Input() popover: PopoverDirective;
15 @Input() popoverContent: Sinonimo[]; 15 @Input() popoverContent: Sinonimo[];
16 @Output() sinonimoSeleccionado = new EventEmitter<Sinonimo>(); 16 @Output() sinonimoSeleccionado = new EventEmitter<Sinonimo>();
17 sinonimo: Sinonimo; 17 sinonimo: Sinonimo;
18 18
19 private cantidadRestanteSinonimos: number[] = [];
20
19 constructor() { } 21 constructor() { }
20 22
21 ngOnInit() { 23 ngOnInit() {
22 24
23 //Seteo en la variable a emitir el sinonimo que sea padre 25 //Seteo en la variable a emitir el sinonimo que sea padre
24 this.popoverContent.forEach(sinonimo => { 26 this.popoverContent.forEach(sinonimo => {
25 // this.sinonimo = sinonimo.esPadre ? sinonimo : undefined; 27
28 this.cantidadRestanteSinonimos.push(0);
29 this.sinonimo = sinonimo.productoPadre ? sinonimo : undefined;
30 sinonimo.productos.forEach(producto => {
31
32 producto.cantidad = (producto.id === sinonimo.productoPadre) ? sinonimo.cantidad : 0;
33 })
26 }) 34 })
27 } 35 }
28 36
29 hidePopover() { 37 hidePopover() {
30 38
31 this.sinonimoSeleccionado.emit(this.sinonimo); 39 this.sinonimoSeleccionado.emit(this.sinonimo);
32 this.popover.hide(); 40 this.popover.hide();
33 } 41 }
34 42
35 setSinonimo(sinonimo: Sinonimo) { 43 setSinonimo(sinonimo: Sinonimo) {
36 44
37 this.sinonimo = sinonimo; 45 this.sinonimo = sinonimo;
38 } 46 }
39 47
48 sumarCantidad(producto: Producto, i: number) {
49
50 if (this.cantidadRestanteSinonimos[i] === 0) return;
51 producto.cantidad++;
52 this.cantidadRestanteSinonimos[i]--;
53 }
54
55 restarCantidad(producto: Producto, i: number) {
56
57 if (this.cantidadRestanteSinonimos[i] === this.popoverContent[i].cantidad) return;
58 if (producto.cantidad === 0) return;
59 producto.cantidad--;
60 this.cantidadRestanteSinonimos[i]++;
61 }
62
40 } 63 }
41 64
src/app/wrappers/producto.ts
1 export interface Producto { 1 export interface Producto {
2 CodSec: number; 2 CodSec: number;
3 CodArt: number; 3 CodArt: number;
4 DetArt: string; 4 DetArt: string;
5 CodRub: number; 5 CodRub: number;
6 Costo: number; 6 Costo: number;
7 PreNet: number; 7 PreNet: number;
8 ImpInt: number; 8 ImpInt: number;
9 UniVen: number; 9 UniVen: number;
10 FecCos: Date; 10 FecCos: Date;
11 UltAct: Date; 11 UltAct: Date;
12 CodPro: number; 12 CodPro: number;
13 ExiDep: number; 13 ExiDep: number;
14 ExiVta: number; 14 ExiVta: number;
15 MinDep: number; 15 MinDep: number;
16 MaxDep: number; 16 MaxDep: number;
17 MinPVE: number; 17 MinPVE: number;
18 MaxPVE: number; 18 MaxPVE: number;
19 ENTTur: number; 19 ENTTur: number;
20 SINTur: number; 20 SINTur: number;
21 SALTur: number; 21 SALTur: number;
22 IvaSN: boolean; 22 IvaSN: boolean;
23 DepSN: boolean; 23 DepSN: boolean;
24 RubMay: number; 24 RubMay: number;
25 PreVen: number; 25 PreVen: number;
26 IvaCO: number; 26 IvaCO: number;
27 TIP: string; 27 TIP: string;
28 IMPIVA: number; 28 IMPIVA: number;
29 ENTADM: number; 29 ENTADM: number;
30 SALADM: number; 30 SALADM: number;
31 CODIIN: number; 31 CODIIN: number;
32 PRO: boolean; 32 PRO: boolean;
33 FPP: boolean; 33 FPP: boolean;
34 ESS: boolean; 34 ESS: boolean;
35 FID: Date; 35 FID: Date;
36 NID: number; 36 NID: number;
37 FIV: Date; 37 FIV: Date;
38 NIV: number; 38 NIV: number;
39 COO: string; 39 COO: string;
40 CAG: string; 40 CAG: string;
41 CAP: number; 41 CAP: number;
42 UTL: number; 42 UTL: number;
43 NHA: boolean; 43 NHA: boolean;
44 PID: boolean; 44 PID: boolean;
45 PRV: number; 45 PRV: number;
46 PRD: number; 46 PRD: number;
47 ImpInt2: number; 47 ImpInt2: number;
48 E_HD: string; 48 E_HD: string;
49 C_HD: string; 49 C_HD: string;
50 CLA: number; 50 CLA: number;
51 UNICAP: number; 51 UNICAP: number;
52 ELBPRO: string; 52 ELBPRO: string;
53 PPP: number; 53 PPP: number;
54 ALI: number; 54 ALI: number;
55 BAL_TIPO: string; 55 BAL_TIPO: string;
56 PER_MAY: boolean; 56 PER_MAY: boolean;
57 ES_MAY: boolean; 57 ES_MAY: boolean;
58 CLA_MAY: number; 58 CLA_MAY: number;
59 PME_CMP: string; 59 PME_CMP: string;
60 USA_BAL: boolean; 60 USA_BAL: boolean;
61 DET_LAR: string; 61 DET_LAR: string;
62 ROTULO: string; 62 ROTULO: string;
63 REC_MANUAL: boolean; 63 REC_MANUAL: boolean;
64 E_HD1: string; 64 E_HD1: string;
65 C_HD1: string; 65 C_HD1: string;
66 ImpInt3: number; 66 ImpInt3: number;
67 FUA_MAE_YPF: Date; 67 FUA_MAE_YPF: Date;
68 CPQ: number; 68 CPQ: number;
69 EPQ: string; 69 EPQ: string;
70 BPQ: number; 70 BPQ: number;
71 PUPQ: number; 71 PUPQ: number;
72 CORVTO: boolean; 72 CORVTO: boolean;
73 CORVTO_COSTO: number; 73 CORVTO_COSTO: number;
74 UTLFR: number; 74 UTLFR: number;
75 FAMILIA: number; 75 FAMILIA: number;
76 ES_LUB: boolean; 76 ES_LUB: boolean;
77 ES_FERT: boolean; 77 ES_FERT: boolean;
78 AutoFac: boolean; 78 AutoFac: boolean;
79 LitrosPCD: number; 79 LitrosPCD: number;
80 LisPCD: number; 80 LisPCD: number;
81 ImpLey23966: boolean; 81 ImpLey23966: boolean;
82 es_bio: boolean; 82 es_bio: boolean;
83 ExpArbaRev: boolean; 83 ExpArbaRev: boolean;
84 ES_AGROQ: boolean; 84 ES_AGROQ: boolean;
85 ES_PLAST: boolean; 85 ES_PLAST: boolean;
86 es_bio_por: string; 86 es_bio_por: string;
87 IMP_IMP_INT: boolean; 87 IMP_IMP_INT: boolean;
88 id: number; 88 id: number;
89 nombreImagen?: any; 89 nombreImagen?: any;
90 categoria_selfservice: number; 90 categoria_selfservice: number;
91 cantidad?: number; 91 cantidad?: number;
92 showCargarProducto?: boolean; 92 showCargarProducto?: boolean;
93 esPadre?: boolean; 93 esPadre?: boolean;
94 codigoBarra: string; 94 codigoBarra: string;
95 idSinonimo?: number;
95 } 96 }
96 97
src/app/wrappers/sinonimo.ts
1 import { Producto } from './producto'; 1 import { Producto } from './producto';
2 2
3 export interface Sinonimo { 3 export interface Sinonimo {
4 4
5 ID_SIN: number, 5 ID_SIN: number,
6 descripcion: string, 6 descripcion: string,
7 productos: Producto[], 7 productos: Producto[],
8 productoPadre?: number;
9 cantidad? : number;
8 } 10 }
9 11