in component-test/src/main/java/org/apache/fineract/cn/portfolio/TestAccountingInteractionInLoanWorkflow.java [1212:1285]
private Payment step7PaybackPartialAmount(
final BigDecimal amount,
final LocalDateTime forDateTime,
final BigDecimal lateFee,
final BigDecimal balanceInEntryAccount,
final String entryAccountIdentifier) throws InterruptedException {
logger.info("step7PaybackPartialAmount '{}' '{}'", amount, forDateTime);
final BigDecimal principal = amount.subtract(interestAccrued).subtract(lateFee.add(nonLateFees));
AccountingFixture.mockBalance(entryAccountIdentifier, balanceInEntryAccount);
final Payment payment = checkCostComponentForActionCorrect(
product.getIdentifier(),
customerCase.getIdentifier(),
Action.ACCEPT_PAYMENT,
new HashSet<>(Arrays.asList(AccountDesignators.ENTRY, AccountDesignators.CUSTOMER_LOAN_GROUP, AccountDesignators.LOAN_FUNDS_SOURCE)),
amount,
forDateTime,
MINOR_CURRENCY_UNIT_DIGITS,
new CostComponent(ChargeIdentifiers.REPAY_PRINCIPAL_ID, principal),
new CostComponent(ChargeIdentifiers.REPAY_INTEREST_ID, interestAccrued),
new CostComponent(ChargeIdentifiers.REPAY_FEES_ID, lateFee.add(nonLateFees)),
new CostComponent(ChargeIdentifiers.INTEREST_ID, interestAccrued),
new CostComponent(ChargeIdentifiers.LATE_FEE_ID, lateFee));
checkStateTransfer(
product.getIdentifier(),
customerCase.getIdentifier(),
Action.ACCEPT_PAYMENT,
forDateTime,
assignEntry(entryAccountIdentifier),
amount,
IndividualLoanEventConstants.ACCEPT_PAYMENT_INDIVIDUALLOAN_CASE,
Case.State.ACTIVE); //Close has to be done explicitly.
checkNextActionsCorrect(product.getIdentifier(), customerCase.getIdentifier(),
Action.APPLY_INTEREST, Action.MARK_LATE, Action.ACCEPT_PAYMENT, Action.DISBURSE, Action.MARK_IN_ARREARS, Action.WRITE_OFF, Action.CLOSE);
final Set<Debtor> debtors = new HashSet<>();
BigDecimal customerDepositAccountDebit = principal;
if (interestAccrued.compareTo(BigDecimal.ZERO) != 0) {
customerDepositAccountDebit = customerDepositAccountDebit.add(interestAccrued);
debtors.add(new Debtor(AccountingFixture.LOAN_INTEREST_ACCRUAL_ACCOUNT_IDENTIFIER, interestAccrued.toPlainString()));
}
if (lateFee.add(nonLateFees).compareTo(BigDecimal.ZERO) != 0) {
customerDepositAccountDebit = customerDepositAccountDebit.add(lateFee.add(nonLateFees));
}
if (lateFee.compareTo(BigDecimal.ZERO) != 0) {
debtors.add(new Debtor(AccountingFixture.LATE_FEE_ACCRUAL_ACCOUNT_IDENTIFIER, lateFee.toPlainString()));
}
debtors.add(new Debtor(entryAccountIdentifier, customerDepositAccountDebit.toPlainString()));
final Set<Creditor> creditors = new HashSet<>();
creditors.add(new Creditor(customerLoanPrincipalIdentifier, principal.toPlainString()));
if (interestAccrued.compareTo(BigDecimal.ZERO) != 0) {
creditors.add(new Creditor(customerLoanInterestIdentifier, interestAccrued.toPlainString()));
creditors.add(new Creditor(AccountingFixture.CONSUMER_LOAN_INTEREST_ACCOUNT_IDENTIFIER, interestAccrued.toPlainString()));
}
if (lateFee.add(nonLateFees).compareTo(BigDecimal.ZERO) != 0) {
creditors.add(new Creditor(customerLoanFeeIdentifier, lateFee.add(nonLateFees).toPlainString()));
}
if (lateFee.compareTo(BigDecimal.ZERO) != 0) {
creditors.add(new Creditor(AccountingFixture.LATE_FEE_INCOME_ACCOUNT_IDENTIFIER, lateFee.toPlainString()));
}
AccountingFixture.verifyTransfer(ledgerManager, debtors, creditors, product.getIdentifier(), customerCase.getIdentifier(), Action.ACCEPT_PAYMENT);
expectedCurrentPrincipal = expectedCurrentPrincipal.subtract(principal);
interestAccrued = BigDecimal.ZERO.setScale(MINOR_CURRENCY_UNIT_DIGITS, RoundingMode.HALF_EVEN);
nonLateFees = BigDecimal.ZERO.setScale(MINOR_CURRENCY_UNIT_DIGITS, RoundingMode.HALF_EVEN);
lateFees = BigDecimal.ZERO.setScale(MINOR_CURRENCY_UNIT_DIGITS, RoundingMode.HALF_EVEN);
updateBalanceMock();
logger.info("Completed step7PaybackPartialAmount");
return payment;
}