Search in sources :

Example 21 with Timesheet

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);
    }
}
Also used : Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService)

Example 22 with 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;
}
Also used : TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 23 with Timesheet

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());
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) Employee(com.axelor.apps.hr.db.Employee) Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Template(com.axelor.apps.message.db.Template)

Example 24 with Timesheet

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();
    }
}
Also used : Timesheet(com.axelor.apps.hr.db.Timesheet) Transactional(com.google.inject.persist.Transactional)

Example 25 with Timesheet

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;
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet)

Aggregations

Timesheet (com.axelor.apps.hr.db.Timesheet)29 AxelorException (com.axelor.exception.AxelorException)14 TimesheetService (com.axelor.apps.hr.service.timesheet.TimesheetService)13 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)6 Message (com.axelor.apps.message.db.Message)6 BigDecimal (java.math.BigDecimal)6 Employee (com.axelor.apps.hr.db.Employee)5 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)4 TimesheetLineService (com.axelor.apps.hr.service.timesheet.TimesheetLineService)4 Transactional (com.google.inject.persist.Transactional)4 Company (com.axelor.apps.base.db.Company)3 TimesheetRepository (com.axelor.apps.hr.db.repo.TimesheetRepository)3 User (com.axelor.auth.db.User)3 Context (com.axelor.rpc.Context)3 LocalDate (java.time.LocalDate)3 Product (com.axelor.apps.base.db.Product)2 OperationOrderTimesheetService (com.axelor.apps.businessproduction.service.OperationOrderTimesheetService)2 TimesheetLineRepository (com.axelor.apps.hr.db.repo.TimesheetLineRepository)2 Project (com.axelor.apps.project.db.Project)2 IOException (java.io.IOException)2