FINERACT-2092: Fix adjust transactions handling

This commit is contained in:
Adam Saghy
2024-06-26 13:15:57 +02:00
parent db8000b4f3
commit 33ecbc7130
3 changed files with 51 additions and 2 deletions
@@ -1040,6 +1040,10 @@ public class LoanTransaction extends AbstractAuditableWithUTCDateTimeCustom<Long
return false;
}
public String getChargeRefundChargeType() {
return chargeRefundChargeType;
}
// TODO missing hashCode(), equals(Object obj), but probably OK as long as
// this is never stored in a Collection.
}
@@ -1444,8 +1444,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final Money transactionAmountAsMoney = Money.of(loan.getCurrency(), transactionAmount);
final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createPaymentDetail(command, changes);
LoanTransaction newTransactionDetail = LoanTransaction.repayment(loan.getOffice(), transactionAmountAsMoney, paymentDetail,
transactionDate, txnExternalId);
LoanTransaction newTransactionDetail = LoanTransaction.repaymentType(transactionToAdjust.getTypeOf(), loan.getOffice(),
transactionAmountAsMoney, paymentDetail, transactionDate, txnExternalId, transactionToAdjust.getChargeRefundChargeType());
if (transactionToAdjust.isInterestWaiver()) {
Money unrecognizedIncome = transactionAmountAsMoney.zero();
Money interestComponent = transactionAmountAsMoney;
@@ -1579,6 +1579,51 @@ public class LoanTransactionInterestPaymentWaiverTest extends BaseLoanIntegratio
});
}
@Test
public void testInterestPaymentWaiverAdjustTransaction() {
runAt("15 January 2023", () -> {
Integer numberOfRepayments = 4;
double amount = 1000.0;
String loanDisbursementDate = "1 January 2023";
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
LOG.info("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
PostLoanProductsResponse loanProductResponse = loanProductHelper
.createLoanProduct(createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
.loanScheduleType(LoanScheduleType.PROGRESSIVE.toString()));
Long loanId = applyAndApproveLoanProgressiveAdvancedPaymentAllocationStrategyMonthlyRepayments(clientId,
loanProductResponse.getResourceId(), numberOfRepayments, loanDisbursementDate, amount, null);
verifyRepaymentSchedule(loanId, //
installment(1000.0, null, "01 January 2023"), //
installment(250.0, false, "01 February 2023"), //
installment(250.0, false, "01 March 2023"), //
installment(250.0, false, "01 April 2023"), //
installment(250.0, false, "01 May 2023") //
);
loanTransactionHelper.disburseLoan(loanId, new PostLoansLoanIdRequest().actualDisbursementDate("1 January 2023")
.dateFormat(DATETIME_PATTERN).transactionAmount(BigDecimal.valueOf(1000.0)).locale("en"));
// loan should be active
Long transactionId = addInterestPaymentWaiverForLoan(loanId, 250.0, "2 January 2023");
verifyTransactions(loanId, //
transaction(1000.0, "Disbursement", "01 January 2023", 1000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
transaction(250.0, "Interest Payment Waiver", "02 January 2023", 750.0, 250.0, 0.0, 0.0, 0, 0.0, 0.0));
loanTransactionHelper.adjustLoanTransaction(loanId, transactionId, new PostLoansLoanIdTransactionsTransactionIdRequest()
.transactionAmount(200.0).dateFormat(DATETIME_PATTERN).transactionDate("3 January 2023").locale("en"));
verifyTransactions(loanId, //
transaction(1000.0, "Disbursement", "01 January 2023", 1000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
transaction(250.0, "Interest Payment Waiver", "02 January 2023", 750.0, 250.0, 0.0, 0.0, 0, 0.0, 0.0, true),
transaction(200.0, "Interest Payment Waiver", "03 January 2023", 800.0, 200.0, 0.0, 0.0, 0, 0.0, 0.0));
});
}
private void chargeFee(Long loanId, Double amount, String dueDate) {
PostChargesResponse feeCharge = chargesHelper.createCharges(new PostChargesRequest().penalty(false).amount(9.0)
.chargeCalculationType(ChargeCalculationType.FLAT.getValue()).chargeTimeType(ChargeTimeType.SPECIFIED_DUE_DATE.getValue())