adamsaghy commented on code in PR #5817:
URL: https://github.com/apache/fineract/pull/5817#discussion_r3224919994
##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanWritePlatformServiceImpl.java:
##########
@@ -668,6 +659,64 @@ public CommandProcessingResult creditBalanceRefund(final
Long loanId, final Json
.withClientId(loan.getClientId()).withLoanId(loanId).with(changes).build();
}
+ @Override
+ public CommandProcessingResult makeGoodwillCredit(Long loanId, JsonCommand
command) {
+ final WorkingCapitalLoan loan = this.loanRepository.findById(loanId)
+ .orElseThrow(() -> new
WorkingCapitalLoanNotFoundException(loanId));
+ this.validator.validateRepayment(command.json(), loan);
+
+ if (!LoanStatus.ACTIVE.equals(loan.getLoanStatus()) &&
!LoanStatus.CLOSED_OBLIGATIONS_MET.equals(loan.getLoanStatus())
+ && !LoanStatus.OVERPAID.equals(loan.getLoanStatus())) {
+ throw new
PlatformApiDataValidationException("validation.msg.wc.loan.transition.not.allowed",
+ "Goodwill Credit is allowed only for active/closed
obligations met/overpaid loans", "loanStatus");
+ }
+
+ final LocalDate transactionDate =
command.localDateValueOfParameterNamed(WorkingCapitalLoanConstants.transactionDateParamName);
+ final BigDecimal transactionAmount = this.fromApiJsonHelper
+
.extractBigDecimalNamed(WorkingCapitalLoanConstants.transactionAmountParamName,
command.parsedJson(), new HashSet<>());
+ final Map<String, Object> changes = new LinkedHashMap<>();
+ changes.put(WorkingCapitalLoanConstants.transactionDateParamName,
transactionDate);
+ changes.put(WorkingCapitalLoanConstants.transactionAmountParamName,
transactionAmount);
+ final PaymentDetail paymentDetail =
createAndPersistPaymentDetailFromCommand(command, changes);
+
+ final Long classificationId =
command.longValueOfParameterNamed(WorkingCapitalLoanConstants.classificationIdParamName);
+ final CodeValue classification = classificationId != null
+ ?
codeValueRepository.findByCodeNameAndId(WorkingCapitalLoanConstants.REPAYMENT_CLASSIFICATION_CODE_NAME,
classificationId)
+ : null;
+ changes.put(WorkingCapitalLoanConstants.classificationIdParamName,
classificationId);
+
+ final ExternalId txnExternalId =
this.externalIdFactory.createFromCommand(command,
+ WorkingCapitalLoanConstants.externalIdParameterName);
+ final WorkingCapitalLoanTransaction repaymentTransaction =
WorkingCapitalLoanTransaction.goodwillCredit(loan, transactionAmount,
+ paymentDetail, transactionDate, classification, txnExternalId);
+ this.transactionRepository.saveAndFlush(repaymentTransaction);
+ final WorkingCapitalLoanBalance currentBalance =
this.balanceRepository.findByWcLoan_Id(loan.getId())
+ .orElseGet(() -> WorkingCapitalLoanBalance.createFor(loan));
+ final BigDecimal outstandingBeforeRepayment =
MathUtil.nullToZero(currentBalance.getPrincipalOutstanding());
+ final BigDecimal amountAppliedToOutstanding =
transactionAmount.min(outstandingBeforeRepayment);
+
+ final WorkingCapitalLoanTransactionAllocation allocation =
WorkingCapitalLoanTransactionAllocation
+ .forPrincipalAllocation(repaymentTransaction,
amountAppliedToOutstanding);
+ this.allocationRepository.saveAndFlush(allocation);
+
+ final RepaymentAmortizationData amortizationData =
amortizationScheduleWriteService.applyRepayment(loan, transactionDate,
+ amountAppliedToOutstanding);
+ updateBalanceOnRepayment(loan, transactionAmount, amortizationData);
+ internalWorkingCapitalLoanPaymentService.makePayment(loanId,
amountAppliedToOutstanding, transactionDate);
+
+ handleStateChanges(loan, transactionDate);
+ changes.put("status", loan.getLoanStatus());
+
+ handleNote(loan, command, changes);
+
+ this.loanRepository.saveAndFlush(loan);
Review Comment:
No need for this.
--
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]