Search in sources :

Example 11 with AccountNotesEntity

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

the class SavingsDaoHibernate method searchNotes.

@SuppressWarnings("unchecked")
@Override
public NotesSearchResultsDto searchNotes(NoteSearchDto noteSearch) {
    Session session = StaticHibernateUtil.getSessionTL();
    Criteria criteriaQuery = session.createCriteria(AccountNotesEntity.class);
    criteriaQuery.add(Restrictions.eq("account.accountId", noteSearch.getAccountId()));
    criteriaQuery.addOrder(Order.desc("commentId"));
    Integer totalNumberOfSavingsNotes = 10;
    int firstResult = (noteSearch.getPage() * noteSearch.getPageSize()) - noteSearch.getPageSize();
    criteriaQuery.setFirstResult(firstResult);
    criteriaQuery.setMaxResults(noteSearch.getPageSize());
    List<AccountNotesEntity> pagedResults = criteriaQuery.list();
    List<CustomerNoteDto> pageDtoResults = new ArrayList<CustomerNoteDto>();
    for (AccountNotesEntity note : pagedResults) {
        pageDtoResults.add(new CustomerNoteDto(note.getCommentDate(), note.getComment(), note.getPersonnelName()));
    }
    SearchDetailsDto searchDetails = new SearchDetailsDto(totalNumberOfSavingsNotes.intValue(), firstResult, noteSearch.getPage(), noteSearch.getPageSize());
    NotesSearchResultsDto resultsDto = new NotesSearchResultsDto(searchDetails, pageDtoResults);
    return resultsDto;
}
Also used : SearchDetailsDto(org.mifos.dto.screen.SearchDetailsDto) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) ArrayList(java.util.ArrayList) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) NotesSearchResultsDto(org.mifos.dto.screen.NotesSearchResultsDto) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 12 with AccountNotesEntity

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

the class SavingsBO method toDto.

public SavingsAccountDetailDto toDto() {
    List<SavingsRecentActivityDto> recentActivity = this.getRecentAccountActivity(3);
    List<CustomerNoteDto> recentNoteDtos = new ArrayList<CustomerNoteDto>();
    List<AccountNotesEntity> recentNotes = this.getRecentAccountNotes();
    for (AccountNotesEntity accountNotesEntity : recentNotes) {
        recentNoteDtos.add(new CustomerNoteDto(accountNotesEntity.getCommentDate(), accountNotesEntity.getComment(), accountNotesEntity.getPersonnelName()));
    }
    SavingsPerformanceHistoryDto savingsPerformanceHistoryDto = new SavingsPerformanceHistoryDto(getActivationDate(), savingsPerformance.getTotalDeposits().toString(), savingsPerformance.getTotalWithdrawals().toString(), savingsPerformance.getTotalInterestEarned().toString(), savingsPerformance.getMissedDeposits() != null ? savingsPerformance.getMissedDeposits().toString() : "0");
    AccountActionDateEntity nextInstallment = getDetailsOfNextInstallment();
    return new SavingsAccountDetailDto(this.savingsOffering.toFullDto(), recentActivity, recentNoteDtos, this.recommendedAmount.toString(), this.globalAccountNum, getAccountId(), getState().getValue(), getState().name(), getSavingsBalance().toString(), nextInstallment != null ? nextInstallment.getActionDate() : null, getTotalAmountDue().toString(), getTotalAmountDueForNextInstallment().toString(), getTotalAmountInArrears().toString(), savingsPerformanceHistoryDto, this.savingsOffering.getSavingsTypeAsEnum().name(), this.customer.getCustomerId());
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) ArrayList(java.util.ArrayList) SavingsRecentActivityDto(org.mifos.dto.screen.SavingsRecentActivityDto) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) SavingsPerformanceHistoryDto(org.mifos.dto.domain.SavingsPerformanceHistoryDto) SavingsAccountDetailDto(org.mifos.dto.domain.SavingsAccountDetailDto)

Example 13 with AccountNotesEntity

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

the class SavingsServiceFacadeWebTier method addNote.

@Override
public void addNote(CreateAccountNote accountNote) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(accountNote.getCreatedById().shortValue());
    SavingsBO savingsAccount = this.savingsDao.findById(accountNote.getAccountId().longValue());
    AccountNotesEntity accountNotes = new AccountNotesEntity(new java.sql.Date(accountNote.getCommentDate().toDateMidnight().toDate().getTime()), accountNote.getComment(), createdBy, savingsAccount);
    try {
        this.transactionHelper.startTransaction();
        savingsAccount.updateDetails(userContext);
        savingsAccount.addAccountNotes(accountNotes);
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 14 with AccountNotesEntity

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

the class CollectionSheetServiceImplRetrieveSavingsAccountsIntegrationTest method testCollectionSheetRetrieveOnlyReturnsActiveAndInactiveSavingsAccounts.

/**
     * need to clean up test data set up
     */
@Ignore
@Test
public void testCollectionSheetRetrieveOnlyReturnsActiveAndInactiveSavingsAccounts() throws Exception {
    UserContext userContext = TestUtils.makeUser();
    collectionSheetRetrieveSavingsAccountsUtils.createSampleCenterHierarchy();
    SavingsBO centerSavingsAccount = (SavingsBO) legacyAccountDao.getAccount(collectionSheetRetrieveSavingsAccountsUtils.getCenterSavingsAccount().getAccountId());
    centerSavingsAccount.setUserContext(userContext);
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    centerSavingsAccount.changeStatus(AccountState.SAVINGS_INACTIVE, Short.valueOf("1"), "Make Center Savings Account Inactive", loggedInUser);
    SavingsBO clientSavings = (SavingsBO) legacyAccountDao.getAccount(collectionSheetRetrieveSavingsAccountsUtils.getClientOfGroupCompleteGroupSavingsAccount().getAccountId());
    AccountPaymentEntity payment = new AccountPaymentEntity(clientSavings, new Money(clientSavings.getCurrency()), null, null, new PaymentTypeEntity(Short.valueOf("1")), new Date());
    AccountNotesEntity notes = new AccountNotesEntity(new java.sql.Date(System.currentTimeMillis()), "close client savings account", TestObjectFactory.getPersonnel(userContext.getId()), clientSavings);
    clientSavings.setUserContext(userContext);
    clientSavings.closeAccount(payment, notes, clientSavings.getCustomer(), loggedInUser);
    IntegrationTestObjectMother.saveSavingsAccount(clientSavings);
    StaticHibernateUtil.flushSession();
    CollectionSheetDto collectionSheet = collectionSheetService.retrieveCollectionSheet(collectionSheetRetrieveSavingsAccountsUtils.getCenter().getCustomerId(), new LocalDate());
    List<CollectionSheetCustomerDto> customers = collectionSheet.getCollectionSheetCustomer();
    for (CollectionSheetCustomerDto customer : customers) {
        for (CollectionSheetCustomerSavingDto customerSaving : customer.getCollectionSheetCustomerSaving()) {
            Boolean accountIsActiveOrInactive = false;
            AccountBO accountBO = legacyAccountDao.getAccount(customerSaving.getAccountId());
            if ((accountBO.getState().equals(AccountState.SAVINGS_ACTIVE)) || (accountBO.getState().equals(AccountState.SAVINGS_INACTIVE))) {
                accountIsActiveOrInactive = true;
            }
            Assert.assertTrue("Found Account State: " + accountBO.getState().toString() + " - Only Active and Inactive Savings Accounts are Allowed", accountIsActiveOrInactive);
        }
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with AccountNotesEntity

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

the class SaveCollectionSheetStructureValidatorIntegrationTest method ignore_testShouldGetINVALID_SAVINGS_ACCOUNT_STATUSIfSavingsAccountClosed.

public void ignore_testShouldGetINVALID_SAVINGS_ACCOUNT_STATUSIfSavingsAccountClosed() throws Exception {
    LocalDate transactionDate = new LocalDate();
    // create a center hierarchy with savings accounts
    collectionSheetRetrieveSavingsAccountsUtils.createSampleCenterHierarchy();
    // retrieve the collection sheet for today
    CollectionSheetService collectionSheetService = ApplicationContextProvider.getBean(CollectionSheetService.class);
    CollectionSheetDto collectionSheet = collectionSheetService.retrieveCollectionSheet(collectionSheetRetrieveSavingsAccountsUtils.getCenter().getCustomerId(), transactionDate);
    // assemble dto for saving collection sheet
    SaveCollectionSheetDto saveCollectionSheet = saveCollectionSheetUtils.assembleSaveCollectionSheetDto(collectionSheet, transactionDate);
    // close a savings account that is about to be saved
    UserContext userContext = TestUtils.makeUser();
    SavingsBO clientSavings = (SavingsBO) legacyAccountDao.getAccount(collectionSheetRetrieveSavingsAccountsUtils.getClientOfGroupCompleteGroupSavingsAccount().getAccountId());
    AccountPaymentEntity payment = new AccountPaymentEntity(clientSavings, new Money(clientSavings.getCurrency()), null, null, new PaymentTypeEntity(Short.valueOf("1")), new Date());
    AccountNotesEntity notes = new AccountNotesEntity(new java.sql.Date(System.currentTimeMillis()), "close client savings account", TestObjectFactory.getPersonnel(userContext.getId()), clientSavings);
    clientSavings.setUserContext(userContext);
    //        clientSavings.closeAccount(payment, notes, clientSavings.getCustomer());
    StaticHibernateUtil.flushSession();
    // Save collection sheet and test for errors returned
    verifyInvalidReason(saveCollectionSheet, InvalidSaveCollectionSheetReason.INVALID_SAVINGS_ACCOUNT_STATUS);
}
Also used : UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money)

Aggregations

AccountNotesEntity (org.mifos.accounts.business.AccountNotesEntity)17 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)10 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 Money (org.mifos.framework.util.helpers.Money)8 Test (org.junit.Test)7 UserContext (org.mifos.security.util.UserContext)7 CustomerBO (org.mifos.customers.business.CustomerBO)6 AccountNotesEntityBuilder (org.mifos.accounts.business.AccountNotesEntityBuilder)5 AccountPaymentEntityBuilder (org.mifos.accounts.business.AccountPaymentEntityBuilder)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 ClientBuilder (org.mifos.domain.builders.ClientBuilder)5 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)5 SavingsAccountBuilder (org.mifos.domain.builders.SavingsAccountBuilder)5 MifosUser (org.mifos.security.MifosUser)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 LocalDate (org.joda.time.LocalDate)4 AccountException (org.mifos.accounts.exceptions.AccountException)4 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)4 CustomerNoteDto (org.mifos.dto.domain.CustomerNoteDto)4