comanda.component.ts
3.25 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { Component, OnInit } from '@angular/core';
import { IComanda, IComandaDetalle, IComponente } from 'src/app/interfaces/IComanda';
import { ComandaService } from 'src/app/services/comanda/comanda.service';
import * as _ from 'lodash';
import { SoundManager } from 'src/app/utils/sound-manager';
@Component({
selector: 'app-comanda',
templateUrl: './comanda.component.html',
styleUrls: ['./comanda.component.scss']
})
export class ComandaComponent implements OnInit {
comandas: IComanda[] = [];
cicloTime: any;
constructor(
private comandaService: ComandaService,
) { }
ngOnInit() {
this.getComandas();
this.timerGetComandas();
}
OnDestroy() {
clearInterval(this.cicloTime);
}
timerGetComandas() {
this.cicloTime = setInterval(() => {
this.getComandas();
}, 5000);
}
getComandas() {
this.comandaService.getAll()
.subscribe((resComandas: IComanda[]) => {
this.addNewComandas(resComandas);
}, e => console.error(e));
}
addNewComandas(resComandas: IComanda[]) {
for (let j = 0; j < resComandas.length; j++) {
for (const comanda of this.comandas) {
if (comanda.id === resComandas[j].id) {
resComandas.splice(j, 1);
}
}
}
if (!resComandas.length) return;
SoundManager.playAudio('bell.mp3');
Array.prototype.push.apply(this.comandas, resComandas);
this.startTimersPedido(resComandas);
}
updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) {
const data = {
idComanda: comanda.id,
estado: estadoNuevo,
observacion: observacionNueva,
tiempoEspera: `${comanda.hoursPedido}:${comanda.secondsPedido}:${comanda.secondsPedido}`,
tiempoElaboracion: `${comanda.hoursElaboracion}:${comanda.secondsElaboracion}:${comanda.secondsElaboracion}`,
};
if (data.estado === 3) {
this.comandaService.imprimirComandaCocina(parseInt(data.idComanda, 10))
.subscribe(res => { }, err => console.error(err)
);
}
if (estadoNuevo !== 2) comanda.detalles.forEach(d => d.seeDetalle = false);
this.comandaService.update(data)
.subscribe((res: any) => {
if (res.data) {
comanda.estado = estadoNuevo;
comanda.observacion = observacionNueva;
if (estadoNuevo === 2) {
this.startTimerElaboracion(comanda);
} else if (comanda.timerElaboracion) {
clearInterval(comanda.timerElaboracion);
}
}
}, e => console.error(e));
}
rellenar(relleno, longitud) {
relleno = '' + relleno;
while (relleno.length < longitud) {
relleno = '0' + relleno;
}
return relleno;
}
toggleVerComponentes(detalle: IComandaDetalle, comanda: IComanda) {
detalle.seeDetalle = !detalle.seeDetalle;
}
hasTipo(componentes: IComponente[]) {
return componentes.some(c => c.tipoArticulo === 6);
}
//#region TIMERS
startTimersPedido(comandas) {
comandas.forEach((comanda: IComanda) => {
this.comandaService.startTimerComanda(comanda, 'Pedido');
if (comanda.estado === 2) {
this.startTimerElaboracion(comanda);
}
});
}
startTimerElaboracion(comanda: IComanda) {
this.comandaService.startTimerComanda(comanda, 'Elaboracion');
}
//#endregion
}