update some logic show option

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Nitesh Yadav
2026-04-21 17:38:07 +05:30
co-authored by Claude Sonnet 4.6
parent e212bf7d79
commit e9a9377148
39 changed files with 2215 additions and 287 deletions
@@ -0,0 +1,170 @@
<!--
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/.
-->
<form [formGroup]="savingsAccountTermForm">
<div class="sat-section">
<div class="sat-section__header">
<span class="sat-section__badge"><i class="fas fa-chart-line"></i></span>
<span>Interest Rate &amp; Posting Terms</span>
</div>
<div class="sat-body">
<!-- Banner showing current rate -->
<div class="sat-banner">
<span class="sat-banner__icon">ℹ️</span>
<span>
Savings Account base rate:
<b>{{ savingsAccountTermForm.get('nominalAnnualInterestRate').value || 0 }}%</b>
</span>
</div>
<!-- Row 1: Nominal Interest + Effective Date + Interest Calculation Type -->
<div class="sat-grid sat-grid--three">
<mat-form-field appearance="outline" class="sat-field">
<mat-label>{{ 'labels.inputs.Nominal Annual Interest' | translate }}</mat-label>
<input type="number" matInput formControlName="nominalAnnualInterestRate" required min="0" step="0.01" />
@if (savingsAccountTermForm.get('nominalAnnualInterestRate').hasError('required')) {
<mat-error>Nominal Annual Interest is <strong>required</strong></mat-error>
}
@if (savingsAccountTermForm.get('nominalAnnualInterestRate').hasError('min')) {
<mat-error>Must be zero or greater</mat-error>
}
</mat-form-field>
<mat-form-field appearance="outline" class="sat-field" (click)="effectiveDatePicker.open()">
<mat-label>Effective Date</mat-label>
<input
matInput
[matDatepicker]="effectiveDatePicker"
formControlName="effectiveDate"
[min]="minDate"
[max]="maxDate"
/>
<mat-datepicker-toggle matSuffix [for]="effectiveDatePicker"></mat-datepicker-toggle>
<mat-datepicker #effectiveDatePicker></mat-datepicker>
</mat-form-field>
<mat-form-field appearance="outline" class="sat-field">
<mat-label>{{ 'labels.inputs.Interest Calculation Type' | translate }}</mat-label>
<mat-select formControlName="interestCalculateSelector">
@for (opt of interestCalculateSelectorData; track opt.id) {
<mat-option [value]="opt.id">{{ opt.value }}</mat-option>
}
</mat-select>
</mat-form-field>
</div>
<!-- Row 2: Interest Calculate (enum) + Average Period (conditional) + Interest Posting Period -->
<div class="sat-grid sat-grid--three">
<mat-form-field appearance="outline" class="sat-field">
<mat-label>Interest Calculate</mat-label>
<mat-select formControlName="interestCalculationType" required>
@for (opt of interestCalculationTypeData; track opt.id) {
<mat-option [value]="opt.id">{{ opt.value | translateKey: 'catalogs' }}</mat-option>
}
</mat-select>
<mat-error
>{{ 'labels.inputs.Interest Calculation Type' | translate }} is <strong>required</strong></mat-error
>
</mat-form-field>
@if (savingsAccountTermForm.value.interestCalculationType === 2) {
<mat-form-field appearance="outline" class="sat-field">
<mat-label>Average Period</mat-label>
<mat-select formControlName="averagePeriod">
@for (period of periodFrequencyData; track period) {
<mat-option [value]="period.value">{{ period.value }}</mat-option>
}
</mat-select>
</mat-form-field>
}
<mat-form-field appearance="outline" class="sat-field">
<mat-label>{{ 'labels.inputs.Interest Posting Period' | translate }}</mat-label>
<mat-select formControlName="interestPostingPeriodType" required>
@for (opt of interestPostingPeriodTypeData; track opt) {
<mat-option [value]="opt.id">{{ opt.value | translateKey: 'catalogs' }}</mat-option>
}
</mat-select>
<mat-error>{{ 'labels.inputs.Interest Posting Period' | translate }} is <strong>required</strong></mat-error>
</mat-form-field>
</div>
<!-- Row 3: Interest Compounding + Days in Year -->
<div class="sat-grid sat-grid--three">
<mat-form-field appearance="outline" class="sat-field">
<mat-label>{{ 'labels.inputs.Interest Compounding Period' | translate }}</mat-label>
<mat-select formControlName="interestCompoundingPeriodType" required>
@for (opt of interestCompoundingPeriodTypeData; track opt) {
<mat-option [value]="opt.id">{{ opt.value | translateKey: 'catalogs' }}</mat-option>
}
</mat-select>
<mat-error
>{{ 'labels.inputs.Interest Compounding Period' | translate }} is <strong>required</strong></mat-error
>
</mat-form-field>
<mat-form-field appearance="outline" class="sat-field">
<mat-label>{{ 'labels.inputs.Days in Year' | translate }}</mat-label>
<mat-select formControlName="interestCalculationDaysInYearType" required>
@for (opt of interestCalculationDaysInYearTypeData; track opt) {
<mat-option [value]="opt.id">{{ opt.value | translateKey: 'catalogs' }}</mat-option>
}
</mat-select>
<mat-error>{{ 'labels.inputs.Days in Year' | translate }} is <strong>required</strong></mat-error>
</mat-form-field>
</div>
<!-- Footer: Auto Post + Frequency Fix Day + Last Interest Date -->
<div class="sat-footer">
<div class="sat-footer__grid">
<div class="sat-toggle-card">
<div>
<h4>Auto Interest Post</h4>
</div>
<div class="sat-toggle-card__choices">
@for (option of yesNoOptions; track option.value) {
<label class="sat-radio-label">
<input type="radio" formControlName="autoPost" [value]="option.value" />
<span>{{ option.label }}</span>
</label>
}
</div>
</div>
<mat-form-field appearance="outline" class="sat-field">
<mat-label>Frequency (Fix Day)</mat-label>
<input type="number" matInput formControlName="frequencyFixDay" min="0" />
<mat-hint>Days</mat-hint>
</mat-form-field>
<mat-form-field appearance="outline" class="sat-field" (click)="lastInterestDatePicker.open()">
<mat-label>Last Interest Date</mat-label>
<input
matInput
[matDatepicker]="lastInterestDatePicker"
formControlName="lastInterestDate"
[min]="minDate"
[max]="maxDate"
/>
<mat-datepicker-toggle matSuffix [for]="lastInterestDatePicker"></mat-datepicker-toggle>
<mat-datepicker #lastInterestDatePicker></mat-datepicker>
</mat-form-field>
</div>
@if (savingsAccountTermForm.value.interestCalculationType === 1) {
<div class="sat-note">
<span>⚠️</span>
<span
>Daily product-based interest accrual enabled - interest calculated EOD on daily closing balance.</span
>
</div>
}
</div>
</div>
</div>
</form>
@@ -0,0 +1,166 @@
/**
* 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/.
*/
$accent: #0ea5e9;
$border: #e2e8f0;
$gray-50: #f8f9fa;
$gray-200: #e8eaed;
$gray-900: #202124;
.sat-section {
border: 1px solid $border;
border-radius: 10px;
overflow: hidden;
background: #fff;
& + & {
margin-top: 16px;
}
&__header {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 24px;
background: $gray-50;
border-bottom: 1px solid $gray-200;
span {
font-size: 14px;
font-weight: 600;
color: $gray-900;
}
}
}
.sat-section__badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
border-radius: 6px;
background: #eff6ff;
font-size: 14px;
}
.sat-body {
background: #fff;
padding: 18px 24px 24px;
}
.sat-banner {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 14px;
margin-bottom: 18px;
border-radius: 8px;
background: #eff6ff;
border: 1px solid #bfdbfe;
font-size: 13px;
color: $gray-900;
&__icon {
font-size: 16px;
}
}
.sat-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 4px 16px;
@media (width <= 900px) {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (width <= 600px) {
grid-template-columns: 1fr;
}
}
.sat-field {
width: 100%;
}
.sat-footer {
margin-top: 16px;
padding-top: 16px;
border-top: 1px solid $border;
&__grid {
display: grid;
grid-template-columns: auto 1fr 1fr;
gap: 4px 16px;
align-items: start;
@media (width <= 900px) {
grid-template-columns: 1fr 1fr;
}
@media (width <= 600px) {
grid-template-columns: 1fr;
}
}
}
.sat-toggle-card {
display: flex;
flex-direction: column;
gap: 8px;
padding: 10px 14px;
border: 1px solid $border;
border-radius: 8px;
background: $gray-50;
min-height: 56px;
h4 {
margin: 0;
font-size: 12px;
font-weight: 600;
color: #64748b;
text-transform: uppercase;
letter-spacing: 0.04em;
}
&__choices {
display: flex;
gap: 16px;
align-items: center;
}
}
.sat-radio-label {
display: flex;
align-items: center;
gap: 6px;
font-size: 14px;
color: $gray-900;
cursor: pointer;
[type='radio'] {
accent-color: $accent;
width: 16px;
height: 16px;
cursor: pointer;
}
}
.sat-note {
display: flex;
align-items: flex-start;
gap: 8px;
margin-top: 12px;
padding: 10px 14px;
border-radius: 8px;
background: #fffbeb;
border: 1px solid #fde68a;
font-size: 13px;
color: #92400e;
}
@@ -0,0 +1,154 @@
/**
* 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/.
*/
import { Component, Input, OnInit, inject } from '@angular/core';
import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms';
import { Dates } from 'app/core/utils/dates';
import { SettingsService } from 'app/settings/settings.service';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
@Component({
selector: 'mifosx-savings-account-term-step',
templateUrl: './savings-account-term-step.component.html',
styleUrls: ['./savings-account-term-step.component.scss'],
imports: [...STANDALONE_SHARED_IMPORTS]
})
export class SavingsAccountTermStepComponent implements OnInit {
private formBuilder = inject(UntypedFormBuilder);
private dateUtils = inject(Dates);
private settingsService = inject(SettingsService);
private _savingsAccountProductTemplate: any;
@Input()
set savingsAccountProductTemplate(value: any) {
this._savingsAccountProductTemplate = value;
if (value && this.savingsAccountTermForm) {
this.applyTemplate(value);
}
}
get savingsAccountProductTemplate(): any {
return this._savingsAccountProductTemplate;
}
savingsAccountTermForm: UntypedFormGroup;
interestCompoundingPeriodTypeData: any[] = [];
interestPostingPeriodTypeData: any[] = [];
interestCalculationTypeData: any[] = [];
interestCalculationDaysInYearTypeData: any[] = [];
interestCalculateSelectorData: any[] = [];
periodFrequencyData: any[] = [];
yesNoOptions = [
{ value: true, label: 'Yes' },
{ value: false, label: 'No' }
];
minDate = new Date(2000, 0, 1);
maxDate = new Date();
constructor() {
this.createForm();
}
createForm() {
this.savingsAccountTermForm = this.formBuilder.group({
currencyCode: [{ value: '', disabled: true }],
nominalAnnualInterestRate: [
'',
[
Validators.required,
Validators.min(0)
]
],
interestCompoundingPeriodType: [
'',
Validators.required
],
interestPostingPeriodType: [
'',
Validators.required
],
interestCalculationType: [
'',
Validators.required
],
interestCalculationDaysInYearType: [
'',
Validators.required
],
effectiveDate: [''],
interestCalculateSelector: [1],
averagePeriod: ['Monthly'],
autoPost: [true],
frequencyFixDay: [
30,
[Validators.min(0)]
],
lastInterestDate: ['']
});
}
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
// Apply template if it was set before the form was ready
if (this._savingsAccountProductTemplate) {
this.applyTemplate(this._savingsAccountProductTemplate);
}
}
private applyTemplate(t: any) {
this.maxDate = this.settingsService.businessDate;
this.interestCompoundingPeriodTypeData = t.interestCompoundingPeriodTypeOptions || [];
this.interestPostingPeriodTypeData = t.interestPostingPeriodTypeOptions || [];
this.interestCalculationTypeData = t.interestCalculationTypeOptions || [];
this.interestCalculateSelectorData = t.interestCalculationTypeOption || [];
this.interestCalculationDaysInYearTypeData = t.interestCalculationDaysInYearTypeOptions || [];
this.periodFrequencyData = t.periodFrequencyOptions?.length ? t.periodFrequencyOptions : [
{ value: 'Monthly' },
{ value: 'Quarterly' },
{ value: 'Half Yearly' },
{ value: 'Yearly' }];
const defaultPeriod = this.periodFrequencyData[0]?.value || 'Monthly';
const savedEnumTypeId = t.interestCalculationType?.id || this.interestCalculationTypeData?.[0]?.id || 1;
const savedSelectorId = t.interestCalculateSelector ?? this.interestCalculateSelectorData?.[0]?.id ?? null;
this.savingsAccountTermForm.patchValue({
currencyCode: t.currency?.code,
nominalAnnualInterestRate: t.nominalAnnualInterestRate,
interestCompoundingPeriodType: t.interestCompoundingPeriodType?.id,
interestPostingPeriodType: t.interestPostingPeriodType?.id,
interestCalculationType: savedEnumTypeId,
interestCalculationDaysInYearType: t.interestCalculationDaysInYearType?.id,
effectiveDate: t.effectiveDate ? new Date(t.effectiveDate) : '',
interestCalculateSelector: savedSelectorId,
averagePeriod: t.averagePeriod || defaultPeriod,
autoPost: t.autoPost ?? true,
frequencyFixDay: t.frequencyFixDay ?? 30,
lastInterestDate: t.lastInterestDate ? new Date(t.lastInterestDate) : ''
});
}
get savingsAccountTerms() {
const value = { ...this.savingsAccountTermForm.getRawValue() };
const dateFormat = this.settingsService.dateFormat;
if (value.effectiveDate instanceof Date) {
value.effectiveDate = this.dateUtils.formatDate(value.effectiveDate, dateFormat) || '';
}
if (value.lastInterestDate instanceof Date) {
value.lastInterestDate = this.dateUtils.formatDate(value.lastInterestDate, dateFormat) || '';
}
delete value.currencyCode;
return value;
}
}