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:
Amritanshu
2019-08-21 17:02:06 +05:30
parent ee54e36dda
commit 04fb6dfcab
3 changed files with 124 additions and 80 deletions

View File

@ -22,13 +22,16 @@
[class.disabled]="!receivePaymentAllowed()">
<h3 class="item-name">Receive Payment</h3>
</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>
</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>
</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>
</mat-card>
</div>

View File

@ -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<boolean | { id: string, name: string, discount: number }[]> {
@ -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<any> {
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<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((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;
}
}