64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { Table } from '../../core/table';
|
|
import { ToasterService } from '../../core/toaster.service';
|
|
import { BillNumberComponent } from '../bill-number/bill-number.component';
|
|
|
|
@Component({
|
|
selector: 'app-running-tables',
|
|
templateUrl: './running-tables.component.html',
|
|
styleUrls: ['./running-tables.component.css'],
|
|
})
|
|
export class RunningTablesComponent implements OnInit {
|
|
list: Table[] = [];
|
|
|
|
constructor(
|
|
private dialog: MatDialog,
|
|
private router: Router,
|
|
private route: ActivatedRoute,
|
|
private toaster: ToasterService,
|
|
) {}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { list: Table[] };
|
|
this.list = data.list;
|
|
});
|
|
}
|
|
|
|
navigateToBill(table: Table): void {
|
|
const qp = { table: table.id };
|
|
if (table.voucherId) {
|
|
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
Object.assign(qp, { voucher: table.voucherId });
|
|
}
|
|
const navigationExtras: NavigationExtras = {
|
|
queryParams: qp,
|
|
queryParamsHandling: 'merge',
|
|
preserveFragment: true,
|
|
};
|
|
this.router.navigate(['/sales', 'bill'], navigationExtras);
|
|
}
|
|
|
|
openBill() {
|
|
return this.dialog
|
|
.open(BillNumberComponent)
|
|
.afterClosed()
|
|
.pipe(
|
|
map((x) => {
|
|
if (x === undefined || x === false) {
|
|
throw new Error('Invalid Bill Number');
|
|
}
|
|
return x;
|
|
}),
|
|
)
|
|
.subscribe(
|
|
(x) => this.router.navigate(['/sales', 'bill'], { queryParams: { bill: x } }),
|
|
(x) => this.toaster.show('Error', x),
|
|
);
|
|
}
|
|
}
|