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:
parent
c81b92c336
commit
6503982897
@ -70,4 +70,8 @@ export class AuthService {
|
||||
);
|
||||
}
|
||||
|
||||
hasPermission(permission: string) : boolean {
|
||||
return this.user !== undefined && this.user.isAuthenticated && this.user.perms.indexOf(permission) !== -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
11
bookie/src/app/sales/bill-type/bill-type.component.css
Normal file
11
bookie/src/app/sales/bill-type/bill-type.component.css
Normal file
@ -0,0 +1,11 @@
|
||||
.square-button {
|
||||
min-width: 150px;
|
||||
max-width: 150px;
|
||||
min-height: 150px;
|
||||
cursor: pointer;
|
||||
margin: 20px;
|
||||
}
|
||||
.selected {
|
||||
background-color: green;
|
||||
}
|
||||
|
18
bookie/src/app/sales/bill-type/bill-type.component.html
Normal file
18
bookie/src/app/sales/bill-type/bill-type.component.html
Normal file
@ -0,0 +1,18 @@
|
||||
<div fxLayout="row wrap" fxLayoutGap="grid 20px">
|
||||
<mat-card fxLayout="column" class="square-button" matRipple (click)="select('REGULAR_BILL')"
|
||||
[class.selected]="selected == 'REGULAR_BILL'">
|
||||
<h3 class="item-name">Regular</h3>
|
||||
</mat-card>
|
||||
<mat-card fxLayout="column" class="square-button" matRipple (click)="select('STAFF')"
|
||||
[class.selected]="selected == 'STAFF'">
|
||||
<h3 class="item-name">Staff</h3>
|
||||
</mat-card>
|
||||
<mat-card fxLayout="column" class="square-button" matRipple (click)="select('NO_CHARGE')"
|
||||
[class.selected]="selected == 'NO_CHARGE'">
|
||||
<h3 class="item-name">No Charge</h3>
|
||||
</mat-card>
|
||||
</div>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button [mat-dialog-close]="false">Cancel</button>
|
||||
<button mat-button [mat-dialog-close]="selected">Done</button>
|
||||
</mat-dialog-actions>
|
25
bookie/src/app/sales/bill-type/bill-type.component.spec.ts
Normal file
25
bookie/src/app/sales/bill-type/bill-type.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { BillTypeComponent } from './bill-type.component';
|
||||
|
||||
describe('BillTypeComponent', () => {
|
||||
let component: BillTypeComponent;
|
||||
let fixture: ComponentFixture<BillTypeComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ BillTypeComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(BillTypeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
28
bookie/src/app/sales/bill-type/bill-type.component.ts
Normal file
28
bookie/src/app/sales/bill-type/bill-type.component.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { MatDialogRef } from '@angular/material';
|
||||
import { PrintType } from "../bills/bill";
|
||||
|
||||
@Component({
|
||||
selector: 'app-bill-type',
|
||||
templateUrl: './bill-type.component.html',
|
||||
styleUrls: ['./bill-type.component.css']
|
||||
})
|
||||
export class BillTypeComponent {
|
||||
selected: string;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<BillTypeComponent>,
|
||||
|
||||
) {
|
||||
this.selected = null;
|
||||
}
|
||||
|
||||
select(s: string) {
|
||||
this.selected = s;
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
this.dialogRef.close(PrintType[this.selected]);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,9 @@ export class BillService {
|
||||
|
||||
}
|
||||
addProduct(product: Product): void {
|
||||
const old = this.data.find(x => !x.isKot && x.productId === product.id && x.isHappyHour === product.hasHappyHour);
|
||||
const old = this.data.find(
|
||||
x => !x.isKot && !x.id && x.productId === product.id && x.isHappyHour === product.hasHappyHour
|
||||
);
|
||||
if (old !== undefined) {
|
||||
old.quantity += 1;
|
||||
} else {
|
||||
@ -170,16 +172,15 @@ export class BillService {
|
||||
);
|
||||
}
|
||||
|
||||
printBill(guest_book_id: string): Observable<Bill> {
|
||||
printBill(guest_book_id: string, printType: PrintType): Observable<Bill> {
|
||||
let item = JSON.parse(JSON.stringify(this.bill));
|
||||
item.kots.forEach(k => {
|
||||
k.inventories.forEach(i => {
|
||||
i.discount = this.data.find(x => !x.isKot && x.id === i.id).discount;
|
||||
})
|
||||
});
|
||||
console.log(item);
|
||||
item.kots.push(this.getKot());
|
||||
return this.ser.saveOrUpdate(item, PrintType.Bill, guest_book_id, true).pipe(
|
||||
return this.ser.saveOrUpdate(item, printType, guest_book_id, true).pipe(
|
||||
tap(x => console.log(x))
|
||||
);
|
||||
}
|
||||
|
@ -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,8 +43,10 @@ export class SalesHomeComponent implements OnInit {
|
||||
}
|
||||
|
||||
discount(): void {
|
||||
if (this.auth.hasPermission("Discount")) {
|
||||
this.showDiscount().subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
showDiscount(): Observable<boolean | { id: string, name: string, discount: number }[]> {
|
||||
const dialogRef = this.dialog.open(DiscountComponent, {
|
||||
@ -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.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")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import { SalesHomeComponent } from './home/sales-home.component';
|
||||
import { BillService } from './bill.service';
|
||||
import { QuantityComponent } from './quantity/quantity.component';
|
||||
import { DiscountComponent } from "./discount/discount.component";
|
||||
import {BillTypeComponent} from "./bill-type/bill-type.component";
|
||||
|
||||
@NgModule({
|
||||
providers: [
|
||||
@ -33,6 +34,7 @@ import { DiscountComponent } from "./discount/discount.component";
|
||||
],
|
||||
declarations: [
|
||||
BillsComponent,
|
||||
BillTypeComponent,
|
||||
DiscountComponent,
|
||||
MenuCategoriesComponent,
|
||||
ModifiersComponent,
|
||||
@ -61,6 +63,7 @@ import { DiscountComponent } from "./discount/discount.component";
|
||||
SalesRoutingModule
|
||||
],
|
||||
entryComponents: [
|
||||
BillTypeComponent,
|
||||
DiscountComponent,
|
||||
ModifiersComponent,
|
||||
QuantityComponent
|
||||
|
Loading…
x
Reference in New Issue
Block a user