/** * 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, ViewChild, inject } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { FormGroup } from '@angular/forms'; /** Custom Components */ import { SavingsAccountDetailsStepComponent } from '../savings-account-stepper/savings-account-details-step/savings-account-details-step.component'; import { SavingsAccountCurrencyStepComponent } from '../savings-account-stepper/savings-account-currency-step/savings-account-currency-step.component'; import { SavingsAccountDigitalStepComponent } from '../savings-account-stepper/savings-account-digital-step/savings-account-digital-step.component'; import { SavingsAccountSettingsStepComponent } from '../savings-account-stepper/savings-account-settings-step/savings-account-settings-step.component'; /** Custom Services */ import { SavingsService } from '../savings.service'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { MatStepper, MatStepperIcon, MatStep, MatStepLabel, MatStepperNext, MatStepperPrevious } from '@angular/material/stepper'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { SavingsAccountPreviewStepComponent } from '../savings-account-stepper/savings-account-preview-step/savings-account-preview-step.component'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; /** * Create Savings Account Component */ @Component({ selector: 'mifosx-create-savings-account', templateUrl: './create-savings-account.component.html', styleUrls: ['./create-savings-account.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, MatStepper, MatStepperIcon, MatStepperNext, MatStepperPrevious, FaIconComponent, MatStep, MatStepLabel, SavingsAccountDetailsStepComponent, SavingsAccountCurrencyStepComponent, SavingsAccountDigitalStepComponent, SavingsAccountPreviewStepComponent ] }) export class CreateSavingsAccountComponent { private route = inject(ActivatedRoute); private router = inject(Router); private dateUtils = inject(Dates); private savingsService = inject(SavingsService); private settingsService = inject(SettingsService); /** Savings Account Template */ savingsAccountTemplate: any; /** Savings Account Product Template */ savingsAccountProductTemplate: any; @ViewChild(SavingsAccountDetailsStepComponent, { static: true }) savingsAccountDetailsStep: SavingsAccountDetailsStepComponent; @ViewChild(SavingsAccountDigitalStepComponent) savingsAccountDigitalStep: SavingsAccountDigitalStepComponent; @ViewChild(SavingsAccountCurrencyStepComponent) savingsAccountCurrencyStep: SavingsAccountCurrencyStepComponent; constructor() { this.route.data.subscribe((data: { savingsAccountTemplate: any }) => { this.savingsAccountTemplate = data.savingsAccountTemplate; }); } setTemplate($event: any) { this.savingsAccountProductTemplate = $event; } get savingsAccountDetailsForm() { return this.savingsAccountDetailsStep.savingsAccountDetailsForm; } /** Stub — no term step in this flow */ get savingsAccountTermsForm(): FormGroup { return new FormGroup({}); } get savingsAccount() { return { ...this.savingsAccountDetailsStep.savingsAccountDetails }; } get savingsAccountDigital() { return this.savingsAccountDigitalStep?.savingsAccountDigital ?? null; } get savingsAccountNominee() { return this.savingsAccountCurrencyStep?.nomineeData ?? null; } submit() { const locale = this.settingsService.language.code; const dateFormat = this.settingsService.dateFormat; const monthDayFormat = 'dd MMMM'; const savingsAccount = { ...this.savingsAccount, charges: [], submittedOnDate: this.dateUtils.formatDate(this.savingsAccount.submittedOnDate, dateFormat), dateFormat, monthDayFormat, locale }; if (this.savingsAccountTemplate.clientId) { savingsAccount.clientId = this.savingsAccountTemplate.clientId; } else { savingsAccount.groupId = this.savingsAccountTemplate.groupId; } this.savingsService.createSavingsAccount(savingsAccount).subscribe((response: any) => { this.router.navigate( [ '../', response.resourceId ], { relativeTo: this.route } ); }); } }