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:
@ -12,6 +12,8 @@ import { map, switchMap } from 'rxjs/operators';
|
||||
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
|
||||
import { TableService } from '../../tables/table.service';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { AuthService } from "../../auth/auth.service";
|
||||
import { SelectionModel } from "@angular/cdk/collections";
|
||||
|
||||
@Component({
|
||||
selector: 'app-bills',
|
||||
@ -22,13 +24,14 @@ export class BillsComponent implements OnInit {
|
||||
dataSource: BillsDataSource;
|
||||
item: Bill;
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns: string[] = ['info', 'quantity'];
|
||||
displayedColumns: string[] = ['select', 'info', 'quantity'];
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private toaster: ToasterService,
|
||||
private auth: AuthService,
|
||||
private bs: BillService,
|
||||
private tSer: TableService
|
||||
) {
|
||||
@ -43,6 +46,38 @@ export class BillsComponent implements OnInit {
|
||||
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
||||
}
|
||||
|
||||
isAllSelected(kot: Kot) {
|
||||
return this.bs.data.filter(
|
||||
x => x.kotId === kot.id
|
||||
).reduce(
|
||||
(p: boolean, c: any) => p && this.bs.selection.isSelected(c)
|
||||
, true
|
||||
);
|
||||
}
|
||||
|
||||
isAnySelected(kot: Kot) {
|
||||
let total: number = 0,
|
||||
found: number = 0;
|
||||
this.bs.data.filter(
|
||||
x => x.kotId === kot.id
|
||||
).forEach((c: any) => {
|
||||
total += 1;
|
||||
if (this.bs.selection.isSelected(c)) {
|
||||
found += 1;
|
||||
}
|
||||
});
|
||||
return found > 0 && found < total;
|
||||
}
|
||||
|
||||
masterToggle(kot: Kot) {
|
||||
const isAllSelected = this.isAllSelected(kot);
|
||||
this.bs.data.filter(
|
||||
x => x.kotId === kot.id
|
||||
).forEach(
|
||||
row => isAllSelected ? this.bs.selection.deselect(row) : this.bs.selection.select(row)
|
||||
);
|
||||
}
|
||||
|
||||
addOne(item: any): void {
|
||||
this.bs.addOne(item);
|
||||
}
|
||||
@ -72,4 +107,48 @@ export class BillsComponent implements OnInit {
|
||||
modifier(item: any): void {
|
||||
this.bs.modifier(item);
|
||||
}
|
||||
|
||||
confirmMoveKotDialog(table: Table): Observable<{table: Table, confirmed: boolean}> {
|
||||
return this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Move KOT?', content: 'Are you sure?'}
|
||||
}).afterClosed().pipe(
|
||||
map ((x: boolean) => ({table: table, confirmed: x}))
|
||||
);
|
||||
}
|
||||
|
||||
moveKot(kot: Kot) {
|
||||
const canMergeTables = this.auth.hasPermission("Merge Tables");
|
||||
this.dialog.open(TablesDialogComponent, {
|
||||
// width: '750px',
|
||||
data: {
|
||||
list: this.tSer.running(),
|
||||
canChooseRunning: canMergeTables
|
||||
}
|
||||
}).afterClosed().pipe(
|
||||
switchMap((x: boolean | Table) => {
|
||||
if (!!x) {
|
||||
return this.confirmMoveKotDialog(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 move');
|
||||
} else if (value.table.status) {
|
||||
return this.bs.mergeKot(kot.id, value.table);
|
||||
} else {
|
||||
return this.bs.moveKot(kot.id, value.table);
|
||||
}
|
||||
}
|
||||
)
|
||||
).subscribe((x) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/sales']);
|
||||
},
|
||||
x => {
|
||||
this.toaster.show('Error', x);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user