MIFOSX-827 corrected update loan charge functionality from modify application

This commit is contained in:
Pramod Nuthakki
2014-01-26 03:07:09 +05:30
committed by Vishwas Babu A J
parent d365545ec1
commit 097189621f
4 changed files with 66 additions and 7 deletions
@@ -221,6 +221,35 @@ public class LoanChargeData {
this.loanId = chargeData.loanId;
this.installmentChargeData = installmentChargeData;
}
public LoanChargeData(final Long id, final LocalDate dueAsOfDate, final BigDecimal amountOrPercentage) {
this.id = id;
this.chargeId = null;
this.name = null;
this.currency = null;
this.amount = null;
this.amountPaid = null;
this.amountWaived = null;
this.amountWrittenOff = null;
this.amountOutstanding = null;
this.chargeTimeType = null;
this.dueDate = dueAsOfDate;
this.chargeCalculationType = null;
this.percentage = null;
this.amountPercentageAppliedTo = null;
this.penalty = false;
this.chargePaymentMode = null;
this.paid = false;
this.waived = false;
this.amountOrPercentage = amountOrPercentage;
this.chargeOptions = null;
this.chargePayable = false;
this.loanId = null;
this.minCap = null;
this.maxCap = null;
this.installmentChargeData = null;
}
public boolean isChargePayable() {
@@ -254,4 +283,9 @@ public class LoanChargeData {
}
return isInstalmentFee;
}
public BigDecimal amountOrPercentage() {
return this.amountOrPercentage;
}
}
@@ -963,7 +963,7 @@ public class Loan extends AbstractPersistable<Long> {
}
public Map<String, Object> loanApplicationModification(final JsonCommand command, final Set<LoanCharge> possiblyModifedLoanCharges,
final Set<LoanCollateral> possiblyModifedLoanCollateralItems, final AprCalculator aprCalculator) {
final Set<LoanCollateral> possiblyModifedLoanCollateralItems, final AprCalculator aprCalculator, boolean isChargesModified) {
final Map<String, Object> actualChanges = this.loanRepaymentScheduleDetail.updateLoanApplicationAttributes(command, aprCalculator);
if (!actualChanges.isEmpty()) {
@@ -1141,9 +1141,7 @@ public class Loan extends AbstractPersistable<Long> {
final String chargesParamName = "charges";
if (command.parameterExists(chargesParamName)) {
final Set<LoanCharge> existingLoanCharges = charges();
if (!possiblyModifedLoanCharges.equals(existingLoanCharges)) {
if (isChargesModified) {
actualChanges.put(chargesParamName, getLoanCharges(possiblyModifedLoanCharges));
actualChanges.put(chargesParamName, getLoanCharges(possiblyModifedLoanCharges));
@@ -352,10 +352,10 @@ public class LoanCharge extends AbstractPersistable<Long> {
loanCharge = percentageOf(this.amountPercentageAppliedTo);
}
this.amount = minimumAndMaximumCap(loanCharge);
this.amountOutstanding = calculateOutstanding();
break;
}
this.amountOrPercentage = amount;
this.amountOutstanding = calculateOutstanding();
if(this.loan !=null && isInstalmentFee()){
final Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this);
if(this.loanInstallmentCharge.isEmpty()){
@@ -786,4 +786,9 @@ public class LoanCharge extends AbstractPersistable<Long> {
public void setActive(boolean active) {
this.active = active;
}
public BigDecimal amountOrPercentage() {
return this.amountOrPercentage;
}
}
@@ -7,6 +7,7 @@ package org.mifosplatform.portfolio.loanaccount.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -45,6 +46,7 @@ import org.mifosplatform.portfolio.fund.domain.Fund;
import org.mifosplatform.portfolio.group.domain.Group;
import org.mifosplatform.portfolio.group.domain.GroupRepositoryWrapper;
import org.mifosplatform.portfolio.group.exception.GroupNotActiveException;
import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData;
import org.mifosplatform.portfolio.loanaccount.domain.DefaultLoanLifecycleStateMachine;
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
import org.mifosplatform.portfolio.loanaccount.domain.LoanCharge;
@@ -267,13 +269,33 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
if (!existingLoanApplication.isSubmittedAndPendingApproval()) { throw new LoanApplicationNotInSubmittedAndPendingApprovalStateCannotBeModified(
loanId); }
final Set<LoanCharge> existingCharges = existingLoanApplication.charges();
Map<Long,LoanChargeData> chargesMap = new HashMap<Long, LoanChargeData>();
for(LoanCharge charge:existingCharges){
LoanChargeData chargeData = new LoanChargeData(charge.getId(),charge.getDueLocalDate() ,charge.amountOrPercentage());
chargesMap.put(charge.getId(), chargeData);
}
final Set<LoanCharge> possiblyModifedLoanCharges = this.loanChargeAssembler.fromParsedJson(command.parsedJson());
boolean isChargeModified = false;
for(LoanCharge loanCharge : possiblyModifedLoanCharges){
if(loanCharge.getId() == null){
isChargeModified = true;
}else{
LoanChargeData chargeData = chargesMap.get(loanCharge.getId());
if(loanCharge.amountOrPercentage().compareTo(chargeData.amountOrPercentage()) != 0 ||
(loanCharge.isSpecifiedDueDate() && !loanCharge.getDueLocalDate().equals(chargeData.getDueDate()))){
isChargeModified = true;
}
}
}
final Set<LoanCollateral> possiblyModifedLoanCollateralItems = this.loanCollateralAssembler
.fromParsedJson(command.parsedJson());
final Map<String, Object> changes = existingLoanApplication.loanApplicationModification(command, possiblyModifedLoanCharges,
possiblyModifedLoanCollateralItems, this.aprCalculator);
possiblyModifedLoanCollateralItems, this.aprCalculator, isChargeModified);
if (changes.containsKey("expectedDisbursementDate")) {
this.loanAssembler.validateExpectedDisbursementForHolidayAndNonWorkingDay(existingLoanApplication);