Added hasPermission function to the auth service to check for permissions.
Added: Bill Type selection Fix: Add product would add to old kots if product was added earlier
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { MatDialog } from "@angular/material";
|
||||
import { mergeMap, tap } from "rxjs/operators";
|
||||
import { Observable, of as observableOf } from "rxjs";
|
||||
import { concatMap, tap } from "rxjs/operators";
|
||||
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";
|
||||
import { SaleCategoryService } from "../../sale-category/sale-category.service";
|
||||
import { BillTypeComponent } from "../bill-type/bill-type.component";
|
||||
import { PrintType } from "../bills/bill";
|
||||
import { AuthService } from "../../auth/auth.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-sales-home',
|
||||
@ -19,6 +22,7 @@ export class SalesHomeComponent implements OnInit {
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private auth: AuthService,
|
||||
private toaster: ToasterService,
|
||||
private mcSer: SaleCategoryService,
|
||||
private bs: BillService) {
|
||||
@ -39,10 +43,12 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
discount(): void {
|
||||
this.showDiscount().subscribe();
|
||||
if (this.auth.hasPermission("Discount")) {
|
||||
this.showDiscount().subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
showDiscount(): Observable<boolean | { id: string, name: string, discount: number }[]> {
|
||||
showDiscount(): Observable<boolean | { id: string, name: string, discount: number }[]> {
|
||||
const dialogRef = this.dialog.open(DiscountComponent, {
|
||||
// width: '750px',
|
||||
data: this.mcSer.listForDiscount()
|
||||
@ -56,24 +62,48 @@ export class SalesHomeComponent implements OnInit {
|
||||
)
|
||||
}
|
||||
|
||||
discountDialog (canGiveDiscount: boolean) : Observable<any> {
|
||||
let discObs = null;
|
||||
if (canGiveDiscount) {
|
||||
return discObs = this.showDiscount();
|
||||
} else {
|
||||
return discObs = observableOf("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
billTypeDialog() {
|
||||
return this.dialog.open(BillTypeComponent).afterClosed().pipe(
|
||||
tap(x => {
|
||||
if (!x) {
|
||||
throwError ("No Bill Type Chosen")
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
printBill() {
|
||||
const canGiveDiscount = true;
|
||||
const canGiveDiscount = this.auth.hasPermission("Discount");
|
||||
let guestBookId = null;
|
||||
if (this.route.snapshot.queryParamMap.has("guest")) {
|
||||
guestBookId = this.route.snapshot.queryParamMap.get("guest");
|
||||
}
|
||||
let discObs = null
|
||||
if (!canGiveDiscount) {
|
||||
discObs = this.showDiscount();
|
||||
} else {
|
||||
discObs = observableOf("");
|
||||
}
|
||||
discObs.pipe(
|
||||
mergeMap(x => this.bs.printBill(guestBookId))
|
||||
).subscribe(x => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/sales']);
|
||||
});
|
||||
this.discountDialog(canGiveDiscount).pipe(
|
||||
concatMap(() => this.billTypeDialog())
|
||||
).pipe(
|
||||
concatMap(
|
||||
(x: boolean | PrintType) => iif(
|
||||
() => !!x,
|
||||
this.bs.printBill(guestBookId, x as PrintType),
|
||||
throwError(x)
|
||||
)
|
||||
),
|
||||
).subscribe(() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/sales']);
|
||||
},
|
||||
x => {
|
||||
this.toaster.show('Error', "No Bill Type Chosen")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user