comanda.component.ts
2.43 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
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';
@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();
}
getComandas() {
this.comandaService.getAll()
.subscribe((resComandas: IComanda[]) => {
console.log(resComandas)
this.addNewComandas(resComandas);
}, e => console.error(e));
}
addNewComandas(resComandas: IComanda[]) {
for (let j = 0; j < resComandas.length; j++) {
for (let i = 0; i < this.comandas.length; i++) {
if (this.comandas[i].id === resComandas[j].id) {
resComandas.splice(j, 1);
}
}
}
if (!resComandas.length) return;
Array.prototype.push.apply(this.comandas, resComandas);
// this.startTimersPedido(resComandas);
}
updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) {
let 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))
.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;
}
}, 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);
}
}