adamsaghy commented on code in PR #2614:
URL: https://github.com/apache/fineract/pull/2614#discussion_r983458624
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -1184,6 +1189,105 @@ public CommandProcessingResult
adjustLoanTransaction(final Long loanId, final Lo
.with(changes).build();
}
+ @Transactional
+ @Override
+ public CommandProcessingResult chargebackLoanTransaction(final Long
loanId, final Long transactionId, final JsonCommand command) {
+ final boolean paymentDetailRequired = true;
+ this.loanEventApiJsonValidator.validateTransaction(command.json(),
paymentDetailRequired);
+
+ Loan loan = this.loanAssembler.assembleFrom(loanId);
+ if
(this.accountTransfersReadPlatformService.isAccountTransfer(transactionId,
PortfolioAccountType.LOAN)) {
+ throw new
PlatformServiceUnavailableException("error.msg.loan.transfer.transaction.update.not.allowed",
+ "Loan transaction:" + transactionId + " chargeback not
allowed as it involves in account transfer", transactionId);
+ }
+ if (loan.isClosedWrittenOff()) {
+ throw new
PlatformServiceUnavailableException("error.msg.loan.chargeback.operation.not.allowed",
+ "Loan transaction:" + transactionId + " chargeback not
allowed as loan status is written off", transactionId);
+ }
+ if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
+ throw new
PlatformServiceUnavailableException("error.msg.loan.chargeback.operation.not.allowed",
+ "Loan transaction:" + transactionId + " chargeback not
allowed as loan product is interest recalculation enabled",
+ transactionId);
+ }
+
+ final List<Long> existingTransactionIds = new ArrayList<>();
+ final List<Long> existingReversedTransactionIds = new ArrayList<>();
+
+ checkClientOrGroupActive(loan);
+
+ LoanTransaction loanTransaction =
this.loanTransactionRepository.findById(transactionId)
+ .orElseThrow(() -> new
LoanTransactionNotFoundException(transactionId));
+
+ if (!loanTransaction.isRepayment()) {
+ throw new
PlatformServiceUnavailableException("error.msg.loan.chargeback.operation.not.allowed",
+ "Loan transaction:" + transactionId + " chargeback not
allowed as loan transaction is not repayment", transactionId);
+ }
+
+ businessEventNotifierService.notifyPreBusinessEvent(new
LoanChargebackTransactionBusinessEvent(loanTransaction));
+
+ final LocalDate transactionDate =
command.localDateValueOfParameterNamed(LoanApiConstants.transactionDateParamName);
+ final BigDecimal transactionAmount =
command.bigDecimalValueOfParameterNamed(LoanApiConstants.TRANSACTION_AMOUNT_PARAMNAME);
+ final String txnExternalId =
command.stringValueOfParameterNamedAllowingNull(LoanApiConstants.externalIdParameterName);
+
+ final Map<String, Object> changes = new LinkedHashMap<>();
+ changes.put("transactionDate",
command.stringValueOfParameterNamed(LoanApiConstants.transactionDateParamName));
+ changes.put("transactionAmount",
command.stringValueOfParameterNamed(LoanApiConstants.TRANSACTION_AMOUNT_PARAMNAME));
+ changes.put("locale", command.locale());
+ changes.put("dateFormat", command.dateFormat());
+ changes.put("paymentTypeId",
command.stringValueOfParameterNamed(LoanApiConstants.PAYMENT_TYPE_PARAMNAME));
+
+ final Money transactionAmountAsMoney = Money.of(loan.getCurrency(),
transactionAmount);
+ final PaymentDetail paymentDetail =
this.paymentDetailWritePlatformService.createPaymentDetail(command, changes);
+ LoanTransaction newTransaction = LoanTransaction.chargeback(loan,
transactionAmountAsMoney, paymentDetail, transactionDate,
+ txnExternalId);
+
+ final Integer validateLoanTransactionAmount =
validateLoanTransactionAmountChargeBack(loanTransaction, newTransaction);
Review Comment:
validateLoanTransactionAmount variable name is misleading. Can we move the
whole
`if (validateLoanTransactionAmount > 0) {
throw new
PlatformServiceUnavailableException("error.msg.loan.chargeback.operation.not.allowed",
"Loan transaction:" + transactionId + " chargeback not
allowed as loan transaction amount is not enough",
transactionId);
}`
into the "validateLoanTransactionAmountChargeBack" method and throw the
error as part of that logic? that way we can rework this method to
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]