Merge pull request #2690 from JaySoni1/WEB-117-loan-account-charge-amount-charges-doubling-on-application-modification
WEB-117 Loan Account Charge(Amount% charges) Doubling on Application Modification
This commit is contained in:
@@ -129,14 +129,29 @@ export class EditLoansAccountComponent {
|
|||||||
const locale = this.settingsService.language.code;
|
const locale = this.settingsService.language.code;
|
||||||
const dateFormat = this.settingsService.dateFormat;
|
const dateFormat = this.settingsService.dateFormat;
|
||||||
const loanType = 'individual';
|
const loanType = 'individual';
|
||||||
|
const uniqueCharges = new Map<number | string, any>();
|
||||||
|
(this.loansAccount.charges ?? []).forEach((charge: any) => {
|
||||||
|
const chargeId = charge.chargeId;
|
||||||
|
if (chargeId == null) {
|
||||||
|
return;
|
||||||
|
} // Skip malformed entries
|
||||||
|
uniqueCharges.set(chargeId, charge);
|
||||||
|
});
|
||||||
|
|
||||||
const loansAccountData = {
|
const loansAccountData = {
|
||||||
...this.loansAccount,
|
...this.loansAccount,
|
||||||
clientId: this.loansAccountAndTemplate.clientId,
|
clientId: this.loansAccountAndTemplate.clientId,
|
||||||
charges: this.loansAccount.charges.map((charge: any) => ({
|
charges: Array.from(uniqueCharges.values()).map((charge: any) => {
|
||||||
chargeId: charge.id,
|
const result: any = {
|
||||||
amount: charge.amount,
|
chargeId: charge.chargeId,
|
||||||
dueDate: charge.dueDate && this.dateUtils.formatDate(charge.dueDate, dateFormat)
|
amount: charge.amount,
|
||||||
})),
|
dueDate: charge.dueDate && this.dateUtils.formatDate(charge.dueDate, dateFormat)
|
||||||
|
};
|
||||||
|
if (charge.id && charge.id !== charge.chargeId) {
|
||||||
|
result.id = charge.id;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}),
|
||||||
collateral: this.loansAccount.collateral.map((collateralEle: any) => ({
|
collateral: this.loansAccount.collateral.map((collateralEle: any) => ({
|
||||||
type: collateralEle.type,
|
type: collateralEle.type,
|
||||||
value: collateralEle.value,
|
value: collateralEle.value,
|
||||||
|
|||||||
+55
-4
@@ -140,7 +140,13 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.loansAccountTemplate && this.loansAccountTemplate.charges) {
|
if (this.loansAccountTemplate && this.loansAccountTemplate.charges) {
|
||||||
this.chargesDataSource =
|
this.chargesDataSource =
|
||||||
this.loansAccountTemplate.charges.map((charge: any) => ({ ...charge, id: charge.chargeId })) || [];
|
this.loansAccountTemplate.charges.map((charge: any) => {
|
||||||
|
return {
|
||||||
|
...charge,
|
||||||
|
id: charge.id,
|
||||||
|
chargeId: charge.chargeId
|
||||||
|
};
|
||||||
|
}) || [];
|
||||||
}
|
}
|
||||||
this.dataSource = new MatTableDataSource<any>(this.activeClientMembers);
|
this.dataSource = new MatTableDataSource<any>(this.activeClientMembers);
|
||||||
}
|
}
|
||||||
@@ -162,13 +168,26 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
|
|||||||
if (this.loansAccountProductTemplate.overdueCharges) {
|
if (this.loansAccountProductTemplate.overdueCharges) {
|
||||||
this.overDueChargesDataSource = this.loansAccountProductTemplate.overdueCharges;
|
this.overDueChargesDataSource = this.loansAccountProductTemplate.overdueCharges;
|
||||||
}
|
}
|
||||||
|
const isModification = this.loanId != null;
|
||||||
if (
|
if (
|
||||||
this.loansAccountProductTemplate.charges &&
|
this.loansAccountProductTemplate.charges &&
|
||||||
this.loansAccountProductTemplate.charges.length > 0 &&
|
this.loansAccountProductTemplate.charges.length > 0 &&
|
||||||
this.chargesDataSource.length === 0
|
this.chargesDataSource.length === 0
|
||||||
) {
|
) {
|
||||||
this.chargesDataSource =
|
this.chargesDataSource =
|
||||||
this.loansAccountProductTemplate.charges.map((charge: any) => ({ ...charge, id: charge.chargeId })) || [];
|
this.loansAccountProductTemplate.charges.map((charge: any) => ({
|
||||||
|
...charge,
|
||||||
|
chargeId: charge.chargeId || charge.id
|
||||||
|
})) || [];
|
||||||
|
} else if (isModification && this.loansAccountTemplate && this.loansAccountTemplate.charges) {
|
||||||
|
this.chargesDataSource =
|
||||||
|
this.loansAccountTemplate.charges.map((charge: any) => {
|
||||||
|
return {
|
||||||
|
...charge,
|
||||||
|
id: charge.id,
|
||||||
|
chargeId: charge.chargeId
|
||||||
|
};
|
||||||
|
}) || [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +196,11 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
|
|||||||
* Add a charge
|
* Add a charge
|
||||||
*/
|
*/
|
||||||
addCharge(charge: any) {
|
addCharge(charge: any) {
|
||||||
this.chargesDataSource = this.chargesDataSource.concat([charge.value]);
|
const newCharge = {
|
||||||
|
...charge.value,
|
||||||
|
chargeId: charge.value.id || charge.value.chargeId
|
||||||
|
};
|
||||||
|
this.chargesDataSource = this.chargesDataSource.concat([newCharge]);
|
||||||
charge.value = '';
|
charge.value = '';
|
||||||
this.pristine = false;
|
this.pristine = false;
|
||||||
}
|
}
|
||||||
@@ -313,10 +336,38 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
|
|||||||
* Returns Loans Account Charges and Collateral Form
|
* Returns Loans Account Charges and Collateral Form
|
||||||
*/
|
*/
|
||||||
get loansAccountCharges() {
|
get loansAccountCharges() {
|
||||||
|
const uniqueCharges = this.getUniqueCharges(this.chargesDataSource);
|
||||||
return {
|
return {
|
||||||
charges: this.chargesDataSource
|
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;
|
||||||
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
if (chargeId == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
uniqueChargesMap.set(chargeId, charge);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(uniqueChargesMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
get selectedClientMembers() {
|
get selectedClientMembers() {
|
||||||
return { selectedMembers: this.activeClientMembers.filter((item: any) => item.selected) };
|
return { selectedMembers: this.activeClientMembers.filter((item: any) => item.selected) };
|
||||||
|
|||||||
Reference in New Issue
Block a user