Skip to content

Commit

Permalink
FINERACT-1968-Advanced-Payment-Allocation-Charge-Off
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchiD authored and galovics committed Oct 9, 2023
1 parent 06b5643 commit d2fe393
Show file tree
Hide file tree
Showing 2 changed files with 780 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void processLatestTransaction(LoanTransaction loanTransaction, MonetaryCu
case REPAYMENT, MERCHANT_ISSUED_REFUND, PAYOUT_REFUND, GOODWILL_CREDIT, CHARGE_REFUND, CHARGE_ADJUSTMENT, DOWN_PAYMENT,
WAIVE_INTEREST, RECOVERY_REPAYMENT ->
handleRepayment(loanTransaction, currency, installments, charges);
case CHARGE_OFF -> handleChargeOff(loanTransaction, currency, installments);
// TODO: Cover rest of the transaction types
default -> {
log.warn("Unhandled transaction processing for transaction type: {}", loanTransaction.getTypeOf());
Expand Down Expand Up @@ -363,6 +364,26 @@ private void handleOverpayment(Money overpaymentPortion, LoanTransaction loanTra
}
}

private void handleChargeOff(LoanTransaction loanTransaction, MonetaryCurrency currency,
List<LoanRepaymentScheduleInstallment> installments) {
loanTransaction.resetDerivedComponents();
// determine how much is outstanding total and breakdown for principal, interest and charges
Money principalPortion = Money.zero(currency);
Money interestPortion = Money.zero(currency);
Money feeChargesPortion = Money.zero(currency);
Money penaltychargesPortion = Money.zero(currency);
for (final LoanRepaymentScheduleInstallment currentInstallment : installments) {
if (currentInstallment.isNotFullyPaidOff()) {
principalPortion = principalPortion.plus(currentInstallment.getPrincipalOutstanding(currency));
interestPortion = interestPortion.plus(currentInstallment.getInterestOutstanding(currency));
feeChargesPortion = feeChargesPortion.plus(currentInstallment.getFeeChargesOutstanding(currency));
penaltychargesPortion = penaltychargesPortion.plus(currentInstallment.getPenaltyChargesCharged(currency));
}
}

loanTransaction.updateComponentsAndTotal(principalPortion, interestPortion, feeChargesPortion, penaltychargesPortion);
}

@AllArgsConstructor
@Getter
@Setter
Expand Down
Loading

0 comments on commit d2fe393

Please sign in to comment.