use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class TimesheetController method computeTimeSpent.
public void computeTimeSpent(ActionRequest request, ActionResponse response) {
Timesheet timesheet = request.getContext().asType(Timesheet.class);
timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
if (timesheet.getTimesheetLineList() != null && !timesheet.getTimesheetLineList().isEmpty()) {
Beans.get(TimesheetService.class).computeTimeSpent(timesheet);
}
}
use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class TimesheetTimerServiceImpl method generateTimesheetLine.
@Transactional
public TimesheetLine generateTimesheetLine(TSTimer timer) {
BigDecimal durationHours = this.convertSecondDurationInHours(timer.getDuration());
Timesheet timesheet = Beans.get(TimesheetService.class).getCurrentOrCreateTimesheet();
LocalDate startDateTime = (timer.getStartDateTime() == null) ? Beans.get(AppBaseService.class).getTodayDateTime().toLocalDate() : timer.getStartDateTime().toLocalDate();
TimesheetLine timesheetLine = Beans.get(TimesheetLineService.class).createTimesheetLine(timer.getProject(), timer.getProduct(), timer.getUser(), startDateTime, timesheet, durationHours, timer.getComments());
Beans.get(TimesheetRepository.class).save(timesheet);
Beans.get(TimesheetLineRepository.class).save(timesheetLine);
timer.setTimesheetLine(timesheetLine);
return timesheetLine;
}
use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class BatchTimesheetValidationReminder method generateEmailTemplate.
public void generateEmailTemplate() {
Company company = batch.getMailBatch().getCompany();
Template template = batch.getMailBatch().getTemplate();
List<Timesheet> timesheetList = null;
if (Beans.get(CompanyRepository.class).all().count() > 1) {
timesheetList = Beans.get(TimesheetRepository.class).all().filter("self.company.id = ?1 AND self.statusSelect = 1 AND self.user.employee.timesheetReminder = true", company.getId()).fetch();
} else {
timesheetList = Beans.get(TimesheetRepository.class).all().filter("self.statusSelect = 1 AND self.user.employee.timesheetReminder = true").fetch();
}
String model = template.getMetaModel().getFullName();
String tag = template.getMetaModel().getName();
for (Timesheet timesheet : timesheetList) {
try {
Employee employee = timesheet.getUser().getEmployee();
if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
continue;
}
Message message = templateMessageService.generateMessage(employee.getId(), model, tag, template);
messageService.sendByEmail(message);
incrementDone();
} catch (Exception e) {
incrementAnomaly();
TraceBackService.trace(new Exception(e), ExceptionOriginRepository.REMINDER, batch.getId());
}
}
}
use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class AppTimesheetServiceImpl method switchTimesheetEditors.
@Override
@Transactional(rollbackOn = { Exception.class })
public void switchTimesheetEditors(Boolean state) {
List<Timesheet> timesheets;
Query<Timesheet> query = timesheetRepo.all().order("id");
int offset = 0;
while (!(timesheets = query.fetch(AbstractBatch.FETCH_LIMIT, offset)).isEmpty()) {
for (Timesheet timesheet : timesheets) {
offset++;
if (timesheet.getShowEditor() != state) {
timesheet.setShowEditor(state);
timesheetRepo.save(timesheet);
}
}
JPA.clear();
}
}
use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.
the class TimesheetHRRepository method validate.
@Override
public Map<String, Object> validate(Map<String, Object> json, Map<String, Object> context) {
Map<String, Object> obj = super.validate(json, context);
if (json.get("id") == null) {
Timesheet timesheet = create(json);
if (timesheet.getTimesheetLineList() == null || timesheet.getTimesheetLineList().isEmpty()) {
timesheet.setTimesheetLineList(new ArrayList<TimesheetLine>());
obj.put("timesheetLineList", timesheetService.createDefaultLines(timesheet));
}
}
return obj;
}
Aggregations