added loan charge update for installment fees

This commit is contained in:
Pramod Nuthakki
2013-11-06 15:33:11 +05:30
parent 75353716a9
commit 906beef7df
7 changed files with 37 additions and 33 deletions
@@ -0,0 +1,2 @@
ALTER TABLE `m_loan_charge`
ADD COLUMN `charge_amount_or_percentage` DECIMAL(19,6) NULL DEFAULT NULL AFTER `calculation_on_amount`;
@@ -11,7 +11,7 @@ public class LoanChargeCannotBeUpdatedException extends AbstractPlatformDomainRu
/*** enum of reasons of why Loan Charge cannot be waived **/
public static enum LOAN_CHARGE_CANNOT_BE_UPDATED_REASON {
ALREADY_PAID, ALREADY_WAIVED, LOAN_NOT_IN_SUBMITTED_AND_PENDING_APPROVAL_STAGE,CHARGE_INSTALLMENT_FEE;
ALREADY_PAID, ALREADY_WAIVED, LOAN_NOT_IN_SUBMITTED_AND_PENDING_APPROVAL_STAGE;
public String errorMessage() {
if (name().toString().equalsIgnoreCase("ALREADY_PAID")) {
@@ -20,10 +20,7 @@ public class LoanChargeCannotBeUpdatedException extends AbstractPlatformDomainRu
return "This loan charge has already been waived";
} else if (name().toString().equalsIgnoreCase("LOAN_NOT_IN_SUBMITTED_AND_PENDING_APPROVAL_STAGE")) {
return "This charge cannot be updated as the loan it is associated with is not in submitted and pending approval stage";
} else if(name().toString().equalsIgnoreCase("CHARGE_INSTALLMENT_FEE")){
return "Installment charge update is not allowed";
}
}
return name().toString();
}
@@ -34,8 +31,6 @@ public class LoanChargeCannotBeUpdatedException extends AbstractPlatformDomainRu
return "error.msg.loan.charge.already.waived";
} else if (name().toString().equalsIgnoreCase("LOAN_NOT_IN_SUBMITTED_AND_PENDING_APPROVAL_STAGE")) {
return "error.msg.loan.charge.associated.loan.not.in.submitted.and.pending.approval.stage";
} else if(name().toString().equalsIgnoreCase("CHARGE_INSTALLMENT_FEE")){
return "error.msg.loan.charge.installment.fee.update.not.allowed";
}
return name().toString();
}
@@ -80,7 +80,7 @@ public class LoanChargeData {
public static LoanChargeData template(final Collection<ChargeData> chargeOptions) {
return new LoanChargeData(null, null, null, null, null, null, null, null, chargeOptions, false, null, false, false, null, null,
null);
null,null);
}
/**
@@ -92,7 +92,7 @@ public class LoanChargeData {
final EnumOptionData chargeCalculationType, final boolean penalty, final EnumOptionData chargePaymentMode,
final BigDecimal minCap, final BigDecimal maxCap) {
return new LoanChargeData(null, chargeId, name, currency, amount, percentage, chargeTimeType, chargeCalculationType, null, penalty,
chargePaymentMode, false, false, null, minCap, maxCap);
chargePaymentMode, false, false, null, minCap, maxCap,amount);
}
public LoanChargeData(final Long id, final Long chargeId, final String name, final CurrencyData currency, final BigDecimal amount,
@@ -100,7 +100,7 @@ public class LoanChargeData {
final BigDecimal amountOutstanding, final EnumOptionData chargeTimeType, final LocalDate dueDate,
final EnumOptionData chargeCalculationType, final BigDecimal percentage, final BigDecimal amountPercentageAppliedTo,
final boolean penalty, final EnumOptionData chargePaymentMode, final boolean paid, final boolean waived, final Long loanId,
final BigDecimal minCap, final BigDecimal maxCap) {
final BigDecimal minCap, final BigDecimal maxCap,final BigDecimal amountOrPercentage) {
this.id = id;
this.chargeId = chargeId;
this.name = name;
@@ -121,11 +121,14 @@ public class LoanChargeData {
this.waived = waived;
this.minCap = minCap;
this.maxCap = maxCap;
if (chargeCalculationType != null && chargeCalculationType.getId().intValue() > 1) {
this.amountOrPercentage = this.percentage;
} else {
this.amountOrPercentage = amount;
if(amountOrPercentage == null){
if (chargeCalculationType != null && chargeCalculationType.getId().intValue() > 1) {
this.amountOrPercentage = this.percentage;
} else {
this.amountOrPercentage = amount;
}
}else{
this.amountOrPercentage = amountOrPercentage;
}
this.chargeOptions = null;
@@ -136,7 +139,7 @@ public class LoanChargeData {
private LoanChargeData(final Long id, final Long chargeId, final String name, final CurrencyData currency, final BigDecimal amount,
final BigDecimal percentage, final EnumOptionData chargeTimeType, final EnumOptionData chargeCalculationType,
final Collection<ChargeData> chargeOptions, final boolean penalty, final EnumOptionData chargePaymentMode, final boolean paid,
final boolean waived, final Long loanId, final BigDecimal minCap, final BigDecimal maxCap) {
final boolean waived, final Long loanId, final BigDecimal minCap, final BigDecimal maxCap,final BigDecimal amountOrPercentage) {
this.id = id;
this.chargeId = chargeId;
this.name = name;
@@ -156,10 +159,14 @@ public class LoanChargeData {
this.paid = paid;
this.waived = waived;
if (chargeCalculationType != null && chargeCalculationType.getId().intValue() > 1) {
this.amountOrPercentage = this.percentage;
} else {
this.amountOrPercentage = amount;
if(amountOrPercentage == null){
if (chargeCalculationType != null && chargeCalculationType.getId().intValue() > 1) {
this.amountOrPercentage = this.percentage;
} else {
this.amountOrPercentage = amount;
}
}else{
this.amountOrPercentage = amountOrPercentage;
}
this.chargeOptions = chargeOptions;
@@ -641,11 +641,7 @@ public class Loan extends AbstractPersistable<Long> {
validateLoanIsNotClosed(loanCharge);
if (setOfLoanCharges().contains(loanCharge)) {
BigDecimal amount = calculateAmountPercentageAppliedTo(loanCharge);
BigDecimal totalChargeAmt = BigDecimal.ZERO;
if(loanCharge.isInstalmentFee()){
totalChargeAmt = calculatePerInstallmentChargeAmount(loanCharge);
}
final Map<String, Object> loanChargeChanges = loanCharge.update(command, amount, totalChargeAmt);
final Map<String, Object> loanChargeChanges = loanCharge.update(command, amount);
actualChanges.putAll(loanChargeChanges);
updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());
}
@@ -65,6 +65,10 @@ public class LoanCharge extends AbstractPersistable<Long> {
@Column(name = "calculation_on_amount", scale = 6, precision = 19, nullable = true)
private BigDecimal amountPercentageAppliedTo;
@SuppressWarnings("unused")
@Column(name = "charge_amount_or_percentage", scale = 6, precision = 19, nullable = false)
private BigDecimal amountOrPercentage;
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
private BigDecimal amount;
@@ -232,6 +236,7 @@ public class LoanCharge extends AbstractPersistable<Long> {
this.amountWrittenOff = null;
break;
}
this.amountOrPercentage = chargeAmount;
}
public void markAsFullyPaid() {
@@ -302,10 +307,11 @@ public class LoanCharge extends AbstractPersistable<Long> {
this.amountOutstanding = calculateOutstanding();
break;
}
this.amountOrPercentage = amount;
}
}
public Map<String, Object> update(final JsonCommand command, final BigDecimal amount, BigDecimal loanCharge) {
public Map<String, Object> update(final JsonCommand command, final BigDecimal amount) {
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(7);
@@ -343,6 +349,7 @@ public class LoanCharge extends AbstractPersistable<Long> {
case PERCENT_OF_INTEREST:
this.percentage = newValue;
this.amountPercentageAppliedTo = amount;
BigDecimal loanCharge = loan.calculatePerInstallmentChargeAmount(ChargeCalculationType.fromInt(this.chargeCalculation),percentage);
if(loanCharge.compareTo(BigDecimal.ZERO) == 0){
loanCharge = percentageOf(this.amountPercentageAppliedTo);
}
@@ -350,8 +357,8 @@ public class LoanCharge extends AbstractPersistable<Long> {
this.amountOutstanding = calculateOutstanding();
break;
}
this.amountOrPercentage = newValue;
}
return actualChanges;
}
@@ -59,6 +59,7 @@ public class LoanChargeReadPlatformServiceImpl implements LoanChargeReadPlatform
+ "lc.is_paid_derived as paid, "
+ "lc.waived as waied, "
+ "lc.min_cap as minCap, lc.max_cap as maxCap, "
+ "lc.charge_amount_or_percentage as amountOrPercentage, "
+ "c.currency_code as currencyCode, oc.name as currencyName, "
+ "oc.decimal_places as currencyDecimalPlaces, oc.currency_multiplesof as inMultiplesOf, oc.display_symbol as currencyDisplaySymbol, "
+ "oc.internationalized_name_code as currencyNameCode from m_charge c "
@@ -105,10 +106,11 @@ public class LoanChargeReadPlatformServiceImpl implements LoanChargeReadPlatform
final boolean waived = rs.getBoolean("waied");
final BigDecimal minCap = rs.getBigDecimal("minCap");
final BigDecimal maxCap = rs.getBigDecimal("maxCap");
final BigDecimal amountOrPercentage = rs.getBigDecimal("amountOrPercentage");
return new LoanChargeData(id, chargeId, name, currency, amount, amountPaid, amountWaived, amountWrittenOff, amountOutstanding,
chargeTimeType, dueAsOfDate, chargeCalculationType, percentageOf, amountPercentageAppliedTo, penalty, paymentMode,
paid, waived, null,minCap,maxCap);
paid, waived, null,minCap,maxCap,amountOrPercentage);
}
}
@@ -890,11 +890,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
// yet to be approved (are in submitted and pending status)
if (!loan.status().isSubmittedAndPendingApproval()) { throw new LoanChargeCannotBeUpdatedException(
LOAN_CHARGE_CANNOT_BE_UPDATED_REASON.LOAN_NOT_IN_SUBMITTED_AND_PENDING_APPROVAL_STAGE, loanCharge.getId()); }
if(loanCharge.isInstalmentFee()){
throw new LoanChargeCannotBeUpdatedException(
LOAN_CHARGE_CANNOT_BE_UPDATED_REASON.CHARGE_INSTALLMENT_FEE, loanCharge.getId());
}
final Map<String, Object> changes = loan.updateLoanCharge(loanCharge, command);