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:
@ -13,6 +13,10 @@ table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mat-column-select{
|
||||
flex: 0 0 50px;
|
||||
}
|
||||
|
||||
.grey900 {
|
||||
background-color: #1b5e20;
|
||||
color: #ffffff;
|
||||
|
||||
@ -8,6 +8,22 @@
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<table mat-table #table [dataSource]="dataSource" aria-label="Elements" class="mat-elevation-z8">
|
||||
<!-- Checkbox Column -->
|
||||
<ng-container matColumnDef="select">
|
||||
<mat-cell *matCellDef="let row">
|
||||
<mat-checkbox *ngIf="row.oldKot"
|
||||
(change)="$event ? masterToggle(row) : null"
|
||||
[checked]="bs.selection.hasValue() && isAllSelected(row)"
|
||||
[indeterminate]="isAnySelected(row)">
|
||||
</mat-checkbox>
|
||||
<mat-checkbox *ngIf="!row.isKot" [disabled]="!row.id"
|
||||
(click)="$event.stopPropagation()"
|
||||
(change)="$event ? bs.selection.toggle(row) : null"
|
||||
[checked]="bs.selection.isSelected(row)">
|
||||
</mat-checkbox>
|
||||
</mat-cell>
|
||||
<mat-footer-cell *matFooterCellDef class="grey900">Amount</mat-footer-cell>
|
||||
</ng-container>
|
||||
<!-- Info Column -->
|
||||
<ng-container matColumnDef="info">
|
||||
<mat-cell *matCellDef="let row" [class.blue800]="row.newKot">
|
||||
@ -18,7 +34,7 @@
|
||||
<li *ngFor="let m of row.modifiers">{{m.name}}</li>
|
||||
</ul>
|
||||
</mat-cell>
|
||||
<mat-footer-cell *matFooterCellDef class="grey900 bold">Amount</mat-footer-cell>
|
||||
<mat-footer-cell *matFooterCellDef class="grey900 bold"></mat-footer-cell>
|
||||
</ng-container>
|
||||
<!-- Quantity Column -->
|
||||
<ng-container matColumnDef="quantity">
|
||||
@ -39,7 +55,7 @@
|
||||
<button mat-icon-button (click)="modifier(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
|
||||
<mat-icon class="del">assignment</mat-icon>
|
||||
</button>
|
||||
<button mat-icon-button (click)="modifier(row)" [disabled]="row.newKot" *ngIf="row.isKot">
|
||||
<button mat-icon-button (click)="moveKot(row)" [disabled]="row.newKot" *ngIf="row.isKot">
|
||||
<mat-icon class="del">open_in_new</mat-icon>
|
||||
</button>
|
||||
</mat-cell>
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ const httpOptions = {
|
||||
};
|
||||
|
||||
const url = '/v1/vouchers';
|
||||
const urlMoveTable = '/v1/move-table';
|
||||
const urlMoveKot = '/v1/move-kot';
|
||||
const serviceName = 'VoucherService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@ -47,29 +49,29 @@ export class VoucherService {
|
||||
);
|
||||
}
|
||||
|
||||
save(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
|
||||
save(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('p', printType).set('u', updateTable.toString())};
|
||||
if (guest_book_id !== null) {
|
||||
options.params = options.params.set('g', guest_book_id);
|
||||
}
|
||||
return <Observable<Bill>>this.http.post<Bill>(`${url}/new`, voucher, options)
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${url}/new`, voucher, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
|
||||
update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('p', printType).set('u', updateTable.toString())};
|
||||
if (guest_book_id !== null) {
|
||||
options.params = options.params.set('g', guest_book_id);
|
||||
}
|
||||
return <Observable<Bill>>this.http.put<Bill>(`${url}/${voucher.id}`, voucher, options)
|
||||
return <Observable<boolean>>this.http.put<boolean>(`${url}/${voucher.id}`, voucher, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
|
||||
saveOrUpdate(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
|
||||
if (!voucher.id) {
|
||||
return this.save(voucher, printType, guest_book_id, updateTable);
|
||||
} else {
|
||||
@ -78,26 +80,75 @@ export class VoucherService {
|
||||
}
|
||||
|
||||
receivePayment(id: string, amounts: { id: string; name: string; amount: number }[], updateTable: boolean): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('receive-payment', '').set('u', updateTable.toString())};
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, amounts, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'receivePayment'))
|
||||
);
|
||||
}
|
||||
|
||||
moveTable(id: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('move-table', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, {table: {id: table.id}}, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'moveTable'))
|
||||
);
|
||||
const options = {params: new HttpParams().set('receive-payment', '').set('u', updateTable.toString())};
|
||||
return <Observable<boolean>>this.http.post<boolean>(
|
||||
`${url}/${id}`, amounts, options
|
||||
).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'receivePayment'))
|
||||
);
|
||||
}
|
||||
|
||||
voidBill(id: string, reason: string, updateTable: boolean): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('void-bill', '').set('u', updateTable.toString())};
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, {reason: reason}, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'voidBill'))
|
||||
);
|
||||
const options = {params: new HttpParams().set('void-bill', '').set('u', updateTable.toString())};
|
||||
return <Observable<boolean>>this.http.post<boolean>(
|
||||
`${url}/${id}`, {reason: reason}, options
|
||||
).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'voidBill'))
|
||||
);
|
||||
}
|
||||
|
||||
moveTable(id: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('move', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
|
||||
voucher: {id: id},
|
||||
table: {id: table.id}
|
||||
}, options).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'moveTable'))
|
||||
);
|
||||
}
|
||||
|
||||
mergeTable(id: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('merge', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
|
||||
voucher: {id: id},
|
||||
table: {id: table.id},
|
||||
newVoucher: {id: table.voucherId}
|
||||
}, options).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'mergeTable'))
|
||||
);
|
||||
}
|
||||
|
||||
moveKotToNewTable(id: string, kotId: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('move', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
|
||||
voucher: {id: id},
|
||||
kot: {id: kotId},
|
||||
table: {id: table.id}
|
||||
}, options).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'moveKotToNewTable'))
|
||||
);
|
||||
}
|
||||
|
||||
mergeKotWithOldBill(id: string, kotId: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('merge', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
|
||||
voucher: {id: id},
|
||||
kot: {id: kotId},
|
||||
table: {id: table.id},
|
||||
newVoucher: {id: table.voucherId}
|
||||
}, options).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'mergeKotWithOldBill'))
|
||||
);
|
||||
}
|
||||
|
||||
splitBill(id: string, inventoriesToMove: string[], table: Table) {
|
||||
const options = {params: new HttpParams().set('split-bill', '').set('u', 'true')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, {
|
||||
voucher: {id: id},
|
||||
inventories: inventoriesToMove,
|
||||
table: {id: table.id}
|
||||
}, options).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'splitBill'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user