Refactor Loan Transaction to support auditable fields
This commit is contained in:
committed by
Arnold Gálovics
parent
176c5700d0
commit
35cc1fc0d6
+6
@@ -20,6 +20,7 @@ package org.apache.fineract.infrastructure.core.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -73,6 +74,11 @@ public final class DateUtils {
|
||||
return LocalDateTime.now(zone).truncatedTo(ChronoUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static OffsetDateTime getOffsetDateTimeOfTenant() {
|
||||
final ZoneId zone = getDateTimeZoneOfTenant();
|
||||
return OffsetDateTime.now(zone).truncatedTo(ChronoUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static LocalDateTime getLocalDateTimeOfSystem() {
|
||||
return LocalDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.SECONDS);
|
||||
}
|
||||
|
||||
+4
-4
@@ -19,7 +19,7 @@
|
||||
package org.apache.fineract.portfolio.collateralmanagement.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
public final class LoanTransactionData {
|
||||
|
||||
@@ -29,9 +29,9 @@ public final class LoanTransactionData {
|
||||
|
||||
private final Long loanId;
|
||||
|
||||
private final LocalDateTime lastRepaymentDate;
|
||||
private final OffsetDateTime lastRepaymentDate;
|
||||
|
||||
private LoanTransactionData(final Long loanId, final LocalDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
||||
private LoanTransactionData(final Long loanId, final OffsetDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
||||
final BigDecimal lastRepayment) {
|
||||
this.lastRepayment = lastRepayment;
|
||||
this.lastRepaymentDate = lastRepaymentDate;
|
||||
@@ -39,7 +39,7 @@ public final class LoanTransactionData {
|
||||
this.loanId = loanId;
|
||||
}
|
||||
|
||||
public static LoanTransactionData instance(final Long loanId, final LocalDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
||||
public static LoanTransactionData instance(final Long loanId, final OffsetDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
||||
final BigDecimal lastRepayment) {
|
||||
return new LoanTransactionData(loanId, lastRepaymentDate, remainingAmount, lastRepayment);
|
||||
}
|
||||
|
||||
+9
-5
@@ -20,7 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -37,7 +37,7 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||
@@ -56,7 +56,7 @@ import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "m_loan_transaction", uniqueConstraints = { @UniqueConstraint(columnNames = { "external_id" }, name = "external_id_UNIQUE") })
|
||||
public class LoanTransaction extends AbstractAuditableCustom {
|
||||
public class LoanTransaction extends AbstractAuditableWithUTCDateTimeCustom {
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "loan_id", nullable = false)
|
||||
@@ -726,8 +726,8 @@ public class LoanTransaction extends AbstractAuditableCustom {
|
||||
this.manuallyAdjustedOrReversed = true;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedDateTime() {
|
||||
return (this.getCreatedDate().isPresent() ? this.getCreatedDate().get() : DateUtils.getLocalDateTimeOfTenant());
|
||||
public OffsetDateTime getCreatedDateTime() {
|
||||
return (this.getCreatedDate().isPresent() ? this.getCreatedDate().get() : DateUtils.getOffsetDateTimeOfTenant());
|
||||
}
|
||||
|
||||
public boolean isLastTransaction(final LoanTransaction loanTransaction) {
|
||||
@@ -808,6 +808,10 @@ public class LoanTransaction extends AbstractAuditableCustom {
|
||||
return this.loanCollateralManagementSet;
|
||||
}
|
||||
|
||||
public LocalDate getSubmittedOnDate() {
|
||||
return submittedOnDate;
|
||||
}
|
||||
|
||||
// TODO missing hashCode(), equals(Object obj), but probably OK as long as
|
||||
// this is never stored in a Collection.
|
||||
}
|
||||
|
||||
+1
-2
@@ -676,8 +676,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
+ " left join m_loan_arrears_aging la on la.loan_id = l.id" //
|
||||
+ " left join m_fund f on f.id = l.fund_id" //
|
||||
+ " left join m_staff s on s.id = l.loan_officer_id" //
|
||||
+ " left join m_appuser sbu on sbu.id = l.submittedon_userid"
|
||||
+ " left join m_appuser rbu on rbu.id = l.rejectedon_userid"
|
||||
+ " left join m_appuser sbu on sbu.id = l.created_by" + " left join m_appuser rbu on rbu.id = l.rejectedon_userid"
|
||||
+ " left join m_appuser wbu on wbu.id = l.withdrawnon_userid"
|
||||
+ " left join m_appuser abu on abu.id = l.approvedon_userid"
|
||||
+ " left join m_appuser dbu on dbu.id = l.disbursedon_userid" + " left join m_appuser cbu on cbu.id = l.closedon_userid"
|
||||
|
||||
+1
-3
@@ -23,7 +23,6 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -3302,8 +3301,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
private void validateTransactionsForTransfer(final Loan loan, final LocalDate transferDate) {
|
||||
|
||||
for (LoanTransaction transaction : loan.getLoanTransactions()) {
|
||||
if ((transaction.getTransactionDate().isEqual(transferDate)
|
||||
&& transaction.getCreatedDateTime().isEqual(transferDate.atStartOfDay(ZoneId.systemDefault()).toLocalDateTime()))
|
||||
if ((transaction.getTransactionDate().isEqual(transferDate) && transaction.getSubmittedOnDate().isEqual(transferDate))
|
||||
|| transaction.getTransactionDate().isAfter(transferDate)) {
|
||||
throw new GeneralPlatformDomainRuleException(TransferApiConstants.transferClientLoanException,
|
||||
TransferApiConstants.transferClientLoanExceptionMessage, transaction.getCreatedDateTime().toLocalDate(),
|
||||
|
||||
+6
-6
@@ -38,10 +38,10 @@ public final class TransferApiConstants {
|
||||
public static final String destinationOfficeIdParamName = "destinationOfficeId";
|
||||
public static final String note = "note";
|
||||
public static final String transferDate = "transferDate";
|
||||
public static final String transferClientLoanException = "error.msg.caanot.transfer.client.as.loan.transaction.present.on.or.after.transfer.date";
|
||||
public static final String transferClientLoanExceptionMessage = "error msg caanot transfer client as loan transaction present on or after transfer date";
|
||||
public static final String transferClientSavingsException = "error.msg.caanot.transfer.client.as.savings.transaction.present.on.or.after.transfer.date";
|
||||
public static final String transferClientSavingsExceptionMessage = "error msg caanot transfer client as savings transaction present on or after transfer date";
|
||||
public static final String transferClientToSameOfficeException = "error.msg.cannot.transfer.clinet.as.selected.office.and.current.office.are.same";
|
||||
public static final String transferClientToSameOfficeExceptionMessage = "error.msg.cannot.transfer.clinet.as.selected.office.and.current.office.are.same";
|
||||
public static final String transferClientLoanException = "error.msg.cannot.transfer.client.as.loan.transaction.present.on.or.after.transfer.date";
|
||||
public static final String transferClientLoanExceptionMessage = "error msg cannot transfer client as loan transaction present on or after transfer date";
|
||||
public static final String transferClientSavingsException = "error.msg.cannot.transfer.client.as.savings.transaction.present.on.or.after.transfer.date";
|
||||
public static final String transferClientSavingsExceptionMessage = "error msg cannot transfer client as savings transaction present on or after transfer date";
|
||||
public static final String transferClientToSameOfficeException = "error.msg.cannot.transfer.client.as.selected.office.and.current.office.are.same";
|
||||
public static final String transferClientToSameOfficeExceptionMessage = "error.msg.cannot.transfer.client.as.selected.office.and.current.office.are.same";
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,11 +22,11 @@
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
||||
<changeSet author="fineract" id="1" onValidationFail="MARK_RAN">
|
||||
<changeSet author="fineract" id="1">
|
||||
<validCheckSum>8:4500ffb68c695d72caba498deff75643</validCheckSum>
|
||||
<addColumn tableName="m_loan_transaction">
|
||||
<column name="createdby_id" type="BIGINT" valueComputed="appuser_id"/>
|
||||
<column name="lastmodifiedby_id" type="BIGINT"/>
|
||||
<column name="lastmodified_date" type="DATETIME"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
<changeSet id="2" author="fineract">
|
||||
|
||||
Reference in New Issue
Block a user