Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/app/loans/edit-loans-account/edit-loans-account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,20 @@ export class EditLoansAccountComponent {
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const loanType = 'individual';
const uniqueCharges = new Map<number | string, any>();
(this.loansAccount.charges ?? []).forEach((charge: any) => {
const chargeId = charge.id ?? charge.chargeId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are doing this? I mean the Charge has an attribute for the Id and that's all

if (chargeId == null) {
return;
} // Skip malformed entries
uniqueCharges.set(chargeId, charge);
});

const loansAccountData = {
...this.loansAccount,
clientId: this.loansAccountAndTemplate.clientId,
charges: this.loansAccount.charges.map((charge: any) => ({
chargeId: charge.id,
charges: Array.from(uniqueCharges.values()).map((charge: any) => ({
chargeId: charge.id ?? charge.chargeId,
amount: charge.amount,
dueDate: charge.dueDate && this.dateUtils.formatDate(charge.dueDate, dateFormat)
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
if (this.loansAccountProductTemplate.overdueCharges) {
this.overDueChargesDataSource = this.loansAccountProductTemplate.overdueCharges;
}
const isModification = this.loanId != null;
if (
this.loansAccountProductTemplate.charges &&
this.loansAccountProductTemplate.charges.length > 0 &&
this.chargesDataSource.length === 0
) {
this.chargesDataSource =
this.loansAccountProductTemplate.charges.map((charge: any) => ({ ...charge, id: charge.chargeId })) || [];
} else if (isModification && this.loansAccountTemplate && this.loansAccountTemplate.charges) {
this.chargesDataSource =
this.loansAccountTemplate.charges.map((charge: any) => ({ ...charge, id: charge.chargeId })) || [];
}
}
}
Expand Down Expand Up @@ -313,10 +317,24 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
* Returns Loans Account Charges and Collateral Form
*/
get loansAccountCharges() {
const uniqueCharges = this.getUniqueCharges(this.chargesDataSource);
return {
charges: this.chargesDataSource
charges: uniqueCharges
};
}
private getUniqueCharges<T extends { id?: number | string; chargeId?: number | string }>(charges: T[]): T[] {
const uniqueChargesMap = new Map<number | string, T>();

for (const charge of charges ?? []) {
const chargeId = charge.chargeId ?? charge.id;
if (chargeId == null) {
continue;
}
uniqueChargesMap.set(chargeId, charge);
}

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

get selectedClientMembers() {
return { selectedMembers: this.activeClientMembers.filter((item: any) => item.selected) };
Expand Down