Files
cbsnexora/src/app/deposits/recurring-deposits/recurring-deposits-account-stepper/recurring-deposits-account-settings-step/recurring-deposits-account-settings-step.component.ts
T

242 lines
11 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/.
*/
/** Angular Imports */
import { Component, OnInit, Input, OnChanges, inject } from '@angular/core';
import {
UntypedFormGroup,
UntypedFormBuilder,
Validators,
UntypedFormControl,
ReactiveFormsModule
} from '@angular/forms';
import { SettingsService } from 'app/settings/settings.service';
import { Currency } from 'app/shared/models/general.model';
import { MatCheckbox } from '@angular/material/checkbox';
import { InputAmountComponent } from '../../../../shared/input-amount/input-amount.component';
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';
/**
* Recurring Deposits Account Settings Step
*/
@Component({
selector: 'mifosx-recurring-deposits-account-settings-step',
templateUrl: './recurring-deposits-account-settings-step.component.html',
styleUrls: ['./recurring-deposits-account-settings-step.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
MatCheckbox,
InputAmountComponent,
MatDivider,
MatStepperPrevious,
FaIconComponent,
MatStepperNext
]
})
export class RecurringDepositsAccountSettingsStepComponent implements OnInit, OnChanges {
private formBuilder = inject(UntypedFormBuilder);
private settingsService = inject(SettingsService);
@Input() isNew = true;
@Input() recurringDepositsAccountTemplate: any;
@Input() recurringDepositsAccountProductTemplate: any;
/** Recurring Deposits Account Settings Form */
recurringDepositAccountSettingsForm: UntypedFormGroup;
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Lockin Period Frequency Type Data */
lockinPeriodFrequencyTypeData: any[] = [];
/** Period Frequency Type Data */
periodFrequencyTypeData: any[] = [];
/** Preclosure Penal Interest Type on Data */
preClosurePenalInterestOnTypeData: any[] = [];
/** Tax Group */
taxGroup: any;
currency: Currency | null = null;
constructor() {
this.createRecurringDepositAccountSettingsForm();
this.buildDependencies();
}
ngOnChanges() {
const recurringDepositsAccount: any = this.isNew
? this.recurringDepositsAccountProductTemplate
: this.recurringDepositsAccountTemplate;
if (recurringDepositsAccount) {
this.currency = recurringDepositsAccount.currency;
// Patch CBS settings fields from product template
this.recurringDepositAccountSettingsForm.patchValue({
loanFacility: recurringDepositsAccount.loanFacility ?? false,
prematureWithdrawalOption: recurringDepositsAccount.prematureWithdrawalOption ?? false,
tenureFlexibility: recurringDepositsAccount.tenureFlexibility ?? false,
lienMarked: recurringDepositsAccount.lienMarked ?? false,
withdrawalFeeForTransfers: recurringDepositsAccount.withdrawalFeeForTransfers ?? false,
enableLockinPeriod: recurringDepositsAccount.enableLockinPeriod ?? false,
lockinPeriodFrequency: recurringDepositsAccount.lockinPeriodFrequency ?? '',
lockinPeriodFrequencyType: recurringDepositsAccount.lockinPeriodFrequencyType
? recurringDepositsAccount.lockinPeriodFrequencyType.id
: '',
maturityInstructions: recurringDepositsAccount.maturityInstructions ?? false,
creditMaturityProceeds: recurringDepositsAccount.creditMaturityProceeds ?? false,
penaltyGracePeriodMissedInstallments: recurringDepositsAccount.penaltyGracePeriodMissedInstallments ?? false,
panelRequestApplicable: recurringDepositsAccount.panelRequestApplicable ?? false,
noPenaltyNomineeHeirClosure: recurringDepositsAccount.noPenaltyNomineeHeirClosure ?? false,
deceasedSettlement: recurringDepositsAccount.deceasedSettlement ?? false,
allowDebitTxnAfterDueDate: recurringDepositsAccount.allowDebitTxnAfterDueDate ?? false,
accountClosedZeroBalanceInDayClosing: recurringDepositsAccount.accountClosedZeroBalanceInDayClosing ?? false,
minBalanceForInterestCalculation: recurringDepositsAccount.minBalanceForInterestCalculation ?? '',
// Account-specific fields — auto-filled from product template (hidden from UI)
isMandatoryDeposit: recurringDepositsAccount.isMandatoryDeposit,
adjustAdvanceTowardsFuturePayments: recurringDepositsAccount.adjustAdvanceTowardsFuturePayments,
allowWithdrawal: recurringDepositsAccount.allowWithdrawal,
minDepositTerm: recurringDepositsAccount.minDepositTerm,
minDepositTermTypeId: recurringDepositsAccount.minDepositTermType
? recurringDepositsAccount.minDepositTermType.id
: '',
inMultiplesOfDepositTerm: recurringDepositsAccount.inMultiplesOfDepositTerm,
inMultiplesOfDepositTermTypeId: recurringDepositsAccount.inMultiplesOfDepositTermType
? recurringDepositsAccount.inMultiplesOfDepositTermType.id
: '',
maxDepositTerm: recurringDepositsAccount.maxDepositTerm,
maxDepositTermTypeId: recurringDepositsAccount.maxDepositTermType
? recurringDepositsAccount.maxDepositTermType.id
: '',
preClosurePenalApplicable: recurringDepositsAccount.preClosurePenalApplicable,
preClosurePenalInterest: recurringDepositsAccount.preClosurePenalInterest,
preClosurePenalInterestOnTypeId: recurringDepositsAccount.preClosurePenalInterestOnType
? recurringDepositsAccount.preClosurePenalInterestOnType.id
: '',
depositPeriod: recurringDepositsAccount.minDepositTerm,
depositPeriodFrequencyId: recurringDepositsAccount.minDepositTermType
? recurringDepositsAccount.minDepositTermType.id
: '',
recurringFrequency: recurringDepositsAccount.recurringFrequency,
recurringFrequencyType: recurringDepositsAccount.recurringFrequencyType
? recurringDepositsAccount.recurringFrequencyType.id
: ''
});
if (recurringDepositsAccount.withHoldTax) {
this.recurringDepositAccountSettingsForm.addControl('withHoldTax', new UntypedFormControl(false));
this.recurringDepositAccountSettingsForm.get('withHoldTax').valueChanges.subscribe((value: boolean) => {
if (value) {
this.recurringDepositAccountSettingsForm.addControl(
'taxGroupId',
new UntypedFormControl({ value: '', disabled: true })
);
this.recurringDepositAccountSettingsForm
.get('taxGroupId')
.patchValue(recurringDepositsAccount.taxGroup && recurringDepositsAccount.taxGroup.name);
} else {
this.recurringDepositAccountSettingsForm.removeControl('taxGroupId');
}
});
this.recurringDepositAccountSettingsForm
.get('withHoldTax')
.patchValue(this.recurringDepositsAccountTemplate?.withHoldTax);
} else {
this.recurringDepositAccountSettingsForm.removeControl('withHoldTax');
}
this.taxGroup = recurringDepositsAccount.taxGroup;
this.setOptions(recurringDepositsAccount);
}
}
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
if (this.recurringDepositsAccountTemplate) {
this.recurringDepositAccountSettingsForm.patchValue({
lockinPeriodFrequency: this.recurringDepositsAccountTemplate.lockinPeriodFrequency,
lockinPeriodFrequencyType:
this.recurringDepositsAccountTemplate.lockinPeriodFrequencyType &&
this.recurringDepositsAccountTemplate.lockinPeriodFrequencyType.id,
mandatoryRecommendedDepositAmount: this.recurringDepositsAccountTemplate.mandatoryRecommendedDepositAmount
});
}
}
createRecurringDepositAccountSettingsForm() {
this.recurringDepositAccountSettingsForm = this.formBuilder.group({
// CBS Settings (visible — same as product settings page)
loanFacility: [false],
prematureWithdrawalOption: [false],
tenureFlexibility: [false],
lienMarked: [false],
withdrawalFeeForTransfers: [false],
enableLockinPeriod: [false],
lockinPeriodFrequency: [''],
lockinPeriodFrequencyType: [''],
maturityInstructions: [false],
creditMaturityProceeds: [false],
penaltyGracePeriodMissedInstallments: [false],
panelRequestApplicable: [false],
noPenaltyNomineeHeirClosure: [false],
deceasedSettlement: [false],
allowDebitTxnAfterDueDate: [false],
accountClosedZeroBalanceInDayClosing: [false],
minBalanceForInterestCalculation: [''],
// Account-specific fields (hidden from UI — auto-filled from product template)
isMandatoryDeposit: [''],
adjustAdvanceTowardsFuturePayments: [''],
allowWithdrawal: [''],
mandatoryRecommendedDepositAmount: [''],
depositPeriod: [''],
depositPeriodFrequencyId: [''],
isCalendarInherited: [''],
expectedFirstDepositOnDate: [''],
recurringFrequency: [''],
recurringFrequencyType: [''],
minDepositTerm: [{ value: '', disabled: true }],
minDepositTermTypeId: [{ value: '', disabled: true }],
inMultiplesOfDepositTerm: [{ value: '', disabled: true }],
inMultiplesOfDepositTermTypeId: [{ value: '', disabled: true }],
maxDepositTerm: [{ value: '', disabled: true }],
maxDepositTermTypeId: [{ value: '', disabled: true }],
preClosurePenalApplicable: [{ value: '', disabled: true }],
preClosurePenalInterest: [{ value: '', disabled: true }],
preClosurePenalInterestOnTypeId: [{ value: '', disabled: true }]
});
}
setOptions(recurringDepositsAccount: any) {
this.lockinPeriodFrequencyTypeData = recurringDepositsAccount.lockinPeriodFrequencyTypeOptions;
this.periodFrequencyTypeData = recurringDepositsAccount.periodFrequencyTypeOptions;
this.preClosurePenalInterestOnTypeData = recurringDepositsAccount.preClosurePenalInterestOnTypeOptions;
}
buildDependencies() {
this.recurringDepositAccountSettingsForm
.get('isCalendarInherited')
.valueChanges.subscribe((isCalendarInherited: any) => {
if (isCalendarInherited) {
this.recurringDepositAccountSettingsForm.removeControl('expectedFirstDepositOnDate');
this.recurringDepositAccountSettingsForm.removeControl('recurringFrequency');
this.recurringDepositAccountSettingsForm.removeControl('recurringFrequencyType');
} else {
this.recurringDepositAccountSettingsForm.addControl('expectedFirstDepositOnDate', new UntypedFormControl());
this.recurringDepositAccountSettingsForm.addControl('recurringFrequency', new UntypedFormControl(''));
this.recurringDepositAccountSettingsForm.addControl('recurringFrequencyType', new UntypedFormControl(''));
}
});
}
get recurringDepositAccountSettings() {
return this.recurringDepositAccountSettingsForm.value;
}
}