Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@ -12,7 +12,7 @@ export class BillResolver implements Resolve<Bill> {
|
||||
constructor(private ser: VoucherService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<Bill> {
|
||||
const tableId = route.queryParamMap.get('table');
|
||||
const tableId = route.queryParamMap.get('table') as string;
|
||||
const guestId = route.queryParamMap.get('guest');
|
||||
const voucherId = route.queryParamMap.get('voucher');
|
||||
return this.ser.getFromTable(tableId, voucherId, guestId);
|
||||
|
||||
@ -5,7 +5,7 @@ import { GuestBook } from '../../guest-book/guest-book';
|
||||
import { Kot } from './kot';
|
||||
|
||||
export class Bill {
|
||||
id: string;
|
||||
id: string | undefined;
|
||||
date: string;
|
||||
pax: number;
|
||||
customer?: { id: string; name: string };
|
||||
@ -13,17 +13,45 @@ export class Bill {
|
||||
creationDate: string;
|
||||
lastEditDate: string;
|
||||
billId: string;
|
||||
kotId: string;
|
||||
table: Table;
|
||||
guest: GuestBook;
|
||||
settlements: any[];
|
||||
void: boolean;
|
||||
voidReason: string;
|
||||
voucherType: string;
|
||||
serial: number;
|
||||
kots: Kot[];
|
||||
reprints: any[];
|
||||
|
||||
get dateTip(): string {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
get creationDateTip(): string {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
get lastEditDateTip(): string {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public constructor(init?: Partial<Bill>) {
|
||||
this.id = undefined;
|
||||
this.date = '';
|
||||
this.pax = 0;
|
||||
this.user = new User();
|
||||
this.creationDate = '';
|
||||
this.lastEditDate = '';
|
||||
this.billId = '';
|
||||
this.kotId = '';
|
||||
this.table = new Table();
|
||||
this.guest = new GuestBook();
|
||||
this.settlements = [];
|
||||
this.voidReason = '';
|
||||
this.voucherType = '';
|
||||
this.serial = 0;
|
||||
this.kots = [];
|
||||
this.reprints = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { BillsComponent } from './bills.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('BillsComponent', () => {
|
||||
let component: BillsComponent;
|
||||
let fixture: ComponentFixture<BillsComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [BillsComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [BillsComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(BillsComponent);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { AuthService } from '../../auth/auth.service';
|
||||
@ -17,6 +17,7 @@ import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component'
|
||||
import { Bill } from './bill';
|
||||
import { BillsDataSource } from './bills-datasource';
|
||||
import { Kot } from './kot';
|
||||
import { VoucherType } from './voucher-type';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bills',
|
||||
@ -24,7 +25,7 @@ import { Kot } from './kot';
|
||||
styleUrls: ['./bills.component.css'],
|
||||
})
|
||||
export class BillsComponent implements OnInit {
|
||||
dataSource: BillsDataSource;
|
||||
dataSource: BillsDataSource = new BillsDataSource(this.bs.dataObs);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns: string[] = ['select', 'info', 'quantity'];
|
||||
|
||||
@ -39,7 +40,8 @@ export class BillsComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { item: Bill }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: Bill };
|
||||
this.bs.loadData(data.item);
|
||||
});
|
||||
this.getPax();
|
||||
@ -122,7 +124,7 @@ export class BillsComponent implements OnInit {
|
||||
}
|
||||
|
||||
subtractOne(item: any): void {
|
||||
const canEdit = this.auth.user.perms.indexOf('edit-printed-product') !== -1;
|
||||
const canEdit = this.auth.allowed('edit-printed-product');
|
||||
this.bs.subtractOne(item, canEdit);
|
||||
}
|
||||
|
||||
@ -134,14 +136,21 @@ export class BillsComponent implements OnInit {
|
||||
this.bs.modifier(item);
|
||||
}
|
||||
|
||||
confirmMoveKotDialog(table: Table): Observable<Table | Observable<never>> {
|
||||
confirmMoveKotDialog(table: Table): Observable<Table> {
|
||||
return this.dialog
|
||||
.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: { title: 'Move KOT?', content: 'Are you sure?' },
|
||||
})
|
||||
.afterClosed()
|
||||
.pipe(map((x: boolean) => (x ? table : throwError('Please confirm move'))));
|
||||
.pipe(
|
||||
map((x: boolean) => {
|
||||
if (!x) {
|
||||
throw new Error('Please confirm move');
|
||||
}
|
||||
return table;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
chooseTable(allowMerge: boolean): Observable<Table> {
|
||||
@ -154,11 +163,18 @@ export class BillsComponent implements OnInit {
|
||||
},
|
||||
})
|
||||
.afterClosed()
|
||||
.pipe(map((x) => x || throwError('Please choose a table')));
|
||||
.pipe(
|
||||
map((x: Table) => {
|
||||
if (!x) {
|
||||
throw new Error('Please choose a table');
|
||||
}
|
||||
return x;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
moveKot(kot: Kot) {
|
||||
const canMergeTables = this.auth.user.perms.indexOf('merge-tables') !== -1;
|
||||
const canMergeTables = this.auth.allowed('merge-tables');
|
||||
this.chooseTable(canMergeTables)
|
||||
.pipe(
|
||||
switchMap((table: Table) => this.confirmMoveKotDialog(table)),
|
||||
@ -170,9 +186,9 @@ export class BillsComponent implements OnInit {
|
||||
return this.bs.moveTable(table);
|
||||
}
|
||||
if (table.status) {
|
||||
return this.bs.mergeKot(kot.id, table);
|
||||
return this.bs.mergeKot(kot.id as string, table);
|
||||
}
|
||||
return this.bs.moveKot(kot.id, table);
|
||||
return this.bs.moveKot(kot.id as string, table);
|
||||
}),
|
||||
)
|
||||
.subscribe(
|
||||
@ -190,10 +206,10 @@ export class BillsComponent implements OnInit {
|
||||
if (!row.isPrinted) {
|
||||
return false;
|
||||
}
|
||||
if (this.bs.bill.isVoid) {
|
||||
if (this.bs.bill.voucherType === VoucherType.Void) {
|
||||
return true;
|
||||
}
|
||||
if (this.auth.user.perms.indexOf('edit-printed-product') === -1) {
|
||||
if (!this.auth.allowed('edit-printed-product')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -3,7 +3,7 @@ import { Product } from '../../core/product';
|
||||
import { Tax } from '../../core/tax';
|
||||
|
||||
export class Inventory {
|
||||
id: string;
|
||||
id: string | undefined;
|
||||
product: Product;
|
||||
quantity: number;
|
||||
price: number;
|
||||
@ -15,6 +15,16 @@ export class Inventory {
|
||||
sortOrder: number;
|
||||
|
||||
public constructor(init?: Partial<Inventory>) {
|
||||
this.id = undefined;
|
||||
this.product = new Product();
|
||||
this.quantity = 0;
|
||||
this.price = 0;
|
||||
this.isHappyHour = false;
|
||||
this.taxRate = 0;
|
||||
this.tax = new Tax();
|
||||
this.discount = 0;
|
||||
this.modifiers = [];
|
||||
this.sortOrder = 0;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,13 +3,18 @@ import { User } from '../../core/user';
|
||||
import { Inventory } from './inventory';
|
||||
|
||||
export class Kot {
|
||||
id: string;
|
||||
id: string | undefined;
|
||||
code: number;
|
||||
date: string;
|
||||
user: User;
|
||||
inventories: Inventory[];
|
||||
|
||||
public constructor(init?: Partial<Kot>) {
|
||||
this.id = undefined;
|
||||
this.code = 0;
|
||||
this.date = '';
|
||||
this.user = new User();
|
||||
this.inventories = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
export enum PrintType {
|
||||
export enum VoucherType {
|
||||
Kot = 'KOT',
|
||||
Bill = 'REGULAR_BILL',
|
||||
NoCharge = 'NO_CHARGE',
|
||||
Staff = 'STAFF',
|
||||
Void = 'VOID',
|
||||
}
|
||||
@ -7,7 +7,7 @@ import { ErrorLoggerService } from '../../core/error-logger.service';
|
||||
import { Table } from '../../core/table';
|
||||
|
||||
import { Bill } from './bill';
|
||||
import { PrintType } from './print-type';
|
||||
import { VoucherType } from './voucher-type';
|
||||
|
||||
const url = '/api/voucher';
|
||||
const urlMoveTable = '/api/move-table';
|
||||
@ -27,7 +27,11 @@ export class VoucherService {
|
||||
);
|
||||
}
|
||||
|
||||
getFromTable(tableId: string, voucherId: string, guestId: string): Observable<Bill> {
|
||||
getFromTable(
|
||||
tableId: string,
|
||||
voucherId: string | null,
|
||||
guestId: string | null,
|
||||
): Observable<Bill> {
|
||||
let params = new HttpParams();
|
||||
if (voucherId !== null) {
|
||||
params = params.set('v', voucherId);
|
||||
@ -50,15 +54,15 @@ export class VoucherService {
|
||||
|
||||
save(
|
||||
voucher: Bill,
|
||||
printType: PrintType,
|
||||
guest_book_id: string,
|
||||
voucherType: VoucherType,
|
||||
guestBookId: string | null,
|
||||
updateTable: boolean,
|
||||
): Observable<boolean> {
|
||||
const options = {
|
||||
params: new HttpParams().set('p', printType).set('u', updateTable.toString()),
|
||||
params: new HttpParams().set('p', voucherType).set('u', updateTable.toString()),
|
||||
};
|
||||
if (guest_book_id !== null) {
|
||||
options.params = options.params.set('g', guest_book_id);
|
||||
if (guestBookId !== null) {
|
||||
options.params = options.params.set('g', guestBookId);
|
||||
}
|
||||
return <Observable<boolean>>(
|
||||
this.http
|
||||
@ -69,15 +73,15 @@ export class VoucherService {
|
||||
|
||||
update(
|
||||
voucher: Bill,
|
||||
printType: PrintType,
|
||||
guest_book_id: string,
|
||||
voucherType: VoucherType,
|
||||
guestBookId: string | null,
|
||||
updateTable: boolean,
|
||||
): Observable<boolean> {
|
||||
const options = {
|
||||
params: new HttpParams().set('p', printType).set('u', updateTable.toString()),
|
||||
params: new HttpParams().set('p', voucherType).set('u', updateTable.toString()),
|
||||
};
|
||||
if (guest_book_id !== null) {
|
||||
options.params = options.params.set('g', guest_book_id);
|
||||
if (guestBookId !== null) {
|
||||
options.params = options.params.set('g', guestBookId);
|
||||
}
|
||||
return <Observable<boolean>>(
|
||||
this.http
|
||||
@ -88,13 +92,13 @@ export class VoucherService {
|
||||
|
||||
change(
|
||||
voucher: Bill,
|
||||
printType: PrintType,
|
||||
guest_book_id: string,
|
||||
voucherType: VoucherType,
|
||||
guestBookId: string | null,
|
||||
updateTable: boolean,
|
||||
): Observable<boolean> {
|
||||
const options = { params: new HttpParams().set('u', updateTable.toString()) };
|
||||
if (guest_book_id !== null) {
|
||||
options.params = options.params.set('g', guest_book_id);
|
||||
if (guestBookId !== null) {
|
||||
options.params = options.params.set('g', guestBookId);
|
||||
}
|
||||
return <Observable<boolean>>(
|
||||
this.http
|
||||
@ -105,17 +109,17 @@ export class VoucherService {
|
||||
|
||||
saveOrUpdate(
|
||||
voucher: Bill,
|
||||
printType: PrintType,
|
||||
guest_book_id: string,
|
||||
voucherType: VoucherType,
|
||||
guestBookId: string | null,
|
||||
updateTable: boolean,
|
||||
): Observable<boolean> {
|
||||
if (!voucher.id) {
|
||||
return this.save(voucher, printType, guest_book_id, updateTable);
|
||||
return this.save(voucher, voucherType, guestBookId, updateTable);
|
||||
}
|
||||
if (voucher.voucherType === PrintType.Kot) {
|
||||
return this.update(voucher, printType, guest_book_id, updateTable);
|
||||
if (voucher.voucherType === VoucherType.Kot) {
|
||||
return this.update(voucher, voucherType, guestBookId, updateTable);
|
||||
}
|
||||
return this.change(voucher, printType, guest_book_id, updateTable);
|
||||
return this.change(voucher, voucherType, guestBookId, updateTable);
|
||||
}
|
||||
|
||||
receivePayment(
|
||||
|
||||
Reference in New Issue
Block a user