Search in sources :

Example 26 with AccountTrxnEntity

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

the class SavingsBO method createDepositTrxnsForMandatoryAccountsAfterAdjust.

private Set<AccountTrxnEntity> createDepositTrxnsForMandatoryAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO createdBy) {
    Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
    SavingsTrxnDetailEntity accountTrxn = null;
    CustomerBO customer = null;
    Date trxnDate = adjustmentDate.toDateMidnight().toDate();
    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        customer = oldAccntTrxn.getCustomer();
        break;
    }
    List<AccountActionDateEntity> accountActionList = getAccountActions(lastAccountPayment.getPaymentDate(), customer.getCustomerId());
    for (AccountActionDateEntity accountActionDateEntity : accountActionList) {
        SavingsScheduleEntity accountAction = (SavingsScheduleEntity) accountActionDateEntity;
        if (newAmount.isZero()) {
            break;
        }
        accountTrxn = null;
        // if payment covers required deposit
        if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
            this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
            Short installmentId = accountAction.getInstallmentId();
            Date dueDate = accountAction.getActionDate();
            Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
            accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
            newAmount = newAmount.subtract(accountAction.getDeposit());
            accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
            accountAction.setPaymentStatus(PaymentStatus.PAID);
        } else {
            this.savingsBalance = this.savingsBalance.add(newAmount);
            Short installmentId = accountAction.getInstallmentId();
            Date dueDate = accountAction.getActionDate();
            Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
            accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
            newAmount = newAmount.subtract(newAmount);
            accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
            accountAction.setPaymentStatus(PaymentStatus.UNPAID);
        }
        accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
        getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
        newTrxns.add(accountTrxn);
    }
    // add trxn for excess amount
    if (newAmount.isGreaterThanZero()) {
        this.savingsBalance = this.savingsBalance.add(newAmount);
        Short installmentId = null;
        Date dueDate = null;
        Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
        accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
        newAmount = newAmount.subtract(newAmount);
        getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
        newTrxns.add(accountTrxn);
    }
    return newTrxns;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 27 with AccountTrxnEntity

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

the class SavingsBO method createDepositTrxnsForVolAccountsAfterAdjust.

/*
     * FIXME - keithw - it doesnt make sense to be that voluntary account break up account payments into more than one account transaction
     * just because the amount deposited is greater than the 'recommended' amount.
     *
     * As a result there is no need to make a distinction between the amount deposited (be it less or greater than recommended amount)
     */
private Set<AccountTrxnEntity> createDepositTrxnsForVolAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO loggedInUser) {
    Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
    SavingsTrxnDetailEntity accountTrxn = null;
    CustomerBO customer = null;
    Date trxnDate = adjustmentDate.toDateMidnight().toDate();
    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        customer = oldAccntTrxn.getCustomer();
        break;
    }
    Short installmentId = null;
    Date dueDate = null;
    Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        if (oldAccntTrxn.getAccountActionEntity().getId().equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
            SavingsTrxnDetailEntity oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
            if (oldAccntTrxn.getInstallmentId() != null) {
                SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(oldSavingsAccntTrxn.getInstallmentId(), oldSavingsAccntTrxn.getCustomer().getCustomerId());
                installmentId = accountAction.getInstallmentId();
                dueDate = accountAction.getActionDate();
                // if recommended amount is covered by payment
                if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
                    this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
                    accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
                    newAmount = newAmount.subtract(accountAction.getDeposit());
                    accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
                    accountAction.setPaymentStatus(PaymentStatus.PAID);
                    accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
                    this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
                } else if (newAmount.isNonZero()) {
                    // not zero and amount paid is less that recommended amount
                    this.savingsBalance = this.savingsBalance.add(newAmount);
                    accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
                    newAmount = newAmount.subtract(newAmount);
                    accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
                    accountAction.setPaymentStatus(PaymentStatus.UNPAID);
                    accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
                    this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
                }
                break;
            }
        }
    }
    if (accountTrxn != null) {
        newTrxns.add(accountTrxn);
    }
    // Create a new transaction with remaining amount
    if (newAmount.isGreaterThanZero()) {
        this.savingsBalance = this.savingsBalance.add(newAmount);
        accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
        this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
        newTrxns.add(accountTrxn);
    }
    return newTrxns;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 28 with AccountTrxnEntity

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

the class FinancialBusinessServiceIntegrationTest method testLoanAdjustmentAccountingEntries.

@Test
public void testLoanAdjustmentAccountingEntries() throws Exception {
    Date currentDate = new Date(System.currentTimeMillis());
    loan = getLoanAccount();
    loan.setUserContext(TestUtils.makeUser());
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loan, TestUtils.createMoney(630), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    FinancialBusinessService financialBusinessService = new FinancialBusinessService();
    AccountTrxnEntity accountTrxnEntity = getAccountTrxnObj(accountPaymentEntity);
    accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, loan);
    financialBusinessService.buildAccountingEntries(accountTrxnEntity);
    TestObjectFactory.updateObject(loan);
    for (FinancialTransactionBO finTrxn : accountTrxnEntity.getFinancialTransactions()) {
        if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("1")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("200"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("200"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("1")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("200"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("200"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("22"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("2")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("300"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("300"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("2")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("300"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("300"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("43"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("3")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("3")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("52"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("4")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("10"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("10"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("4")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("10"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("10"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("52"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("6")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("20"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("20"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("6")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("20"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("20"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("44"));
        } else {
        //--fail("There should not be any other entry");
        }
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 29 with AccountTrxnEntity

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

the class StandardAccountServiceIntegrationTest method testMakePaymentForLoanAccount.

@Test
public void testMakePaymentForLoanAccount() throws Exception {
    String payemntAmount = "700";
    CustomerDto clientDto = new CustomerDto();
    clientDto.setCustomerId(client.getCustomerId());
    LocalDate paymentDate = new LocalDate();
    LocalDate receiptDate = new LocalDate().minusDays(3);
    String receiptNumber = "AA/03/UX-9Q";
    AccountPaymentParametersDto loanPayment = new AccountPaymentParametersDto(new UserReferenceDto(groupLoan.getPersonnel().getPersonnelId()), new AccountReferenceDto(groupLoan.getAccountId()), new BigDecimal(payemntAmount), paymentDate, defaultPaymentType, "comment", receiptDate, receiptNumber, clientDto);
    standardAccountService.makePayment(loanPayment);
    TestObjectFactory.updateObject(groupLoan);
    Assert.assertEquals("The amount returned for the payment should have been " + payemntAmount, Double.parseDouble(payemntAmount), groupLoan.getLastPmntAmnt());
    Assert.assertEquals(1, groupLoan.getAccountPayments().size());
    for (AccountPaymentEntity payment : groupLoan.getAccountPayments()) {
        Assert.assertEquals(TestUtils.createMoney(payemntAmount), payment.getAmount());
        Assert.assertEquals(paymentDate.toDateMidnight().toDate(), payment.getPaymentDate());
        Assert.assertEquals(defaultPaymentType.getName(), payment.getPaymentType().getName());
        Assert.assertEquals("comment", payment.getComment());
        Assert.assertEquals(groupLoan, payment.getAccount());
        Assert.assertEquals(groupLoan.getPersonnel(), payment.getCreatedByUser());
        Assert.assertEquals(receiptDate.toDateMidnight().toDate(), payment.getReceiptDate());
        Assert.assertEquals(receiptNumber, payment.getReceiptNumber());
        Assert.assertNull(payment.getCheckNumber());
        Assert.assertNull(payment.getBankName());
        Assert.assertNull(payment.getVoucherNumber());
        Assert.assertFalse(payment.isSavingsDeposit());
        Assert.assertFalse(payment.isSavingsWithdrawal());
        Assert.assertFalse(payment.isSavingsDepositOrWithdrawal());
        for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
            Assert.assertEquals(group.getCustomerId(), accountTrxn.getCustomer().getCustomerId());
        }
    }
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) CustomerDto(org.mifos.dto.domain.CustomerDto) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 30 with AccountTrxnEntity

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

the class LoanBO method buildLoanActivity.

private LoanActivityEntity buildLoanActivity(final Collection<AccountTrxnEntity> accountTrxnDetails, final PersonnelBO personnel, String comments, final Date trxnDate) {
    Date activityDate = trxnDate;
    Money principal = new Money(getCurrency());
    Money interest = new Money(getCurrency());
    Money penalty = new Money(getCurrency());
    Money fees = new Money(getCurrency());
    for (AccountTrxnEntity accountTrxn : accountTrxnDetails) {
        if (!accountTrxn.isTrxnForReversalOfLoanDisbursal()) {
            LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) accountTrxn;
            principal = principal.add(removeSign(loanTrxn.getPrincipalAmount()));
            interest = interest.add(removeSign(loanTrxn.getInterestAmount()));
            penalty = penalty.add(removeSign(loanTrxn.getPenaltyAmount())).add(removeSign(loanTrxn.getMiscPenaltyAmount()));
            fees = fees.add(removeSign(loanTrxn.getMiscFeeAmount()));
            for (FeesTrxnDetailEntity feesTrxn : loanTrxn.getFeesTrxnDetails()) {
                fees = fees.add(removeSign(feesTrxn.getFeeAmount()));
            }
        }
        if (accountTrxn.isTrxnForReversalOfLoanDisbursal() || accountTrxn.getAccountActionEntity().getId().equals(AccountActionTypes.LOAN_REVERSAL.getValue())) {
            comments = "Loan Reversal";
        }
    }
    Money interestOutstanding = loanSummary.getOriginalInterest().subtract(loanSummary.getInterestPaid());
    if (isDecliningBalanceInterestRecalculation()) {
        for (LoanScheduleEntity loanScheduleEntity : getLoanScheduleEntities()) {
            interestOutstanding = interestOutstanding.add(loanScheduleEntity.getExtraInterest());
        }
    }
    return new LoanActivityEntity(this, personnel, comments, principal, loanSummary.getOriginalPrincipal().subtract(loanSummary.getPrincipalPaid()), interest, interestOutstanding, fees, loanSummary.getOriginalFees().subtract(loanSummary.getFeesPaid()), penalty, loanSummary.getOriginalPenalty().subtract(loanSummary.getPenaltyPaid()), activityDate);
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

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