Search in sources :

Example 21 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method computePeriodTotal.

@Override
public BigDecimal computePeriodTotal(Timesheet timesheet) {
    BigDecimal periodTotal = BigDecimal.ZERO;
    List<TimesheetLine> timesheetLines = timesheet.getTimesheetLineList();
    if (timesheetLines != null) {
        BigDecimal periodTotalTemp;
        for (TimesheetLine timesheetLine : timesheetLines) {
            if (timesheetLine != null) {
                periodTotalTemp = timesheetLine.getHoursDuration();
                if (periodTotalTemp != null) {
                    periodTotal = periodTotal.add(periodTotalTemp);
                }
            }
        }
    }
    return periodTotal;
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) BigDecimal(java.math.BigDecimal)

Example 22 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method checkEmptyPeriod.

public void checkEmptyPeriod(Timesheet timesheet) throws AxelorException {
    LeaveService leaveService = Beans.get(LeaveService.class);
    PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
    User user = timesheet.getUser();
    Employee employee = user.getEmployee();
    if (employee == null) {
        return;
    }
    if (employee.getPublicHolidayEventsPlanning() == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
    }
    WeeklyPlanning planning = employee.getWeeklyPlanning();
    if (planning == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName());
    }
    List<DayPlanning> dayPlanningList = planning.getWeekDays();
    Map<Integer, String> correspMap = getCorresMap();
    List<TimesheetLine> timesheetLines = timesheet.getTimesheetLineList();
    timesheetLines.sort(Comparator.comparing(TimesheetLine::getDate));
    for (int i = 0; i < timesheetLines.size(); i++) {
        if (i + 1 < timesheetLines.size()) {
            LocalDate date1 = timesheetLines.get(i).getDate();
            LocalDate date2 = timesheetLines.get(i + 1).getDate();
            LocalDate missingDay = date1.plusDays(1);
            while (ChronoUnit.DAYS.between(date1, date2) > 1) {
                if (isWorkedDay(missingDay, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, missingDay) && !publicHolidayHrService.checkPublicHolidayDay(missingDay, employee)) {
                    throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "Line for %s is missing.", missingDay);
                }
                date1 = missingDay;
                missingDay = missingDay.plusDays(1);
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) DayPlanning(com.axelor.apps.base.db.DayPlanning) LocalDate(java.time.LocalDate) Employee(com.axelor.apps.hr.db.Employee) PublicHolidayHrService(com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService) LeaveService(com.axelor.apps.hr.service.leave.LeaveService)

Example 23 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetLineServiceImpl method getProjectTimeSpentMap.

@Override
public Map<Project, BigDecimal> getProjectTimeSpentMap(List<TimesheetLine> timesheetLineList) {
    Map<Project, BigDecimal> projectTimeSpentMap = new HashMap<>();
    if (timesheetLineList != null) {
        for (TimesheetLine timesheetLine : timesheetLineList) {
            Project project = timesheetLine.getProject();
            BigDecimal hoursDuration = timesheetLine.getHoursDuration();
            if (project != null) {
                if (projectTimeSpentMap.containsKey(project)) {
                    hoursDuration = hoursDuration.add(projectTimeSpentMap.get(project));
                }
                projectTimeSpentMap.put(project, hoursDuration);
            }
        }
    }
    return projectTimeSpentMap;
}
Also used : Project(com.axelor.apps.project.db.Project) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Example 24 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetLineServiceImpl method createTimesheetLine.

@Override
public TimesheetLine createTimesheetLine(Project project, Product product, User user, LocalDate date, Timesheet timesheet, BigDecimal hours, String comments) {
    TimesheetLine timesheetLine = new TimesheetLine();
    timesheetLine.setDate(date);
    timesheetLine.setComments(comments);
    timesheetLine.setProduct(product);
    timesheetLine.setProject(project);
    timesheetLine.setUser(user);
    timesheetLine.setHoursDuration(hours);
    try {
        timesheetLine.setDuration(computeHoursDuration(timesheet, hours, false));
    } catch (AxelorException e) {
        log.error(e.getLocalizedMessage());
        TraceBackService.trace(e);
    }
    timesheet.addTimesheetLineListItem(timesheetLine);
    return timesheetLine;
}
Also used : AxelorException(com.axelor.exception.AxelorException) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine)

Example 25 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method fillToDate.

/**
 * If the toDate field of the timesheet is empty, fill it with the last timesheet line date.
 *
 * @param timesheet
 * @throws AxelorException
 */
protected void fillToDate(Timesheet timesheet) throws AxelorException {
    if (timesheet.getToDate() == null) {
        List<TimesheetLine> timesheetLineList = timesheet.getTimesheetLineList();
        if (timesheetLineList.isEmpty()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.TIMESHEET_TIMESHEET_LINE_LIST_IS_EMPTY));
        }
        LocalDate timesheetLineLastDate = timesheetLineList.get(0).getDate();
        if (timesheetLineLastDate == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_LINE_NULL_DATE), 1);
        }
        for (TimesheetLine timesheetLine : timesheetLineList.subList(1, timesheetLineList.size())) {
            LocalDate timesheetLineDate = timesheetLine.getDate();
            if (timesheetLineDate == null) {
                throw new AxelorException(timesheetLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_LINE_NULL_DATE), timesheetLineList.indexOf(timesheetLine) + 1);
            }
            if (timesheetLineDate.isAfter(timesheetLineLastDate)) {
                timesheetLineLastDate = timesheetLineDate;
            }
        }
        timesheet.setToDate(timesheetLineLastDate);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) LocalDate(java.time.LocalDate)

Aggregations

TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)32 BigDecimal (java.math.BigDecimal)15 Transactional (com.google.inject.persist.Transactional)9 LocalDate (java.time.LocalDate)8 User (com.axelor.auth.db.User)7 ArrayList (java.util.ArrayList)7 Timesheet (com.axelor.apps.hr.db.Timesheet)6 Project (com.axelor.apps.project.db.Project)6 AxelorException (com.axelor.exception.AxelorException)6 HashMap (java.util.HashMap)6 TimesheetLineService (com.axelor.apps.hr.service.timesheet.TimesheetLineService)5 Product (com.axelor.apps.base.db.Product)4 Employee (com.axelor.apps.hr.db.Employee)4 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)3 TimesheetLineRepository (com.axelor.apps.hr.db.repo.TimesheetLineRepository)3 ProjectTask (com.axelor.apps.project.db.ProjectTask)3 DayPlanning (com.axelor.apps.base.db.DayPlanning)2 PriceList (com.axelor.apps.base.db.PriceList)2 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)2 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)2