use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetLineController method updateOperationOrder.
/**
* Called from timesheet line form view, on save. <br>
* Call {@link OperationOrderTimesheetService#updateOperationOrders(Timesheet)}.
*
* @param request
* @param response
*/
public void updateOperationOrder(ActionRequest request, ActionResponse response) {
try {
TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
Timesheet timesheet = timesheetLine.getTimesheet();
if (timesheet == null && request.getContext().getParent() != null) {
timesheet = request.getContext().getParent().asType(Timesheet.class);
}
if (timesheet != null) {
Beans.get(OperationOrderTimesheetService.class).updateOperationOrders(timesheet);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method computeTimeSpent.
@Override
public BigDecimal computeTimeSpent(Project project) {
BigDecimal sum = BigDecimal.ZERO;
List<TimesheetLine> timesheetLineList = timesheetlineRepo.all().filter("self.project = ?1 AND self.timesheet.statusSelect = ?2", project, TimesheetRepository.STATUS_VALIDATED).fetch();
for (TimesheetLine timesheetLine : timesheetLineList) {
sum = sum.add(timesheetLine.getHoursDuration());
}
return sum;
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method generateLines.
@Override
public Timesheet generateLines(Timesheet timesheet, LocalDate fromGenerationDate, LocalDate toGenerationDate, BigDecimal logTime, Project project, Product product) throws AxelorException {
User user = timesheet.getUser();
Employee employee = user.getEmployee();
if (fromGenerationDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_FROM_DATE));
}
if (toGenerationDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_TO_DATE));
}
if (product == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
}
if (employee == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), 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();
LocalDate fromDate = fromGenerationDate;
LocalDate toDate = toGenerationDate;
if (employee.getPublicHolidayEventsPlanning() == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
}
LeaveService leaveService = Beans.get(LeaveService.class);
PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
while (!fromDate.isAfter(toDate)) {
if (isWorkedDay(fromDate, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, fromDate) && !publicHolidayHrService.checkPublicHolidayDay(fromDate, employee)) {
TimesheetLine timesheetLine = timesheetLineService.createTimesheetLine(project, product, user, fromDate, timesheet, timesheetLineService.computeHoursDuration(timesheet, logTime, true), "");
timesheetLine.setDuration(logTime);
}
fromDate = fromDate.plusDays(1);
}
return timesheet;
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method updateTimeLoggingPreference.
@Override
public void updateTimeLoggingPreference(Timesheet timesheet) throws AxelorException {
String timeLoggingPref;
if (timesheet.getUser() == null || timesheet.getUser().getEmployee() == null) {
timeLoggingPref = EmployeeRepository.TIME_PREFERENCE_HOURS;
} else {
Employee employee = timesheet.getUser().getEmployee();
timeLoggingPref = employee.getTimeLoggingPreferenceSelect();
}
timesheet.setTimeLoggingPreferenceSelect(timeLoggingPref);
if (timesheet.getTimesheetLineList() != null) {
for (TimesheetLine timesheetLine : timesheet.getTimesheetLineList()) {
timesheetLine.setDuration(Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getHoursDuration(), false));
}
}
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method computeTimeSpent.
@Override
@Transactional
public void computeTimeSpent(Timesheet timesheet) {
List<TimesheetLine> timesheetLineList = timesheet.getTimesheetLineList();
if (timesheetLineList != null) {
Map<Project, BigDecimal> projectTimeSpentMap = timesheetLineService.getProjectTimeSpentMap(timesheetLineList);
Iterator<Project> projectIterator = projectTimeSpentMap.keySet().iterator();
while (projectIterator.hasNext()) {
Project project = projectIterator.next();
getEntityManager().flush();
executor.submit(() -> {
final Long startTime = System.currentTimeMillis();
boolean done = false;
PersistenceException persistenceException = null;
do {
try {
inTransaction(() -> {
final Project updateProject = findProject(project.getId());
getEntityManager().lock(updateProject, LockModeType.PESSIMISTIC_WRITE);
BigDecimal timeSpent = projectTimeSpentMap.get(updateProject).add(this.computeSubTimeSpent(updateProject));
updateProject.setTimeSpent(timeSpent);
projectRepo.save(updateProject);
this.computeParentTimeSpent(updateProject);
});
done = true;
} catch (PersistenceException e) {
persistenceException = e;
sleep();
}
} while (!done && System.currentTimeMillis() - startTime < ENTITY_FIND_TIMEOUT);
if (!done) {
throw persistenceException;
}
return true;
});
}
}
this.setProjectTaskTotalRealHrs(timesheet.getTimesheetLineList(), true);
}
Aggregations