/** * 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, ReactiveFormsModule } from '@angular/forms'; import { ActivatedRoute, Router, RouterLink } from '@angular/router'; /** Custom Services */ import { RecurringDepositsService } from '../../recurring-deposits.service'; import { SettingsService } from 'app/settings/settings.service'; import { Dates } from 'app/core/utils/dates'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; /** * Activate Recurring Deposits Account Component */ @Component({ selector: 'mifosx-activate-recurring-deposits-account', templateUrl: './activate-recurring-deposits-account.component.html', styleUrls: ['./activate-recurring-deposits-account.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS ] }) export class ActivateRecurringDepositsAccountComponent implements OnInit { private formBuilder = inject(UntypedFormBuilder); private recurringDepositsService = inject(RecurringDepositsService); private dateUtils = inject(Dates); private route = inject(ActivatedRoute); private router = inject(Router); private settingsService = inject(SettingsService); /** Minimum date allowed. */ minDate = new Date(2000, 0, 1); /** Maximum date allowed. */ maxDate = new Date(); /** Activate Recurring Deposits Account form. */ activateRecurringDepositsAccountForm: UntypedFormGroup; /** Recurring Deposits Account Id */ accountId: any; /** * @param {FormBuilder} formBuilder Form Builder * @param {recurringDepositsService} recurringDepositsService Recurring Deposits Service * @param {Dates} dateUtils Date Utils * @param {ActivatedRoute} route Activated Route * @param {Router} router Router * @param {SavingsService} savingsService Savings Service */ constructor() { this.accountId = this.route.parent.snapshot.params['recurringDepositAccountId']; } /** * Creates the activate recurring deposits form. */ ngOnInit() { this.maxDate = this.settingsService.businessDate; this.createActivateRecurringDepositsAccountForm(); } /** * Creates the activate recurring deposits account form. */ createActivateRecurringDepositsAccountForm() { this.activateRecurringDepositsAccountForm = this.formBuilder.group({ // Defaults to the business date (the branch's working day), which is what the account is normally activated on. activatedOnDate: [ this.settingsService.businessDate, Validators.required ] }); } /** * Submits the form and activates the recurring deposit account, * if successful redirects to the recurring deposit account. */ submit() { const activateRecurringDepositsAccountFormData = this.activateRecurringDepositsAccountForm.value; const locale = this.settingsService.language.code; const dateFormat = this.settingsService.dateFormat; const prevActivatedOnDate: Date = this.activateRecurringDepositsAccountForm.value.activatedOnDate; if (activateRecurringDepositsAccountFormData.activatedOnDate instanceof Date) { activateRecurringDepositsAccountFormData.activatedOnDate = this.dateUtils.formatDate( prevActivatedOnDate, dateFormat ); } const data = { ...activateRecurringDepositsAccountFormData, dateFormat, locale }; this.recurringDepositsService .executeRecurringDepositsAccountCommand(this.accountId, 'activate', data) .subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); }); } }