Commit 96fcfbe1541c2fae83895ee7a1d531099d404292

Authored by Marcelo Puebla
Exists in master

Merge branch 'validar_pve' into 'develop'

Validar pve

See merge request !128
src/app/components/configuracion/configuracion.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { BsModalRef } from 'ngx-bootstrap'; 2 import { BsModalRef } from 'ngx-bootstrap';
3 import { PuntoVentaService } from 'src/app/services/punto-venta.service'; 3 import { PuntoVentaService } from 'src/app/services/punto-venta.service';
4 import { PuntoVenta } from 'src/app/wrappers/puntoVenta'; 4 import { PuntoVenta } from 'src/app/wrappers/puntoVenta';
5 import { ImpresoraService } from 'src/app/services/impresora.service'; 5 import { ImpresoraService } from 'src/app/services/impresora.service';
6 import { Impresora } from 'src/app/wrappers/impresora'; 6 import { Impresora } from 'src/app/wrappers/impresora';
7 import { FormGroup, FormControl } from '@angular/forms'; 7 import { FormGroup, FormControl } from '@angular/forms';
8 import { Router } from '@angular/router';
8 9
9 @Component({ 10 @Component({
10 selector: 'app-configuracion', 11 selector: 'app-configuracion',
11 templateUrl: './configuracion.component.html', 12 templateUrl: './configuracion.component.html',
12 styleUrls: ['./configuracion.component.scss'] 13 styleUrls: ['./configuracion.component.scss']
13 }) 14 })
14 export class ConfiguracionComponent implements OnInit { 15 export class ConfiguracionComponent implements OnInit {
15 16
16 puntosVenta: PuntoVenta[] = []; 17 puntosVenta: PuntoVenta[] = [];
17 impresoras: Impresora[] = []; 18 impresoras: Impresora[] = [];
18 form: FormGroup; 19 form: FormGroup;
20 reiniciar: boolean = false;
19 21
20 constructor( 22 constructor(
21 private activeModal: BsModalRef, 23 private activeModal: BsModalRef,
22 private puntoVentaService: PuntoVentaService, 24 private puntoVentaService: PuntoVentaService,
23 private impresoraService: ImpresoraService, 25 private impresoraService: ImpresoraService,
26 private router: Router
24 ) { } 27 ) { }
25 28
26 ngOnInit() { 29 ngOnInit() {
27 30
28 this.form = new FormGroup({ 31 this.form = new FormGroup({
29 usePlanillaPropia: new FormControl(false, []), 32 usePlanillaPropia: new FormControl(false, []),
30 puntoVenta: new FormControl(null, []), 33 puntoVenta: new FormControl(null, []),
31 impresora: new FormControl(null, []), 34 impresora: new FormControl(null, []),
32 }) 35 })
33 36
34 this.puntoVentaService.getAll() 37 this.puntoVentaService.getAll()
35 .subscribe((res: PuntoVenta[]) => { 38 .subscribe((res: PuntoVenta[]) => {
36 39
37 this.puntosVenta = res; 40 this.puntosVenta = res;
38 this.setPuntoVenta(); 41 this.setPuntoVenta();
39 }, console.error); 42 }, console.error);
40 43
41 this.impresoraService.getAll() 44 this.impresoraService.getAll()
42 .subscribe((res: Impresora[]) => { 45 .subscribe((res: Impresora[]) => {
43 46
44 this.impresoras = res; 47 this.impresoras = res;
45 this.setImpresora(); 48 this.setImpresora();
46 }, console.error); 49 }, console.error);
47 50
48 } 51 }
49 52
50 close() { 53 close() {
51 54
52 this.activeModal.hide(); 55 this.activeModal.hide();
56 if (this.reiniciar) {
57 this.router.navigate(['inicio']);
58 }
53 } 59 }
54 60
55 acept() { 61 acept() {
62 this.reiniciar = !localStorage.getItem('impresoraPVE') ? true : false;
56 63
57 let auxPuntoVenta = this.puntosVenta.find(p => p.ID === this.form.get('puntoVenta').value); 64 let auxPuntoVenta = this.puntosVenta.find(p => p.ID === this.form.get('puntoVenta').value);
58 let auxImpresora = this.impresoras.find(p => p.PVE === this.form.get('impresora').value); 65 let auxImpresora = this.impresoras.find(p => p.PVE === this.form.get('impresora').value);
59 localStorage.setItem('pve', auxPuntoVenta ? auxPuntoVenta.ID.toString() : null); 66 localStorage.setItem('pve', auxPuntoVenta ? auxPuntoVenta.ID.toString() : null);
60 localStorage.setItem('impresoraPVE', auxImpresora ? auxImpresora.PVE.toString() : null); 67 localStorage.setItem('impresoraPVE', auxImpresora ? auxImpresora.PVE.toString() : null);
61 this.close(); 68 this.close();
62 } 69 }
63 70
64 setPuntoVenta() { 71 setPuntoVenta() {
65 72
66 let pve = parseInt(localStorage.getItem('pve')); 73 let pve = parseInt(localStorage.getItem('pve'));
67 let auxPuntoVenta = this.puntosVenta.find(x => x.ID === pve); 74 let auxPuntoVenta = this.puntosVenta.find(x => x.ID === pve);
68 this.form.get('puntoVenta').setValue(auxPuntoVenta ? auxPuntoVenta.ID : null); 75 this.form.get('puntoVenta').setValue(auxPuntoVenta ? auxPuntoVenta.ID : null);
69 } 76 }
70 77
71 setImpresora() { 78 setImpresora() {
72 79
73 let impresoraPVE = parseInt(localStorage.getItem('impresoraPVE')); 80 let impresoraPVE = parseInt(localStorage.getItem('impresoraPVE'));
74 let auxImpresora = this.impresoras.find(x => x.PVE === impresoraPVE); 81 let auxImpresora = this.impresoras.find(x => x.PVE === impresoraPVE);
75 this.form.get('impresora').setValue(auxImpresora ? auxImpresora.PVE : null); 82 this.form.get('impresora').setValue(auxImpresora ? auxImpresora.PVE : null);
76 } 83 }
77 84
78 } 85 }
79 86
src/app/components/inicio/inicio.component.html
1 <div class="row m-0 fade-in"> 1 <div class="row m-0 fade-in" [hidden]="!mostrarPantalla">
2 <div class="col-12 p-0"> 2 <div class="col-12 p-0">
3 3
4 <!-- NOMBRE DE SECCION --> 4 <!-- NOMBRE DE SECCION -->
5 <div class="row m-0"> 5 <div class="row m-0">
6 <div class="col-12 p-0"> 6 <div class="col-12 p-0">
7 <p class="h5 m-0 py-1 bg-gray text-muted text-center">Inicio</p> 7 <p class="h5 m-0 py-1 bg-gray text-muted text-center">Inicio</p>
8 </div> 8 </div>
9 </div> 9 </div>
10 10
11 <div class="row m-0 d-flex align-items-start disable-user-select"> 11 <div class="row m-0 d-flex align-items-start disable-user-select">
12 <div class="col-md-5 py-3 pr-0 d-flex align-items-end flex-column"> 12 <div class="col-md-5 py-3 pr-0 d-flex align-items-end flex-column">
13 13
14 <!-- PROMOCIONES --> 14 <!-- PROMOCIONES -->
15 <div 15 <div
16 (click)="irBusquedaProductos('promociones')" 16 (click)="irBusquedaProductos('promociones')"
17 class="card card-effect bg-white border-0 shadow rounded w-100 mb-auto"> 17 class="card card-effect bg-white border-0 shadow rounded w-100 mb-auto">
18 <div class="card-body text-left px-4 py-3"> 18 <div class="card-body text-left px-4 py-3">
19 <div class="row"> 19 <div class="row">
20 <div class="col-auto"> 20 <div class="col-auto">
21 <p class="m-0 h3 card-title">Promociones</p> 21 <p class="m-0 h3 card-title">Promociones</p>
22 </div> 22 </div>
23 <div class="col-auto p-0"> 23 <div class="col-auto p-0">
24 <img src="{{apiImagenes}}/imagenes/primario.promociones.png" class="w-15 m-0"> 24 <img src="{{apiImagenes}}/imagenes/primario.promociones.png" class="w-15 m-0">
25 </div> 25 </div>
26 </div> 26 </div>
27 <p class="h5 card-text text-muted font-weight-light">Conozca las ofertas del momento.</p> 27 <p class="h5 card-text text-muted font-weight-light">Conozca las ofertas del momento.</p>
28 </div> 28 </div>
29 <!-- CAROUSEL --> 29 <!-- CAROUSEL -->
30 <carousel [showIndicators]="false" [interval]="1500"> 30 <carousel [showIndicators]="false" [interval]="1500">
31 <slide class="h-100"> 31 <slide class="h-100">
32 <img 32 <img
33 src="{{apiImagenes}}/imagenes/beldent.jpg" 33 src="{{apiImagenes}}/imagenes/beldent.jpg"
34 class="fade-in d-block w-75 m-auto rounded"> 34 class="fade-in d-block w-75 m-auto rounded">
35 </slide> 35 </slide>
36 <slide class="h-100"> 36 <slide class="h-100">
37 <img 37 <img
38 src="{{apiImagenes}}/imagenes/cafe con leche y medialunas.jpg" 38 src="{{apiImagenes}}/imagenes/cafe con leche y medialunas.jpg"
39 class="fade-in d-block w-75 m-auto rounded"> 39 class="fade-in d-block w-75 m-auto rounded">
40 </slide> 40 </slide>
41 <slide class="h-100"> 41 <slide class="h-100">
42 <img 42 <img
43 src="{{apiImagenes}}/imagenes/Surtido bagley.jpg" 43 src="{{apiImagenes}}/imagenes/Surtido bagley.jpg"
44 class="fade-in d-block w-75 m-auto rounded"> 44 class="fade-in d-block w-75 m-auto rounded">
45 </slide> 45 </slide>
46 <slide class="h-100"> 46 <slide class="h-100">
47 <img 47 <img
48 src="{{apiImagenes}}/imagenes/yogurisimo.jpg" 48 src="{{apiImagenes}}/imagenes/yogurisimo.jpg"
49 class="fade-in d-block w-75 m-auto rounded"> 49 class="fade-in d-block w-75 m-auto rounded">
50 </slide> 50 </slide>
51 </carousel> 51 </carousel>
52 </div> 52 </div>
53 53
54 <!-- ORDENAR --> 54 <!-- ORDENAR -->
55 <div (click)="irBusquedaProductos('ordenar')" 55 <div (click)="irBusquedaProductos('ordenar')"
56 class="card card-effect bg-white border-0 shadow rounded w-100 mt-3"> 56 class="card card-effect bg-white border-0 shadow rounded w-100 mt-3">
57 <div class="card-body text-left px-4 py-3"> 57 <div class="card-body text-left px-4 py-3">
58 <div class="row"> 58 <div class="row">
59 <div class="col-auto"> 59 <div class="col-auto">
60 <p class="m-0 h3 card-title">Ordenar Pedido</p> 60 <p class="m-0 h3 card-title">Ordenar Pedido</p>
61 </div> 61 </div>
62 <div class="col-auto p-0"> 62 <div class="col-auto p-0">
63 <img src="{{apiImagenes}}/imagenes/primario.ordenar.png" class="w-15"> 63 <img src="{{apiImagenes}}/imagenes/primario.ordenar.png" class="w-15">
64 </div> 64 </div>
65 </div> 65 </div>
66 <p class="h5 card-text text-muted font-weight-light">Arme su pedido y solo pase a retirar.</p> 66 <p class="h5 card-text text-muted font-weight-light">Arme su pedido y solo pase a retirar.</p>
67 </div> 67 </div>
68 <img 68 <img
69 class="card-img-bottom d-block w-100 mx-auto rounded" 69 class="card-img-bottom d-block w-100 mx-auto rounded"
70 src="{{apiImagenes}}/imagenes/cafe.jpg"> 70 src="{{apiImagenes}}/imagenes/cafe.jpg">
71 </div> 71 </div>
72 </div> 72 </div>
73 73
74 <div class="col-md-7 py-3 d-flex align-items-end flex-column mt-4 mt-md-0"> 74 <div class="col-md-7 py-3 d-flex align-items-end flex-column mt-4 mt-md-0">
75 75
76 <!-- CARGAR PRODUCTOS --> 76 <!-- CARGAR PRODUCTOS -->
77 <ng-template #popTemplate> 77 <ng-template #popTemplate>
78 <app-popover-promos 78 <app-popover-promos
79 *ngIf="promociones.length > 0 && sinonimos.length === 0" 79 *ngIf="promociones.length > 0 && sinonimos.length === 0"
80 [popover]="popoverDirective" 80 [popover]="popoverDirective"
81 [popoverContent]="promociones" 81 [popoverContent]="promociones"
82 (promoSeleccionada)="promoSeleccionada($event, false)" 82 (promoSeleccionada)="promoSeleccionada($event, false)"
83 class="text-white rounded-sm border-0"> 83 class="text-white rounded-sm border-0">
84 </app-popover-promos> 84 </app-popover-promos>
85 <app-popover-sinonimos 85 <app-popover-sinonimos
86 *ngIf="sinonimos.length > 0" 86 *ngIf="sinonimos.length > 0"
87 [popover]="popoverDirective" 87 [popover]="popoverDirective"
88 [popoverContent]="sinonimos" 88 [popoverContent]="sinonimos"
89 (productosPersonalizados)="productosPersonalizados($event)" 89 (productosPersonalizados)="productosPersonalizados($event)"
90 class="text-white rounded-sm border-0"> 90 class="text-white rounded-sm border-0">
91 </app-popover-sinonimos> 91 </app-popover-sinonimos>
92 </ng-template> 92 </ng-template>
93 <div 93 <div
94 placement="left" 94 placement="left"
95 triggers="" 95 triggers=""
96 [popover]="popTemplate" 96 [popover]="popTemplate"
97 class="w-100" 97 class="w-100"
98 #pop="bs-popover"> 98 #pop="bs-popover">
99 <div class="card bg-white border-0 shadow rounded mb-auto"> 99 <div class="card bg-white border-0 shadow rounded mb-auto">
100 <div class="card-body text-left px-4 py-3"> 100 <div class="card-body text-left px-4 py-3">
101 <div class="row"> 101 <div class="row">
102 <div class="col-auto"> 102 <div class="col-auto">
103 <p class="m-0 h3 card-title">Cargar Productos</p> 103 <p class="m-0 h3 card-title">Cargar Productos</p>
104 </div> 104 </div>
105 <div class="col-auto p-0"> 105 <div class="col-auto p-0">
106 <img src="../../../assets/img/escanear.png" class="w-15"> 106 <img src="../../../assets/img/escanear.png" class="w-15">
107 </div> 107 </div>
108 </div> 108 </div>
109 <p class="h5 card-text text-muted font-weight-light"> 109 <p class="h5 card-text text-muted font-weight-light">
110 Coloque un producto frente<br> 110 Coloque un producto frente<br>
111 al lector de códigos o selecciónelo en pantalla. 111 al lector de códigos o selecciónelo en pantalla.
112 </p> 112 </p>
113 </div> 113 </div>
114 <div class="row mx-3 mb-3"> 114 <div class="row mx-3 mb-3">
115 <div class="col card bg-white shadow border-0 w-75 p-0 mx-auto rounded-sm"> 115 <div class="col card bg-white shadow border-0 w-75 p-0 mx-auto rounded-sm">
116 <!-- IMAGEN DE ESCANER --> 116 <!-- IMAGEN DE ESCANER -->
117 <img 117 <img
118 *ngIf="!productoAcargar" 118 *ngIf="!productoAcargar"
119 class="card-img-top d-block w-100 mx-auto rounded-sm" 119 class="card-img-top d-block w-100 mx-auto rounded-sm"
120 src="../../../assets/img/escanner.jpg"> 120 src="../../../assets/img/escanner.jpg">
121 121
122 <!-- PRODUCTO A CARGAR --> 122 <!-- PRODUCTO A CARGAR -->
123 <div class="fade-in m-0" *ngIf="productoAcargar && !promoAcargar"> 123 <div class="fade-in m-0" *ngIf="productoAcargar && !promoAcargar">
124 <img 124 <img
125 class="card-img-top d-block w-75 shadow mx-auto rounded-sm" 125 class="card-img-top d-block w-75 shadow mx-auto rounded-sm"
126 src="{{apiImagenes}}/imagenes/{{productoAcargar.imagenes[0].imagen}}"> 126 src="{{apiImagenes}}/imagenes/{{productoAcargar.imagenes[0].imagen}}">
127 127
128 <div class="row justify-content-between m-3"> 128 <div class="row justify-content-between m-3">
129 <div class="col-12 text-left px-1"> 129 <div class="col-12 text-left px-1">
130 <p class="h6 font-weight-bold mb-0">{{productoAcargar.DET_LAR}}</p> 130 <p class="h6 font-weight-bold mb-0">{{productoAcargar.DET_LAR}}</p>
131 </div> 131 </div>
132 <div class="col-12 text-right mt-2"> 132 <div class="col-12 text-right mt-2">
133 <p class="h5 font-weight-bold mb-0">{{productoAcargar.PreVen | currency}}</p> 133 <p class="h5 font-weight-bold mb-0">{{productoAcargar.PreVen | currency}}</p>
134 </div> 134 </div>
135 </div> 135 </div>
136 </div> 136 </div>
137 137
138 <!-- PROMO A CARGAR --> 138 <!-- PROMO A CARGAR -->
139 <div class="fade-in m-0" *ngIf="promoAcargar"> 139 <div class="fade-in m-0" *ngIf="promoAcargar">
140 <img 140 <img
141 class="card-img-top d-block w-100 mx-auto rounded-sm" 141 class="card-img-top d-block w-100 mx-auto rounded-sm"
142 src="{{apiImagenes}}/imagenes/{{promoAcargar.imagenes[0].imagen}}"> 142 src="{{apiImagenes}}/imagenes/{{promoAcargar.imagenes[0].imagen}}">
143 143
144 <div class="row justify-content-between m-3"> 144 <div class="row justify-content-between m-3">
145 <div class="col-12 text-left px-1"> 145 <div class="col-12 text-left px-1">
146 <p class="h6 font-weight-bold mb-0">{{promoAcargar.DET_LAR}}</p> 146 <p class="h6 font-weight-bold mb-0">{{promoAcargar.DET_LAR}}</p>
147 </div> 147 </div>
148 <div class="col-12 text-right mt-2 align-self-end"> 148 <div class="col-12 text-right mt-2 align-self-end">
149 <p class="h5 font-weight-bold mb-0">{{promoAcargar.PreVen | currency}}</p> 149 <p class="h5 font-weight-bold mb-0">{{promoAcargar.PreVen | currency}}</p>
150 </div> 150 </div>
151 </div> 151 </div>
152 </div> 152 </div>
153 153
154 </div> 154 </div>
155 <!-- BOTONES DE CARGAR PRODUCTOS--> 155 <!-- BOTONES DE CARGAR PRODUCTOS-->
156 <div 156 <div
157 class="col-5 pr-0" 157 class="col-5 pr-0"
158 *ngIf="promociones.length > 0"> 158 *ngIf="promociones.length > 0">
159 <button 159 <button
160 *ngIf="!promoAcargar || sinonimos.length == 0" 160 *ngIf="!promoAcargar || sinonimos.length == 0"
161 type="button" 161 type="button"
162 class="btn btn-primary btn-block shadow-sm" 162 class="btn btn-primary btn-block shadow-sm"
163 (click)="pop.show()"> 163 (click)="pop.show()">
164 <span class="pr-2">Mostrar promociones</span> 164 <span class="pr-2">Mostrar promociones</span>
165 <i class="fa fa-bullhorn fa-flip-horizontal" aria-hidden="true"></i> 165 <i class="fa fa-bullhorn fa-flip-horizontal" aria-hidden="true"></i>
166 </button> 166 </button>
167 <button 167 <button
168 *ngIf="sinonimos.length == 0" 168 *ngIf="sinonimos.length == 0"
169 type="button" 169 type="button"
170 class="btn btn-light btn-block shadow-sm my-3" 170 class="btn btn-light btn-block shadow-sm my-3"
171 (click)="confirmarProducto()"> 171 (click)="confirmarProducto()">
172 <span class="pr-2 font-weight-bold">Confirmar</span> 172 <span class="pr-2 font-weight-bold">Confirmar</span>
173 <i class="fa fa-check text-success" aria-hidden="true"></i> 173 <i class="fa fa-check text-success" aria-hidden="true"></i>
174 </button> 174 </button>
175 <button 175 <button
176 type="button" 176 type="button"
177 class="btn btn-light btn-block shadow-sm" 177 class="btn btn-light btn-block shadow-sm"
178 (click)="deshacerCarga()"> 178 (click)="deshacerCarga()">
179 <span class="pr-2">Deshacer</span> 179 <span class="pr-2">Deshacer</span>
180 <i class="fa fa-undo text-warning" aria-hidden="true"></i> 180 <i class="fa fa-undo text-warning" aria-hidden="true"></i>
181 </button> 181 </button>
182 </div> 182 </div>
183 </div> 183 </div>
184 </div> 184 </div>
185 </div> 185 </div>
186 186
187 <!-- BUSCAR PRODUCTOS --> 187 <!-- BUSCAR PRODUCTOS -->
188 <div (click)="irBusquedaProductos('todos')" 188 <div (click)="irBusquedaProductos('todos')"
189 class="card card-effect bg-white border-0 shadow rounded w-100 mt-3"> 189 class="card card-effect bg-white border-0 shadow rounded w-100 mt-3">
190 <div class="card-body text-left px-4 py-3"> 190 <div class="card-body text-left px-4 py-3">
191 <div class="row"> 191 <div class="row">
192 <div class="col-auto"> 192 <div class="col-auto">
193 <p class="m-0 h3 card-title">Buscar Productos</p> 193 <p class="m-0 h3 card-title">Buscar Productos</p>
194 <p class="h5 card-text text-muted font-weight-light"> 194 <p class="h5 card-text text-muted font-weight-light">
195 Busque aquí los productos<br> 195 Busque aquí los productos<br>
196 que no tienen código.</p> 196 que no tienen código.</p>
197 </div> 197 </div>
198 <div class="col-auto p-0"> 198 <div class="col-auto p-0">
199 <img src="../../../assets/img/primario.buscar.png" class="w-15"> 199 <img src="../../../assets/img/primario.buscar.png" class="w-15">
200 </div> 200 </div>
201 </div> 201 </div>
202 202
203 </div> 203 </div>
204 </div> 204 </div>
205 205
206 </div> 206 </div>
207 207
208 </div> 208 </div>
209 209
210 </div> 210 </div>
211 </div> 211 </div>
212
213 <div class="row m-0 fade-in" [hidden]="mostrarPantalla">
214 <p class="w-100 text-center">No esá configurado el punto de venta</p>
215 </div>
212 216
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 { APP_SETTINGS } from 'src/etc/AppSettings'; 3 import { APP_SETTINGS } 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 = APP_SETTINGS.apiImagenes; 24 private apiImagenes: string = APP_SETTINGS.apiImagenes;
25 private mostrarPantalla : boolean = false;
25 26
26 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; 27 @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective;
27 28
28 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { 29 @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) {
29 30
30 if (e.keyCode == 13) { 31 if (e.keyCode == 13) {
31 this.buscarByCodigoBarras(this.busqueda); 32 this.buscarByCodigoBarras(this.busqueda);
32 this.busqueda = ''; 33 this.busqueda = '';
33 } else { 34 } else {
34 this.busqueda += e.key; 35 this.busqueda += e.key;
35 } 36 }
36 }; 37 };
37 38
38 constructor( 39 constructor(
39 private router: Router, 40 private router: Router,
40 private productoService: ProductoService 41 private productoService: ProductoService
41 ) { } 42 ) { }
42 43
43 ngOnInit() { 44 ngOnInit() {
44 45
45 this.productoAcargar = this.productoService.productoAcargar; 46 this.productoAcargar = this.productoService.productoAcargar;
46 this.getProductos(); 47 this.getProductos();
48 this.mostrarPantalla = localStorage.getItem('impresoraPVE') ? true : false;
47 } 49 }
48 50
49 ngAfterViewInit() { 51 ngAfterViewInit() {
50 52
51 setTimeout(() => { 53 setTimeout(() => {
52 if (!this.productoAcargar) return; 54 if (!this.productoAcargar) return;
53 55
54 if (this.productoAcargar.PRO) { 56 if (this.productoAcargar.PRO) {
55 this.promociones.push(this.productoAcargar); 57 this.promociones.push(this.productoAcargar);
56 this.promoSeleccionada(this.productoAcargar, true); 58 this.promoSeleccionada(this.productoAcargar, true);
57 } 59 }
58 else { 60 else {
59 this.getPromociones(); 61 this.getPromociones();
60 } 62 }
61 }) 63 })
62 } 64 }
63 65
64 getProductos() { 66 getProductos() {
65 67
66 this.productoService.getAll() 68 this.productoService.getAll()
67 .subscribe((productos: Producto[]) => { 69 .subscribe((productos: Producto[]) => {
68 this.productos = productos; 70 this.productos = productos;
69 }); 71 });
70 } 72 }
71 73
72 getPromociones() { 74 getPromociones() {
73 75
74 var sector = this.productoAcargar.CodSec; 76 var sector = this.productoAcargar.CodSec;
75 var codigo = this.productoAcargar.CodArt; 77 var codigo = this.productoAcargar.CodArt;
76 this.productoService.getPromociones(sector, codigo) 78 this.productoService.getPromociones(sector, codigo)
77 .subscribe((res: Producto[]) => { 79 .subscribe((res: Producto[]) => {
78 80
79 if (res.length === 0) { 81 if (res.length === 0) {
80 82
81 this.productoAcargar.cantidad ? false : this.productoAcargar.cantidad = 1; 83 this.productoAcargar.cantidad ? false : this.productoAcargar.cantidad = 1;
82 this.productoService.setProductos(this.productoAcargar); 84 this.productoService.setProductos(this.productoAcargar);
83 this.productoAcargar = this.productoService.productoAcargar = undefined; 85 this.productoAcargar = this.productoService.productoAcargar = undefined;
84 } else { 86 } else {
85 87
86 this.promociones = res; 88 this.promociones = res;
87 this.popoverDirective.show(); 89 this.popoverDirective.show();
88 } 90 }
89 }, error => { console.error(error); }) 91 }, error => { console.error(error); })
90 } 92 }
91 93
92 confirmarProducto(cantidad?: number) { 94 confirmarProducto(cantidad?: number) {
93 95
94 let producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; 96 let producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar;
95 97
96 if (cantidad) { 98 if (cantidad) {
97 producto.cantidad = cantidad; 99 producto.cantidad = cantidad;
98 } else { 100 } else {
99 producto.cantidad = producto.cantidad ? producto.cantidad : 1; 101 producto.cantidad = producto.cantidad ? producto.cantidad : 1;
100 } 102 }
101 103
102 this.productoService.setProductos(producto); 104 this.productoService.setProductos(producto);
103 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; 105 this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined;
104 this.productoService.esPromoPersonalizada = false; 106 this.productoService.esPromoPersonalizada = false;
105 this.promociones = []; 107 this.promociones = [];
106 this.popoverDirective.hide(); 108 this.popoverDirective.hide();
107 } 109 }
108 110
109 promoSeleccionada($event: Producto, showPopover: boolean) { 111 promoSeleccionada($event: Producto, showPopover: boolean) {
110 112
111 this.productoService.getProductoById($event.id) 113 this.productoService.getProductoById($event.id)
112 .subscribe((res: Producto) => { 114 .subscribe((res: Producto) => {
113 115
114 $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes; 116 $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes;
115 this.promoAcargar = $event; 117 this.promoAcargar = $event;
116 118
117 if ($event.tieneSinonimos) { 119 if ($event.tieneSinonimos) {
118 this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); 120 this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt);
119 } else if (showPopover) { 121 } else if (showPopover) {
120 this.popoverDirective.show(); 122 this.popoverDirective.show();
121 } else { 123 } else {
122 this.popoverDirective.hide(); 124 this.popoverDirective.hide();
123 } 125 }
124 126
125 }, 127 },
126 error => { console.log(error); }) 128 error => { console.log(error); })
127 } 129 }
128 130
129 getSinonimos(sector, codigo) { 131 getSinonimos(sector, codigo) {
130 132
131 this.productoService.getPromocionSinonimos(sector, codigo) 133 this.productoService.getPromocionSinonimos(sector, codigo)
132 .subscribe((res: Sinonimo[]) => { 134 .subscribe((res: Sinonimo[]) => {
133 135
134 res.forEach(sinonimo => { 136 res.forEach(sinonimo => {
135 137
136 sinonimo.cantidad = 0; 138 sinonimo.cantidad = 0;
137 this.promoAcargar.productos.forEach(productoPromo => { 139 this.promoAcargar.productos.forEach(productoPromo => {
138 140
139 sinonimo.productos.forEach(productoSinonimo => { 141 sinonimo.productos.forEach(productoSinonimo => {
140 142
141 if (productoSinonimo.id === productoPromo.id) { 143 if (productoSinonimo.id === productoPromo.id) {
142 productoSinonimo.cantidad = productoPromo.cantidad; 144 productoSinonimo.cantidad = productoPromo.cantidad;
143 sinonimo.cantidad += productoPromo.cantidad; 145 sinonimo.cantidad += productoPromo.cantidad;
144 } 146 }
145 }) 147 })
146 }) 148 })
147 }) 149 })
148 this.sinonimos = res; 150 this.sinonimos = res;
149 (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide(); 151 (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide();
150 }) 152 })
151 } 153 }
152 154
153 productosPersonalizados($event: any) { 155 productosPersonalizados($event: any) {
154 156
155 let productosPersonalizados = $event.productosAenviar; 157 let productosPersonalizados = $event.productosAenviar;
156 158
157 productosPersonalizados.forEach(productoElegido => { 159 productosPersonalizados.forEach(productoElegido => {
158 160
159 this.promoAcargar.productos = this.promoAcargar.productos.filter(productoPromo => { 161 this.promoAcargar.productos = this.promoAcargar.productos.filter(productoPromo => {
160 return productoPromo.idSinonimo != productoElegido.idSinonimo; 162 return productoPromo.idSinonimo != productoElegido.idSinonimo;
161 }); 163 });
162 }); 164 });
163 165
164 this.promoAcargar.productos = this.promoAcargar.productos.concat(productosPersonalizados); 166 this.promoAcargar.productos = this.promoAcargar.productos.concat(productosPersonalizados);
165 this.confirmarProducto($event.cantidadPromo); 167 this.confirmarProducto($event.cantidadPromo);
166 } 168 }
167 169
168 buscarByCodigoBarras(busqueda) { 170 buscarByCodigoBarras(busqueda) {
169 171
170 let producto = this.productos.filter(producto => { 172 let producto = this.productos.filter(producto => {
171 return producto.codigoBarra == busqueda; 173 return producto.codigoBarra == busqueda;
172 }); 174 });
173 175
174 if (producto.length) { 176 if (producto.length) {
175 177
176 this.productoAcargar = producto[0]; 178 this.productoAcargar = producto[0];
177 this.getPromociones(); 179 this.getPromociones();
178 180
179 } else { 181 } else {
180 alert('No se encuentra el producto'); 182 alert('No se encuentra el producto');
181 } 183 }
182 184
183 } 185 }
184 186
185 irBusquedaProductos(value) { 187 irBusquedaProductos(value) {
186 188
187 this.productoService.mostrar = value; 189 this.productoService.mostrar = value;
188 this.router.navigate(['busqueda-productos']); 190 this.router.navigate(['busqueda-productos']);
189 } 191 }
190 192
191 deshacerCarga() { 193 deshacerCarga() {
192 194
193 if (this.sinonimos.length > 0) { 195 if (this.sinonimos.length > 0) {
194 this.sinonimos = []; 196 this.sinonimos = [];
195 this.productoService.esPromoPersonalizada = false; 197 this.productoService.esPromoPersonalizada = false;
196 this.popoverDirective.hide(); 198 this.popoverDirective.hide();
197 } 199 }
198 200
199 if (this.promoAcargar) { 201 if (this.promoAcargar) {
200 this.promoAcargar = undefined; 202 this.promoAcargar = undefined;
201 if (this.productoAcargar.PRO) { 203 if (this.productoAcargar.PRO) {
202 this.productoAcargar = undefined; 204 this.productoAcargar = undefined;
203 this.promociones = []; 205 this.promociones = [];
204 this.popoverDirective.hide(); 206 this.popoverDirective.hide();
205 } else { 207 } else {
206 this.popoverDirective.show(); 208 this.popoverDirective.show();
207 } 209 }
208 } else { 210 } else {
209 this.productoAcargar = undefined; 211 this.productoAcargar = undefined;
210 this.promociones = []; 212 this.promociones = [];
211 this.popoverDirective.hide(); 213 this.popoverDirective.hide();
212 } 214 }
213 } 215 }
214 216
215 } 217 }
216 218