diff --git a/mifosng-db/migrations/core_db/V149__add_created_date_savings_transaction.sql b/mifosng-db/migrations/core_db/V149__add_created_date_savings_transaction.sql new file mode 100755 index 000000000..85ffedd80 --- /dev/null +++ b/mifosng-db/migrations/core_db/V149__add_created_date_savings_transaction.sql @@ -0,0 +1,4 @@ +ALTER TABLE `m_savings_account_transaction` + ADD COLUMN `created_date` DATETIME NOT NULL AFTER `cumulative_balance_derived`; + +update m_savings_account_transaction sat set sat.created_date=sat.transaction_date; \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java index 5fdeeb71a..646d7d279 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java @@ -1,6 +1,7 @@ package org.mifosplatform.portfolio.savings.data; import java.math.BigDecimal; +import java.util.Date; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormatter; @@ -12,13 +13,15 @@ public class SavingsAccountTransactionDTO { private final LocalDate transactionDate; private final BigDecimal transactionAmount; private final PaymentDetail paymentDetail; + private final Date crecreatedDate; public SavingsAccountTransactionDTO(final DateTimeFormatter formatter, final LocalDate transactionDate, - final BigDecimal transactionAmount, final PaymentDetail paymentDetail) { + final BigDecimal transactionAmount, final PaymentDetail paymentDetail,final Date crecreatedDate) { this.formatter = formatter; this.transactionDate = transactionDate; this.transactionAmount = transactionAmount; this.paymentDetail = paymentDetail; + this.crecreatedDate = crecreatedDate; } public DateTimeFormatter getFormatter() { @@ -36,4 +39,8 @@ public class SavingsAccountTransactionDTO { public PaymentDetail getPaymentDetail() { return this.paymentDetail; } + + public Date getCrecreatedDate() { + return this.crecreatedDate; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java index 0aabd02ab..f3a365209 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java @@ -231,7 +231,7 @@ public class SavingsAccount extends AbstractPersistable { @Embedded private SavingsAccountSummary summary; - @OrderBy(value = "dateOf, id") + @OrderBy(value = "dateOf, createdDate, id") @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(cascade = CascadeType.ALL, mappedBy = "savingsAccount", orphanRemoval = true) private final List transactions = new ArrayList(); @@ -495,13 +495,13 @@ public class SavingsAccount extends AbstractPersistable { private List retreiveListOfTransactions() { final List listOfTransactionsSorted = new ArrayList(); - for (final SavingsAccountTransaction transaction : this.transactions) { + listOfTransactionsSorted.addAll(this.transactions); +/* for (final SavingsAccountTransaction transaction : this.transactions) { listOfTransactionsSorted.add(transaction); } - +*/ final SavingsAccountTransactionComparator transactionComparator = new SavingsAccountTransactionComparator(); Collections.sort(listOfTransactionsSorted, transactionComparator); - return listOfTransactionsSorted; } @@ -615,7 +615,7 @@ public class SavingsAccount extends AbstractPersistable { final Money amount = Money.of(this.currency, transactionDTO.getTransactionAmount()); final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(this, office(), transactionDTO.getPaymentDetail(), - transactionDTO.getTransactionDate(), amount); + transactionDTO.getTransactionDate(), amount, transactionDTO.getCrecreatedDate()); this.transactions.add(transaction); this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); @@ -686,7 +686,8 @@ public class SavingsAccount extends AbstractPersistable { final Money transactionAmountMoney = Money.of(this.currency, transactionDTO.getTransactionAmount()); final SavingsAccountTransaction transaction = SavingsAccountTransaction.withdrawal(this, office(), - transactionDTO.getPaymentDetail(), transactionDTO.getTransactionDate(), transactionAmountMoney); + transactionDTO.getPaymentDetail(), transactionDTO.getTransactionDate(), transactionAmountMoney, + transactionDTO.getCrecreatedDate()); this.transactions.add(transaction); if (applyWithdrawFee){ @@ -1530,7 +1531,7 @@ public class SavingsAccount extends AbstractPersistable { final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance); if (minRequiredOpeningBalance.isGreaterThanZero()) { final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, getActivationLocalDate(), - minRequiredOpeningBalance.getAmount(), null); + minRequiredOpeningBalance.getAmount(), null,new Date()); deposit(transactionDTO); // no openingBalance concept supported yet but probably will to diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java index b7c474c6a..3fc878cb1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java @@ -7,6 +7,7 @@ package org.mifosplatform.portfolio.savings.domain; import java.math.BigDecimal; import java.math.MathContext; +import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -53,7 +54,7 @@ public class SavingsAccountDomainServiceJpa implements SavingsAccountDomainServi final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail); + paymentDetail,new Date()); final SavingsAccountTransaction withdrawal = account.withdraw(transactionDTO, applyWithdrawFee); final MathContext mc = MathContext.DECIMAL64; @@ -82,7 +83,7 @@ public class SavingsAccountDomainServiceJpa implements SavingsAccountDomainServi final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail); + paymentDetail,new Date()); final SavingsAccountTransaction deposit = account.deposit(transactionDTO); final MathContext mc = MathContext.DECIMAL64; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransaction.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransaction.java index 1d88dd62a..863e9221e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransaction.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransaction.java @@ -92,24 +92,29 @@ public final class SavingsAccountTransaction extends AbstractPersistable { @Column(name = "overdraft_amount_derived", scale = 6, precision = 19, nullable = true) private BigDecimal overdraftAmount; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "created_date", nullable = false) + private final Date createdDate; protected SavingsAccountTransaction() { this.dateOf = null; this.typeOf = null; + this.createdDate = null; } public static SavingsAccountTransaction deposit(final SavingsAccount savingsAccount, final Office office, - final PaymentDetail paymentDetail, final LocalDate date, final Money amount) { + final PaymentDetail paymentDetail, final LocalDate date, final Money amount, Date createdDate) { final boolean isReversed = false; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, SavingsAccountTransactionType.DEPOSIT.getValue(), date, - amount, isReversed); + createdDate, amount, isReversed); } public static SavingsAccountTransaction withdrawal(final SavingsAccount savingsAccount, final Office office, - final PaymentDetail paymentDetail, final LocalDate date, final Money amount) { + final PaymentDetail paymentDetail, final LocalDate date, final Money amount, Date createdDate) { final boolean isReversed = false; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, SavingsAccountTransactionType.WITHDRAWAL.getValue(), - date, amount, isReversed); + date,createdDate, amount, isReversed); } public static SavingsAccountTransaction interestPosting(final SavingsAccount savingsAccount, final Office office, final LocalDate date, @@ -151,7 +156,7 @@ public final class SavingsAccountTransaction extends AbstractPersistable { final boolean isReversed = false; final PaymentDetail paymentDetail = null; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, - SavingsAccountTransactionType.INITIATE_TRANSFER.getValue(), date, savingsAccount.getSummary().getAccountBalance(), + SavingsAccountTransactionType.INITIATE_TRANSFER.getValue(), date, new Date(),savingsAccount.getSummary().getAccountBalance(), isReversed); } @@ -159,7 +164,7 @@ public final class SavingsAccountTransaction extends AbstractPersistable { final boolean isReversed = false; final PaymentDetail paymentDetail = null; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, - SavingsAccountTransactionType.APPROVE_TRANSFER.getValue(), date, savingsAccount.getSummary().getAccountBalance(), + SavingsAccountTransactionType.APPROVE_TRANSFER.getValue(), date,new Date(), savingsAccount.getSummary().getAccountBalance(), isReversed); } @@ -167,29 +172,29 @@ public final class SavingsAccountTransaction extends AbstractPersistable { final boolean isReversed = false; final PaymentDetail paymentDetail = null; return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, - SavingsAccountTransactionType.WITHDRAW_TRANSFER.getValue(), date, savingsAccount.getSummary().getAccountBalance(), + SavingsAccountTransactionType.WITHDRAW_TRANSFER.getValue(), date,new Date(), savingsAccount.getSummary().getAccountBalance(), isReversed); } public static SavingsAccountTransaction copyTransaction(SavingsAccountTransaction accountTransaction) { return new SavingsAccountTransaction(accountTransaction.savingsAccount, accountTransaction.office, accountTransaction.paymentDetail, - accountTransaction.typeOf, accountTransaction.transactionLocalDate(), accountTransaction.amount, + accountTransaction.typeOf, accountTransaction.transactionLocalDate(),accountTransaction.createdDate, accountTransaction.amount, accountTransaction.reversed); } private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final Integer typeOf, final LocalDate transactionLocalDate, final Money amount, final boolean isReversed) { - this(savingsAccount, office, null, typeOf, transactionLocalDate, amount, isReversed); + this(savingsAccount, office, null, typeOf, transactionLocalDate, new Date(),amount, isReversed); } private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final PaymentDetail paymentDetail, - final Integer typeOf, final LocalDate transactionLocalDate, final Money amount, final boolean isReversed) { - this(savingsAccount, office, paymentDetail, typeOf, transactionLocalDate, amount.getAmount(), isReversed); + final Integer typeOf, final LocalDate transactionLocalDate,final Date createdDate, final Money amount, final boolean isReversed) { + this(savingsAccount, office, paymentDetail, typeOf, transactionLocalDate,createdDate, amount.getAmount(), isReversed); } private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final PaymentDetail paymentDetail, - final Integer typeOf, final LocalDate transactionLocalDate, final BigDecimal amount, final boolean isReversed) { + final Integer typeOf, final LocalDate transactionLocalDate, final Date createdDate, final BigDecimal amount, final boolean isReversed) { this.savingsAccount = savingsAccount; this.office = office; this.typeOf = typeOf; @@ -197,7 +202,7 @@ public final class SavingsAccountTransaction extends AbstractPersistable { this.amount = amount; this.reversed = isReversed; this.paymentDetail = paymentDetail; - + this.createdDate = createdDate; } public LocalDate transactionLocalDate() { @@ -555,5 +560,9 @@ public final class SavingsAccountTransaction extends AbstractPersistable { return Money.of(currency, this.overdraftAmount); } + public Date createdDate() { + return this.createdDate; + } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransactionComparator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransactionComparator.java index 9e228e91e..fc54d7a74 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransactionComparator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountTransactionComparator.java @@ -15,30 +15,18 @@ public class SavingsAccountTransactionComparator implements Comparator retrieveAllTransactions(final Long savingsId) { - final String sql = "select " + this.transactionsMapper.schema() + " where sa.id = ? order by tr.transaction_date DESC, tr.id DESC"; + final String sql = "select " + this.transactionsMapper.schema() + " where sa.id = ? order by tr.transaction_date DESC, tr.created_date DESC, tr.id DESC"; return this.jdbcTemplate.query(sql, this.transactionsMapper, new Object[] { savingsId }); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 1ad48169b..2434b048f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -441,13 +441,11 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } SavingsAccountTransaction transaction = null; + final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, + paymentDetail,savingsAccountTransaction.createdDate()); if (savingsAccountTransaction.isDeposit()) { - final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail); transaction = account.deposit(transactionDTO); } else { - final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, - paymentDetail); transaction = account.withdraw(transactionDTO, true); } final Long newtransactionId = saveTransactionToGenerateTransactionId(transaction);