Skip to content

Commit 753b623

Browse files
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
1 parent 5effdb9 commit 753b623

File tree

5 files changed

+60
-30
lines changed

5 files changed

+60
-30
lines changed

src/app/loans/glim-account/create-glim-account/create-glim-account.component.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,31 @@ export class CreateGlimAccountComponent {
183183
// const monthDayFormat = 'dd MMMM';
184184
const data = {
185185
...this.loansAccount,
186-
charges: this.loansAccount.charges.map((charge: any) => ({
187-
chargeId: charge.id,
188-
amount: charge.amount
189-
})),
186+
charges: (this.loansAccount.charges ?? [])
187+
.map((charge: any) => {
188+
const chargeId = charge.chargeId ?? charge.id;
189+
if (chargeId == null) {
190+
return null;
191+
}
192+
const mappedCharge: any = {
193+
chargeId,
194+
amount: charge.amount
195+
};
196+
if (charge.id && charge.id !== chargeId) {
197+
mappedCharge.id = charge.id;
198+
}
199+
if (charge.dueDate) {
200+
mappedCharge.dueDate = this.dateUtils.formatDate(charge.dueDate, dateFormat);
201+
}
202+
if (charge.feeInterval !== undefined) {
203+
mappedCharge.feeInterval = charge.feeInterval;
204+
}
205+
if (charge.feeOnMonthDay !== undefined) {
206+
mappedCharge.feeOnMonthDay = charge.feeOnMonthDay;
207+
}
208+
return mappedCharge;
209+
})
210+
.filter(Boolean),
190211
clientId: client.id,
191212
totalLoan: totalLoan,
192213
loanType: 'glim',

src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<ng-container matColumnDef="name">
2525
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.name' | translate }}</th>
2626
<td mat-cell *matCellDef="let charge">
27-
{{ charge.name + ', ' + charge.currency.displaySymbol }}
27+
{{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }}
2828
</td>
2929
</ng-container>
3030

@@ -110,7 +110,7 @@ <h4 class="mat-h4 flex-98">{{ 'labels.heading.Overdue Charges' | translate }}</h
110110
<table mat-table class="mat-elevation-z1" [dataSource]="overDueChargesDataSource">
111111
<ng-container matColumnDef="name">
112112
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.name' | translate }}</th>
113-
<td mat-cell *matCellDef="let charge">{{ charge.name }},{{ charge.currency.displaySymbol }}</td>
113+
<td mat-cell *matCellDef="let charge">{{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }}</td>
114114
</ng-container>
115115

116116
<ng-container matColumnDef="type">

src/app/loans/loans-account-stepper/loans-account-charges-step/loans-account-charges-step.component.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,32 +338,21 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
338338
get loansAccountCharges() {
339339
const uniqueCharges = this.getUniqueCharges(this.chargesDataSource);
340340
return {
341-
charges: uniqueCharges.map((charge: any) => {
342-
const result: any = {};
343-
result.chargeId = charge.chargeId;
344-
345-
if (charge.id && charge.id !== charge.chargeId) {
346-
result.id = charge.id;
347-
}
348-
349-
if (charge.amount !== undefined) result.amount = charge.amount;
350-
if (charge.dueDate !== undefined) result.dueDate = charge.dueDate;
351-
if (charge.feeInterval !== undefined) result.feeInterval = charge.feeInterval;
352-
if (charge.feeOnMonthDay !== undefined) result.feeOnMonthDay = charge.feeOnMonthDay;
353-
354-
return result;
355-
})
341+
charges: uniqueCharges.map((charge: any) => ({
342+
...charge,
343+
chargeId: charge.chargeId ?? charge.id
344+
}))
356345
};
357346
}
358347
private getUniqueCharges<T extends { id?: number | string; chargeId?: number | string }>(charges: T[]): T[] {
359348
const uniqueChargesMap = new Map<number | string, T>();
360349

361350
for (const charge of charges ?? []) {
362-
const chargeId = charge.chargeId;
351+
const chargeId = charge.chargeId ?? charge.id;
363352
if (chargeId == null) {
364353
continue;
365354
}
366-
uniqueChargesMap.set(chargeId, charge);
355+
uniqueChargesMap.set(chargeId, { ...charge, chargeId });
367356
}
368357

369358
return Array.from(uniqueChargesMap.values());

src/app/loans/loans-account-stepper/loans-account-preview-step/loans-account-preview-step.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ <h3 class="mat-h3 flex-fill">{{ 'labels.heading.Charges' | translate }}</h3>
262262
<ng-container matColumnDef="name">
263263
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.name' | translate }}</th>
264264
<td mat-cell *matCellDef="let charge">
265-
{{ charge.name + ', ' + charge.currency.displaySymbol }}
265+
{{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }}
266266
</td>
267267
</ng-container>
268268

@@ -329,7 +329,7 @@ <h3 class="mat-h3 flex-98">{{ 'labels.heading.Overdue Charges' | translate }}</h
329329
<table mat-table class="mat-elevation-z1" [dataSource]="loansAccountProductTemplate.overdueCharges">
330330
<ng-container matColumnDef="name">
331331
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.name' | translate }}</th>
332-
<td mat-cell *matCellDef="let charge">{{ charge.name }},{{ charge.currency.displaySymbol }}</td>
332+
<td mat-cell *matCellDef="let charge">{{ charge.name + ', ' + (charge.currency?.displaySymbol || '') }}</td>
333333
</ng-container>
334334

335335
<ng-container matColumnDef="type">

src/app/loans/loans.service.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,31 @@ export class LoansService {
642642
): any {
643643
const loansAccountData = {
644644
...loansAccount,
645-
charges: loansAccount.charges.map((charge: any) => ({
646-
chargeId: charge.id,
647-
amount: charge.amount,
648-
dueDate: charge.dueDate && this.dateUtils.formatDate(charge.dueDate, dateFormat)
649-
})),
645+
charges: (loansAccount.charges ?? [])
646+
.map((charge: any) => {
647+
const chargeId = charge.chargeId ?? charge.id;
648+
if (chargeId == null) {
649+
return null;
650+
}
651+
const mappedCharge: any = {
652+
chargeId,
653+
amount: charge.amount
654+
};
655+
if (charge.id && charge.id !== chargeId) {
656+
mappedCharge.id = charge.id;
657+
}
658+
if (charge.dueDate) {
659+
mappedCharge.dueDate = this.dateUtils.formatDate(charge.dueDate, dateFormat);
660+
}
661+
if (charge.feeInterval !== undefined) {
662+
mappedCharge.feeInterval = charge.feeInterval;
663+
}
664+
if (charge.feeOnMonthDay !== undefined) {
665+
mappedCharge.feeOnMonthDay = charge.feeOnMonthDay;
666+
}
667+
return mappedCharge;
668+
})
669+
.filter(Boolean),
650670
disbursementData: loansAccount.disbursementData.map((item: any) => ({
651671
expectedDisbursementDate: this.dateUtils.formatDate(item.expectedDisbursementDate, dateFormat),
652672
principal: item.principal

0 commit comments

Comments
 (0)