diff --git a/bookie/src/app/auth/auth.service.ts b/bookie/src/app/auth/auth.service.ts index c21e7c3..68ad3fb 100644 --- a/bookie/src/app/auth/auth.service.ts +++ b/bookie/src/app/auth/auth.service.ts @@ -70,4 +70,8 @@ export class AuthService { ); } + hasPermission(permission: string) : boolean { + return this.user !== undefined && this.user.isAuthenticated && this.user.perms.indexOf(permission) !== -1; + } + } diff --git a/bookie/src/app/sales/bill-type/bill-type.component.css b/bookie/src/app/sales/bill-type/bill-type.component.css new file mode 100644 index 0000000..ae1afd4 --- /dev/null +++ b/bookie/src/app/sales/bill-type/bill-type.component.css @@ -0,0 +1,11 @@ +.square-button { + min-width: 150px; + max-width: 150px; + min-height: 150px; + cursor: pointer; + margin: 20px; +} +.selected { + background-color: green; +} + diff --git a/bookie/src/app/sales/bill-type/bill-type.component.html b/bookie/src/app/sales/bill-type/bill-type.component.html new file mode 100644 index 0000000..78cbdcd --- /dev/null +++ b/bookie/src/app/sales/bill-type/bill-type.component.html @@ -0,0 +1,18 @@ +
+ +

Regular

+
+ +

Staff

+
+ +

No Charge

+
+
+ + + + diff --git a/bookie/src/app/sales/bill-type/bill-type.component.spec.ts b/bookie/src/app/sales/bill-type/bill-type.component.spec.ts new file mode 100644 index 0000000..9601258 --- /dev/null +++ b/bookie/src/app/sales/bill-type/bill-type.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BillTypeComponent } from './bill-type.component'; + +describe('BillTypeComponent', () => { + let component: BillTypeComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BillTypeComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BillTypeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/bookie/src/app/sales/bill-type/bill-type.component.ts b/bookie/src/app/sales/bill-type/bill-type.component.ts new file mode 100644 index 0000000..b3e7e47 --- /dev/null +++ b/bookie/src/app/sales/bill-type/bill-type.component.ts @@ -0,0 +1,28 @@ +import { Component } from '@angular/core'; +import { MatDialogRef } from '@angular/material'; +import { PrintType } from "../bills/bill"; + +@Component({ + selector: 'app-bill-type', + templateUrl: './bill-type.component.html', + styleUrls: ['./bill-type.component.css'] +}) +export class BillTypeComponent { + selected: string; + + constructor( + public dialogRef: MatDialogRef, + + ) { + this.selected = null; + } + + select(s: string) { + this.selected = s; + } + + accept(): void { + this.dialogRef.close(PrintType[this.selected]); + } +} + diff --git a/bookie/src/app/sales/bill.service.ts b/bookie/src/app/sales/bill.service.ts index aa733f1..b94bd9d 100644 --- a/bookie/src/app/sales/bill.service.ts +++ b/bookie/src/app/sales/bill.service.ts @@ -57,7 +57,9 @@ export class BillService { } addProduct(product: Product): void { - const old = this.data.find(x => !x.isKot && x.productId === product.id && x.isHappyHour === product.hasHappyHour); + const old = this.data.find( + x => !x.isKot && !x.id && x.productId === product.id && x.isHappyHour === product.hasHappyHour + ); if (old !== undefined) { old.quantity += 1; } else { @@ -170,16 +172,15 @@ export class BillService { ); } - printBill(guest_book_id: string): Observable { + printBill(guest_book_id: string, printType: PrintType): Observable { let item = JSON.parse(JSON.stringify(this.bill)); item.kots.forEach(k => { k.inventories.forEach(i => { i.discount = this.data.find(x => !x.isKot && x.id === i.id).discount; }) }); - console.log(item); item.kots.push(this.getKot()); - return this.ser.saveOrUpdate(item, PrintType.Bill, guest_book_id, true).pipe( + return this.ser.saveOrUpdate(item, printType, guest_book_id, true).pipe( tap(x => console.log(x)) ); } diff --git a/bookie/src/app/sales/home/sales-home.component.ts b/bookie/src/app/sales/home/sales-home.component.ts index b2e70a1..81fe6c0 100644 --- a/bookie/src/app/sales/home/sales-home.component.ts +++ b/bookie/src/app/sales/home/sales-home.component.ts @@ -1,12 +1,15 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from "@angular/router"; import { MatDialog } from "@angular/material"; -import { mergeMap, tap } from "rxjs/operators"; -import { Observable, of as observableOf } from "rxjs"; +import { concatMap, tap } from "rxjs/operators"; +import { iif, Observable, of as observableOf, throwError} from "rxjs"; import { BillService } from '../bill.service'; import { ToasterService } from "../../core/toaster.service"; import { DiscountComponent } from "../discount/discount.component"; import { SaleCategoryService } from "../../sale-category/sale-category.service"; +import { BillTypeComponent } from "../bill-type/bill-type.component"; +import { PrintType } from "../bills/bill"; +import { AuthService } from "../../auth/auth.service"; @Component({ selector: 'app-sales-home', @@ -19,6 +22,7 @@ export class SalesHomeComponent implements OnInit { private route: ActivatedRoute, private router: Router, private dialog: MatDialog, + private auth: AuthService, private toaster: ToasterService, private mcSer: SaleCategoryService, private bs: BillService) { @@ -39,10 +43,12 @@ export class SalesHomeComponent implements OnInit { } discount(): void { - this.showDiscount().subscribe(); + if (this.auth.hasPermission("Discount")) { + this.showDiscount().subscribe(); + } } - showDiscount(): Observable { + showDiscount(): Observable { const dialogRef = this.dialog.open(DiscountComponent, { // width: '750px', data: this.mcSer.listForDiscount() @@ -56,24 +62,48 @@ export class SalesHomeComponent implements OnInit { ) } + discountDialog (canGiveDiscount: boolean) : Observable { + let discObs = null; + if (canGiveDiscount) { + return discObs = this.showDiscount(); + } else { + return discObs = observableOf(""); + } + + } + + billTypeDialog() { + return this.dialog.open(BillTypeComponent).afterClosed().pipe( + tap(x => { + if (!x) { + throwError ("No Bill Type Chosen") + } + }) + ) + } printBill() { - const canGiveDiscount = true; + const canGiveDiscount = this.auth.hasPermission("Discount"); let guestBookId = null; if (this.route.snapshot.queryParamMap.has("guest")) { guestBookId = this.route.snapshot.queryParamMap.get("guest"); } - let discObs = null - if (!canGiveDiscount) { - discObs = this.showDiscount(); - } else { - discObs = observableOf(""); - } - discObs.pipe( - mergeMap(x => this.bs.printBill(guestBookId)) - ).subscribe(x => { - this.toaster.show('Success', ''); - this.router.navigate(['/sales']); - }); + this.discountDialog(canGiveDiscount).pipe( + concatMap(() => this.billTypeDialog()) + ).pipe( + concatMap( + (x: boolean | PrintType) => iif( + () => !!x, + this.bs.printBill(guestBookId, x as PrintType), + throwError(x) + ) + ), + ).subscribe(() => { + this.toaster.show('Success', ''); + this.router.navigate(['/sales']); + }, + x => { + this.toaster.show('Error', "No Bill Type Chosen") + }); } } diff --git a/bookie/src/app/sales/sales.module.ts b/bookie/src/app/sales/sales.module.ts index 91a1e14..4df267b 100644 --- a/bookie/src/app/sales/sales.module.ts +++ b/bookie/src/app/sales/sales.module.ts @@ -26,6 +26,7 @@ import { SalesHomeComponent } from './home/sales-home.component'; import { BillService } from './bill.service'; import { QuantityComponent } from './quantity/quantity.component'; import { DiscountComponent } from "./discount/discount.component"; +import {BillTypeComponent} from "./bill-type/bill-type.component"; @NgModule({ providers: [ @@ -33,6 +34,7 @@ import { DiscountComponent } from "./discount/discount.component"; ], declarations: [ BillsComponent, + BillTypeComponent, DiscountComponent, MenuCategoriesComponent, ModifiersComponent, @@ -61,6 +63,7 @@ import { DiscountComponent } from "./discount/discount.component"; SalesRoutingModule ], entryComponents: [ + BillTypeComponent, DiscountComponent, ModifiersComponent, QuantityComponent