Commit 7a57878740682b920c37346284034629862e9fad

Authored by Marcelo Puebla
1 parent 7569cac360
Exists in develop

Change

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