Fix: Receive Payment

Since the amount Behaviour Subject pipe was not being subscribed to
and the original Behaviour Subject as being subscribed,
 amountVal was not being populated. Now it will be.
This was creating problem where amount in receive payment was always 0
Added a check in the backend so that if any part of bill remains unsettled, it will give an error instead of silently accepting and removing the entry.
This commit is contained in:
2020-12-19 09:09:10 +05:30
parent 36915b41c1
commit 8bb6235e67
6 changed files with 19 additions and 15 deletions

View File

@ -30,9 +30,10 @@ export class BillService {
public netAmount: BehaviorSubject<number>;
public discountAmount: BehaviorSubject<number>;
public taxAmount: BehaviorSubject<number>;
public amount: BehaviorSubject<number>;
public amount: Observable<number>;
public amountVal: number;
public selection = new SelectionModel<string>(true, []);
private amountBs: BehaviorSubject<number>;
constructor(
private dialog: MatDialog,
@ -44,9 +45,9 @@ export class BillService {
this.netAmount = new BehaviorSubject(0);
this.discountAmount = new BehaviorSubject(0);
this.taxAmount = new BehaviorSubject(0);
this.amount = new BehaviorSubject(0);
this.amountBs = new BehaviorSubject(0);
this.amountVal = 0;
this.amount.pipe(tap((x) => (this.amountVal = x)));
this.amount = this.amountBs.pipe(tap((x) => (this.amountVal = x)));
}
displayBill(): void {
@ -248,10 +249,6 @@ export class BillService {
return this.ser.saveOrUpdate(item, voucherType, guest_book_id, true);
}
type() {
return this.bill.voucherType;
}
receivePayment(value: { choices: ReceivePaymentItem[]; reason: string }): Observable<boolean> {
return this.ser.receivePayment(this.bill.id as string, value.choices, value.reason, true);
}
@ -311,7 +308,7 @@ export class BillService {
),
),
);
this.amount.next(
this.amountBs.next(
round(
this.bill.kots.reduce(
(t, k) =>

View File

@ -117,12 +117,12 @@ export class VoucherService {
receivePayment(
id: string,
amounts: { id: number; name: string; amount: number }[],
name: string,
reason: string,
updateTable: boolean,
): Observable<boolean> {
const options = { params: new HttpParams().set('u', updateTable.toString()) };
return this.http
.post<boolean>(`${url}/receive-payment/${id}`, { name, amounts }, options)
.post<boolean>(`${url}/receive-payment/${id}`, { reason, amounts }, options)
.pipe(catchError(this.log.handleError(serviceName, 'receivePayment'))) as Observable<boolean>;
}

View File

@ -192,7 +192,7 @@ export class SalesHomeComponent {
return;
}
const amount = this.bs.amountVal;
const type = this.bs.type();
const type = this.bs.bill.voucherType;
this.dialog
.open(ReceivePaymentComponent, {
data: {