Void Bill Working

This commit is contained in:
Amritanshu
2019-08-10 18:49:05 +05:30
parent 2fcff26e34
commit 40a958a935
17 changed files with 212 additions and 46 deletions

View File

@ -21,7 +21,7 @@
<mat-card fxLayout="column" class="square-button" matRipple (click)="moveTable()">
<h3 class="item-name">Move Table</h3>
</mat-card>
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['../../tables']">
<mat-card fxLayout="column" class="square-button" matRipple (click)="voidBill()">
<h3 class="item-name">Void Bill</h3>
</mat-card>
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['../../tables']">

View File

@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from "@angular/router";
import { MatDialog } from "@angular/material";
import { concatMap, map, switchMap, tap } from "rxjs/operators";
import { iif, Observable, of as observableOf, throwError} from "rxjs";
import { iif, Observable, of as observableOf, throwError } from "rxjs";
import { BillService } from '../bill.service';
import { ToasterService } from "../../core/toaster.service";
import { DiscountComponent } from "../discount/discount.component";
@ -15,6 +15,7 @@ import { TableService } from "../../tables/table.service";
import { Table } from "../../core/table";
import { TablesDialogComponent } from "../tables-dialog/tables-dialog.component";
import { ConfirmDialogComponent } from "../../shared/confirm-dialog/confirm-dialog.component";
import { VoidReasonComponent } from "../void-reason/void-reason.component";
@Component({
selector: 'app-sales-home',
@ -97,6 +98,15 @@ export class SalesHomeComponent implements OnInit {
);
}
confirmVoidDialog(reason: string): Observable<boolean | string> {
return this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Void Bill?', content: 'Are you sure?'}
}).afterClosed().pipe(
map((x: boolean) => x ? reason : x)
);
}
printBill() {
const canGiveDiscount = this.auth.hasPermission("Discount");
let guestBookId = null;
@ -143,19 +153,18 @@ export class SalesHomeComponent implements OnInit {
}
moveTable() {
const dialogRef = this.dialog.open(TablesDialogComponent, {
this.dialog.open(TablesDialogComponent, {
// width: '750px',
data: {
list: this.tSer.running(),
canChooseRunning: false
}
});
dialogRef.afterClosed().pipe(
}).afterClosed().pipe(
switchMap((x: boolean | Table) => {
if (!!x) {
return this.confirmMoveTableDialog(x as Table)
return this.confirmMoveTableDialog(x as Table);
} else {
return throwError("Please choose a table")
return throwError("Please choose a table");
}
}),
switchMap((value: { table: Table, confirmed: boolean }, index: number) => {
@ -176,6 +185,29 @@ export class SalesHomeComponent implements OnInit {
}
voidBill() {
this.dialog.open(VoidReasonComponent, {
// width: '750px'
}).afterClosed().pipe(
switchMap((x: boolean | string) => {
if (!!x) {
return this.confirmVoidDialog(x as string);
} else {
return throwError("Please choose a reason to void the bill");
}
}),
switchMap((x: boolean | string) => {
if (!!x) {
return this.bs.voidBill(x as string)
} else {
return throwError("You chose not to void the bill")
}
})
).subscribe((x) => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
},
x => {
this.toaster.show('Error', x)
})
}
}