MIFOSX-866 changes for returing transaction type associated with a journal entry

This commit is contained in:
Vishwas Babu A J
2014-01-16 12:23:48 +05:30
parent 5441f29b84
commit 74a058a6b1
5 changed files with 147 additions and 103 deletions
@@ -15,7 +15,7 @@ public class TransactionDetailData {
private final NoteData noteData; private final NoteData noteData;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String transactionType; private final TransactionTypeEnumData transactionType;
public TransactionDetailData(final Long transactionId, final PaymentDetailData paymentDetails, final NoteData noteData) { public TransactionDetailData(final Long transactionId, final PaymentDetailData paymentDetails, final NoteData noteData) {
this.transactionId = transactionId; this.transactionId = transactionId;
@@ -25,7 +25,8 @@ public class TransactionDetailData {
} }
public TransactionDetailData(final Long transactionId, final PaymentDetailData paymentDetails, final NoteData noteData,final String transactionType) { public TransactionDetailData(final Long transactionId, final PaymentDetailData paymentDetails, final NoteData noteData,
final TransactionTypeEnumData transactionType) {
this.transactionId = transactionId; this.transactionId = transactionId;
this.paymentDetails = paymentDetails; this.paymentDetails = paymentDetails;
this.noteData = noteData; this.noteData = noteData;
@@ -0,0 +1,28 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.journalentry.data;
/**
* Immutable data object represent loan and Savings status enumerations.
*/
@SuppressWarnings("unused")
public class TransactionTypeEnumData {
private final Long id;
private final String code;
private final String value;
public TransactionTypeEnumData(final Long id, final String code, final String value) {
this.id = id;
this.code = code;
this.value = value;
}
public Long id() {
return this.id;
}
}
@@ -5,7 +5,6 @@
*/ */
package org.mifosplatform.accounting.journalentry.service; package org.mifosplatform.accounting.journalentry.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@@ -20,6 +19,7 @@ import org.mifosplatform.accounting.common.AccountingEnumerations;
import org.mifosplatform.accounting.journalentry.data.JournalEntryAssociationParametersData; import org.mifosplatform.accounting.journalentry.data.JournalEntryAssociationParametersData;
import org.mifosplatform.accounting.journalentry.data.JournalEntryData; import org.mifosplatform.accounting.journalentry.data.JournalEntryData;
import org.mifosplatform.accounting.journalentry.data.TransactionDetailData; import org.mifosplatform.accounting.journalentry.data.TransactionDetailData;
import org.mifosplatform.accounting.journalentry.data.TransactionTypeEnumData;
import org.mifosplatform.accounting.journalentry.exception.JournalEntriesNotFoundException; import org.mifosplatform.accounting.journalentry.exception.JournalEntriesNotFoundException;
import org.mifosplatform.infrastructure.codes.data.CodeValueData; import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.data.EnumOptionData;
@@ -29,8 +29,12 @@ import org.mifosplatform.infrastructure.core.service.PaginationHelper;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.portfolio.group.service.SearchParameters; import org.mifosplatform.portfolio.group.service.SearchParameters;
import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionEnumData;
import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations;
import org.mifosplatform.portfolio.note.data.NoteData; import org.mifosplatform.portfolio.note.data.NoteData;
import org.mifosplatform.portfolio.paymentdetail.data.PaymentDetailData; import org.mifosplatform.portfolio.paymentdetail.data.PaymentDetailData;
import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionEnumData;
import org.mifosplatform.portfolio.savings.service.SavingsEnumerations;
import org.mifosplatform.portfolio.account.PortfolioAccountType; import org.mifosplatform.portfolio.account.PortfolioAccountType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
@@ -52,13 +56,12 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
private static final class GLJournalEntryMapper implements RowMapper<JournalEntryData> { private static final class GLJournalEntryMapper implements RowMapper<JournalEntryData> {
private final JournalEntryAssociationParametersData associationParametersData;
private final JournalEntryAssociationParametersData associationParametersData ; public GLJournalEntryMapper(final JournalEntryAssociationParametersData associationParametersData) {
if (associationParametersData == null) {
public GLJournalEntryMapper(final JournalEntryAssociationParametersData associationParametersData ) {
if(associationParametersData == null){
this.associationParametersData = new JournalEntryAssociationParametersData(); this.associationParametersData = new JournalEntryAssociationParametersData();
}else{ } else {
this.associationParametersData = associationParametersData; this.associationParametersData = associationParametersData;
} }
} }
@@ -76,34 +79,27 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
.append(" journalEntry.created_date as createdDate, journalEntry.reversed as reversed, ") .append(" journalEntry.created_date as createdDate, journalEntry.reversed as reversed, ")
.append(" journalEntry.currency_code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ") .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 "); .append(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf ");
if(associationParametersData.isRunningBalanceRequired()){ if (associationParametersData.isRunningBalanceRequired()) {
sb.append(" ,journalEntry.is_running_balance_caculated as runningBalanceComputed, ") sb.append(" ,journalEntry.is_running_balance_caculated as runningBalanceComputed, ")
.append(" journalEntry.office_running_balance as officeRunningBalance, ") .append(" journalEntry.office_running_balance as officeRunningBalance, ")
.append(" journalEntry.organization_running_balance as organizationRunningBalance "); .append(" journalEntry.organization_running_balance as organizationRunningBalance ");
} }
if(associationParametersData.isTransactionDetailsRequired()){ if (associationParametersData.isTransactionDetailsRequired()) {
sb.append(" ,pd.receipt_number as receiptNumber, ") sb.append(" ,pd.receipt_number as receiptNumber, ").append(" pd.check_number as checkNumber, ")
.append(" pd.check_number as checkNumber, ") .append(" pd.account_number as accountNumber, ").append(" cdv.code_value as paymentTypeName, ")
.append(" pd.account_number as accountNumber, ") .append(" pd.payment_type_cv_id as paymentTypeId,").append(" pd.bank_number as bankNumber, ")
.append(" cdv.code_value as paymentTypeName, ") .append(" pd.routing_code as routingCode, ").append(" note.id as noteId, ")
.append(" pd.payment_type_cv_id as paymentTypeId,") .append(" note.note as transactionNote, ").append(" lt.transaction_type_enum as loanTransactionType, ")
.append(" pd.bank_number as bankNumber, ") .append(" st.transaction_type_enum as savingsTransactionType ");
.append(" pd.routing_code as routingCode, ")
.append(" note.id as noteId, ")
.append(" note.note as transactionNote, ")
.append(" lte.enum_value as loanTransactionType, ")
.append(" ste.enum_value as savingTransactionType ");
} }
sb.append(" from acc_gl_journal_entry as journalEntry ") sb.append(" from acc_gl_journal_entry as journalEntry ")
.append(" left join acc_gl_account as glAccount on glAccount.id = journalEntry.account_id") .append(" left join acc_gl_account as glAccount on glAccount.id = journalEntry.account_id")
.append(" left join m_office as office on office.id = journalEntry.office_id") .append(" left join m_office as office on office.id = journalEntry.office_id")
.append(" left join m_appuser as creatingUser on creatingUser.id = journalEntry.createdby_id ") .append(" left join m_appuser as creatingUser on creatingUser.id = journalEntry.createdby_id ")
.append(" join m_currency curr on curr.code = journalEntry.currency_code "); .append(" join m_currency curr on curr.code = journalEntry.currency_code ");
if(associationParametersData.isTransactionDetailsRequired()){ if (associationParametersData.isTransactionDetailsRequired()) {
sb.append(" left join m_loan_transaction as lt on journalEntry.loan_transaction_id = lt.id ") sb.append(" left join m_loan_transaction as lt on journalEntry.loan_transaction_id = lt.id ")
.append(" left join r_enum_value as lte on ( lt.transaction_type_enum = lte.enum_id and lte.enum_name = 'transaction_type_enum' )")
.append(" left join m_savings_account_transaction as st on journalEntry.savings_transaction_id = st.id ") .append(" left join m_savings_account_transaction as st on journalEntry.savings_transaction_id = st.id ")
.append(" left join r_enum_value as ste on (st.transaction_type_enum = ste.enum_id and ste.enum_name = 'transaction_type_enum' )")
.append(" left join m_payment_detail as pd on lt.payment_detail_id = pd.id or st.payment_detail_id = pd.id") .append(" left join m_payment_detail as pd on lt.payment_detail_id = pd.id or st.payment_detail_id = pd.id")
.append(" left join m_code_value as cdv on cdv.id = pd.payment_type_cv_id ") .append(" left join m_code_value as cdv on cdv.id = pd.payment_type_cv_id ")
.append(" left join m_note as note on lt.id = note.loan_transaction_id or st.id = note.savings_account_transaction_id "); .append(" left join m_note as note on lt.id = note.loan_transaction_id or st.id = note.savings_account_transaction_id ");
@@ -144,8 +140,8 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final Boolean reversed = rs.getBoolean("reversed"); final Boolean reversed = rs.getBoolean("reversed");
final String referenceNumber = rs.getString("referenceNumber"); final String referenceNumber = rs.getString("referenceNumber");
BigDecimal officeRunningBalance = null; BigDecimal officeRunningBalance = null;
BigDecimal organizationRunningBalance =null; BigDecimal organizationRunningBalance = null;
Boolean runningBalanceComputed =null; Boolean runningBalanceComputed = null;
final String currencyCode = rs.getString("currencyCode"); final String currencyCode = rs.getString("currencyCode");
final String currencyName = rs.getString("currencyName"); final String currencyName = rs.getString("currencyName");
@@ -156,14 +152,14 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final CurrencyData currency = new CurrencyData(currencyCode, currencyName, currencyDigits, inMultiplesOf, final CurrencyData currency = new CurrencyData(currencyCode, currencyName, currencyDigits, inMultiplesOf,
currencyDisplaySymbol, currencyNameCode); currencyDisplaySymbol, currencyNameCode);
if(associationParametersData.isRunningBalanceRequired()){ if (associationParametersData.isRunningBalanceRequired()) {
officeRunningBalance = rs.getBigDecimal("officeRunningBalance"); officeRunningBalance = rs.getBigDecimal("officeRunningBalance");
organizationRunningBalance = rs.getBigDecimal("organizationRunningBalance"); organizationRunningBalance = rs.getBigDecimal("organizationRunningBalance");
runningBalanceComputed = rs.getBoolean("runningBalanceComputed"); runningBalanceComputed = rs.getBoolean("runningBalanceComputed");
} }
TransactionDetailData transactionDetailData = null; TransactionDetailData transactionDetailData = null;
if(associationParametersData.isTransactionDetailsRequired()){ if (associationParametersData.isTransactionDetailsRequired()) {
PaymentDetailData paymentDetailData = null; PaymentDetailData paymentDetailData = null;
final Long paymentTypeId = JdbcSupport.getLong(rs, "paymentTypeId"); final Long paymentTypeId = JdbcSupport.getLong(rs, "paymentTypeId");
if (paymentTypeId != null) { if (paymentTypeId != null) {
@@ -177,35 +173,37 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
paymentDetailData = new PaymentDetailData(id, paymentType, accountNumber, checkNumber, routingCode, receiptNumber, paymentDetailData = new PaymentDetailData(id, paymentType, accountNumber, checkNumber, routingCode, receiptNumber,
bankNumber); bankNumber);
} }
NoteData noteData =null; NoteData noteData = null;
final Long noteId = JdbcSupport.getLong(rs, "noteId"); final Long noteId = JdbcSupport.getLong(rs, "noteId");
if(noteId!=null){ if (noteId != null) {
final String note = rs.getString("transactionNote"); final String note = rs.getString("transactionNote");
noteData = new NoteData(noteId, null, null, null, null, null, null, null, note, null, null, null, null, null, null); noteData = new NoteData(noteId, null, null, null, null, null, null, null, note, null, null, null, null, null, null);
} }
Long transaction = null; Long transaction = null;
if(entityType!=null){ if (entityType != null) {
transaction = Long.parseLong(transactionId.substring(1).trim()); transaction = Long.parseLong(transactionId.substring(1).trim());
} }
String transactionType = null; TransactionTypeEnumData transactionTypeEnumData = null;
if (PortfolioAccountType.fromInt(entityTypeId).isLoanAccount()) {
final LoanTransactionEnumData loanTransactionType = LoanEnumerations.transactionType(JdbcSupport.getInteger(rs,
if(PortfolioAccountType.fromInt(entityTypeId).isLoanAccount()) "loanTransactionType"));
{ transactionTypeEnumData = new TransactionTypeEnumData(loanTransactionType.id(), loanTransactionType.getCode(),
transactionType = rs.getString("loanTransactionType"); loanTransactionType.getValue());
} } else if (PortfolioAccountType.fromInt(entityTypeId).isSavingsAccount()) {
else if(PortfolioAccountType.fromInt(entityTypeId).isSavingsAccount()){ final SavingsAccountTransactionEnumData savingsTransactionType = SavingsEnumerations.transactionType(JdbcSupport
.getInteger(rs, "savingsTransactionType"));
transactionType = rs.getString("savingTransactionType"); transactionTypeEnumData = new TransactionTypeEnumData(savingsTransactionType.getId(), savingsTransactionType.getCode(),
savingsTransactionType.getValue());
} }
transactionDetailData = new TransactionDetailData(transaction, paymentDetailData, noteData,transactionType); transactionDetailData = new TransactionDetailData(transaction, paymentDetailData, noteData, transactionTypeEnumData);
} }
return new JournalEntryData(id, officeId, officeName, glAccountName, glAccountId, glCode, accountType, transactionDate, return new JournalEntryData(id, officeId, officeName, glAccountName, glAccountId, glCode, accountType, transactionDate,
entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, createdDate, createdByUserName, entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, createdDate, createdByUserName,
comments, reversed, referenceNumber,officeRunningBalance,organizationRunningBalance,runningBalanceComputed,transactionDetailData, currency); comments, reversed, referenceNumber, officeRunningBalance, organizationRunningBalance, runningBalanceComputed,
transactionDetailData, currency);
} }
} }
@@ -224,37 +222,37 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
String whereClose = " where "; String whereClose = " where ";
if (StringUtils.isNotBlank(transactionId)) { if (StringUtils.isNotBlank(transactionId)) {
sqlBuilder.append(whereClose+" journalEntry.transaction_id = ?"); sqlBuilder.append(whereClose + " journalEntry.transaction_id = ?");
objectArray[arrayPos] = transactionId; objectArray[arrayPos] = transactionId;
arrayPos = arrayPos + 1; arrayPos = arrayPos + 1;
whereClose =" and "; whereClose = " and ";
} }
if (entityType != null && entityType != 0 && (onlyManualEntries == null)) { if (entityType != null && entityType != 0 && (onlyManualEntries == null)) {
sqlBuilder.append(whereClose+" journalEntry.entity_type_enum = ?"); sqlBuilder.append(whereClose + " journalEntry.entity_type_enum = ?");
objectArray[arrayPos] = entityType; objectArray[arrayPos] = entityType;
arrayPos = arrayPos + 1; arrayPos = arrayPos + 1;
whereClose =" and "; whereClose = " and ";
} }
if (searchParameters.isOfficeIdPassed()) { if (searchParameters.isOfficeIdPassed()) {
sqlBuilder.append(whereClose+" journalEntry.office_id = ?"); sqlBuilder.append(whereClose + " journalEntry.office_id = ?");
objectArray[arrayPos] = searchParameters.getOfficeId(); objectArray[arrayPos] = searchParameters.getOfficeId();
arrayPos = arrayPos + 1; arrayPos = arrayPos + 1;
whereClose =" and "; whereClose = " and ";
} }
if (glAccountId != null && glAccountId != 0) { if (glAccountId != null && glAccountId != 0) {
sqlBuilder.append(whereClose+" journalEntry.account_id = ?"); sqlBuilder.append(whereClose + " journalEntry.account_id = ?");
objectArray[arrayPos] = glAccountId; objectArray[arrayPos] = glAccountId;
arrayPos = arrayPos + 1; arrayPos = arrayPos + 1;
whereClose =" and "; whereClose = " and ";
} }
if (fromDate != null || toDate != null) { if (fromDate != null || toDate != null) {
@@ -262,9 +260,9 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
String fromDateString = null; String fromDateString = null;
String toDateString = null; String toDateString = null;
if (fromDate != null && toDate != null) { if (fromDate != null && toDate != null) {
sqlBuilder.append(whereClose+" journalEntry.entry_date between ? and ? "); sqlBuilder.append(whereClose + " journalEntry.entry_date between ? and ? ");
whereClose =" and "; whereClose = " and ";
fromDateString = df.format(fromDate); fromDateString = df.format(fromDate);
toDateString = df.format(toDate); toDateString = df.format(toDate);
@@ -273,27 +271,27 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
objectArray[arrayPos] = toDateString; objectArray[arrayPos] = toDateString;
arrayPos = arrayPos + 1; arrayPos = arrayPos + 1;
} else if (fromDate != null) { } else if (fromDate != null) {
sqlBuilder.append(whereClose+" journalEntry.entry_date >= ? "); sqlBuilder.append(whereClose + " journalEntry.entry_date >= ? ");
fromDateString = df.format(fromDate); fromDateString = df.format(fromDate);
objectArray[arrayPos] = fromDateString; objectArray[arrayPos] = fromDateString;
arrayPos = arrayPos + 1; arrayPos = arrayPos + 1;
whereClose =" and "; whereClose = " and ";
} else if (toDate != null) { } else if (toDate != null) {
sqlBuilder.append(whereClose+" journalEntry.entry_date <= ? "); sqlBuilder.append(whereClose + " journalEntry.entry_date <= ? ");
toDateString = df.format(toDate); toDateString = df.format(toDate);
objectArray[arrayPos] = toDateString; objectArray[arrayPos] = toDateString;
arrayPos = arrayPos + 1; arrayPos = arrayPos + 1;
whereClose =" and "; whereClose = " and ";
} }
} }
if (onlyManualEntries != null) { if (onlyManualEntries != null) {
if (onlyManualEntries) { if (onlyManualEntries) {
sqlBuilder.append(whereClose+" journalEntry.manual_entry = 1"); sqlBuilder.append(whereClose + " journalEntry.manual_entry = 1");
whereClose =" and "; whereClose = " and ";
} }
} }
@@ -303,9 +301,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
if (searchParameters.isSortOrderProvided()) { if (searchParameters.isSortOrderProvided()) {
sqlBuilder.append(' ').append(searchParameters.getSortOrder()); sqlBuilder.append(' ').append(searchParameters.getSortOrder());
} }
} } else {
else
{
sqlBuilder.append(" order by journalEntry.entry_date, journalEntry.id"); sqlBuilder.append(" order by journalEntry.entry_date, journalEntry.id");
} }
@@ -318,12 +314,12 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final Object[] finalObjectArray = Arrays.copyOf(objectArray, arrayPos); final Object[] finalObjectArray = Arrays.copyOf(objectArray, arrayPos);
final String sqlCountRows = "SELECT FOUND_ROWS()"; final String sqlCountRows = "SELECT FOUND_ROWS()";
return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(), finalObjectArray, return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(), finalObjectArray, rm);
rm);
} }
@Override @Override
public JournalEntryData retrieveGLJournalEntryById(final long glJournalEntryId, JournalEntryAssociationParametersData associationParametersData) { public JournalEntryData retrieveGLJournalEntryById(final long glJournalEntryId,
JournalEntryAssociationParametersData associationParametersData) {
try { try {
final GLJournalEntryMapper rm = new GLJournalEntryMapper(associationParametersData); final GLJournalEntryMapper rm = new GLJournalEntryMapper(associationParametersData);
@@ -58,6 +58,14 @@ public class LoanTransactionEnumData {
return this.id; return this.id;
} }
public String getCode() {
return this.code;
}
public String getValue() {
return this.value;
}
/** /**
* Returns true if the transaction involves either a payment (disbursement) * Returns true if the transaction involves either a payment (disbursement)
* or a receipt (repayments, repayments during disbursement etc) * or a receipt (repayments, repayments during disbursement etc)
@@ -11,7 +11,6 @@ import org.mifosplatform.portfolio.savings.SavingsAccountTransactionType;
* Immutable data object represent savings account transaction type * Immutable data object represent savings account transaction type
* enumerations. * enumerations.
*/ */
@SuppressWarnings("unused")
public class SavingsAccountTransactionEnumData { public class SavingsAccountTransactionEnumData {
private final Long id; private final Long id;
@@ -43,6 +42,18 @@ public class SavingsAccountTransactionEnumData {
this.rejectTransfer = Long.valueOf(SavingsAccountTransactionType.REJECT_TRANSFER.getValue()).equals(this.id); this.rejectTransfer = Long.valueOf(SavingsAccountTransactionType.REJECT_TRANSFER.getValue()).equals(this.id);
} }
public Long getId() {
return this.id;
}
public String getCode() {
return this.code;
}
public String getValue() {
return this.value;
}
public boolean isDeposit() { public boolean isDeposit() {
return this.deposit; return this.deposit;
} }