164 lines
5.3 KiB
TypeScript
164 lines
5.3 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/.
|
|
*/
|
|
|
|
import { Component, Input, OnInit, inject } from '@angular/core';
|
|
import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms';
|
|
import { MatCheckbox } from '@angular/material/checkbox';
|
|
import { MatRadioGroup, MatRadioButton } from '@angular/material/radio';
|
|
import { FormatNumberPipe } from '../../../pipes/format-number.pipe';
|
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|
|
|
@Component({
|
|
selector: 'mifosx-current-account-settings-step',
|
|
templateUrl: './current-account-settings-step.component.html',
|
|
styleUrls: ['./current-account-settings-step.component.scss'],
|
|
imports: [
|
|
...STANDALONE_SHARED_IMPORTS,
|
|
MatCheckbox,
|
|
MatRadioGroup,
|
|
MatRadioButton,
|
|
FormatNumberPipe
|
|
]
|
|
})
|
|
export class CurrentAccountSettingsStepComponent implements OnInit {
|
|
private formBuilder = inject(UntypedFormBuilder);
|
|
|
|
private _currentAccountProductTemplate: any;
|
|
|
|
@Input()
|
|
set currentAccountProductTemplate(value: any) {
|
|
this._currentAccountProductTemplate = value;
|
|
if (value && this.currentAccountSettingsForm) {
|
|
this.applyTemplate(value);
|
|
}
|
|
}
|
|
get currentAccountProductTemplate(): any {
|
|
return this._currentAccountProductTemplate;
|
|
}
|
|
|
|
currentAccountSettingsForm: UntypedFormGroup;
|
|
|
|
lockinPeriodFrequencyTypeData: any[] = [];
|
|
|
|
periodFrequencyData: any[] = [
|
|
{ value: 'Daily' },
|
|
{ value: 'Weekly' },
|
|
{ value: 'Monthly' },
|
|
{ value: 'Quarterly' },
|
|
{ value: 'Half Yearly' },
|
|
{ value: 'Yearly' }];
|
|
|
|
constructor() {
|
|
this.createForm();
|
|
this.buildDependencies();
|
|
}
|
|
|
|
createForm() {
|
|
this.currentAccountSettingsForm = this.formBuilder.group({
|
|
minRequiredOpeningBalance: [
|
|
'',
|
|
[Validators.min(0)]
|
|
],
|
|
withdrawalFeeForTransfers: [false],
|
|
enforceMinRequiredBalance: [false],
|
|
minRequiredBalance: [
|
|
'',
|
|
[Validators.min(0)]
|
|
],
|
|
balanceFrequency: ['Monthly'],
|
|
enableLockinPeriod: [false],
|
|
lockinPeriodFrequency: [''],
|
|
lockinPeriodFrequencyType: [''],
|
|
accountClosedZeroBalanceInDayClosing: [false],
|
|
allowOverdraft: [false],
|
|
odAccountClosedZeroBalanceInDayClosing: [false],
|
|
avgBalanceCalcPeriod: ['6M'],
|
|
validForPeriod: ['3M'],
|
|
overdraftLimit: [
|
|
'',
|
|
[Validators.min(0)]
|
|
],
|
|
nominalAnnualInterestRateOverdraft: [
|
|
'',
|
|
[Validators.min(0)]
|
|
]
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
if (this._currentAccountProductTemplate) {
|
|
this.applyTemplate(this._currentAccountProductTemplate);
|
|
}
|
|
}
|
|
|
|
private applyTemplate(t: any) {
|
|
this.lockinPeriodFrequencyTypeData = t.lockinPeriodFrequencyTypeOptions || [];
|
|
const hasLockin = !!(t.lockinPeriodFrequency && t.lockinPeriodFrequency > 0);
|
|
|
|
this.currentAccountSettingsForm.patchValue({
|
|
minRequiredOpeningBalance: t.minRequiredOpeningBalance,
|
|
withdrawalFeeForTransfers: t.withdrawalFeeForTransfers || false,
|
|
enforceMinRequiredBalance: t.enforceMinRequiredBalance || false,
|
|
minRequiredBalance: t.minRequiredBalance,
|
|
balanceFrequency: t.balanceFrequency || 'Monthly',
|
|
enableLockinPeriod: hasLockin,
|
|
lockinPeriodFrequency: hasLockin ? t.lockinPeriodFrequency : '',
|
|
lockinPeriodFrequencyType: hasLockin ? t.lockinPeriodFrequencyType?.id || '' : '',
|
|
accountClosedZeroBalanceInDayClosing: t.accountClosedZeroBalanceInDayClosing || false,
|
|
allowOverdraft: t.allowOverdraft || false,
|
|
odAccountClosedZeroBalanceInDayClosing: t.odAccountClosedZeroBalanceInDayClosing || false,
|
|
avgBalanceCalcPeriod: t.avgBalanceCalcPeriod || '6M',
|
|
validForPeriod: t.validForPeriod || '3M',
|
|
overdraftLimit: t.overdraftLimit || '',
|
|
nominalAnnualInterestRateOverdraft: t.nominalAnnualInterestRateOverdraft || ''
|
|
});
|
|
}
|
|
|
|
buildDependencies() {
|
|
this.currentAccountSettingsForm.get('enableLockinPeriod').valueChanges.subscribe((enabled: boolean) => {
|
|
const freq = this.currentAccountSettingsForm.get('lockinPeriodFrequency');
|
|
const type = this.currentAccountSettingsForm.get('lockinPeriodFrequencyType');
|
|
if (enabled) {
|
|
freq.setValidators([
|
|
Validators.required,
|
|
Validators.min(1)
|
|
]);
|
|
type.setValidators([Validators.required]);
|
|
} else {
|
|
freq.setValue('');
|
|
type.setValue('');
|
|
freq.clearValidators();
|
|
type.clearValidators();
|
|
}
|
|
freq.updateValueAndValidity();
|
|
type.updateValueAndValidity();
|
|
});
|
|
}
|
|
|
|
get currentAccountSettings() {
|
|
const value = { ...this.currentAccountSettingsForm.getRawValue() };
|
|
|
|
if (!value.enableLockinPeriod) {
|
|
value.lockinPeriodFrequency = null;
|
|
value.lockinPeriodFrequencyType = null;
|
|
}
|
|
delete value.enableLockinPeriod;
|
|
delete value.balanceFrequency;
|
|
|
|
if (!value.allowOverdraft) {
|
|
delete value.overdraftLimit;
|
|
delete value.nominalAnnualInterestRateOverdraft;
|
|
delete value.avgBalanceCalcPeriod;
|
|
delete value.validForPeriod;
|
|
delete value.odAccountClosedZeroBalanceInDayClosing;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
}
|