diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java index 9aee80458..85977c029 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java @@ -84,15 +84,25 @@ public class RecurringDepositAccountTransactionsApiResource { this.context.authenticatedUser().validateHasReadPermission(DepositsApiConstants.RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME); - SavingsAccountTransactionData savingsAccount = null; + /*** + * Check @Param commandParam value for deposit or withdrawal + */ + if (!(is(commandParam, "deposit") || is(commandParam, "withdrawal"))) { throw new UnrecognizedQueryParamException("command", + commandParam, new Object[] { "deposit", "withdrawal" }); } - if (is(commandParam, "deposit")) { - savingsAccount = this.depositAccountReadPlatformService - .retrieveRecurringAccountDepositTransactionTemplate(recurringDepositAccountId); - } else if (is(commandParam, "withdrawal")) { - // - } else { - throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "deposit", "withdrawal" }); + /*** + * By default get the deposit template for deposits and withdrawal + * transactions + */ + SavingsAccountTransactionData savingsAccount = this.depositAccountReadPlatformService + .retrieveRecurringAccountDepositTransactionTemplate(recurringDepositAccountId); + + /*** + * Update transaction date and transaction type if transaction type is + * withdrawal + */ + if (is(commandParam, "withdrawal")) { + savingsAccount = SavingsAccountTransactionData.withWithDrawalTransactionDetails(savingsAccount); } final Collection paymentTypeOptions = this.codeValueReadPlatformService diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionData.java index 9dfce4890..502203f33 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionData.java @@ -10,9 +10,12 @@ import java.util.Collection; import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.codes.data.CodeValueData; +import org.mifosplatform.infrastructure.core.service.DateUtils; import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.portfolio.account.data.AccountTransferData; import org.mifosplatform.portfolio.paymentdetail.data.PaymentDetailData; +import org.mifosplatform.portfolio.savings.SavingsAccountTransactionType; +import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; /** * Immutable data object representing a savings account transaction. @@ -83,4 +86,18 @@ public class SavingsAccountTransactionData { this.transfer = transfer; this.paymentTypeOptions = paymentTypeOptions; } + + public static SavingsAccountTransactionData withWithDrawalTransactionDetails(final SavingsAccountTransactionData savingsAccountTransactionData) { + + final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); + final SavingsAccountTransactionEnumData transactionType = SavingsEnumerations + .transactionType(SavingsAccountTransactionType.WITHDRAWAL.getValue()); + + return new SavingsAccountTransactionData(savingsAccountTransactionData.id, transactionType, + savingsAccountTransactionData.paymentDetailData, savingsAccountTransactionData.accountId, + savingsAccountTransactionData.accountNo, currentDate, savingsAccountTransactionData.currency, + savingsAccountTransactionData.runningBalance, savingsAccountTransactionData.runningBalance, + savingsAccountTransactionData.reversed, savingsAccountTransactionData.transfer, + savingsAccountTransactionData.paymentTypeOptions); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java index 043ab054d..5e8d725e3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java @@ -1333,6 +1333,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead .append("sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, sa.currency_multiplesof as inMultiplesOf, "); sqlBuilder.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, "); sqlBuilder.append("curr.display_symbol as currencyDisplaySymbol, "); + sqlBuilder.append("sa.account_balance_derived as runningBalance, "); sqlBuilder .append("mss.duedate as duedate, (mss.deposit_amount - ifnull(mss.deposit_amount_completed_derived,0)) as dueamount "); sqlBuilder.append("from m_savings_account sa "); @@ -1365,7 +1366,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead .transactionType(SavingsAccountTransactionType.DEPOSIT.getValue()); final PaymentDetailData paymentDetailData = null; final AccountTransferData transfer = null; - final BigDecimal runningBalance = null; + final BigDecimal runningBalance = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "runningBalance");; return SavingsAccountTransactionData.create(savingsId, transactionType, paymentDetailData, savingsId, accountNo, duedate, currency, dueamount, runningBalance, false, transfer); }