Files
cbsnexora/src/app/savings/saving-account-actions/add-charge-savings-account/add-charge-savings-account.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

162 lines
5.7 KiB
TypeScript

/** Angular Imports */
import { Component, OnInit, inject } from '@angular/core';
import {
UntypedFormGroup,
UntypedFormBuilder,
Validators,
UntypedFormControl,
ReactiveFormsModule
} from '@angular/forms';
import { Router, ActivatedRoute, RouterLink } from '@angular/router';
/** Custom Services */
import { SavingsService } from '../../savings.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
/**
* Add Savings Charge component.
*/
@Component({
selector: 'mifosx-add-charge-savings-account',
templateUrl: './add-charge-savings-account.component.html',
styleUrls: ['./add-charge-savings-account.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS
]
})
export class AddChargeSavingsAccountComponent implements OnInit {
private formBuilder = inject(UntypedFormBuilder);
private route = inject(ActivatedRoute);
private router = inject(Router);
private dateUtils = inject(Dates);
private savingsService = inject(SavingsService);
private settingsService = inject(SettingsService);
/** Minimum Due Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Due Date allowed. */
maxDate = new Date();
/** Add Savings Charge form. */
savingsChargeForm: UntypedFormGroup;
/** savings charge options. */
savingsChargeOptions: any;
/** savings Id of the savings account. */
savingAccountId: string;
/** charge details */
chargeDetails: any;
/**
* Retrieves charge template data from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {Dates} dateUtils Date Utils
* @param {SavingsService} savingsService Savings Service
* @param {SettingsService} settingsService Settings Service
*/
constructor() {
this.route.data.subscribe((data: { savingsAccountActionData: any }) => {
this.savingsChargeOptions = data.savingsAccountActionData.chargeOptions;
});
this.savingAccountId = this.route.snapshot.params['savingAccountId'];
}
/**
* Creates the Savings Charge form.
*/
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
this.createSavingsChargeForm();
this.buildDependencies();
}
buildDependencies() {
this.savingsChargeForm.controls.chargeId.valueChanges.subscribe((chargeId) => {
this.savingsService.getChargeTemplate(chargeId).subscribe((data: any) => {
this.chargeDetails = data;
const chargeTimeType = data.chargeTimeType.id;
if (data.chargeTimeType.value === 'Withdrawal Fee' || data.chargeTimeType.value === 'Saving No Activity Fee') {
this.chargeDetails.dueDateNotRequired = true;
}
if (data.chargeTimeType.value === 'Annual Fee' || data.chargeTimeType.value === 'Monthly Fee') {
this.chargeDetails.chargeTimeTypeAnnualOrMonth = true;
}
if (!this.chargeDetails.dueDateNotRequired && !this.chargeDetails.chargeTimeTypeAnnualOrMonth) {
this.savingsChargeForm.addControl('dueDate', new UntypedFormControl('', Validators.required));
} else {
this.savingsChargeForm.removeControl('dueDate');
}
if (!this.chargeDetails.dueDateNotRequired && this.chargeDetails.chargeTimeTypeAnnualOrMonth) {
this.savingsChargeForm.addControl('feeOnMonthDay', new UntypedFormControl('', Validators.required));
} else {
this.savingsChargeForm.removeControl('feeOnMonthDay');
}
if (chargeTimeType.value === 'Monthly Fee') {
this.savingsChargeForm.addControl(
'feeInterval',
new UntypedFormControl(data.feeInterval, Validators.required)
);
} else {
this.savingsChargeForm.removeControl('feeInterval');
}
this.savingsChargeForm.patchValue({
amount: data.amount,
chargeCalculationType: data.chargeCalculationType.id,
chargeTimeType: data.chargeTimeType.id
});
});
});
}
/**
* Creates the Savings Charge form.
*/
createSavingsChargeForm() {
this.savingsChargeForm = this.formBuilder.group({
chargeId: [
'',
Validators.required
],
amount: [
'',
Validators.required
],
chargeCalculationType: [{ value: '', disabled: true }],
chargeTimeType: [{ value: '', disabled: true }]
});
}
/**
* Submits savings charge.
*/
submit() {
const savingsCharge = this.savingsChargeForm.value;
savingsCharge.locale = this.settingsService.language.code;
if (!savingsCharge.feeInterval) {
savingsCharge.feeInterval = this.chargeDetails.feeInterval;
}
if (this.chargeDetails.dueDateNotRequired !== true) {
if (this.chargeDetails.chargeTimeTypeAnnualOrMonth === true) {
const monthDayFormat = 'MMMM-dd'; // TODO: Update once language and date settings are setup
savingsCharge.monthDayFormat = monthDayFormat;
if (savingsCharge.feeOnMonthDay) {
const prevDate = this.savingsChargeForm.value.feeOnMonthDay;
savingsCharge.feeOnMonthDay = this.dateUtils.formatDate(prevDate, monthDayFormat);
}
} else {
const dateFormat = this.settingsService.dateFormat;
savingsCharge.dateFormat = dateFormat;
if (savingsCharge.dueDate) {
const prevDate = this.savingsChargeForm.value.dueDate;
savingsCharge.dueDate = this.dateUtils.formatDate(prevDate, dateFormat);
}
}
}
this.savingsService.createSavingsCharge(this.savingAccountId, 'charges', savingsCharge).subscribe(() => {
this.router.navigate(['../../transactions'], { relativeTo: this.route });
});
}
}