FINERACT-1840: Fee income is not realised if the loan got fully repaid
This commit is contained in:
committed by
Adam Saghy
parent
3a2f25980f
commit
95ec9eaa37
+2
-2
@@ -104,7 +104,7 @@ public class JournalEntriesApiResource {
|
|||||||
+ "\n" + "journalentries?orderBy=transactionId&sortOrder=DESC\n" + "\n" + "journalentries?runningBalance=true\n" + "\n"
|
+ "\n" + "journalentries?orderBy=transactionId&sortOrder=DESC\n" + "\n" + "journalentries?runningBalance=true\n" + "\n"
|
||||||
+ "journalentries?transactionDetails=true\n" + "\n" + "journalentries?loanId=12\n" + "\n" + "journalentries?savingsId=24")
|
+ "journalentries?transactionDetails=true\n" + "\n" + "journalentries?loanId=12\n" + "\n" + "journalentries?savingsId=24")
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = JournalEntryData.class)))) })
|
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = JournalEntriesApiResourceSwagger.GetJournalEntriesTransactionIdResponse.class)))) })
|
||||||
public String retrieveAll(@Context final UriInfo uriInfo,
|
public String retrieveAll(@Context final UriInfo uriInfo,
|
||||||
@QueryParam("officeId") @Parameter(description = "officeId") final Long officeId,
|
@QueryParam("officeId") @Parameter(description = "officeId") final Long officeId,
|
||||||
@QueryParam("glAccountId") @Parameter(description = "glAccountId") final Long glAccountId,
|
@QueryParam("glAccountId") @Parameter(description = "glAccountId") final Long glAccountId,
|
||||||
@@ -166,7 +166,7 @@ public class JournalEntriesApiResource {
|
|||||||
+ "journalentries/1?fields=officeName,glAccountId,entryType,amount\n" + "\n" + "journalentries/1?runningBalance=true\n" + "\n"
|
+ "journalentries/1?fields=officeName,glAccountId,entryType,amount\n" + "\n" + "journalentries/1?runningBalance=true\n" + "\n"
|
||||||
+ "journalentries/1?transactionDetails=true")
|
+ "journalentries/1?transactionDetails=true")
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = JournalEntryData.class))) })
|
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = JournalEntriesApiResourceSwagger.JournalEntryTransactionItem.class))) })
|
||||||
public String retrieveJournalEntryById(
|
public String retrieveJournalEntryById(
|
||||||
@PathParam("journalEntryId") @Parameter(description = "journalEntryId") final Long journalEntryId,
|
@PathParam("journalEntryId") @Parameter(description = "journalEntryId") final Long journalEntryId,
|
||||||
@Context final UriInfo uriInfo,
|
@Context final UriInfo uriInfo,
|
||||||
|
|||||||
+114
@@ -19,6 +19,12 @@
|
|||||||
package org.apache.fineract.accounting.journalentry.api;
|
package org.apache.fineract.accounting.journalentry.api;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.fineract.organisation.monetary.api.CurrenciesApiResourceSwagger.CurrencyItem;
|
||||||
|
import org.apache.fineract.portfolio.note.api.NotesApiResourceSwagger.GetResourceTypeResourceIdNotesResponse;
|
||||||
|
import org.apache.fineract.portfolio.paymenttype.api.PaymentTypeApiResourceSwagger.GetPaymentTypesResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sanyam on 25/7/17.
|
* Created by sanyam on 25/7/17.
|
||||||
@@ -62,4 +68,112 @@ final class JournalEntriesApiResourceSwagger {
|
|||||||
@Schema(description = "1")
|
@Schema(description = "1")
|
||||||
public Long officeId;
|
public Long officeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final class EnumOptionType {
|
||||||
|
|
||||||
|
private EnumOptionType() {}
|
||||||
|
|
||||||
|
@Schema(example = "2")
|
||||||
|
public Long id;
|
||||||
|
@Schema(example = "accountType.asset")
|
||||||
|
public String code;
|
||||||
|
@Schema(example = "ASSET")
|
||||||
|
public String value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class JournalEntryTransactionItem {
|
||||||
|
|
||||||
|
private JournalEntryTransactionItem() {}
|
||||||
|
|
||||||
|
static final class PaymentDetailData {
|
||||||
|
|
||||||
|
private PaymentDetailData() {}
|
||||||
|
|
||||||
|
@Schema(example = "62")
|
||||||
|
public Long id;
|
||||||
|
public GetPaymentTypesResponse paymentType;
|
||||||
|
@Schema(example = "acc123")
|
||||||
|
public String accountNumber;
|
||||||
|
@Schema(example = "che123")
|
||||||
|
public String checkNumber;
|
||||||
|
@Schema(example = "rou123")
|
||||||
|
public String routingCode;
|
||||||
|
@Schema(example = "rec123")
|
||||||
|
public String receiptNumber;
|
||||||
|
@Schema(example = "ban123")
|
||||||
|
public String bankNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class TransactionDetails {
|
||||||
|
|
||||||
|
private TransactionDetails() {}
|
||||||
|
|
||||||
|
@Schema(example = "2")
|
||||||
|
public Long transactionId;
|
||||||
|
public EnumOptionType transactionType;
|
||||||
|
public GetResourceTypeResourceIdNotesResponse noteData;
|
||||||
|
public PaymentDetailData paymentDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Long id;
|
||||||
|
@Schema(example = "L12")
|
||||||
|
public String transactionId;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Long entityId;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Long officeId;
|
||||||
|
@Schema(example = "Head Office")
|
||||||
|
public String officeName;
|
||||||
|
@Schema(example = "10")
|
||||||
|
public Long glAccountId;
|
||||||
|
@Schema(example = "Cash Account")
|
||||||
|
public String glAccountName;
|
||||||
|
@Schema(example = "0123-4567")
|
||||||
|
public String glAccountCode;
|
||||||
|
@Schema(example = "[2022, 07, 01]")
|
||||||
|
public LocalDate transactionDate;
|
||||||
|
@Schema(example = "[2022, 07, 01]")
|
||||||
|
public LocalDate submittedOnDate;
|
||||||
|
|
||||||
|
@Schema(example = "100.000000")
|
||||||
|
public Double amount;
|
||||||
|
@Schema(example = "false")
|
||||||
|
public boolean reversed;
|
||||||
|
@Schema(example = "false")
|
||||||
|
public boolean manualEntry;
|
||||||
|
@Schema(example = "Manual entry")
|
||||||
|
public String comments;
|
||||||
|
@Schema(example = "QWERTY")
|
||||||
|
public String referenceNumber;
|
||||||
|
@Schema(example = "1234.56")
|
||||||
|
public BigDecimal officeRunningBalance;
|
||||||
|
@Schema(example = "1234.56")
|
||||||
|
public BigDecimal organizationRunningBalance;
|
||||||
|
@Schema(example = "false")
|
||||||
|
public boolean runningBalanceComputed;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Long createdByUserId;
|
||||||
|
@Schema(example = "mifos")
|
||||||
|
public String createdByUserName;
|
||||||
|
@Schema(example = "[2022, 07, 01]")
|
||||||
|
public LocalDate createdDate;
|
||||||
|
|
||||||
|
public CurrencyItem currency;
|
||||||
|
public EnumOptionType glAccountType;
|
||||||
|
public EnumOptionType entryType;
|
||||||
|
public EnumOptionType entityType;
|
||||||
|
public TransactionDetails transactionDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Schema(description = "GetJournalEntriesTransactionIdResponse")
|
||||||
|
public static final class GetJournalEntriesTransactionIdResponse {
|
||||||
|
|
||||||
|
private GetJournalEntriesTransactionIdResponse() {}
|
||||||
|
|
||||||
|
@Schema(example = "2")
|
||||||
|
public Long totalFilteredRecords;
|
||||||
|
public List<JournalEntryTransactionItem> pageItems;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-1
@@ -25,12 +25,32 @@ import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
|||||||
/**
|
/**
|
||||||
* Created by sanyam on 14/8/17.
|
* Created by sanyam on 14/8/17.
|
||||||
*/
|
*/
|
||||||
final class CurrenciesApiResourceSwagger {
|
public final class CurrenciesApiResourceSwagger {
|
||||||
|
|
||||||
private CurrenciesApiResourceSwagger() {
|
private CurrenciesApiResourceSwagger() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class CurrencyItem {
|
||||||
|
|
||||||
|
private CurrencyItem() {}
|
||||||
|
|
||||||
|
@Schema(example = "USD")
|
||||||
|
public String code;
|
||||||
|
@Schema(example = "US Dollar")
|
||||||
|
public String name;
|
||||||
|
@Schema(example = "2")
|
||||||
|
public Integer decimalPlaces;
|
||||||
|
@Schema(example = "100")
|
||||||
|
public Integer inMultiplesOf;
|
||||||
|
@Schema(example = "$")
|
||||||
|
public String displaySymbol;
|
||||||
|
@Schema(example = "currency.USD")
|
||||||
|
public String nameCode;
|
||||||
|
@Schema(example = "US Dollar ($)")
|
||||||
|
public String displayLabel;
|
||||||
|
}
|
||||||
|
|
||||||
@Schema(description = "GetCurrenciesResponse")
|
@Schema(description = "GetCurrenciesResponse")
|
||||||
public static final class GetCurrenciesResponse {
|
public static final class GetCurrenciesResponse {
|
||||||
|
|
||||||
|
|||||||
+44
-11
@@ -3447,10 +3447,10 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isAllChargesPaid) {
|
if (isAllChargesPaid) {
|
||||||
loanLifecycleStateMachine.transition(LoanEvent.REPAID_IN_FULL, this);
|
|
||||||
|
|
||||||
this.closedOnDate = transactionDate;
|
this.closedOnDate = transactionDate;
|
||||||
this.actualMaturityDate = transactionDate;
|
this.actualMaturityDate = transactionDate;
|
||||||
|
loanLifecycleStateMachine.transition(LoanEvent.REPAID_IN_FULL, this);
|
||||||
|
|
||||||
} else if (LoanStatus.fromInt(this.loanStatus).isOverpaid()) {
|
} else if (LoanStatus.fromInt(this.loanStatus).isOverpaid()) {
|
||||||
if (this.totalOverpaid == null || BigDecimal.ZERO.compareTo(this.totalOverpaid) == 0) {
|
if (this.totalOverpaid == null || BigDecimal.ZERO.compareTo(this.totalOverpaid) == 0) {
|
||||||
this.overpaidOnDate = null;
|
this.overpaidOnDate = null;
|
||||||
@@ -3506,6 +3506,39 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
updateLoanOutstandingBalances();
|
updateLoanOutstandingBalances();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void applyIncomeAccrualTransaction(LocalDate closedDate) {
|
||||||
|
ExternalId externalId = ExternalId.empty();
|
||||||
|
boolean isExternalIdAutoGenerationEnabled = TemporaryConfigurationServiceContainer.isExternalIdAutoGenerationEnabled();
|
||||||
|
if (isPeriodicAccrualAccountingEnabledOnLoanProduct()) {
|
||||||
|
List<LoanTransaction> updatedAccrualTransactions = retrieveListOfAccrualTransactions();
|
||||||
|
LocalDate lastAccruedDate = this.getDisbursementDate();
|
||||||
|
if (!updatedAccrualTransactions.isEmpty()) {
|
||||||
|
lastAccruedDate = updatedAccrualTransactions.get(updatedAccrualTransactions.size() - 1).getTransactionDate();
|
||||||
|
}
|
||||||
|
HashMap<String, Object> feeDetails = new HashMap<>();
|
||||||
|
determineFeeDetails(lastAccruedDate, closedDate, feeDetails);
|
||||||
|
if (isExternalIdAutoGenerationEnabled) {
|
||||||
|
externalId = ExternalId.generate();
|
||||||
|
}
|
||||||
|
BigDecimal fee = (BigDecimal) feeDetails.get(FEE);
|
||||||
|
if (fee == null) {
|
||||||
|
fee = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
BigDecimal penalty = (BigDecimal) feeDetails.get(PENALTIES);
|
||||||
|
if (penalty == null) {
|
||||||
|
penalty = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
BigDecimal total = fee.add(penalty);
|
||||||
|
// TODO: calculate interest?
|
||||||
|
if (total.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
LoanTransaction accrualTransaction = LoanTransaction.accrueTransaction(this, this.getOffice(), closedDate, total, null, fee,
|
||||||
|
penalty, externalId);
|
||||||
|
updateLoanChargesPaidBy(accrualTransaction, feeDetails, null);
|
||||||
|
addLoanTransaction(accrualTransaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void determineCumulativeIncomeFromInstallments(HashMap<String, BigDecimal> cumulativeIncomeFromInstallments) {
|
private void determineCumulativeIncomeFromInstallments(HashMap<String, BigDecimal> cumulativeIncomeFromInstallments) {
|
||||||
BigDecimal interest = BigDecimal.ZERO;
|
BigDecimal interest = BigDecimal.ZERO;
|
||||||
BigDecimal fee = BigDecimal.ZERO;
|
BigDecimal fee = BigDecimal.ZERO;
|
||||||
@@ -3797,6 +3830,10 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
|
|
||||||
validateAccountStatus(LoanEvent.WRITE_OFF_OUTSTANDING);
|
validateAccountStatus(LoanEvent.WRITE_OFF_OUTSTANDING);
|
||||||
|
|
||||||
|
final LocalDate writtenOffOnLocalDate = command.localDateValueOfParameterNamed(TRANSACTION_DATE);
|
||||||
|
this.closedOnDate = writtenOffOnLocalDate;
|
||||||
|
this.writtenOffOnDate = writtenOffOnLocalDate;
|
||||||
|
this.closedBy = currentUser;
|
||||||
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.WRITE_OFF_OUTSTANDING, this);
|
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.WRITE_OFF_OUTSTANDING, this);
|
||||||
|
|
||||||
LoanTransaction loanTransaction = null;
|
LoanTransaction loanTransaction = null;
|
||||||
@@ -3807,7 +3844,6 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
existingTransactionIds.addAll(findExistingTransactionIds());
|
existingTransactionIds.addAll(findExistingTransactionIds());
|
||||||
existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
|
existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
|
||||||
|
|
||||||
final LocalDate writtenOffOnLocalDate = command.localDateValueOfParameterNamed(TRANSACTION_DATE);
|
|
||||||
final String txnExternalId = command.stringValueOfParameterNamedAllowingNull(EXTERNAL_ID);
|
final String txnExternalId = command.stringValueOfParameterNamedAllowingNull(EXTERNAL_ID);
|
||||||
|
|
||||||
ExternalId externalId = ExternalIdFactory.produce(txnExternalId);
|
ExternalId externalId = ExternalIdFactory.produce(txnExternalId);
|
||||||
@@ -3816,9 +3852,6 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
externalId = ExternalId.generate();
|
externalId = ExternalId.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.closedOnDate = writtenOffOnLocalDate;
|
|
||||||
this.writtenOffOnDate = writtenOffOnLocalDate;
|
|
||||||
this.closedBy = currentUser;
|
|
||||||
changes.put(CLOSED_ON_DATE, command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
changes.put(CLOSED_ON_DATE, command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
||||||
changes.put(WRITTEN_OFF_ON_DATE, command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
changes.put(WRITTEN_OFF_ON_DATE, command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
||||||
changes.put("externalId", externalId);
|
changes.put("externalId", externalId);
|
||||||
@@ -3934,12 +3967,12 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
final Money totalOutstanding = this.summary.getTotalOutstanding(loanCurrency());
|
final Money totalOutstanding = this.summary.getTotalOutstanding(loanCurrency());
|
||||||
if (totalOutstanding.isGreaterThanZero() && getInArrearsTolerance().isGreaterThanOrEqualTo(totalOutstanding)) {
|
if (totalOutstanding.isGreaterThanZero() && getInArrearsTolerance().isGreaterThanOrEqualTo(totalOutstanding)) {
|
||||||
|
|
||||||
|
this.closedOnDate = closureDate;
|
||||||
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.REPAID_IN_FULL, this);
|
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.REPAID_IN_FULL, this);
|
||||||
if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
|
if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
|
||||||
loanLifecycleStateMachine.transition(LoanEvent.REPAID_IN_FULL, this);
|
loanLifecycleStateMachine.transition(LoanEvent.REPAID_IN_FULL, this);
|
||||||
changes.put(PARAM_STATUS, LoanEnumerations.status(this.loanStatus));
|
changes.put(PARAM_STATUS, LoanEnumerations.status(this.loanStatus));
|
||||||
}
|
}
|
||||||
this.closedOnDate = closureDate;
|
|
||||||
changes.put("externalId", externalId);
|
changes.put("externalId", externalId);
|
||||||
loanTransaction = LoanTransaction.writeoff(this, getOffice(), closureDate, externalId);
|
loanTransaction = LoanTransaction.writeoff(this, getOffice(), closureDate, externalId);
|
||||||
final boolean isLastTransaction = isChronologicallyLatestTransaction(loanTransaction, getLoanTransactions());
|
final boolean isLastTransaction = isChronologicallyLatestTransaction(loanTransaction, getLoanTransactions());
|
||||||
@@ -3965,14 +3998,13 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
final Money totalLoanOverpayment = calculateTotalOverpayment();
|
final Money totalLoanOverpayment = calculateTotalOverpayment();
|
||||||
if (totalLoanOverpayment.isGreaterThanZero() && getInArrearsTolerance().isGreaterThanOrEqualTo(totalLoanOverpayment)) {
|
if (totalLoanOverpayment.isGreaterThanZero() && getInArrearsTolerance().isGreaterThanOrEqualTo(totalLoanOverpayment)) {
|
||||||
// TODO - KW - technically should set somewhere that this loan
|
// TODO - KW - technically should set somewhere that this loan
|
||||||
// has
|
// has 'overpaid' amount
|
||||||
// 'overpaid' amount
|
this.closedOnDate = closureDate;
|
||||||
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.REPAID_IN_FULL, this);
|
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.REPAID_IN_FULL, this);
|
||||||
if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
|
if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
|
||||||
loanLifecycleStateMachine.transition(LoanEvent.REPAID_IN_FULL, this);
|
loanLifecycleStateMachine.transition(LoanEvent.REPAID_IN_FULL, this);
|
||||||
changes.put(PARAM_STATUS, LoanEnumerations.status(this.loanStatus));
|
changes.put(PARAM_STATUS, LoanEnumerations.status(this.loanStatus));
|
||||||
}
|
}
|
||||||
this.closedOnDate = closureDate;
|
|
||||||
} else if (totalLoanOverpayment.isGreaterThanZero()) {
|
} else if (totalLoanOverpayment.isGreaterThanZero()) {
|
||||||
final String errorMessage = "The loan is marked as 'Overpaid' and cannot be moved to 'Closed (obligations met).";
|
final String errorMessage = "The loan is marked as 'Overpaid' and cannot be moved to 'Closed (obligations met).";
|
||||||
throw new InvalidLoanStateTransitionException("close", "loan.is.overpaid", errorMessage, totalLoanOverpayment.toString());
|
throw new InvalidLoanStateTransitionException("close", "loan.is.overpaid", errorMessage, totalLoanOverpayment.toString());
|
||||||
@@ -3995,13 +4027,13 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
|
|
||||||
final LocalDate rescheduledOn = command.localDateValueOfParameterNamed(TRANSACTION_DATE);
|
final LocalDate rescheduledOn = command.localDateValueOfParameterNamed(TRANSACTION_DATE);
|
||||||
|
|
||||||
|
this.closedOnDate = rescheduledOn;
|
||||||
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.LOAN_RESCHEDULE, this);
|
final LoanStatus statusEnum = loanLifecycleStateMachine.dryTransition(LoanEvent.LOAN_RESCHEDULE, this);
|
||||||
if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
|
if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
|
||||||
loanLifecycleStateMachine.transition(LoanEvent.LOAN_RESCHEDULE, this);
|
loanLifecycleStateMachine.transition(LoanEvent.LOAN_RESCHEDULE, this);
|
||||||
changes.put(PARAM_STATUS, LoanEnumerations.status(this.loanStatus));
|
changes.put(PARAM_STATUS, LoanEnumerations.status(this.loanStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.closedOnDate = rescheduledOn;
|
|
||||||
this.rescheduledOnDate = rescheduledOn;
|
this.rescheduledOnDate = rescheduledOn;
|
||||||
changes.put(CLOSED_ON_DATE, command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
changes.put(CLOSED_ON_DATE, command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
||||||
changes.put("rescheduledOnDate", command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
changes.put("rescheduledOnDate", command.stringValueOfParameterNamed(TRANSACTION_DATE));
|
||||||
@@ -6121,6 +6153,7 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
|
|||||||
|
|
||||||
if (this.totalOverpaid == null || BigDecimal.ZERO.compareTo(this.totalOverpaid) == 0) {
|
if (this.totalOverpaid == null || BigDecimal.ZERO.compareTo(this.totalOverpaid) == 0) {
|
||||||
this.overpaidOnDate = null;
|
this.overpaidOnDate = null;
|
||||||
|
this.closedOnDate = newCreditBalanceRefundTransaction.getTransactionDate();
|
||||||
defaultLoanLifecycleStateMachine.transition(LoanEvent.LOAN_CREDIT_BALANCE_REFUND, this);
|
defaultLoanLifecycleStateMachine.transition(LoanEvent.LOAN_CREDIT_BALANCE_REFUND, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.loanaccount.service;
|
||||||
|
|
||||||
|
public interface LoanStatusChangePlatformService {}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.loanaccount.service;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.BusinessEventListener;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanStatusChangedBusinessEvent;
|
||||||
|
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||||
|
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class LoanStatusChangePlatformServiceImpl implements LoanStatusChangePlatformService {
|
||||||
|
|
||||||
|
private final BusinessEventNotifierService businessEventNotifierService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void addListeners() {
|
||||||
|
businessEventNotifierService.addPostBusinessEventListener(LoanStatusChangedBusinessEvent.class, new LoanStatusChangedListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LoanStatusChangedListener implements BusinessEventListener<LoanStatusChangedBusinessEvent> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBusinessEvent(LoanStatusChangedBusinessEvent event) {
|
||||||
|
final Loan loan = event.get();
|
||||||
|
log.debug("Loan Status change for loan {}", loan.getId());
|
||||||
|
// Apply common actions on Loan account closed
|
||||||
|
if (loan.isClosed()) {
|
||||||
|
log.debug("Loan Status {} for loan {}", loan.getStatus().getCode(), loan.getId());
|
||||||
|
loan.applyIncomeAccrualTransaction(loan.getClosedOnDate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-98
@@ -1039,110 +1039,30 @@ final class LoanProductsApiResourceSwagger {
|
|||||||
|
|
||||||
private GetLoanAccountingMappings() {}
|
private GetLoanAccountingMappings() {}
|
||||||
|
|
||||||
static final class GetLoanFundSourceAccount {
|
static final class GetGlAccountMapping {
|
||||||
|
|
||||||
private GetLoanFundSourceAccount() {}
|
private GetGlAccountMapping() {}
|
||||||
|
|
||||||
@Schema(example = "1")
|
|
||||||
public Long id;
|
|
||||||
@Schema(example = "fund source")
|
|
||||||
public String name;
|
|
||||||
@Schema(example = "01")
|
|
||||||
public Integer glCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GetLoanPortfolioAccount {
|
|
||||||
|
|
||||||
private GetLoanPortfolioAccount() {}
|
|
||||||
|
|
||||||
@Schema(example = "2")
|
|
||||||
public Long id;
|
|
||||||
@Schema(example = "Loan portfolio")
|
|
||||||
public String name;
|
|
||||||
@Schema(example = "02")
|
|
||||||
public Integer glCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GetLoanTransfersInSuspenseAccount {
|
|
||||||
|
|
||||||
private GetLoanTransfersInSuspenseAccount() {}
|
|
||||||
|
|
||||||
@Schema(example = "3")
|
|
||||||
public Long id;
|
|
||||||
@Schema(example = "transfers")
|
|
||||||
public String name;
|
|
||||||
@Schema(example = "03")
|
|
||||||
public Integer glCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GetLoanInterestOnLoanAccount {
|
|
||||||
|
|
||||||
private GetLoanInterestOnLoanAccount() {}
|
|
||||||
|
|
||||||
@Schema(example = "4")
|
|
||||||
public Long id;
|
|
||||||
@Schema(example = "income from interest")
|
|
||||||
public String name;
|
|
||||||
@Schema(example = "04")
|
|
||||||
public Integer glCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GetLoanIncomeFromFeeAccount {
|
|
||||||
|
|
||||||
private GetLoanIncomeFromFeeAccount() {}
|
|
||||||
|
|
||||||
@Schema(example = "8")
|
|
||||||
public Long id;
|
|
||||||
@Schema(example = "income from fees 2")
|
|
||||||
public String name;
|
|
||||||
@Schema(example = "10")
|
|
||||||
public Integer glCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GetLoanIncomeFromPenaltyAccount {
|
|
||||||
|
|
||||||
private GetLoanIncomeFromPenaltyAccount() {}
|
|
||||||
|
|
||||||
@Schema(example = "9")
|
|
||||||
public Long id;
|
|
||||||
@Schema(example = "income from penalities 2")
|
|
||||||
public String name;
|
|
||||||
@Schema(example = "11")
|
|
||||||
public Integer glCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GetLoanWriteOffAccount {
|
|
||||||
|
|
||||||
private GetLoanWriteOffAccount() {}
|
|
||||||
|
|
||||||
@Schema(example = "10")
|
@Schema(example = "10")
|
||||||
public Long id;
|
public Long id;
|
||||||
@Schema(example = "loans written off 2")
|
@Schema(example = "Cash Account")
|
||||||
public String name;
|
public String name;
|
||||||
@Schema(example = "12")
|
@Schema(example = "012-34-65")
|
||||||
public Integer glCode;
|
public String glCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class GetLoanOverpaymentLiabilityAccount {
|
public GetGlAccountMapping fundSourceAccount;
|
||||||
|
public GetGlAccountMapping loanPortfolioAccount;
|
||||||
private GetLoanOverpaymentLiabilityAccount() {}
|
public GetGlAccountMapping transfersInSuspenseAccount;
|
||||||
|
public GetGlAccountMapping receivableInterestAccount;
|
||||||
@Schema(example = "11")
|
public GetGlAccountMapping receivablePenaltyAccount;
|
||||||
public Long id;
|
public GetGlAccountMapping interestOnLoanAccount;
|
||||||
@Schema(example = "over payment")
|
public GetGlAccountMapping incomeFromFeeAccount;
|
||||||
public String name;
|
public GetGlAccountMapping incomeFromPenaltyAccount;
|
||||||
@Schema(example = "13")
|
public GetGlAccountMapping incomeFromRecoveryAccount;
|
||||||
public Integer glCode;
|
public GetGlAccountMapping writeOffAccount;
|
||||||
}
|
public GetGlAccountMapping goodwillCreditAccount;
|
||||||
|
public GetGlAccountMapping overpaymentLiabilityAccount;
|
||||||
public GetLoanFundSourceAccount fundSourceAccount;
|
|
||||||
public GetLoanPortfolioAccount loanPortfolioAccount;
|
|
||||||
public GetLoanTransfersInSuspenseAccount transfersInSuspenseAccount;
|
|
||||||
public GetLoanInterestOnLoanAccount interestOnLoanAccount;
|
|
||||||
public GetLoanIncomeFromFeeAccount incomeFromFeeAccount;
|
|
||||||
public GetLoanIncomeFromPenaltyAccount incomeFromPenaltyAccount;
|
|
||||||
public GetLoanWriteOffAccount writeOffAccount;
|
|
||||||
public GetLoanOverpaymentLiabilityAccount overpaymentLiabilityAccount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class GetLoanPaymentChannelToFundSourceMappings {
|
static final class GetLoanPaymentChannelToFundSourceMappings {
|
||||||
@@ -1174,7 +1094,7 @@ final class LoanProductsApiResourceSwagger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GetLoanCharge charge;
|
public GetLoanCharge charge;
|
||||||
public GetLoanAccountingMappings.GetLoanIncomeFromFeeAccount incomeAccount;
|
public GetLoanAccountingMappings.GetGlAccountMapping incomeAccount;
|
||||||
@Schema(example = "10")
|
@Schema(example = "10")
|
||||||
public Long chargeId;
|
public Long chargeId;
|
||||||
@Schema(example = "39")
|
@Schema(example = "39")
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ import java.time.ZonedDateTime;
|
|||||||
/**
|
/**
|
||||||
* Created by Chirag Gupta on 12/29/17.
|
* Created by Chirag Gupta on 12/29/17.
|
||||||
*/
|
*/
|
||||||
final class NotesApiResourceSwagger {
|
public final class NotesApiResourceSwagger {
|
||||||
|
|
||||||
private NotesApiResourceSwagger() {}
|
private NotesApiResourceSwagger() {}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
/**
|
/**
|
||||||
* Created by Chirag Gupta on 01/01/18.
|
* Created by Chirag Gupta on 01/01/18.
|
||||||
*/
|
*/
|
||||||
final class PaymentTypeApiResourceSwagger {
|
public final class PaymentTypeApiResourceSwagger {
|
||||||
|
|
||||||
private PaymentTypeApiResourceSwagger() {}
|
private PaymentTypeApiResourceSwagger() {}
|
||||||
|
|
||||||
|
|||||||
+166
-7
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.integrationtests;
|
package org.apache.fineract.integrationtests;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import io.restassured.builder.RequestSpecBuilder;
|
import io.restassured.builder.RequestSpecBuilder;
|
||||||
@@ -27,15 +28,25 @@ import io.restassured.specification.RequestSpecification;
|
|||||||
import io.restassured.specification.ResponseSpecification;
|
import io.restassured.specification.ResponseSpecification;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
|
||||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||||
|
import org.apache.fineract.client.models.JournalEntryTransactionItem;
|
||||||
import org.apache.fineract.client.models.PostChargesResponse;
|
import org.apache.fineract.client.models.PostChargesResponse;
|
||||||
import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdResponse;
|
import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdResponse;
|
||||||
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
|
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
|
||||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
|
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
|
||||||
|
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||||
|
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
|
||||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||||
import org.apache.fineract.integrationtests.common.Utils;
|
import org.apache.fineract.integrationtests.common.Utils;
|
||||||
|
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||||
|
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.accounting.JournalEntryHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.accounting.PeriodicAccrualAccountingHelper;
|
||||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||||
@@ -49,6 +60,10 @@ public class LoanChargeSpecificDueDateTest {
|
|||||||
private ResponseSpecification responseSpec;
|
private ResponseSpecification responseSpec;
|
||||||
private RequestSpecification requestSpec;
|
private RequestSpecification requestSpec;
|
||||||
private LoanTransactionHelper loanTransactionHelper;
|
private LoanTransactionHelper loanTransactionHelper;
|
||||||
|
private PeriodicAccrualAccountingHelper periodicAccrualAccountingHelper;
|
||||||
|
private AccountHelper accountHelper;
|
||||||
|
private JournalEntryHelper journalEntryHelper;
|
||||||
|
|
||||||
private static final String principalAmount = "1000.00";
|
private static final String principalAmount = "1000.00";
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@@ -60,6 +75,9 @@ public class LoanChargeSpecificDueDateTest {
|
|||||||
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
|
|
||||||
loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||||
|
periodicAccrualAccountingHelper = new PeriodicAccrualAccountingHelper(this.requestSpec, this.responseSpec);
|
||||||
|
accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||||
|
journalEntryHelper = new JournalEntryHelper(this.requestSpec, this.responseSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -79,7 +97,7 @@ public class LoanChargeSpecificDueDateTest {
|
|||||||
|
|
||||||
// Create Loan Account
|
// Create Loan Account
|
||||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
getLoanProductsProductResponse.getId().toString(), operationDate, "12", "0");
|
||||||
|
|
||||||
// Get loan details
|
// Get loan details
|
||||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
@@ -132,7 +150,7 @@ public class LoanChargeSpecificDueDateTest {
|
|||||||
|
|
||||||
// Create Loan Account
|
// Create Loan Account
|
||||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
getLoanProductsProductResponse.getId().toString(), operationDate, "12", "0");
|
||||||
|
|
||||||
// Get loan details
|
// Get loan details
|
||||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
@@ -187,7 +205,7 @@ public class LoanChargeSpecificDueDateTest {
|
|||||||
|
|
||||||
// Create Loan Account
|
// Create Loan Account
|
||||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
getLoanProductsProductResponse.getId().toString(), operationDate, "12", "0");
|
||||||
|
|
||||||
// Get loan details
|
// Get loan details
|
||||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
@@ -233,6 +251,132 @@ public class LoanChargeSpecificDueDateTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplyFeeAccrualOnClosedDate() {
|
||||||
|
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
|
||||||
|
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||||
|
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, todaysDate);
|
||||||
|
|
||||||
|
// Client and Loan account creation
|
||||||
|
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||||
|
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProductWithPeriodicAccrual(loanTransactionHelper,
|
||||||
|
null);
|
||||||
|
assertNotNull(getLoanProductsProductResponse);
|
||||||
|
|
||||||
|
LocalDate transactionDate = LocalDate.of(Utils.getLocalDateOfTenant().getYear(), 1, 1);
|
||||||
|
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||||
|
log.info("Disbursement date {}", transactionDate);
|
||||||
|
|
||||||
|
// Create Loan Account
|
||||||
|
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||||
|
getLoanProductsProductResponse.getId().toString(), operationDate, "1", "0");
|
||||||
|
|
||||||
|
// Get loan details
|
||||||
|
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
|
validateLoanAccount(getLoansLoanIdResponse, Double.valueOf(principalAmount), Double.valueOf("0.00"), true);
|
||||||
|
|
||||||
|
// Apply Loan Charge with specific due date
|
||||||
|
String feeAmount = "10.00";
|
||||||
|
String payloadJSON = ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, feeAmount, true);
|
||||||
|
final PostChargesResponse postChargesResponse = ChargesHelper.createLoanCharge(requestSpec, responseSpec, payloadJSON);
|
||||||
|
assertNotNull(postChargesResponse);
|
||||||
|
final Long chargeId = postChargesResponse.getResourceId();
|
||||||
|
assertNotNull(chargeId);
|
||||||
|
|
||||||
|
// First Loan Charge
|
||||||
|
transactionDate = transactionDate.plusDays(1);
|
||||||
|
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, transactionDate);
|
||||||
|
operationDate = Utils.dateFormatter.format(transactionDate);
|
||||||
|
log.info("Operation date {}", transactionDate);
|
||||||
|
payloadJSON = LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(), operationDate, feeAmount);
|
||||||
|
PostLoansLoanIdChargesResponse postLoansLoanIdChargesResponse = loanTransactionHelper.addChargeForLoan(loanId, payloadJSON,
|
||||||
|
responseSpec);
|
||||||
|
assertNotNull(postLoansLoanIdChargesResponse);
|
||||||
|
final Long loanChargeId01 = postLoansLoanIdChargesResponse.getResourceId();
|
||||||
|
assertNotNull(loanChargeId01);
|
||||||
|
|
||||||
|
// Run Accruals
|
||||||
|
log.info("Running Periodic Accrual for date {}", transactionDate);
|
||||||
|
periodicAccrualAccountingHelper.runPeriodicAccrualAccounting(operationDate);
|
||||||
|
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
|
loanTransactionHelper.evaluateLoanTransactionData(getLoansLoanIdResponse, "loanTransactionType.accrual", Double.valueOf("10.00"));
|
||||||
|
|
||||||
|
// Repay the first charge fully, 10
|
||||||
|
Float amount = Float.valueOf("10.00");
|
||||||
|
transactionDate = transactionDate.plusDays(40);
|
||||||
|
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, transactionDate);
|
||||||
|
operationDate = Utils.dateFormatter.format(transactionDate);
|
||||||
|
log.info("Operation date {}", transactionDate);
|
||||||
|
PostLoansLoanIdTransactionsResponse loanIdTransactionsResponse = loanTransactionHelper.makeLoanRepayment(operationDate, amount,
|
||||||
|
loanId);
|
||||||
|
assertNotNull(loanIdTransactionsResponse);
|
||||||
|
log.info("Loan Transaction Id: {} {}", loanId, loanIdTransactionsResponse.getResourceId());
|
||||||
|
|
||||||
|
// Second Loan Charge
|
||||||
|
feeAmount = "15.00";
|
||||||
|
transactionDate = transactionDate.plusDays(1);
|
||||||
|
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, transactionDate);
|
||||||
|
operationDate = Utils.dateFormatter.format(transactionDate);
|
||||||
|
log.info("Operation date {}", transactionDate);
|
||||||
|
payloadJSON = LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(), operationDate, feeAmount);
|
||||||
|
postLoansLoanIdChargesResponse = loanTransactionHelper.addChargeForLoan(loanId, payloadJSON, responseSpec);
|
||||||
|
assertNotNull(postLoansLoanIdChargesResponse);
|
||||||
|
final Long loanChargeId02 = postLoansLoanIdChargesResponse.getResourceId();
|
||||||
|
assertNotNull(loanChargeId02);
|
||||||
|
|
||||||
|
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
|
validateLoanAccount(getLoansLoanIdResponse, Double.valueOf(principalAmount), Double.valueOf("15.00"), true);
|
||||||
|
|
||||||
|
// Run Accruals
|
||||||
|
log.info("Running Periodic Accrual for date {}", transactionDate);
|
||||||
|
periodicAccrualAccountingHelper.runPeriodicAccrualAccounting(operationDate);
|
||||||
|
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
|
loanTransactionHelper.evaluateLoanTransactionData(getLoansLoanIdResponse, "loanTransactionType.accrual", Double.valueOf("25.00"));
|
||||||
|
|
||||||
|
// Third Loan Charge
|
||||||
|
feeAmount = "25.00";
|
||||||
|
transactionDate = transactionDate.plusDays(1);
|
||||||
|
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, transactionDate);
|
||||||
|
operationDate = Utils.dateFormatter.format(transactionDate);
|
||||||
|
log.info("Operation date {}", transactionDate);
|
||||||
|
payloadJSON = LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(), operationDate, feeAmount);
|
||||||
|
postLoansLoanIdChargesResponse = loanTransactionHelper.addChargeForLoan(loanId, payloadJSON, responseSpec);
|
||||||
|
assertNotNull(postLoansLoanIdChargesResponse);
|
||||||
|
final Long loanChargeId03 = postLoansLoanIdChargesResponse.getResourceId();
|
||||||
|
assertNotNull(loanChargeId03);
|
||||||
|
|
||||||
|
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
|
validateLoanAccount(getLoansLoanIdResponse, Double.valueOf(principalAmount), Double.valueOf("40.00"), true);
|
||||||
|
loanTransactionHelper.evaluateLoanTransactionData(getLoansLoanIdResponse, "loanTransactionType.accrual", Double.valueOf("25.00"));
|
||||||
|
|
||||||
|
amount = Float.valueOf("1040.00");
|
||||||
|
loanIdTransactionsResponse = loanTransactionHelper.makeLoanRepayment(operationDate, amount, loanId);
|
||||||
|
assertNotNull(loanIdTransactionsResponse);
|
||||||
|
log.info("Loan Transaction Id: {} {}", loanId, loanIdTransactionsResponse.getResourceId());
|
||||||
|
|
||||||
|
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||||
|
assertNotNull(getLoansLoanIdResponse);
|
||||||
|
loanTransactionHelper.validateLoanStatus(getLoansLoanIdResponse, "loanStatusType.closed.obligations.met");
|
||||||
|
loanTransactionHelper.evaluateLoanTransactionData(getLoansLoanIdResponse, "loanTransactionType.accrual", Double.valueOf("50.00"));
|
||||||
|
|
||||||
|
final Long transactionId = loanTransactionHelper.evaluateLastLoanTransactionData(getLoansLoanIdResponse,
|
||||||
|
"loanTransactionType.accrual", operationDate, Double.valueOf("25.00"));
|
||||||
|
assertNotNull(transactionId);
|
||||||
|
log.info("transactionId {}", transactionId);
|
||||||
|
|
||||||
|
final GetJournalEntriesTransactionIdResponse journalEntriesResponse = journalEntryHelper
|
||||||
|
.getJournalEntries("L" + transactionId.toString());
|
||||||
|
assertNotNull(journalEntriesResponse);
|
||||||
|
final List<JournalEntryTransactionItem> journalEntries = journalEntriesResponse.getPageItems();
|
||||||
|
assertEquals(2, journalEntries.size());
|
||||||
|
assertEquals(25, journalEntries.get(0).getAmount());
|
||||||
|
assertEquals(25, journalEntries.get(1).getAmount());
|
||||||
|
assertEquals(transactionDate, journalEntries.get(0).getTransactionDate());
|
||||||
|
assertEquals(transactionDate, journalEntries.get(1).getTransactionDate());
|
||||||
|
|
||||||
|
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
||||||
final Integer delinquencyBucketId) {
|
final Integer delinquencyBucketId) {
|
||||||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
||||||
@@ -240,12 +384,27 @@ public class LoanChargeSpecificDueDateTest {
|
|||||||
return loanTransactionHelper.getLoanProduct(loanProductId);
|
return loanTransactionHelper.getLoanProduct(loanProductId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GetLoanProductsProductIdResponse createLoanProductWithPeriodicAccrual(final LoanTransactionHelper loanTransactionHelper,
|
||||||
|
final Integer delinquencyBucketId) {
|
||||||
|
final Account assetAccount = this.accountHelper.createAssetAccount();
|
||||||
|
final Account assetFeeAndPenaltyAccount = this.accountHelper.createAssetAccount();
|
||||||
|
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
||||||
|
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
||||||
|
final Account overpaymentAccount = this.accountHelper.createLiabilityAccount();
|
||||||
|
|
||||||
|
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder()
|
||||||
|
.withAccountingRulePeriodicAccrual(new Account[] { assetAccount, incomeAccount, expenseAccount, overpaymentAccount })
|
||||||
|
.build(null, delinquencyBucketId);
|
||||||
|
final Integer loanProductId = loanTransactionHelper.getLoanProductId(Utils.convertToJson(loanProductMap));
|
||||||
|
return loanTransactionHelper.getLoanProduct(loanProductId);
|
||||||
|
}
|
||||||
|
|
||||||
private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
|
private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
|
||||||
final String operationDate) {
|
final String operationDate, final String repayments, final String interestRate) {
|
||||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(principalAmount).withLoanTermFrequency("12")
|
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(principalAmount).withLoanTermFrequency(repayments)
|
||||||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("12").withRepaymentEveryAfter("1")
|
.withLoanTermFrequencyAsMonths().withNumberOfRepayments(repayments).withRepaymentEveryAfter("1")
|
||||||
.withRepaymentFrequencyTypeAsMonths() //
|
.withRepaymentFrequencyTypeAsMonths() //
|
||||||
.withInterestRatePerPeriod("0") //
|
.withInterestRatePerPeriod(interestRate) //
|
||||||
.withExpectedDisbursementDate(operationDate) //
|
.withExpectedDisbursementDate(operationDate) //
|
||||||
.withInterestTypeAsDecliningBalance() //
|
.withInterestTypeAsDecliningBalance() //
|
||||||
.withSubmittedOnDate(operationDate) //
|
.withSubmittedOnDate(operationDate) //
|
||||||
|
|||||||
+14
@@ -20,18 +20,24 @@ package org.apache.fineract.integrationtests.common.accounting;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import io.restassured.specification.RequestSpecification;
|
import io.restassured.specification.RequestSpecification;
|
||||||
import io.restassured.specification.ResponseSpecification;
|
import io.restassured.specification.ResponseSpecification;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
|
||||||
|
import org.apache.fineract.client.util.JSON;
|
||||||
import org.apache.fineract.integrationtests.common.Utils;
|
import org.apache.fineract.integrationtests.common.Utils;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class JournalEntryHelper {
|
public class JournalEntryHelper {
|
||||||
|
|
||||||
private final RequestSpecification requestSpec;
|
private final RequestSpecification requestSpec;
|
||||||
private final ResponseSpecification responseSpec;
|
private final ResponseSpecification responseSpec;
|
||||||
|
private static final Gson GSON = new JSON().getGson();
|
||||||
|
|
||||||
public JournalEntryHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
public JournalEntryHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||||
this.requestSpec = requestSpec;
|
this.requestSpec = requestSpec;
|
||||||
@@ -104,4 +110,12 @@ public class JournalEntryHelper {
|
|||||||
+ "&orderBy=id&sortOrder=desc&locale=en&dateFormat=dd MMMM yyyy");
|
+ "&orderBy=id&sortOrder=desc&locale=en&dateFormat=dd MMMM yyyy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GetJournalEntriesTransactionIdResponse getJournalEntries(final String transactionId) {
|
||||||
|
log.info("Getting GL Journal entries for transaction id {}", transactionId);
|
||||||
|
final String url = createURLForGettingAccountEntriesByTransactionId(transactionId);
|
||||||
|
final String response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, null);
|
||||||
|
log.info("response {}", response);
|
||||||
|
return GSON.fromJson(response, GetJournalEntriesTransactionIdResponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+32
@@ -55,6 +55,7 @@ import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
|
|||||||
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentSchedule;
|
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentSchedule;
|
||||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||||
import org.apache.fineract.client.models.GetLoansLoanIdSummary;
|
import org.apache.fineract.client.models.GetLoansLoanIdSummary;
|
||||||
|
import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
|
||||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTemplateResponse;
|
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTemplateResponse;
|
||||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
|
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
|
||||||
import org.apache.fineract.client.models.GetPaymentTypesResponse;
|
import org.apache.fineract.client.models.GetPaymentTypesResponse;
|
||||||
@@ -1580,6 +1581,37 @@ public class LoanTransactionHelper extends IntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void evaluateLoanTransactionData(GetLoansLoanIdResponse getLoansLoanIdResponse, String transactionType, Double amountExpected) {
|
||||||
|
List<GetLoansLoanIdTransactions> transactions = getLoansLoanIdResponse.getTransactions();
|
||||||
|
log.info("Loan with {} transactions", transactions.size());
|
||||||
|
Double transactionsAmount = 0.0;
|
||||||
|
for (GetLoansLoanIdTransactions transaction : transactions) {
|
||||||
|
log.info(" Id {} code {} date {} amount {}", transaction.getId(), transaction.getType().getCode(), transaction.getDate(),
|
||||||
|
transaction.getAmount());
|
||||||
|
if (transactionType.equals(transaction.getType().getCode())) {
|
||||||
|
transactionsAmount += transaction.getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(amountExpected, transactionsAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long evaluateLastLoanTransactionData(GetLoansLoanIdResponse getLoansLoanIdResponse, String transactionType,
|
||||||
|
String transactionExpected, Double amountExpected) {
|
||||||
|
List<GetLoansLoanIdTransactions> transactions = getLoansLoanIdResponse.getTransactions();
|
||||||
|
log.info("Loan with {} transactions", transactions.size());
|
||||||
|
GetLoansLoanIdTransactions lastTransaction = null;
|
||||||
|
for (GetLoansLoanIdTransactions transaction : transactions) {
|
||||||
|
log.info(" Id {} code {} date {} amount {}", transaction.getId(), transaction.getType().getCode(), transaction.getDate(),
|
||||||
|
transaction.getAmount());
|
||||||
|
if (transactionType.equals(transaction.getType().getCode())) {
|
||||||
|
lastTransaction = transaction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(transactionExpected, Utils.dateFormatter.format(lastTransaction.getDate()));
|
||||||
|
assertEquals(amountExpected, lastTransaction.getAmount());
|
||||||
|
return lastTransaction.getId();
|
||||||
|
}
|
||||||
|
|
||||||
public void validateLoanStatus(GetLoansLoanIdResponse getLoansLoanIdResponse, final String statusCodeExpected) {
|
public void validateLoanStatus(GetLoansLoanIdResponse getLoansLoanIdResponse, final String statusCodeExpected) {
|
||||||
final String statusCode = getLoansLoanIdResponse.getStatus().getCode();
|
final String statusCode = getLoansLoanIdResponse.getStatus().getCode();
|
||||||
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
|
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
|
||||||
|
|||||||
Reference in New Issue
Block a user