feat: add permissions (#1198)

- add permission in centers, loans, recurring deposits, products and account transfer module
- add charges action in loans view
This commit is contained in:
Muskan Khedia
2020-08-12 20:44:00 +05:30
committed by GitHub
parent dbcf40e064
commit 2f3005cab8
58 changed files with 744 additions and 101 deletions
@@ -0,0 +1,119 @@
<div *ngIf="loansAccountData.status.value === 'Active' && chargeData.amountOutstanding !== 0"
fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
<button mat-raised-button color="accent" *mifosxHasPermission="'PAY_SAVINGSACCOUNTCHARGE'" (click)="payCharge()">
<fa-icon icon="dollar-sign"></fa-icon>&nbsp;&nbsp;
Pay
</button>
<button mat-raised-button color="primary" *mifosxHasPermission="'WAIVE_SAVINGSACCOUNTCHARGE'" (click)="waiveCharge()">
<fa-icon icon="flag"></fa-icon>&nbsp;&nbsp;
Waive
</button>
</div>
<div *ngIf="loansAccountData.status.value === 'Submitted and pending approval'"
fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
<button mat-raised-button color="primary" *mifosxHasPermission="'UPDATE_SAVINGSACCOUNTCHARGE'" (click)="editCharge()">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit
</button>
<button mat-raised-button color="warn" *mifosxHasPermission="'DELETE_SAVINGSACCOUNTCHARGE'" (click)="deleteCharge()">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;
Delete
</button>
</div>
<div class="container">
<mat-card>
<mat-card-content>
<div fxLayout="row wrap" class="content">
<div fxFlex="50%" class="mat-body-strong">
Name
</div>
<div fxFlex="50%">
{{ chargeData.name }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Charge Type
</div>
<div fxFlex="50%">
{{ chargeData.penalty ? 'Penalty' : 'Fees' }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Currency
</div>
<div fxFlex="50%">
{{ chargeData.currency.displayLabel }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Payment due at
</div>
<div fxFlex="50%">
{{ chargeData.chargeTimeType.value }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Payment due as of
</div>
<div fxFlex="50%">
{{ chargeData.dueDate | date }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Calculation Type
</div>
<div fxFlex="50%">
{{ chargeData.chargeCalculationType.value }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Due
</div>
<div fxFlex="50%">
{{ chargeData.amount }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Paid
</div>
<div fxFlex="50%">
{{ chargeData.amountPaid }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Waived
</div>
<div fxFlex="50%">
{{ chargeData.amountWaived }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Outstanding
</div>
<div fxFlex="50%">
{{ chargeData.amountOutstanding }}
</div>
</div>
</mat-card-content>
</mat-card>
</div>
@@ -0,0 +1,10 @@
.container {
max-width: 37rem;
.content {
div {
margin: 1rem 0;
word-wrap: break-word;
}
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ViewChargeComponent } from './view-charge.component';
describe('ViewChargeComponent', () => {
let component: ViewChargeComponent;
let fixture: ComponentFixture<ViewChargeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewChargeComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ViewChargeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,179 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
import { DatePipe } from '@angular/common';
/** Custom Services */
import { LoansService } from 'app/loans/loans.service';
/** Custom Dialogs */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component';
/** Custom Models */
import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base';
import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base';
import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicker-base';
/**
* View Charge Component.
*/
@Component({
selector: 'mifosx-view-charge',
templateUrl: './view-charge.component.html',
styleUrls: ['./view-charge.component.scss']
})
export class ViewChargeComponent {
/** Charge data. */
chargeData: any;
/** Loans Account Data */
loansAccountData: any;
/**
* Retrieves the Charge data from `resolve`.
* @param {LoansService} loansService Loans Service
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
* @param {DatePipe} datePipe DatePipe.
*/
constructor(private loansService: LoansService,
private route: ActivatedRoute,
private datePipe: DatePipe,
private router: Router,
public dialog: MatDialog) {
this.route.data.subscribe((data: { loansAccountCharge: any }) => {
this.chargeData = data.loansAccountCharge;
});
this.route.parent.parent.data.subscribe((data: { loanDetailsData: any }) => {
this.loansAccountData = data.loanDetailsData;
});
}
/**
* Pays the charge.
*/
payCharge() {
const formfields: FormfieldBase[] = [
new InputBase({
controlName: 'amount',
label: 'Amount',
value: '',
type: 'number',
required: true
}),
new DatepickerBase({
controlName: 'dueDate',
label: 'Payment Date',
value: '',
type: 'date',
required: true
})
];
const data = {
title: 'Pay Charge',
layout: { addButtonText: 'Confirm' },
formfields: formfields
};
const payChargeDialogRef = this.dialog.open(FormDialogComponent, { data });
payChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const dataObject = {
...response.data.value,
dueDate: this.datePipe.transform(response.data.value.dueDate, dateFormat),
dateFormat,
locale
};
this.loansService.executeLoansAccountChargesCommand(this.chargeData.accountId, 'paycharge', dataObject, this.chargeData.id)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Waive's the charge
*/
waiveCharge() {
const waiveChargeDialogRef = this.dialog.open(ConfirmationDialogComponent, { data: { heading: 'Waive Charge', dialogContext: `Are you sure you want to waive charge with id: ${this.chargeData.id}`, type: 'Basic' } });
waiveChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
this.loansService.executeLoansAccountChargesCommand(this.chargeData.accountId, 'waive', {}, this.chargeData.id)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Edits the charge
*/
editCharge() {
const formfields: FormfieldBase[] = [
new InputBase({
controlName: 'amount',
label: 'Amount',
value: this.chargeData.amount || this.chargeData.amountOrPercentage,
type: 'number',
required: true
})
];
const data = {
title: 'Edit Charge',
layout: { addButtonText: 'Confirm' },
formfields: formfields
};
const editChargeDialogRef = this.dialog.open(FormDialogComponent, { data });
editChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const dataObject = {
...response.data.value,
dateFormat,
locale
};
this.loansService.editLoansAccountCharge(this.loansAccountData.id, dataObject, this.chargeData.id)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Deletes the charge
*/
deleteCharge() {
const deleteChargeDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `charge id:${this.chargeData.id}` }
});
deleteChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.loansService.deleteLoansAccountCharge(this.loansAccountData.id, this.chargeData.id)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Refetches data fot the component
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
*/
private reload() {
const clientId = this.loansAccountData.clientId;
const url: string = this.router.url.replace(`/${this.chargeData.id}`, '');
this.router.navigateByUrl(`/clients/${clientId}/loansaccounts`, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
}
}