Search in sources :

Example 11 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class SavingsBO method createNewAccountPaymentWithAdjustedAmount.

private Set<AccountTrxnEntity> createNewAccountPaymentWithAdjustedAmount(Money amountAdjustedTo, PersonnelBO updatedBy, AccountPaymentEntity payment, AccountActionTypes savingsTransactionType, Date adjustedOn, LocalDate adjustmentDate) {
    AccountPaymentEntity newAccountPayment = new AccountPaymentEntity(this, amountAdjustedTo, payment.getReceiptNumber(), payment.getReceiptDate(), payment.getPaymentType(), adjustmentDate.toDateMidnight().toDate());
    newAccountPayment.setCreatedByUser(updatedBy);
    newAccountPayment.setAmount(amountAdjustedTo);
    Set<AccountTrxnEntity> accountTrxns = new HashSet<AccountTrxnEntity>();
    if (isMandatory() && savingsTransactionType.equals(AccountActionTypes.SAVINGS_DEPOSIT)) {
        accountTrxns = createDepositTrxnsForMandatoryAccountsAfterAdjust(newAccountPayment, payment, amountAdjustedTo, adjustmentDate, updatedBy);
    } else if (isVoluntary() && savingsTransactionType.equals(AccountActionTypes.SAVINGS_DEPOSIT)) {
        accountTrxns = createDepositTrxnsForVolAccountsAfterAdjust(newAccountPayment, payment, amountAdjustedTo, adjustmentDate, updatedBy);
    } else {
        accountTrxns = createWithdrawalTrxnsAfterAdjust(newAccountPayment, payment, amountAdjustedTo, adjustmentDate, updatedBy);
    }
    for (AccountTrxnEntity accountTrxn : accountTrxns) {
        newAccountPayment.addAccountTrxn(accountTrxn);
    }
    this.addAccountPayment(newAccountPayment);
    AccountActionEntity depositOrWithdrawalTransactionType = new AccountActionEntity(savingsTransactionType);
    SavingsActivityEntity depositOrWithdrawalActivity = new SavingsActivityEntity(updatedBy, depositOrWithdrawalTransactionType, amountAdjustedTo, this.savingsBalance, adjustedOn, this);
    this.savingsActivityDetails.add(depositOrWithdrawalActivity);
    return newAccountPayment.getAccountTrxns();
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class SavingsBO method createWithdrawalTrxnsAfterAdjust.

private Set<AccountTrxnEntity> createWithdrawalTrxnsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, final Money newAmount, final LocalDate adjustmentDate, PersonnelBO loggedInUser) {
    Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
    SavingsTrxnDetailEntity accountTrxn = null;
    // create transaction for withdrawal
    SavingsTrxnDetailEntity oldSavingsAccntTrxn = null;
    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
        break;
    }
    this.savingsBalance = this.savingsBalance.subtract(newAmount);
    Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
    accountTrxn = SavingsTrxnDetailEntity.savingsWithdrawal(newAccountPayment, oldSavingsAccntTrxn.getCustomer(), newAmount, newAmount, loggedInUser, oldSavingsAccntTrxn.getDueDate(), adjustmentDate.toDateMidnight().toDate(), transactionCreatedDate);
    this.savingsPerformance.setTotalWithdrawals(this.savingsPerformance.getTotalWithdrawals().add(accountTrxn.getWithdrawlAmount()));
    newTrxns.add(accountTrxn);
    return newTrxns;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 13 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class SavingsBO method withdrawalAdjustmentDoesNotMakeBalanceNegative.

private boolean withdrawalAdjustmentDoesNotMakeBalanceNegative(final AccountPaymentEntity accountPayment, final Money amountAdjustedTo) {
    boolean balanceIsPositive = true;
    Money balanceAfterAdjust = this.savingsBalance;
    for (AccountTrxnEntity accntTrxn : accountPayment.getAccountTrxns()) {
        SavingsTrxnDetailEntity savingsTrxn = (SavingsTrxnDetailEntity) accntTrxn;
        if (accountPayment.isSavingsWithdrawal() && amountAdjustedTo.isGreaterThan(savingsTrxn.getWithdrawlAmount())) {
            balanceAfterAdjust = balanceAfterAdjust.subtract(amountAdjustedTo.subtract(savingsTrxn.getWithdrawlAmount()));
            if (balanceAfterAdjust.isLessThanZero()) {
                balanceIsPositive = false;
            }
        }
    }
    return balanceIsPositive;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity)

Example 14 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class SavingsBO method adjustUserAction.

private AccountPaymentEntity adjustUserAction(Money amountAdjustedTo, String adjustmentNote, LocalDate adjustmentDate, PersonnelBO updatedBy, AccountPaymentEntity payment) {
    AccountPaymentEntity newPayment = null;
    try {
        if (!isAdjustPossibleOnTrxn(amountAdjustedTo, payment)) {
            throw new BusinessRuleException(AccountExceptionConstants.CANNOTADJUST);
        }
        AccountActionTypes savingsTransactionType = findFirstDepositOrWithdrawalTransaction(payment);
        Date adjustedOn = new DateTimeService().getCurrentJavaDateTime();
        List<AccountTrxnEntity> reversedTransactions = reverseTransaction(adjustmentNote, updatedBy, payment, savingsTransactionType, adjustedOn);
        buildFinancialEntries(new LinkedHashSet<AccountTrxnEntity>(reversedTransactions));
        if (amountAdjustedTo.isGreaterThanZero()) {
            Set<AccountTrxnEntity> adjustedPaymentTransactions = createNewAccountPaymentWithAdjustedAmount(amountAdjustedTo, updatedBy, payment, savingsTransactionType, adjustedOn, adjustmentDate);
            buildFinancialEntries(adjustedPaymentTransactions);
            newPayment = adjustedPaymentTransactions.toArray(new AccountTrxnEntity[adjustedPaymentTransactions.size()])[0].getAccountPayment();
        }
    } catch (AccountException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
    goActiveDueToDepositOrWithdrawalOnAccount(updatedBy);
    return newPayment;
}
Also used : AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountException(org.mifos.accounts.exceptions.AccountException) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 15 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.

the class LoanAccountServiceFacadeWebTier method getApplicablePayments.

private List<LoanActivityDto> getApplicablePayments(LoanBO loan) {
    List<LoanActivityDto> payments = new ArrayList<LoanActivityDto>();
    List<AccountPaymentEntity> accountPayments = loan.getAccountPayments();
    int i = accountPayments.size() - 1;
    if (accountPayments.size() > 0) {
        for (AccountPaymentEntity accountPayment : accountPayments) {
            if (accountPayment.getAmount().isGreaterThanZero()) {
                Money amount = new Money(accountPayment.getAmount().getCurrency());
                if (i == 0) {
                    for (AccountTrxnEntity accountTrxn : accountPayment.getAccountTrxns()) {
                        short accountActionTypeId = accountTrxn.getAccountActionEntity().getId().shortValue();
                        boolean isLoanRepayment = accountActionTypeId == AccountActionTypes.LOAN_REPAYMENT.getValue();
                        boolean isFeeRepayment = accountActionTypeId == AccountActionTypes.FEE_REPAYMENT.getValue();
                        if (isLoanRepayment || isFeeRepayment) {
                            amount = amount.add(accountTrxn.getAmount());
                        }
                    }
                } else {
                    amount = accountPayment.getAmount();
                }
                if (amount.isGreaterThanZero()) {
                    LoanActivityDto loanActivityDto = new LoanActivityDto();
                    loanActivityDto.setActionDate(accountPayment.getPaymentDate());
                    loanActivityDto.setTotal(amount.toString());
                    loanActivityDto.setTotalValue(amount.getAmount().doubleValue());
                    payments.add(0, loanActivityDto);
                }
            }
            i--;
        }
    }
    return payments;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) LoanActivityDto(org.mifos.dto.domain.LoanActivityDto) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity)

Aggregations

AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)36 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)22 Test (org.junit.Test)15 Money (org.mifos.framework.util.helpers.Money)14 LocalDate (org.joda.time.LocalDate)8 Date (java.sql.Date)7 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 AccountException (org.mifos.accounts.exceptions.AccountException)6 PaymentData (org.mifos.accounts.util.helpers.PaymentData)6 CustomerBO (org.mifos.customers.business.CustomerBO)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)6 FeesTrxnDetailEntity (org.mifos.accounts.business.FeesTrxnDetailEntity)5 DateTimeService (org.mifos.framework.util.DateTimeService)5 LinkedHashSet (java.util.LinkedHashSet)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)3 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)3 FinancialTransactionBO (org.mifos.accounts.financial.business.FinancialTransactionBO)3