From 74b219fe0026700a8f48496542155e271e80feab Mon Sep 17 00:00:00 2001
From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com>
Date: Wed, 8 Jul 2020 09:15:13 +0530
Subject: [PATCH] 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
---
...deposit-confirmation-dialog.component.html | 8 +
...deposit-confirmation-dialog.component.scss | 0
...osit-confirmation-dialog.component.spec.ts | 25 +++
...g-deposit-confirmation-dialog.component.ts | 22 +++
...curring-deposits-account-view.component.ts | 162 ++++++++++++++++++
.../recurring-deposits-buttons.config.ts | 2 +-
.../recurring-deposits.module.ts | 10 +-
.../recurring-deposits.service.ts | 8 +
8 files changed, 235 insertions(+), 2 deletions(-)
create mode 100644 src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.html
create mode 100644 src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.scss
create mode 100644 src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.spec.ts
create mode 100644 src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.html b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.html
new file mode 100644
index 000000000..a50cbd7df
--- /dev/null
+++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.html
@@ -0,0 +1,8 @@
+
{{data.heading}}
+
+
{{ data.dialogContext }}
+
+
+
+
+
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.scss b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.spec.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.spec.ts
new file mode 100644
index 000000000..2005f43bf
--- /dev/null
+++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.spec.ts
@@ -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;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ RecurringDepositConfirmationDialogComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(RecurringDepositConfirmationDialogComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts
new file mode 100644
index 000000000..683a3b764
--- /dev/null
+++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/custom-dialogs/recurring-deposit-confirmation-dialog/recurring-deposit-confirmation-dialog.component.ts
@@ -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,
+ @Inject(MAT_DIALOG_DATA) public data: any) { }
+
+ ngOnInit() {
+ }
+
+}
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts
index aa00a4828..6d8a52e8f 100644
--- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts
+++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts
@@ -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();
+ });
+ }
+ });
+ }
+
}
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-buttons.config.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-buttons.config.ts
index 423d412b6..40b32caa3 100644
--- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-buttons.config.ts
+++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-buttons.config.ts
@@ -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);
}
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits.module.ts b/src/app/deposits/recurring-deposits/recurring-deposits.module.ts
index ad7bfdf83..957177667 100644
--- a/src/app/deposits/recurring-deposits/recurring-deposits.module.ts
+++ b/src/app/deposits/recurring-deposits/recurring-deposits.module.ts
@@ -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]
})
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits.service.ts b/src/app/deposits/recurring-deposits/recurring-deposits.service.ts
index 97e202de6..973b4c965 100644
--- a/src/app/deposits/recurring-deposits/recurring-deposits.service.ts
+++ b/src/app/deposits/recurring-deposits/recurring-deposits.service.ts
@@ -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}
+ */
+ deleteRecurringDepositsAccount(accountId: string): Observable {
+ return this.http.delete(`/recurringdepositaccounts/${accountId}`);
+ }
}