Settle Options are now stored in the Database and can be updated
This commit is contained in:
@ -29,5 +29,5 @@
|
||||
</div>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button [mat-dialog-close]="false">Cancel</button>
|
||||
<button mat-button [mat-dialog-close]="selected">Done</button>
|
||||
<button mat-button [mat-dialog-close]="selectedVal">Done</button>
|
||||
</mat-dialog-actions>
|
||||
|
||||
@ -9,25 +9,20 @@ import { VoucherType } from '../bills/voucher-type';
|
||||
styleUrls: ['./bill-type.component.css'],
|
||||
})
|
||||
export class BillTypeComponent {
|
||||
selected: string;
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<BillTypeComponent>) {
|
||||
this.selected = '';
|
||||
}
|
||||
selected?: string;
|
||||
selectedVal?: VoucherType;
|
||||
constructor(public dialogRef: MatDialogRef<BillTypeComponent>) {}
|
||||
|
||||
select(voucherType: string) {
|
||||
this.selected = voucherType;
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
if (this.selected === 'REGULAR_BILL') {
|
||||
this.dialogRef.close(VoucherType.Bill);
|
||||
} else if (this.selected === 'STAFF') {
|
||||
this.dialogRef.close(VoucherType.Staff);
|
||||
} else if (this.selected === 'NO_CHARGE') {
|
||||
this.dialogRef.close(VoucherType.NoCharge);
|
||||
} else {
|
||||
this.dialogRef.close();
|
||||
this.selectedVal = VoucherType.Bill;
|
||||
}
|
||||
if (this.selected === 'STAFF') {
|
||||
this.selectedVal = VoucherType.Staff;
|
||||
}
|
||||
if (this.selected === 'NO_CHARGE') {
|
||||
this.selectedVal = VoucherType.NoCharge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import { Observable } from 'rxjs/internal/Observable';
|
||||
import { BillViewItem } from '../core/bill-view-item';
|
||||
import { ModifierCategory } from '../core/modifier-category';
|
||||
import { Product } from '../core/product';
|
||||
import { ReceivePaymentItem } from '../core/receive-payment-item';
|
||||
import { Table } from '../core/table';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { ModifierCategoryService } from '../modifier-categories/modifier-category.service';
|
||||
@ -219,11 +220,8 @@ export class BillService {
|
||||
return this.bill.voucherType;
|
||||
}
|
||||
|
||||
receivePayment(
|
||||
amounts: { id: number; name: string; amount: number }[],
|
||||
name: string,
|
||||
): Observable<boolean> {
|
||||
return this.ser.receivePayment(this.bill.id as string, amounts, name, true);
|
||||
receivePayment(value: { choices: ReceivePaymentItem[]; reason: string }): Observable<boolean> {
|
||||
return this.ser.receivePayment(this.bill.id as string, value.choices, value.reason, true);
|
||||
}
|
||||
|
||||
moveTable(table: Table): Observable<boolean> {
|
||||
|
||||
@ -3,6 +3,7 @@ import { User } from '../../core/user';
|
||||
import { GuestBook } from '../../guest-book/guest-book';
|
||||
|
||||
import { Kot } from './kot';
|
||||
import { VoucherType } from './voucher-type';
|
||||
|
||||
export class Bill {
|
||||
id: string | undefined;
|
||||
@ -18,7 +19,7 @@ export class Bill {
|
||||
guest: GuestBook;
|
||||
// settlements: any[];
|
||||
voidReason: string;
|
||||
voucherType: string;
|
||||
voucherType: VoucherType;
|
||||
serial: number;
|
||||
kots: Kot[];
|
||||
// reprints: any[];
|
||||
@ -48,7 +49,7 @@ export class Bill {
|
||||
this.guest = new GuestBook();
|
||||
// this.settlements = [];
|
||||
this.voidReason = '';
|
||||
this.voucherType = '';
|
||||
this.voucherType = VoucherType.Kot;
|
||||
this.serial = 0;
|
||||
this.kots = [];
|
||||
// this.reprints = [];
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
export enum VoucherType {
|
||||
Kot = 'KOT',
|
||||
Bill = 'REGULAR_BILL',
|
||||
NoCharge = 'NO_CHARGE',
|
||||
Staff = 'STAFF',
|
||||
Void = 'VOID',
|
||||
Kot = 0,
|
||||
Bill = 1,
|
||||
NoCharge = 2,
|
||||
Staff = 4,
|
||||
Void = 8,
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ export class VoucherService {
|
||||
updateTable: boolean,
|
||||
): Observable<boolean> {
|
||||
const options = {
|
||||
params: new HttpParams().set('p', voucherType).set('u', updateTable.toString()),
|
||||
params: new HttpParams().set('p', voucherType.toString()).set('u', updateTable.toString()),
|
||||
};
|
||||
if (guestBookId !== null) {
|
||||
options.params = options.params.set('g', guestBookId);
|
||||
@ -74,7 +74,7 @@ export class VoucherService {
|
||||
updateTable: boolean,
|
||||
): Observable<boolean> {
|
||||
const options = {
|
||||
params: new HttpParams().set('p', voucherType).set('u', updateTable.toString()),
|
||||
params: new HttpParams().set('p', voucherType.toString()).set('u', updateTable.toString()),
|
||||
};
|
||||
if (guestBookId !== null) {
|
||||
options.params = options.params.set('g', guestBookId);
|
||||
|
||||
@ -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);
|
||||
}),
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { ReceivePaymentItem } from '../../core/receive-payment-item';
|
||||
import { SettleOption } from '../../core/settle-option';
|
||||
|
||||
export class ReceivePaymentDatasource extends DataSource<ReceivePaymentItem> {
|
||||
constructor(private data: ReceivePaymentItem[]) {
|
||||
export class ReceivePaymentDatasource extends DataSource<SettleOption> {
|
||||
constructor(private data: SettleOption[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<ReceivePaymentItem[]> {
|
||||
connect(): Observable<SettleOption[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<h2 mat-dialog-title>Receive Payment</h2>
|
||||
<mat-dialog-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<mat-table #table [dataSource]="dataSource" formArrayName="amounts">
|
||||
<mat-table #table [dataSource]="dataSource" formArrayName="amounts" *ngIf="this.displayTable">
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef class="bold">Amount</mat-header-cell>
|
||||
@ -28,9 +28,22 @@
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
<mat-footer-row *matFooterRowDef="displayedColumns"></mat-footer-row>
|
||||
</mat-table>
|
||||
<mat-form-field fxFlex *ngIf="this.displayReason">
|
||||
<mat-label>Reason</mat-label>
|
||||
<input
|
||||
type="text"
|
||||
matInput
|
||||
#son
|
||||
placeholder="Reason"
|
||||
formControlName="son"
|
||||
autocomplete="off"
|
||||
(focus)="select(son.value) && son.select()"
|
||||
(input)="select(son.value)"
|
||||
/>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button [mat-dialog-close]="false">Cancel</button>
|
||||
<button mat-button [mat-dialog-close]>Cancel</button>
|
||||
<button mat-button (click)="accept()" color="primary" [disabled]="!!balance">Ok</button>
|
||||
</mat-dialog-actions>
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { Component, ElementRef, Inject, ViewChild } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { distinctUntilChanged } from 'rxjs/operators';
|
||||
import { distinctUntilChanged, map, tap } from 'rxjs/operators';
|
||||
|
||||
import { ReceivePaymentItem } from '../../core/receive-payment-item';
|
||||
import { ReceivePaymentList } from '../../core/receive-payment-list';
|
||||
import { SettleOption } from '../../core/settle-option';
|
||||
import { SettleOptionService } from '../../settle-option/settle-option.service';
|
||||
import { VoucherType } from '../bills/voucher-type';
|
||||
|
||||
import { ReceivePaymentDatasource } from './receive-payment-datasource';
|
||||
@ -15,48 +16,15 @@ import { ReceivePaymentDatasource } from './receive-payment-datasource';
|
||||
styleUrls: ['./receive-payment.component.css'],
|
||||
})
|
||||
export class ReceivePaymentComponent {
|
||||
choices: ReceivePaymentList = {
|
||||
REGULAR_BILL: [
|
||||
{
|
||||
id: 2,
|
||||
name: 'Cash',
|
||||
amount: 0,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Credit Card',
|
||||
amount: 0,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'Bill To Company',
|
||||
amount: 0,
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'Tip',
|
||||
amount: 0,
|
||||
},
|
||||
],
|
||||
NO_CHARGE: [
|
||||
{
|
||||
id: 4,
|
||||
name: 'No Charge',
|
||||
amount: 0,
|
||||
},
|
||||
],
|
||||
STAFF: [
|
||||
{
|
||||
id: 10,
|
||||
name: 'Staff Account',
|
||||
amount: 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
@ViewChild('son', { static: true }) son?: ElementRef;
|
||||
choices: ReceivePaymentItem[] = [];
|
||||
|
||||
type: VoucherType;
|
||||
amount: number;
|
||||
balance: number;
|
||||
reason = '';
|
||||
displayReason: boolean;
|
||||
displayTable: boolean;
|
||||
form: FormGroup;
|
||||
dataSource: ReceivePaymentDatasource;
|
||||
|
||||
@ -65,41 +33,70 @@ export class ReceivePaymentComponent {
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<ReceivePaymentComponent>,
|
||||
private fb: FormBuilder,
|
||||
private ser: SettleOptionService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: { type: VoucherType; amount: number },
|
||||
) {
|
||||
this.form = this.fb.group({
|
||||
amounts: '',
|
||||
son: '',
|
||||
});
|
||||
this.type = data.type;
|
||||
this.amount = data.amount;
|
||||
this.balance = data.amount;
|
||||
this.form.setControl(
|
||||
'amounts',
|
||||
this.fb.array(
|
||||
this.choices[this.type].map((x: ReceivePaymentItem) =>
|
||||
this.fb.group({
|
||||
name: [x.name],
|
||||
amount: [''],
|
||||
}),
|
||||
this.displayReason = false;
|
||||
this.displayTable = false;
|
||||
this.ser
|
||||
.listForType(data.type)
|
||||
.pipe(
|
||||
tap(
|
||||
(x: SettleOption[]) =>
|
||||
(this.displayReason = x.reduce((o, n) => o || n.hasReason, this.displayReason)),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new ReceivePaymentDatasource(this.choices[this.type]);
|
||||
tap((x: SettleOption[]) => (this.displayTable = x.length > 1)),
|
||||
map((x: SettleOption[]) =>
|
||||
x.map(
|
||||
(y) => ({ ...y, amount: !this.displayTable ? this.amount : 0 } as ReceivePaymentItem),
|
||||
),
|
||||
),
|
||||
)
|
||||
.subscribe((x) => {
|
||||
this.choices = x;
|
||||
this.form.setControl(
|
||||
'amounts',
|
||||
this.fb.array(
|
||||
this.choices.map((y: ReceivePaymentItem) =>
|
||||
this.fb.group({
|
||||
name: [y.name],
|
||||
amount: [y.amount === 0 ? '' : '' + this.amount],
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new ReceivePaymentDatasource(this.choices);
|
||||
this.listenToAmountChange();
|
||||
this.balance = this.amount - this.choices.reduce((a, c) => a + c.amount, 0);
|
||||
});
|
||||
this.dataSource = new ReceivePaymentDatasource(this.choices);
|
||||
this.listenToAmountChange();
|
||||
}
|
||||
|
||||
listenToAmountChange() {
|
||||
const array = this.form.get('amounts') as FormArray;
|
||||
this.choices[this.type].forEach((z, i) =>
|
||||
this.choices.forEach((z, i) =>
|
||||
array.controls[i].valueChanges.pipe(distinctUntilChanged()).subscribe((x) => {
|
||||
(this.choices[this.type].find((s) => s.name === x.name) as ReceivePaymentItem).amount =
|
||||
(this.choices.find((s) => s.name === x.name) as ReceivePaymentItem).amount =
|
||||
x.amount === '' ? 0 : parseInt(x.amount, 10);
|
||||
this.balance = this.amount - this.choices[this.type].reduce((a, c) => a + c.amount, 0);
|
||||
this.balance = this.amount - this.choices.reduce((a, c) => a + c.amount, 0);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
select(reason: string) {
|
||||
this.reason = reason.trim();
|
||||
return true;
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
this.dialogRef.close(this.choices[this.type]);
|
||||
this.dialogRef.close({ choices: this.choices, reason: this.reason });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user