Search in sources :

Example 91 with AccountPaymentEntity

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

the class SavingsBOIntegrationTest method createSavingsAccountPayment.

private SavingsBO createSavingsAccountPayment() throws Exception {
    AccountPaymentEntity payment;
    createInitialObjects();
    savingsOffering = helper.createSavingsOffering("2333dsf", "2132");
    savings = helper.createSavingsAccount(savingsOffering, group, AccountState.SAVINGS_ACTIVE, userContext);
    Money initialBal = new Money(currency, "5500");
    payment = helper.createAccountPayment(savings, null, new Money(currency, "5500.0"), new Date(), createdBy);
    SavingsTrxnDetailEntity adjustment = SavingsTrxnDetailEntity.savingsAdjustment(payment, group, initialBal, initialBal, createdBy, helper.getDate("04/01/2006"), helper.getDate("04/01/2006"), new DateTime().toDate(), "", null);
    payment.addAccountTrxn(adjustment);
    AccountTestUtils.addAccountPayment(payment, savings);
    savings.update();
    return TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 92 with AccountPaymentEntity

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

the class SavingsClosureActionStrutsTest method testSuccessfullPreview_withoutReceipt.

@Test
public void testSuccessfullPreview_withoutReceipt() throws Exception {
    AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
    addRequestParameter("receiptId", "");
    addRequestParameter("receiptDate", "");
    addRequestParameter("paymentTypeId", "1");
    addRequestParameter("customerId", "1");
    addRequestParameter("notes", "notes");
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "preview");
    actionPerform();
    verifyForward("preview_success");
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) Test(org.junit.Test)

Example 93 with AccountPaymentEntity

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

the class SavingsClosureActionStrutsTest method testPreviewDateValidation.

@Test
public void testPreviewDateValidation() throws Exception {
    AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
    addRequestParameter("receiptId", "101");
    // an invalid date
    String badDate = "3/20/2005";
    addRequestParameter("receiptDate", badDate);
    addRequestParameter("paymentTypeId", "1");
    addRequestParameter("customerId", "1");
    addRequestParameter("notes", "notes");
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "preview");
    actionPerform();
    verifyActionErrors(new String[] { AccountConstants.ERROR_INVALIDDATE });
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) Test(org.junit.Test)

Example 94 with AccountPaymentEntity

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

the class SavingsClosureActionStrutsTest method testSuccessfullPreviewWithNullPaymentId.

@Test
public void testSuccessfullPreviewWithNullPaymentId() throws Exception {
    AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
    addRequestParameter("receiptId", "101");
    addRequestParameter("receiptDate", "");
    // paymentTypeId is left null
    addRequestParameter("customerId", "1");
    addRequestParameter("notes", "notes");
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "preview");
    actionPerform();
    verifyNoActionErrors();
    verifyForward("preview_success");
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) Test(org.junit.Test)

Example 95 with AccountPaymentEntity

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

the class LoanBO method disburseLoan.

private void disburseLoan(final String receiptNum, final Date transactionDate, final Short paymentTypeId, final PersonnelBO loggedInUser, final Date receiptDate, final Short rcvdPaymentTypeId, final boolean persistChange, final Short paymentTypeIdForFees, Integer accountForTransferId) throws AccountException, PersistenceException {
    if ((this.getState().compareTo(AccountState.LOAN_APPROVED) != 0) && (this.getState().compareTo(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER) != 0)) {
        throw new AccountException("Loan not in a State to be Disbursed: " + this.getState().toString());
    }
    if (this.getCustomer().isDisbursalPreventedDueToAnyExistingActiveLoansForTheSameProduct(this.getLoanOffering())) {
        throw new AccountException("errors.cannotDisburseLoan.because.otherLoansAreActive");
    }
    try {
        new ProductMixValidator().checkIfProductsOfferingCanCoexist(this);
    } catch (ServiceException e1) {
        throw new AccountException(e1.getMessage());
    }
    addLoanActivity(buildLoanActivity(this.loanAmount, loggedInUser, AccountConstants.LOAN_DISBURSAL, transactionDate));
    // regenerate the installments
    if (!isFixedRepaymentSchedule() && !DateUtils.getDateWithoutTimeStamp(disbursementDate.getTime()).equals(DateUtils.getDateWithoutTimeStamp(transactionDate.getTime()))) {
        final boolean lsimEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
        if (lsimEnabled) {
            // QUESTION: does minDays
            final int minDaysInterval = new ConfigurationPersistence().getConfigurationValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY);
            this.disbursementDate = new DateTime(transactionDate).plusDays(minDaysInterval - 1).toDate();
        } else {
            this.disbursementDate = transactionDate;
        }
        regeneratePaymentSchedule(lsimEnabled, null);
        if (this.isParentGroupLoanAccount()) {
            groupLoanAccountServiceFacade.fixMemberAndParentInstallmentDetails(this.getAccountId());
        }
    }
    this.disbursementDate = transactionDate;
    final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
    this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(this.getAccountState(), newState, loggedInUser, this));
    this.setAccountState(newState);
    //
    // Client performance entry
    updateCustomerHistoryOnDisbursement(this.loanAmount);
    if (getPerformanceHistory() != null) {
        getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
    }
    //
    //
    // build up account payment related data
    AccountPaymentEntity accountPayment = null;
    if (this.isInterestDeductedAtDisbursement()) {
        // the 1st payment is made and creates an initial accountPaymentEntity.
        // This disbursal process carries on with that accountPaymentEntity by updating the 'amount' to the actual
        // disbursed amount.
        accountPayment = payInterestAtDisbursement(receiptNum, transactionDate, rcvdPaymentTypeId, loggedInUser, receiptDate);
        accountPayment.setAmount(this.loanAmount.subtract(accountPayment.getAmount()));
    } else {
        // Disbursal process has to create its own accountPayment taking into account any disbursement fees
        Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
        accountPayment = new AccountPaymentEntity(this, this.loanAmount.subtract(feeAmountAtDisbursement), receiptNum, receiptDate, getPaymentTypeEntity(paymentTypeId), transactionDate);
        accountPayment.setCreatedByUser(loggedInUser);
        if (feeAmountAtDisbursement.isGreaterThanZero()) {
            processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, paymentTypeIdForFees, accountForTransferId);
        }
    }
    // create trxn entry for disbursal
    final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, loggedInUser, transactionDate, this.loanAmount, "-", null, this.loanAmount, new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
    accountPayment.addAccountTrxn(loanTrxnDetailEntity);
    this.addAccountPayment(accountPayment);
    this.buildFinancialEntries(accountPayment.getAccountTrxns());
    if (persistChange) {
        try {
            ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
        } catch (PersistenceException e) {
            throw new AccountException(e);
        }
    }
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) DateTime(org.joda.time.DateTime) Money(org.mifos.framework.util.helpers.Money) ProductMixValidator(org.mifos.accounts.loan.struts.action.validate.ProductMixValidator) AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

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