Search in sources :

Example 1 with TimesheetFilter

use of org.projectforge.business.timesheet.TimesheetFilter in project projectforge by micromata.

the class TimesheetEventsProvider method buildEvents.

/**
 * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime,
 * org.joda.time.DateTime)
 */
@Override
protected void buildEvents(final DateTime start, final DateTime end) {
    totalDuration = 0;
    for (int i = 0; i < durationsPerDayOfMonth.length; i++) {
        durationsPerDayOfMonth[i] = 0;
    }
    for (int i = 0; i < durationsPerDayOfYear.length; i++) {
        durationsPerDayOfYear[i] = 0;
    }
    final Integer userId = calFilter.getTimesheetUserId();
    if (userId == null) {
        return;
    }
    breaksMap = new HashMap<String, TimesheetDO>();
    int breaksCounter = 0;
    final TimesheetFilter filter = new TimesheetFilter();
    filter.setUserId(userId);
    filter.setStartTime(start.toDate());
    filter.setStopTime(end.toDate());
    filter.setOrderType(OrderDirection.ASC);
    timesheets = timesheetDao.getList(filter);
    boolean longFormat = false;
    days = Days.daysBetween(start, end).getDays();
    if (days < 10) {
        // Week or day view:
        longFormat = true;
        month = null;
        firstDayOfMonth = null;
    } else {
        // Month view:
        // Now we're definitely in the right
        final DateTime currentMonth = new DateTime(start.plusDays(10), ThreadLocalUserContext.getDateTimeZone());
        // month.
        month = currentMonth.getMonthOfYear();
        firstDayOfMonth = currentMonth.withDayOfMonth(1);
    }
    if (CollectionUtils.isEmpty(timesheets) == false) {
        DateTime lastStopTime = null;
        for (final TimesheetDO timesheet : timesheets) {
            final DateTime startTime = new DateTime(timesheet.getStartTime(), ThreadLocalUserContext.getDateTimeZone());
            final DateTime stopTime = new DateTime(timesheet.getStopTime(), ThreadLocalUserContext.getDateTimeZone());
            if (stopTime.isBefore(start) == true || startTime.isAfter(end) == true) {
                // Time sheet doesn't match time period start - end.
                continue;
            }
            if (calFilter.isShowBreaks() == true) {
                if (lastStopTime != null && DateHelper.isSameDay(stopTime, lastStopTime) == true && startTime.getMillis() - lastStopTime.getMillis() > 60000) {
                    // Show breaks between time sheets of one day (> 60s).
                    final Event breakEvent = new Event();
                    breakEvent.setEditable(false);
                    final String breakId = String.valueOf(++breaksCounter);
                    breakEvent.setClassName(Const.BREAK_EVENT_CLASS_NAME).setId(breakId).setStart(lastStopTime).setEnd(startTime).setTitle(getString("timesheet.break"));
                    breakEvent.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
                    events.put(breakId, breakEvent);
                    final TimesheetDO breakTimesheet = new TimesheetDO().setStartDate(lastStopTime.toDate()).setStopDate(startTime.getMillis());
                    breaksMap.put(breakId, breakTimesheet);
                }
                lastStopTime = stopTime;
            }
            final long duration = timesheet.getDuration();
            final MyWicketEvent event = new MyWicketEvent();
            final String id = "" + timesheet.getId();
            event.setClassName(Const.EVENT_CLASS_NAME);
            event.setId(id);
            event.setStart(startTime);
            event.setEnd(stopTime);
            final String title = CalendarHelper.getTitle(timesheet);
            if (longFormat == true) {
                // Week or day view:
                event.setTitle(title + "\n" + getToolTip(timesheet) + "\n" + formatDuration(duration, false));
            } else {
                // Month view:
                event.setTitle(title);
            }
            if (month != null && startTime.getMonthOfYear() != month && stopTime.getMonthOfYear() != month) {
                // Display time sheets of other month as grey blue:
                event.setTextColor("#222222").setBackgroundColor("#ACD9E8").setColor("#ACD9E8");
            }
            events.put(id, event);
            if (month == null || startTime.getMonthOfYear() == month) {
                totalDuration += duration;
                addDurationOfDay(startTime.getDayOfMonth(), duration);
            }
            final int dayOfYear = startTime.getDayOfYear();
            addDurationOfDayOfYear(dayOfYear, duration);
            event.setTooltip(getString("timesheet"), new String[][] { { title }, { timesheet.getLocation(), getString("timesheet.location") }, { KostFormatter.formatLong(timesheet.getKost2()), getString("fibu.kost2") }, { WicketTaskFormatter.getTaskPath(timesheet.getTaskId(), true, OutputType.PLAIN), getString("task") }, { timesheet.getDescription(), getString("description") } });
        }
    }
    if (calFilter.isShowStatistics() == true) {
        // Show statistics: duration of every day is shown as all day event.
        DateTime day = start;
        final int numberOfDaysInYear = PFDay.from(start.toDate()).getNumberOfDaysInYear();
        int paranoiaCounter = 0;
        do {
            if (++paranoiaCounter > 1000) {
                log.error("Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents.");
                break;
            }
            final int dayOfYear = day.getDayOfYear();
            final long duration = durationsPerDayOfYear[dayOfYear];
            final boolean firstDayOfWeek = day.getDayOfWeek() == ThreadLocalUserContext.getFirstDayOfWeekValue();
            if (firstDayOfWeek == false && duration == 0) {
                day = day.plusDays(1);
                continue;
            }
            final Event event = new Event().setAllDay(true);
            final String id = "s-" + (dayOfYear);
            event.setId(id);
            event.setStart(day);
            final String durationString = formatDuration(duration, false);
            if (firstDayOfWeek == true) {
                // Show week of year at top of first day of week.
                long weekDuration = 0;
                for (short i = 0; i < 7; i++) {
                    int d = dayOfYear + i;
                    if (d > numberOfDaysInYear) {
                        d -= numberOfDaysInYear;
                    }
                    weekDuration += durationsPerDayOfYear[d];
                }
                final StringBuffer buf = new StringBuffer();
                buf.append(getString("calendar.weekOfYearShortLabel")).append(DateHelper.getWeekOfYear(day));
                if (days > 1 && weekDuration > 0) {
                    // Show total sum of durations over all time sheets of current week (only in week and month view).
                    buf.append(": ").append(formatDuration(weekDuration, false));
                }
                if (duration > 0) {
                    buf.append(", ").append(durationString);
                }
                event.setTitle(buf.toString());
            } else {
                event.setTitle(durationString);
            }
            event.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
            event.setEditable(false);
            events.put(id, event);
            day = day.plusDays(1);
        } while (day.isAfter(end) == false);
    }
}
Also used : DateTime(org.joda.time.DateTime) MyWicketEvent(org.projectforge.web.teamcal.event.MyWicketEvent) TimesheetFilter(org.projectforge.business.timesheet.TimesheetFilter) Event(net.ftlines.wicket.fullcalendar.Event) MyWicketEvent(org.projectforge.web.teamcal.event.MyWicketEvent) TimesheetDO(org.projectforge.business.timesheet.TimesheetDO)

Example 2 with TimesheetFilter

use of org.projectforge.business.timesheet.TimesheetFilter in project projectforge by micromata.

the class EmployeeServiceImpl method getReportOfMonth.

@Override
public MonthlyEmployeeReport getReportOfMonth(final int year, final Integer month, final PFUserDO user) {
    MonthlyEmployeeReport monthlyEmployeeReport = new MonthlyEmployeeReport(this, vacationService, user, year, month);
    monthlyEmployeeReport.init();
    TimesheetFilter filter = new TimesheetFilter();
    filter.setDeleted(false);
    filter.setStartTime(monthlyEmployeeReport.getFromDate());
    filter.setStopTime(monthlyEmployeeReport.getToDate());
    filter.setUserId(user.getId());
    List<TimesheetDO> list = timesheetDao.getList(filter);
    PFUserDO loggedInUser = ThreadLocalUserContext.getUser();
    if (CollectionUtils.isNotEmpty(list)) {
        for (TimesheetDO sheet : list) {
            monthlyEmployeeReport.addTimesheet(sheet, timesheetDao.hasUserSelectAccess(loggedInUser, sheet, false));
        }
    }
    monthlyEmployeeReport.calculate();
    return monthlyEmployeeReport;
}
Also used : TimesheetFilter(org.projectforge.business.timesheet.TimesheetFilter) TimesheetDO(org.projectforge.business.timesheet.TimesheetDO) PFUserDO(org.projectforge.framework.persistence.user.entities.PFUserDO)

Example 3 with TimesheetFilter

use of org.projectforge.business.timesheet.TimesheetFilter in project projectforge by micromata.

the class MonthlyEmployeeReportDao method getReport.

/**
 * @param year
 * @param month 1-based: 1 - January, ..., 12 - December
 * @param user
 * @return
 */
public MonthlyEmployeeReport getReport(Integer year, Integer month, PFUserDO user) {
    if (user == null || year == null || month == null) {
        return null;
    }
    MonthlyEmployeeReport report = new MonthlyEmployeeReport(employeeService, vacationService, user, year, month);
    report.init();
    TimesheetFilter filter = new TimesheetFilter();
    filter.setDeleted(false);
    filter.setStartTime(report.getFromDate());
    filter.setStopTime(report.getToDate());
    filter.setUserId(user.getId());
    // Attention: No access checking!!!!
    List<TimesheetDO> list = timesheetDao.internalGetList(filter, false);
    PFUserDO loggedInUser = ThreadLocalUserContext.getUser();
    if (CollectionUtils.isNotEmpty(list)) {
        for (TimesheetDO sheet : list) {
            report.addTimesheet(sheet, timesheetDao.hasUserSelectAccess(loggedInUser, sheet, false));
        }
    }
    report.calculate();
    return report;
}
Also used : TimesheetFilter(org.projectforge.business.timesheet.TimesheetFilter) TimesheetDO(org.projectforge.business.timesheet.TimesheetDO) PFUserDO(org.projectforge.framework.persistence.user.entities.PFUserDO)

Example 4 with TimesheetFilter

use of org.projectforge.business.timesheet.TimesheetFilter in project projectforge by micromata.

the class HRViewDao method getResources.

/**
 * Rows contains the users and the last row contains the total sums. Columns of each rows are the man days of the
 * projects (see getProjectNames)
 */
public HRViewData getResources(final HRFilter filter) {
    final HRViewData data = new HRViewData(filter);
    if (filter.getStartDay() == null) {
        filter.setStartDay(PFDay.today().getLocalDate());
    }
    if (filter.getStopDay() == null) {
        filter.setStartDay(PFDay.today().getLocalDate());
    }
    if (filter.isShowBookedTimesheets()) {
        final TimesheetFilter tsFilter = new TimesheetFilter();
        tsFilter.setStartTime(PFDateTime.fromOrNull(filter.getStartDay()).getBeginOfDay().getUtilDate());
        tsFilter.setStopTime(PFDateTime.fromOrNull(filter.getStopDay()).getEndOfDay().getUtilDate());
        final List<TimesheetDO> sheets = timesheetDao.getList(tsFilter);
        for (final TimesheetDO sheet : sheets) {
            final PFUserDO user = userGroupCache.getUser(sheet.getUserId());
            if (user == null) {
                log.error("Oups, user of time sheet is null or unknown? Ignoring entry: " + sheet);
                continue;
            }
            final ProjektDO projekt = taskTree.getProjekt(sheet.getTaskId());
            final Object targetObject = getTargetObject(userGroupCache, filter, projekt);
            if (targetObject == null) {
                data.addTimesheet(sheet, user);
            } else if (targetObject instanceof ProjektDO) {
                data.addTimesheet(sheet, user, (ProjektDO) targetObject);
            } else if (targetObject instanceof KundeDO) {
                data.addTimesheet(sheet, user, (KundeDO) targetObject);
            } else {
                log.error("Target object of type " + targetObject + " not supported.");
                data.addTimesheet(sheet, user);
            }
        }
    }
    if (filter.isShowPlanning()) {
        final HRPlanningFilter hrFilter = new HRPlanningFilter();
        PFDay day = PFDay.fromOrNow(filter.getStartDay());
        hrFilter.setStartDay(day.getLocalDate());
        day = PFDay.fromOrNow(filter.getStopDay());
        hrFilter.setStopDay(day.getLocalDate());
        final List<HRPlanningDO> plannings = hrPlanningDao.getList(hrFilter);
        for (final HRPlanningDO planning : plannings) {
            if (planning.getEntries() == null) {
                continue;
            }
            for (final HRPlanningEntryDO entry : planning.getEntries()) {
                if (entry.isDeleted()) {
                    continue;
                }
                final PFUserDO user = userGroupCache.getUser(planning.getUserId());
                final ProjektDO projekt = entry.getProjekt();
                final Object targetObject = getTargetObject(userGroupCache, filter, projekt);
                if (targetObject == null) {
                    data.addHRPlanningEntry(entry, user);
                } else if (targetObject instanceof ProjektDO) {
                    data.addHRPlanningEntry(entry, user, (ProjektDO) targetObject);
                } else if (targetObject instanceof KundeDO) {
                    data.addHRPlanningEntry(entry, user, (KundeDO) targetObject);
                } else {
                    log.error("Target object of type " + targetObject + " not supported.");
                    data.addHRPlanningEntry(entry, user);
                }
            }
        }
    }
    if (filter.isOnlyMyProjects()) {
        // remove all user entries which have no planning or booking on my projects.
        final List<HRViewUserData> list = data.getUserDatas();
        if (list != null) {
            final Iterator<HRViewUserData> it = list.iterator();
            while (it.hasNext()) {
                final HRViewUserData entry = it.next();
                boolean hasEntries = false;
                if (entry.entries != null) {
                    for (final HRViewUserEntryData entryData : entry.entries) {
                        if (entryData.projekt != null || entryData.kunde != null) {
                            hasEntries = true;
                            break;
                        }
                    }
                }
                if (!hasEntries) {
                    it.remove();
                }
            }
        }
    }
    return data;
}
Also used : ProjektDO(org.projectforge.business.fibu.ProjektDO) KundeDO(org.projectforge.business.fibu.KundeDO) PFUserDO(org.projectforge.framework.persistence.user.entities.PFUserDO) PFDay(org.projectforge.framework.time.PFDay) TimesheetFilter(org.projectforge.business.timesheet.TimesheetFilter) TimesheetDO(org.projectforge.business.timesheet.TimesheetDO)

Example 5 with TimesheetFilter

use of org.projectforge.business.timesheet.TimesheetFilter in project projectforge by micromata.

the class IHKPage method findTimesheets.

private List<TimesheetDO> findTimesheets() {
    final TimeZone usersTimeZone = ThreadLocalUserContext.getTimeZone();
    final Date fromDate = form.getTimePeriod().getFromDate();
    final PFDateTime startDate = PFDateTime.fromOrNow(fromDate, usersTimeZone).withDayOfWeek(DayOfWeek.MONDAY.getValue());
    final TimesheetFilter tf = new TimesheetFilter();
    // ASC = Montag bis Sonntag
    tf.setOrderType(OrderDirection.ASC);
    tf.setStartTime(startDate.getUtilDate());
    tf.setUserId(this.getUserId());
    // stopDate auf Sonntag 23:59:59.999 setzten um alle Eintragungen aus der Woche zu bekommen
    PFDateTime stopDate = startDate.withDayOfWeek(DayOfWeek.SUNDAY.getValue());
    stopDate = stopDate.plus(23, ChronoUnit.HOURS);
    stopDate = stopDate.plus(59, ChronoUnit.MINUTES);
    stopDate = stopDate.plus(59, ChronoUnit.SECONDS);
    stopDate = stopDate.plus(999, ChronoUnit.MILLIS);
    tf.setStopTime(stopDate.getUtilDate());
    tf.setRecursive(true);
    return timesheetDao.getList(tf);
}
Also used : TimeZone(java.util.TimeZone) TimesheetFilter(org.projectforge.business.timesheet.TimesheetFilter) Date(java.util.Date) LocalDate(java.time.LocalDate) PFDateTime(org.projectforge.framework.time.PFDateTime)

Aggregations

TimesheetFilter (org.projectforge.business.timesheet.TimesheetFilter)9 TimesheetDO (org.projectforge.business.timesheet.TimesheetDO)8 PFUserDO (org.projectforge.framework.persistence.user.entities.PFUserDO)4 PFDateTime (org.projectforge.framework.time.PFDateTime)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 XYDifferenceRenderer (org.jfree.chart.renderer.xy.XYDifferenceRenderer)2 Day (org.jfree.data.time.Day)2 TimeSeries (org.jfree.data.time.TimeSeries)2 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)2 XYChartBuilder (org.projectforge.charting.XYChartBuilder)2 LocalDate (java.time.LocalDate)1 TimeZone (java.util.TimeZone)1 Event (net.ftlines.wicket.fullcalendar.Event)1 Form (org.apache.wicket.markup.html.form.Form)1 FormComponent (org.apache.wicket.markup.html.form.FormComponent)1 IFormValidator (org.apache.wicket.markup.html.form.validation.IFormValidator)1 Model (org.apache.wicket.model.Model)1 PropertyModel (org.apache.wicket.model.PropertyModel)1 DateTime (org.joda.time.DateTime)1