Search in sources :

Example 21 with AccountTrxnEntity

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

the class CustomerAccountBOIntegrationTest method testActivityForMultiplePayments.

@Test
public void testActivityForMultiplePayments() throws Exception {
    // setup
    createCenter();
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    Assert.assertNotNull(customerAccount);
    Date transactionDate = incrementCurrentDate(14);
    final Money paymentForThisInstallmentAndLastTwoInstallmentsInArrears = TestUtils.createMoney("300.0");
    List<AccountActionDateEntity> dueActionDates = TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate);
    Assert.assertEquals("The size of the due insallments is ", dueActionDates.size(), 3);
    PaymentData accountPaymentDataView = TestObjectFactory.getCustomerAccountPaymentDataView(dueActionDates, paymentForThisInstallmentAndLastTwoInstallmentsInArrears, null, center.getPersonnel(), "3424324", Short.valueOf("1"), transactionDate, transactionDate);
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    customerAccount = center.getCustomerAccount();
    // exercise test
    customerAccount.applyPayment(accountPaymentDataView);
    // verification
    assertThat(customerAccount.getCustomerActivitDetails().size(), is(1));
    assertThat("The size of the payments done is", customerAccount.getAccountPayments().size(), is(1));
    assertThat("The size of the due insallments after payment is", TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate).size(), is(0));
    assertThat(customerAccount.getAccountPayments().size(), is(1));
    for (AccountPaymentEntity accountPayment : customerAccount.getAccountPayments()) {
        assertThat(accountPayment.getAccountTrxns().size(), is(3));
        for (AccountTrxnEntity accountTrxnEntity : accountPayment.getAccountTrxns()) {
            assertThat(accountTrxnEntity.getFinancialTransactions().size(), is(2));
        }
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 22 with AccountTrxnEntity

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

the class AdminDocumentsServiceImpl method getAdminDocumentsForAccountPayment.

@Override
public List<AdminDocumentDto> getAdminDocumentsForAccountPayment(Integer paymentId) {
    try {
        List<AdminDocumentDto> adminDocuments = new ArrayList<AdminDocumentDto>();
        AccountPaymentEntity accountPaymentEntity = legacyAccountDao.findPaymentById(paymentId);
        Set<AccountTrxnEntity> accountTrxnEntities = accountPaymentEntity.getAccountTrxns();
        for (AccountTrxnEntity accountTrxnEntity : accountTrxnEntities) {
            List<AdminDocumentBO> adminDocumentBOs = legacyAdminDocumentDao.getActiveAdminDocumentsByAccountActionId(accountTrxnEntity.getAccountActionEntity().getId());
            if (adminDocumentBOs != null && !adminDocumentBOs.isEmpty()) {
                for (AdminDocumentBO adminDocumentBO : adminDocumentBOs) {
                    AdminDocumentDto adminDocumentDto = new AdminDocumentDto(adminDocumentBO.getAdmindocId().intValue(), adminDocumentBO.getAdminDocumentName(), adminDocumentBO.getAdminDocumentIdentifier(), BooleanUtils.toBoolean(adminDocumentBO.getIsActive().intValue()));
                    if (!adminDocuments.contains(adminDocumentDto)) {
                        adminDocuments.add(adminDocumentDto);
                    }
                }
            }
        }
        return adminDocuments;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AdminDocumentBO(org.mifos.reports.admindocuments.business.AdminDocumentBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AdminDocumentDto(org.mifos.dto.domain.AdminDocumentDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 23 with AccountTrxnEntity

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

the class ImportTransactionsServiceFacadeWebTier method getUndoImportDateToValidate.

/**
     * Method currently returns last problem found for each account.
     */
@Override
public Map<String, Map<String, String>> getUndoImportDateToValidate(String importTransactionsFileName) {
    Map<String, Map<String, String>> validationResults = new HashMap<String, Map<String, String>>();
    Map<String, String> accountStatusValidationResults = new HashMap<String, String>();
    ;
    Map<String, String> trxnToUndo = new HashMap<String, String>();
    ;
    List<AccountTrxnEntity> trxnData = new ArrayList<AccountTrxnEntity>(this.importedFilesService.getImportedFileByName(importTransactionsFileName).getImportedTrxn());
    TreeSet<String> accountsWithAdjustedPayments = new TreeSet<String>();
    Integer iterator = 0;
    Boolean error_flag = Boolean.FALSE;
    for (AccountTrxnEntity trxn : trxnData) {
        error_flag = Boolean.FALSE;
        if (trxn.getAccount().getAccountState().isLoanCanceled() || trxn.getAccount().getAccountState().isLoanClosedWrittenOff()) {
            accountStatusValidationResults.put(trxn.getAccount().getGlobalAccountNum(), ApplicationContextProvider.getBean(MessageLookup.class).lookup("ftlDefinedLabels.undoImport.invalidAccountState") + trxn.getAccount().getAccountState().getName());
            error_flag = Boolean.TRUE;
        } else {
            try {
                validateForAdjustedPayments(trxn, accountsWithAdjustedPayments);
                monthClosingServiceFacade.validateTransactionDate(trxn.getAccountPayment().getPaymentDate());
            } catch (BusinessRuleException e) {
                accountStatusValidationResults.put(trxn.getAccount().getGlobalAccountNum(), ApplicationContextProvider.getBean(MessageLookup.class).lookup(e.getMessageKey()));
                error_flag = Boolean.TRUE;
            }
        }
        if (error_flag) {
            iterator += 1;
        }
    }
    Integer valid_trxn = trxnData.size() - iterator;
    validationResults.put(INVALID_TRXN, accountStatusValidationResults);
    trxnToUndo.put(valid_trxn.toString(), ((Integer) trxnData.size()).toString());
    validationResults.put(VALID_TRXN, trxnToUndo);
    return validationResults;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) TreeSet(java.util.TreeSet) MessageLookup(org.mifos.application.master.MessageLookup) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with AccountTrxnEntity

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

the class ImportedFilesServiceImpl method saveImportedFileName.

@Override
public void saveImportedFileName(String fileName, PersonnelBO submittedBy, List<AccountTrxDto> idsToUndoImport, Boolean phaseOut, Boolean undoable) {
    Timestamp submittedOn = new Timestamp(new DateTimeService().getCurrentDateTime().getMillis());
    Set<AccountTrxnEntity> accTrxEnt = new HashSet<AccountTrxnEntity>();
    ImportedFilesEntity importedFile = new ImportedFilesEntity(fileName, submittedOn, submittedBy, accTrxEnt, phaseOut, undoable);
    if (null != idsToUndoImport) {
        for (AccountTrxDto trx : idsToUndoImport) {
            accTrxEnt.add(importedFileDao.getAccTrxById(trx.getId()));
        }
        importedFile.setImportedTrxn(accTrxEnt);
    }
    try {
        hibernateTransactionHelper.startTransaction();
        importedFileDao.saveImportedFile(importedFile);
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountTrxDto(org.mifos.dto.domain.AccountTrxDto) Timestamp(java.sql.Timestamp) DateTimeService(org.mifos.framework.util.DateTimeService) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) HashSet(java.util.HashSet) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 25 with AccountTrxnEntity

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

the class LoanBOTest method repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest.

@Test
public void repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest() throws PersistenceException {
    final LegacyLoanDao legacyLoanDao = mock(LegacyLoanDao.class);
    final CustomerBO customerBO = mock(CustomerBO.class);
    final LoanSummaryEntity loanSummaryEntity = mock(LoanSummaryEntity.class);
    LoanBO loanBO = new LoanBO() {

        @Override
        public boolean isDecliningBalanceInterestRecalculation() {
            return true;
        }

        @Override
        public LegacyLoanDao getlegacyLoanDao() {
            return legacyLoanDao;
        }

        @Override
        public CustomerBO getCustomer() {
            return customerBO;
        }

        @Override
        public LoanSummaryEntity getLoanSummary() {
            return loanSummaryEntity;
        }

        @Override
        public MifosCurrency getCurrency() {
            return rupee;
        }
    };
    AccountActionTypes accountActionTypes = AccountActionTypes.LOAN_REPAYMENT;
    AccountActionEntity accountActionEntity = mock(AccountActionEntity.class);
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntityBuilder().with(loanBO).build();
    PersonnelBO user = new PersonnelBO();
    Money extraInterestDue = new Money(rupee, "0.98");
    Money interest = new Money(rupee, "10");
    Money interestDue = new Money(rupee, "0");
    when(legacyLoanDao.getPersistentObject(AccountActionEntity.class, accountActionTypes.getValue())).thenReturn(accountActionEntity);
    when(loanScheduleEntity.getPrincipalDue()).thenReturn(new Money(rupee, "1000"));
    when(loanScheduleEntity.getTotalFeeDueWithMiscFeeDue()).thenReturn(new Money(rupee, "10"));
    when(loanScheduleEntity.getPenaltyDue()).thenReturn(new Money(rupee, "10"));
    when(loanScheduleEntity.getPenalty()).thenReturn(new Money(rupee, "100"));
    when(loanScheduleEntity.getExtraInterestDue()).thenReturn(extraInterestDue);
    when(loanScheduleEntity.getExtraInterestPaid()).thenReturn(extraInterestDue);
    when(loanScheduleEntity.getInterest()).thenReturn(interest);
    loanBO.repayInstallmentWithInterestWaiver(loanScheduleEntity, accountPaymentEntity, "", accountActionTypes, user);
    Set<AccountTrxnEntity> accountTrxns = accountPaymentEntity.getAccountTrxns();
    AccountTrxnEntity accountTrxnEntity = accountTrxns.toArray(new AccountTrxnEntity[accountTrxns.size()])[0];
    LoanTrxnDetailEntity loanTrxnDetailEntity = (LoanTrxnDetailEntity) accountTrxnEntity;
    assertThat(loanTrxnDetailEntity.getInterestAmount().getAmount().doubleValue(), is(0.98));
    CalculatedInterestOnPayment calculatedInterestOnPayment = loanTrxnDetailEntity.getCalculatedInterestOnPayment();
    assertNotNull(calculatedInterestOnPayment);
    assertThat(calculatedInterestOnPayment.getExtraInterestPaid(), is(extraInterestDue));
    assertThat(calculatedInterestOnPayment.getInterestDueTillPaid(), is(interestDue));
    assertThat(calculatedInterestOnPayment.getOriginalInterest(), is(interest));
    Mockito.verify(loanScheduleEntity).makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY, interestDue, accountPaymentEntity.getPaymentDate());
}
Also used : AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerBO(org.mifos.customers.business.CustomerBO) LegacyLoanDao(org.mifos.accounts.loan.persistance.LegacyLoanDao) Test(org.junit.Test)

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