diff --git a/barker/views/__init__.py b/barker/views/__init__.py index 96f0605..f8386a6 100644 --- a/barker/views/__init__.py +++ b/barker/views/__init__.py @@ -3,6 +3,7 @@ import uuid import re import pkg_resources +from pyramid.httpexceptions import HTTPFound from barker.exceptions import ValidationFailure from pyramid.response import Response, FileResponse @@ -17,12 +18,17 @@ def home(request): return FileResponse(file, request=request) -@forbidden_view_config(renderer='json') +@forbidden_view_config() def forbidden(request): - response = Response() - response.status_int = 403 if request.authenticated_userid is not None else 401 - response.content_type = 'application/json' - response.json = {'Error': 'Forbidden'} + if request.accept.quality("application/json") == 1: + response = Response("Forbidden") + response.status_int = 401 + return response + else: + ret = HTTPFound( + location=request.route_url("login", _query={"returnUrl": request.path_qs}) + ) + return ret return response diff --git a/bookie/src/app/sales/home/sales-home.component.html b/bookie/src/app/sales/home/sales-home.component.html index f3c0a72..71ede36 100644 --- a/bookie/src/app/sales/home/sales-home.component.html +++ b/bookie/src/app/sales/home/sales-home.component.html @@ -22,13 +22,16 @@ [class.disabled]="!receivePaymentAllowed()">

Receive Payment

- +

Move Table

- +

Void Bill

- +

Split Bill

diff --git a/bookie/src/app/sales/home/sales-home.component.ts b/bookie/src/app/sales/home/sales-home.component.ts index f0c82e3..21f9711 100644 --- a/bookie/src/app/sales/home/sales-home.component.ts +++ b/bookie/src/app/sales/home/sales-home.component.ts @@ -38,6 +38,22 @@ export class SalesHomeComponent implements OnInit { ngOnInit() { } + printKotAllowed(): boolean { + if (!this.auth.hasPermission('Print Kot')) { + return false; + } + if (!this.bs.bill.id) { + return true; + } + if (this.bs.bill.voucherType !== PrintType.Kot) { + return false; + } + if (this.bs.bill.isVoid) { + return false; + } + return true; + } + printKot() { if (!this.printKotAllowed()) { return; @@ -52,11 +68,8 @@ export class SalesHomeComponent implements OnInit { }); } - discount(): void { - if (!this.discountAllowed()) { - return; - } - this.showDiscount().subscribe(); + discountAllowed(): boolean { + return this.auth.hasPermission('Discount'); } showDiscount(): Observable { @@ -64,21 +77,18 @@ export class SalesHomeComponent implements OnInit { // width: '750px', data: this.mcSer.listForDiscount() }); - return dialogRef.afterClosed().pipe( - tap((result: boolean | { id: string, name: string, discount: number }[]) => { + return dialogRef.afterClosed(); + } + + discount(): void { + if (!this.discountAllowed()) { + return; + } + this.showDiscount().subscribe((result: boolean | { id: string, name: string, discount: number }[]) => { if (!!result) { this.bs.discount(result as { id: string, name: string, discount: number }[]); } - }) - ); - } - - discountDialog (canGiveDiscount: boolean): Observable { - if (canGiveDiscount) { - return this.showDiscount(); - } else { - return observableOf(''); - } + }); } billTypeDialog() { @@ -109,16 +119,38 @@ export class SalesHomeComponent implements OnInit { ); } + printBillAllowed(): boolean { + if (!this.auth.hasPermission('Print Bill')) { + return false; + } + if (!this.bs.bill.id) { + return true; + } + if (this.bs.bill.voucherType !== PrintType.Kot && !this.auth.hasPermission('Edit Printed Bill')) { + return false; + } + if (this.bs.bill.isVoid) { + return false; + } + return true; + } + printBill() { if (!this.printBillAllowed()) { return; } - const canGiveDiscount = this.auth.hasPermission('Discount'); let guestBookId = null; if (this.route.snapshot.queryParamMap.has('guest')) { guestBookId = this.route.snapshot.queryParamMap.get('guest'); } - this.discountDialog(canGiveDiscount).pipe( + let discountObservable: Observable = (this.discountAllowed()) ? this.showDiscount() : observableOf(''); + + discountObservable.pipe( + tap((result: boolean | { id: string, name: string, discount: number }[]) => { + if (!!result) { + this.bs.discount(result as { id: string, name: string, discount: number }[]); + } + }), switchMap(() => this.billTypeDialog()), switchMap((x: boolean | PrintType) => { if (!!x) { @@ -136,6 +168,22 @@ export class SalesHomeComponent implements OnInit { }); } + receivePaymentAllowed(): boolean { + if (!this.auth.hasPermission('Settle Bill')) { + return false; + } + if (!this.bs.bill.id) { + return false; + } + if (this.bs.bill.voucherType === PrintType.Kot) { + return false; + } + if (this.bs.bill.isVoid) { + return false; + } + return true; + } + receivePayment() { if (!this.receivePaymentAllowed()) { return; @@ -159,7 +207,20 @@ export class SalesHomeComponent implements OnInit { }); } + moveTableAllowed(): boolean { + if (!this.auth.hasPermission('Move Table') && !this.auth.hasPermission('Merge Tables')) { + return false; + } + if (!this.bs.bill.id) { + return false; + } + return true; + } + moveTable() { + if (!this.moveTableAllowed()) { + return; + } const canMergeTables = this.auth.hasPermission('Merge Tables'); this.dialog.open(TablesDialogComponent, { // width: '750px', @@ -169,7 +230,7 @@ export class SalesHomeComponent implements OnInit { } }).afterClosed().pipe( switchMap((x: boolean | Table) => { - if (!x) { + if (!!x) { return this.confirmTableDialog(x as Table); } else { return throwError('Please choose a table'); @@ -194,7 +255,20 @@ export class SalesHomeComponent implements OnInit { }); } + voidBillAllowed(): boolean { + if (!this.auth.hasPermission('Void Bill')) { + return false; + } + if (!this.bs.bill.id) { + return false; + } + return true; + } + voidBill() { + if (!this.voidBillAllowed()) { + return; + } this.dialog.open(VoidReasonComponent, { // width: '750px' }).afterClosed().pipe( @@ -221,7 +295,20 @@ export class SalesHomeComponent implements OnInit { }); } + splitBillAllowed(): boolean { + if (!this.auth.hasPermission('Split Bill')) { + return false; + } + if (!this.bs.bill.id) { + return false; + } + return true; + } + splitBill() { + if (!this.splitBillAllowed()) { + return; + } this.dialog.open(TablesDialogComponent, { // width: '750px', data: { @@ -251,56 +338,4 @@ export class SalesHomeComponent implements OnInit { this.toaster.show('Error', x); }); } - - discountAllowed(): boolean { - return this.auth.hasPermission('Discount'); - } - - printKotAllowed(): boolean { - if (!this.auth.hasPermission('Print Kot')) { - return false; - } - if (!this.bs.bill.id) { - return true; - } - if (this.bs.bill.voucherType !== PrintType.Kot) { - return false; - } - if (this.bs.bill.isVoid) { - return false; - } - return true; - } - - printBillAllowed(): boolean { - if (!this.auth.hasPermission('Print Bill')) { - return false; - } - if (!this.bs.bill.id) { - return true; - } - if (this.bs.bill.voucherType !== PrintType.Kot && !this.auth.hasPermission('Edit Printed Bill')) { - return false; - } - if (this.bs.bill.isVoid) { - return false; - } - return true; - } - - receivePaymentAllowed(): boolean { - if (!this.auth.hasPermission('Settle Bill')) { - return false; - } - if (!this.bs.bill.id) { - return false; - } - if (this.bs.bill.voucherType === PrintType.Kot) { - return false; - } - if (this.bs.bill.isVoid) { - return false; - } - return true; - } }