use of com.axelor.apps.hr.service.timesheet.TimesheetLineService in project axelor-open-suite by axelor.
the class TimesheetLineController method setDuration.
/**
* Called from timesheet editor Get the timesheet corresponding to timesheetline and call {@link
* TimesheetLineService#computeHoursDuration(Timesheet, BigDecimal, boolean)}
*
* @param request
* @param response
*/
public void setDuration(ActionRequest request, ActionResponse response) {
try {
TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
Timesheet timesheet;
Context parent = request.getContext().getParent();
if (parent != null && parent.getContextClass().equals(Timesheet.class)) {
timesheet = parent.asType(Timesheet.class);
} else {
timesheet = timesheetLine.getTimesheet();
}
BigDecimal duration = Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getHoursDuration(), false);
response.setValue(DURATION_FIELD, duration);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.service.timesheet.TimesheetLineService in project axelor-open-suite by axelor.
the class TimesheetLineController method setStoredDuration.
/**
* Called from timesheet line editable grid or form. Get the timesheet corresponding to
* timesheetline and call {@link TimesheetLineService#computeHoursDuration(Timesheet, BigDecimal,
* boolean)}
*
* @param request
* @param response
*/
public void setStoredDuration(ActionRequest request, ActionResponse response) {
try {
TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
Timesheet timesheet;
Context parent = request.getContext().getParent();
if (parent != null && parent.getContextClass().equals(Timesheet.class)) {
timesheet = parent.asType(Timesheet.class);
} else {
timesheet = timesheetLine.getTimesheet();
}
BigDecimal hoursDuration = Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getDuration(), true);
response.setValue(HOURS_DURATION_FIELD, hoursDuration);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.service.timesheet.TimesheetLineService in project axelor-open-suite by axelor.
the class HumanResourceMobileController method insertOrUpdateTSLine.
/*
* This method is used in mobile application.
* It was in TimesheetServiceImpl
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
* fields: (id,) project, activity, date, duration, comments
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine",
* "id": 1,
* "project": 1,
* "activity": 2,
* "date": "2018-02-22",
* "duration": 10,
* "comments": "no"
* } }
*/
@Transactional
public void insertOrUpdateTSLine(ActionRequest request, ActionResponse response) {
// insert TimesheetLine
try {
Map<String, Object> requestData = request.getData();
User user = AuthUtils.getUser();
Project project = Beans.get(ProjectRepository.class).find(new Long(request.getData().get("project").toString()));
Product product = Beans.get(ProductRepository.class).find(new Long(request.getData().get("activity").toString()));
LocalDate date = LocalDate.parse(request.getData().get("date").toString(), DateTimeFormatter.ISO_DATE);
TimesheetRepository timesheetRepository = Beans.get(TimesheetRepository.class);
TimesheetService timesheetService = Beans.get(TimesheetService.class);
TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
if (user != null) {
Timesheet timesheet = timesheetRepository.all().filter("self.statusSelect = 1 AND self.user.id = ?1", user.getId()).order("-id").fetchOne();
if (timesheet == null) {
timesheet = timesheetService.createTimesheet(user, date, date);
}
BigDecimal hours = new BigDecimal(request.getData().get("duration").toString());
TimesheetLine line;
Object idO = requestData.get("id");
if (idO != null) {
line = timesheetLineService.updateTimesheetLine(Beans.get(TimesheetLineRepository.class).find(Long.valueOf(idO.toString())), project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
} else {
line = timesheetLineService.createTimesheetLine(project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
}
// convert hours to what is defined in timeLoggingPreferenceSelect
BigDecimal duration = timesheetLineService.computeHoursDuration(timesheet, hours, false);
line.setDuration(duration);
timesheet.addTimesheetLineListItem(line);
timesheetRepository.save(timesheet);
response.setTotal(1);
HashMap<String, Object> data = new HashMap<>();
data.put("id", line.getId());
response.setData(data);
}
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.apps.hr.service.timesheet.TimesheetLineService in project axelor-open-suite by axelor.
the class OperationOrderTimesheetServiceImpl method updateOperationOrders.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateOperationOrders(Timesheet timesheet) throws AxelorException {
if (timesheet.getTimesheetLineList() == null) {
return;
}
// ensure that correct hoursDuration is filled
TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
for (TimesheetLine timesheetLine : timesheet.getTimesheetLineList()) {
BigDecimal hoursDuration = timesheetLineService.computeHoursDuration(timesheet, timesheetLine.getDuration(), true);
timesheetLine.setHoursDuration(hoursDuration);
}
if (!Beans.get(AppProductionService.class).getAppProduction().getEnableTimesheetOnManufOrder()) {
return;
}
List<TimesheetLine> oldTimesheetLineList = Beans.get(TimesheetLineRepository.class).all().filter("self.timesheet.id = :timesheetId").bind("timesheetId", timesheet.getId()).fetch();
List<TimesheetLine> newTimesheetLineList = timesheet.getTimesheetLineList();
List<TimesheetLine> allTimesheetLineList = new ArrayList<>(oldTimesheetLineList);
allTimesheetLineList.addAll(newTimesheetLineList);
List<OperationOrder> operationOrdersToUpdate = allTimesheetLineList.stream().map(TimesheetLine::getOperationOrder).filter(Objects::nonNull).distinct().collect(Collectors.toList());
operationOrdersToUpdate.forEach(operationOrder -> updateOperationOrder(operationOrder, oldTimesheetLineList, newTimesheetLineList));
}
Aggregations