import { Component , OnInit , EventEmitter , Output } from '@angular/core' ; import { Item , Order } from '../../item' ; import { PosService } from '../../pos.service' ; import { DatabaseService } from '../../database.service' ; import { MatTabsModule } from '@angular/material' ; @ Component ( { selector : 'app-pos' , templateUrl : './pos.component.html' , styleUrls : [ './pos.component.scss' ] } ) export class PosComponent implements OnInit { products = [ ] ; productTypes = [ 'Drink' , 'Food' ] ; ticket : Item [ ] ; cartTotal = 0 ; cartNumItems = 0 ; items ; constructor ( private ticketSync , private db ) { } ngOnInit ( ) { this . ticketSync . currentTicket . subscribe ( data => this . ticket = data ) ; this . ticketSync . currentTotal . subscribe ( total => this . cartTotal = total ) ; this . ticketSync . currentCartNum . subscribe ( num => this . cartNumItems ) ; this . products [ 0 ] = this . db . getDrink ( ) ; this . products [ 1 ] = this . db . getFood ( ) ; } addToCheck ( item ) { if ( this . ticket . includes ( item ) ) { this . ticket [ this . ticket . indexOf ( item ) ] . quantity += 1 ; } else { this . ticket . push ( item ) ; } this . calculateTotal ( ) ; } calculateTotal ( ) { let total = 0 ; let cartNum = 0 ; this . ticket . forEach ( function ( item ) { total += ( item . price * item . quantity ) ; cartNum += item . quantity ; } ) ; this . cartTotal = total ; this . cartNumItems = cartNum ; this . ticketSync . updateNumItems ( this . cartNumItems ) ; this . ticketSync . updateTotal ( this . cartTotal ) ; } syncTicket ( ) { this . ticketSync . changeTicket ( this . ticket ) ; } }