2019-06-19 18:25:42 +00:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2019-08-10 20:07:14 +00:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { Bill, Kot } from './bill';
|
2019-07-13 16:02:18 +00:00
|
|
|
import { BillsDataSource } from './bills-datasource';
|
|
|
|
import { BillService } from '../bill.service';
|
|
|
|
import { QuantityComponent } from '../quantity/quantity.component';
|
2020-06-14 13:13:10 +00:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2019-08-10 20:07:14 +00:00
|
|
|
import { Table } from '../../core/table';
|
|
|
|
import { Observable, throwError } from 'rxjs';
|
|
|
|
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
|
|
|
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';
|
2019-08-20 17:32:17 +00:00
|
|
|
import { AuthService } from '../../auth/auth.service';
|
2020-09-24 03:17:09 +00:00
|
|
|
import { PaxComponent } from '../pax/pax.component';
|
2019-06-19 18:25:42 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-bills',
|
|
|
|
templateUrl: './bills.component.html',
|
|
|
|
styleUrls: ['./bills.component.css']
|
|
|
|
})
|
|
|
|
export class BillsComponent implements OnInit {
|
2019-07-11 06:47:41 +00:00
|
|
|
dataSource: BillsDataSource;
|
|
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
2019-08-17 19:35:59 +00:00
|
|
|
displayedColumns: string[] = ['select', 'info', 'quantity'];
|
2019-06-19 18:25:42 +00:00
|
|
|
|
2019-07-11 06:47:41 +00:00
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
2019-08-10 20:07:14 +00:00
|
|
|
private router: Router,
|
2019-07-13 16:02:18 +00:00
|
|
|
private dialog: MatDialog,
|
2019-08-10 20:07:14 +00:00
|
|
|
private toaster: ToasterService,
|
2019-08-17 19:35:59 +00:00
|
|
|
private auth: AuthService,
|
2019-08-10 20:07:14 +00:00
|
|
|
private bs: BillService,
|
|
|
|
private tSer: TableService
|
2019-07-11 06:47:41 +00:00
|
|
|
) {
|
2019-06-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.data
|
2019-07-11 06:47:41 +00:00
|
|
|
.subscribe((data: { item: Bill }) => {
|
2019-07-13 16:02:18 +00:00
|
|
|
this.bs.loadData(data.item);
|
2019-06-19 18:25:42 +00:00
|
|
|
});
|
2019-08-26 09:41:28 +00:00
|
|
|
this.getPax();
|
2019-07-13 16:02:18 +00:00
|
|
|
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
2019-07-11 06:47:41 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 09:41:28 +00:00
|
|
|
getPax(): void {
|
2020-09-24 03:17:09 +00:00
|
|
|
if (this.bs.bill.id || this.bs.bill.customer) {
|
|
|
|
return;
|
2019-08-26 09:41:28 +00:00
|
|
|
}
|
|
|
|
const dialogRef = this.dialog.open(PaxComponent, {
|
|
|
|
// width: '750px',
|
|
|
|
data: this.bs.bill.pax
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe((result: boolean | number) => {
|
|
|
|
if (!result) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.bs.bill.pax = result as number;
|
|
|
|
});
|
|
|
|
}
|
2019-08-17 19:35:59 +00:00
|
|
|
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) {
|
2019-08-20 17:32:17 +00:00
|
|
|
let total = 0,
|
|
|
|
found = 0;
|
2019-08-17 19:35:59 +00:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-11 06:47:41 +00:00
|
|
|
addOne(item: any): void {
|
|
|
|
this.bs.addOne(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
quantity(item: any): void {
|
2019-07-13 16:02:18 +00:00
|
|
|
const dialogRef = this.dialog.open(QuantityComponent, {
|
|
|
|
// width: '750px',
|
|
|
|
data: item.quantity
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe((result: boolean | number) => {
|
|
|
|
if (!result) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.bs.quantity(item, result as number);
|
|
|
|
});
|
2019-07-11 06:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
subtractOne(item: any): void {
|
|
|
|
this.bs.subtractOne(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeItem(item: any): void {
|
|
|
|
this.bs.removeItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
modifier(item: any): void {
|
|
|
|
this.bs.modifier(item);
|
2019-06-19 18:25:42 +00:00
|
|
|
}
|
2019-08-17 19:35:59 +00:00
|
|
|
|
|
|
|
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) {
|
2020-09-25 03:18:50 +00:00
|
|
|
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') !== -1);
|
2019-08-17 19:35:59 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2019-06-19 18:25:42 +00:00
|
|
|
}
|