Search in sources :

Example 26 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.

the class SavingsClosureAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
    actionForm.clearForm();
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = Long.valueOf(savings.getAccountId());
    savings = this.savingsDao.findById(savingsId);
    savings.setUserContext(uc);
    // NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
    // use within Tag library in jsp.
    new SavingsPersistence().initialize(savings);
    LocalDate accountCloseDate = new LocalDate();
    SavingsAccountClosureDto closureDetails = this.savingsServiceFacade.retrieveClosingDetails(savingsId, accountCloseDate);
    LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
    List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
    Money interestAmountDue = new Money(savings.getCurrency(), closureDetails.getInterestAmountAtClosure());
    Money endOfAccountBalance = new Money(savings.getCurrency(), closureDetails.getBalance());
    Date transactionDate = closureDetails.getClosureDate().toDateMidnight().toDate();
    Money withdrawalAmountAtClosure = endOfAccountBalance.add(interestAmountDue);
    AccountPaymentEntity payment = new AccountPaymentEntity(savings, withdrawalAmountAtClosure, null, null, null, transactionDate);
    actionForm.setAmount(withdrawalAmountAtClosure.toString());
    actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
    return mapping.findForward("load_success");
}
Also used : SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) SavingsAccountClosureDto(org.mifos.dto.domain.SavingsAccountClosureDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 27 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.

the class SavingsClosureAction method preview.

@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
    AccountPaymentEntity payment = (AccountPaymentEntity) SessionUtils.getAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
    AccountPaymentEntity accountPaymentEntity = null;
    Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
    if (actionForm.getReceiptDate() != null && actionForm.getReceiptDate() != "") {
        accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), new java.util.Date(DateUtils.getDateAsSentFromBrowser(actionForm.getReceiptDate()).getTime()), new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
    } else {
        if (actionForm.getPaymentTypeId() != null && !actionForm.getPaymentTypeId().equals("")) {
            if (!(actionForm.getPaymentTypeId().equals(""))) {
                accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
            } else {
                accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
            }
        } else {
            accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
        }
    }
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, accountPaymentEntity, request);
    return closeSavingsQuestionnaire.fetchAppliedQuestions(mapping, actionForm, request, ActionForwards.preview_success);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 28 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity 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 29 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity 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 30 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity 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)

Aggregations

PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)40 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)24 LocalDate (org.joda.time.LocalDate)16 Money (org.mifos.framework.util.helpers.Money)16 Date (java.util.Date)15 ArrayList (java.util.ArrayList)13 UserContext (org.mifos.security.util.UserContext)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)10 Date (java.sql.Date)9 Test (org.junit.Test)9 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 PersistenceException (org.mifos.framework.exceptions.PersistenceException)8 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)8 CustomerBO (org.mifos.customers.business.CustomerBO)6 DateTime (org.joda.time.DateTime)4 AcceptedPaymentType (org.mifos.accounts.acceptedpaymenttype.business.AcceptedPaymentType)4 DateTimeService (org.mifos.framework.util.DateTimeService)4 BigDecimal (java.math.BigDecimal)3 LegacyAcceptedPaymentTypeDao (org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao)3