configuracion.component.ts
2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Component, OnInit } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap';
import { PuntoVentaService } from 'src/app/services/punto-venta.service';
import { PuntoVenta } from 'src/app/wrappers/puntoVenta';
import { ImpresoraService } from 'src/app/services/impresora.service';
import { Impresora } from 'src/app/wrappers/impresora';
import { FormGroup, FormControl } from '@angular/forms';
import { Router } from '@angular/router';
@Component({
selector: 'app-configuracion',
templateUrl: './configuracion.component.html',
styleUrls: ['./configuracion.component.scss']
})
export class ConfiguracionComponent implements OnInit {
puntosVenta: PuntoVenta[] = [];
impresoras: Impresora[] = [];
form: FormGroup;
reiniciar: boolean = false;
constructor(
private activeModal: BsModalRef,
private puntoVentaService: PuntoVentaService,
private impresoraService: ImpresoraService,
private router: Router
) { }
ngOnInit() {
this.form = new FormGroup({
usePlanillaPropia: new FormControl(false, []),
puntoVenta: new FormControl(null, []),
impresora: new FormControl(null, []),
})
this.puntoVentaService.getAll()
.subscribe((res: PuntoVenta[]) => {
this.puntosVenta = res;
this.setPuntoVenta();
}, console.error);
this.impresoraService.getAll()
.subscribe((res: Impresora[]) => {
this.impresoras = res;
this.setImpresora();
}, console.error);
}
close() {
this.activeModal.hide();
if (this.reiniciar) {
this.router.navigate(['inicio']);
}
}
acept() {
this.reiniciar = !localStorage.getItem('impresoraPVE') ? true : false;
let auxPuntoVenta = this.puntosVenta.find(p => p.ID === this.form.get('puntoVenta').value);
let auxImpresora = this.impresoras.find(p => p.PVE === this.form.get('impresora').value);
localStorage.setItem('pve', auxPuntoVenta ? auxPuntoVenta.ID.toString() : null);
localStorage.setItem('impresoraPVE', auxImpresora ? auxImpresora.PVE.toString() : null);
this.close();
}
setPuntoVenta() {
let pve = parseInt(localStorage.getItem('pve'));
let auxPuntoVenta = this.puntosVenta.find(x => x.ID === pve);
this.form.get('puntoVenta').setValue(auxPuntoVenta ? auxPuntoVenta.ID : null);
}
setImpresora() {
let impresoraPVE = parseInt(localStorage.getItem('impresoraPVE'));
let auxImpresora = this.impresoras.find(x => x.PVE === impresoraPVE);
this.form.get('impresora').setValue(auxImpresora ? auxImpresora.PVE : null);
}
}