feat: fixed deposit account charges actions (#991)

Fixes: 990
This commit is contained in:
Karan Takalkar
2020-07-04 18:07:23 +05:30
committed by GitHub
parent 18a6e6f487
commit 380d09c22e
23 changed files with 352 additions and 152 deletions
@@ -68,22 +68,27 @@
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let charge">
<span *ngIf="fixedDepositsAccountData.status.value === 'Submitted and pending approval'">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Edit Charge">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Edit Charge"
*mifosxHasPermission="'UPDATE_SAVINGSACCOUNTCHARGE'" (click)="routeEdit($event); editCharge(charge)">
<i class="fa fa-pencil"></i>
</button>
<button class="account-action-button" mat-raised-button color="warn" matTooltip="Delete Charge">
<button class="account-action-button" mat-raised-button color="warn" matTooltip="Delete Charge"
*mifosxHasPermission="'DELETE_SAVINGSACCOUNTCHARGE'" (click)="routeEdit($event); deleteCharge(charge.id)">
<i class="fa fa-trash"></i>
</button>
</span>
<span *ngIf="fixedDepositsAccountData.status.value === 'Active' && charge.amountOutstanding !== 0">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Pay Charge">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Pay Charge"
*mifosxHasPermission="'PAY_SAVINGSACCOUNTCHARGE'" (click)="routeEdit($event); payCharge(charge.id)">
<i class="fa fa-dollar"></i>
</button>
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Waive Charge">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Waive Charge"
*mifosxHasPermission="'WAIVE_SAVINGSACCOUNTCHARGE'" (click)="routeEdit($event); 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">
<button class="account-action-button" mat-raised-button color="primary" matTooltip="Inactivate Charge"
*mifosxHasPermission="'INACTIVATE_SAVINGSACCOUNTCHARGE'" (click)="routeEdit($event); inactivateCharge(charge.id)">
<i class="fa fa-ban"></i>
</button>
</ng-container>
@@ -1,10 +1,26 @@
/** 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';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-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
* Note: Fixed deposits endpoints are not supported so using Savings endpoints.
*/
@Component({
selector: 'mifosx-charges-tab',
@@ -40,10 +56,18 @@ export class ChargesTabComponent implements OnInit {
@ViewChild('chargesTable') chargesTableRef: MatTable<Element>;
/**
* Retrieves Fixed Deposits Account Data from `resolve`.
* Retrieves the Fixed Deposits 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: { fixedDepositsAccountData: any }) => {
this.fixedDepositsAccountData = data.fixedDepositsAccountData;
this.chargesData = this.fixedDepositsAccountData.charges;
@@ -70,6 +94,138 @@ 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.fixedDepositsAccountData.id, 'paycharge', dataObject, chargeId)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* 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.fixedDepositsAccountData.id, 'waive', {}, chargeId)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* 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.fixedDepositsAccountData.id, 'inactivate', {}, chargeId)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Edits the charge
* @param {any} charge Charge
*/
editCharge(charge: any) {
const formfields: FormfieldBase[] = [
new InputBase({
controlName: 'amount',
label: 'Amount',
value: charge.amount || charge.amountOrPercentage,
type: 'number',
required: true
})
];
const data = {
title: `Edit Charge ${charge.id}`,
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.savingsService.editSavingsAccountCharge(this.fixedDepositsAccountData.id, dataObject, charge.id)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Deletes the charge
* @param {any} chargeId Charge Id
*/
deleteCharge(chargeId: any) {
const deleteChargeDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `charge id:${chargeId}` }
});
deleteChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.savingsService.deleteSavingsAccountCharge(this.fixedDepositsAccountData.id, chargeId)
.subscribe(() => {
this.reload();
});
}
});
}
/**
* Checks if charge is recurring.
* @param {any} charge Charge
@@ -78,4 +234,23 @@ export class ChargesTabComponent implements OnInit {
return charge.chargeTimeType.value === 'Monthly Fee' || charge.chargeTimeType.value === 'Annual Fee' || charge.chargeTimeType.value === 'Weekly Fee';
}
/**
* Stops the propagation to view charge page.
* @param $event Mouse Event
*/
routeEdit($event: MouseEvent) {
$event.stopPropagation();
}
/**
* Refetches data fot the component
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
*/
private reload() {
const clientId = this.fixedDepositsAccountData.clientId;
const url: string = this.router.url;
this.router.navigateByUrl(`/clients/${clientId}/fixed-deposits-accounts`, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
}
}
@@ -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) { }
}
@@ -1,8 +0,0 @@
<h1 mat-dialog-title>Undo Transaction</h1>
<div mat-dialog-content>
<p>Are you sure you want to undo this transaction ?</p>
</div>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="warn" [mat-dialog-close]="{ confirm: true }">Confirm</button>
</mat-dialog-actions>
@@ -1,25 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UndoTransactionDialogComponent } from './undo-transaction-dialog.component';
describe('UndoTransactionDialogComponent', () => {
let component: UndoTransactionDialogComponent;
let fixture: ComponentFixture<UndoTransactionDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UndoTransactionDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UndoTransactionDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -1,20 +0,0 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { MatDialogRef } from '@angular/material';
/**
* Undo transaction dialog component.
*/
@Component({
selector: 'mifosx-undo-transaction-dialog',
templateUrl: './undo-transaction-dialog.component.html',
styleUrls: ['./undo-transaction-dialog.component.scss']
})
export class UndoTransactionDialogComponent {
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
*/
constructor(public dialogRef: MatDialogRef<UndoTransactionDialogComponent>) { }
}
@@ -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) { }
}
@@ -59,7 +59,7 @@
<div fxFlex="49%" fxLayout="column" fxLayoutGap="4%">
<div>
<h4 class="table-headers">Fixed Deposits Details</h4>
<h4 class="table-headers">Fixed Deposit Details</h4>
<table>
<tbody>
<tr>
@@ -1,5 +1,11 @@
<div class="tab-container mat-typography">
<div fxLayoutAlign="start">
<div class="m-b-20">
<h3>All Interest Rates</h3>
</div>
</div>
<div class="mat-elevation-z1 m-b-25">
<table mat-table [dataSource]="dataSource" >
@@ -1,5 +1,11 @@
<div class="tab-container mat-typography">
<div fxLayoutAlign="start">
<div class="m-b-20">
<h3>All Transactions</h3>
</div>
</div>
<div class="mat-elevation-z1 m-b-25">
<table mat-table [dataSource]="dataSource" >
@@ -1,68 +0,0 @@
/** 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 { FixedDepositsService } from 'app/deposits/fixed-deposits/fixed-deposits.service';
/** Custom Dialogs */
import { UndoTransactionDialogComponent } from '../../custom-dialogs/undo-transaction-dialog/undo-transaction-dialog.component';
/**
* View Transaction Component.
* TODO: Add support for account transfers.
*/
@Component({
selector: 'mifosx-view-transaction',
templateUrl: './view-transaction.component.html',
styleUrls: ['./view-transaction.component.scss']
})
export class ViewTransactionComponent {
/** Transaction data. */
transactionData: any;
/**
* Retrieves the Transaction data from `resolve`.
* @param {FixedDepositsService} fixedDepositsService Savings Service
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
* @param {DatePipe} datePipe DatePipe.
*/
constructor(private fixedDepositsService: FixedDepositsService,
private route: ActivatedRoute,
private datePipe: DatePipe,
private router: Router,
public dialog: MatDialog) {
this.route.data.subscribe((data: { fixedDepositsAccountTransaction: any }) => {
this.transactionData = data.fixedDepositsAccountTransaction;
});
}
/**
* Undo the savings transaction
*/
undoTransaction() {
const accountId = this.route.parent.snapshot.params['fixedDepositAccountId'];
const undoTransactionAccountDialogRef = this.dialog.open(UndoTransactionDialogComponent);
undoTransactionAccountDialogRef.afterClosed().subscribe((response: any) => {
if (response.confirm) {
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const data = {
transactionDate: this.datePipe.transform(this.transactionData.date && new Date(this.transactionData.date), dateFormat),
transactionAmount: 0,
dateFormat,
locale
};
this.fixedDepositsService.executeFixedDepositsAccountTransactionsCommand(accountId, 'undo', data, this.transactionData.id).subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
});
}
}
@@ -1,19 +1,3 @@
<div fxLayoutAlign="end" class="container m-b-20" fxLayoutGap="2%"
*ngIf="!(transactionData.reversed)">
<span *mifosxHasPermission="'ADJUSTTRANSACTION_SAVINGSACCOUNT'">
<button mat-raised-button color="primary"
*ngIf="transactionData.transactionType.value == 'Transfer' || transactionData.reversed == 'true'"
[routerLink]="'edit'">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;Edit
</button>
</span>
<button mat-raised-button color="warn"
*mifosxHasPermission="'UNDOTRANSACTION_SAVINGSACCOUNT'"
(click)="undoTransaction()">
<fa-icon icon="undo"></fa-icon>&nbsp;&nbsp;Undo
</button>
</div>
<div class="container">
<mat-card>
@@ -0,0 +1,32 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatDialog } from '@angular/material';
/**
* View Transaction Component.
* TODO: Add support for account transfers.
*/
@Component({
selector: 'mifosx-view-transaction',
templateUrl: './view-transaction.component.html',
styleUrls: ['./view-transaction.component.scss']
})
export class ViewTransactionComponent {
/** Transaction data. */
transactionData: any;
/**
* Retrieves the Transaction data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
* @param {MatDialog} dialog Dialog reference.
*/
constructor(private route: ActivatedRoute,
public dialog: MatDialog) {
this.route.data.subscribe((data: { fixedDepositsAccountTransaction: any }) => {
this.transactionData = data.fixedDepositsAccountTransaction;
});
}
}
@@ -13,7 +13,7 @@ import { ChargesTabComponent } from './fixed-deposit-account-view/charges-tab/ch
import { StandingInstructionsTabComponent } from './fixed-deposit-account-view/standing-instructions-tab/standing-instructions-tab.component';
import { DatatableTabsComponent } from './fixed-deposit-account-view/datatable-tabs/datatable-tabs.component';
import { FixedDepositsAccountActionsComponent } from './fixed-deposits-account-actions/fixed-deposits-account-actions.component';
import { ViewTransactionComponent } from './fixed-deposit-account-view/transactions/view-transaction/view-transaction.component';
import { ViewTransactionComponent } from './fixed-deposit-account-view/view-transaction/view-transaction.component';
/** Custom Resolvers */
import { FixedDepositsAccountViewResolver } from '../fixed-deposits/common-resolvers/fixed-deposit-account-view.resolver';
@@ -26,8 +26,9 @@ import { ToggleWithholdTaxDialogComponent } from './fixed-deposit-account-view/c
import { ActivateFixedDepositsAccountComponent } from './fixed-deposits-account-actions/activate-fixed-deposits-account/activate-fixed-deposits-account.component';
import { UndoApprovalFixedDepositsAccountComponent } from './fixed-deposits-account-actions/undo-approval-fixed-deposits-account/undo-approval-fixed-deposits-account.component';
import { WithdrawByClientFixedDepositsAccountComponent } from './fixed-deposits-account-actions/withdraw-by-client-fixed-deposits-account/withdraw-by-client-fixed-deposits-account.component';
import { ViewTransactionComponent } from './fixed-deposit-account-view/transactions/view-transaction/view-transaction.component';
import { UndoTransactionDialogComponent } from './fixed-deposit-account-view/custom-dialogs/undo-transaction-dialog/undo-transaction-dialog.component';
import { ViewTransactionComponent } from './fixed-deposit-account-view/view-transaction/view-transaction.component';
import { WaiveChargeDialogComponent } from './fixed-deposit-account-view/custom-dialogs/waive-charge-dialog/waive-charge-dialog.component';
import { InactivateChargeDialogComponent } from './fixed-deposit-account-view/custom-dialogs/inactivate-charge-dialog/inactivate-charge-dialog.component';
@NgModule({
declarations: [
@@ -49,7 +50,8 @@ import { UndoTransactionDialogComponent } from './fixed-deposit-account-view/cus
UndoApprovalFixedDepositsAccountComponent,
WithdrawByClientFixedDepositsAccountComponent,
ViewTransactionComponent,
UndoTransactionDialogComponent
WaiveChargeDialogComponent,
InactivateChargeDialogComponent
],
imports: [
SharedModule,
@@ -61,7 +63,8 @@ import { UndoTransactionDialogComponent } from './fixed-deposit-account-view/cus
PostInterestDialogComponent,
CalculateInterestDialogComponent,
ToggleWithholdTaxDialogComponent,
UndoTransactionDialogComponent
WaiveChargeDialogComponent,
InactivateChargeDialogComponent
],
providers: [DatePipe]
})