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;
@SuppressWarnings("unused")
private final String transactionType;
private final TransactionTypeEnumData transactionType;
public TransactionDetailData(final Long transactionId, final PaymentDetailData paymentDetails, final NoteData noteData) {
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.paymentDetails = paymentDetails;
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;
import java.math.BigDecimal;
import java.sql.ResultSet;
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.JournalEntryData;
import org.mifosplatform.accounting.journalentry.data.TransactionDetailData;
import org.mifosplatform.accounting.journalentry.data.TransactionTypeEnumData;
import org.mifosplatform.accounting.journalentry.exception.JournalEntriesNotFoundException;
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
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.organisation.monetary.data.CurrencyData;
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.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.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
@@ -52,63 +56,55 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
private static final class GLJournalEntryMapper implements RowMapper<JournalEntryData> {
private final JournalEntryAssociationParametersData associationParametersData ;
public GLJournalEntryMapper(final JournalEntryAssociationParametersData associationParametersData ) {
if(associationParametersData == null){
private final JournalEntryAssociationParametersData associationParametersData;
public GLJournalEntryMapper(final JournalEntryAssociationParametersData associationParametersData) {
if (associationParametersData == null) {
this.associationParametersData = new JournalEntryAssociationParametersData();
}else{
} else {
this.associationParametersData = associationParametersData;
}
}
public String schema() {
StringBuilder sb = new StringBuilder();
sb.append(" journalEntry.id as id, glAccount.classification_enum as classification ,")
.append("journalEntry.transaction_id,")
.append(" glAccount.name as glAccountName, glAccount.gl_code as glAccountCode,glAccount.id as glAccountId, ")
.append(" journalEntry.office_id as officeId, office.name as officeName, journalEntry.ref_num as referenceNumber, ")
.append(" journalEntry.manual_entry as manualEntry,journalEntry.entry_date as transactionDate, ")
.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.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(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf ");
if(associationParametersData.isRunningBalanceRequired()){
sb.append(" ,journalEntry.is_running_balance_caculated as runningBalanceComputed, ")
.append(" journalEntry.office_running_balance as officeRunningBalance, ")
.append(" journalEntry.organization_running_balance as organizationRunningBalance ");
}
if(associationParametersData.isTransactionDetailsRequired()){
sb.append(" ,pd.receipt_number as receiptNumber, ")
.append(" pd.check_number as checkNumber, ")
.append(" pd.account_number as accountNumber, ")
.append(" cdv.code_value as paymentTypeName, ")
.append(" pd.payment_type_cv_id as paymentTypeId,")
.append(" pd.bank_number as bankNumber, ")
.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 ")
.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_appuser as creatingUser on creatingUser.id = journalEntry.createdby_id ")
.append(" join m_currency curr on curr.code = journalEntry.currency_code ");
if(associationParametersData.isTransactionDetailsRequired()){
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 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_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 ");
}
return sb.toString();
sb.append(" journalEntry.id as id, glAccount.classification_enum as classification ,")
.append("journalEntry.transaction_id,")
.append(" glAccount.name as glAccountName, glAccount.gl_code as glAccountCode,glAccount.id as glAccountId, ")
.append(" journalEntry.office_id as officeId, office.name as officeName, journalEntry.ref_num as referenceNumber, ")
.append(" journalEntry.manual_entry as manualEntry,journalEntry.entry_date as transactionDate, ")
.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.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(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf ");
if (associationParametersData.isRunningBalanceRequired()) {
sb.append(" ,journalEntry.is_running_balance_caculated as runningBalanceComputed, ")
.append(" journalEntry.office_running_balance as officeRunningBalance, ")
.append(" journalEntry.organization_running_balance as organizationRunningBalance ");
}
if (associationParametersData.isTransactionDetailsRequired()) {
sb.append(" ,pd.receipt_number as receiptNumber, ").append(" pd.check_number as checkNumber, ")
.append(" pd.account_number as accountNumber, ").append(" cdv.code_value as paymentTypeName, ")
.append(" pd.payment_type_cv_id as paymentTypeId,").append(" pd.bank_number as bankNumber, ")
.append(" pd.routing_code as routingCode, ").append(" note.id as noteId, ")
.append(" note.note as transactionNote, ").append(" lt.transaction_type_enum as loanTransactionType, ")
.append(" st.transaction_type_enum as savingsTransactionType ");
}
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 m_office as office on office.id = journalEntry.office_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 ");
if (associationParametersData.isTransactionDetailsRequired()) {
sb.append(" left join m_loan_transaction as lt on journalEntry.loan_transaction_id = lt.id ")
.append(" left join m_savings_account_transaction as st on journalEntry.savings_transaction_id = st.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_note as note on lt.id = note.loan_transaction_id or st.id = note.savings_account_transaction_id ");
}
return sb.toString();
}
@@ -144,9 +140,9 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final Boolean reversed = rs.getBoolean("reversed");
final String referenceNumber = rs.getString("referenceNumber");
BigDecimal officeRunningBalance = null;
BigDecimal organizationRunningBalance =null;
Boolean runningBalanceComputed =null;
BigDecimal organizationRunningBalance = null;
Boolean runningBalanceComputed = null;
final String currencyCode = rs.getString("currencyCode");
final String currencyName = rs.getString("currencyName");
final String currencyNameCode = rs.getString("currencyNameCode");
@@ -155,15 +151,15 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final Integer inMultiplesOf = JdbcSupport.getInteger(rs, "inMultiplesOf");
final CurrencyData currency = new CurrencyData(currencyCode, currencyName, currencyDigits, inMultiplesOf,
currencyDisplaySymbol, currencyNameCode);
if(associationParametersData.isRunningBalanceRequired()){
if (associationParametersData.isRunningBalanceRequired()) {
officeRunningBalance = rs.getBigDecimal("officeRunningBalance");
organizationRunningBalance = rs.getBigDecimal("organizationRunningBalance");
runningBalanceComputed = rs.getBoolean("runningBalanceComputed");
}
TransactionDetailData transactionDetailData = null;
if(associationParametersData.isTransactionDetailsRequired()){
if (associationParametersData.isTransactionDetailsRequired()) {
PaymentDetailData paymentDetailData = null;
final Long paymentTypeId = JdbcSupport.getLong(rs, "paymentTypeId");
if (paymentTypeId != null) {
@@ -177,41 +173,43 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
paymentDetailData = new PaymentDetailData(id, paymentType, accountNumber, checkNumber, routingCode, receiptNumber,
bankNumber);
}
NoteData noteData =null;
NoteData noteData = null;
final Long noteId = JdbcSupport.getLong(rs, "noteId");
if(noteId!=null){
final String note = rs.getString("transactionNote");
if (noteId != null) {
final String note = rs.getString("transactionNote");
noteData = new NoteData(noteId, null, null, null, null, null, null, null, note, null, null, null, null, null, null);
}
Long transaction = null;
if(entityType!=null){
if (entityType != null) {
transaction = Long.parseLong(transactionId.substring(1).trim());
}
String transactionType = null;
TransactionTypeEnumData transactionTypeEnumData = null;
if(PortfolioAccountType.fromInt(entityTypeId).isLoanAccount())
{
transactionType = rs.getString("loanTransactionType");
}
else if(PortfolioAccountType.fromInt(entityTypeId).isSavingsAccount()){
transactionType = rs.getString("savingTransactionType");
if (PortfolioAccountType.fromInt(entityTypeId).isLoanAccount()) {
final LoanTransactionEnumData loanTransactionType = LoanEnumerations.transactionType(JdbcSupport.getInteger(rs,
"loanTransactionType"));
transactionTypeEnumData = new TransactionTypeEnumData(loanTransactionType.id(), loanTransactionType.getCode(),
loanTransactionType.getValue());
} else if (PortfolioAccountType.fromInt(entityTypeId).isSavingsAccount()) {
final SavingsAccountTransactionEnumData savingsTransactionType = SavingsEnumerations.transactionType(JdbcSupport
.getInteger(rs, "savingsTransactionType"));
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,
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);
}
}
@Override
public Page<JournalEntryData> retrieveAll(final SearchParameters searchParameters, final Long glAccountId,
final Boolean onlyManualEntries, final Date fromDate, final Date toDate, final String transactionId, final Integer entityType,
final Boolean onlyManualEntries, final Date fromDate, final Date toDate, final String transactionId, final Integer entityType,
final JournalEntryAssociationParametersData associationParametersData) {
GLJournalEntryMapper rm = new GLJournalEntryMapper(associationParametersData);
@@ -221,40 +219,40 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
final Object[] objectArray = new Object[5];
int arrayPos = 0;
String whereClose = " where ";
String whereClose = " where ";
if (StringUtils.isNotBlank(transactionId)) {
sqlBuilder.append(whereClose+" journalEntry.transaction_id = ?");
sqlBuilder.append(whereClose + " journalEntry.transaction_id = ?");
objectArray[arrayPos] = transactionId;
arrayPos = arrayPos + 1;
whereClose =" and ";
whereClose = " and ";
}
if (entityType != null && entityType != 0 && (onlyManualEntries == null)) {
sqlBuilder.append(whereClose+" journalEntry.entity_type_enum = ?");
sqlBuilder.append(whereClose + " journalEntry.entity_type_enum = ?");
objectArray[arrayPos] = entityType;
arrayPos = arrayPos + 1;
whereClose =" and ";
whereClose = " and ";
}
if (searchParameters.isOfficeIdPassed()) {
sqlBuilder.append(whereClose+" journalEntry.office_id = ?");
sqlBuilder.append(whereClose + " journalEntry.office_id = ?");
objectArray[arrayPos] = searchParameters.getOfficeId();
arrayPos = arrayPos + 1;
whereClose =" and ";
whereClose = " and ";
}
if (glAccountId != null && glAccountId != 0) {
sqlBuilder.append(whereClose+" journalEntry.account_id = ?");
sqlBuilder.append(whereClose + " journalEntry.account_id = ?");
objectArray[arrayPos] = glAccountId;
arrayPos = arrayPos + 1;
whereClose =" and ";
whereClose = " and ";
}
if (fromDate != null || toDate != null) {
@@ -262,9 +260,9 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
String fromDateString = null;
String toDateString = 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);
toDateString = df.format(toDate);
@@ -273,27 +271,27 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
objectArray[arrayPos] = toDateString;
arrayPos = arrayPos + 1;
} else if (fromDate != null) {
sqlBuilder.append(whereClose+" journalEntry.entry_date >= ? ");
sqlBuilder.append(whereClose + " journalEntry.entry_date >= ? ");
fromDateString = df.format(fromDate);
objectArray[arrayPos] = fromDateString;
arrayPos = arrayPos + 1;
whereClose =" and ";
whereClose = " and ";
} else if (toDate != null) {
sqlBuilder.append(whereClose+" journalEntry.entry_date <= ? ");
sqlBuilder.append(whereClose + " journalEntry.entry_date <= ? ");
toDateString = df.format(toDate);
objectArray[arrayPos] = toDateString;
arrayPos = arrayPos + 1;
whereClose =" and ";
whereClose = " and ";
}
}
if (onlyManualEntries != null) {
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()) {
sqlBuilder.append(' ').append(searchParameters.getSortOrder());
}
}
else
{
} else {
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 String sqlCountRows = "SELECT FOUND_ROWS()";
return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(), finalObjectArray,
rm);
return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(), finalObjectArray, rm);
}
@Override
public JournalEntryData retrieveGLJournalEntryById(final long glJournalEntryId, JournalEntryAssociationParametersData associationParametersData) {
public JournalEntryData retrieveGLJournalEntryById(final long glJournalEntryId,
JournalEntryAssociationParametersData associationParametersData) {
try {
final GLJournalEntryMapper rm = new GLJournalEntryMapper(associationParametersData);
@@ -58,6 +58,14 @@ public class LoanTransactionEnumData {
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)
* 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
* enumerations.
*/
@SuppressWarnings("unused")
public class SavingsAccountTransactionEnumData {
private final Long id;
@@ -43,6 +42,18 @@ public class SavingsAccountTransactionEnumData {
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() {
return this.deposit;
}