Fix Loan Transaction Chargeback outstanding

This commit is contained in:
Jose Alberto Hernandez
2022-10-24 16:32:55 +02:00
committed by Arnold Gálovics
parent 134b6248a1
commit ce4c1dd137
4 changed files with 54 additions and 25 deletions
@@ -164,6 +164,22 @@ final class LoanTransactionsApiResourceSwagger {
public String reversalExternalId;
@Schema(example = "[2012, 5, 18]")
public LocalDate reversedOnDate;
@Schema(example = "1000.00")
public Double netDisbursalAmount;
@Schema(example = "240.00")
public Double principalPortion;
@Schema(example = "23.90")
public Double feeChargesPortion;
@Schema(example = "12.80")
public Double penaltyChargesPortion;
@Schema(example = "33.00")
public Double overpaymentPortion;
@Schema(example = "55.50")
public Double unrecognizedIncomePortion;
@Schema(example = "100.00")
public Double outstandingLoanBalance;
@Schema(example = "[2012, 5, 18]")
public LocalDate possibleNextRepaymentDate;
public Set<GetLoanTransactionRelation> transactionRelations;
}
@@ -5656,7 +5656,11 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
} else if (loanTransaction.isChargeback()) {
Money transactionOutstanding = loanTransaction.getAmount(getCurrency());
if (!loanTransaction.getOverPaymentPortion(getCurrency()).isZero()) {
transactionOutstanding = transactionOutstanding.minus(loanTransaction.getOverPaymentPortion(getCurrency()));
transactionOutstanding = loanTransaction.getAmount(getCurrency())
.minus(loanTransaction.getOverPaymentPortion(getCurrency()));
if (transactionOutstanding.isLessThanZero()) {
transactionOutstanding = Money.zero(getCurrency());
}
}
outstanding = outstanding.plus(transactionOutstanding);
loanTransaction.updateOutstandingLoanBalance(outstanding.getAmount());
@@ -6120,11 +6124,7 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
.determineProcessor(this.transactionProcessingStrategy);
final Money overpaidAmount = calculateTotalOverpayment(); // Before Transaction
if (overpaidAmount.isGreaterThanZero()) {
Money difference = chargebackTransaction.getAmount(getCurrency()).minus(overpaidAmount);
if (difference.isLessThanZero()) {
difference = null;
}
chargebackTransaction.setOverPayments(difference);
chargebackTransaction.setOverPayments(overpaidAmount);
}
if (chargebackTransaction.isNotZero(loanCurrency())) {
@@ -1286,7 +1286,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
businessEventNotifierService.notifyPostBusinessEvent(new LoanChargebackTransactionBusinessEvent(loanTransaction));
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(transactionId)
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(newTransaction.getId())
.withOfficeId(loan.getOfficeId()).withClientId(loan.getClientId()).withGroupId(loan.getGroupId()).withLoanId(loanId)
.with(changes).build();
}