FINERACT-1971: Auto down payment disbursement to savings not affecting linked account

This commit is contained in:
Ruchi Dhamankar
2024-01-26 14:12:02 +01:00
committed by Adam Saghy
parent b01ccc4619
commit f7a056204c
6 changed files with 318 additions and 5 deletions
@@ -27,7 +27,8 @@ public enum AccountTransferType {
ACCOUNT_TRANSFER(1, "accountTransferType.account.transfer"), //
LOAN_REPAYMENT(2, "accountTransferType.loan.repayment"), //
CHARGE_PAYMENT(3, "accountTransferType.charge.payment"), //
INTEREST_TRANSFER(4, "accountTransferType.interest.transfer"); //
INTEREST_TRANSFER(4, "accountTransferType.interest.transfer"), //
LOAN_DOWN_PAYMENT(5, "accountTransferType.loan.downpayment"); //
private final Integer value;
private final String code;
@@ -48,6 +49,9 @@ public enum AccountTransferType {
case 4:
enumeration = AccountTransferType.INTEREST_TRANSFER;
break;
case 5:
enumeration = AccountTransferType.LOAN_DOWN_PAYMENT;
break;
}
return enumeration;
}
@@ -84,4 +88,9 @@ public enum AccountTransferType {
public boolean isInterestTransfer() {
return this.value.equals(AccountTransferType.INTEREST_TRANSFER.getValue());
}
public boolean isLoanDownPayment() {
return this.value.equals(AccountTransferType.LOAN_DOWN_PAYMENT.getValue());
}
}
@@ -107,6 +107,11 @@ public final class AccountTransferEnumerations {
optionData = new EnumOptionData(AccountTransferType.INTEREST_TRANSFER.getValue().longValue(),
AccountTransferType.INTEREST_TRANSFER.getCode(), "Interest Transfer");
break;
case LOAN_DOWN_PAYMENT:
optionData = new EnumOptionData(AccountTransferType.LOAN_DOWN_PAYMENT.getValue().longValue(),
AccountTransferType.LOAN_DOWN_PAYMENT.getCode(), "Loan Down Payment");
break;
}
}
return optionData;
@@ -329,6 +329,16 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
accountTransferDTO.getPaymentDetail(), null, externalId, accountTransferDTO.getToTransferType(),
accountTransferDTO.getLoanInstallmentNumber());
} else if (AccountTransferType.fromInt(accountTransferDTO.getTransferType()).isLoanDownPayment()) {
final boolean isRecoveryRepayment = false;
final Boolean isHolidayValidationDone = false;
final HolidayDetailDTO holidayDetailDto = null;
final String chargeRefundChargeType = null;
loanTransaction = this.loanAccountDomainService.makeRepayment(LoanTransactionType.DOWN_PAYMENT, toLoanAccount,
accountTransferDTO.getTransactionDate(), accountTransferDTO.getTransactionAmount(),
accountTransferDTO.getPaymentDetail(), null, externalId, isRecoveryRepayment, chargeRefundChargeType,
isAccountTransfer, holidayDetailDto, isHolidayValidationDone);
toLoanAccount = loanTransaction.getLoan();
} else {
final boolean isRecoveryRepayment = false;
final Boolean isHolidayValidationDone = false;
@@ -59,6 +59,7 @@ import org.apache.fineract.infrastructure.core.exception.PlatformServiceUnavaila
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
import org.apache.fineract.infrastructure.core.service.MathUtil;
import org.apache.fineract.infrastructure.dataqueries.data.EntityTables;
import org.apache.fineract.infrastructure.dataqueries.data.StatusEnum;
import org.apache.fineract.infrastructure.dataqueries.service.EntityDatatableChecksWritePlatformService;
@@ -384,6 +385,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
Money amountBeforeAdjust = loan.getPrincipal();
boolean canDisburse = loan.canDisburse(actualDisbursementDate);
ChangedTransactionDetail changedTransactionDetail = null;
final Locale locale = command.extractLocale();
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
if (canDisburse) {
// Get netDisbursalAmount from disbursal screen field.
@@ -458,7 +461,31 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
}
loan.adjustNetDisbursalAmount(amountToDisburse.getAmount());
if (loan.isAutoRepaymentForDownPaymentEnabled()) {
loanDownPaymentHandlerService.handleDownPayment(scheduleGeneratorDTO, command, amountToDisburse, loan);
// updating linked savings account for auto down payment transaction for disbursement to savings account
if (isAccountTransfer && loan.shouldCreateStandingInstructionAtDisbursement()) {
final PortfolioAccountData linkedSavingsAccountData = this.accountAssociationsReadPlatformService
.retriveLoanLinkedAssociation(loanId);
final SavingsAccount fromSavingsAccount = null;
final boolean isRegularTransaction = true;
final boolean isExceptionForBalanceCheck = false;
BigDecimal disbursedAmountPercentageForDownPayment = loan.getLoanRepaymentScheduleDetail()
.getDisbursedAmountPercentageForDownPayment();
Money downPaymentMoney = Money.of(loan.getCurrency(),
MathUtil.percentageOf(amountToDisburse.getAmount(), disbursedAmountPercentageForDownPayment, 19));
final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(actualDisbursementDate,
downPaymentMoney.getAmount(), PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN,
linkedSavingsAccountData.getId(), loan.getId(),
"To loan " + loan.getAccountNumber() + " from savings " + linkedSavingsAccountData.getAccountNo()
+ " Standing instruction transfer ",
locale, fmt, null, null, LoanTransactionType.DOWN_PAYMENT.getValue(), null, null,
AccountTransferType.LOAN_DOWN_PAYMENT.getValue(), null, null, ExternalId.empty(), null, null,
fromSavingsAccount, isRegularTransaction, isExceptionForBalanceCheck);
this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
} else {
loanDownPaymentHandlerService.handleDownPayment(scheduleGeneratorDTO, command, amountToDisburse, loan);
}
}
}
if (!changes.isEmpty()) {
@@ -498,9 +525,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
businessEventNotifierService.notifyPostBusinessEvent(new LoanAccrualTransactionCreatedBusinessEvent(savedLoanTransaction));
}
}
final Locale locale = command.extractLocale();
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
for (final Map.Entry<Long, BigDecimal> entrySet : disBuLoanCharges.entrySet()) {
final PortfolioAccountData savingAccountData = this.accountAssociationsReadPlatformService.retriveLoanLinkedAssociation(loanId);
final SavingsAccount fromSavingsAccount = null;