Search in sources :

Example 76 with AccountPaymentEntity

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

the class SavingsDepositWithdrawalAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
    clearActionForm(actionForm);
    Long savingsId = savings.getAccountId().longValue();
    Integer customerId = savings.getCustomer().getCustomerId();
    if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
        customerId = Integer.valueOf(actionForm.getCustomerId());
    }
    DepositWithdrawalReferenceDto depositWithdrawalReferenceDto = this.savingsServiceFacade.retrieveDepositWithdrawalReferenceData(savingsId, customerId);
    savings = this.savingsDao.findById(savingsId);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    if (savings.isGroupModelWithIndividualAccountability()) {
        List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savings.getCustomer().getSearchId(), savings.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
        SessionUtils.setCollectionAttribute(SavingsConstants.CLIENT_LIST, activeAndOnHoldClients, request);
    } else {
        SessionUtils.setAttribute(SavingsConstants.CLIENT_LIST, new ArrayList<CustomerBO>(), request);
    }
    LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
    List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_deposit.getValue());
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
    List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
    trxnTypes.add(getAccountsService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), uc.getLocaleId()));
    trxnTypes.add(getAccountsService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), uc.getLocaleId()));
    SessionUtils.setCollectionAttribute(AccountConstants.TRXN_TYPES, trxnTypes, request);
    SessionUtils.setAttribute(SavingsConstants.IS_BACKDATED_TRXN_ALLOWED, depositWithdrawalReferenceDto.isBackDatedTransactionsAllowed(), request);
    AccountPaymentEntity lastPayment = savings.findMostRecentDepositOrWithdrawalByDate();
    if (lastPayment != null) {
        actionForm.setLastTrxnDate(lastPayment.getPaymentDate());
    }
    actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : UserContext(org.mifos.security.util.UserContext) SavingsDepositWithdrawalActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) DepositWithdrawalReferenceDto(org.mifos.dto.screen.DepositWithdrawalReferenceDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 77 with AccountPaymentEntity

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

the class FinancialBusinessServiceIntegrationTest method testLoanRescheduleAccountingEntries.

@Test
public void testLoanRescheduleAccountingEntries() throws Exception {
    loan = getLoanAccount();
    loan.setUserContext(TestUtils.makeUser());
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loan, TestUtils.createMoney(630), null, null, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    FinancialBusinessService financialBusinessService = new FinancialBusinessService();
    AccountActionDateEntity accountActionDateEntity = loan.getAccountActionDate(Short.valueOf("1"));
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(loan.getUserContext().getId());
    LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.LOAN_RESCHEDULED, accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate(), personnel, new Date(System.currentTimeMillis()), ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), "Loan Rescheduled", null, ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
    accountPaymentEntity.addAccountTrxn(loanTrxnDetailEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, loan);
    financialBusinessService.buildAccountingEntries(loanTrxnDetailEntity);
    TestObjectFactory.updateObject(loan);
    Set<FinancialTransactionBO> finTrxnSet = loanTrxnDetailEntity.getFinancialTransactions();
    Assert.assertEquals(finTrxnSet.size(), 2);
    for (FinancialTransactionBO finTrxn : finTrxnSet) {
        if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("23")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("22"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("23")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
        } else {
            Assert.fail("There should not be any other entry");
        }
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 78 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity 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 79 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity 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 80 with AccountPaymentEntity

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

the class LegacyAccountDaoIntegrationTest method testFindingAccountPaymentShouldReturnZeroPayments.

@Test
public void testFindingAccountPaymentShouldReturnZeroPayments() throws Exception {
    savingsBO = createSavingsAccount();
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(savingsBO, TestUtils.createMoney(100), "2222", new Date(System.currentTimeMillis()), new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    List<AccountPaymentEntity> payments = new ArrayList<AccountPaymentEntity>();
    payments.add(accountPaymentEntity);
    savingsBO.setAccountPayments(payments);
    legacyAccountDao.createOrUpdate(savingsBO);
    StaticHibernateUtil.commitTransaction();
    List<AccountPaymentEntity> result = legacyAccountDao.findAccountPaymentsByReceiptNumber("1111");
    Assert.assertNotNull(result);
    Assert.assertEquals(0, result.size());
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)113 Money (org.mifos.framework.util.helpers.Money)56 Date (java.util.Date)43 LocalDate (org.joda.time.LocalDate)41 Test (org.junit.Test)36 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)34 AccountException (org.mifos.accounts.exceptions.AccountException)30 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)24 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)23 UserContext (org.mifos.security.util.UserContext)23 ArrayList (java.util.ArrayList)22 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)22 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 PaymentData (org.mifos.accounts.util.helpers.PaymentData)18 CustomerBO (org.mifos.customers.business.CustomerBO)18 AccountBO (org.mifos.accounts.business.AccountBO)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 BigDecimal (java.math.BigDecimal)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 Date (java.sql.Date)13