FINERACT-378 and 379 : Can not link a Saving account to during Group Loan Application and Bluck JLG Loan application

This commit is contained in:
nazeer1100126
2017-03-10 13:45:54 +05:30
parent f1f3d65161
commit 0296fd4351
3 changed files with 52 additions and 18 deletions
@@ -22,6 +22,7 @@ public class PortfolioAccountDTO {
private final Integer accountTypeId;
private final Long clientId;
private Long groupId;
private final String currencyCode;
private final long[] accountStatus;
private final Integer depositType;
@@ -79,5 +80,13 @@ public class PortfolioAccountDTO {
public boolean isExcludeOverDraftAccounts() {
return this.excludeOverDraftAccounts;
}
public Long getGroupId() {
return this.groupId;
}
public void setGroupId(final Long groupId) {
this.groupId = groupId;
}
}
@@ -104,8 +104,8 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount
@Override
public Collection<PortfolioAccountData> retrieveAllForLookup(final PortfolioAccountDTO portfolioAccountDTO) {
List<Object> sqlParams = new ArrayList<>();
sqlParams.add(portfolioAccountDTO.getClientId());
final List<Object> sqlParams = new ArrayList<>();
//sqlParams.add(portfolioAccountDTO.getClientId());
Collection<PortfolioAccountData> accounts = null;
String sql = null;
String defaultAccountStatus = "300";
@@ -120,8 +120,13 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount
case INVALID:
break;
case LOAN:
sql = "select " + this.loanAccountMapper.schema() + " where la.client_id = ? and la.loan_status_id in ("
+ defaultAccountStatus.toString() + ")";
sql = "select " + this.loanAccountMapper.schema() + " where ";
if (portfolioAccountDTO.getClientId() != null) {
sql += " la.client_id = ? and la.loan_status_id in (" + defaultAccountStatus.toString() + ") ";
sqlParams.add(portfolioAccountDTO.getClientId());
} else {
sql += " la.loan_status_id in (" + defaultAccountStatus.toString() + ") ";
}
if (portfolioAccountDTO.getCurrencyCode() != null) {
sql += " and la.currency_code = ?";
sqlParams.add(portfolioAccountDTO.getCurrencyCode());
@@ -130,8 +135,13 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount
accounts = this.jdbcTemplate.query(sql, this.loanAccountMapper, sqlParams.toArray());
break;
case SAVINGS:
sql = "select " + this.savingsAccountMapper.schema() + " where sa.client_id = ? and sa.status_enum in ("
+ defaultAccountStatus.toString() + ")";
sql = "select " + this.savingsAccountMapper.schema() + " where ";
if (portfolioAccountDTO.getClientId() != null) {
sql += " sa.client_id = ? and sa.status_enum in (" + defaultAccountStatus.toString() + ") ";
sqlParams.add(portfolioAccountDTO.getClientId());
} else {
sql += " sa.status_enum in (" + defaultAccountStatus.toString() + ") ";
}
if (portfolioAccountDTO.getCurrencyCode() != null) {
sql += " and sa.currency_code = ?";
sqlParams.add(portfolioAccountDTO.getCurrencyCode());
@@ -145,7 +155,12 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount
if(portfolioAccountDTO.isExcludeOverDraftAccounts()){
sql += " and sa.allow_overdraft = 0";
}
if(portfolioAccountDTO.getClientId() == null && portfolioAccountDTO.getGroupId() != null){
sql += " and sa.group_id = ? ";
sqlParams.add(portfolioAccountDTO.getGroupId());
}
accounts = this.jdbcTemplate.query(sql, this.savingsAccountMapper, sqlParams.toArray());
break;
default:
@@ -267,6 +267,7 @@ public class LoansApiResource {
Collection<CalendarData> calendarOptions = null;
LoanAccountData newLoanAccount = null;
Long officeId = null;
Collection<PortfolioAccountData> accountLinkingOptions = null;
if (productId != null) {
newLoanAccount = this.loanReadPlatformService.retrieveLoanProductDetailsTemplate(productId, clientId, groupId);
@@ -306,6 +307,7 @@ public class LoansApiResource {
calendarOptions = this.loanReadPlatformService.retrieveCalendars(groupId);
newLoanAccount = newLoanAccount == null ? loanAccountGroupData : LoanAccountData.populateGroupDefaults(newLoanAccount,
loanAccountGroupData);
accountLinkingOptions = getaccountLinkingOptions(newLoanAccount, clientId, groupId);
} else if (templateType.equals("jlgbulk")) {
// get group details along with members in that group
@@ -317,9 +319,11 @@ public class LoansApiResource {
if (productId != null) {
Map<Long, Integer> memberLoanCycle = new HashMap<>();
Collection<ClientData> members = loanAccountGroupData.groupData().clientMembers();
accountLinkingOptions = new ArrayList<>();
for (ClientData clientData : members) {
Integer loanCounter = this.loanReadPlatformService.retriveLoanCounter(clientData.id(), productId);
memberLoanCycle.put(clientData.id(), loanCounter);
accountLinkingOptions.addAll(getaccountLinkingOptions(newLoanAccount, clientData.id(), groupId));
}
newLoanAccount = LoanAccountData.associateMemberVariations(newLoanAccount, memberLoanCycle);
}
@@ -331,18 +335,8 @@ public class LoansApiResource {
allowedLoanOfficers = this.loanReadPlatformService.retrieveAllowedLoanOfficers(officeId, staffInSelectedOfficeOnly);
Collection<PortfolioAccountData> accountLinkingOptions = null;
if (clientId != null) {
final CurrencyData currencyData = newLoanAccount.currency();
String currencyCode = null;
if (currencyData != null) {
currencyCode = currencyData.code();
}
final long[] accountStatus = { SavingsAccountStatusType.ACTIVE.getValue() };
PortfolioAccountDTO portfolioAccountDTO = new PortfolioAccountDTO(PortfolioAccountType.SAVINGS.getValue(), clientId,
currencyCode, accountStatus, DepositAccountType.SAVINGS_DEPOSIT.getValue());
accountLinkingOptions = this.portfolioAccountReadPlatformService.retrieveAllForLookup(portfolioAccountDTO);
accountLinkingOptions = getaccountLinkingOptions(newLoanAccount, clientId, groupId);
}
// add product options, allowed loan officers and calendar options
@@ -358,6 +352,22 @@ public class LoansApiResource {
return this.toApiJsonSerializer.serialize(settings, newLoanAccount, this.LOAN_DATA_PARAMETERS);
}
private Collection<PortfolioAccountData> getaccountLinkingOptions(final LoanAccountData newLoanAccount, final Long clientId,
final Long groupId) {
final CurrencyData currencyData = newLoanAccount.currency();
String currencyCode = null;
if (currencyData != null) {
currencyCode = currencyData.code();
}
final long[] accountStatus = { SavingsAccountStatusType.ACTIVE.getValue() };
final PortfolioAccountDTO portfolioAccountDTO = new PortfolioAccountDTO(PortfolioAccountType.SAVINGS.getValue(), clientId, currencyCode,
accountStatus, DepositAccountType.SAVINGS_DEPOSIT.getValue());
if (groupId != null) {
portfolioAccountDTO.setGroupId(groupId);
}
return this.portfolioAccountReadPlatformService.retrieveAllForLookup(portfolioAccountDTO);
}
@GET
@Path("{loanId}")
@Consumes({ MediaType.APPLICATION_JSON })