Fix: Move table was checking !x instead of !!x and so was not working
Added checks to void bill, split bill and move table
This commit is contained in:
@ -3,6 +3,7 @@ import uuid
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
from pyramid.httpexceptions import HTTPFound
|
||||||
|
|
||||||
from barker.exceptions import ValidationFailure
|
from barker.exceptions import ValidationFailure
|
||||||
from pyramid.response import Response, FileResponse
|
from pyramid.response import Response, FileResponse
|
||||||
@ -17,12 +18,17 @@ def home(request):
|
|||||||
return FileResponse(file, request=request)
|
return FileResponse(file, request=request)
|
||||||
|
|
||||||
|
|
||||||
@forbidden_view_config(renderer='json')
|
@forbidden_view_config()
|
||||||
def forbidden(request):
|
def forbidden(request):
|
||||||
response = Response()
|
if request.accept.quality("application/json") == 1:
|
||||||
response.status_int = 403 if request.authenticated_userid is not None else 401
|
response = Response("Forbidden")
|
||||||
response.content_type = 'application/json'
|
response.status_int = 401
|
||||||
response.json = {'Error': 'Forbidden'}
|
return response
|
||||||
|
else:
|
||||||
|
ret = HTTPFound(
|
||||||
|
location=request.route_url("login", _query={"returnUrl": request.path_qs})
|
||||||
|
)
|
||||||
|
return ret
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,13 +22,16 @@
|
|||||||
[class.disabled]="!receivePaymentAllowed()">
|
[class.disabled]="!receivePaymentAllowed()">
|
||||||
<h3 class="item-name">Receive Payment</h3>
|
<h3 class="item-name">Receive Payment</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple (click)="moveTable()">
|
<mat-card fxLayout="column" class="square-button" matRipple (click)="moveTable()"
|
||||||
|
[class.disabled]="!moveTableAllowed()">
|
||||||
<h3 class="item-name">Move Table</h3>
|
<h3 class="item-name">Move Table</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple (click)="voidBill()">
|
<mat-card fxLayout="column" class="square-button" matRipple (click)="voidBill()"
|
||||||
|
[class.disabled]="!voidBillAllowed()">
|
||||||
<h3 class="item-name">Void Bill</h3>
|
<h3 class="item-name">Void Bill</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple (click)="splitBill()">
|
<mat-card fxLayout="column" class="square-button" matRipple (click)="splitBill()"
|
||||||
|
[class.disabled]="!splitBillAllowed()">
|
||||||
<h3 class="item-name">Split Bill</h3>
|
<h3 class="item-name">Split Bill</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -38,6 +38,22 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
ngOnInit() {
|
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() {
|
printKot() {
|
||||||
if (!this.printKotAllowed()) {
|
if (!this.printKotAllowed()) {
|
||||||
return;
|
return;
|
||||||
@ -52,11 +68,8 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
discount(): void {
|
discountAllowed(): boolean {
|
||||||
if (!this.discountAllowed()) {
|
return this.auth.hasPermission('Discount');
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.showDiscount().subscribe();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showDiscount(): Observable<boolean | { id: string, name: string, discount: number }[]> {
|
showDiscount(): Observable<boolean | { id: string, name: string, discount: number }[]> {
|
||||||
@ -64,21 +77,18 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
// width: '750px',
|
// width: '750px',
|
||||||
data: this.mcSer.listForDiscount()
|
data: this.mcSer.listForDiscount()
|
||||||
});
|
});
|
||||||
return dialogRef.afterClosed().pipe(
|
return dialogRef.afterClosed();
|
||||||
tap((result: boolean | { id: string, name: string, discount: number }[]) => {
|
}
|
||||||
|
|
||||||
|
discount(): void {
|
||||||
|
if (!this.discountAllowed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.showDiscount().subscribe((result: boolean | { id: string, name: string, discount: number }[]) => {
|
||||||
if (!!result) {
|
if (!!result) {
|
||||||
this.bs.discount(result as { id: string, name: string, discount: number }[]);
|
this.bs.discount(result as { id: string, name: string, discount: number }[]);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
discountDialog (canGiveDiscount: boolean): Observable<any> {
|
|
||||||
if (canGiveDiscount) {
|
|
||||||
return this.showDiscount();
|
|
||||||
} else {
|
|
||||||
return observableOf('');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
billTypeDialog() {
|
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() {
|
printBill() {
|
||||||
if (!this.printBillAllowed()) {
|
if (!this.printBillAllowed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const canGiveDiscount = this.auth.hasPermission('Discount');
|
|
||||||
let guestBookId = null;
|
let guestBookId = null;
|
||||||
if (this.route.snapshot.queryParamMap.has('guest')) {
|
if (this.route.snapshot.queryParamMap.has('guest')) {
|
||||||
guestBookId = this.route.snapshot.queryParamMap.get('guest');
|
guestBookId = this.route.snapshot.queryParamMap.get('guest');
|
||||||
}
|
}
|
||||||
this.discountDialog(canGiveDiscount).pipe(
|
let discountObservable: Observable<any> = (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(() => this.billTypeDialog()),
|
||||||
switchMap((x: boolean | PrintType) => {
|
switchMap((x: boolean | PrintType) => {
|
||||||
if (!!x) {
|
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() {
|
receivePayment() {
|
||||||
if (!this.receivePaymentAllowed()) {
|
if (!this.receivePaymentAllowed()) {
|
||||||
return;
|
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() {
|
moveTable() {
|
||||||
|
if (!this.moveTableAllowed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const canMergeTables = this.auth.hasPermission('Merge Tables');
|
const canMergeTables = this.auth.hasPermission('Merge Tables');
|
||||||
this.dialog.open(TablesDialogComponent, {
|
this.dialog.open(TablesDialogComponent, {
|
||||||
// width: '750px',
|
// width: '750px',
|
||||||
@ -169,7 +230,7 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}).afterClosed().pipe(
|
}).afterClosed().pipe(
|
||||||
switchMap((x: boolean | Table) => {
|
switchMap((x: boolean | Table) => {
|
||||||
if (!x) {
|
if (!!x) {
|
||||||
return this.confirmTableDialog(x as Table);
|
return this.confirmTableDialog(x as Table);
|
||||||
} else {
|
} else {
|
||||||
return throwError('Please choose a table');
|
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() {
|
voidBill() {
|
||||||
|
if (!this.voidBillAllowed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.dialog.open(VoidReasonComponent, {
|
this.dialog.open(VoidReasonComponent, {
|
||||||
// width: '750px'
|
// width: '750px'
|
||||||
}).afterClosed().pipe(
|
}).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() {
|
splitBill() {
|
||||||
|
if (!this.splitBillAllowed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.dialog.open(TablesDialogComponent, {
|
this.dialog.open(TablesDialogComponent, {
|
||||||
// width: '750px',
|
// width: '750px',
|
||||||
data: {
|
data: {
|
||||||
@ -251,56 +338,4 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
this.toaster.show('Error', x);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user