Merge pull request #589 from pramodn02/MIFOSX-642_2

Mifosx 642 2
This commit is contained in:
Vishwas Babu A J
2013-09-19 03:40:05 -07:00
5 changed files with 29 additions and 26 deletions
@@ -94,11 +94,11 @@ public class ChargeEnumerations {
switch (type) {
case ACCOUNT_TRANSFER:
optionData = new EnumOptionData(ChargePaymentMode.ACCOUNT_TRANSFER.getValue().longValue(),
ChargePaymentMode.ACCOUNT_TRANSFER.getCode(), ChargePaymentMode.ACCOUNT_TRANSFER.getCode());
ChargePaymentMode.ACCOUNT_TRANSFER.getCode(), "Account transfer");
break;
default:
optionData = new EnumOptionData(ChargePaymentMode.REGULAR.getValue().longValue(), ChargePaymentMode.REGULAR.getCode(),
ChargePaymentMode.REGULAR.getCode());
"Regular");
break;
}
return optionData;
@@ -504,6 +504,9 @@ public class Loan extends AbstractPersistable<Long> {
private void handleChargePaidTransaction(final LoanCharge charge, final LoanTransaction chargesPayment,
final LoanLifecycleStateMachine loanLifecycleStateMachine) {
chargesPayment.updateLoan(this);
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(chargesPayment, charge, chargesPayment.getAmount(getCurrency())
.getAmount());
chargesPayment.getLoanChargesPaid().add(loanChargePaidBy);
this.loanTransactions.add(chargesPayment);
final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_CHARGE_PAYMENT,
LoanStatus.fromInt(this.loanStatus));
@@ -1444,16 +1447,14 @@ public class Loan extends AbstractPersistable<Long> {
* for repayments at disbursements too?
***/
final Money totalFeeChargesDueAtDisbursement = this.summary.getTotalFeeChargesDueAtDisbursement(loanCurrency());
if (totalFeeChargesDueAtDisbursement.isGreaterThanZero()) {
/**
/**
* all Charges repaid at disbursal is marked as repaid and
* "APPLY Charge" transactions are created for all other fees (
* which are created during disbursal but not repaid)
**/
for (final LoanCharge charge : setOfLoanCharges()) {
if (charge.isDueAtDisbursement()) {
if (!charge.getChargePaymentMode().isPaymentModeAccountTransfer()) {
if (totalFeeChargesDueAtDisbursement.isGreaterThanZero() && !charge.getChargePaymentMode().isPaymentModeAccountTransfer()) {
final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(this.getOffice(),
charge.getAmount(getCurrency()), null, disbursedOn, txnExternalId);
final Money zero = Money.zero(getCurrency());
@@ -1469,7 +1470,6 @@ public class Loan extends AbstractPersistable<Long> {
} else {
handleChargeAppliedTransaction(charge, disbursedOn);
}
}
}
if (getApprovedOnDate() != null && disbursedOn.isBefore(getApprovedOnDate())) {
@@ -58,17 +58,4 @@ public class LoanChargePaidBy extends AbstractPersistable<Long> {
public void setAmount(BigDecimal 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);
Money amountPaidTowardsCharge = unpaidCharge.updatePaidAmountBy(amountRemaining);
if (!amountPaidTowardsCharge.isZero()) {
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge,
amountPaidTowardsCharge.getAmount());
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy);
if(!loanTransaction.isChargePayment()){
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge,
amountPaidTowardsCharge.getAmount());
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy);
}
amountRemaining = amountRemaining.minus(amountPaidTowardsCharge);
}
}
@@ -240,9 +242,11 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
final LoanCharge unpaidCharge = findEarliestUnpaidChargeFromUnOrderedSet(charges);
Money amountPaidTowardsCharge = unpaidCharge.updatePaidAmountBy(amountRemaining);
if (!amountPaidTowardsCharge.isZero()) {
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge,
amountPaidTowardsCharge.getAmount());
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy);
if(!loanTransaction.isChargePayment()){
LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(loanTransaction, loanCharge,
amountPaidTowardsCharge.getAmount());
loanTransaction.getLoanChargesPaid().add(loanChargePaidBy);
}
amountRemaining = amountRemaining.minus(amountPaidTowardsCharge);
}
}
@@ -96,6 +96,7 @@ import org.mifosplatform.portfolio.loanaccount.serialization.LoanUpdateCommandFr
import org.mifosplatform.portfolio.loanproduct.data.LoanProductData;
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductRelatedDetail;
import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException;
import org.mifosplatform.portfolio.loanproduct.exception.LinkedAccountRequiredException;
import org.mifosplatform.portfolio.loanproduct.service.LoanProductReadPlatformService;
import org.mifosplatform.portfolio.note.domain.Note;
import org.mifosplatform.portfolio.note.domain.NoteRepository;
@@ -786,6 +787,13 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final String errorMessage = "Charge and Loan must have the same currency.";
throw new InvalidCurrencyException("loanCharge", "attach.to.loan", errorMessage);
}
if(loanCharge.getChargePaymentMode().isPaymentModeAccountTransfer()){
PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loanId);
if(portfolioAccountData == null){
final String errorMessage = loanCharge.name()+"Charge requires linked savings account for payment";
throw new LinkedAccountRequiredException("loanCharge.add", errorMessage,loanCharge.name());
}
}
final List<Long> existingTransactionIds = new ArrayList<Long>();
final List<Long> existingReversedTransactionIds = new ArrayList<Long>();
@@ -965,6 +973,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loanId);
if(portfolioAccountData == null){
final String errorMessage = "Charge with id:"+loanChargeId+" requires linked savings account for payment";
throw new LinkedAccountRequiredException("loanCharge.pay", errorMessage,loanChargeId);
}
AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, loanCharge.amountOutstanding(),
PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, portfolioAccountData.accountId(), loanId, "Loan Charge Payment",
locale, fmt, null, null, LoanTransactionType.CHARGE_PAYMENT.getValue(), loanChargeId);