use of com.axelor.apps.hr.db.Timesheet 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.Timesheet in project axelor-open-suite by axelor.
the class TimesheetLineServiceImpl method setTimesheet.
@Transactional
public TimesheetLine setTimesheet(TimesheetLine timesheetLine) {
Timesheet timesheet = timesheetRepository.all().filter("self.user = ?1 AND self.company = ?2 AND (self.statusSelect = 1 OR self.statusSelect = 2) AND ((?3 BETWEEN self.fromDate AND self.toDate) OR (self.toDate = null)) ORDER BY self.id ASC", timesheetLine.getUser(), timesheetLine.getProject().getCompany(), timesheetLine.getDate()).fetchOne();
if (timesheet == null) {
Timesheet lastTimesheet = timesheetRepository.all().filter("self.user = ?1 AND self.statusSelect != ?2 ORDER BY self.toDate DESC", timesheetLine.getUser(), TimesheetRepository.STATUS_CANCELED).fetchOne();
timesheet = timesheetService.createTimesheet(timesheetLine.getUser(), lastTimesheet != null && lastTimesheet.getToDate() != null ? lastTimesheet.getToDate().plusDays(1) : timesheetLine.getDate(), null);
timesheet = timesheetHRRepository.save(timesheet);
}
timesheetLine.setTimesheet(timesheet);
return timesheetLine;
}
use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class TimesheetController method generateLinesFromExpectedPlanning.
public void generateLinesFromExpectedPlanning(ActionRequest request, ActionResponse response) {
try {
Timesheet timesheet = request.getContext().asType(Timesheet.class);
timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
Beans.get(TimesheetService.class).generateLinesFromExpectedProjectPlanning(timesheet);
response.setReload(true);
} catch (AxelorException e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class TimesheetController method removeAfterToDateTimesheetLines.
public void removeAfterToDateTimesheetLines(ActionRequest request, ActionResponse response) {
Timesheet timesheet = request.getContext().asType(Timesheet.class);
if (timesheet.getTimesheetLineList() != null && !timesheet.getTimesheetLineList().isEmpty()) {
Beans.get(TimesheetService.class).removeAfterToDateTimesheetLines(timesheet);
}
response.setValues(timesheet);
}
use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class TimesheetController method generateLines.
@SuppressWarnings("unchecked")
public void generateLines(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Timesheet timesheet = request.getContext().asType(Timesheet.class);
Context context = request.getContext();
LocalDate fromGenerationDate = null;
if (context.get("fromGenerationDate") != null)
fromGenerationDate = LocalDate.parse(context.get("fromGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
LocalDate toGenerationDate = null;
if (context.get("toGenerationDate") != null)
toGenerationDate = LocalDate.parse(context.get("toGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
BigDecimal logTime = BigDecimal.ZERO;
if (context.get("logTime") != null)
logTime = new BigDecimal(context.get("logTime").toString());
Map<String, Object> projectContext = (Map<String, Object>) context.get("project");
Project project = null;
if (projectContext != null) {
project = Beans.get(ProjectRepository.class).find(((Integer) projectContext.get("id")).longValue());
}
Map<String, Object> productContext = (Map<String, Object>) context.get("product");
Product product = null;
if (productContext != null) {
product = Beans.get(ProductRepository.class).find(((Integer) productContext.get("id")).longValue());
}
if (context.get("showActivity") == null || !(Boolean) context.get("showActivity")) {
product = Beans.get(UserHrService.class).getTimesheetProduct(timesheet.getUser());
}
timesheet = Beans.get(TimesheetService.class).generateLines(timesheet, fromGenerationDate, toGenerationDate, logTime, project, product);
response.setValue("timesheetLineList", timesheet.getTimesheetLineList());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations