Blacked and isorted the python files
Prettied and eslinted the typescript/html files
This commit is contained in:
@ -1,24 +1,27 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { Bill, Kot } from './bill';
|
||||
import { BillsDataSource } from './bills-datasource';
|
||||
import { BillService } from '../bill.service';
|
||||
import { QuantityComponent } from '../quantity/quantity.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { Table } from '../../core/table';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
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';
|
||||
|
||||
import { AuthService } from '../../auth/auth.service';
|
||||
import { Table } from '../../core/table';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { TableService } from '../../tables/table.service';
|
||||
import { BillService } from '../bill.service';
|
||||
import { PaxComponent } from '../pax/pax.component';
|
||||
import { QuantityComponent } from '../quantity/quantity.component';
|
||||
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
|
||||
|
||||
import { Bill } from './bill';
|
||||
import { BillsDataSource } from './bills-datasource';
|
||||
import { Kot } from './kot';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bills',
|
||||
templateUrl: './bills.component.html',
|
||||
styleUrls: ['./bills.component.css']
|
||||
styleUrls: ['./bills.component.css'],
|
||||
})
|
||||
export class BillsComponent implements OnInit {
|
||||
dataSource: BillsDataSource;
|
||||
@ -32,15 +35,13 @@ export class BillsComponent implements OnInit {
|
||||
private toaster: ToasterService,
|
||||
private auth: AuthService,
|
||||
public bs: BillService,
|
||||
private tSer: TableService
|
||||
) {
|
||||
}
|
||||
private tSer: TableService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Bill }) => {
|
||||
this.bs.loadData(data.item);
|
||||
});
|
||||
this.route.data.subscribe((data: { item: Bill }) => {
|
||||
this.bs.loadData(data.item);
|
||||
});
|
||||
this.getPax();
|
||||
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
||||
}
|
||||
@ -51,7 +52,7 @@ export class BillsComponent implements OnInit {
|
||||
}
|
||||
const dialogRef = this.dialog.open(PaxComponent, {
|
||||
// width: '750px',
|
||||
data: this.bs.bill.pax
|
||||
data: this.bs.bill.pax,
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean | number) => {
|
||||
@ -61,36 +62,34 @@ export class BillsComponent implements OnInit {
|
||||
this.bs.bill.pax = result as number;
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
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 = 0,
|
||||
found = 0;
|
||||
this.bs.data.filter(
|
||||
x => x.kotId === kot.id
|
||||
).forEach((c: any) => {
|
||||
total += 1;
|
||||
if (this.bs.selection.isSelected(c)) {
|
||||
found += 1;
|
||||
}
|
||||
});
|
||||
let total = 0;
|
||||
let found = 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)
|
||||
);
|
||||
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 {
|
||||
@ -100,7 +99,7 @@ export class BillsComponent implements OnInit {
|
||||
quantity(item: any): void {
|
||||
const dialogRef = this.dialog.open(QuantityComponent, {
|
||||
// width: '750px',
|
||||
data: item.quantity
|
||||
data: item.quantity,
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean | number) => {
|
||||
@ -123,47 +122,53 @@ export class BillsComponent implements OnInit {
|
||||
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}))
|
||||
);
|
||||
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, confirmed: x })));
|
||||
}
|
||||
|
||||
moveKot(kot: Kot) {
|
||||
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') !== -1);
|
||||
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 {
|
||||
const canMergeTables = this.auth.user.perms.indexOf('merge-tables') !== -1;
|
||||
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);
|
||||
}
|
||||
return throwError('Please choose a table');
|
||||
}
|
||||
}),
|
||||
switchMap((value: { table: Table, confirmed: boolean }, index: number) => {
|
||||
}),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (value.table.status) {
|
||||
return this.bs.mergeKot(kot.id, value.table);
|
||||
}
|
||||
return this.bs.moveKot(kot.id, value.table);
|
||||
}),
|
||||
)
|
||||
).subscribe((x) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/sales']);
|
||||
},
|
||||
x => {
|
||||
this.toaster.show('Error', x);
|
||||
});
|
||||
.subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/sales']);
|
||||
},
|
||||
(x) => {
|
||||
this.toaster.show('Error', x);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user