temp check for null charges
This commit is contained in:
+40
-46
@@ -8,7 +8,8 @@ import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
|||||||
import org.mifosplatform.organisation.monetary.domain.Money;
|
import org.mifosplatform.organisation.monetary.domain.Money;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract implementation of {@link LoanRepaymentScheduleTransactionProcessor} which is more convenient for concrete implementations to extend.
|
* Abstract implementation of {@link LoanRepaymentScheduleTransactionProcessor}
|
||||||
|
* which is more convenient for concrete implementations to extend.
|
||||||
*
|
*
|
||||||
* @see HeavensFamilyLoanRepaymentScheduleTransactionProcessor
|
* @see HeavensFamilyLoanRepaymentScheduleTransactionProcessor
|
||||||
* @see CreocoreLoanRepaymentScheduleTransactionProcessor
|
* @see CreocoreLoanRepaymentScheduleTransactionProcessor
|
||||||
@@ -23,24 +24,23 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
* existing in which case the entire loan schedule needs to be re-processed.
|
* existing in which case the entire loan schedule needs to be re-processed.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleTransaction(
|
public void handleTransaction(final LocalDate disbursementDate, final List<LoanTransaction> transactionsPostDisbursement,
|
||||||
final LocalDate disbursementDate,
|
final MonetaryCurrency currency, final List<LoanRepaymentScheduleInstallment> installments, final Set<LoanCharge> charges) {
|
||||||
final List<LoanTransaction> transactionsPostDisbursement,
|
|
||||||
final MonetaryCurrency currency,
|
|
||||||
final List<LoanRepaymentScheduleInstallment> installments,
|
|
||||||
final Set<LoanCharge> charges) {
|
|
||||||
|
|
||||||
|
if (charges != null) {
|
||||||
for (LoanCharge loanCharge : charges) {
|
for (LoanCharge loanCharge : charges) {
|
||||||
if (!loanCharge.isDueAtDisbursement()) {
|
if (!loanCharge.isDueAtDisbursement()) {
|
||||||
loanCharge.resetPaidAmount(currency);
|
loanCharge.resetPaidAmount(currency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (LoanRepaymentScheduleInstallment currentInstallment : installments) {
|
for (LoanRepaymentScheduleInstallment currentInstallment : installments) {
|
||||||
currentInstallment.resetDerivedComponents();
|
currentInstallment.resetDerivedComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-process loan charges over repayment periods (picking up on waived loan charges)
|
// re-process loan charges over repayment periods (picking up on waived
|
||||||
|
// loan charges)
|
||||||
LoanScheduleWrapper wrapper = new LoanScheduleWrapper();
|
LoanScheduleWrapper wrapper = new LoanScheduleWrapper();
|
||||||
wrapper.reprocess(currency, disbursementDate, installments, charges);
|
wrapper.reprocess(currency, disbursementDate, installments, charges);
|
||||||
|
|
||||||
@@ -57,16 +57,15 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides support for processing the latest transaction (which should be latest transaction) against the loan schedule.
|
* Provides support for processing the latest transaction (which should be
|
||||||
|
* latest transaction) against the loan schedule.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleTransaction(
|
public void handleTransaction(final LoanTransaction loanTransaction, final MonetaryCurrency currency,
|
||||||
final LoanTransaction loanTransaction,
|
final List<LoanRepaymentScheduleInstallment> installments, final Set<LoanCharge> charges) {
|
||||||
final MonetaryCurrency currency,
|
|
||||||
final List<LoanRepaymentScheduleInstallment> installments,
|
|
||||||
final Set<LoanCharge> charges) {
|
|
||||||
|
|
||||||
// find earliest unpaid installment for which to apply this transaction to.
|
// find earliest unpaid installment for which to apply this transaction
|
||||||
|
// to.
|
||||||
int installmentIndex = 0;
|
int installmentIndex = 0;
|
||||||
|
|
||||||
final LocalDate transactionDate = loanTransaction.getTransactionDate();
|
final LocalDate transactionDate = loanTransaction.getTransactionDate();
|
||||||
@@ -76,15 +75,20 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
|
|
||||||
if (currentInstallment.isNotFullyCompleted()) {
|
if (currentInstallment.isNotFullyCompleted()) {
|
||||||
|
|
||||||
// is this transaction early/late/on-time with respect to the current installment?
|
// is this transaction early/late/on-time with respect to the
|
||||||
|
// current installment?
|
||||||
if (isTransactionInAdvanceOfInstallment(installmentIndex, installments, transactionDate, transactionAmountUnprocessed)) {
|
if (isTransactionInAdvanceOfInstallment(installmentIndex, installments, transactionDate, transactionAmountUnprocessed)) {
|
||||||
transactionAmountUnprocessed = handleTransactionThatIsPaymentInAdvanceOfInstallment(currentInstallment, installments, loanTransaction, transactionDate, transactionAmountUnprocessed);
|
transactionAmountUnprocessed = handleTransactionThatIsPaymentInAdvanceOfInstallment(currentInstallment, installments,
|
||||||
|
loanTransaction, transactionDate, transactionAmountUnprocessed);
|
||||||
} else if (isTransactionALateRepaymentOnInstallment(installmentIndex, installments, loanTransaction.getTransactionDate())) {
|
} else if (isTransactionALateRepaymentOnInstallment(installmentIndex, installments, loanTransaction.getTransactionDate())) {
|
||||||
// does this result in a late payment of existing installment?
|
// does this result in a late payment of existing
|
||||||
transactionAmountUnprocessed = handleTransactionThatIsALateRepaymentOfInstallment(currentInstallment, installments, loanTransaction, transactionAmountUnprocessed);
|
// installment?
|
||||||
|
transactionAmountUnprocessed = handleTransactionThatIsALateRepaymentOfInstallment(currentInstallment, installments,
|
||||||
|
loanTransaction, transactionAmountUnprocessed);
|
||||||
} else {
|
} else {
|
||||||
// standard transaction
|
// standard transaction
|
||||||
transactionAmountUnprocessed = handleTransactionThatIsOnTimePaymentOfInstallment(currentInstallment, loanTransaction, transactionAmountUnprocessed);
|
transactionAmountUnprocessed = handleTransactionThatIsOnTimePaymentOfInstallment(currentInstallment, loanTransaction,
|
||||||
|
transactionAmountUnprocessed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +143,8 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
|
|
||||||
for (LoanCharge loanCharge : charges) {
|
for (LoanCharge loanCharge : charges) {
|
||||||
if (loanCharge.isNotFullyPaid() && !loanCharge.isDueAtDisbursement()) {
|
if (loanCharge.isNotFullyPaid() && !loanCharge.isDueAtDisbursement()) {
|
||||||
if (earliestUnpaidCharge == null || loanCharge.getDueForCollectionAsOfLocalDate().isBefore(earliestUnpaidCharge.getDueForCollectionAsOfLocalDate())) {
|
if (earliestUnpaidCharge == null
|
||||||
|
|| loanCharge.getDueForCollectionAsOfLocalDate().isBefore(earliestUnpaidCharge.getDueForCollectionAsOfLocalDate())) {
|
||||||
earliestUnpaidCharge = loanCharge;
|
earliestUnpaidCharge = loanCharge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,9 +154,7 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleWriteOff(
|
public void handleWriteOff(final LoanTransaction loanTransaction, final MonetaryCurrency currency,
|
||||||
final LoanTransaction loanTransaction,
|
|
||||||
final MonetaryCurrency currency,
|
|
||||||
final List<LoanRepaymentScheduleInstallment> installments) {
|
final List<LoanRepaymentScheduleInstallment> installments) {
|
||||||
|
|
||||||
Money principalPortion = Money.zero(currency);
|
Money principalPortion = Money.zero(currency);
|
||||||
@@ -159,7 +162,8 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
Money feeChargesPortion = Money.zero(currency);
|
Money feeChargesPortion = Money.zero(currency);
|
||||||
Money penaltychargesPortion = Money.zero(currency);
|
Money penaltychargesPortion = Money.zero(currency);
|
||||||
|
|
||||||
// determine how much is written off in total and breakdown for principal, interest and charges
|
// determine how much is written off in total and breakdown for
|
||||||
|
// principal, interest and charges
|
||||||
for (LoanRepaymentScheduleInstallment currentInstallment : installments) {
|
for (LoanRepaymentScheduleInstallment currentInstallment : installments) {
|
||||||
|
|
||||||
if (currentInstallment.isNotFullyCompleted()) {
|
if (currentInstallment.isNotFullyCompleted()) {
|
||||||
@@ -180,8 +184,7 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
* transaction date is after the installment due date.
|
* transaction date is after the installment due date.
|
||||||
*/
|
*/
|
||||||
protected boolean isTransactionALateRepaymentOnInstallment(final int installmentIndex,
|
protected boolean isTransactionALateRepaymentOnInstallment(final int installmentIndex,
|
||||||
final List<LoanRepaymentScheduleInstallment> installments,
|
final List<LoanRepaymentScheduleInstallment> installments, final LocalDate transactionDate) {
|
||||||
final LocalDate transactionDate) {
|
|
||||||
|
|
||||||
LoanRepaymentScheduleInstallment currentInstallment = installments.get(installmentIndex);
|
LoanRepaymentScheduleInstallment currentInstallment = installments.get(installmentIndex);
|
||||||
|
|
||||||
@@ -191,44 +194,35 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
|||||||
/**
|
/**
|
||||||
* For late repayments, how should components of installment be paid off
|
* For late repayments, how should components of installment be paid off
|
||||||
*/
|
*/
|
||||||
protected abstract Money handleTransactionThatIsALateRepaymentOfInstallment(
|
protected abstract Money handleTransactionThatIsALateRepaymentOfInstallment(final LoanRepaymentScheduleInstallment currentInstallment,
|
||||||
final LoanRepaymentScheduleInstallment currentInstallment,
|
final List<LoanRepaymentScheduleInstallment> installments, final LoanTransaction loanTransaction,
|
||||||
final List<LoanRepaymentScheduleInstallment> installments,
|
|
||||||
final LoanTransaction loanTransaction,
|
|
||||||
final Money transactionAmountUnprocessed);
|
final Money transactionAmountUnprocessed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is responsible for checking if the current transaction is 'an
|
* This method is responsible for checking if the current transaction is 'an
|
||||||
* advance/early payment' based on the details passed through.
|
* advance/early payment' based on the details passed through.
|
||||||
*/
|
*/
|
||||||
protected abstract boolean isTransactionInAdvanceOfInstallment(
|
protected abstract boolean isTransactionInAdvanceOfInstallment(final int currentInstallmentIndex,
|
||||||
final int currentInstallmentIndex,
|
final List<LoanRepaymentScheduleInstallment> installments, final LocalDate transactionDate, final Money transactionAmount);
|
||||||
final List<LoanRepaymentScheduleInstallment> installments,
|
|
||||||
final LocalDate transactionDate,
|
|
||||||
final Money transactionAmount);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For early/'in advance' repayments.
|
* For early/'in advance' repayments.
|
||||||
*/
|
*/
|
||||||
protected abstract Money handleTransactionThatIsPaymentInAdvanceOfInstallment(
|
protected abstract Money handleTransactionThatIsPaymentInAdvanceOfInstallment(
|
||||||
final LoanRepaymentScheduleInstallment currentInstallment,
|
final LoanRepaymentScheduleInstallment currentInstallment, final List<LoanRepaymentScheduleInstallment> installments,
|
||||||
final List<LoanRepaymentScheduleInstallment> installments,
|
final LoanTransaction loanTransaction, final LocalDate transactionDate, final Money paymentInAdvance);
|
||||||
final LoanTransaction loanTransaction,
|
|
||||||
final LocalDate transactionDate,
|
|
||||||
final Money paymentInAdvance);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For normal on-time repayments.
|
* For normal on-time repayments.
|
||||||
*/
|
*/
|
||||||
protected abstract Money handleTransactionThatIsOnTimePaymentOfInstallment(
|
protected abstract Money handleTransactionThatIsOnTimePaymentOfInstallment(final LoanRepaymentScheduleInstallment currentInstallment,
|
||||||
final LoanRepaymentScheduleInstallment currentInstallment,
|
final LoanTransaction loanTransaction, final Money transactionAmountUnprocessed);
|
||||||
final LoanTransaction loanTransaction,
|
|
||||||
final Money transactionAmountUnprocessed);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when a transaction results in an over-payment of the full loan.
|
* Invoked when a transaction results in an over-payment of the full loan.
|
||||||
*
|
*
|
||||||
* transaction amount is greater than the total expected principal and interest of the loan.
|
* transaction amount is greater than the total expected principal and
|
||||||
|
* interest of the loan.
|
||||||
*/
|
*/
|
||||||
protected abstract void onLoanOverpayment(final LoanTransaction loanTransaction, final Money loanOverPaymentAmount);
|
protected abstract void onLoanOverpayment(final LoanTransaction loanTransaction, final Money loanOverPaymentAmount);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user