Move / Merge KOT Done.

We need to check if it is the only kot and raise an error if it is.
Split Bill Done
This commit is contained in:
Amritanshu
2019-08-18 01:05:59 +05:30
parent dcaf23b390
commit e697631cd4
15 changed files with 539 additions and 295 deletions

View File

@ -24,10 +24,7 @@
<mat-card fxLayout="column" class="square-button" matRipple (click)="voidBill()">
<h3 class="item-name">Void Bill</h3>
</mat-card>
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['../../tables']">
<h3 class="item-name">Move KOT</h3>
</mat-card>
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['../../tables']">
<mat-card fxLayout="column" class="square-button" matRipple (click)="splitBill()">
<h3 class="item-name">Split Bill</h3>
</mat-card>
</div>

View File

@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
import { concatMap, map, switchMap, tap } from 'rxjs/operators';
import { iif, Observable, of as observableOf, throwError } from 'rxjs';
import { map, switchMap, tap } from 'rxjs/operators';
import { Observable, of as observableOf, throwError } from 'rxjs';
import { BillService } from '../bill.service';
import { ToasterService } from '../../core/toaster.service';
import { DiscountComponent } from '../discount/discount.component';
@ -70,13 +70,11 @@ export class SalesHomeComponent implements OnInit {
}
discountDialog (canGiveDiscount: boolean): Observable<any> {
let discObs = null;
if (canGiveDiscount) {
return discObs = this.showDiscount();
return this.showDiscount();
} else {
return discObs = observableOf('');
return observableOf('');
}
}
billTypeDialog() {
@ -89,10 +87,10 @@ export class SalesHomeComponent implements OnInit {
);
}
confirmMoveTableDialog(table: Table): Observable<{table: Table, confirmed: boolean}> {
confirmTableDialog(table: Table): Observable<{table: Table, confirmed: boolean}> {
return this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Move Table?', content: 'Are you sure?'}
data: {title: 'Select Table?', content: 'Are you sure?'}
}).afterClosed().pipe(
map ((x: boolean) => ({table: table, confirmed: x}))
);
@ -114,20 +112,19 @@ export class SalesHomeComponent implements OnInit {
guestBookId = this.route.snapshot.queryParamMap.get('guest');
}
this.discountDialog(canGiveDiscount).pipe(
concatMap(() => this.billTypeDialog())
).pipe(
concatMap(
(x: boolean | PrintType) => iif(
() => !!x,
this.bs.printBill(guestBookId, x as PrintType),
throwError(x)
)
),
switchMap(() => this.billTypeDialog()),
switchMap((x: boolean | PrintType) => {
if (!!x) {
return this.bs.printBill(guestBookId, x as PrintType);
} else {
return throwError(x);
}
}),
).subscribe(() => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
},
x => {
() => {
this.toaster.show('Error', 'No Bill Type Chosen');
});
}
@ -153,29 +150,32 @@ export class SalesHomeComponent implements OnInit {
}
moveTable() {
const canMergeTables = this.auth.hasPermission("Merge Tables");
this.dialog.open(TablesDialogComponent, {
// width: '750px',
data: {
list: this.tSer.running(),
canChooseRunning: false
canChooseRunning: canMergeTables
}
}).afterClosed().pipe(
switchMap((x: boolean | Table) => {
if (!!x) {
return this.confirmMoveTableDialog(x as Table);
if (!x) {
return this.confirmTableDialog(x as Table);
} else {
return throwError('Please choose a table');
}
}),
switchMap((value: { table: Table, confirmed: boolean }, index: number) => {
if (!!value.confirmed) {
return this.bs.moveTable(value.table);
} else {
if (!value.confirmed) {
return throwError('Please confirm move');
} else if (value.table.status) {
return this.bs.mergeTable(value.table);
} else {
return this.bs.moveTable(value.table);
}
}
)
).subscribe((x) => {
).subscribe(() => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
},
@ -210,4 +210,35 @@ export class SalesHomeComponent implements OnInit {
this.toaster.show('Error', x);
});
}
splitBill() {
this.dialog.open(TablesDialogComponent, {
// width: '750px',
data: {
list: this.tSer.running(),
canChooseRunning: false
}
}).afterClosed().pipe(
switchMap((x: boolean | Table) => {
if (!!x) {
return this.confirmTableDialog(x as Table);
} else {
return throwError('Please choose a table');
}
}),
switchMap((value: { table: Table, confirmed: boolean }, index: number) => {
if (!value.confirmed) {
return throwError('Please confirm split');
} else {
return this.bs.splitBill(value.table);
}
})
).subscribe((x) => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
},
x => {
this.toaster.show('Error', x);
});
}
}