feat: add recurring deposit action buttons (#1022)
- add delete action - add calculate interest action - add post interest action - add enable withhold tax action - add disable withhold tax action Fixes: #1020
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
<h1 mat-dialog-title>{{data.heading}}</h1>
|
||||
<div mat-dialog-content>
|
||||
<p>{{ data.dialogContext }}</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>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RecurringDepositConfirmationDialogComponent } from './recurring-deposit-confirmation-dialog.component';
|
||||
|
||||
describe('RecurringDepositConfirmationDialogComponent', () => {
|
||||
let component: RecurringDepositConfirmationDialogComponent;
|
||||
let fixture: ComponentFixture<RecurringDepositConfirmationDialogComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ RecurringDepositConfirmationDialogComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RecurringDepositConfirmationDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { Component, OnInit, Inject } from '@angular/core';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-recurring-deposit-confirmation-action',
|
||||
templateUrl: './recurring-deposit-confirmation-dialog.component.html',
|
||||
styleUrls: ['./recurring-deposit-confirmation-dialog.component.scss']
|
||||
})
|
||||
export class RecurringDepositConfirmationDialogComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* @param {MatDialogRef} dialogRef Component reference to dialog.
|
||||
* @param {any} data Provides a confirmation for all the recurring deposit actions.
|
||||
*/
|
||||
constructor(public dialogRef: MatDialogRef<DeleteDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any) { }
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
+162
@@ -6,10 +6,16 @@ import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { RecurringDepositsService } from '../recurring-deposits.service';
|
||||
import { SavingsService } from 'app/savings/savings.service';
|
||||
|
||||
/** Custom Buttons Configuration */
|
||||
import { RecurringDepositsButtonsConfiguration } from './recurring-deposits-buttons.config';
|
||||
|
||||
/** Custom Dialogs */
|
||||
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
||||
import { RecurringDepositConfirmationDialogComponent } from './custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component';
|
||||
|
||||
|
||||
/**
|
||||
* RecurringDeposits Account View Component
|
||||
*/
|
||||
@@ -22,10 +28,14 @@ export class RecurringDepositsAccountViewComponent implements OnInit {
|
||||
|
||||
/** RecurringDeposits Account Data */
|
||||
recurringDepositsAccountData: any;
|
||||
/** Button Configuration */
|
||||
buttonConfig: RecurringDepositsButtonsConfiguration;
|
||||
/** Charges Data */
|
||||
charges: any;
|
||||
/** Savings Data Tables */
|
||||
savingsDatatables: any;
|
||||
/** Is Prematured Allowed */
|
||||
isprematureAllowed: any;
|
||||
/**
|
||||
* Fetches recurringDeposits account data from `resolve`
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
@@ -36,11 +46,13 @@ export class RecurringDepositsAccountViewComponent implements OnInit {
|
||||
private router: Router,
|
||||
private datePipe: DatePipe,
|
||||
private recurringDepositsService: RecurringDepositsService,
|
||||
private savingsService: SavingsService,
|
||||
public dialog: MatDialog) {
|
||||
this.route.data.subscribe((data: { recurringDepositsAccountData: any, savingsDatatables: any }) => {
|
||||
this.recurringDepositsAccountData = data.recurringDepositsAccountData;
|
||||
this.charges = this.recurringDepositsAccountData.charges;
|
||||
this.savingsDatatables = data.savingsDatatables;
|
||||
this.isprematureAllowed = data.recurringDepositsAccountData.maturityDate != null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,6 +81,56 @@ export class RecurringDepositsAccountViewComponent implements OnInit {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.recurringDepositsAccountData.clientId && this.recurringDepositsAccountData.status.value === 'Active') {
|
||||
if (this.recurringDepositsAccountData.allowWithdrawal === true) {
|
||||
this.buttonConfig.addOption({
|
||||
name: 'Withdraw'
|
||||
});
|
||||
}
|
||||
if (this.recurringDepositsAccountData.charges) {
|
||||
this.charges.forEach((element: any) => {
|
||||
if (element.name === 'Annual fee - INR') {
|
||||
this.buttonConfig.addOption({
|
||||
name: 'Apply Annual Fees',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.isprematureAllowed) {
|
||||
this.buttonConfig.addOption({
|
||||
name: 'Close',
|
||||
icon: 'fa fa-arrow-right'
|
||||
});
|
||||
}
|
||||
|
||||
if (this.recurringDepositsAccountData.taxGroup) {
|
||||
if (this.recurringDepositsAccountData.withHoldTax) {
|
||||
this.buttonConfig.addOption({
|
||||
name: 'Disable Withhold Tax',
|
||||
taskPermissionName: 'UPDATEWITHHOLDTAX_SAVINGSACCOUNT'
|
||||
});
|
||||
} else {
|
||||
this.buttonConfig.addOption({
|
||||
name: 'Enable Withhold Tax',
|
||||
taskPermissionName: 'UPDATEWITHHOLDTAX_SAVINGSACCOUNT'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Refetches data for the component
|
||||
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
|
||||
*/
|
||||
reload() {
|
||||
const clientId = this.recurringDepositsAccountData.clientId;
|
||||
const url: string = this.router.url;
|
||||
this.router.navigateByUrl(`/clients/${clientId}/recurringdeposits`, { skipLocationChange: true })
|
||||
.then(() => this.router.navigate([url]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +147,107 @@ export class RecurringDepositsAccountViewComponent implements OnInit {
|
||||
case 'Withdraw By Client':
|
||||
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
|
||||
break;
|
||||
case 'Delete':
|
||||
this.deleteRecurringDepositsAccount();
|
||||
break;
|
||||
case 'Calculate Interest':
|
||||
this.calculateInterest();
|
||||
break;
|
||||
case 'Post Interest':
|
||||
this.postInterest();
|
||||
break;
|
||||
case 'Enable Withhold Tax':
|
||||
this.enableWithHoldTax();
|
||||
break;
|
||||
case 'Disable Withhold Tax':
|
||||
this.disableWithHoldTax();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes Recurring Deposits Account.
|
||||
*/
|
||||
private deleteRecurringDepositsAccount() {
|
||||
const deleteRecurringDepositsAccountDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||
data: { deleteContext: `Recurring deposit account with id: ${this.recurringDepositsAccountData.id}` }
|
||||
});
|
||||
deleteRecurringDepositsAccountDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.delete) {
|
||||
this.recurringDepositsService.deleteRecurringDepositsAccount(this.recurringDepositsAccountData.id).subscribe(() => {
|
||||
this.router.navigate(['../../'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates savings account's interest
|
||||
*/
|
||||
private calculateInterest() {
|
||||
const calculateInterestAccountDialogRef = this.dialog.open(RecurringDepositConfirmationDialogComponent, {
|
||||
data: { heading: 'Calculate Interest', dialogContext: `Are you sure you want to calculate interest ?` }
|
||||
});
|
||||
calculateInterestAccountDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.confirm) {
|
||||
this.recurringDepositsService.executeRecurringDepositsAccountCommand(this.recurringDepositsAccountData.id, 'calculateInterest', {}).subscribe(() => {
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts savings account's interest
|
||||
*/
|
||||
private postInterest() {
|
||||
const postInterestAccountDialogRef = this.dialog.open(RecurringDepositConfirmationDialogComponent, {
|
||||
data: { heading: 'Post Interest', dialogContext: 'Are you sure you want to post interest ?' }
|
||||
});
|
||||
postInterestAccountDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.confirm) {
|
||||
this.recurringDepositsService.executeRecurringDepositsAccountCommand(this.recurringDepositsAccountData.id, 'postInterest', {}).subscribe(() => {
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enables withhold tax for recurring deposits account.
|
||||
* Recurring deposits endpoint is not supported so using Savings endpoint.
|
||||
*/
|
||||
private enableWithHoldTax() {
|
||||
const deleteSavingsAccountDialogRef = this.dialog.open(RecurringDepositConfirmationDialogComponent, {
|
||||
data: { heading: 'Enable Withhold Tax', dialogContext: `Enable withhold tax for this account ?` }
|
||||
});
|
||||
deleteSavingsAccountDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.confirm) {
|
||||
this.savingsService.executeSavingsAccountUpdateCommand(this.recurringDepositsAccountData.id, 'updateWithHoldTax', { withHoldTax: true })
|
||||
.subscribe(() => {
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables withhold tax for recurring deposits account
|
||||
* Recurring deposits endpoint is not supported so using Savings endpoint.
|
||||
*/
|
||||
private disableWithHoldTax() {
|
||||
const disableWithHoldTaxDialogRef = this.dialog.open(RecurringDepositConfirmationDialogComponent, {
|
||||
data: { heading: 'Disable Withhold Tax', dialogContext: 'Disable withhold tax for this account ?' }
|
||||
});
|
||||
disableWithHoldTaxDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.confirm) {
|
||||
this.savingsService.executeSavingsAccountUpdateCommand(this.recurringDepositsAccountData.id, 'updateWithHoldTax', { withHoldTax: false })
|
||||
.subscribe(() => {
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ export class RecurringDepositsButtonsConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
addOption(option: {name: string, taskPermissionName?: string}) {
|
||||
addOption(option: {name: string, icon?: string, taskPermissionName?: string}) {
|
||||
this.optionArray.push(option);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,10 @@ import { RejectRecurringDepositsAccountComponent } from './recurring-deposits-ac
|
||||
import { WithdrawByClientRecurringDepositsAccountComponent } from './recurring-deposits-account-actions/withdraw-by-client-recurring-deposits-account/withdraw-by-client-recurring-deposits-account.component';
|
||||
import { AddChargeRecurringDepositsAccountComponent } from './recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component';
|
||||
|
||||
/* Dialog Components */
|
||||
import { RecurringDepositConfirmationDialogComponent } from './recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component';
|
||||
|
||||
|
||||
/**
|
||||
* RecurringDeposits Module
|
||||
*
|
||||
@@ -68,7 +72,11 @@ import { AddChargeRecurringDepositsAccountComponent } from './recurring-deposits
|
||||
ApproveRecurringDepositsAccountComponent,
|
||||
RejectRecurringDepositsAccountComponent,
|
||||
WithdrawByClientRecurringDepositsAccountComponent,
|
||||
AddChargeRecurringDepositsAccountComponent
|
||||
AddChargeRecurringDepositsAccountComponent,
|
||||
RecurringDepositConfirmationDialogComponent
|
||||
],
|
||||
entryComponents: [
|
||||
RecurringDepositConfirmationDialogComponent
|
||||
],
|
||||
providers: [DatePipe]
|
||||
})
|
||||
|
||||
@@ -75,4 +75,12 @@ export class RecurringDepositsService {
|
||||
const httpParams = new HttpParams().set('command', command);
|
||||
return this.http.post(`/recurringdepositaccounts/${accountId}`, data, { params: httpParams });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} accountId recurring deposits account Id
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
deleteRecurringDepositsAccount(accountId: string): Observable<any> {
|
||||
return this.http.delete(`/recurringdepositaccounts/${accountId}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user