Example usage for org.joda.time Days daysBetween

List of usage examples for org.joda.time Days daysBetween

Introduction

In this page you can find the example usage for org.joda.time Days daysBetween.

Prototype

public static Days daysBetween(ReadablePartial start, ReadablePartial end) 

Source Link

Document

Creates a Days representing the number of whole days between the two specified partial datetimes.

Usage

From source file:org.meveo.model.shared.DateUtils.java

License:Open Source License

public static double daysBetween(Date start, Date end) {
    DateTime dateTimeStart = new DateTime(start.getTime());
    DateTime dateTimeEnd = new DateTime(end.getTime());
    return Days.daysBetween(dateTimeStart, dateTimeEnd).getDays();
}

From source file:org.mifos.accounts.business.AccountActionDateEntity.java

License:Open Source License

public Integer getDaysLate() {
    int daysLate = Days.daysBetween(new DateTime(getActionDate()),
            getPaymentDate() != null ? new DateTime(getPaymentDate()) : new DateTime()).getDays();
    return daysLate < 0 ? 0 : daysLate;
}

From source file:org.mifos.accounts.savings.interest.AverageBalanceCalculationStrategy.java

License:Open Source License

@Override
public Money calculatePrincipal(InterestCalculationPeriodDetail interestCalculationPeriodDetail) {

    CalendarPeriod interestCalculationInterval = interestCalculationPeriodDetail.getInterval();

    LocalDate startDate = interestCalculationInterval.getStartDate();
    LocalDate endDate = interestCalculationInterval.getEndDate();

    List<EndOfDayDetail> endOfDayDetails = interestCalculationPeriodDetail.getDailyDetails();

    if (endOfDayDetails.isEmpty()) {
        return interestCalculationPeriodDetail.getBalanceBeforeInterval();
    }/*  w  w  w . j  av a2 s . c o m*/

    int duration = interestCalculationPeriodDetail.getDuration();
    LocalDate prevDate = startDate;
    LocalDate nextDate = endOfDayDetails.get(0).getDate();
    Money runningBalance = interestCalculationPeriodDetail.getBalanceBeforeInterval();

    //Calculation of effect of previous balance till the first activity in the calculation interval
    int subDuration = Days.daysBetween(prevDate, nextDate).getDays();

    // if not a period which has first activity rule, then number of days is inclusive e.g duration for 1st to 10th is 10 days (not 9)
    if (interestCalculationPeriodDetail.isFirstActivityBeforeInterval()) {
        subDuration++;
    }

    Money totalBalance = runningBalance.multiply(subDuration);

    prevDate = nextDate;

    for (int count = 0; count < endOfDayDetails.size(); count++) {

        if (count < endOfDayDetails.size() - 1) {
            nextDate = endOfDayDetails.get(count + 1).getDate();
        } else {
            nextDate = endDate;
        }

        subDuration = Days.daysBetween(prevDate, nextDate).getDays();

        if (count == 0 && !interestCalculationPeriodDetail.isFirstActivityBeforeInterval()) {
            subDuration -= 1;
            duration -= 1;
        }

        runningBalance = runningBalance.add(endOfDayDetails.get(count).getResultantAmountForDay());

        totalBalance = totalBalance.add(runningBalance.multiply(subDuration));

        prevDate = nextDate;
    }

    if (duration != 0) {
        totalBalance = totalBalance.divide(duration);
    }

    return MoneyUtils.currencyRound(totalBalance);
}

From source file:org.mifos.accounts.savings.interest.InterestCalculationPeriodDetail.java

License:Open Source License

public int getDuration() {
    int duration = Days.daysBetween(interval.getStartDate(), interval.getEndDate()).getDays();
    if (isFirstActivityBeforeInterval) {
        duration += 1;//from www  .ja va  2  s.c o  m
    }
    return duration;
}

From source file:org.mifos.application.servicefacade.PersonnelServiceFacadeWebTier.java

License:Open Source License

private boolean isCustomerHavingMeetingOnDay(CustomerBO customerBO, DateTime day, DateTime currentDate) {
    boolean isMeetingOnDay = false;

    if (customerBO.getCustomerMeetingValue().isDaily()) {
        List<DateTime> actionDates = customerDao.getAccountActionDatesForCustomer(customerBO.getCustomerId());
        if (isDateInList(actionDates, day)) {
            isMeetingOnDay = true;/*from  w  w w . j av  a 2  s  . com*/
        }
    } else {
        try {
            DateTime nextMeeting = new DateTime(customerBO.getCustomerMeetingValue()
                    .getNextScheduleDateAfterRecurrenceWithoutAdjustment(currentDate.toDate()));
            if (Days.daysBetween(day, nextMeeting).getDays() == 0) {
                isMeetingOnDay = true;
            }
        } catch (MeetingException e) {
            e.printStackTrace();
        }
    }
    return isMeetingOnDay;
}

From source file:org.mifos.application.servicefacade.PersonnelServiceFacadeWebTier.java

License:Open Source License

private boolean isDateInList(final List<DateTime> datesList, final DateTime dateToFind) {
    boolean isInList = false;

    for (DateTime date : datesList) {
        if (date.isBefore(dateToFind)) {
            break;
        }//from   w  ww . j ava 2 s  .c om
        if (Days.daysBetween(date, dateToFind).getDays() == 0) {
            isInList = true;
            break;
        }
    }

    return isInList;
}

From source file:org.mifos.framework.components.batchjobs.helpers.ApplyPenaltyToLoanAccountsHelper.java

License:Open Source License

private boolean checkPeriod(AccountPenaltiesEntity penaltyEntity, LocalDate installmentDate) {
    int days = Days.daysBetween(installmentDate, currentLocalDate).getDays();
    boolean check = false;
    boolean oneTime = penaltyEntity.isOneTime();

    if (oneTime && penaltyEntity.getLastAppliedDate() != null) {
        check = true;//  w  ww.  j av  a2 s  .  c o  m
    } else if (!oneTime && ((penaltyEntity.isMonthlyTime() && days % 31 != 1)
            || penaltyEntity.isWeeklyTime() && days % 7 != 1)) {
        check = true;
    }

    return check;
}

From source file:org.mifos.framework.components.batchjobs.helpers.ApplyPenaltyToLoanAccountsHelper.java

License:Open Source License

private boolean checkGracePeriodTypeDays(final LoanScheduleEntity entity, final int duration) {
    boolean check = false;

    int days = Days.daysBetween(new LocalDate(entity.getActionDate().getTime()), currentLocalDate).getDays();
    check = days <= duration;//ww  w .j a v a2s . c  o  m

    return check;
}

From source file:org.mifosplatform.infrastructure.security.api.AuthenticationApiResource.java

License:Mozilla Public License

@POST
@Produces({ MediaType.APPLICATION_JSON })
public String authenticate(@QueryParam("username") final String username,
        @QueryParam("password") final String password, @Context HttpServletRequest req) {

    Authentication authentication = new UsernamePasswordAuthenticationToken(username, password);
    Authentication authenticationCheck = customAuthenticationProvider.authenticate(authentication);
    MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
    System.out.println(tenant.getLicensekey());
    String notificationMessage = null;
    LicenseData licenseData = this.licenseUpdateService.getLicenseDetails(tenant.getLicensekey());
    int days = Days.daysBetween(DateUtils.getLocalDateOfTenant(), new LocalDate(licenseData.getKeyDate()))
            .getDays();//from  www. j a  va2s  .c  o m

    if (days < 7) {
        notificationMessage = "License will be exipired on "
                + new SimpleDateFormat("dd-MMM-yyyy").format(licenseData.getKeyDate()) + ". Please Update";
    }
    Collection<String> permissions = new ArrayList<String>();
    AuthenticatedUserData authenticatedUserData = new AuthenticatedUserData(username, permissions);

    if (authenticationCheck.isAuthenticated()) {

        String ipAddress = req.getRemoteHost(); /** Returns IpAddress of user*/
        String session = req.getSession().getId(); /** creates session and returns sessionId*/
        int maxTime = req.getSession().getMaxInactiveInterval();
        /**
         * Condition to Login History 
         * Calls When Session is New One
         * @author rakesh
         * */
        if (req.getSession().isNew() && !username.equalsIgnoreCase("selfcare")) {
            LoginHistory loginHistory = new LoginHistory(ipAddress, null, session, DateUtils.getDateOfTenant(),
                    null, username, "ACTIVE");
            this.loginHistoryRepository.save(loginHistory);
            Long loginHistoryId = loginHistory.getId();
            req.getSession().setAttribute("lId", loginHistoryId);
        }

        Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
                authenticationCheck.getAuthorities());
        for (GrantedAuthority grantedAuthority : authorities) {
            permissions.add(grantedAuthority.getAuthority());
        }
        AppUser principal = (AppUser) authenticationCheck.getPrincipal();
        byte[] base64EncodedAuthenticationKey = Base64.encode(username + ":" + password);

        Collection<RoleData> roles = this.roleReadPlatformService.retrieveAll();
        Long unreadMessages = this.userChatReadplatformReadService.getUnreadMessages(username);

        authenticatedUserData = new AuthenticatedUserData(username, roles, permissions, principal.getId(),
                new String(base64EncodedAuthenticationKey), unreadMessages, ipAddress, session, maxTime,
                (Long) req.getSession().getAttribute("lId"), principal.getRoles(), notificationMessage);
    }

    return this.apiJsonSerializerService.serialize(authenticatedUserData);
}

From source file:org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanSchedulePeriodData.java

License:Mozilla Public License

private LoanSchedulePeriodData(final Integer periodNumber, final LocalDate fromDate, final LocalDate dueDate,
        final BigDecimal principalDisbursed, final BigDecimal chargesDueAtTimeOfDisbursement,
        final boolean isDisbursed) {
    this.period = periodNumber;
    this.fromDate = fromDate;
    this.dueDate = dueDate;
    this.obligationsMetOnDate = null;
    this.complete = null;
    if (fromDate != null) {
        this.daysInPeriod = Days.daysBetween(this.fromDate, this.dueDate).getDays();
    } else {/*from   w  w w.  j  a  v a 2  s  .  c om*/
        this.daysInPeriod = null;
    }
    this.principalDisbursed = principalDisbursed;
    this.principalOriginalDue = null;
    this.principalDue = null;
    this.principalPaid = null;
    this.principalWrittenOff = null;
    this.principalOutstanding = null;
    this.principalLoanBalanceOutstanding = principalDisbursed;

    this.interestOriginalDue = null;
    this.interestDue = null;
    this.interestPaid = null;
    this.interestWaived = null;
    this.interestWrittenOff = null;
    this.interestOutstanding = null;

    this.feeChargesDue = chargesDueAtTimeOfDisbursement;
    if (isDisbursed) {
        this.feeChargesPaid = chargesDueAtTimeOfDisbursement;
        this.feeChargesWaived = null;
        this.feeChargesWrittenOff = null;
        this.feeChargesOutstanding = null;
    } else {
        this.feeChargesPaid = null;
        this.feeChargesWaived = null;
        this.feeChargesWrittenOff = null;
        this.feeChargesOutstanding = chargesDueAtTimeOfDisbursement;
    }

    this.penaltyChargesDue = null;
    this.penaltyChargesPaid = null;
    this.penaltyChargesWaived = null;
    this.penaltyChargesWrittenOff = null;
    this.penaltyChargesOutstanding = null;

    this.totalOriginalDueForPeriod = chargesDueAtTimeOfDisbursement;
    this.totalDueForPeriod = chargesDueAtTimeOfDisbursement;
    this.totalPaidForPeriod = this.feeChargesPaid;
    this.totalPaidInAdvanceForPeriod = null;
    this.totalPaidLateForPeriod = null;
    this.totalWaivedForPeriod = null;
    this.totalWrittenOffForPeriod = null;
    this.totalOutstandingForPeriod = this.feeChargesOutstanding;
    this.totalActualCostOfLoanForPeriod = this.feeChargesDue;
    if (dueDate.isBefore(new LocalDate())) {
        this.totalOverdue = this.totalOutstandingForPeriod;
    } else {
        this.totalOverdue = null;
    }
}