Example usage for org.joda.time LocalDate plusMonths

List of usage examples for org.joda.time LocalDate plusMonths

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusMonths.

Prototype

public LocalDate plusMonths(int months) 

Source Link

Document

Returns a copy of this date plus the specified number of months.

Usage

From source file:org.killbill.billing.invoice.generator.BillingIntervalDetail.java

License:Apache License

@VisibleForTesting
void calculateFirstBillingCycleDate() {

    final int lastDayOfMonth = startDate.dayOfMonth().getMaximumValue();
    final LocalDate billingCycleDate;
    if (billingCycleDay > lastDayOfMonth) {
        billingCycleDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), lastDayOfMonth,
                startDate.getChronology());
    } else {/*from w w  w. j  a  v a2 s .  c  o  m*/
        billingCycleDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), billingCycleDay,
                startDate.getChronology());
    }

    final int numberOfMonthsInPeriod = billingPeriod.getNumberOfMonths();
    LocalDate proposedDate = billingCycleDate;
    while (proposedDate.isBefore(startDate)) {
        proposedDate = proposedDate.plusMonths(numberOfMonthsInPeriod);
    }
    firstBillingCycleDate = alignProposedBillCycleDate(proposedDate, billingCycleDay);
}

From source file:org.killbill.billing.invoice.generator.BillingIntervalDetail.java

License:Apache License

private void calculateLastBillingCycleDate() {

    // Start from firstBillingCycleDate and billingPeriod until we pass the effectiveEndDate
    LocalDate proposedDate = firstBillingCycleDate;
    int numberOfPeriods = 0;
    while (!proposedDate.isAfter(effectiveEndDate)) {
        proposedDate = firstBillingCycleDate.plusMonths(numberOfPeriods * billingPeriod.getNumberOfMonths());
        numberOfPeriods += 1;//from  w w w  .ja  va2  s.  co  m
    }

    // Our proposed date is billingCycleDate prior to the effectiveEndDate
    proposedDate = proposedDate.plusMonths(-billingPeriod.getNumberOfMonths());
    proposedDate = alignProposedBillCycleDate(proposedDate, billingCycleDay);

    if (proposedDate.isBefore(firstBillingCycleDate)) {
        // Make sure not to go too far in the past
        lastBillingCycleDate = firstBillingCycleDate;
    } else {
        lastBillingCycleDate = proposedDate;
    }
}

From source file:org.killbill.billing.invoice.InvoiceDispatcher.java

License:Apache License

private DateTime getNextUsageBillingDate(final UUID subscriptionId, final String usageName,
        final LocalDate chargedThroughDate, final DateAndTimeZoneContext dateAndTimeZoneContext,
        final BillingEventSet billingEvents) {

    final Usage usage = billingEvents.getUsages().get(usageName);
    final BillingEvent billingEventSubscription = Iterables
            .tryFind(billingEvents, new Predicate<BillingEvent>() {
                @Override//from   w  ww  .  j  a v  a 2 s . com
                public boolean apply(@Nullable final BillingEvent input) {
                    return input.getSubscription().getId().equals(subscriptionId);
                }
            }).orNull();

    final LocalDate nextCallbackUsageDate = (usage.getBillingMode() == BillingMode.IN_ARREAR)
            ? BillingIntervalDetail.alignProposedBillCycleDate(
                    chargedThroughDate.plusMonths(usage.getBillingPeriod().getNumberOfMonths()),
                    billingEventSubscription.getBillCycleDayLocal())
            : chargedThroughDate;
    return dateAndTimeZoneContext.computeUTCDateTimeFromLocalDate(nextCallbackUsageDate);
}

From source file:org.killbill.billing.invoice.usage.RawUsageOptimizer.java

License:Apache License

@VisibleForTesting
LocalDate getOptimizedRawUsageStartDate(final LocalDate firstEventStartDate, final LocalDate targetDate,
        final Iterable<InvoiceItem> existingUsageItems, final Map<String, Usage> knownUsage) {

    if (!existingUsageItems.iterator().hasNext()) {
        return firstEventStartDate;

    }/*from  w w  w.j  a v a  2 s .co  m*/
    // Extract all usage billing period known in that catalog
    final Set<BillingPeriod> knownUsageBillingPeriod = ImmutableSet
            .copyOf(Iterables.transform(knownUsage.values(), new Function<Usage, BillingPeriod>() {
                @Nullable
                @Override
                public BillingPeriod apply(final Usage input) {
                    return input.getBillingPeriod();
                }
            }));

    // Make sure all usage items are sorted by endDate
    final List<InvoiceItem> sortedUsageItems = USAGE_ITEM_ORDERING.sortedCopy(existingUsageItems);

    // Compute an array with one date per BillingPeriod:
    // If BillingPeriod is never defined in the catalog (no need to look for items), we initialize its value
    // such that it cannot be chosen
    //
    final LocalDate[] perBillingPeriodMostRecentConsumableInArrearItemEndDate = new LocalDate[BillingPeriod
            .values().length - 1]; // Exclude the NO_BILLING_PERIOD
    int idx = 0;
    for (BillingPeriod bp : BillingPeriod.values()) {
        if (bp != BillingPeriod.NO_BILLING_PERIOD) {
            final LocalDate makerDateThanCannotBeChosenAsTheMinOfAllDates = targetDate
                    .plusMonths(config.getMaxRawUsagePreviousPeriod() * bp.getNumberOfMonths());
            perBillingPeriodMostRecentConsumableInArrearItemEndDate[idx++] = (knownUsageBillingPeriod
                    .contains(bp)) ? null : makerDateThanCannotBeChosenAsTheMinOfAllDates;
        }
    }

    final ListIterator<InvoiceItem> iterator = sortedUsageItems.listIterator(sortedUsageItems.size());
    while (iterator.hasPrevious()) {
        final InvoiceItem previous = iterator.previous();
        Preconditions.checkState(previous instanceof UsageInvoiceItem);
        final UsageInvoiceItem item = (UsageInvoiceItem) previous;
        final Usage usage = knownUsage.get(item.getUsageName());

        if (perBillingPeriodMostRecentConsumableInArrearItemEndDate[usage.getBillingPeriod()
                .ordinal()] == null) {
            perBillingPeriodMostRecentConsumableInArrearItemEndDate[usage.getBillingPeriod().ordinal()] = item
                    .getEndDate();
            if (!containsNullEntries(perBillingPeriodMostRecentConsumableInArrearItemEndDate)) {
                break;
            }
        }
    }

    // Extract the min from all the dates
    LocalDate targetStartDate = null;
    idx = 0;
    for (BillingPeriod bp : BillingPeriod.values()) {
        if (bp != BillingPeriod.NO_BILLING_PERIOD) {
            final LocalDate tmp = perBillingPeriodMostRecentConsumableInArrearItemEndDate[idx];
            final LocalDate targetBillingPeriodDate = tmp != null
                    ? tmp.minusMonths(config.getMaxRawUsagePreviousPeriod() * bp.getNumberOfMonths())
                    : null;
            if (targetStartDate == null || (targetBillingPeriodDate != null
                    && targetBillingPeriodDate.compareTo(targetStartDate) < 0)) {
                targetStartDate = targetBillingPeriodDate;
            }
            idx++;
        }
    }

    final LocalDate result = targetStartDate.compareTo(firstEventStartDate) > 0 ? targetStartDate
            : firstEventStartDate;
    return result;
}

From source file:org.kuali.kpme.core.accrualcategory.rule.service.AccrualCategoryRuleServiceImpl.java

License:Educational Community License

public AccrualCategoryRule getAccrualCategoryRuleForDate(AccrualCategory accrualCategory, LocalDate currentDate,
        LocalDate serviceDate) {/*www .  j  a  v a 2  s.  c o m*/
    if (serviceDate == null) {
        return null;
    }
    List<AccrualCategoryRule> acrList = this
            .getActiveAccrualCategoryRules(accrualCategory.getLmAccrualCategoryId());
    for (AccrualCategoryRule acr : acrList) {
        String uot = acr.getServiceUnitOfTime();
        int startTime = acr.getStart().intValue();
        int endTime = acr.getEnd().intValue();

        LocalDate startDate = serviceDate;
        LocalDate endDate = serviceDate;
        if (uot.equals("M")) { // monthly
            startDate = startDate.plusMonths(startTime);
            endDate = endDate.plusMonths(endTime).minusDays(1);
        } else if (uot.endsWith("Y")) { // yearly
            startDate = startDate.plusYears(startTime);
            endDate = endDate.plusYears(endTime).minusDays(1);
        }

        // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
        if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
            startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
        }
        if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
            endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
        }

        if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
            return acr;
        }
    }
    return null;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public void calculateFutureAccrualUsingPlanningMonth(String principalId, LocalDate asOfDate,
        String runAsPrincipalId) {
    PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService()
            .getPrincipalCalendar(principalId, asOfDate);
    if (phra != null) {
        // use the date from pay period to get the leave plan
        LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(phra.getLeavePlan(), asOfDate);
        if (lp != null && StringUtils.isNotEmpty(lp.getPlanningMonths())) {
            // go back a year 
            LocalDate startDate = asOfDate.minusYears(1);
            if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
            }/*from   www. j  a v  a2 s . com*/
            // go forward using planning months
            LocalDate endDate = asOfDate.plusMonths(Integer.parseInt(lp.getPlanningMonths()));
            // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
            if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
            }
            runAccrual(principalId, startDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay(), true,
                    runAsPrincipalId);

        }
    }
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

public List<AccrualCategoryRule> getAccrualCategoryRulesForDate(List<AccrualCategoryRule> acrList,
        String accrualCategoryId, LocalDate currentDate, LocalDate serviceDate) {
    List<AccrualCategoryRule> aList = new ArrayList<AccrualCategoryRule>();
    if (CollectionUtils.isNotEmpty(acrList)) {
        for (AccrualCategoryRule acr : acrList) {
            if (acr.getLmAccrualCategoryId().equals(accrualCategoryId)) {
                String uot = acr.getServiceUnitOfTime();
                int startTime = acr.getStart().intValue();
                int endTime = acr.getEnd().intValue();

                LocalDate startDate = serviceDate;
                LocalDate endDate = serviceDate;
                if (uot.equals("M")) { // monthly
                    startDate = startDate.plusMonths(startTime);
                    endDate = endDate.plusMonths(endTime).minusDays(1);
                } else if (uot.endsWith("Y")) { // yearly
                    startDate = startDate.plusYears(startTime);
                    endDate = endDate.plusYears(endTime).minusDays(1);
                }/*from w  w w .j  a v a 2 s  .  co  m*/

                // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
                if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                    startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
                }
                if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                    endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
                }

                if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
                    aList.add(acr);
                }
            }
        }
    }
    return aList;
}

From source file:org.kuali.kpme.tklm.leave.summary.service.LeaveSummaryServiceImpl.java

License:Educational Community License

protected LeaveSummary getLeaveSummary(String principalId, LocalDate startDate, LocalDate endDate,
        String accrualCategory, boolean includeFuture) {
    LeaveSummary ls = new LeaveSummary();
    List<LeaveSummaryRow> rows = new ArrayList<LeaveSummaryRow>();

    if (StringUtils.isEmpty(principalId) || startDate == null || endDate == null) {
        return ls;
    }//from w ww .  j a v  a2 s  . c om

    Set<String> leavePlans = getLeavePlans(principalId, startDate, endDate);
    PrincipalHRAttributes pha = getPrincipalHrAttributes(principalId, startDate, endDate);
    if (CollectionUtils.isNotEmpty(leavePlans)) {
        for (String aLpString : leavePlans) {
            LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(aLpString, startDate);
            if (lp == null) {
                continue;
            }
            DateTimeFormatter formatter = DateTimeFormat.forPattern("MMMM d");
            DateTimeFormatter formatter2 = DateTimeFormat.forPattern("MMMM d yyyy");
            DateTime entryEndDate = endDate.toDateTimeAtStartOfDay();
            if (entryEndDate.getHourOfDay() == 0) {
                entryEndDate = entryEndDate.minusDays(1);
            }
            String aString = formatter.print(startDate) + " - " + formatter2.print(entryEndDate);
            ls.setPendingDatesString(aString);

            LeaveCalendarDocumentHeader approvedLcdh = LmServiceLocator.getLeaveCalendarDocumentHeaderService()
                    .getMaxEndDateApprovedLeaveCalendar(principalId);
            if (approvedLcdh != null) {
                DateTime endApprovedDate = approvedLcdh.getEndDateTime();
                LocalDateTime aLocalTime = approvedLcdh.getEndDateTime().toLocalDateTime();
                DateTime endApprovedTime = aLocalTime
                        .toDateTime(HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback());
                if (endApprovedTime.getHourOfDay() == 0) {
                    endApprovedDate = endApprovedDate.minusDays(1);
                }
                String datesString = formatter.print(approvedLcdh.getBeginDateTime()) + " - "
                        + formatter2.print(endApprovedDate);
                ls.setYtdDatesString(datesString);
            }

            //until we have something that creates carry over, we need to grab everything.
            // Calculating leave bLocks from Calendar Year start instead of Service Date
            Map<String, LeaveBlock> carryOverBlocks = getLeaveBlockService().getLastCarryOverBlocks(principalId,
                    startDate);

            boolean filterByAccrualCategory = false;
            if (StringUtils.isNotEmpty(accrualCategory)) {
                filterByAccrualCategory = true;
                //remove unwanted carry over blocks from map
                LeaveBlock carryOverBlock = carryOverBlocks.get(accrualCategory);
                carryOverBlocks = new HashMap<String, LeaveBlock>(1);
                if (ObjectUtils.isNotNull(carryOverBlock))
                    carryOverBlocks.put(carryOverBlock.getAccrualCategory(), carryOverBlock);
            }
            List<LeaveBlock> leaveBlocks = getLeaveBlockService().getLeaveBlocksSinceCarryOver(principalId,
                    carryOverBlocks, endDate, filterByAccrualCategory);

            List<LeaveBlock> futureLeaveBlocks = new ArrayList<LeaveBlock>();
            if (includeFuture) {
                if (!filterByAccrualCategory) {
                    futureLeaveBlocks = getLeaveBlockService().getLeaveBlocks(principalId, endDate,
                            endDate.plusMonths(Integer.parseInt(lp.getPlanningMonths())));
                } else {
                    futureLeaveBlocks = getLeaveBlockService().getLeaveBlocksWithAccrualCategory(principalId,
                            endDate, endDate.plusMonths(Integer.parseInt(lp.getPlanningMonths())),
                            accrualCategory);
                }
            }
            Map<String, List<LeaveBlock>> leaveBlockMap = mapLeaveBlocksByAccrualCategory(leaveBlocks);
            Map<String, List<LeaveBlock>> futureLeaveBlockMap = mapLeaveBlocksByAccrualCategory(
                    futureLeaveBlocks);
            List<AccrualCategory> acList = HrServiceLocator.getAccrualCategoryService()
                    .getActiveAccrualCategoriesForLeavePlan(lp.getLeavePlan(), endDate);
            if (CollectionUtils.isNotEmpty(acList)) {
                for (AccrualCategory ac : acList) {
                    if (ac.getShowOnGrid().equals("Y")) {

                        LeaveSummaryRow lsr = new LeaveSummaryRow();
                        lsr.setAccrualCategory(ac.getAccrualCategory());
                        lsr.setAccrualCategoryId(ac.getLmAccrualCategoryId());
                        //get max balances
                        AccrualCategoryRule acRule = HrServiceLocator.getAccrualCategoryRuleService()
                                .getAccrualCategoryRuleForDate(ac, endDate, pha.getServiceLocalDate());
                        //accrual category rule id set on a leave summary row will be useful in generating a relevant balance transfer
                        //document from the leave calendar display. Could put this id in the request for balance transfer document.
                        EmployeeOverride maxUsageOverride = LmServiceLocator.getEmployeeOverrideService()
                                .getEmployeeOverride(principalId, lp.getLeavePlan(), ac.getAccrualCategory(),
                                        "MU", endDate);

                        lsr.setAccrualCategoryRuleId(
                                acRule == null ? null : acRule.getLmAccrualCategoryRuleId());
                        if (acRule != null
                                && (acRule.getMaxBalance() != null || acRule.getMaxUsage() != null)) {
                            if (acRule.getMaxUsage() != null) {
                                lsr.setUsageLimit(new BigDecimal(acRule.getMaxUsage()).setScale(2));
                            } else {
                                lsr.setUsageLimit(null);
                            }

                        } else {
                            lsr.setUsageLimit(null);
                        }

                        if (maxUsageOverride != null)
                            lsr.setUsageLimit(new BigDecimal(maxUsageOverride.getOverrideValue()));

                        //Fetching leaveblocks for accCat with type CarryOver -- This is logic according to the CO blocks created from scheduler job.
                        BigDecimal carryOver = BigDecimal.ZERO.setScale(2);
                        lsr.setCarryOver(carryOver);

                        //handle up to current leave blocks
                        //CalendarEntry.getEndPeriodDate passed to fetch leave block amounts on last day of Calendar period
                        assignApprovedValuesToRow(lsr, ac.getAccrualCategory(),
                                leaveBlockMap.get(ac.getAccrualCategory()), lp, startDate, endDate);

                        //how about the leave blocks on the calendar entry being currently handled??
                        /*                            if(carryOverBlocks.containsKey(lsr.getAccrualCategory())) {
                                                       LeaveBlock carryOverBlock = carryOverBlocks.get(lsr.getAccrualCategory());
                                                       DateTime carryOverBlockLPStart = HrServiceLocator.getLeavePlanService().getFirstDayOfLeavePlan(lp.getLeavePlan(), carryOverBlock.getLeaveDate());
                                                       DateTime currentLPStart = HrServiceLocator.getLeavePlanService().getFirstDayOfLeavePlan(lp.getLeavePlan(), TKUtils.getCurrentDate());
                                                       if(carryOverBlockLPStart.equals(currentLPStart))
                          carryOver = carryOverBlock.getLeaveAmount();
                                                    }*/
                        //figure out past carry over values!!!
                        //We now have list of past years accrual and use (with ordered keys!!!)

                        //merge key sets
                        if (carryOverBlocks.containsKey(lsr.getAccrualCategory())) {
                            carryOver = carryOverBlocks.get(lsr.getAccrualCategory()).getLeaveAmount();
                            carryOver = carryOver.setScale(2);
                        }
                        Set<String> keyset = new HashSet<String>();
                        keyset.addAll(lsr.getPriorYearsUsage().keySet());
                        keyset.addAll(lsr.getPriorYearsTotalAccrued().keySet());
                        for (String key : keyset) {
                            BigDecimal value = lsr.getPriorYearsTotalAccrued().get(key);
                            if (value == null) {
                                value = BigDecimal.ZERO;
                            }
                            carryOver = carryOver.add(value);
                            BigDecimal use = lsr.getPriorYearsUsage().containsKey(key)
                                    ? lsr.getPriorYearsUsage().get(key)
                                    : BigDecimal.ZERO;
                            carryOver = carryOver.add(use);
                            EmployeeOverride carryOverOverride = LmServiceLocator.getEmployeeOverrideService()
                                    .getEmployeeOverride(principalId, lp.getLeavePlan(),
                                            ac.getAccrualCategory(), "MAC", endDate);
                            if (acRule != null && acRule.getMaxCarryOver() != null) {
                                BigDecimal carryOverDisplay = BigDecimal.ZERO;
                                if (carryOverOverride != null)
                                    carryOverDisplay = new BigDecimal(
                                            carryOverOverride.getOverrideValue() < carryOver.longValue()
                                                    ? carryOverOverride.getOverrideValue()
                                                    : carryOver.longValue());
                                else
                                    carryOverDisplay = new BigDecimal(
                                            acRule.getMaxCarryOver() < carryOver.longValue()
                                                    ? acRule.getMaxCarryOver()
                                                    : carryOver.longValue());
                                carryOver = carryOverDisplay;
                            }
                        }

                        lsr.setCarryOver(carryOver);
                        if (acRule != null && acRule.getMaxCarryOver() != null) {
                            EmployeeOverride carryOverOverride = LmServiceLocator.getEmployeeOverrideService()
                                    .getEmployeeOverride(principalId, lp.getLeavePlan(),
                                            ac.getAccrualCategory(), "MAC", endDate);
                            if (carryOverOverride != null)
                                lsr.setMaxCarryOver(new BigDecimal(carryOverOverride.getOverrideValue()));
                            else
                                lsr.setMaxCarryOver(
                                        new BigDecimal(acRule.getMaxCarryOver() < carryOver.longValue()
                                                ? acRule.getMaxCarryOver()
                                                : carryOver.longValue()));
                        }

                        //handle future leave blocks
                        assignPendingValuesToRow(lsr, ac.getAccrualCategory(),
                                futureLeaveBlockMap.get(ac.getAccrualCategory()));

                        //compute Leave Balance
                        BigDecimal leaveBalance = lsr.getAccruedBalance()
                                .subtract(lsr.getPendingLeaveRequests());
                        //if leave balance is set
                        //Employee overrides have already been taken into consideration and the appropriate values
                        //for usage have been set by this point.
                        //                            if (acRule != null && StringUtils.equals(acRule.getMaxBalFlag(), "Y")) {
                        //there exists an accrual category rule with max balance limit imposed.
                        //max bal flag = 'Y' has no precedence here with max-bal / balance transfers implemented.
                        //unless institutions are not required to define a max balance limit for action_at_max_bal = LOSE.
                        //Possibly preferable to procure forfeiture blocks through balance transfer
                        if (lsr.getUsageLimit() != null) { //should not set leave balance to usage limit simply because it's not null.
                            BigDecimal availableUsage = lsr.getUsageLimit()
                                    .subtract(lsr.getYtdApprovedUsage().add(lsr.getPendingLeaveRequests()));
                            if (leaveBalance.compareTo(availableUsage) > 0)
                                lsr.setLeaveBalance(availableUsage);
                            else
                                lsr.setLeaveBalance(leaveBalance);
                        } else { //no usage limit
                            lsr.setLeaveBalance(leaveBalance);
                        }

                        rows.add(lsr);
                    }
                }
                // let's check for 'empty' accrual categories
                if (leaveBlockMap.containsKey(null) || futureLeaveBlockMap.containsKey(null)) {
                    LeaveSummaryRow otherLeaveSummary = new LeaveSummaryRow();
                    //otherLeaveSummary.setAccrualCategory("Other");

                    assignApprovedValuesToRow(otherLeaveSummary, null, leaveBlockMap.get(null), lp, startDate,
                            endDate);
                    BigDecimal carryOver = BigDecimal.ZERO.setScale(2);
                    for (Map.Entry<String, BigDecimal> entry : otherLeaveSummary.getPriorYearsTotalAccrued()
                            .entrySet()) {
                        carryOver = carryOver.add(entry.getValue());
                        BigDecimal use = otherLeaveSummary.getPriorYearsUsage().containsKey(entry.getKey())
                                ? otherLeaveSummary.getPriorYearsUsage().get(entry.getKey())
                                : BigDecimal.ZERO;
                        carryOver = carryOver.add(use);
                    }
                    otherLeaveSummary.setCarryOver(carryOver);
                    assignPendingValuesToRow(otherLeaveSummary, null, futureLeaveBlockMap.get(null));
                    otherLeaveSummary.setAccrualCategory("Other");

                    //compute Leave Balance
                    // blank the avail
                    otherLeaveSummary.setUsageLimit(null);
                    otherLeaveSummary.setLeaveBalance(null);

                    rows.add(otherLeaveSummary);
                }
            }
        }
    }
    ls.setLeaveSummaryRows(rows);
    return ls;
}

From source file:org.libreplan.importers.notifications.realization.SendEmailOnTimesheetDataMissing.java

License:Open Source License

@Transactional
private List<User> getPersonalTimesheets() {
    List<PersonalTimesheetDTO> personalTimesheetDTO = new ArrayList<>();
    List<User> usersWithoutTimesheets = new ArrayList<>();
    List<User> users = userModel.getUsers();

    for (User user : users)
        if (user.isBound()) {
            Resource resource = user.getWorker();
            BaseCalendarModel.forceLoadBaseCalendar(resource.getCalendar());

            LocalDate activationDate = getActivationDate(user.getWorker());
            LocalDate currentDate = new LocalDate();
            personalTimesheetDTO.addAll(getPersonalTimesheets(user.getWorker(), activationDate,
                    currentDate.plusMonths(1), getPersonalTimesheetsPeriodicity()));

            for (PersonalTimesheetDTO item : personalTimesheetDTO) {
                WorkReport workReport = item.getWorkReport();

                if (item.getTasksNumber() == 0 && workReport == null)
                    if (!usersWithoutTimesheets.contains(user))
                        usersWithoutTimesheets.add(user);
            }/* ww w.  j  a va  2s.c  om*/

            personalTimesheetDTO.clear();
        }

    return usersWithoutTimesheets;
}

From source file:org.libreplan.web.users.dashboard.MyTasksAreaModel.java

License:Open Source License

@Override
@Transactional(readOnly = true)/*from   w  ww  . ja  v a  2s. co m*/
public List<Task> getTasks() {
    User user = UserUtil.getUserFromSession();
    if (!user.isBound()) {
        return new ArrayList<Task>();
    }

    /*
     * mvanmiddelkoop jan 2015 - Tasks from <settings> months ago to
     * <settings> month ahead
     */

    LocalDate myTodayDate = LocalDate.now();
    int since = 1;
    if (user.getResourcesLoadFilterPeriodSince() != null) {
        since = user.getResourcesLoadFilterPeriodSince();
    }
    int to = 3;
    if (user.getResourcesLoadFilterPeriodTo() != null) {
        to = user.getResourcesLoadFilterPeriodTo();
    }

    List<SpecificResourceAllocation> resourceAllocations = resourceAllocationDAO
            .findSpecificAllocationsRelatedTo(scenarioManager.getCurrent(),
                    UserDashboardUtil.getBoundResourceAsList(user), myTodayDate.minusMonths(since),
                    myTodayDate.plusMonths(to));

    List<Task> tasks = new ArrayList<Task>();
    for (SpecificResourceAllocation each : resourceAllocations) {
        Task task = each.getTask();
        if (task != null) {
            forceLoad(task);

            /* mvanmiddelkoop jan 2015 - show only unfinished tasks */
            if (task.getAdvancePercentage().intValue() < 1) {
                tasks.add(task);
            }
        }
    }

    /*
     * mvanmiddelkoop jan 2015 - Sort Ascending instead of Descending
     * sortTasksDescendingByStartDate(tasks);
     */
    sortTasksAscendingByStartDate(tasks);

    return tasks;
}