Updated to angular 11

Now compiling with strict mode in typescript
Need to error checking now
This commit is contained in:
2020-11-22 10:13:37 +05:30
parent cabd6f2ea1
commit 6567f560ab
187 changed files with 1709 additions and 1184 deletions

View File

@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { SalesHomeComponent } from './sales-home.component';
@ -6,11 +6,13 @@ describe('SalesHomeComponent', () => {
let component: SalesHomeComponent;
let fixture: ComponentFixture<SalesHomeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SalesHomeComponent],
}).compileComponents();
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [SalesHomeComponent],
}).compileComponents();
}),
);
beforeEach(() => {
fixture = TestBed.createComponent(SalesHomeComponent);

View File

@ -5,6 +5,7 @@ import { Observable, of as observableOf, throwError } from 'rxjs';
import { map, switchMap, tap } from 'rxjs/operators';
import { AuthService } from '../../auth/auth.service';
import { ReceivePaymentList } from '../../core/receive-payment-list';
import { Table } from '../../core/table';
import { ToasterService } from '../../core/toaster.service';
import { SaleCategoryService } from '../../sale-category/sale-category.service';
@ -12,7 +13,7 @@ import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dial
import { TableService } from '../../tables/table.service';
import { BillTypeComponent } from '../bill-type/bill-type.component';
import { BillService } from '../bill.service';
import { PrintType } from '../bills/print-type';
import { VoucherType } from '../bills/voucher-type';
import { DiscountComponent } from '../discount/discount.component';
import { ReasonComponent } from '../reason/reason.component';
import { ReceivePaymentComponent } from '../receive-payment/receive-payment.component';
@ -36,16 +37,13 @@ export class SalesHomeComponent {
) {}
printKotAllowed(): boolean {
if (this.auth.user && this.auth.user.perms.indexOf('print-kot') === -1) {
if (!this.auth.allowed('print-kot')) {
return false;
}
if (!this.bs.bill.id) {
return true;
}
if (this.bs.bill.voucherType !== PrintType.Kot) {
return false;
}
if (this.bs.bill.isVoid) {
if (this.bs.bill.voucherType !== VoucherType.Kot) {
return false;
}
return true;
@ -71,7 +69,7 @@ export class SalesHomeComponent {
}
discountAllowed(): boolean {
return this.auth.user && this.auth.user.perms.indexOf('discount') !== -1;
return this.auth.allowed('discount');
}
showDiscount(): Observable<boolean | { id: string; name: string; discount: number }[]> {
@ -96,7 +94,7 @@ export class SalesHomeComponent {
}
billTypeDialog() {
if (this.bs.bill.voucherType !== PrintType.Kot) {
if (this.bs.bill.voucherType !== VoucherType.Kot) {
return observableOf(this.bs.bill.voucherType);
}
return this.dialog.open(BillTypeComponent).afterClosed();
@ -123,19 +121,16 @@ export class SalesHomeComponent {
}
printBillAllowed(): boolean {
if (this.auth.user && this.auth.user.perms.indexOf('print-bill') === -1) {
if (!this.auth.allowed('print-bill')) {
return false;
}
if (!this.bs.bill.id) {
return true;
}
if (
this.bs.bill.voucherType !== PrintType.Kot &&
this.auth.user.perms.indexOf('edit-printed-bill') === -1
) {
if (this.bs.bill.voucherType !== VoucherType.Kot && !this.auth.allowed('edit-printed-bill')) {
return false;
}
if (this.bs.bill.isVoid) {
if (this.bs.bill.voucherType === VoucherType.Void) {
return false;
}
return true;
@ -145,7 +140,7 @@ export class SalesHomeComponent {
if (!this.printBillAllowed()) {
return;
}
let guestBookId = null;
let guestBookId: string | null = null;
if (this.route.snapshot.queryParamMap.has('guest')) {
guestBookId = this.route.snapshot.queryParamMap.get('guest');
}
@ -163,7 +158,7 @@ export class SalesHomeComponent {
}
return throwError('No Bill Type Chosen');
}),
switchMap((x: PrintType) => this.bs.printBill(guestBookId, x as PrintType)),
switchMap((x: VoucherType) => this.bs.printBill(guestBookId, x as VoucherType)),
)
.subscribe(
() => {
@ -177,23 +172,23 @@ export class SalesHomeComponent {
}
receivePaymentAllowed(): boolean {
if (this.auth.user && this.auth.user.perms.indexOf('settle-bill') === -1) {
if (!this.auth.allowed('settle-bill')) {
return false;
}
if (!this.bs.bill.id) {
return false;
}
if (this.bs.bill.voucherType === PrintType.Kot) {
if (this.bs.bill.voucherType === VoucherType.Kot) {
return false;
}
if (this.bs.bill.isVoid) {
if (this.bs.bill.voucherType === VoucherType.Void) {
return false;
}
return true;
}
receivePaymentWithReason(type: string, amount: number): Observable<boolean> {
const types = {
const types: ReceivePaymentList = {
NO_CHARGE: [
{
id: 4,
@ -267,12 +262,7 @@ export class SalesHomeComponent {
}
moveTableAllowed(): boolean {
// TODO: Check if this condition should be "and" or "or"
if (
this.auth.user &&
this.auth.user.perms.indexOf('move-table') === -1 &&
this.auth.user.perms.indexOf('merge-tables') === -1
) {
if (!this.auth.allowed('move-table') && !this.auth.allowed('merge-tables')) {
return false;
}
if (!this.bs.bill.id) {
@ -285,7 +275,7 @@ export class SalesHomeComponent {
if (!this.moveTableAllowed()) {
return;
}
const canMergeTables = this.auth.user.perms.indexOf('merge-tables') !== -1;
const canMergeTables = this.auth.allowed('merge-tables');
this.dialog
.open(TablesDialogComponent, {
// width: '750px',
@ -325,7 +315,7 @@ export class SalesHomeComponent {
}
voidBillAllowed(): boolean {
if (this.auth.user && this.auth.user.perms.indexOf('void-bill') === -1) {
if (!this.auth.allowed('void-bill')) {
return false;
}
if (!this.bs.bill.id) {
@ -381,7 +371,7 @@ export class SalesHomeComponent {
}
splitBillAllowed(): boolean {
if (this.auth.user && this.auth.user.perms.indexOf('split-bill') === -1) {
if (!this.auth.allowed('split-bill')) {
return false;
}
if (!this.bs.bill.id) {