Commit 58593c6862598025de4512ff2d50c572c6f0004f
1 parent
5922cb62b4
Exists in
develop
arreglo de commit
Showing
1 changed file
with
0 additions
and
1 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 | detalles: [] = []; | ||
| 14 | cicloTime: any; | 13 | cicloTime: any; | 
| 15 | 14 | ||
| 16 | constructor( | 15 | constructor( | 
| 17 | private comandaService: ComandaService, | 16 | private comandaService: ComandaService, | 
| 18 | ) { } | 17 | ) { } | 
| 19 | 18 | ||
| 20 | ngOnInit() { | 19 | ngOnInit() { | 
| 21 | this.getComandas(); | 20 | this.getComandas(); | 
| 22 | this.timerGetComandas(); | 21 | this.timerGetComandas(); | 
| 23 | } | 22 | } | 
| 24 | 23 | ||
| 25 | OnDestroy() { | 24 | OnDestroy() { | 
| 26 | clearInterval(this.cicloTime); | 25 | clearInterval(this.cicloTime); | 
| 27 | } | 26 | } | 
| 28 | 27 | ||
| 29 | timerGetComandas() { | 28 | timerGetComandas() { | 
| 30 | this.cicloTime = setInterval(() => { | 29 | this.cicloTime = setInterval(() => { | 
| 31 | this.getComandas(); | 30 | this.getComandas(); | 
| 32 | }, 5000); | 31 | }, 5000); | 
| 33 | } | 32 | } | 
| 34 | 33 | ||
| 35 | getComandas() { | 34 | getComandas() { | 
| 36 | this.comandaService.getAll() | 35 | this.comandaService.getAll() | 
| 37 | .subscribe((resComandas: IComanda[]) => { | 36 | .subscribe((resComandas: IComanda[]) => { | 
| 38 | this.addNewComandas(resComandas); | 37 | this.addNewComandas(resComandas); | 
| 39 | }, e => console.error(e)); | 38 | }, e => console.error(e)); | 
| 40 | } | 39 | } | 
| 41 | 40 | ||
| 42 | addNewComandas(resComandas: IComanda[]) { | 41 | addNewComandas(resComandas: IComanda[]) { | 
| 43 | for (let j = 0; j < resComandas.length; j++) { | 42 | for (let j = 0; j < resComandas.length; j++) { | 
| 44 | for (const comanda of this.comandas) { | 43 | for (const comanda of this.comandas) { | 
| 45 | if (comanda.id === resComandas[j].id) { | 44 | if (comanda.id === resComandas[j].id) { | 
| 46 | resComandas.splice(j, 1); | 45 | resComandas.splice(j, 1); | 
| 47 | } | 46 | } | 
| 48 | } | 47 | } | 
| 49 | } | 48 | } | 
| 50 | if (!resComandas.length) return; | 49 | if (!resComandas.length) return; | 
| 51 | Array.prototype.push.apply(this.comandas, resComandas); | 50 | Array.prototype.push.apply(this.comandas, resComandas); | 
| 52 | this.startTimersPedido(resComandas); | 51 | this.startTimersPedido(resComandas); | 
| 53 | } | 52 | } | 
| 54 | 53 | ||
| 55 | updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) { | 54 | updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) { | 
| 56 | const data = { | 55 | const data = { | 
| 57 | idComanda: comanda.id, | 56 | idComanda: comanda.id, | 
| 58 | estado: estadoNuevo, | 57 | estado: estadoNuevo, | 
| 59 | observacion: observacionNueva, | 58 | observacion: observacionNueva, | 
| 60 | tiempoEspera: `${comanda.hoursPedido}:${comanda.secondsPedido}:${comanda.secondsPedido}`, | 59 | tiempoEspera: `${comanda.hoursPedido}:${comanda.secondsPedido}:${comanda.secondsPedido}`, | 
| 61 | tiempoElaboracion: `${comanda.hoursElaboracion}:${comanda.secondsElaboracion}:${comanda.secondsElaboracion}`, | 60 | tiempoElaboracion: `${comanda.hoursElaboracion}:${comanda.secondsElaboracion}:${comanda.secondsElaboracion}`, | 
| 62 | }; | 61 | }; | 
| 63 | if (data.estado === 3) { | 62 | if (data.estado === 3) { | 
| 64 | this.comandaService.imprimirComandaCocina(parseInt(data.idComanda, 10)) | 63 | this.comandaService.imprimirComandaCocina(parseInt(data.idComanda, 10)) | 
| 65 | .subscribe(res => { }, err => console.error(err) | 64 | .subscribe(res => { }, err => console.error(err) | 
| 66 | ); | 65 | ); | 
| 67 | } | 66 | } | 
| 68 | 67 | ||
| 69 | if (estadoNuevo !== 2) comanda.detalles.forEach(d => d.seeDetalle = false); | 68 | if (estadoNuevo !== 2) comanda.detalles.forEach(d => d.seeDetalle = false); | 
| 70 | 69 | ||
| 71 | this.comandaService.update(data) | 70 | this.comandaService.update(data) | 
| 72 | .subscribe((res: any) => { | 71 | .subscribe((res: any) => { | 
| 73 | if (res.data) { | 72 | if (res.data) { | 
| 74 | comanda.estado = estadoNuevo; | 73 | comanda.estado = estadoNuevo; | 
| 75 | comanda.observacion = observacionNueva; | 74 | comanda.observacion = observacionNueva; | 
| 76 | if (estadoNuevo === 2) { | 75 | if (estadoNuevo === 2) { | 
| 77 | this.startTimerElaboracion(comanda); | 76 | this.startTimerElaboracion(comanda); | 
| 78 | } else if (comanda.timerElaboracion) { | 77 | } else if (comanda.timerElaboracion) { | 
| 79 | clearInterval(comanda.timerElaboracion); | 78 | clearInterval(comanda.timerElaboracion); | 
| 80 | } | 79 | } | 
| 81 | } | 80 | } | 
| 82 | }, e => console.error(e)); | 81 | }, e => console.error(e)); | 
| 83 | } | 82 | } | 
| 84 | 83 | ||
| 85 | rellenar(relleno, longitud) { | 84 | rellenar(relleno, longitud) { | 
| 86 | relleno = '' + relleno; | 85 | relleno = '' + relleno; | 
| 87 | while (relleno.length < longitud) { | 86 | while (relleno.length < longitud) { | 
| 88 | relleno = '0' + relleno; | 87 | relleno = '0' + relleno; | 
| 89 | } | 88 | } | 
| 90 | return relleno; | 89 | return relleno; | 
| 91 | } | 90 | } | 
| 92 | 91 | ||
| 93 | toggleVerComponentes(detalle: IComandaDetalle, comanda: IComanda) { | 92 | toggleVerComponentes(detalle: IComandaDetalle, comanda: IComanda) { | 
| 94 | detalle.seeDetalle = !detalle.seeDetalle; | 93 | detalle.seeDetalle = !detalle.seeDetalle; | 
| 95 | } | 94 | } | 
| 96 | 95 | ||
| 97 | hasTipo(componentes: IComponente[]) { | 96 | hasTipo(componentes: IComponente[]) { | 
| 98 | return componentes.some(c => c.tipoArticulo === 6); | 97 | return componentes.some(c => c.tipoArticulo === 6); | 
| 99 | } | 98 | } | 
| 100 | 99 | ||
| 101 | //#region TIMERS | 100 | //#region TIMERS | 
| 102 | startTimersPedido(comandas) { | 101 | startTimersPedido(comandas) { | 
| 103 | comandas.forEach((comanda: IComanda) => { | 102 | comandas.forEach((comanda: IComanda) => { | 
| 104 | this.comandaService.startTimerComanda(comanda, 'Pedido'); | 103 | this.comandaService.startTimerComanda(comanda, 'Pedido'); | 
| 105 | if (comanda.estado === 2) { | 104 | if (comanda.estado === 2) { | 
| 106 | this.startTimerElaboracion(comanda); | 105 | this.startTimerElaboracion(comanda); | 
| 107 | } | 106 | } | 
| 108 | }); | 107 | }); | 
| 109 | } | 108 | } | 
| 110 | 109 | ||
| 111 | startTimerElaboracion(comanda: IComanda) { | 110 | startTimerElaboracion(comanda: IComanda) { | 
| 112 | this.comandaService.startTimerComanda(comanda, 'Elaboracion'); | 111 | this.comandaService.startTimerComanda(comanda, 'Elaboracion'); | 
| 113 | } | 112 | } | 
| 114 | //#endregion | 113 | //#endregion | 
| 115 | 114 | ||
| 116 | } | 115 | } | 
| 117 | 116 |