159 lines
5.5 KiB
TypeScript
159 lines
5.5 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 {
|
|
UntypedFormGroup,
|
|
UntypedFormBuilder,
|
|
Validators,
|
|
UntypedFormControl,
|
|
ReactiveFormsModule
|
|
} from '@angular/forms';
|
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
|
|
|
/** Custom Services */
|
|
import { FixedDepositsService } from '../../fixed-deposits.service';
|
|
import { SettingsService } from 'app/settings/settings.service';
|
|
import { Dates } from 'app/core/utils/dates';
|
|
import { AlertService } from 'app/core/alert/alert.service';
|
|
import { CdkTextareaAutosize } from '@angular/cdk/text-field';
|
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|
|
|
/**
|
|
* Close On Maturity Fixed Deposits Account Component
|
|
*/
|
|
@Component({
|
|
selector: 'mifosx-close-fixed-deposits-account',
|
|
templateUrl: './close-fixed-deposits-account.component.html',
|
|
styleUrls: ['./close-fixed-deposits-account.component.scss'],
|
|
imports: [
|
|
...STANDALONE_SHARED_IMPORTS,
|
|
CdkTextareaAutosize
|
|
]
|
|
})
|
|
export class CloseFixedDepositsAccountComponent implements OnInit {
|
|
private formBuilder = inject(UntypedFormBuilder);
|
|
private fixedDepositsService = inject(FixedDepositsService);
|
|
private dateUtils = inject(Dates);
|
|
private route = inject(ActivatedRoute);
|
|
private router = inject(Router);
|
|
private settingsService = inject(SettingsService);
|
|
private alertService = inject(AlertService);
|
|
|
|
/** Minimum date allowed. */
|
|
minDate = new Date(2000, 0, 1);
|
|
/** Maximum date allowed. */
|
|
maxDate = new Date();
|
|
/** Close on maturity FD Account form. */
|
|
closeOnMaturityAccountForm: UntypedFormGroup;
|
|
/** Savings Account Data */
|
|
savingsAccountsData: any;
|
|
/** On account Closure Options */
|
|
onAccountClosureOptions: any;
|
|
/** Fixed Deposits Account Id */
|
|
accountId: any;
|
|
/** Maturity Amount */
|
|
maturityAmount: any;
|
|
|
|
/**
|
|
* Fetches close action data from `resolve`
|
|
* @param {FormBuilder} formBuilder Form Builder
|
|
* @param {FixedDepositsService} fixedDepositsService Fixed Deposits Service
|
|
* @param {Dates} dateUtils Date Utils
|
|
* @param {ActivatedRoute} route Activated Route
|
|
* @param {Router} router Router
|
|
* @param {SettingsService} settingsService Settings Service
|
|
*/
|
|
constructor() {
|
|
this.route.data.subscribe((data: { fixedDepositsAccountActionData: any }) => {
|
|
this.savingsAccountsData = data.fixedDepositsAccountActionData.savingsAccounts;
|
|
this.onAccountClosureOptions = data.fixedDepositsAccountActionData.onAccountClosureOptions;
|
|
this.maturityAmount = data.fixedDepositsAccountActionData.maturityAmount;
|
|
});
|
|
this.accountId = this.route.parent.snapshot.params['fixedDepositAccountId'];
|
|
}
|
|
|
|
/**
|
|
* Creates the close on maturity fd account form.
|
|
*/
|
|
ngOnInit() {
|
|
this.maxDate = this.settingsService.businessDate;
|
|
this.createCloseOnMaturityAccountForm();
|
|
this.addTransferDetails();
|
|
}
|
|
|
|
/**
|
|
* Creates the close on maturity fd account form.
|
|
*/
|
|
createCloseOnMaturityAccountForm() {
|
|
this.closeOnMaturityAccountForm = this.formBuilder.group({
|
|
closedOnDate: [
|
|
'',
|
|
Validators.required
|
|
],
|
|
maturityAmount: [{ value: this.maturityAmount, disabled: true }],
|
|
onAccountClosureId: [
|
|
'',
|
|
Validators.required
|
|
],
|
|
note: ['']
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Subscribes to value changes of `onAccountClosureId` adds and removes transfer details accordingly.
|
|
*/
|
|
addTransferDetails() {
|
|
this.closeOnMaturityAccountForm.get('onAccountClosureId').valueChanges.subscribe((id: any) => {
|
|
if (id === 200) {
|
|
this.closeOnMaturityAccountForm.addControl(
|
|
'toSavingsAccountId',
|
|
new UntypedFormControl('', Validators.required)
|
|
);
|
|
this.closeOnMaturityAccountForm.addControl('transferDescription', new UntypedFormControl(''));
|
|
} else {
|
|
this.closeOnMaturityAccountForm.removeControl('toSavingsAccountId');
|
|
this.closeOnMaturityAccountForm.removeControl('transferDescription');
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Submits the form and close the fd account on maturity,
|
|
* if successful redirects to the fd account.
|
|
*/
|
|
submit() {
|
|
const closeOnMaturityAccountFormData = this.closeOnMaturityAccountForm.value;
|
|
const locale = this.settingsService.language.code;
|
|
const dateFormat = this.settingsService.dateFormat;
|
|
const prevClosedDate: Date = this.closeOnMaturityAccountForm.value.closedOnDate;
|
|
if (closeOnMaturityAccountFormData.closedOnDate instanceof Date) {
|
|
closeOnMaturityAccountFormData.closedOnDate = this.dateUtils.formatDate(prevClosedDate, dateFormat);
|
|
}
|
|
const data = {
|
|
...closeOnMaturityAccountFormData,
|
|
dateFormat,
|
|
locale
|
|
};
|
|
this.fixedDepositsService
|
|
.executeFixedDepositsAccountCommand(this.accountId, 'close', data)
|
|
.subscribe((response: any) => {
|
|
// Parked in the Checker Inbox rather than executed (HTTP 200 with rollbackTransaction: true),
|
|
// so the deposit reloads unchanged -- say so instead of letting that read as "nothing happened".
|
|
if (response?.rollbackTransaction) {
|
|
this.alertService.alert({
|
|
type: 'Success',
|
|
message: 'Closure has been sent for checker approval. The deposit is unchanged until a checker approves it.'
|
|
});
|
|
}
|
|
this.router.navigate(['../../'], { relativeTo: this.route });
|
|
});
|
|
}
|
|
}
|