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;
}
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);
}
}
}
}
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;
}
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;
}
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);
}
}
Aggregations