feat(accounts): add Modify Application for rejected Current/Savings/FD/RD accounts

- Add 'Modify Application' button in kebab menu for rejected accounts (all 4 types)
- Rewrite edit components with tab-based UI matching create form
- Pre-populate all create-time values in edit form: product, account status,
  customer segment, account type, joint holders, nominees, introducer,
  deposit account link, senior citizen rate, tenure, flags (msme/balanceSwap/autoDebit)
- Fix edit mode detection using accountNo presence
- Add preselectedIntroducer @Input to IntroducerSearchComponent for pre-fill
- Support both camelCase and lowercase keys for joint holders (MySQL queryForList)
- Fix account number display: actual accountNo before previewAccountNo
- Fix cbsAccountType restore: cbsAccountType only, avoid Fineract enum object
- Add nominees fetch via /clients/{id}/nominees API in all 4 edit components
- Fix RD/FD Interest Rate Chart: SimpleChanges to prevent reset race condition
- Pre-check Senior Citizen checkbox in edit form from isSeniorCitizen DB field
- Auto-calculate rate when tenure pre-filled in edit mode
- FD calculator: use backend calculate-fd-interest API for all compounding types
- Support interestCompoundingPeriodInMonths=0 (daily) in FD calculator API

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jaanu423
2026-06-03 10:36:40 +05:30
co-authored by Claude Sonnet 4.6
parent 3be2f96210
commit 260fabaa48
37 changed files with 2744 additions and 730 deletions
@@ -6,76 +6,140 @@
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<div class="container">
<mat-stepper
orientation="vertical"
[linear]="false"
class="mat-elevation-z8"
labelPosition="bottom"
#savingProductStepper
<div class="csa-container">
<!-- Hero -->
<div class="csa-header">
<fa-icon icon="piggy-bank" class="csa-header__icon"></fa-icon>
<div>
<h2 class="csa-header__title">Modify Savings Account Application</h2>
<div class="csa-header__sub">
Review and update the account details, currency settings and digital channels before resubmitting.
</div>
</div>
</div>
<!-- Wizard tabs -->
<mat-tab-group
class="csa-tabs"
animationDuration="200ms"
[preserveContent]="true"
[(selectedIndex)]="selectedTabIndex"
>
<ng-template matStepperIcon="number">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>
<ng-template matStepperIcon="edit">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>
<ng-template matStepperIcon="done">
<fa-icon icon="check" size="sm"></fa-icon>
</ng-template>
<ng-template matStepperIcon="error">
<fa-icon icon="exclamation-triangle" size="lg"></fa-icon>
</ng-template>
<ng-template matStepperIcon="preview">
<fa-icon icon="eye" size="sm"></fa-icon>
</ng-template>
<mat-step [stepControl]="savingsAccountDetailsForm">
<ng-template matStepLabel>{{ 'labels.inputs.DETAILS' | translate }}</ng-template>
<mifosx-savings-account-details-step
[savingsAccountTemplate]="savingsAccountAndTemplate"
(savingsAccountProductTemplate)="setTemplate($event)"
>
</mifosx-savings-account-details-step>
</mat-step>
<mat-step [stepControl]="savingsAccountTermsForm">
<ng-template matStepLabel>{{ 'labels.inputs.TERMS' | translate }}</ng-template>
<mifosx-savings-account-terms-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
[savingsAccountTemplate]="savingsAccountAndTemplate"
></mifosx-savings-account-terms-step>
</mat-step>
<mat-step>
<ng-template matStepLabel>{{ 'labels.inputs.CHARGES' | translate }}</ng-template>
<mifosx-savings-account-charges-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
[savingsAccountTemplate]="savingsAccountAndTemplate"
[currencyCode]="savingsAccountTermsForm.get('currencyCode')"
>
</mifosx-savings-account-charges-step>
</mat-step>
@if (savingsAccountFormValidAndNotPristine) {
<mat-step completed>
<ng-template matStepLabel>{{ 'labels.inputs.PREVIEW' | translate }}</ng-template>
<mifosx-savings-account-preview-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
<!-- Tab 1: Product Classification + Details -->
<mat-tab>
<ng-template mat-tab-label>
<fa-icon icon="check-square" class="csa-tab__icon"></fa-icon>
Product
</ng-template>
<div class="csa-tab-body">
<mifosx-savings-account-details-step
[savingsAccountTemplate]="savingsAccountAndTemplate"
[savingsAccountTermsForm]="savingsAccountTermsForm"
[savingsAccount]="savingsAccount"
(submitEvent)="submit()"
(savingsAccountProductTemplate)="setTemplate($event)"
>
</mifosx-savings-account-preview-step>
</mat-step>
}
</mat-stepper>
</mifosx-savings-account-details-step>
<div class="csa-actions">
<span class="csa-actions__spacer"></span>
<button mat-raised-button color="primary" [disabled]="!savingsAccountProductTemplate" (click)="next()">
{{ 'labels.buttons.Next' | translate }}
<fa-icon icon="arrow-right" class="m-l-10"></fa-icon>
</button>
</div>
</div>
</mat-tab>
<!-- Tab 2: Currency -->
<mat-tab [disabled]="!savingsAccountProductTemplate">
<ng-template mat-tab-label>
<fa-icon icon="dollar-sign" class="csa-tab__icon"></fa-icon>
Currency
</ng-template>
<div class="csa-tab-body">
@if (savingsAccountProductTemplate) {
<mifosx-savings-account-currency-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
[primaryClientId]="savingsAccountAndTemplate?.clientId ?? null"
[existingAccount]="savingsAccountAndTemplate"
></mifosx-savings-account-currency-step>
}
<div class="csa-actions">
<button mat-stroked-button (click)="prev()">
<fa-icon icon="arrow-left" class="m-r-10"></fa-icon>
{{ 'labels.buttons.Previous' | translate }}
</button>
<span class="csa-actions__spacer"></span>
<button mat-raised-button color="primary" (click)="next()">
{{ 'labels.buttons.Next' | translate }}
<fa-icon icon="arrow-right" class="m-l-10"></fa-icon>
</button>
</div>
</div>
</mat-tab>
<!-- Tab 3: Digital -->
<mat-tab [disabled]="!savingsAccountProductTemplate">
<ng-template mat-tab-label>
<fa-icon icon="mobile-alt" class="csa-tab__icon"></fa-icon>
Digital
</ng-template>
<div class="csa-tab-body">
@if (savingsAccountProductTemplate) {
<mifosx-savings-account-digital-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
[existingAccount]="savingsAccountAndTemplate"
></mifosx-savings-account-digital-step>
}
<div class="csa-actions">
<button mat-stroked-button (click)="prev()">
<fa-icon icon="arrow-left" class="m-r-10"></fa-icon>
{{ 'labels.buttons.Previous' | translate }}
</button>
<span class="csa-actions__spacer"></span>
<button mat-raised-button color="primary" (click)="next()">
{{ 'labels.buttons.Next' | translate }}
<fa-icon icon="arrow-right" class="m-l-10"></fa-icon>
</button>
</div>
</div>
</mat-tab>
<!-- Tab 4: Preview / Submit -->
<mat-tab [disabled]="!savingsAccountProductTemplate">
<ng-template mat-tab-label>
<fa-icon icon="eye" class="csa-tab__icon"></fa-icon>
{{ 'labels.inputs.PREVIEW' | translate }}
</ng-template>
<div class="csa-tab-body">
@if (savingsAccountProductTemplate) {
<mifosx-savings-account-preview-step
[savingsAccountProductTemplate]="savingsAccountProductTemplate"
[savingsAccountTemplate]="savingsAccountAndTemplate"
[savingsAccountTermsForm]="savingsAccountTermsForm"
[savingsAccount]="savingsAccount"
[savingsAccountDigital]="savingsAccountDigital"
[savingsAccountNominees]="savingsAccountCurrencyStep?.nominees ?? []"
(submitEvent)="submit()"
>
</mifosx-savings-account-preview-step>
}
<div class="csa-actions">
<button mat-stroked-button (click)="prev()">
<fa-icon icon="arrow-left" class="m-r-10"></fa-icon>
{{ 'labels.buttons.Previous' | translate }}
</button>
<span class="csa-actions__spacer"></span>
<button mat-stroked-button [routerLink]="['../']">
{{ 'labels.buttons.Cancel' | translate }}
</button>
<button mat-raised-button color="primary" (click)="submit()">
<fa-icon icon="check" class="m-r-10"></fa-icon>
{{ 'labels.buttons.Submit' | translate }}
</button>
</div>
</div>
</mat-tab>
</mat-tab-group>
</div>
@@ -5,3 +5,164 @@
* 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/.
*/
$navy: #0d1b2a;
$blue: #1e88e5;
$blue-d: #1e40af;
$indigo: #4f46e5;
$border: #e2e8f0;
.csa-container {
max-width: 1180px;
margin: 0 auto;
padding: 20px 24px;
}
/* ─── Hero header (matches Nexora pages) ────────────────────────────── */
.csa-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 16px;
&__icon {
width: 44px;
height: 44px;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 12px;
background: linear-gradient(135deg, $blue 0%, $indigo 100%);
color: #fff;
font-size: 18px;
box-shadow: 0 2px 8px rgb(29 78 216 / 25%);
flex-shrink: 0;
}
&__title {
margin: 0;
font-size: 20px;
font-weight: 800;
color: $navy;
line-height: 1.1;
letter-spacing: 0.02em;
}
&__sub {
margin-top: 2px;
font-size: 12.5px;
color: #64748b;
}
}
/* ─── Wizard tab strip ──────────────────────────────────────────────── */
.csa-tabs {
background: #fff;
border: 1px solid $border;
border-radius: 14px;
box-shadow: 0 1px 3px rgb(15 23 42 / 4%);
overflow: hidden;
::ng-deep {
.mat-mdc-tab-header {
background: #f8fafc;
border-bottom: 1px solid $border;
}
.mat-mdc-tab {
min-width: 140px;
height: 50px;
padding: 0 22px;
font-size: 13px !important;
font-weight: 600 !important;
letter-spacing: 0.01em;
color: #475569 !important;
opacity: 1 !important;
}
.mat-mdc-tab:hover:not(.mdc-tab--active, .mat-mdc-tab-disabled) {
background: rgb(30 64 175 / 5%);
color: $navy !important;
}
.mat-mdc-tab.mdc-tab--active {
.mdc-tab__text-label {
color: $blue-d !important;
font-weight: 700 !important;
}
}
.mdc-tab-indicator__content--underline {
border-color: $blue-d !important;
border-top-width: 3px !important;
}
.mat-mdc-tab.mat-mdc-tab-disabled {
opacity: 0.45 !important;
cursor: not-allowed;
}
.mat-mdc-tab-body-wrapper {
min-height: 320px;
}
.mat-mdc-tab-body,
.mat-mdc-tab-body-content {
overflow: visible !important;
}
}
}
.csa-tab__icon {
margin-right: 8px;
font-size: 13px;
}
/* ─── Tab body + action bar ─────────────────────────────────────────── */
.csa-tab-body {
padding: 24px;
@media (width <= 768px) {
padding: 16px;
}
}
.csa-actions {
display: flex;
align-items: center;
gap: 12px;
margin-top: 24px;
padding-top: 16px;
border-top: 1px solid #f1f5f9;
&__spacer {
flex: 1;
}
button {
height: 40px !important;
border-radius: 10px !important;
font-weight: 600 !important;
padding: 0 18px !important;
}
}
.m-l-10 {
margin-left: 8px;
}
.m-r-10 {
margin-right: 8px;
}
button.preview-submit-row__primary,
.mat-mdc-raised-button.mat-primary.preview-submit-row__primary,
.preview-submit-row__primary {
background: linear-gradient(135deg, #10b981 0%, #047857 100%) !important;
--mdc-protected-button-container-color: transparent !important;
--mdc-filled-button-container-color: transparent !important;
color: #fff !important;
box-shadow: 0 4px 12px -2px rgb(4 120 87 / 35%) !important;
}
@@ -9,23 +9,26 @@
/** Angular Imports */
import { Component, ViewChild, inject } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormGroup } from '@angular/forms';
import { ClientsService } from 'app/clients/clients.service';
/** Custom Components */
import { SavingsAccountDetailsStepComponent } from '../savings-account-stepper/savings-account-details-step/savings-account-details-step.component';
import { SavingsAccountTermsStepComponent } from '../savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component';
import { SavingsAccountChargesStepComponent } from '../savings-account-stepper/savings-account-charges-step/savings-account-charges-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';
/** 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 } from '@angular/material/stepper';
import { AlertService } from 'app/core/alert/alert.service';
import { MatTabsModule } from '@angular/material/tabs';
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';
/**
* Edit Savings Account Component
* Edit Savings Account Component — same tab UI as Create, pre-populated with existing data.
*/
@Component({
selector: 'mifosx-edit-savings-account',
@@ -33,14 +36,11 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
styleUrls: ['./edit-savings-account.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
MatStepper,
MatStepperIcon,
MatTabsModule,
FaIconComponent,
MatStep,
MatStepLabel,
SavingsAccountDetailsStepComponent,
SavingsAccountTermsStepComponent,
SavingsAccountChargesStepComponent,
SavingsAccountCurrencyStepComponent,
SavingsAccountDigitalStepComponent,
SavingsAccountPreviewStepComponent
]
})
@@ -50,109 +50,135 @@ export class EditSavingsAccountComponent {
private dateUtils = inject(Dates);
private savingsService = inject(SavingsService);
private settingsService = inject(SettingsService);
private alertService = inject(AlertService);
private clientsService = inject(ClientsService);
/** Savings Account Template */
/** Full account data + template from resolver */
savingsAccountAndTemplate: any;
/** Savings Account Product Template */
/** Product template emitted by details step */
savingsAccountProductTemplate: any;
/** Currently visible wizard tab (0-indexed). */
selectedTabIndex = 0;
private readonly totalTabs = 4;
/** Savings Account Details Step */
@ViewChild(SavingsAccountDetailsStepComponent, { static: true })
savingsAccountDetailsStep: SavingsAccountDetailsStepComponent;
/** Savings Account Terms Step */
@ViewChild(SavingsAccountTermsStepComponent, { static: true })
savingsAccountTermsStep: SavingsAccountTermsStepComponent;
/** Savings Account Charges Step */
@ViewChild(SavingsAccountChargesStepComponent, { static: true })
savingsAccountChargesStep: SavingsAccountChargesStepComponent;
/**
* Fetches savings account template from `resolve`
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {Dates} dateUtils Date Utils
* @param {SavingsService} savingsService Savings Service
* @param {SettingsService} settingsService Settings Service
*/
@ViewChild(SavingsAccountCurrencyStepComponent)
savingsAccountCurrencyStep: SavingsAccountCurrencyStepComponent;
@ViewChild(SavingsAccountDigitalStepComponent)
savingsAccountDigitalStep: SavingsAccountDigitalStepComponent;
constructor() {
this.route.data.subscribe((data: { savingsAccountAndTemplate: any }) => {
this.savingsAccountAndTemplate = data.savingsAccountAndTemplate;
const account = data.savingsAccountAndTemplate;
this.savingsAccountAndTemplate = account;
if (account?.clientId && account?.accountNo) {
this.clientsService
.getClientNominees(String(account.clientId), account.accountNo, 'SB')
.subscribe((nominees: any[]) => {
if (Array.isArray(nominees) && nominees.length > 0) {
this.savingsAccountAndTemplate = { ...this.savingsAccountAndTemplate, nominees };
}
});
}
});
}
/**
* Sets savings account product template.
* @param {any} $event API response
*/
setTemplate($event: any) {
this.savingsAccountProductTemplate = $event;
}
/**
* Retrieves savings account details form.
*/
next(): void {
if (this.selectedTabIndex < this.totalTabs - 1) {
this.selectedTabIndex += 1;
}
}
prev(): void {
if (this.selectedTabIndex > 0) {
this.selectedTabIndex -= 1;
}
}
get savingsAccountDetailsForm() {
return this.savingsAccountDetailsStep.savingsAccountDetailsForm;
}
/**
* Retrieves savings account terms form.
*/
get savingsAccountTermsForm() {
return this.savingsAccountTermsStep.savingsAccountTermsForm;
get savingsAccountTermsForm(): FormGroup {
return new FormGroup({});
}
/**
* Checks validity and pristinity of overall savings account form .
*/
get savingsAccountFormValidAndNotPristine() {
return (
this.savingsAccountDetailsForm.valid &&
this.savingsAccountTermsForm.valid &&
(!this.savingsAccountDetailsForm.pristine ||
!this.savingsAccountTermsForm.pristine ||
!this.savingsAccountChargesStep.pristine)
);
}
/**
* Retrieves savings account object.
*/
get savingsAccount() {
return {
...this.savingsAccountDetailsStep.savingsAccountDetails,
...this.savingsAccountTermsStep.savingsAccountTerms,
...this.savingsAccountChargesStep.savingsAccountCharges
};
return { ...this.savingsAccountDetailsStep.savingsAccountDetails };
}
get savingsAccountDigital() {
return this.savingsAccountDigitalStep?.savingsAccountDigital ?? null;
}
/**
* Creates a new share account.
*/
submit() {
// TODO: Update once language and date settings are setup
const detailsStep = this.savingsAccountDetailsStep;
if (detailsStep.selectedAccountStatus === 'JOINT' && detailsStep.totalJointSharePercentage !== 100) {
this.alertService.alert({
type: 'Error',
message: `Total ownership is ${detailsStep.totalJointSharePercentage}%. It must equal 100% before submitting.`
});
return;
}
if (
this.savingsAccountProductTemplate?.nominationFacility &&
(this.savingsAccountCurrencyStep?.nominees ?? []).length === 0
) {
this.alertService.alert({
type: 'Error',
message: 'Nomination Facility is enabled for this product. Please add at least one nominee before submitting.'
});
return;
}
if (this.savingsAccountProductTemplate?.introducerRequired && !this.savingsAccountDetailsStep.introducerId) {
this.alertService.alert({
type: 'Error',
message: 'Introducer is required for this product. Please select an introducer before submitting.'
});
return;
}
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const monthDayFormat = 'dd MMMM';
const savingsAccount = {
const savingsAccount: any = {
...this.savingsAccount,
charges: this.savingsAccount.charges.map((charge: any) => ({
chargeId: charge.id,
amount: charge.amount,
dueDate: this.dateUtils.formatDate(charge.dueDate, dateFormat),
feeOnMonthDay: this.dateUtils.formatDate(charge.feeOnMonthDay, dateFormat),
feeInterval: charge.feeInterval
})),
charges: [],
submittedOnDate: this.dateUtils.formatDate(this.savingsAccount.submittedOnDate, dateFormat),
dateFormat,
monthDayFormat,
locale
};
if (this.savingsAccountDigital?.accountFacilityConfig) {
savingsAccount.accountFacilityConfig = this.savingsAccountDigital.accountFacilityConfig;
}
if (this.savingsAccountAndTemplate.clientId) {
savingsAccount.clientId = this.savingsAccountAndTemplate.clientId;
} else {
savingsAccount.groupId = this.savingsAccountAndTemplate.groupId;
}
const nominees = this.savingsAccountCurrencyStep?.nominees ?? [];
if (nominees.length > 0) {
savingsAccount.nominees = nominees.map((n: any) => ({
nomineeClientId: n.nomineeClientId,
nominationType: n.nominationType,
relationshipId: n.relationshipId,
percentageShare: n.percentageShare,
nomineeIsMinor: n.nomineeIsMinor,
...(n.guardianClientId ? { guardianClientId: n.guardianClientId } : {}),
remarks: n.remarks
}));
}
this.savingsService
.updateSavingsAccount(this.savingsAccountAndTemplate.id, savingsAccount)
.subscribe((response: any) => {
@@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { Component, Input, ViewChild } from '@angular/core';
import { Component, Input, OnChanges, SimpleChanges, ViewChild } from '@angular/core';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
import { NomineeFormComponent } from 'app/shared/nominee-form/nominee-form.component';
import { DormancyAlertPanelComponent } from 'app/shared/dormancy-alert-panel/dormancy-alert-panel.component';
@@ -21,9 +21,10 @@ import { DormancyAlertPanelComponent } from 'app/shared/dormancy-alert-panel/dor
DormancyAlertPanelComponent
]
})
export class SavingsAccountCurrencyStepComponent {
export class SavingsAccountCurrencyStepComponent implements OnChanges {
@Input() savingsAccountProductTemplate: any;
@Input() primaryClientId: number | null = null;
@Input() existingAccount: any = null;
@ViewChild(NomineeFormComponent) nomineeFormComp: NomineeFormComponent;
nominees: any[] = [];
@@ -31,6 +32,32 @@ export class SavingsAccountCurrencyStepComponent {
showNomineeForm = false;
nomineeError = '';
private existingAccountApplied = false;
ngOnChanges(changes: SimpleChanges): void {
if (changes['existingAccount']?.currentValue) {
const ea = changes['existingAccount'].currentValue;
this.existingAccountApplied = true;
const nominees =
Array.isArray(ea.nominees) && ea.nominees.length > 0 ? ea.nominees : this.parseNomineeData(ea.nomineeData);
if (nominees.length > 0) {
this.nominees = [...nominees];
}
}
}
private parseNomineeData(nomineeData: any): any[] {
if (!nomineeData) {
return [];
}
try {
const parsed = typeof nomineeData === 'string' ? JSON.parse(nomineeData) : nomineeData;
return Array.isArray(parsed) ? parsed : [];
} catch {
return [];
}
}
get totalShare(): number {
return this.nominees.reduce((sum, n) => sum + (+n.percentageShare || 0), 0);
}
@@ -91,7 +91,7 @@
<mat-label>Account No</mat-label>
<input
matInput
[value]="productTemplate?.previewAccountNo || savingsAccountTemplate?.accountNo || 'Auto-generated'"
[value]="savingsAccountTemplate?.accountNo || productTemplate?.previewAccountNo || 'Auto-generated'"
readonly
/>
</mat-form-field>
@@ -127,6 +127,9 @@
@if (productTemplate?.introducerRequired) {
<mifosx-introducer-search
[excludedClientIds]="primaryClientId ? [primaryClientId] : []"
[preselectedIntroducer]="
introducerId ? { clientId: introducerId, displayName: introducerName, cifNumber: introducerCif } : null
"
(introducerChange)="onIntroducerChange($event)"
></mifosx-introducer-search>
}
@@ -65,6 +65,7 @@ export class SavingsAccountDetailsStepComponent implements OnInit {
introducerId: number | null = null;
introducerName: string | null = null;
introducerCif: string | null = null;
private isEditMode = false;
@Output() savingsAccountProductTemplate = new EventEmitter();
@@ -166,11 +167,25 @@ export class SavingsAccountDetailsStepComponent implements OnInit {
this.buildDependencies();
if (this.savingsAccountTemplate) {
this.productData = this.savingsAccountTemplate.productOptions;
if (this.savingsAccountTemplate.savingsProductId) {
const existingProductId = this.savingsAccountTemplate.savingsProductId ?? this.savingsAccountTemplate.productId;
// Edit mode: account response always has accountNo
if (this.savingsAccountTemplate.accountNo) {
this.isEditMode = true;
}
if ((!this.productData || this.productData.length === 0) && existingProductId) {
this.isEditMode = true;
this.productData = [
{
id: existingProductId,
name: this.savingsAccountTemplate.productName ?? this.savingsAccountTemplate.savingsProductName ?? 'Product'
}
];
}
if (existingProductId) {
this.savingsAccountDetailsForm.patchValue({
productId: this.savingsAccountTemplate.savingsProductId,
productId: existingProductId,
submittedOnDate:
this.savingsAccountTemplate.timeline.submittedOnDate &&
this.savingsAccountTemplate.timeline?.submittedOnDate &&
new Date(this.savingsAccountTemplate.timeline.submittedOnDate)
});
} else {
@@ -280,6 +295,9 @@ export class SavingsAccountDetailsStepComponent implements OnInit {
/** Auto-set status tile based on age; pre-fill minorDob if minor */
private autoDetectAccountStatus(): void {
if (this.isEditMode) {
return;
}
if (this.clientAge === null) return;
if (this.clientAge < 18) {
@@ -319,8 +337,6 @@ export class SavingsAccountDetailsStepComponent implements OnInit {
this.customerSegmentOptions = this.extractOptions(response.customerSegmentOptions, response.customerSegment);
this.selectedAccountType = response.accountType ?? null;
this.selectedCustomerSegment = response.customerSegment ?? null;
// Override the product's default segment with the one inferred
// from the client's entity type when an option matches.
this.applyInferredCustomerSegment();
this.savingsAccountProductTemplate.emit(response);
this.fieldOfficerData = response.fieldOfficerOptions;
@@ -332,10 +348,93 @@ export class SavingsAccountDetailsStepComponent implements OnInit {
} else {
this.savingsAccountDetailsForm.get('fieldOfficerId').patchValue('');
}
// === Restore existing account values when in edit/modify mode ===
this.restoreExistingAccountValues();
});
});
}
private restoreExistingAccountValues(): void {
const ea = this.savingsAccountTemplate;
if (!ea?.savingsProductId && !ea?.productId) {
return;
}
const strVal = (v: any): string => (typeof v === 'object' && v !== null ? (v.value ?? '') : (v ?? ''));
const accountStatus = strVal(ea.accountStatus);
if (accountStatus) {
this.selectedAccountStatus = accountStatus;
}
const customerSegment = strVal(ea.customerSegment);
if (customerSegment) {
this.selectedCustomerSegment = customerSegment;
}
const accountType = ea.cbsAccountType ? strVal(ea.cbsAccountType) : null;
if (accountType) {
this.selectedAccountType = accountType;
}
if (accountStatus === 'JOINT') {
const modeOfOp = strVal(ea.modeOfOperation);
if (modeOfOp) {
this.modeOfOperation = modeOfOp;
}
if (Array.isArray(ea.jointHolders) && ea.jointHolders.length > 0) {
const isPH = (h: any) => h.isPrimary ?? h.isprimary ?? false;
const primary = ea.jointHolders.find((h: any) => isPH(h));
const ps = primary?.sharePercentage ?? primary?.sharepercentage;
if (ps) {
this.primaryHolderShare = +ps;
}
this.jointHolders = ea.jointHolders
.filter((h: any) => !isPH(h))
.map((h: any) => ({
clientId: h.clientId ?? h.clientid,
clientName: h.displayName ?? h.displayname ?? h.clientName ?? '',
clientCif: h.cifNumber ?? h.cifnumber ?? h.clientCif ?? '',
sharePercentage: +(h.sharePercentage ?? h.sharepercentage ?? 0),
isMandatory: !!(h.isMandatory ?? h.ismandatory)
}));
}
}
if (accountStatus === 'INDIVIDUAL_MALE' && ea.specialCategory) {
this.selectedSpecialCategory = ea.specialCategory;
}
if (accountStatus === 'INDIVIDUAL_FEMALE' && ea.weakerSection) {
this.selectedWeakerSection = ea.weakerSection;
}
if (accountStatus === 'MINOR') {
if (ea.guardianClientId) {
this.guardianClientId = ea.guardianClientId;
}
if (ea.guardianName) {
this.guardianName = ea.guardianName;
}
if (ea.guardianCifNumber) {
this.guardianCif = ea.guardianCifNumber;
}
if (ea.guardianRelationship) {
this.guardianRelationship = ea.guardianRelationship;
}
if (ea.minorDateOfBirth) {
const d = new Date(ea.minorDateOfBirth);
if (!isNaN(d.getTime())) {
this.minorDob = d;
}
}
}
const introId = ea.introducerId ?? ea.introducerClientId;
if (introId) {
this.introducerId = introId;
this.introducerName = ea.introducerName ?? null;
this.introducerCif = ea.introducerCifNumber ?? null;
}
this.cdr.detectChanges();
}
private extractOptions(options: any[], fallback?: string): string[] {
if (Array.isArray(options) && options.length > 0) {
return options.map((o: any) => o.value ?? o.name ?? o);
@@ -40,10 +40,19 @@ const DEFAULT_FACILITY_CONFIG = {
})
export class SavingsAccountDigitalStepComponent {
facilityConfig = { ...DEFAULT_FACILITY_CONFIG };
private hasExistingAccount = false;
@Input()
set existingAccount(value: any) {
if (value?.accountFacilityConfig) {
this.hasExistingAccount = true;
this.facilityConfig = { ...DEFAULT_FACILITY_CONFIG, ...value.accountFacilityConfig };
}
}
@Input()
set savingsAccountProductTemplate(value: any) {
if (value?.accountFacilityConfig) {
if (!this.hasExistingAccount && value?.accountFacilityConfig) {
this.facilityConfig = { ...DEFAULT_FACILITY_CONFIG, ...value.accountFacilityConfig };
}
}
@@ -142,6 +142,16 @@ export class SavingsButtonsConfiguration {
}
];
break;
case 'Rejected':
case 'rejected':
this.buttonsArray = [
{
name: 'Modify Application',
icon: 'pen',
taskPermissionName: 'UPDATE_SAVINGSACCOUNT'
}
];
break;
default:
this.buttonsArray = [];
}