mifosx-816 : corrected loan variations to pick based on loan product count

This commit is contained in:
Pramod Nuthakki
2013-12-04 23:40:12 +05:30
parent 865ce43de0
commit f991075cb7
5 changed files with 39 additions and 28 deletions
@@ -64,9 +64,9 @@ public class LoanScheduleCalculationPlatformServiceImpl implements LoanScheduleC
final Long groupId = this.fromJsonHelper.extractLongNamed("groupId", query.parsedJson()); final Long groupId = this.fromJsonHelper.extractLongNamed("groupId", query.parsedJson());
Integer cycleNumber = 0; Integer cycleNumber = 0;
if (clientId != null) { if (clientId != null) {
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId); cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId, loanProduct.getId());
} else if (groupId != null) { } else if (groupId != null) {
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue()); cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue(), loanProduct.getId());
} }
this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(query.parsedJson(), baseDataValidator, this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(query.parsedJson(), baseDataValidator,
loanProduct, cycleNumber); loanProduct, cycleNumber);
@@ -180,9 +180,9 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
final Long groupId = this.fromJsonHelper.extractLongNamed("groupId", command.parsedJson()); final Long groupId = this.fromJsonHelper.extractLongNamed("groupId", command.parsedJson());
Integer cycleNumber = 0; Integer cycleNumber = 0;
if (clientId != null) { if (clientId != null) {
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId); cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId, loanProduct.getId());
} else if (groupId != null) { } else if (groupId != null) {
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue()); cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue(), loanProduct.getId());
} }
this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(command.parsedJson(), baseDataValidator, this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(command.parsedJson(), baseDataValidator,
loanProduct, cycleNumber); loanProduct, cycleNumber);
@@ -314,9 +314,9 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
final Long groupId = this.fromJsonHelper.extractLongNamed("groupId", command.parsedJson()); final Long groupId = this.fromJsonHelper.extractLongNamed("groupId", command.parsedJson());
Integer cycleNumber = 0; Integer cycleNumber = 0;
if (clientId != null) { if (clientId != null) {
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId); cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId, loanProduct.getId());
} else if (groupId != null) { } else if (groupId != null) {
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue()); cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue(), loanProduct.getId());
} }
this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(command.parsedJson(), baseDataValidator, this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(command.parsedJson(), baseDataValidator,
loanProduct, cycleNumber); loanProduct, cycleNumber);
@@ -62,7 +62,7 @@ public interface LoanReadPlatformService {
*/ */
Collection<OverdueLoanScheduleData> retrieveAllLoansWithOverdueInstallmentsNotAlreadyPenalized(final Long penaltyWaitPeriod); Collection<OverdueLoanScheduleData> retrieveAllLoansWithOverdueInstallmentsNotAlreadyPenalized(final Long penaltyWaitPeriod);
Integer retriveLoanCounter(Long groupId, Integer loanType); Integer retriveLoanCounter(Long groupId, Integer loanType, Long productId);
Integer retriveLoanCounter(Long clientId); Integer retriveLoanCounter(Long clientId, Long productId);
} }
@@ -1067,9 +1067,9 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
Integer loanCycleCounter = null; Integer loanCycleCounter = null;
if (loanProduct.useBorrowerCycle()) { if (loanProduct.useBorrowerCycle()) {
if (clientId == null) { if (clientId == null) {
loanCycleCounter = retriveLoanCounter(groupId, AccountType.GROUP.getValue()); loanCycleCounter = retriveLoanCounter(groupId, AccountType.GROUP.getValue(), loanProduct.getId());
} else { } else {
loanCycleCounter = retriveLoanCounter(clientId); loanCycleCounter = retriveLoanCounter(clientId, loanProduct.getId());
} }
} }
return LoanAccountData.loanProductWithTemplateDefaults(loanProduct, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions, return LoanAccountData.loanProductWithTemplateDefaults(loanProduct, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
@@ -1161,14 +1161,14 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public Integer retriveLoanCounter(final Long groupId, final Integer loanType) { public Integer retriveLoanCounter(final Long groupId, final Integer loanType, Long productId) {
final String sql = "Select MAX(l.loan_counter) from m_loan l where l.group_id = ? " + " and l.loan_type_enum = ?"; final String sql = "Select MAX(l.loan_product_counter) from m_loan l where l.group_id = ? and l.loan_type_enum = ? and l.product_id=?";
return this.jdbcTemplate.queryForInt(sql, groupId, loanType); return this.jdbcTemplate.queryForInt(sql, groupId, loanType,productId);
} }
@Override @Override
public Integer retriveLoanCounter(final Long clientId) { public Integer retriveLoanCounter(final Long clientId, Long productId) {
final String sql = "Select MAX(l.loan_counter) from m_loan l where l.client_id = ?"; final String sql = "Select MAX(l.loan_product_counter) from m_loan l where l.client_id = ? and l.product_id=?";
return this.jdbcTemplate.queryForInt(sql, clientId); return this.jdbcTemplate.queryForInt(sql, clientId,productId);
} }
} }
@@ -680,20 +680,31 @@ public class LoanProduct extends AbstractPersistable<Long> {
public Map<String, BigDecimal> fetchBorrowerCycleVariationsForCycleNumber(final Integer cycleNumber) { public Map<String, BigDecimal> fetchBorrowerCycleVariationsForCycleNumber(final Integer cycleNumber) {
Map<String, BigDecimal> borrowerCycleVariations = new HashMap<String, BigDecimal>(); Map<String, BigDecimal> borrowerCycleVariations = new HashMap<String, BigDecimal>();
borrowerCycleVariations.put(LoanProductConstants.principal, this.loanProductRelatedDetail.getPrincipal().getAmount()); borrowerCycleVariations.put(LoanProductConstants.principal, this.loanProductRelatedDetail.getPrincipal().getAmount());
borrowerCycleVariations.put(LoanProductConstants.minPrincipal, this.loanProductMinMaxConstraints.getMinPrincipal());
borrowerCycleVariations.put(LoanProductConstants.maxPrincipal, this.loanProductMinMaxConstraints.getMaxPrincipal());
borrowerCycleVariations.put(LoanProductConstants.interestRatePerPeriod, borrowerCycleVariations.put(LoanProductConstants.interestRatePerPeriod,
this.loanProductRelatedDetail.getNominalInterestRatePerPeriod()); this.loanProductRelatedDetail.getNominalInterestRatePerPeriod());
borrowerCycleVariations.put(LoanProductConstants.minInterestRatePerPeriod, if(this.loanProductRelatedDetail.getNumberOfRepayments() != null){
this.loanProductMinMaxConstraints.getMinNominalInterestRatePerPeriod()); borrowerCycleVariations.put(LoanProductConstants.numberOfRepayments,
borrowerCycleVariations.put(LoanProductConstants.maxInterestRatePerPeriod, BigDecimal.valueOf(this.loanProductRelatedDetail.getNumberOfRepayments()));
this.loanProductMinMaxConstraints.getMaxNominalInterestRatePerPeriod()); }
borrowerCycleVariations.put(LoanProductConstants.numberOfRepayments,
BigDecimal.valueOf(this.loanProductRelatedDetail.getNumberOfRepayments())); if(this.loanProductMinMaxConstraints !=null){
borrowerCycleVariations.put(LoanProductConstants.minNumberOfRepayments, borrowerCycleVariations.put(LoanProductConstants.minPrincipal, this.loanProductMinMaxConstraints.getMinPrincipal());
BigDecimal.valueOf(this.loanProductMinMaxConstraints.getMinNumberOfRepayments())); borrowerCycleVariations.put(LoanProductConstants.maxPrincipal, this.loanProductMinMaxConstraints.getMaxPrincipal());
borrowerCycleVariations.put(LoanProductConstants.maxNumberOfRepayments, borrowerCycleVariations.put(LoanProductConstants.minInterestRatePerPeriod,
BigDecimal.valueOf(this.loanProductMinMaxConstraints.getMaxNumberOfRepayments())); this.loanProductMinMaxConstraints.getMinNominalInterestRatePerPeriod());
borrowerCycleVariations.put(LoanProductConstants.maxInterestRatePerPeriod,
this.loanProductMinMaxConstraints.getMaxNominalInterestRatePerPeriod());
if(this.loanProductMinMaxConstraints.getMinNumberOfRepayments() != null){
borrowerCycleVariations.put(LoanProductConstants.minNumberOfRepayments,
BigDecimal.valueOf(this.loanProductMinMaxConstraints.getMinNumberOfRepayments()));
}
if(this.loanProductMinMaxConstraints.getMaxNumberOfRepayments() != null){
borrowerCycleVariations.put(LoanProductConstants.maxNumberOfRepayments,
BigDecimal.valueOf(this.loanProductMinMaxConstraints.getMaxNumberOfRepayments()));
}
}
if (cycleNumber > 0) { if (cycleNumber > 0) {
Integer principalCycleUsed = 0; Integer principalCycleUsed = 0;
Integer interestCycleUsed = 0; Integer interestCycleUsed = 0;