Skip to content

Commit

Permalink
FINERACT-1971: Auto down payment disbursement to savings not affectin…
Browse files Browse the repository at this point in the history
…g linked account
  • Loading branch information
ruchiD authored and adamsaghy committed Jan 26, 2024
1 parent b01ccc4 commit f7a0562
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +49,9 @@ public static AccountTransferType fromInt(final Integer statusValue) {
case 4:
enumeration = AccountTransferType.INTEREST_TRANSFER;
break;
case 5:
enumeration = AccountTransferType.LOAN_DOWN_PAYMENT;
break;
}
return enumeration;
}
Expand Down Expand Up @@ -84,4 +88,9 @@ public boolean isChargePayment() {
public boolean isInterestTransfer() {
return this.value.equals(AccountTransferType.INTEREST_TRANSFER.getValue());
}

public boolean isLoanDownPayment() {
return this.value.equals(AccountTransferType.LOAN_DOWN_PAYMENT.getValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public static EnumOptionData transferType(final AccountTransferType type) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ public Long transferFunds(final AccountTransferDTO accountTransferDTO) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
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;
Expand Down Expand Up @@ -384,6 +385,8 @@ public CommandProcessingResult disburseLoan(final Long loanId, final JsonCommand
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.
Expand Down Expand Up @@ -458,7 +461,31 @@ public CommandProcessingResult disburseLoan(final Long loanId, final JsonCommand
}
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()) {
Expand Down Expand Up @@ -498,9 +525,6 @@ public CommandProcessingResult disburseLoan(final Long loanId, final JsonCommand
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;
Expand Down
Loading

0 comments on commit f7a0562

Please sign in to comment.