From 492a8547a9ed166f92680739aa8e3277c2d963d6 Mon Sep 17 00:00:00 2001 From: Madhukar Date: Thu, 6 Sep 2012 07:46:11 +0530 Subject: [PATCH] Get the transactions for DepositAccounts --- .../api/DepositAccountsApiResource.java | 2 +- .../platform/api/data/DepositAccountData.java | 19 ++++++ .../data/DepositAccountTransactionData.java | 56 +++++++++++++++++ .../GoogleGsonApiJsonSerializerService.java | 3 +- ...DepositAccountReadPlatformServiceImpl.java | 62 ++++++++++++++++++- ...DepositAccountTransactionEnumerations.java | 34 ++++++++++ 6 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountTransactionData.java create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountTransactionEnumerations.java diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java index 3701864ca..2f5dacfad 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java @@ -68,7 +68,7 @@ public class DepositAccountsApiResource { "interestCompoundedEvery", "interestCompoundedEveryPeriodType", "renewalAllowed", "preClosureAllowed", "preClosureInterestRate", - "withdrawnonDate","rejectedonDate","closedonDate")); + "withdrawnonDate","rejectedonDate","closedonDate","transactions")); @POST diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java index a858d7aea..7cfbaa5eb 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java @@ -46,6 +46,8 @@ public class DepositAccountData { private final List interestCompoundedEveryPeriodTypeOptions; private final List productOptions; + private Collection transactions; + /* * used when returning account template data but only a clientId is passed, no selected product. */ @@ -87,6 +89,8 @@ public class DepositAccountData { this.withdrawnonDate=null; this.closedonDate=null; this.rejectedonDate=null; + + this.transactions=null; } public DepositAccountData( @@ -124,6 +128,8 @@ public class DepositAccountData { this.withdrawnonDate=account.getWithdrawnonDate(); this.rejectedonDate=account.getRejectedonDate(); this.closedonDate=account.getClosedonDate(); + + this.transactions=account.getTransactions(); } public DepositAccountData( @@ -184,6 +190,8 @@ public class DepositAccountData { this.withdrawnonDate = withdrawnonDate; this.rejectedonDate = rejectedonDate; this.closedonDate = closedonDate; + + this.transactions = null; } public DepositAccountData( @@ -230,6 +238,8 @@ public class DepositAccountData { this.withdrawnonDate=null; this.closedonDate=null; this.rejectedonDate=null; + + this.transactions = null; } public Long getId() { @@ -347,4 +357,13 @@ public class DepositAccountData { public LocalDate getClosedonDate() { return closedonDate; } + + public Collection getTransactions() { + return transactions; + } + + public void setTransactions(Collection transactions) { + this.transactions = transactions; + } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountTransactionData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountTransactionData.java new file mode 100644 index 000000000..63db8f8bc --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountTransactionData.java @@ -0,0 +1,56 @@ +package org.mifosng.platform.api.data; + +import java.math.BigDecimal; + +import org.joda.time.LocalDate; + +public class DepositAccountTransactionData { + + private final Long transactionId; + private final EnumOptionData transactionType; + private final LocalDate transactionDate; + private final BigDecimal transactionAmount; + private final Long accountId; + + public DepositAccountTransactionData() { + + this.transactionId = null; + this.accountId = null; + this.transactionType = null; + this.transactionDate = null; + this.transactionAmount = null; + + } + + public DepositAccountTransactionData(final Long transactionId, final Long accountId, final EnumOptionData transactionType, final LocalDate transactionDate, final BigDecimal transactionAmount ){ + + this.transactionId = transactionId; + this.accountId = accountId; + this.transactionType = transactionType; + this.transactionDate = transactionDate; + this.transactionAmount = transactionAmount; + } + + public Long getAccountId() { + return accountId; + } + + public Long getTransactionId() { + return transactionId; + } + + public EnumOptionData getTransactionType() { + return transactionType; + } + + public LocalDate getTransactionDate() { + return transactionDate; + } + + public BigDecimal getTransactionAmount() { + return transactionAmount; + } + + + +} diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java index 2abfe8e7e..8694e41f0 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java @@ -105,7 +105,7 @@ public class GoogleGsonApiJsonSerializerService implements "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", "renewalAllowed","preClosureAllowed","preClosureInterestRate", - "withdrawnonDate","rejectedonDate","closedonDate" + "withdrawnonDate","rejectedonDate","closedonDate","transactions" ) ); @@ -559,4 +559,5 @@ public class GoogleGsonApiJsonSerializerService implements return helper.serializedJsonFrom(gsonDeserializer, staff.toArray(new StaffData[staff.size()])); } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java index 5781b6073..d355c0fe1 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java @@ -3,12 +3,15 @@ package org.mifosng.platform.saving.service; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.joda.time.LocalDate; import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.CurrencyData; import org.mifosng.platform.api.data.DepositAccountData; +import org.mifosng.platform.api.data.DepositAccountTransactionData; import org.mifosng.platform.api.data.DepositProductData; import org.mifosng.platform.api.data.DepositProductLookup; import org.mifosng.platform.api.data.EnumOptionData; @@ -50,7 +53,23 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead String sql = "select " + mapper.schema() + " where da.is_deleted=0"; - return this.jdbcTemplate.query(sql,mapper, new Object[]{}); + Collection depositAccountDatas = this.jdbcTemplate.query(sql,mapper, new Object[]{}); + + DepositAccountTransactionMapper transactionMapper = new DepositAccountTransactionMapper(); + String transactionSchema = "Select "+transactionMapper.schema(); + Collection depositAccountTransactionDatas = this.jdbcTemplate.query(transactionSchema, transactionMapper, new Object[]{}); + + for(DepositAccountData depositAccountData : depositAccountDatas){ + List myAccountTransactionDatas = new ArrayList(); + for(DepositAccountTransactionData depositAccountTransactionData : depositAccountTransactionDatas){ + if(depositAccountData.getId().equals(depositAccountTransactionData.getAccountId())){ + myAccountTransactionDatas.add(depositAccountTransactionData); + } + depositAccountData.setTransactions(myAccountTransactionDatas); + } + } + + return depositAccountDatas; } @@ -64,6 +83,20 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead DepositAccountData productData = this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { accountId }); + DepositAccountTransactionMapper transactionMapper = new DepositAccountTransactionMapper(); + String transactionSchema = "Select "+transactionMapper.schema() +" where txn.deposit_account_id = ? "; + Collection depositAccountTransactionDatas = this.jdbcTemplate.query(transactionSchema, transactionMapper, new Object[]{accountId}); + + List myAccountTransactionDatas = new ArrayList(); + for(DepositAccountTransactionData depositAccountTransactionData : depositAccountTransactionDatas){ + + if(productData.getId().equals(depositAccountTransactionData.getAccountId())) + myAccountTransactionDatas.add(depositAccountTransactionData); + + } + + productData.setTransactions(myAccountTransactionDatas); + return productData; } catch (EmptyResultDataAccessException e) { throw new LoanProductNotFoundException(accountId); @@ -126,11 +159,11 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead + " da.is_renewal_allowed as renewalAllowed, da.is_preclosure_allowed as preClosureAllowed, da.pre_closure_interest_rate as preClosureInterestRate, " + " da.withdrawnon_date as withdrawnonDate, da.rejectedon_date as rejectedonDate, da.closedon_date as closedonDate, " + " c.firstname as firstname, c.lastname as lastname, pd.name as productName," - + " curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol" + + " curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol " + " from m_deposit_account da " + " join m_currency curr on curr.code = da.currency_code " + " join m_client c on c.id = da.client_id " - + " join m_product_deposit pd on pd.id = da.product_id"; + + " join m_product_deposit pd on pd.id = da.product_id"; } @Override @@ -190,4 +223,27 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead withdrawnonDate,rejectedonDate,closedonDate); } } + + private static final class DepositAccountTransactionMapper implements RowMapper{ + + public String schema() { + return " txn.id as transactionId, txn.deposit_account_id as accountId, txn.transaction_type_enum as transactionType, txn.transaction_date as transactionDate, txn.amount as transactionAmount " + + " from m_deposit_account_transaction txn"; + } + + @Override + public DepositAccountTransactionData mapRow(ResultSet rs, int rowNum) + throws SQLException { + + Long transactionId = rs.getLong("transactionId"); + Long accountId = rs.getLong("accountId"); + Integer transactionTypeValue = JdbcSupport.getInteger(rs, "transactionType"); + EnumOptionData transactionType=DepositAccountTransactionEnumerations.depositType(transactionTypeValue); + LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate"); + BigDecimal transactionAmount = rs.getBigDecimal("transactionAmount"); + + return new DepositAccountTransactionData(transactionId, accountId, transactionType, transactionDate, transactionAmount); + } + + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountTransactionEnumerations.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountTransactionEnumerations.java new file mode 100644 index 000000000..60eca5eff --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountTransactionEnumerations.java @@ -0,0 +1,34 @@ +package org.mifosng.platform.saving.service; + +import org.mifosng.platform.api.data.EnumOptionData; +import org.mifosng.platform.saving.domain.DepositTransactionType; + +public class DepositAccountTransactionEnumerations { + + public static EnumOptionData depositType(final Integer statusId) { + return depositType(DepositTransactionType.fromInt(statusId)); + } + + private static EnumOptionData depositType(DepositTransactionType transactionType) { + + EnumOptionData optionData=null; + switch (transactionType) { + case DEPOSIT: + optionData=new EnumOptionData(DepositTransactionType.DEPOSIT.getValue().longValue(), DepositTransactionType.DEPOSIT.getCode(), "Deposit"); + break; + + case WITHDRAW: + optionData=new EnumOptionData(DepositTransactionType.WITHDRAW.getValue().longValue(), DepositTransactionType.WITHDRAW.getCode(), "Withdraw"); + break; + + case REVERSAL: + optionData=new EnumOptionData(DepositTransactionType.REVERSAL.getValue().longValue(), DepositTransactionType.REVERSAL.getCode(), "Revarsal"); + break; + default: + optionData=new EnumOptionData(DepositTransactionType.INVALID.getValue().longValue(), DepositTransactionType.INVALID.getCode(), "Invalid Transaction"); + break; + } + return optionData; + } + +}