Commit cffd6f774a95124ae78678f81237e0c84e0e1fb2

Authored by Benjamin Rodriguez
1 parent a4b272bda1

arreglo commit

Showing 1 changed file with 4 additions and 4 deletions   Show diff stats
src/app/modules/comanda/comanda.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { IComanda, IComandaDetalle, IComponente } from 'src/app/interfaces/IComanda'; 2 import { IComanda, IComandaDetalle, IComponente } from 'src/app/interfaces/IComanda';
3 import { ComandaService } from 'src/app/services/comanda/comanda.service'; 3 import { ComandaService } from 'src/app/services/comanda/comanda.service';
4 import * as _ from 'lodash'; 4 import * as _ from 'lodash';
5 5
6 @Component({ 6 @Component({
7 selector: 'app-comanda', 7 selector: 'app-comanda',
8 templateUrl: './comanda.component.html', 8 templateUrl: './comanda.component.html',
9 styleUrls: ['./comanda.component.scss'] 9 styleUrls: ['./comanda.component.scss']
10 }) 10 })
11 export class ComandaComponent implements OnInit { 11 export class ComandaComponent implements OnInit {
12 comandas: IComanda[] = []; 12 comandas: IComanda[] = [];
13 cicloTime: any; 13 cicloTime: any;
14 14
15 constructor( 15 constructor(
16 private comandaService: ComandaService, 16 private comandaService: ComandaService,
17 ) { } 17 ) { }
18 18
19 ngOnInit() { 19 ngOnInit() {
20 this.getComandas(); 20 this.getComandas();
21 this.timerGetComandas(); 21 this.timerGetComandas();
22 } 22 }
23 23
24 ngOnDestroy() { 24 ngOnDestroy() {
25 clearInterval(this.cicloTime); 25 clearInterval(this.cicloTime);
26 } 26 }
27 27
28 timerGetComandas() { 28 timerGetComandas() {
29 this.cicloTime = setInterval(() => { 29 this.cicloTime = setInterval(() => {
30 this.getComandas(); 30 this.getComandas();
31 }, 5000); 31 }, 5000);
32 } 32 }
33 33
34 getComandas() { 34 getComandas() {
35 this.comandaService.getAll() 35 this.comandaService.getAll()
36 .subscribe((resComandas: IComanda[]) => { 36 .subscribe((resComandas: IComanda[]) => {
37 this.addNewComandas(resComandas); 37 this.addNewComandas(resComandas);
38 }, e => console.error(e)); 38 }, e => console.error(e));
39 } 39 }
40 40
41 addNewComandas(resComandas: IComanda[]) { 41 addNewComandas(resComandas: IComanda[]) {
42 for (let j = 0; j < resComandas.length; j++) { 42 for (let j = 0; j < resComandas.length; j++) {
43 for (let i = 0; i < this.comandas.length; i++) { 43 for (let i = 0; i < this.comandas.length; i++) {
44 if (this.comandas[i].id === resComandas[j].id) { 44 if (this.comandas[i].id === resComandas[j].id) {
45 resComandas.splice(j, 1); 45 resComandas.splice(j, 1);
46 } 46 }
47 } 47 }
48 } 48 }
49 if (!resComandas.length) return; 49 if (!resComandas.length) return;
50 Array.prototype.push.apply(this.comandas, resComandas); 50 Array.prototype.push.apply(this.comandas, resComandas);
51 this.startTimersPedido(resComandas); 51 this.startTimersPedido(resComandas);
52 } 52 }
53 53
54 updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) { 54 updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) {
55 let data = { 55 let data = {
56 idComanda: comanda.id, 56 idComanda: comanda.id,
57 estado: estadoNuevo, 57 estado: estadoNuevo,
58 observacion: observacionNueva, 58 observacion: observacionNueva,
59 tiempoEspera: `${comanda.hoursPedido}:${comanda.secondsPedido}:${comanda.secondsPedido}`, 59 tiempoEspera: `${comanda.hoursPedido}:${comanda.secondsPedido}:${comanda.secondsPedido}`,
60 tiempoElaboracion: `${comanda.hoursElaboracion}:${comanda.secondsElaboracion}:${comanda.secondsElaboracion}`, 60 tiempoElaboracion: `${comanda.hoursElaboracion}:${comanda.secondsElaboracion}:${comanda.secondsElaboracion}`,
61 } 61 };
62 if (data.estado == 3) { 62 if (data.estado === 3) {
63 this.comandaService.imprimirComandaCocina(parseInt(data.idComanda)) 63 this.comandaService.imprimirComandaCocina(parseInt(data.idComanda))
64 .subscribe(res => { }, err => console.error(err) 64 .subscribe(res => { }, err => console.error(err)
65 ); 65 );
66 } 66 }
67 67
68 if (estadoNuevo !== 2) comanda.detalles.forEach(d => d.seeDetalle = false); 68 if (estadoNuevo !== 2) comanda.detalles.forEach(d => d.seeDetalle = false);
69 69
70 this.comandaService.update(data) 70 this.comandaService.update(data)
71 .subscribe((res: any) => { 71 .subscribe((res: any) => {
72 if (res.data) { 72 if (res.data) {
73 comanda.estado = estadoNuevo; 73 comanda.estado = estadoNuevo;
74 comanda.observacion = observacionNueva; 74 comanda.observacion = observacionNueva;
75 if (estadoNuevo == 2) { 75 if (estadoNuevo === 2) {
76 this.startTimerElaboracion(comanda); 76 this.startTimerElaboracion(comanda);
77 } else if (comanda.timerElaboracion) { 77 } else if (comanda.timerElaboracion) {
78 clearInterval(comanda.timerElaboracion) 78 clearInterval(comanda.timerElaboracion);
79 } 79 }
80 } 80 }
81 }, e => console.error(e)); 81 }, e => console.error(e));
82 } 82 }
83 83
84 rellenar(relleno, longitud) { 84 rellenar(relleno, longitud) {
85 relleno = '' + relleno; 85 relleno = '' + relleno;
86 while (relleno.length < longitud) { 86 while (relleno.length < longitud) {
87 relleno = '0' + relleno; 87 relleno = '0' + relleno;
88 } 88 }
89 return relleno; 89 return relleno;
90 } 90 }
91 91
92 toggleVerComponentes(detalle: IComandaDetalle, comanda: IComanda) { 92 toggleVerComponentes(detalle: IComandaDetalle, comanda: IComanda) {
93 detalle.seeDetalle = !detalle.seeDetalle; 93 detalle.seeDetalle = !detalle.seeDetalle;
94 } 94 }
95 95
96 hasTipo(componentes: IComponente[]) { 96 hasTipo(componentes: IComponente[]) {
97 return componentes.some(c => c.tipoArticulo === 6); 97 return componentes.some(c => c.tipoArticulo === 6);
98 } 98 }
99 99
100 //#region TIMERS 100 //#region TIMERS
101 startTimersPedido(comandas) { 101 startTimersPedido(comandas) {
102 comandas.forEach((comanda: IComanda) => { 102 comandas.forEach((comanda: IComanda) => {
103 this.comandaService.startTimerComanda(comanda, 'Pedido'); 103 this.comandaService.startTimerComanda(comanda, 'Pedido');
104 if (comanda.estado === 2) { 104 if (comanda.estado === 2) {
105 this.startTimerElaboracion(comanda); 105 this.startTimerElaboracion(comanda);
106 } 106 }
107 }); 107 });
108 } 108 }
109 109
110 startTimerElaboracion(comanda: IComanda) { 110 startTimerElaboracion(comanda: IComanda) {
111 this.comandaService.startTimerComanda(comanda, 'Elaboracion'); 111 this.comandaService.startTimerComanda(comanda, 'Elaboracion');
112 } 112 }
113 //#endregion 113 //#endregion
114 114
115 } 115 }
116 116