Search in sources :

Example 6 with AccountStateEntity

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

the class ProcessFlowRules method initLoanPendingApprovalState.

private static void initLoanPendingApprovalState() throws ConfigurationException {
    LegacyAccountDao ap = ApplicationContextProvider.getBean(LegacyAccountDao.class);
    AccountStateEntity ase = ap.loadPersistentObject(AccountStateEntity.class, AccountState.LOAN_PENDING_APPROVAL.getValue());
    boolean fromDb = isLoanPendingApprovalStateEnabledOnDatabaseConfig(ase);
    boolean fromCfg = isLoanPendingApprovalStateEnabled();
    if (databaseAndCustomConfigurationAreNotTheSame(fromDb, fromCfg)) {
        int count = ApplicationContextProvider.getBean(LegacyLoanDao.class).countOfLoanAccounts();
        if (count > 0) {
            String errMsg = getBadOverrideMsg(LOAN_PENDING_APPROVAL, "Records for loans in the 'pending approval' state" + " may already exist.");
            throw new ConfigurationException(errMsg);
        }
        makeDatabaseConfigurationMatchPropertiesFileConfiguration(ap, ase, fromCfg);
    }
}
Also used : LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) LegacyLoanDao(org.mifos.accounts.loan.persistance.LegacyLoanDao)

Example 7 with AccountStateEntity

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

the class EditStatusAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    EditStatusActionForm actionForm = (EditStatusActionForm) form;
    actionForm.setSelectedItems(null);
    actionForm.setNotes(null);
    actionForm.setNewStatusId(null);
    actionForm.setFlagId(null);
    actionForm.setQuestionGroups(null);
    actionForm.setTransactionDate(DateUtils.makeDateAsSentFromBrowser());
    actionForm.setAllowBackDatedApprovals(AccountingRules.isBackDatedApprovalAllowed());
    request.getSession().removeAttribute(Constants.BUSINESS_KEY);
    UserContext userContext = getUserContext(request);
    Integer accountId = Integer.valueOf(actionForm.getAccountId());
    AccountBO accountBO = new AccountBusinessService().getAccount(accountId);
    java.util.Date lastPaymentDate = new java.util.Date(0);
    AccountPaymentEntity lastPayment = accountBO.findMostRecentNonzeroPaymentByPaymentDate();
    if (lastPayment != null) {
        lastPaymentDate = lastPayment.getPaymentDate();
    }
    actionForm.setLastPaymentDate(lastPaymentDate);
    if (accountBO.isLoanAccount() || accountBO.isGroupLoanAccount()) {
        // NOTE - not using dto values at present but available when ui is refactored away from jsp
        AccountStatusDto accountStatuses = this.loanAccountServiceFacade.retrieveAccountStatuses(accountId.longValue());
        LoanBO loanAccount = this.loanDao.findById(accountId);
        EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
        editStatusActionForm.setAccountTypeId(AccountTypes.LOAN_ACCOUNT.getValue().toString());
        editStatusActionForm.setCurrentStatusId(loanAccount.getAccountState().getId().toString());
        editStatusActionForm.setGlobalAccountNum(loanAccount.getGlobalAccountNum());
        editStatusActionForm.setAccountName(loanAccount.getLoanOffering().getPrdOfferingName());
        if (loanAccount.isGroupLoanAccount() && loanAccount.getParentAccount() == null) {
            editStatusActionForm.setInput("grouploan");
        } else {
            editStatusActionForm.setInput("loan");
        }
        if (loanAccount.getAccountState().getId().equals(Short.valueOf("2"))) {
            List<AdminDocumentBO> allAdminDocuments = legacyAdminDocumentDao.getAllActiveAdminDocuments();
            List<AdminDocumentBO> loanAdminDocuments = new ArrayList();
            for (AdminDocumentBO adminDocumentBO : allAdminDocuments) {
                List<AdminDocAccStateMixBO> admindoclist = legacyAdminDocAccStateMixDao.getMixByAdminDocuments(adminDocumentBO.getAdmindocId());
                if (!loanAdminDocuments.contains(adminDocumentBO) && admindoclist.size() > 0 && admindoclist.get(0).getAccountStateID().getPrdType().getProductTypeID().equals(loanAccount.getType().getValue().shortValue())) {
                    for (AdminDocAccStateMixBO admindoc : admindoclist) {
                        if (admindoc.getAccountStateID().getId().shortValue() == loanAccount.getAccountState().getId().shortValue()) {
                            loanAdminDocuments.add(adminDocumentBO);
                        }
                    }
                }
            }
            SessionUtils.setCollectionAttribute("editAccountStatusDocumentsList", loanAdminDocuments, request);
        } else {
            SessionUtils.setCollectionAttribute("editAccountStatusDocumentsList", null, request);
        }
    }
    if (accountBO.isSavingsAccount()) {
        // NOTE - not using dto values at present but available when ui is refactored away from jsp
        AccountStatusDto accountStatuses = this.savingsServiceFacade.retrieveAccountStatuses(accountId.longValue());
        SavingsBO savingsAccount = this.savingsDao.findById(accountId.longValue());
        EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
        editStatusActionForm.setAccountTypeId(AccountTypes.SAVINGS_ACCOUNT.getValue().toString());
        editStatusActionForm.setCurrentStatusId(savingsAccount.getAccountState().getId().toString());
        editStatusActionForm.setGlobalAccountNum(savingsAccount.getGlobalAccountNum());
        editStatusActionForm.setAccountName(savingsAccount.getSavingsOffering().getPrdOfferingName());
        editStatusActionForm.setInput("savings");
    }
    List<AccountStateEntity> accountStatuses = new AccountBusinessService().getStatusList(accountBO.getAccountState(), accountBO.getType(), userContext.getLocaleId());
    for (AccountStateEntity customerStatusEntity : accountStatuses) {
        for (AccountStateFlagEntity flag : customerStatusEntity.getFlagSet()) {
            String statusMessageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(flag.getLookUpValue().getPropertiesKey());
            flag.setStatusFlagMessageText(statusMessageText);
        }
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
    SessionUtils.setCollectionAttribute(SavingsConstants.STATUS_LIST, accountStatuses, request);
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : AccountStatusDto(org.mifos.dto.domain.AccountStatusDto) EditStatusActionForm(org.mifos.accounts.struts.actionforms.EditStatusActionForm) UserContext(org.mifos.security.util.UserContext) Date(java.util.Date) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AdminDocAccStateMixBO(org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Date(java.util.Date) AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) AccountStateFlagEntity(org.mifos.accounts.business.AccountStateFlagEntity) AdminDocumentBO(org.mifos.reports.admindocuments.business.AdminDocumentBO) MessageLookup(org.mifos.application.master.MessageLookup) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 8 with AccountStateEntity

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

the class SavingsScheduleTest method whenASavingsScheduleForAnInActiveSavingsAccountIsCreatedDepositEqualsZero.

@Test
public void whenASavingsScheduleForAnInActiveSavingsAccountIsCreatedDepositEqualsZero() {
    AccountStateEntity savingsAccountState = new AccountStateEntity(AccountState.SAVINGS_INACTIVE);
    // stubbing
    when(savingsAccount.getAccountState()).thenReturn(savingsAccountState);
    // exercise
    savingsSchedule = new SavingsScheduleBuilder().withInstallmentNumber(1).withAccount(savingsAccount).withCustomer(payingCustomer).withDepositDue(recommendedAmount).build();
    // verification
    assertThat(savingsSchedule.getDeposit(), is(new Money(defaultCurrency)));
}
Also used : SavingsScheduleBuilder(org.mifos.domain.builders.SavingsScheduleBuilder) Money(org.mifos.framework.util.helpers.Money) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Test(org.junit.Test)

Example 9 with AccountStateEntity

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

the class SavingsPaymentStrategyForVoluntarySavingsAccountsTest method setupMifosLoggerDueToUseOfStaticClientRules.

@BeforeClass
public static void setupMifosLoggerDueToUseOfStaticClientRules() {
    defaultCurrency = TestUtils.RUPEE;
    Money.setDefaultCurrency(defaultCurrency);
    savingsAccountState = new AccountStateEntity(AccountState.SAVINGS_ACTIVE);
}
Also used : AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) BeforeClass(org.junit.BeforeClass)

Example 10 with AccountStateEntity

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

the class SavingsServiceFacadeWebTier method retrieveDepositDueDetails.

@Override
public SavingsAccountDepositDueDto retrieveDepositDueDetails(String globalAccountNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
    try {
        personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    List<DueOnDateDto> previousDueDates = new ArrayList<DueOnDateDto>();
    SavingsScheduleEntity nextInstallment = (SavingsScheduleEntity) savingsAccount.getDetailsOfNextInstallment();
    Money totalDepositDue = Money.zero(savingsAccount.getCurrency());
    LocalDate nextDueDate = new LocalDate();
    if (nextInstallment != null) {
        nextDueDate = new LocalDate(nextInstallment.getActionDate());
        totalDepositDue = nextInstallment.getTotalDepositDue();
    }
    List<AccountActionDateEntity> scheduledDeposits = savingsAccount.getAccountActionDatesSortedByInstallmentId();
    for (AccountActionDateEntity scheduledDeposit : scheduledDeposits) {
        if (!scheduledDeposit.isPaid() && scheduledDeposit.isBefore(nextDueDate)) {
            SavingsScheduleEntity savingsScheduledDeposit = (SavingsScheduleEntity) scheduledDeposit;
            previousDueDates.add(new DueOnDateDto(scheduledDeposit.getActionDate(), MoneyUtils.currencyRound(savingsScheduledDeposit.getTotalDepositDue()).toString()));
        }
    }
    DueOnDateDto nextDueDetail = new DueOnDateDto(new java.sql.Date(nextDueDate.toDateMidnight().toDate().getTime()), MoneyUtils.currencyRound(totalDepositDue).toString());
    AccountStateEntity accountStateEntity = savingsAccount.getAccountState();
    return new SavingsAccountDepositDueDto(nextDueDetail, previousDueDates, accountStateEntity.getId(), accountStateEntity.getName());
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) LocalDate(org.joda.time.LocalDate) SavingsAccountDepositDueDto(org.mifos.dto.screen.SavingsAccountDepositDueDto) DueOnDateDto(org.mifos.dto.domain.DueOnDateDto) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)49 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)11 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)11 AccountException (org.mifos.accounts.exceptions.AccountException)8 PersistenceException (org.mifos.framework.exceptions.PersistenceException)7 Money (org.mifos.framework.util.helpers.Money)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 AdminDocAccStateMixBO (org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO)5 AdminDocumentBO (org.mifos.reports.admindocuments.business.AdminDocumentBO)5 Date (java.util.Date)4 List (java.util.List)4 LocalDate (org.joda.time.LocalDate)4 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 AccountStateFlagEntity (org.mifos.accounts.business.AccountStateFlagEntity)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 DateTimeService (org.mifos.framework.util.DateTimeService)4 UserContext (org.mifos.security.util.UserContext)4