Settle Options are now stored in the Database and can be updated

This commit is contained in:
2020-12-13 09:44:32 +05:30
parent d65379a068
commit 27aa4d12a6
72 changed files with 1326 additions and 551 deletions

View File

@ -1,11 +1,11 @@
import { Component } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, of as observableOf, throwError } from 'rxjs';
import { Observable, of as observableOf } from 'rxjs';
import { map, switchMap, tap } from 'rxjs/operators';
import { AuthService } from '../../auth/auth.service';
import { ReceivePaymentList } from '../../core/receive-payment-list';
import { ReceivePaymentItem } from '../../core/receive-payment-item';
import { Table } from '../../core/table';
import { ToasterService } from '../../core/toaster.service';
import { SaleCategoryService } from '../../sale-category/sale-category.service';
@ -156,7 +156,7 @@ export class SalesHomeComponent {
if (x) {
return observableOf(x);
}
return throwError('No Bill Type Chosen');
throw new Error('No Bill Type Chosen');
}),
switchMap((x: VoucherType) => this.bs.printBill(guestBookId, x as VoucherType)),
)
@ -187,43 +187,14 @@ export class SalesHomeComponent {
return true;
}
receivePaymentWithReason(type: string, amount: number): Observable<boolean> {
const types: ReceivePaymentList = {
NO_CHARGE: [
{
id: 4,
name: 'No Charge',
amount,
},
],
STAFF: [
{
id: 10,
name: 'Staff Account',
amount,
},
],
};
return this.dialog
.open(ReasonComponent, {
// width: '750px'
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 throwError('Cancelled');
}),
);
}
receiveRegularPayment(type: string, amount: number): Observable<boolean> {
return this.dialog
receivePayment() {
if (!this.receivePaymentAllowed()) {
return;
}
const amount = this.bs.amountVal();
const type = this.bs.type();
this.dialog
.open(ReceivePaymentComponent, {
// width: '750px',
data: {
type,
amount,
@ -231,36 +202,24 @@ export class SalesHomeComponent {
})
.afterClosed()
.pipe(
switchMap((value: boolean | { id: number; name: string; amount: number }[]) => {
if (value) {
return this.bs.receivePayment(
value as { id: number; name: string; amount: number }[],
'',
);
switchMap((value: undefined | { choices: ReceivePaymentItem[]; reason: string }) => {
if (value === undefined) {
throw new Error('Receive Payment Choices / Reason not selected');
}
return throwError('Cancelled');
return this.bs.receivePayment(value);
}),
)
.subscribe(
() => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
},
(value) => {
this.toaster.show('Error', value);
},
);
}
receivePayment() {
if (!this.receivePaymentAllowed()) {
return;
}
const amount = this.bs.amountVal();
const type = this.bs.type();
let obs: Observable<boolean>;
if (type === 'NO_CHARGE' || type === 'STAFF') {
obs = this.receivePaymentWithReason(type, amount);
} else {
obs = this.receiveRegularPayment(type, amount);
}
obs.subscribe(() => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
});
}
moveTableAllowed(): boolean {
if (!this.auth.allowed('move-table') && !this.auth.allowed('merge-tables')) {
return false;
@ -290,12 +249,12 @@ export class SalesHomeComponent {
if (x) {
return this.confirmTableDialog(x as Table);
}
return throwError('Please choose a table');
throw new Error('Please choose a table');
}),
// 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');
throw new Error('Please confirm move');
}
if (value.table.status) {
return this.bs.mergeTable(value.table);
@ -350,13 +309,13 @@ export class SalesHomeComponent {
if (x) {
return this.confirmVoidDialog(x as string);
}
return throwError('Please choose a reason to void the bill');
throw new Error('Please choose a reason to void the bill');
}),
switchMap((x: boolean | string) => {
if (x) {
return this.bs.voidBill(x as string);
}
return throwError('You chose not to void the bill');
throw new Error('You chose not to void the bill');
}),
)
.subscribe(
@ -398,12 +357,12 @@ export class SalesHomeComponent {
if (x) {
return this.confirmTableDialog(x as Table);
}
return throwError('Please choose a table');
throw new Error('Please choose a table');
}),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
switchMap((value: { table: Table; confirmed: boolean }, index: number) => {
if (!value.confirmed) {
return throwError('Please confirm split');
throw new Error('Please confirm split');
}
return this.bs.splitBill(value.table);
}),