feat: savings account view charge (#939)

Fixes: #938
This commit is contained in:
Karan Takalkar
2020-06-27 23:22:22 +05:30
committed by GitHub
parent 6ed67a763d
commit 222681b916
21 changed files with 602 additions and 14 deletions
@@ -79,16 +79,16 @@
</span>
<span *ngIf="savingsAccountData.status.value === 'Active' && charge.amountOutstanding !== 0">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Pay Charge"
*mifosxHasPermission="'PAY_SAVINGSACCOUNTCHARGE'">
*mifosxHasPermission="'PAY_SAVINGSACCOUNTCHARGE'" (click)="payCharge(charge.id)">
<i class="fa fa-dollar"></i>
</button>
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Waive Charge"
*mifosxHasPermission="'WAIVE_SAVINGSACCOUNTCHARGE'">
*mifosxHasPermission="'WAIVE_SAVINGSACCOUNTCHARGE'" (click)="waiveCharge(charge.id)">
<i class="fa fa-flag"></i>
</button>
<ng-container *ngIf="isRecurringCharge(charge)">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Inactivate Charge"
*mifosxHasPermission="'INACTIVATE_SAVINGSACCOUNTCHARGE'">
*mifosxHasPermission="'INACTIVATE_SAVINGSACCOUNTCHARGE'" (click)="inactivateCharge(charge.id)">
<i class="fa fa-ban"></i>
</button>
</ng-container>
@@ -97,7 +97,7 @@
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row" [routerLink]="[row.id]"></tr>
</table>
@@ -15,5 +15,8 @@
margin: 4px;
line-height: 25px;
}
.select-row:hover {
cursor: pointer;
}
}
}
@@ -1,7 +1,21 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatTable } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog, MatTableDataSource, MatTable } from '@angular/material';
import { DatePipe } from '@angular/common';
/** Custom Services */
import { SavingsService } from 'app/savings/savings.service';
/** Custom Dialogs */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
import { WaiveChargeDialogComponent } from '../custom-dialogs/waive-charge-dialog/waive-charge-dialog.component';
import { InactivateChargeDialogComponent } from '../custom-dialogs/inactivate-charge-dialog/inactivate-charge-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';
/**
* Charges Tab Component
@@ -40,10 +54,18 @@ export class ChargesTabComponent implements OnInit {
@ViewChild('chargesTable') chargesTableRef: MatTable<Element>;
/**
* Retrieves Savings Account Data from `resolve`.
* Retrieves the Savings account data from `resolve`.
* @param {SavingsService} savingsService Savings Service
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
* @param {DatePipe} datePipe DatePipe.
*/
constructor(private route: ActivatedRoute) {
constructor(private savingsService: SavingsService,
private route: ActivatedRoute,
private datePipe: DatePipe,
private router: Router,
public dialog: MatDialog) {
this.route.parent.data.subscribe((data: { savingsAccountData: any }) => {
this.savingsAccountData = data.savingsAccountData;
this.chargesData = this.savingsAccountData.charges;
@@ -70,6 +92,84 @@ export class ChargesTabComponent implements OnInit {
this.chargesTableRef.renderRows();
}
/**
* Pays the charge.
* @param {any} chargeId Charge Id
*/
payCharge(chargeId: any) {
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 ${chargeId}`,
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.savingsService.executeSavingsAccountChargesCommand(this.savingsAccountData.id, 'paycharge', dataObject, chargeId)
.subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
/**
* Waive's the charge
* @param {any} chargeId Charge Id
*/
waiveCharge(chargeId: any) {
const waiveChargeDialogRef = this.dialog.open(WaiveChargeDialogComponent, { data: { id: chargeId } });
waiveChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
this.savingsService.executeSavingsAccountChargesCommand(this.savingsAccountData.id, 'waive', {}, chargeId)
.subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
/**
* Inactivate's the charge
* @param {any} chargeId Charge Id
*/
inactivateCharge(chargeId: any) {
const inactivateChargeDialogRef = this.dialog.open(InactivateChargeDialogComponent, { data: { id: chargeId } });
inactivateChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
this.savingsService.executeSavingsAccountChargesCommand(this.savingsAccountData.id, 'inactivate', {}, chargeId)
.subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
/**
* Checks if charge is recurring.
* @param {any} charge Charge
@@ -0,0 +1,8 @@
<h1 mat-dialog-title>Inactivate Charge</h1>
<div mat-dialog-content>
<p>Are you sure you want to inactivate charge with id: {{ data.id }} ?</p>
</div>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="primary" [mat-dialog-close]="{ confirm: true }">Confirm</button>
</mat-dialog-actions>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { InactivateChargeDialogComponent } from './inactivate-charge-dialog.component';
describe('InactivateChargeDialogComponent', () => {
let component: InactivateChargeDialogComponent;
let fixture: ComponentFixture<InactivateChargeDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ InactivateChargeDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(InactivateChargeDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,22 @@
/** Angular Imports */
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
/**
* Inactivate charge dialog component.
*/
@Component({
selector: 'mifosx-inactivate-charge-dialog',
templateUrl: './inactivate-charge-dialog.component.html',
styleUrls: ['./inactivate-charge-dialog.component.scss']
})
export class InactivateChargeDialogComponent {
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {any} data.
*/
constructor(public dialogRef: MatDialogRef<InactivateChargeDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
}
@@ -0,0 +1,8 @@
<h1 mat-dialog-title>Waive Charge</h1>
<div mat-dialog-content>
<p>Are you sure you want to waive charge with id: {{ data.id }} ?</p>
</div>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="primary" [mat-dialog-close]="{ confirm: true }">Confirm</button>
</mat-dialog-actions>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { WaiveChargeDialogComponent } from './waive-charge-dialog.component';
describe('WaiveChargeDialogComponent', () => {
let component: WaiveChargeDialogComponent;
let fixture: ComponentFixture<WaiveChargeDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WaiveChargeDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WaiveChargeDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,22 @@
/** Angular Imports */
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
/**
* Waive charge dialog component.
*/
@Component({
selector: 'mifosx-waive-charge-dialog',
templateUrl: './waive-charge-dialog.component.html',
styleUrls: ['./waive-charge-dialog.component.scss']
})
export class WaiveChargeDialogComponent {
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {any} data.
*/
constructor(public dialogRef: MatDialogRef<WaiveChargeDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
}
@@ -0,0 +1,116 @@
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
<span *ngIf="savingsAccountData.status.value === 'Active' && chargeData.amountOutstanding !== 0">
<button mat-raised-button color="accent" *mifosxHasPermission="'PAY_SAVINGSACCOUNTCHARGE'" (click)="payCharge()">
<fa-icon icon="dollar-sign"></fa-icon>&nbsp;&nbsp;
Pay Charge
</button>
<button mat-raised-button color="primary" *mifosxHasPermission="'WAIVE_SAVINGSACCOUNTCHARGE'" (click)="waiveCharge()">
<fa-icon icon="flag"></fa-icon>&nbsp;&nbsp;
Waive Charge
</button>
<span *ngIf="isRecurringCharge()">
<button mat-raised-button color="warn" *mifosxHasPermission="'INACTIVATE_SAVINGSACCOUNTCHARGE'" (click)="inactivateCharge()">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;
Inactivate Charge
</button>
</span>
</span>
</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,136 @@
/** 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 { SavingsService } from 'app/savings/savings.service';
/** Custom Dialogs */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
import { WaiveChargeDialogComponent } from '../custom-dialogs/waive-charge-dialog/waive-charge-dialog.component';
import { InactivateChargeDialogComponent } from '../custom-dialogs/inactivate-charge-dialog/inactivate-charge-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;
/** Savings Account Data */
savingsAccountData: any;
/**
* Retrieves the Charge data from `resolve`.
* @param {SavingsService} savingsService Savings Service
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
* @param {DatePipe} datePipe DatePipe.
*/
constructor(private savingsService: SavingsService,
private route: ActivatedRoute,
private datePipe: DatePipe,
private router: Router,
public dialog: MatDialog) {
this.route.data.subscribe((data: { savingsAccountCharge: any, savingsAccountData: any }) => {
this.chargeData = data.savingsAccountCharge;
this.savingsAccountData = data.savingsAccountData;
});
}
/**
* 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.savingsService.executeSavingsAccountChargesCommand(this.chargeData.accountId, 'paycharge', dataObject, this.chargeData.id)
.subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
/**
* Waive's the charge
*/
waiveCharge() {
const waiveChargeDialogRef = this.dialog.open(WaiveChargeDialogComponent, { data: { id: this.chargeData.id } });
waiveChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
this.savingsService.executeSavingsAccountChargesCommand(this.chargeData.accountId, 'waive', {}, this.chargeData.id)
.subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
/**
* Inactivate's the charge
*/
inactivateCharge() {
const inactivateChargeDialogRef = this.dialog.open(InactivateChargeDialogComponent, { data: { id: this.chargeData.id } });
inactivateChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
this.savingsService.executeSavingsAccountChargesCommand(this.chargeData.accountId, 'inactivate', {}, this.chargeData.id)
.subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
/**
* Checks if charge is recurring
*/
isRecurringCharge() {
const chargeTimeType = this.chargeData.chargeTimeType.value;
return chargeTimeType === 'Monthly Fee' || chargeTimeType === 'Annual Fee' || chargeTimeType === 'Weekly Fee';
}
}