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 6aa7ceb04..7efb73b8b 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 @@ -12,8 +12,8 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.localePara import static org.mifosplatform.portfolio.savings.SavingsApiConstants.lockinPeriodFrequencyParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.lockinPeriodFrequencyTypeParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName; -import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName; import java.math.BigDecimal; import java.math.MathContext; @@ -59,6 +59,7 @@ import org.mifosplatform.infrastructure.security.service.RandomPasswordGenerator import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.organisation.monetary.domain.Money; +import org.mifosplatform.organisation.office.domain.Office; import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.portfolio.accountdetails.domain.AccountType; import org.mifosplatform.portfolio.client.domain.Client; @@ -376,7 +377,7 @@ public class SavingsAccount extends AbstractPersistable { final SavingsAccountTransaction postingTransaction = findInterestPostingTransactionFor(interestPostingTransactionDate); if (postingTransaction == null) { - final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting(this, + final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(), interestPostingTransactionDate, interestEarnedToBePostedForPeriod); this.transactions.add(newPostingTransaction); recalucateDailyBalanceDetails = true; @@ -384,7 +385,7 @@ public class SavingsAccount extends AbstractPersistable { final boolean correctionRequired = postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod); if (correctionRequired) { postingTransaction.reverse(); - final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting(this, + final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(), interestPostingTransactionDate, interestEarnedToBePostedForPeriod); this.transactions.add(newPostingTransaction); recalucateDailyBalanceDetails = true; @@ -590,7 +591,7 @@ public class SavingsAccount extends AbstractPersistable { final Money amount = Money.of(this.currency, transactionDTO.getTransactionAmount()); - final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(this, transactionDTO.getPaymentDetail(), + final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(this, office(), transactionDTO.getPaymentDetail(), transactionDTO.getTransactionDate(), amount); this.transactions.add(transaction); @@ -663,8 +664,8 @@ public class SavingsAccount extends AbstractPersistable { transactionDTO.getExistingReversedTransactionIds().addAll(findExistingReversedTransactionIds()); final Money transactionAmountMoney = Money.of(this.currency, transactionDTO.getTransactionAmount()); - final SavingsAccountTransaction transaction = SavingsAccountTransaction.withdrawal(this, transactionDTO.getPaymentDetail(), - transactionDTO.getTransactionDate(), transactionAmountMoney); + final SavingsAccountTransaction transaction = SavingsAccountTransaction.withdrawal(this, office(), + transactionDTO.getPaymentDetail(), transactionDTO.getTransactionDate(), transactionAmountMoney); this.transactions.add(transaction); if (applyWithdrawFee && isAutomaticWithdrawalFee()) { @@ -676,14 +677,16 @@ public class SavingsAccount extends AbstractPersistable { break; case FLAT: feeAmount = Money.of(this.currency, this.withdrawalFeeAmount); - withdrawalFeeTransaction = SavingsAccountTransaction.fee(this, transactionDTO.getTransactionDate(), feeAmount); + withdrawalFeeTransaction = SavingsAccountTransaction + .fee(this, office(), transactionDTO.getTransactionDate(), feeAmount); this.transactions.add(withdrawalFeeTransaction); break; case PERCENT_OF_AMOUNT: final BigDecimal feeAmountDecimal = transactionDTO.getTransactionAmount().multiply(this.withdrawalFeeAmount) .divide(BigDecimal.valueOf(100l)); feeAmount = Money.of(this.currency, feeAmountDecimal); - withdrawalFeeTransaction = SavingsAccountTransaction.fee(this, transactionDTO.getTransactionDate(), feeAmount); + withdrawalFeeTransaction = SavingsAccountTransaction + .fee(this, office(), transactionDTO.getTransactionDate(), feeAmount); this.transactions.add(withdrawalFeeTransaction); break; } @@ -722,8 +725,7 @@ public class SavingsAccount extends AbstractPersistable { if (runningBalance.isLessThanZero()) { // final BigDecimal withdrawalFee = null; - throw new InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), withdrawalFee, - transactionAmount); + throw new InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), withdrawalFee, transactionAmount); } } } @@ -806,8 +808,8 @@ public class SavingsAccount extends AbstractPersistable { existingReversedTransactionIds.addAll(findExistingReversedTransactionIds()); final Money annualFee = Money.of(this.currency, this.annualFeeAmount); - final SavingsAccountTransaction annualFeeTransaction = SavingsAccountTransaction.annualFee(this, annualFeeTransactionDate, - annualFee); + final SavingsAccountTransaction annualFeeTransaction = SavingsAccountTransaction.annualFee(this, office(), + annualFeeTransactionDate, annualFee); this.transactions.add(annualFeeTransaction); validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.applyAnnualFeeTransactionAction); @@ -1247,6 +1249,16 @@ public class SavingsAccount extends AbstractPersistable { return officeId; } + public Office office() { + Office office = null; + if (this.client != null) { + office = this.client.getOffice(); + } else { + office = this.group.getOffice(); + } + return office; + } + public Long clientId() { Long id = null; if (this.client != null) { @@ -1669,8 +1681,8 @@ public class SavingsAccount extends AbstractPersistable { // activating account. final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance); if (minRequiredOpeningBalance.isGreaterThanZero()) { - SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, activationDate, minRequiredOpeningBalance.getAmount(), - existingTransactionIds, existingReversedTransactionIds, null); + SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, activationDate, + minRequiredOpeningBalance.getAmount(), existingTransactionIds, existingReversedTransactionIds, null); deposit(transactionDTO); } 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 7916de80a..54bc36800 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 @@ -23,6 +23,7 @@ import org.mifosplatform.infrastructure.core.domain.LocalDateInterval; import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.organisation.monetary.domain.Money; +import org.mifosplatform.organisation.office.domain.Office; import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail; import org.mifosplatform.portfolio.savings.SavingsAccountTransactionType; import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionEnumData; @@ -42,6 +43,10 @@ public final class SavingsAccountTransaction extends AbstractPersistable { @JoinColumn(name = "savings_account_id", nullable = false) private SavingsAccount savingsAccount; + @ManyToOne + @JoinColumn(name = "office_id", nullable = false) + private Office office; + @ManyToOne(optional = true) @JoinColumn(name = "payment_detail_id", nullable = true) private PaymentDetail paymentDetail; @@ -77,45 +82,50 @@ public final class SavingsAccountTransaction extends AbstractPersistable { this.typeOf = null; } - public static SavingsAccountTransaction deposit(final SavingsAccount savingsAccount, final PaymentDetail paymentDetail, - final LocalDate date, final Money amount) { + public static SavingsAccountTransaction deposit(final SavingsAccount savingsAccount, final Office office, + final PaymentDetail paymentDetail, final LocalDate date, final Money amount) { final boolean isReversed = false; - return new SavingsAccountTransaction(savingsAccount, paymentDetail, SavingsAccountTransactionType.DEPOSIT.getValue(), date, amount, - isReversed); - } - - public static SavingsAccountTransaction withdrawal(final SavingsAccount savingsAccount, final PaymentDetail paymentDetail, - final LocalDate date, final Money amount) { - final boolean isReversed = false; - return new SavingsAccountTransaction(savingsAccount, paymentDetail, SavingsAccountTransactionType.WITHDRAWAL.getValue(), date, + return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, SavingsAccountTransactionType.DEPOSIT.getValue(), date, amount, isReversed); } - public static SavingsAccountTransaction interestPosting(final SavingsAccount savingsAccount, final LocalDate date, final Money amount) { + public static SavingsAccountTransaction withdrawal(final SavingsAccount savingsAccount, final Office office, + final PaymentDetail paymentDetail, final LocalDate date, final Money amount) { final boolean isReversed = false; - return new SavingsAccountTransaction(savingsAccount, SavingsAccountTransactionType.INTEREST_POSTING.getValue(), date, amount, + return new SavingsAccountTransaction(savingsAccount, office, paymentDetail, SavingsAccountTransactionType.WITHDRAWAL.getValue(), + date, amount, isReversed); + } + + public static SavingsAccountTransaction interestPosting(final SavingsAccount savingsAccount, final Office office, final LocalDate date, + final Money amount) { + final boolean isReversed = false; + return new SavingsAccountTransaction(savingsAccount, office, SavingsAccountTransactionType.INTEREST_POSTING.getValue(), date, + amount, isReversed); + } + + public static SavingsAccountTransaction fee(final SavingsAccount savingsAccount, final Office office, final LocalDate date, + final Money amount) { + final boolean isReversed = false; + return new SavingsAccountTransaction(savingsAccount, office, SavingsAccountTransactionType.WITHDRAWAL_FEE.getValue(), date, amount, isReversed); } - public static SavingsAccountTransaction fee(final SavingsAccount savingsAccount, final LocalDate date, final Money amount) { + public static SavingsAccountTransaction annualFee(final SavingsAccount savingsAccount, final Office office, final LocalDate date, + final Money amount) { final boolean isReversed = false; - return new SavingsAccountTransaction(savingsAccount, SavingsAccountTransactionType.WITHDRAWAL_FEE.getValue(), date, amount, + return new SavingsAccountTransaction(savingsAccount, office, SavingsAccountTransactionType.ANNUAL_FEE.getValue(), date, amount, isReversed); } - public static SavingsAccountTransaction annualFee(final SavingsAccount savingsAccount, final LocalDate date, final Money amount) { - final boolean isReversed = false; - return new SavingsAccountTransaction(savingsAccount, SavingsAccountTransactionType.ANNUAL_FEE.getValue(), date, amount, isReversed); - } - - private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Integer typeOf, final LocalDate transactionLocalDate, - final Money amount, final boolean isReversed) { - this(savingsAccount, null, typeOf, transactionLocalDate, amount, isReversed); - } - - private SavingsAccountTransaction(final SavingsAccount savingsAccount, final PaymentDetail paymentDetail, final Integer typeOf, + 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); + } + + 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 = savingsAccount; + this.office = office; this.typeOf = typeOf; this.dateOf = transactionLocalDate.toDate(); this.amount = amount.getAmount(); @@ -302,15 +312,15 @@ public final class SavingsAccountTransaction extends AbstractPersistable { numberOfDaysOfBalance = spanOfBalance.daysInPeriodInclusiveOfEndDate(); } else { if (isDeposit()) { -// endOfDayBalance = openingBalance.plus(getAmount(currency)); -// if (endOfDayBalance.isLessThanZero()) { - endOfDayBalance = Money.of(currency, this.runningBalance); -// } + // endOfDayBalance = openingBalance.plus(getAmount(currency)); + // if (endOfDayBalance.isLessThanZero()) { + endOfDayBalance = Money.of(currency, this.runningBalance); + // } } else if (isWithdrawal() || isWithdrawalFeeAndNotReversed()) { -// endOfDayBalance = openingBalance.minus(getAmount(currency)); -// if (endOfDayBalance.isLessThanZero()) { - endOfDayBalance = Money.of(currency, this.runningBalance); -// } + // endOfDayBalance = openingBalance.minus(getAmount(currency)); + // if (endOfDayBalance.isLessThanZero()) { + endOfDayBalance = Money.of(currency, this.runningBalance); + // } } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java index df7e1d12c..8095b2522 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java @@ -409,16 +409,20 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr if (!client.isTransferInProgress()) { throw new ClientNotAwaitingTransferApprovalException(client.getId()); } } - private void validateGroupAwaitingTransferAcceptance(final Group group) { - if (!group.isTransferInProgress()) { throw new ClientNotAwaitingTransferApprovalException(group.getId()); } - } + /** + * private void validateGroupAwaitingTransferAcceptance(final Group group) { + * if (!group.isTransferInProgress()) { throw new + * ClientNotAwaitingTransferApprovalException(group.getId()); } } + **/ private void validateClientAwaitingTransferAcceptanceOnHold(final Client client) { if (!client.isTransferInProgressOrOnHold()) { throw new ClientNotAwaitingTransferApprovalOrOnHoldException(client.getId()); } } - private void validateGroupAwaitingTransferAcceptanceOnHold(final Group group) { - if (!group.isTransferInProgressOrOnHold()) { throw new ClientNotAwaitingTransferApprovalException(group.getId()); } - } + /** + * private void validateGroupAwaitingTransferAcceptanceOnHold(final Group + * group) { if (!group.isTransferInProgressOrOnHold()) { throw new + * ClientNotAwaitingTransferApprovalException(group.getId()); } } + **/ } \ No newline at end of file