WEB-598 Client Performance History doesn't render any value (#3024)
This commit is contained in:
@@ -14,16 +14,17 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
{{ 'labels.inputs.No. Of Loan Cycles' | translate }} :{{ clientSummary?.loanCycle }} <br />
|
{{ 'labels.inputs.No. Of Loan Cycles' | translate }} :{{ performanceHistory.loanCycle }} <br />
|
||||||
{{ 'labels.inputs.No. of Active Loans' | translate }} :{{ clientSummary?.activeLoans }} <br />
|
{{ 'labels.inputs.No. of Active Loans' | translate }} :{{ performanceHistory.activeLoans }} <br />
|
||||||
{{ 'labels.inputs.Last Loan Amount' | translate }} :{{ clientSummary?.lastLoanAmount | formatNumber }}
|
{{ 'labels.inputs.Last Loan Amount' | translate }} :{{ performanceHistory.lastLoanAmount | formatNumber }}
|
||||||
<br />
|
<br />
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
{{ 'labels.inputs.No. of Active Savings' | translate }} :{{ clientSummary?.activeSavings }} <br />
|
{{ 'labels.inputs.No. of Active Savings' | translate }} :{{ performanceHistory.activeSavings }} <br />
|
||||||
{{ 'labels.inputs.Total Savings' | translate }} :{{ clientSummary?.totalSavings | formatNumber }} <br />
|
{{ 'labels.inputs.Total Savings' | translate }} :{{ performanceHistory.totalSavings | formatNumber }}
|
||||||
|
<br />
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -149,8 +149,20 @@ export class GeneralTabComponent {
|
|||||||
shareAccounts: any;
|
shareAccounts: any;
|
||||||
/** Upcoming Charges Data */
|
/** Upcoming Charges Data */
|
||||||
upcomingCharges: any;
|
upcomingCharges: any;
|
||||||
/** Client Summary Data */
|
/** Performance History Data */
|
||||||
clientSummary: any;
|
performanceHistory: {
|
||||||
|
loanCycle: number;
|
||||||
|
activeLoans: number;
|
||||||
|
lastLoanAmount: number;
|
||||||
|
activeSavings: number;
|
||||||
|
totalSavings: number;
|
||||||
|
} = {
|
||||||
|
loanCycle: 0,
|
||||||
|
activeLoans: 0,
|
||||||
|
lastLoanAmount: 0,
|
||||||
|
activeSavings: 0,
|
||||||
|
totalSavings: 0
|
||||||
|
};
|
||||||
/** Collaterals Data */
|
/** Collaterals Data */
|
||||||
collaterals: any;
|
collaterals: any;
|
||||||
|
|
||||||
@@ -182,12 +194,54 @@ export class GeneralTabComponent {
|
|||||||
this.shareAccounts = data.clientAccountsData.shareAccounts;
|
this.shareAccounts = data.clientAccountsData.shareAccounts;
|
||||||
this.upcomingCharges = data.clientChargesData.pageItems;
|
this.upcomingCharges = data.clientChargesData.pageItems;
|
||||||
this.collaterals = data.clientCollateralData;
|
this.collaterals = data.clientCollateralData;
|
||||||
this.clientSummary = data.clientSummary ? data.clientSummary[0] : [];
|
|
||||||
this.clientid = this.route.parent.snapshot.params['clientId'];
|
this.clientid = this.route.parent.snapshot.params['clientId'];
|
||||||
|
|
||||||
|
// Compute performance history from accounts data
|
||||||
|
this.computePerformanceHistory(data.clientAccountsData);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private computePerformanceHistory(accountsData: any) {
|
||||||
|
// Loan Cycles: total number of loans
|
||||||
|
const allLoans = accountsData.loanAccounts || [];
|
||||||
|
this.performanceHistory.loanCycle = allLoans.length;
|
||||||
|
// Active Loans: status === 'Active'
|
||||||
|
this.performanceHistory.activeLoans = allLoans.filter((l: any) => {
|
||||||
|
if (!l.status) return false;
|
||||||
|
if (typeof l.status === 'string') {
|
||||||
|
return l.status.toLowerCase() === 'active';
|
||||||
|
}
|
||||||
|
if (typeof l.status === 'object' && l.status.value) {
|
||||||
|
return l.status.value.toLowerCase() === 'active';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).length;
|
||||||
|
// Loan Amount: most recent loan by submittedOnDate
|
||||||
|
if (allLoans.length > 0) {
|
||||||
|
const sortedLoans = [...allLoans].sort(
|
||||||
|
(a, b) => new Date(b.submittedOnDate).getTime() - new Date(a.submittedOnDate).getTime()
|
||||||
|
);
|
||||||
|
this.performanceHistory.lastLoanAmount = sortedLoans[0].principal || 0;
|
||||||
|
} else {
|
||||||
|
this.performanceHistory.lastLoanAmount = 0;
|
||||||
|
}
|
||||||
|
// Active Savings: status === 'Active'
|
||||||
|
const allSavings = accountsData.savingsAccounts || [];
|
||||||
|
this.performanceHistory.activeSavings = allSavings.filter((s: any) => {
|
||||||
|
if (!s.status) return false;
|
||||||
|
if (typeof s.status === 'string') {
|
||||||
|
return s.status.toLowerCase() === 'active';
|
||||||
|
}
|
||||||
|
if (typeof s.status === 'object' && s.status.value) {
|
||||||
|
return s.status.value.toLowerCase() === 'active';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).length;
|
||||||
|
// Total Savings: sum of balances
|
||||||
|
this.performanceHistory.totalSavings = allSavings.reduce((sum: number, s: any) => sum + (s.accountBalance || 0), 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggles Loan Accounts Overview
|
* Toggles Loan Accounts Overview
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user