Search in sources :

Example 86 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanBO method hasPortfolioAtRisk.

public Boolean hasPortfolioAtRisk() {
    List<AccountActionDateEntity> accountActionDateList = getDetailsOfInstallmentsInArrears();
    for (AccountActionDateEntity accountActionDateEntity : accountActionDateList) {
        Calendar actionDate = new GregorianCalendar();
        actionDate.setTime(accountActionDateEntity.getActionDate());
        long diffInTermsOfDay = (new DateTimeService().getCurrentDateTime().getMillis() - actionDate.getTimeInMillis()) / (24 * 60 * 60 * 1000);
        if (diffInTermsOfDay > 30) {
            return true;
        }
    }
    return false;
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 87 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanBO method getMFITime.

private long getMFITime(final Date date) {
    Calendar cal1 = new DateTimeService().getCurrentDateTime().toGregorianCalendar();
    cal1.setTimeZone(Configuration.getInstance().getSystemConfig().getMifosTimeZone());
    cal1.setTime(date);
    return date.getTime() + cal1.get(Calendar.ZONE_OFFSET) + cal1.get(Calendar.DST_OFFSET);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 88 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanBO method applyPenalty.

public void applyPenalty(final Money charge, final int scheduleEntityId, final AccountPenaltiesEntity penaltiesEntity, final Date current) {
    LoanScheduleEntity loanScheduleEntity = new ArrayList<LoanScheduleEntity>(getLoanScheduleEntities()).get(scheduleEntityId - 1);
    PenaltyBO penalty = penaltiesEntity.getPenalty();
    LoanPenaltyScheduleEntity entity = loanScheduleEntity.getPenaltyScheduleEntity(penalty.getPenaltyId());
    Money money = new Money(getCurrency());
    loanScheduleEntity.setPenalty(loanScheduleEntity.getPenalty().add(charge));
    getLoanSummary().updateOriginalPenalty(charge);
    addLoanActivity(new LoanActivityEntity(this, personnel, money, money, money, charge, getLoanSummary(), penalty.getPenaltyName() + " applied"));
    if (entity == null) {
        loanScheduleEntity.addLoanPenaltySchedule(new LoanPenaltyScheduleEntity(loanScheduleEntity, penalty, penaltiesEntity, charge, current));
    } else {
        entity.setPenaltyAmount(entity.getPenaltyAmount().add(charge));
        entity.setLastApplied(current);
    }
    penaltiesEntity.setLastAppliedDate(new DateTimeService().getCurrentJavaDateTime());
}
Also used : Money(org.mifos.framework.util.helpers.Money) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 89 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class MifosLegacyUsernamePasswordAuthenticationFilter method handleLegacySuccessfulAuthentication.

private void handleLegacySuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, final String username, final String password) {
    try {
        FlowManager flowManager = new FlowManager();
        String flowKey = String.valueOf(new DateTimeService().getCurrentDateTime().getMillis());
        flowManager.addFLow(flowKey, new Flow(), this.getFilterName());
        request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
        request.getSession(false).setAttribute(Constants.FLOWMANAGER, flowManager);
        request.getSession(false).setAttribute(Constants.RANDOMNUM, new Random().nextLong());
        boolean flag = AccountingRules.getSimpleAccountingStatus();
        request.getSession(false).setAttribute("accountingActivationStatus", flag);
        LoginDto loginActivity = loginServiceFacade.login(username, password);
        PersonnelBO user = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).findPersonnelById(loginActivity.getUserId());
        SitePreferenceHelper sitePreferenceHelper = new SitePreferenceHelper();
        sitePreferenceHelper.setSitePreferenceCookie(SitePreferenceType.getSitePreference(user.getSitePreference()), response);
        ActivityContext activityContext = new ActivityContext(Short.valueOf("0"), user.getOffice().getOfficeId(), user.getPersonnelId());
        request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, activityContext);
        request.setAttribute("activityDto", loginActivity);
        Short localeId = user.getPreferredLocale();
        Locale preferredLocale = Localization.getInstance().getLocaleById(localeId);
        UserContext userContext = new UserContext();
        userContext.setPreferredLocale(preferredLocale);
        userContext.setLocaleId(localeId);
        userContext.setId(user.getPersonnelId());
        userContext.setName(user.getDisplayName());
        userContext.setLevel(user.getLevelEnum());
        userContext.setRoles(user.getRoles());
        userContext.setLastLogin(user.getLastLogin());
        userContext.setPasswordChanged(user.getPasswordChanged());
        userContext.setBranchId(user.getOffice().getOfficeId());
        userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
        userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
        request.setAttribute(Constants.USERCONTEXT, userContext);
        request.getSession(false).setAttribute(Constants.USERCONTEXT, userContext);
        request.removeAttribute("CURRENT_LOCALE_ID");
        request.setAttribute("CURRENT_LOCALE_ID", localeId);
        if (loginActivity.isPasswordChanged()) {
            HttpSession hs = request.getSession(false);
            hs.setAttribute(Constants.USERCONTEXT, userContext);
            hs.setAttribute(Globals.LOCALE_KEY, userContext.getCurrentLocale());
        } else {
            flowManager.addObjectToFlow(flowKey, Constants.TEMPUSERCONTEXT, userContext);
        }
        if (loginActivity.isPasswordChanged()) {
            flowManager.removeFlow((String) request.getAttribute(Constants.CURRENTFLOWKEY));
            request.setAttribute(Constants.CURRENTFLOWKEY, null);
        }
    } catch (ApplicationException e1) {
        throw new MifosRuntimeException(e1);
    }
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Locale(java.util.Locale) FlowManager(org.mifos.framework.util.helpers.FlowManager) SitePreferenceHelper(org.mifos.ui.core.controller.util.helpers.SitePreferenceHelper) UserContext(org.mifos.security.util.UserContext) HttpSession(javax.servlet.http.HttpSession) LegacyPersonnelDao(org.mifos.customers.personnel.persistence.LegacyPersonnelDao) Flow(org.mifos.framework.util.helpers.Flow) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Random(java.util.Random) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoginDto(org.mifos.dto.domain.LoginDto) DateTimeService(org.mifos.framework.util.DateTimeService) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 90 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class BaseAction method createToken.

private void createToken(HttpServletRequest request) {
    String flowKey = String.valueOf(new DateTimeService().getCurrentDateTime().getMillis());
    FlowManager flowManager = (FlowManager) request.getSession().getAttribute(Constants.FLOWMANAGER);
    if (flowManager == null) {
        flowManager = new FlowManager();
        request.getSession(false).setAttribute(Constants.FLOWMANAGER, flowManager);
    }
    flowManager.addFLow(flowKey, new Flow(), this.clazz.getName());
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
}
Also used : FlowManager(org.mifos.framework.util.helpers.FlowManager) DateTimeService(org.mifos.framework.util.DateTimeService) Flow(org.mifos.framework.util.helpers.Flow)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8