corrections to stop duplicate entries for loan charge paid by

This commit is contained in:
Pramod Nuthakki
2013-09-19 16:03:49 +05:30
parent 77913d2eee
commit 344ca591c2
4 changed files with 17 additions and 26 deletions
@@ -94,11 +94,11 @@ public class ChargeEnumerations {
switch (type) { switch (type) {
case ACCOUNT_TRANSFER: case ACCOUNT_TRANSFER:
optionData = new EnumOptionData(ChargePaymentMode.ACCOUNT_TRANSFER.getValue().longValue(), optionData = new EnumOptionData(ChargePaymentMode.ACCOUNT_TRANSFER.getValue().longValue(),
ChargePaymentMode.ACCOUNT_TRANSFER.getCode(), ChargePaymentMode.ACCOUNT_TRANSFER.getCode()); ChargePaymentMode.ACCOUNT_TRANSFER.getCode(), "Account transfer");
break; break;
default: default:
optionData = new EnumOptionData(ChargePaymentMode.REGULAR.getValue().longValue(), ChargePaymentMode.REGULAR.getCode(), optionData = new EnumOptionData(ChargePaymentMode.REGULAR.getValue().longValue(), ChargePaymentMode.REGULAR.getCode(),
ChargePaymentMode.REGULAR.getCode()); "Regular");
break; break;
} }
return optionData; return optionData;
@@ -504,6 +504,9 @@ public class Loan extends AbstractPersistable<Long> {
private void handleChargePaidTransaction(final LoanCharge charge, final LoanTransaction chargesPayment, private void handleChargePaidTransaction(final LoanCharge charge, final LoanTransaction chargesPayment,
final LoanLifecycleStateMachine loanLifecycleStateMachine) { final LoanLifecycleStateMachine loanLifecycleStateMachine) {
chargesPayment.updateLoan(this); chargesPayment.updateLoan(this);
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(chargesPayment, charge, chargesPayment.getAmount(getCurrency())
.getAmount());
chargesPayment.getLoanChargesPaid().add(loanChargePaidBy);
this.loanTransactions.add(chargesPayment); this.loanTransactions.add(chargesPayment);
final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_CHARGE_PAYMENT, final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_CHARGE_PAYMENT,
LoanStatus.fromInt(this.loanStatus)); LoanStatus.fromInt(this.loanStatus));
@@ -1444,16 +1447,14 @@ public class Loan extends AbstractPersistable<Long> {
* for repayments at disbursements too? * for repayments at disbursements too?
***/ ***/
final Money totalFeeChargesDueAtDisbursement = this.summary.getTotalFeeChargesDueAtDisbursement(loanCurrency()); final Money totalFeeChargesDueAtDisbursement = this.summary.getTotalFeeChargesDueAtDisbursement(loanCurrency());
if (totalFeeChargesDueAtDisbursement.isGreaterThanZero()) { /**
/**
* all Charges repaid at disbursal is marked as repaid and * all Charges repaid at disbursal is marked as repaid and
* "APPLY Charge" transactions are created for all other fees ( * "APPLY Charge" transactions are created for all other fees (
* which are created during disbursal but not repaid) * which are created during disbursal but not repaid)
**/ **/
for (final LoanCharge charge : setOfLoanCharges()) { for (final LoanCharge charge : setOfLoanCharges()) {
if (charge.isDueAtDisbursement()) { if (charge.isDueAtDisbursement()) {
if (!charge.getChargePaymentMode().isPaymentModeAccountTransfer()) { if (totalFeeChargesDueAtDisbursement.isGreaterThanZero() && !charge.getChargePaymentMode().isPaymentModeAccountTransfer()) {
final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(this.getOffice(), final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(this.getOffice(),
charge.getAmount(getCurrency()), null, disbursedOn, txnExternalId); charge.getAmount(getCurrency()), null, disbursedOn, txnExternalId);
final Money zero = Money.zero(getCurrency()); final Money zero = Money.zero(getCurrency());
@@ -1469,7 +1470,6 @@ public class Loan extends AbstractPersistable<Long> {
} else { } else {
handleChargeAppliedTransaction(charge, disbursedOn); handleChargeAppliedTransaction(charge, disbursedOn);
} }
}
} }
if (getApprovedOnDate() != null && disbursedOn.isBefore(getApprovedOnDate())) { if (getApprovedOnDate() != null && disbursedOn.isBefore(getApprovedOnDate())) {
@@ -58,17 +58,4 @@ public class LoanChargePaidBy extends AbstractPersistable<Long> {
public void setAmount(BigDecimal amount) { public void setAmount(BigDecimal amount) {
this.amount = amount; this.amount = amount;
} }
@Override
public boolean equals(Object obj) {
boolean isEqual = false;
LoanChargePaidBy paidBy = (LoanChargePaidBy)obj;
if(this.loanTransaction.getId() == paidBy.loanTransaction.getId()
&& this.loanCharge.getId() == paidBy.loanCharge.getId()
&& this.amount == paidBy.amount){
isEqual = true;
}
return isEqual;
}
} }
@@ -219,9 +219,11 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
final LoanCharge unpaidCharge = findEarliestUnpaidChargeFromUnOrderedSet(charges); final LoanCharge unpaidCharge = findEarliestUnpaidChargeFromUnOrderedSet(charges);
Money amountPaidTowardsCharge = unpaidCharge.updatePaidAmountBy(amountRemaining); Money amountPaidTowardsCharge = unpaidCharge.updatePaidAmountBy(amountRemaining);
if (!amountPaidTowardsCharge.isZero()) { if (!amountPaidTowardsCharge.isZero()) {
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge, if(!loanTransaction.isChargePayment()){
amountPaidTowardsCharge.getAmount()); LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge,
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy); amountPaidTowardsCharge.getAmount());
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy);
}
amountRemaining = amountRemaining.minus(amountPaidTowardsCharge); amountRemaining = amountRemaining.minus(amountPaidTowardsCharge);
} }
} }
@@ -240,9 +242,11 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
final LoanCharge unpaidCharge = findEarliestUnpaidChargeFromUnOrderedSet(charges); final LoanCharge unpaidCharge = findEarliestUnpaidChargeFromUnOrderedSet(charges);
Money amountPaidTowardsCharge = unpaidCharge.updatePaidAmountBy(amountRemaining); Money amountPaidTowardsCharge = unpaidCharge.updatePaidAmountBy(amountRemaining);
if (!amountPaidTowardsCharge.isZero()) { if (!amountPaidTowardsCharge.isZero()) {
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge, if(!loanTransaction.isChargePayment()){
amountPaidTowardsCharge.getAmount()); LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge,
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy); amountPaidTowardsCharge.getAmount());
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy);
}
amountRemaining = amountRemaining.minus(amountPaidTowardsCharge); amountRemaining = amountRemaining.minus(amountPaidTowardsCharge);
} }
} }