From 753b623eb16e737f452541cdf63df0d279ef53cc Mon Sep 17 00:00:00 2001 From: Shubham Kumar Date: Thu, 27 Nov 2025 20:44:50 +0530 Subject: [PATCH] fix(charges): normalize chargeId, skip invalid charges, and preserve UI charge fields to fix preview errors and disbursement failures (#2822) improve the line is missing the empty string fallback present --- .../create-glim-account.component.ts | 29 +++++++++++++++--- .../loans-account-charges-step.component.html | 4 +-- .../loans-account-charges-step.component.ts | 23 ++++---------- .../loans-account-preview-step.component.html | 4 +-- src/app/loans/loans.service.ts | 30 +++++++++++++++---- 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/app/loans/glim-account/create-glim-account/create-glim-account.component.ts b/src/app/loans/glim-account/create-glim-account/create-glim-account.component.ts index c1d04dcfb..cce31c63b 100644 --- a/src/app/loans/glim-account/create-glim-account/create-glim-account.component.ts +++ b/src/app/loans/glim-account/create-glim-account/create-glim-account.component.ts @@ -183,10 +183,31 @@ export class CreateGlimAccountComponent { // const monthDayFormat = 'dd MMMM'; const data = { ...this.loansAccount, - charges: this.loansAccount.charges.map((charge: any) => ({ - chargeId: charge.id, - amount: charge.amount - })), + charges: (this.loansAccount.charges ?? []) + .map((charge: any) => { + const chargeId = charge.chargeId ?? charge.id; + if (chargeId == null) { + return null; + } + const mappedCharge: any = { + chargeId, + amount: charge.amount + }; + if (charge.id && charge.id !== chargeId) { + mappedCharge.id = charge.id; + } + if (charge.dueDate) { + mappedCharge.dueDate = this.dateUtils.formatDate(charge.dueDate, dateFormat); + } + if (charge.feeInterval !== undefined) { + mappedCharge.feeInterval = charge.feeInterval; + } + if (charge.feeOnMonthDay !== undefined) { + mappedCharge.feeOnMonthDay = charge.feeOnMonthDay; + } + return mappedCharge; + }) + .filter(Boolean), clientId: client.id, totalLoan: totalLoan, loanType: 'glim', diff --git a/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.html b/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.html index bec25484f..d257c71b8 100644 --- a/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.html +++ b/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.html @@ -24,7 +24,7 @@ {{ 'labels.inputs.name' | translate }} - {{ charge.name + ', ' + charge.currency.displaySymbol }} + {{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }} @@ -110,7 +110,7 @@ - + diff --git a/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts b/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts index 1dc89530e..95a13bc45 100644 --- a/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts +++ b/src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts @@ -338,32 +338,21 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges { get loansAccountCharges() { const uniqueCharges = this.getUniqueCharges(this.chargesDataSource); return { - charges: uniqueCharges.map((charge: any) => { - const result: any = {}; - result.chargeId = charge.chargeId; - - if (charge.id && charge.id !== charge.chargeId) { - result.id = charge.id; - } - - if (charge.amount !== undefined) result.amount = charge.amount; - if (charge.dueDate !== undefined) result.dueDate = charge.dueDate; - if (charge.feeInterval !== undefined) result.feeInterval = charge.feeInterval; - if (charge.feeOnMonthDay !== undefined) result.feeOnMonthDay = charge.feeOnMonthDay; - - return result; - }) + charges: uniqueCharges.map((charge: any) => ({ + ...charge, + chargeId: charge.chargeId ?? charge.id + })) }; } private getUniqueCharges(charges: T[]): T[] { const uniqueChargesMap = new Map(); for (const charge of charges ?? []) { - const chargeId = charge.chargeId; + const chargeId = charge.chargeId ?? charge.id; if (chargeId == null) { continue; } - uniqueChargesMap.set(chargeId, charge); + uniqueChargesMap.set(chargeId, { ...charge, chargeId }); } return Array.from(uniqueChargesMap.values()); diff --git a/src/app/loans/loans-account-stepper/loans-account-preview-step/loans-account-preview-step.component.html b/src/app/loans/loans-account-stepper/loans-account-preview-step/loans-account-preview-step.component.html index cbe1a36f4..13c8ad7f1 100644 --- a/src/app/loans/loans-account-stepper/loans-account-preview-step/loans-account-preview-step.component.html +++ b/src/app/loans/loans-account-stepper/loans-account-preview-step/loans-account-preview-step.component.html @@ -262,7 +262,7 @@ @@ -329,7 +329,7 @@
{{ 'labels.inputs.name' | translate }}{{ charge.name }},{{ charge.currency.displaySymbol }}{{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }} {{ 'labels.inputs.name' | translate }} - {{ charge.name + ', ' + charge.currency.displaySymbol }} + {{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }}
- + diff --git a/src/app/loans/loans.service.ts b/src/app/loans/loans.service.ts index 2f2da319a..59d31f6ea 100644 --- a/src/app/loans/loans.service.ts +++ b/src/app/loans/loans.service.ts @@ -642,11 +642,31 @@ export class LoansService { ): any { const loansAccountData = { ...loansAccount, - charges: loansAccount.charges.map((charge: any) => ({ - chargeId: charge.id, - amount: charge.amount, - dueDate: charge.dueDate && this.dateUtils.formatDate(charge.dueDate, dateFormat) - })), + charges: (loansAccount.charges ?? []) + .map((charge: any) => { + const chargeId = charge.chargeId ?? charge.id; + if (chargeId == null) { + return null; + } + const mappedCharge: any = { + chargeId, + amount: charge.amount + }; + if (charge.id && charge.id !== chargeId) { + mappedCharge.id = charge.id; + } + if (charge.dueDate) { + mappedCharge.dueDate = this.dateUtils.formatDate(charge.dueDate, dateFormat); + } + if (charge.feeInterval !== undefined) { + mappedCharge.feeInterval = charge.feeInterval; + } + if (charge.feeOnMonthDay !== undefined) { + mappedCharge.feeOnMonthDay = charge.feeOnMonthDay; + } + return mappedCharge; + }) + .filter(Boolean), disbursementData: loansAccount.disbursementData.map((item: any) => ({ expectedDisbursementDate: this.dateUtils.formatDate(item.expectedDisbursementDate, dateFormat), principal: item.principal
{{ 'labels.inputs.name' | translate }}{{ charge.name }},{{ charge.currency.displaySymbol }}{{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }}