FINERACT-1681: Filter Journal entry by submitted on date

This commit is contained in:
Adam Saghy
2022-08-05 13:54:05 +02:00
committed by Arnold Gálovics
parent 4685e96c81
commit 7b55951a3a
4 changed files with 96 additions and 153 deletions
@@ -79,10 +79,10 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class JournalEntriesApiResource {
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(
Arrays.asList("id", "officeId", "officeName", "glAccountName", "glAccountId", "glAccountCode", "glAccountType",
"transactionDate", "entryType", "amount", "transactionId", "manualEntry", "entityType", "entityId", "createdByUserId",
"createdDate", "createdByUserName", "comments", "reversed", "referenceNumber", "currency", "transactionDetails"));
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "officeId", "officeName", "glAccountName",
"glAccountId", "glAccountCode", "glAccountType", "transactionDate", "entryType", "amount", "transactionId", "manualEntry",
"entityType", "entityId", "createdByUserId", "createdDate", "submittedOnDate", "createdByUserName", "comments", "reversed",
"referenceNumber", "currency", "transactionDetails"));
private final String resourceNameForPermission = "JOURNALENTRY";
@@ -111,6 +111,8 @@ public class JournalEntriesApiResource {
@QueryParam("manualEntriesOnly") @Parameter(description = "manualEntriesOnly") final Boolean onlyManualEntries,
@QueryParam("fromDate") @Parameter(description = "fromDate") final DateParam fromDateParam,
@QueryParam("toDate") @Parameter(description = "toDate") final DateParam toDateParam,
@QueryParam("submittedOnDateFrom") @Parameter(description = "submittedOnDateFrom") final DateParam submittedOnDateFromParam,
@QueryParam("submittedOnDateTo") @Parameter(description = "submittedOnDateTo") final DateParam submittedOnDateToParam,
@QueryParam("transactionId") @Parameter(description = "transactionId") final String transactionId,
@QueryParam("entityType") @Parameter(description = "entityType") final Integer entityType,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@@ -135,13 +137,23 @@ public class JournalEntriesApiResource {
toDate = toDateParam.getDate("toDate", dateFormat, locale);
}
LocalDate submittedOnDateFrom = null;
if (submittedOnDateFromParam != null) {
submittedOnDateFrom = submittedOnDateFromParam.getDate("submittedOnDateFrom", dateFormat, locale);
}
LocalDate submittedOnDateTo = null;
if (submittedOnDateToParam != null) {
submittedOnDateTo = submittedOnDateToParam.getDate("submittedOnDateTo", dateFormat, locale);
}
final SearchParameters searchParameters = SearchParameters.forJournalEntries(officeId, offset, limit, orderBy, sortOrder, loanId,
savingsId);
JournalEntryAssociationParametersData associationParametersData = new JournalEntryAssociationParametersData(transactionDetails,
runningBalance);
final Page<JournalEntryData> glJournalEntries = this.journalEntryReadPlatformService.retrieveAll(searchParameters, glAccountId,
onlyManualEntries, fromDate, toDate, transactionId, entityType, associationParametersData);
onlyManualEntries, fromDate, toDate, submittedOnDateFrom, submittedOnDateTo, transactionId, entityType,
associationParametersData);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.apiJsonSerializerService.serialize(settings, glJournalEntries, RESPONSE_DATA_PARAMETERS);
}
@@ -234,8 +246,8 @@ public class JournalEntriesApiResource {
this.context.authenticatedUser();
String transactionId = "P" + entryId;
SearchParameters params = SearchParameters.forPagination(offset, limit);
Page<JournalEntryData> entries = this.journalEntryReadPlatformService.retrieveAll(params, null, null, null, null, transactionId,
PortfolioProductType.PROVISIONING.getValue(), null);
Page<JournalEntryData> entries = this.journalEntryReadPlatformService.retrieveAll(params, null, null, null, null, null, null,
transactionId, PortfolioProductType.PROVISIONING.getValue(), null);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.apiJsonSerializerService.serialize(settings, entries, RESPONSE_DATA_PARAMETERS);
}
@@ -21,6 +21,7 @@ package org.apache.fineract.accounting.journalentry.data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import lombok.Getter;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
@@ -30,6 +31,7 @@ import org.apache.fineract.organisation.monetary.data.CurrencyData;
*
* Note: no getter/setters required as google will produce json from fields of object.
*/
@Getter
public class JournalEntryData {
private final Long id;
@@ -76,6 +78,8 @@ public class JournalEntryData {
@SuppressWarnings("unused")
private final TransactionDetailData transactionDetails;
@SuppressWarnings("unused")
private final LocalDate submittedOnDate;
// import fields
private transient Integer rowIndex;
@@ -132,6 +136,7 @@ public class JournalEntryData {
this.organizationRunningBalance = null;
this.runningBalanceComputed = null;
this.transactionDetails = null;
this.submittedOnDate = null;
}
public static JournalEntryData importInstance(Long officeId, LocalDate transactionDate, String currencyCode, Long paymentTypeId,
@@ -179,6 +184,7 @@ public class JournalEntryData {
this.entityType = null;
this.entityId = null;
this.createdByUserId = null;
this.submittedOnDate = null;
this.createdDate = null;
this.createdByUserName = null;
this.reversed = null;
@@ -209,7 +215,7 @@ public class JournalEntryData {
public JournalEntryData(final Long id, final Long officeId, final String officeName, final String glAccountName, final Long glAccountId,
final String glAccountCode, final EnumOptionData glAccountClassification, final LocalDate transactionDate,
final EnumOptionData entryType, final BigDecimal amount, final String transactionId, final Boolean manualEntry,
final EnumOptionData entityType, final Long entityId, final Long createdByUserId, final LocalDate createdDate,
final EnumOptionData entityType, final Long entityId, final Long createdByUserId, final LocalDate submittedOnDate,
final String createdByUserName, final String comments, final Boolean reversed, final String referenceNumber,
final BigDecimal officeRunningBalance, final BigDecimal organizationRunningBalance, final Boolean runningBalanceComputed,
final TransactionDetailData transactionDetailData, final CurrencyData currency) {
@@ -228,7 +234,8 @@ public class JournalEntryData {
this.entityType = entityType;
this.entityId = entityId;
this.createdByUserId = createdByUserId;
this.createdDate = createdDate;
this.createdDate = submittedOnDate;
this.submittedOnDate = submittedOnDate;
this.createdByUserName = createdByUserName;
this.comments = comments;
this.reversed = reversed;
@@ -240,40 +247,6 @@ public class JournalEntryData {
this.currency = currency;
}
public JournalEntryData(final Long id, final Long officeId, final String glAccountName, final Long glAccountId,
final String glAccountCode, final EnumOptionData glAccountClassification, final LocalDate transactionDate,
final EnumOptionData entryType, final BigDecimal amount, final String transactionId, final Boolean manualEntry,
final EnumOptionData entityType, final Long entityId, final LocalDate createdDate, final String currencyCode,
final Long savingTransactionId) {
this.id = id;
this.officeId = officeId;
this.officeName = null;
this.glAccountName = glAccountName;
this.glAccountId = glAccountId;
this.glAccountCode = glAccountCode;
this.glAccountType = glAccountClassification;
this.transactionDate = transactionDate;
this.entryType = entryType;
this.amount = amount;
this.transactionId = transactionId;
this.savingTransactionId = savingTransactionId;
this.manualEntry = manualEntry;
this.entityType = entityType;
this.entityId = entityId;
this.createdByUserId = null;
this.createdDate = createdDate;
this.createdByUserName = null;
this.comments = null;
this.reversed = false;
this.referenceNumber = null;
this.officeRunningBalance = null;
this.organizationRunningBalance = null;
this.runningBalanceComputed = null;
this.transactionDetails = null;
this.currency = null;
this.currencyCode = currencyCode;
}
public static JournalEntryData fromGLAccountData(final GLAccountData glAccountData) {
final Long id = null;
@@ -291,7 +264,7 @@ public class JournalEntryData {
final EnumOptionData entityType = null;
final Long entityId = null;
final Long createdByUserId = null;
final LocalDate createdDate = null;
final LocalDate submittedOnDate = null;
final String createdByUserName = null;
final String comments = null;
final Boolean reversed = null;
@@ -302,65 +275,8 @@ public class JournalEntryData {
final TransactionDetailData transactionDetailData = null;
final CurrencyData currency = null;
return new JournalEntryData(id, officeId, officeName, glAccountName, glAccountId, glAccountCode, glAccountClassification,
transactionDate, entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, createdDate,
transactionDate, entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, submittedOnDate,
createdByUserName, comments, reversed, referenceNumber, officeRunningBalance, organizationRunningBalance,
runningBalanceComputed, transactionDetailData, currency);
}
public Long getId() {
return this.id;
}
public Long getGlAccountId() {
return this.glAccountId;
}
public EnumOptionData getGlAccountType() {
return this.glAccountType;
}
public BigDecimal getAmount() {
return this.amount;
}
public EnumOptionData getEntryType() {
return this.entryType;
}
public Long getOfficeId() {
return this.officeId;
}
public String getTransactionId() {
return transactionId;
}
public Long getSavingTransactionId() {
return this.savingTransactionId;
}
public String getCurrencyCode() {
return this.currencyCode;
}
public boolean isManualEntry() {
return this.manualEntry;
}
public EnumOptionData getEntityType() {
return this.entityType;
}
public Long getEntityId() {
return this.entityId;
}
public LocalDate getCreatedDate() {
return this.createdDate;
}
public Long getPaymentTypeId() {
return this.paymentTypeId;
}
}
@@ -30,7 +30,8 @@ public interface JournalEntryReadPlatformService {
JournalEntryData retrieveGLJournalEntryById(long glJournalEntryId, JournalEntryAssociationParametersData associationParametersData);
Page<JournalEntryData> retrieveAll(SearchParameters searchParameters, Long glAccountId, Boolean onlyManualEntries, LocalDate fromDate,
LocalDate toDate, String transactionId, Integer entityType, JournalEntryAssociationParametersData associationParametersData);
LocalDate toDate, LocalDate submittedOnDateFrom, LocalDate submittedOnDateTo, String transactionId, Integer entityType,
JournalEntryAssociationParametersData associationParametersData);
OfficeOpeningBalancesData retrieveOfficeOpeningBalances(Long officeId, String currencyCode);
@@ -22,11 +22,10 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.accounting.common.AccountingEnumerations;
@@ -85,11 +84,8 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
private final JournalEntryAssociationParametersData associationParametersData;
GLJournalEntryMapper(final JournalEntryAssociationParametersData associationParametersData) {
if (associationParametersData == null) {
this.associationParametersData = new JournalEntryAssociationParametersData();
} else {
this.associationParametersData = associationParametersData;
}
this.associationParametersData = Objects.requireNonNullElseGet(associationParametersData,
JournalEntryAssociationParametersData::new);
}
public String schema() {
@@ -101,7 +97,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
.append(" journalEntry.type_enum as entryType,journalEntry.amount as amount, journalEntry.transaction_id as transactionId,")
.append(" journalEntry.entity_type_enum as entityType, journalEntry.entity_id as entityId, creatingUser.id as createdByUserId, ")
.append(" creatingUser.username as createdByUserName, journalEntry.description as comments, ")
.append(" journalEntry.submitted_on_date as createdDate, journalEntry.reversed as reversed, ")
.append(" journalEntry.submitted_on_date as submittedOnDate, journalEntry.reversed as reversed, ")
.append(" journalEntry.currency_code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ")
.append(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf ");
if (associationParametersData.isRunningBalanceRequired()) {
@@ -159,7 +155,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final Long entityId = JdbcSupport.getLong(rs, "entityId");
final Long createdByUserId = rs.getLong("createdByUserId");
final LocalDate createdDate = JdbcSupport.getLocalDate(rs, "createdDate");
final LocalDate submittedOnDate = JdbcSupport.getLocalDate(rs, "submittedOnDate");
final String createdByUserName = rs.getString("createdByUserName");
final String comments = rs.getString("comments");
final Boolean reversed = rs.getBoolean("reversed");
@@ -226,20 +222,21 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
transactionDetailData = new TransactionDetailData(transaction, paymentDetailData, noteData, transactionTypeEnumData);
}
return new JournalEntryData(id, officeId, officeName, glAccountName, glAccountId, glCode, accountType, transactionDate,
entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, createdDate, createdByUserName,
comments, reversed, referenceNumber, officeRunningBalance, organizationRunningBalance, runningBalanceComputed,
transactionDetailData, currency);
entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, submittedOnDate,
createdByUserName, comments, reversed, referenceNumber, officeRunningBalance, organizationRunningBalance,
runningBalanceComputed, transactionDetailData, currency);
}
}
@Override
public Page<JournalEntryData> retrieveAll(final SearchParameters searchParameters, final Long glAccountId,
final Boolean onlyManualEntries, final LocalDate fromDate, final LocalDate toDate, final String transactionId,
final Integer entityType, final JournalEntryAssociationParametersData associationParametersData) {
final Boolean onlyManualEntries, final LocalDate fromDate, final LocalDate toDate, final LocalDate submittedOnDateFrom,
final LocalDate submittedOnDateTo, final String transactionId, final Integer entityType,
final JournalEntryAssociationParametersData associationParametersData) {
GLJournalEntryMapper rm = new GLJournalEntryMapper(associationParametersData);
final StringBuilder sqlBuilder = new StringBuilder(200);
sqlBuilder.append("select " + sqlGenerator.calcFoundRows() + " ");
sqlBuilder.append("select ").append(sqlGenerator.calcFoundRows()).append(" ");
sqlBuilder.append(rm.schema());
final Object[] objectArray = new Object[15];
@@ -247,7 +244,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
String whereClose = " where ";
if (StringUtils.isNotBlank(transactionId)) {
sqlBuilder.append(whereClose + " journalEntry.transaction_id = ?");
sqlBuilder.append(whereClose).append(" journalEntry.transaction_id = ?");
objectArray[arrayPos] = transactionId;
arrayPos = arrayPos + 1;
@@ -256,7 +253,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
if (entityType != null && entityType != 0 && (onlyManualEntries == null)) {
sqlBuilder.append(whereClose + " journalEntry.entity_type_enum = ?");
sqlBuilder.append(whereClose).append(" journalEntry.entity_type_enum = ?");
objectArray[arrayPos] = entityType;
arrayPos = arrayPos + 1;
@@ -265,7 +262,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
}
if (searchParameters.isOfficeIdPassed()) {
sqlBuilder.append(whereClose + " journalEntry.office_id = ?");
sqlBuilder.append(whereClose).append(" journalEntry.office_id = ?");
objectArray[arrayPos] = searchParameters.getOfficeId();
arrayPos = arrayPos + 1;
@@ -273,7 +270,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
}
if (searchParameters.isCurrencyCodePassed()) {
sqlBuilder.append(whereClose + " journalEntry.currency_code = ?");
sqlBuilder.append(whereClose).append(" journalEntry.currency_code = ?");
objectArray[arrayPos] = searchParameters.getCurrencyCode();
arrayPos = arrayPos + 1;
@@ -281,7 +278,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
}
if (glAccountId != null && glAccountId != 0) {
sqlBuilder.append(whereClose + " journalEntry.account_id = ?");
sqlBuilder.append(whereClose).append(" journalEntry.account_id = ?");
objectArray[arrayPos] = glAccountId;
arrayPos = arrayPos + 1;
@@ -289,50 +286,69 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
}
if (fromDate != null || toDate != null) {
final DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd").toFormatter();
String fromDateString = null;
String toDateString = null;
if (fromDate != null && toDate != null) {
fromDateString = df.format(fromDate);
toDateString = df.format(toDate);
sqlBuilder.append(whereClose + " journalEntry.entry_date between '" + fromDateString + "' and '" + toDateString + "' ");
sqlBuilder.append(whereClose).append(" journalEntry.entry_date between ? and ? ");
whereClose = " and ";
objectArray[arrayPos] = fromDate;
arrayPos = arrayPos + 1;
objectArray[arrayPos] = toDate;
arrayPos = arrayPos + 1;
} else if (fromDate != null) {
fromDateString = df.format(fromDate);
sqlBuilder.append(whereClose + " journalEntry.entry_date >= '" + fromDateString + "' ");
sqlBuilder.append(whereClose).append(" journalEntry.entry_date >= ? ");
whereClose = " and ";
} else if (toDate != null) {
toDateString = df.format(toDate);
sqlBuilder.append(whereClose + " journalEntry.entry_date <= '" + toDateString + "' ");
objectArray[arrayPos] = fromDate;
arrayPos = arrayPos + 1;
} else {
sqlBuilder.append(whereClose).append(" journalEntry.entry_date <= ? ");
whereClose = " and ";
objectArray[arrayPos] = toDate;
arrayPos = arrayPos + 1;
}
}
if (submittedOnDateFrom != null || submittedOnDateTo != null) {
if (submittedOnDateFrom != null && toDate != null) {
sqlBuilder.append(whereClose).append(" journalEntry.submitted_on_date between ? and ? ");
whereClose = " and ";
objectArray[arrayPos] = submittedOnDateFrom;
arrayPos = arrayPos + 1;
objectArray[arrayPos] = submittedOnDateTo;
arrayPos = arrayPos + 1;
} else if (fromDate != null) {
sqlBuilder.append(whereClose).append(" journalEntry.submitted_on_date >= ? ");
whereClose = " and ";
objectArray[arrayPos] = submittedOnDateFrom;
arrayPos = arrayPos + 1;
} else {
sqlBuilder.append(whereClose).append(" journalEntry.submitted_on_date <= ? ");
whereClose = " and ";
objectArray[arrayPos] = submittedOnDateTo;
arrayPos = arrayPos + 1;
}
}
if (onlyManualEntries != null) {
if (onlyManualEntries) {
sqlBuilder.append(whereClose + " journalEntry.manual_entry = true");
sqlBuilder.append(whereClose).append(" journalEntry.manual_entry = ?");
whereClose = " and ";
objectArray[arrayPos] = Boolean.TRUE;
arrayPos = arrayPos + 1;
}
}
if (searchParameters.isLoanIdPassed()) {
sqlBuilder.append(whereClose + " journalEntry.loan_transaction_id in (select id from m_loan_transaction where loan_id = ?)");
sqlBuilder.append(whereClose)
.append(" journalEntry.loan_transaction_id in (select id from m_loan_transaction where loan_id = ?)");
objectArray[arrayPos] = searchParameters.getLoanId();
arrayPos = arrayPos + 1;
whereClose = " and ";
}
if (searchParameters.isSavingsIdPassed()) {
sqlBuilder.append(whereClose
+ " journalEntry.savings_transaction_id in (select id from m_savings_account_transaction where savings_account_id = ?)");
sqlBuilder.append(whereClose).append(
" journalEntry.savings_transaction_id in (select id from m_savings_account_transaction where savings_account_id = ?)");
objectArray[arrayPos] = searchParameters.getSavingsId();
arrayPos = arrayPos + 1;
whereClose = " and ";
}
if (searchParameters.isOrderByRequested()) {
@@ -368,9 +384,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final GLJournalEntryMapper rm = new GLJournalEntryMapper(associationParametersData);
final String sql = "select " + rm.schema() + " where journalEntry.id = ?";
final JournalEntryData glJournalEntryData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { glJournalEntryId }); // NOSONAR
return glJournalEntryData;
return this.jdbcTemplate.queryForObject(sql, rm, glJournalEntryId);
} catch (final EmptyResultDataAccessException e) {
throw new JournalEntriesNotFoundException(glJournalEntryId, e);
}
@@ -428,10 +442,8 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final LocalDate transactionDate = DateUtils.getBusinessLocalDate();
final OfficeOpeningBalancesData officeOpeningBalancesData = OfficeOpeningBalancesData.createNew(officeId, officeData.name(),
transactionDate, contraAccount, assetAccountOpeningBalances, liabityAccountOpeningBalances, incomeAccountOpeningBalances,
equityAccountOpeningBalances, expenseAccountOpeningBalances);
return officeOpeningBalancesData;
return OfficeOpeningBalancesData.createNew(officeId, officeData.name(), transactionDate, contraAccount, assetAccountOpeningBalances,
liabityAccountOpeningBalances, incomeAccountOpeningBalances, equityAccountOpeningBalances, expenseAccountOpeningBalances);
}
private List<JournalEntryData> populateOpeningBalances(final List<JournalEntryData> existingOpeningBalanceTransactions,
@@ -493,14 +505,16 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final Boolean onlyManualEntries = null;
final LocalDate fromDate = null;
final LocalDate toDate = null;
final LocalDate submittedOnDateFrom = null;
final LocalDate submittedOnDateTo = null;
final JournalEntryAssociationParametersData associationParametersData = null;
final Long loanId = null;
final Long savingsId = null;
final SearchParameters searchParameters = SearchParameters.forJournalEntries(officeId, offset, limit, orderBy, sortOrder, loanId,
savingsId, currencyCode);
return retrieveAll(searchParameters, contraId, onlyManualEntries, fromDate, toDate, transactionId, entityType,
associationParametersData);
return retrieveAll(searchParameters, contraId, onlyManualEntries, fromDate, toDate, submittedOnDateFrom, submittedOnDateTo,
transactionId, entityType, associationParametersData);
}