382 lines
13 KiB
TypeScript
382 lines
13 KiB
TypeScript
/**
|
|
* Copyright since 2025 Mifos Initiative
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
/** Angular Imports */
|
|
import { Component, OnInit, inject } from '@angular/core';
|
|
import { ActivatedRoute, Router, RouterLinkActive, RouterLink, RouterOutlet } from '@angular/router';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
|
import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component';
|
|
import { CalculateInterestDialogComponent } from './custom-dialogs/calculate-interest-dialog/calculate-interest-dialog.component';
|
|
import { PostInterestDialogComponent } from './custom-dialogs/post-interest-dialog/post-interest-dialog.component';
|
|
import { ToggleWithholdTaxDialogComponent } from './custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component';
|
|
|
|
/** Custom Button Config. */
|
|
import { FixedDepositsButtonsConfiguration } from './fixed-deposits-buttons.config';
|
|
|
|
/** Custom Services */
|
|
import { FixedDepositsService } from '../fixed-deposits.service';
|
|
import { SavingsService } from 'app/savings/savings.service';
|
|
import { AccountsService } from 'app/accounts/accounts.service';
|
|
import { Currency } from 'app/shared/models/general.model';
|
|
import { SettingsService } from 'app/settings/settings.service';
|
|
import { Dates } from 'app/core/utils/dates';
|
|
import { AuthenticationService } from '../../../core/authentication/authentication.service';
|
|
import { MatTooltip } from '@angular/material/tooltip';
|
|
import { NgClass, CurrencyPipe } from '@angular/common';
|
|
import { AccountNumberComponent } from '../../../shared/account-number/account-number.component';
|
|
import { LongTextComponent } from '../../../shared/long-text/long-text.component';
|
|
import { MatIconButton } from '@angular/material/button';
|
|
import { MatMenuTrigger, MatMenu, MatMenuItem } from '@angular/material/menu';
|
|
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
|
import { MatTabNav, MatTabLink, MatTabNavPanel } from '@angular/material/tabs';
|
|
import { StatusLookupPipe } from '../../../pipes/status-lookup.pipe';
|
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|
import { DormancyAlertPanelComponent } from 'app/shared/dormancy-alert-panel/dormancy-alert-panel.component';
|
|
|
|
/**
|
|
* Fixed Deposits Account View Component
|
|
*/
|
|
@Component({
|
|
selector: 'mifosx-fixed-deposit-account-view',
|
|
templateUrl: './fixed-deposit-account-view.component.html',
|
|
styleUrls: ['./fixed-deposit-account-view.component.scss'],
|
|
imports: [
|
|
...STANDALONE_SHARED_IMPORTS,
|
|
MatTooltip,
|
|
NgClass,
|
|
LongTextComponent,
|
|
AccountNumberComponent,
|
|
MatIconButton,
|
|
MatMenuTrigger,
|
|
FaIconComponent,
|
|
MatMenu,
|
|
MatMenuItem,
|
|
MatTabNav,
|
|
MatTabLink,
|
|
RouterLinkActive,
|
|
MatTabNavPanel,
|
|
RouterOutlet,
|
|
CurrencyPipe,
|
|
StatusLookupPipe,
|
|
DormancyAlertPanelComponent
|
|
]
|
|
})
|
|
export class FixedDepositAccountViewComponent implements OnInit {
|
|
private route = inject(ActivatedRoute);
|
|
private router = inject(Router);
|
|
private fixedDepositsService = inject(FixedDepositsService);
|
|
private savingsService = inject(SavingsService);
|
|
private accountsService = inject(AccountsService);
|
|
private settingsService = inject(SettingsService);
|
|
private dateUtils = inject(Dates);
|
|
private authenticationService = inject(AuthenticationService);
|
|
dialog = inject(MatDialog);
|
|
|
|
/** Fixed Deposits Account Data */
|
|
fixedDepositsAccountData: any;
|
|
/** Savings Data Tables */
|
|
savingsDatatables: any;
|
|
/** Button Configurations */
|
|
buttonConfig: FixedDepositsButtonsConfiguration;
|
|
/** Entity Type */
|
|
entityType: string;
|
|
currency: Currency;
|
|
showTransactions = false;
|
|
|
|
private readonly ACTION_KIND: Record<string, 'transact' | 'block' | 'interest' | 'admin' | 'danger'> = {
|
|
Deposit: 'transact',
|
|
Withdrawal: 'transact',
|
|
'Transfer Funds': 'transact',
|
|
'Calculate Interest': 'interest',
|
|
'Post Interest': 'interest',
|
|
'Enable Withhold Tax': 'interest',
|
|
'Disable Withhold Tax': 'interest',
|
|
'Premature Close': 'danger',
|
|
'Undo Activation': 'admin',
|
|
Close: 'danger',
|
|
'Modify Application': 'admin',
|
|
Approve: 'admin',
|
|
'Undo Approval': 'admin',
|
|
Activate: 'admin',
|
|
'Add Charge': 'admin',
|
|
'Apply Annual Fees': 'admin',
|
|
Reject: 'danger',
|
|
'Withdrawn by Client': 'danger',
|
|
Delete: 'danger',
|
|
Terminate: 'danger'
|
|
};
|
|
|
|
private readonly ACTION_ICON: Record<string, string> = {
|
|
Deposit: 'arrow-down',
|
|
Withdrawal: 'arrow-up',
|
|
'Transfer Funds': 'exchange-alt',
|
|
'Calculate Interest': 'calculator',
|
|
'Post Interest': 'percentage',
|
|
'Enable Withhold Tax': 'percentage',
|
|
'Disable Withhold Tax': 'percentage',
|
|
'Premature Close': 'times-circle',
|
|
'Undo Activation': 'undo',
|
|
Close: 'times-circle',
|
|
'Modify Application': 'edit',
|
|
Approve: 'check-circle',
|
|
'Undo Approval': 'undo',
|
|
Activate: 'check',
|
|
'Add Charge': 'plus-circle',
|
|
'Apply Annual Fees': 'receipt',
|
|
Reject: 'ban',
|
|
'Withdrawn by Client': 'user-slash',
|
|
Delete: 'trash',
|
|
Terminate: 'times-circle'
|
|
};
|
|
|
|
kindOf(name: string): 'transact' | 'block' | 'interest' | 'admin' | 'danger' {
|
|
return this.ACTION_KIND[name] ?? 'admin';
|
|
}
|
|
|
|
iconOf(name: string, fallback?: string): string {
|
|
return this.ACTION_ICON[name] ?? fallback ?? 'circle';
|
|
}
|
|
|
|
hasKind(kind: 'transact' | 'block' | 'interest' | 'admin' | 'danger'): boolean {
|
|
const all = [
|
|
...(this.buttonConfig?.singleButtons ?? []),
|
|
...(this.buttonConfig?.options ?? [])
|
|
];
|
|
return all.some((item) => this.kindOf(item.name) === kind);
|
|
}
|
|
|
|
/**
|
|
* Fetches fixed deposits account data from `resolve`
|
|
* @param {ActivatedRoute} route Activated Route
|
|
* @param {Router} router Router
|
|
* @param {FixedDepositsService} fixedDepositsService Fixed Deposits Service
|
|
* @param {SavingsService} savingsService Savings Service
|
|
* @param {MatDialog} dialog Mat Dialog
|
|
*/
|
|
constructor() {
|
|
this.route.data.subscribe((data: { fixedDepositsAccountData: any; savingsDatatables: any }) => {
|
|
this.fixedDepositsAccountData = data.fixedDepositsAccountData;
|
|
this.savingsDatatables = data.savingsDatatables;
|
|
this.currency = this.fixedDepositsAccountData.currency;
|
|
const status: any = data.fixedDepositsAccountData.status;
|
|
this.showTransactions = status.id >= 300;
|
|
});
|
|
if (this.router.url.includes('clients')) {
|
|
this.entityType = 'Client';
|
|
} else if (this.router.url.includes('groups')) {
|
|
this.entityType = 'Group';
|
|
} else if (this.router.url.includes('centers')) {
|
|
this.entityType = 'Center';
|
|
}
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.setConditionalButtons();
|
|
}
|
|
|
|
/**
|
|
* Adds options to button config. conditionaly.
|
|
*/
|
|
setConditionalButtons() {
|
|
const status = this.fixedDepositsAccountData.status.value;
|
|
this.buttonConfig = new FixedDepositsButtonsConfiguration(status);
|
|
if (this.fixedDepositsAccountData.taxGroup && status === 'Active') {
|
|
if (this.fixedDepositsAccountData.withHoldTax) {
|
|
this.buttonConfig.addOption({
|
|
name: 'Disable Withhold Tax'
|
|
});
|
|
} else {
|
|
this.buttonConfig.addOption({
|
|
name: 'Enable Withhold Tax'
|
|
});
|
|
}
|
|
}
|
|
if (!this.authenticationService.hasCashierRole()) {
|
|
this.buttonConfig.buttonsArray = this.buttonConfig.buttonsArray.filter(
|
|
(btn) => btn.name !== 'Deposit' && btn.name !== 'Withdrawal'
|
|
);
|
|
this.buttonConfig.optionArray = this.buttonConfig.optionArray.filter(
|
|
(opt) => opt.name !== 'Deposit' && opt.name !== 'Withdrawal'
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Refetches data fot the component
|
|
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
|
|
*/
|
|
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]));
|
|
}
|
|
|
|
/**
|
|
* Performs action button/option action.
|
|
* @param {string} name action name.
|
|
*/
|
|
doAction(name: string) {
|
|
switch (name) {
|
|
case 'Approve':
|
|
case 'Reject':
|
|
case 'Activate':
|
|
case 'Close':
|
|
case 'Undo Approval':
|
|
case 'Undo Activation':
|
|
case 'Add Charge':
|
|
case 'Withdrawn by Client':
|
|
case 'Premature Close':
|
|
case 'Deposit':
|
|
case 'Withdrawal':
|
|
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
|
|
break;
|
|
case 'Modify Application':
|
|
this.router.navigate(['edit'], { relativeTo: this.route });
|
|
break;
|
|
case 'Delete':
|
|
this.deleteFixedDepositsAccount();
|
|
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;
|
|
case 'Terminate':
|
|
this.terminateFixedDepositsAccount();
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Deletes Fixed Deposits Account.
|
|
*/
|
|
private deleteFixedDepositsAccount() {
|
|
const deleteFixedDepositsAccountDialogRef = this.dialog.open(DeleteDialogComponent, {
|
|
data: { deleteContext: `fixed deposit account with id: ${this.fixedDepositsAccountData.id}` }
|
|
});
|
|
deleteFixedDepositsAccountDialogRef.afterClosed().subscribe((response: any) => {
|
|
if (response.delete) {
|
|
this.fixedDepositsService.deleteFixedDepositsAccount(this.fixedDepositsAccountData.id).subscribe(() => {
|
|
this.router.navigate(['../../'], { relativeTo: this.route });
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
private terminateFixedDepositsAccount() {
|
|
const terminateFixedDepositAccountDialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
data: {
|
|
heading: 'Terminate Account',
|
|
dialogContext: 'Are you sure you want to terminate this account?',
|
|
type: 'Strong'
|
|
}
|
|
});
|
|
terminateFixedDepositAccountDialogRef.afterClosed().subscribe((response: any) => {
|
|
if (response && response.confirm) {
|
|
const locale = this.settingsService.language.code;
|
|
const dateFormat = this.settingsService.dateFormat;
|
|
const terminatedOnDate = this.dateUtils.formatDate(new Date(), dateFormat);
|
|
const data = {
|
|
accountType: 'FD',
|
|
terminatedOnDate,
|
|
dateFormat,
|
|
locale
|
|
};
|
|
this.accountsService.terminateAccount(this.fixedDepositsAccountData.id, data).subscribe(() => {
|
|
this.reload();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Calculates fixed deposit account's interest
|
|
*/
|
|
private calculateInterest() {
|
|
const calculateInterestAccountDialogRef = this.dialog.open(CalculateInterestDialogComponent);
|
|
calculateInterestAccountDialogRef.afterClosed().subscribe((response: any) => {
|
|
if (response.confirm) {
|
|
this.fixedDepositsService
|
|
.executeFixedDepositsAccountCommand(this.fixedDepositsAccountData.id, 'calculateInterest', {})
|
|
.subscribe(() => {
|
|
this.reload();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Posts fixed deposit account's interest
|
|
*/
|
|
private postInterest() {
|
|
const postInterestAccountDialogRef = this.dialog.open(PostInterestDialogComponent);
|
|
postInterestAccountDialogRef.afterClosed().subscribe((response: any) => {
|
|
if (response.confirm) {
|
|
this.fixedDepositsService
|
|
.executeFixedDepositsAccountCommand(this.fixedDepositsAccountData.id, 'postInterest', {})
|
|
.subscribe(() => {
|
|
this.reload();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Enables withhold tax for fixed deposits account.
|
|
* Fixed deposits endpoint is not supported so using Savings endpoint.
|
|
*/
|
|
private enableWithHoldTax() {
|
|
const deleteSavingsAccountDialogRef = this.dialog.open(ToggleWithholdTaxDialogComponent, {
|
|
data: { isEnable: true }
|
|
});
|
|
deleteSavingsAccountDialogRef.afterClosed().subscribe((response: any) => {
|
|
if (response.confirm) {
|
|
this.savingsService
|
|
.executeSavingsAccountUpdateCommand(this.fixedDepositsAccountData.id, 'updateWithHoldTax', {
|
|
withHoldTax: true
|
|
})
|
|
.subscribe(() => {
|
|
this.reload();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Disables withhold tax for fixed deposits account
|
|
* Fixed deposits endpoint is not supported so using Savings endpoint.
|
|
*/
|
|
private disableWithHoldTax() {
|
|
const disableWithHoldTaxDialogRef = this.dialog.open(ToggleWithholdTaxDialogComponent, {
|
|
data: { isEnable: false }
|
|
});
|
|
disableWithHoldTaxDialogRef.afterClosed().subscribe((response: any) => {
|
|
if (response.confirm) {
|
|
this.savingsService
|
|
.executeSavingsAccountUpdateCommand(this.fixedDepositsAccountData.id, 'updateWithHoldTax', {
|
|
withHoldTax: false
|
|
})
|
|
.subscribe(() => {
|
|
this.reload();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|