Ported:
Split bill done - TODO: If the products have different price due to paid modifiers
This commit is contained in:
@ -13,6 +13,7 @@ const httpOptions = {
|
||||
const url = '/api/voucher';
|
||||
const urlMoveTable = '/api/move-table';
|
||||
const urlMoveKot = '/api/move-kot';
|
||||
const urlSplitBill = '/api/split-bill';
|
||||
const serviceName = 'VoucherService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@ -140,11 +141,10 @@ export class VoucherService {
|
||||
}
|
||||
|
||||
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},
|
||||
const options = {params: new HttpParams().set('u', 'true')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${urlSplitBill}/${id}`, {
|
||||
inventories: inventoriesToMove,
|
||||
table: {id: table.id}
|
||||
tableId: table.id
|
||||
}, options).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'splitBill'))
|
||||
);
|
||||
|
||||
@ -39,7 +39,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
printKotAllowed(): boolean {
|
||||
if (this.auth.user.perms.indexOf('print-kot') === -1) {
|
||||
if (this.auth.user && this.auth.user.perms.indexOf('print-kot') === -1) {
|
||||
return false;
|
||||
}
|
||||
if (!this.bs.bill.id) {
|
||||
@ -69,7 +69,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
discountAllowed(): boolean {
|
||||
return this.auth.user.perms.indexOf('discount') !== -1;
|
||||
return this.auth.user && this.auth.user.perms.indexOf('discount') !== -1;
|
||||
}
|
||||
|
||||
showDiscount(): Observable<boolean | { id: string, name: string, discount: number }[]> {
|
||||
@ -120,7 +120,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
printBillAllowed(): boolean {
|
||||
if (this.auth.user.perms.indexOf('print-bill') === -1) {
|
||||
if (this.auth.user && this.auth.user.perms.indexOf('print-bill') === -1) {
|
||||
return false;
|
||||
}
|
||||
if (!this.bs.bill.id) {
|
||||
@ -143,7 +143,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
if (this.route.snapshot.queryParamMap.has('guest')) {
|
||||
guestBookId = this.route.snapshot.queryParamMap.get('guest');
|
||||
}
|
||||
let discountObservable: Observable<any> = (this.discountAllowed()) ? this.showDiscount() : observableOf('');
|
||||
const discountObservable: Observable<any> = (this.discountAllowed()) ? this.showDiscount() : observableOf('');
|
||||
|
||||
discountObservable.pipe(
|
||||
tap((result: boolean | { id: string, name: string, discount: number }[]) => {
|
||||
@ -169,7 +169,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
receivePaymentAllowed(): boolean {
|
||||
if (this.auth.user.perms.indexOf('settle-bill') === -1) {
|
||||
if (this.auth.user && this.auth.user.perms.indexOf('settle-bill') === -1) {
|
||||
return false;
|
||||
}
|
||||
if (!this.bs.bill.id) {
|
||||
@ -184,7 +184,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
return true;
|
||||
}
|
||||
|
||||
receivePaymentWithReason(type:string, amount: number): Observable<boolean> {
|
||||
receivePaymentWithReason(type: string, amount: number): Observable<boolean> {
|
||||
const types = {
|
||||
NO_CHARGE: [
|
||||
{
|
||||
@ -203,13 +203,13 @@ export class SalesHomeComponent implements OnInit {
|
||||
};
|
||||
return this.dialog.open(ReasonComponent, {
|
||||
// width: '750px'
|
||||
data: {title: (type === "NO_CHARGE") ? "NC for whom" : "Staff name"}
|
||||
data: {title: (type === 'NO_CHARGE') ? 'NC for whom' : 'Staff name'}
|
||||
}).afterClosed().pipe(
|
||||
switchMap((value: boolean | string) => {
|
||||
if (!!value) {
|
||||
return this.bs.receivePayment(types[type], value as string)
|
||||
return this.bs.receivePayment(types[type], value as string);
|
||||
} else {
|
||||
return throwError("Cancelled");
|
||||
return throwError('Cancelled');
|
||||
}
|
||||
})
|
||||
);
|
||||
@ -227,7 +227,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
if (!!value) {
|
||||
return this.bs.receivePayment(value as { id: number, name: string, amount: number }[], '')
|
||||
} else {
|
||||
return throwError("Cancelled");
|
||||
return throwError('Cancelled');
|
||||
}
|
||||
})
|
||||
);
|
||||
@ -252,7 +252,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
|
||||
moveTableAllowed(): boolean {
|
||||
// TODO: Check if this condition should be "and" or "or"
|
||||
if (this.auth.user.perms.indexOf('move-table') === -1 && this.auth.user.perms.indexOf('merge-tables') === -1) {
|
||||
if (this.auth.user && this.auth.user.perms.indexOf('move-table') === -1 && this.auth.user.perms.indexOf('merge-tables') === -1) {
|
||||
return false;
|
||||
}
|
||||
if (!this.bs.bill.id) {
|
||||
@ -300,7 +300,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
voidBillAllowed(): boolean {
|
||||
if (this.auth.user.perms.indexOf('void-bill') === -1) {
|
||||
if (this.auth.user && this.auth.user.perms.indexOf('void-bill') === -1) {
|
||||
return false;
|
||||
}
|
||||
if (!this.bs.bill.id) {
|
||||
@ -352,7 +352,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
splitBillAllowed(): boolean {
|
||||
if (this.auth.user.perms.indexOf('split-bill') === -1) {
|
||||
if (this.auth.user && this.auth.user.perms.indexOf('split-bill') === -1) {
|
||||
return false;
|
||||
}
|
||||
if (!this.bs.bill.id) {
|
||||
|
||||
Reference in New Issue
Block a user