Files
cbsnexora/src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.ts
T
Felix van Hove 7fd1486c08 Upgrading to Angular 20:
Replaced checked in package-lock.json by regenerated one.
Ran ng update @angular/core@20 @angular/cli@20
Ran npm install @angular-builders/jest@^20.0.0 @fortawesome/angular-fontawesome@^3.0.0 @swimlane/ngx-graph@^11
Ran npm install ngx-mat-select-search@^8.0.2.
Ran ng update @angular/material@20.
Updated all eslint and typescript to the latest versions.
Removed @angular-devkit/schematics.
Updated fontawesome.
Updated rxjs and tslib.
Moved required node version from 16 to 20.
Updated jest-preset-angular.
Set preserveWhitespaces to false.
Corrected two type declarations in two typescript files to make ng serve run without errors.
Removed unused angular-devkit/schematics from view-user.component.ts .
Updated list of supported browsers.
Upgraded prettier.
Ran prettier . --write the first time.
Ran prettier . --write the second time.
Ran ng generate @angular/core:inject with defaults, excepted a handful of files.
Fixed remaining eslint problems.
Added dist directory to ignores in eslint.config.js.
Let prettier fix formatting, almost everything is just line breaks.
Made htmlhint ignore @if and @for Angular constructs.
Updated node version in Github workflow to 22.12.0 (build.yml).
Updated .env.ts.
Updated Angular datetime format strings from YYYY-MM-DD to yyyy-MM-dd.
Merged changes from dev into angular20 branch.
2025-12-08 11:01:01 +01:00

192 lines
7.9 KiB
TypeScript

/** Angular Imports */
import { Component, OnChanges, OnInit, Input, inject } from '@angular/core';
import {
UntypedFormGroup,
UntypedFormBuilder,
Validators,
UntypedFormControl,
ReactiveFormsModule
} from '@angular/forms';
import { SettingsService } from 'app/settings/settings.service';
import { MatCheckbox } from '@angular/material/checkbox';
import { MatDivider } from '@angular/material/divider';
import { MatStepperPrevious, MatStepperNext } from '@angular/material/stepper';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
/**
* Savings Account Terms Step
*/
@Component({
selector: 'mifosx-savings-account-terms-step',
templateUrl: './savings-account-terms-step.component.html',
styleUrls: ['./savings-account-terms-step.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
MatCheckbox,
MatDivider,
MatStepperPrevious,
FaIconComponent,
MatStepperNext
]
})
export class SavingsAccountTermsStepComponent implements OnChanges, OnInit {
private formBuilder = inject(UntypedFormBuilder);
private settingsService = inject(SettingsService);
/** Savings Account and Product Template */
@Input() savingsAccountProductTemplate: any;
/** Savings Account Template */
@Input() savingsAccountTemplate: any;
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Savings Account Terms Form */
savingsAccountTermsForm: UntypedFormGroup;
/** Lockin Period Frequency Type Data */
lockinPeriodFrequencyTypeData: any;
/** Interest Compounding Period Type Data */
interestCompoundingPeriodTypeData: any;
/** Interest Posting Period Type Data */
interestPostingPeriodTypeData: any;
/** Interest Calculation Type Data */
interestCalculationTypeData: any;
/** Interest Calculation Days in Year Data */
interestCalculationDaysInYearTypeData: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {SettingsService} settingsService Setting service
*/
constructor() {
this.createSavingsAccountTermsForm();
this.buildDependencies();
}
ngOnChanges() {
if (this.savingsAccountProductTemplate) {
this.savingsAccountTermsForm.patchValue({
currencyCode: this.savingsAccountProductTemplate.currency.code,
decimal: this.savingsAccountProductTemplate.currency.decimalPlaces,
minBalanceForInterestCalculation: this.savingsAccountProductTemplate.minBalanceForInterestCalculation,
nominalAnnualInterestRate: this.savingsAccountProductTemplate.nominalAnnualInterestRate,
interestCompoundingPeriodType: this.savingsAccountProductTemplate.interestCompoundingPeriodType.id,
interestPostingPeriodType: this.savingsAccountProductTemplate.interestPostingPeriodType.id,
interestCalculationType: this.savingsAccountProductTemplate.interestCalculationType.id,
interestCalculationDaysInYearType: this.savingsAccountProductTemplate.interestCalculationDaysInYearType.id,
minRequiredOpeningBalance: this.savingsAccountProductTemplate.minRequiredOpeningBalance,
allowOverdraft: this.savingsAccountProductTemplate.allowOverdraft,
overdraftLimit: this.savingsAccountProductTemplate.overdraftLimit,
enforceMinRequiredBalance: this.savingsAccountProductTemplate.enforceMinRequiredBalance,
minOverdraftForInterestCalculation: this.savingsAccountProductTemplate.minOverdraftForInterestCalculation,
nominalAnnualInterestRateOverdraft: this.savingsAccountProductTemplate.nominalAnnualInterestRateOverdraft,
minRequiredBalance: this.savingsAccountProductTemplate.minRequiredBalance,
withdrawalFeeForTransfers: this.savingsAccountProductTemplate.withdrawalFeeForTransfers
});
this.setOptions();
}
}
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
if (this.savingsAccountTemplate) {
this.savingsAccountTermsForm.patchValue({
nominalAnnualInterestRate: this.savingsAccountTemplate.nominalAnnualInterestRate,
interestCompoundingPeriodType: this.savingsAccountTemplate.interestCompoundingPeriodType.id,
interestPostingPeriodType: this.savingsAccountTemplate.interestPostingPeriodType.id,
interestCalculationType: this.savingsAccountTemplate.interestCalculationType.id,
interestCalculationDaysInYearType: this.savingsAccountTemplate.interestCalculationDaysInYearType.id,
minRequiredOpeningBalance: this.savingsAccountTemplate.minRequiredOpeningBalance,
withdrawalFeeForTransfers: this.savingsAccountTemplate.withdrawalFeeForTransfers,
lockinPeriodFrequency: this.savingsAccountTemplate.lockinPeriodFrequency,
lockinPeriodFrequencyType:
this.savingsAccountTemplate.lockinPeriodFrequencyType &&
this.savingsAccountTemplate.lockinPeriodFrequencyType.id,
allowOverdraft: this.savingsAccountTemplate.allowOverdraft,
enforceMinRequiredBalance: this.savingsAccountTemplate.enforceMinRequiredBalance,
minRequiredBalance: this.savingsAccountTemplate.minRequiredBalance
});
}
}
/**
* Creates savings account terms form.
*/
createSavingsAccountTermsForm() {
this.savingsAccountTermsForm = this.formBuilder.group({
currencyCode: [{ value: '', disabled: true }],
decimal: [{ value: '', disabled: true }],
nominalAnnualInterestRate: [
'',
Validators.required
],
interestCompoundingPeriodType: [
'',
Validators.required
],
interestPostingPeriodType: [
'',
Validators.required
],
interestCalculationType: [
'',
Validators.required
],
interestCalculationDaysInYearType: [
'',
Validators.required
],
minRequiredOpeningBalance: [''],
withdrawalFeeForTransfers: [false],
lockinPeriodFrequency: [''],
lockinPeriodFrequencyType: [''],
allowOverdraft: [false],
enforceMinRequiredBalance: [false],
minRequiredBalance: [''],
minBalanceForInterestCalculation: [{ value: '', disabled: true }]
});
}
/**
* Sets all select dropdown options.
*/
setOptions() {
this.lockinPeriodFrequencyTypeData = this.savingsAccountProductTemplate.lockinPeriodFrequencyTypeOptions;
this.interestCompoundingPeriodTypeData = this.savingsAccountProductTemplate.interestCompoundingPeriodTypeOptions;
this.interestPostingPeriodTypeData = this.savingsAccountProductTemplate.interestPostingPeriodTypeOptions;
this.interestCalculationTypeData = this.savingsAccountProductTemplate.interestCalculationTypeOptions;
this.interestCalculationDaysInYearTypeData =
this.savingsAccountProductTemplate.interestCalculationDaysInYearTypeOptions;
}
/**
* Subscribes to value changes and sets new form controls accordingly.
*/
buildDependencies() {
this.savingsAccountTermsForm.get('allowOverdraft').valueChanges.subscribe((allowOverdraft: any) => {
if (allowOverdraft) {
this.savingsAccountTermsForm.addControl('minOverdraftForInterestCalculation', new UntypedFormControl(''));
this.savingsAccountTermsForm.addControl('nominalAnnualInterestRateOverdraft', new UntypedFormControl(''));
this.savingsAccountTermsForm.addControl('overdraftLimit', new UntypedFormControl(''));
} else {
this.savingsAccountTermsForm.removeControl('minOverdraftForInterestCalculation');
this.savingsAccountTermsForm.removeControl('nominalAnnualInterestRateOverdraft');
this.savingsAccountTermsForm.removeControl('overdraftLimit');
}
});
}
/**
* Returns savings account terms form value.
*/
get savingsAccountTerms() {
const payload = this.savingsAccountTermsForm.getRawValue();
delete payload.currencyCode;
delete payload.decimal;
delete payload.minBalanceForInterestCalculation; // Backend is not accepting minBalanceForInterestCalculation value
return payload;
}
}