Strict done!!
This commit is contained in:
@@ -92,7 +92,7 @@
|
||||
mat-raised-button
|
||||
(click)="post()"
|
||||
*ngIf="voucher.id"
|
||||
[disabled]="voucher.posted || auth.user.perms.indexOf('post-vouchers') === -1"
|
||||
[disabled]="voucher.posted || auth.allowed('post-vouchers')"
|
||||
>
|
||||
{{ voucher.posted ? 'Posted' : 'Post' }}
|
||||
</button>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { FormArray, FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { Account } from '../core/account';
|
||||
import { Incentive } from '../core/incentive';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { User } from '../core/user';
|
||||
import { Voucher } from '../core/voucher';
|
||||
import { VoucherService } from '../core/voucher.service';
|
||||
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
@@ -23,16 +24,14 @@ import { IncentiveDataSource } from './incentive-datasource';
|
||||
})
|
||||
export class IncentiveComponent implements OnInit {
|
||||
public incentiveObservable = new BehaviorSubject<Incentive[]>([]);
|
||||
dataSource: IncentiveDataSource;
|
||||
dataSource: IncentiveDataSource = new IncentiveDataSource(this.incentiveObservable);
|
||||
form: FormGroup;
|
||||
voucher: Voucher;
|
||||
account: Account;
|
||||
voucher: Voucher = new Voucher();
|
||||
account: Account = new Account();
|
||||
accBal: any;
|
||||
|
||||
displayedColumns = ['name', 'designation', 'department', 'daysWorked', 'points', 'amount'];
|
||||
|
||||
accounts: Observable<Account[]>;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
@@ -46,7 +45,17 @@ export class IncentiveComponent implements OnInit {
|
||||
date: '',
|
||||
incentives: this.fb.array([]),
|
||||
});
|
||||
this.listenToDateChange();
|
||||
// Listen to Date Change
|
||||
(this.form.get('date') as FormControl).valueChanges
|
||||
.pipe(map((x) => moment(x).format('DD-MMM-YYYY')))
|
||||
.subscribe((x) => {
|
||||
if (x !== this.voucher.date && !this.voucher.id) {
|
||||
return this.ser.getIncentive(x).subscribe((voucher: Voucher) => {
|
||||
this.loadVoucher(voucher);
|
||||
});
|
||||
}
|
||||
return '';
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -57,9 +66,11 @@ export class IncentiveComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
loadVoucher(voucher) {
|
||||
loadVoucher(voucher: Voucher) {
|
||||
this.voucher = voucher;
|
||||
this.form.get('date').setValue(moment(this.voucher.date, 'DD-MMM-YYYY').toDate());
|
||||
(this.form.get('date') as FormControl).setValue(
|
||||
moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
|
||||
);
|
||||
this.form.setControl(
|
||||
'incentives',
|
||||
this.fb.array(
|
||||
@@ -74,20 +85,6 @@ export class IncentiveComponent implements OnInit {
|
||||
this.incentiveObservable.next(this.voucher.incentives);
|
||||
}
|
||||
|
||||
listenToDateChange(): void {
|
||||
this.form
|
||||
.get('date')
|
||||
.valueChanges.pipe(map((x) => moment(x).format('DD-MMM-YYYY')))
|
||||
.subscribe((x) => {
|
||||
if (x !== this.voucher.date && !this.voucher.id) {
|
||||
return this.ser.getIncentive(x).subscribe((voucher: Voucher) => {
|
||||
this.loadVoucher(voucher);
|
||||
});
|
||||
}
|
||||
return '';
|
||||
});
|
||||
}
|
||||
|
||||
totalPoints() {
|
||||
return this.voucher.incentives
|
||||
.map((item) => item.daysWorked * item.points)
|
||||
@@ -95,36 +92,35 @@ export class IncentiveComponent implements OnInit {
|
||||
}
|
||||
|
||||
pointValue() {
|
||||
return Math.round((this.voucher.incentive * 100) / this.totalPoints()) / 100;
|
||||
return Math.round(((this.voucher.incentive as number) * 100) / this.totalPoints()) / 100;
|
||||
}
|
||||
|
||||
less(row: Incentive, i: number) {
|
||||
if (row.points >= 1) {
|
||||
row.points -= 1;
|
||||
this.form
|
||||
.get('incentives')
|
||||
.get(`${i}`)
|
||||
.setValue({ points: `${row.points}` });
|
||||
((this.form.get('incentives') as FormArray).get(`${i}`) as FormGroup).setValue({
|
||||
points: `${row.points}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
change(row: Incentive, i: number) {
|
||||
row.points = +this.form.get('incentives').get(`${i}`).get('points').value;
|
||||
this.form
|
||||
.get('incentives')
|
||||
.get(`${i}`)
|
||||
.setValue({ points: `${row.points}` });
|
||||
row.points = +(((this.form.get('incentives') as FormArray).get(`${i}`) as FormGroup).get(
|
||||
'points',
|
||||
) as FormControl).value;
|
||||
((this.form.get('incentives') as FormArray).get(`${i}`) as FormGroup).setValue({
|
||||
points: `${row.points}`,
|
||||
});
|
||||
}
|
||||
|
||||
more(row: Incentive, i: number) {
|
||||
row.points += 1;
|
||||
this.form
|
||||
.get('incentives')
|
||||
.get(`${i}`)
|
||||
.setValue({ points: `${row.points}` });
|
||||
((this.form.get('incentives') as FormArray).get(`${i}`) as FormGroup).setValue({
|
||||
points: `${row.points}`,
|
||||
});
|
||||
}
|
||||
|
||||
amount(row) {
|
||||
amount(row: Incentive) {
|
||||
return row.points * row.daysWorked * this.pointValue();
|
||||
}
|
||||
|
||||
@@ -132,17 +128,17 @@ export class IncentiveComponent implements OnInit {
|
||||
if (!this.voucher.id) {
|
||||
return true;
|
||||
}
|
||||
if (this.voucher.posted && this.auth.user.perms.indexOf('edit-posted-vouchers') !== -1) {
|
||||
if (this.voucher.posted && this.auth.allowed('edit-posted-vouchers')) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
this.voucher.user.id === this.auth.user.id ||
|
||||
this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1
|
||||
this.voucher.user.id === (this.auth.user as User).id ||
|
||||
this.auth.allowed("edit-other-user's-vouchers")
|
||||
);
|
||||
}
|
||||
|
||||
post() {
|
||||
this.ser.post(this.voucher.id).subscribe(
|
||||
this.ser.post(this.voucher.id as string).subscribe(
|
||||
(result) => {
|
||||
this.loadVoucher(result);
|
||||
this.toaster.show('Success', 'Voucher Posted');
|
||||
@@ -180,7 +176,7 @@ export class IncentiveComponent implements OnInit {
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.voucher.id).subscribe(
|
||||
this.ser.delete(this.voucher.id as string).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/incentive'], { replaceUrl: true });
|
||||
|
||||
Reference in New Issue
Block a user