Search in sources :

Example 1 with Timesheet

use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.

the class TimesheetController method validateTimesheet.

public void validateTimesheet(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Employee employee = user.getEmployee();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Timesheets to Validate")).model(Timesheet.class.getName()).add("grid", "timesheet-validate-grid").add("form", "timesheet-form").param("search-filters", "timesheet-filters").context("todayDate", Beans.get(AppBaseService.class).getTodayDate(user.getActiveCompany()));
    Beans.get(HRMenuValidateService.class).createValidateDomain(user, employee, actionView);
    response.setView(actionView.map());
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) HRMenuValidateService(com.axelor.apps.hr.service.HRMenuValidateService) Timesheet(com.axelor.apps.hr.db.Timesheet) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 2 with Timesheet

use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.

the class TimesheetController method refuse.

// action called when refusing a timesheet. Changing status + Sending mail to Applicant
public void refuse(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
        Message message = Beans.get(TimesheetService.class).refuseAndSendRefusalEmail(timesheet);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

Example 3 with Timesheet

use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method createTimesheet.

@Override
public Timesheet createTimesheet(User user, LocalDate fromDate, LocalDate toDate) {
    Timesheet timesheet = new Timesheet();
    timesheet.setUser(user);
    Company company = null;
    Employee employee = user.getEmployee();
    if (employee != null && employee.getMainEmploymentContract() != null) {
        company = employee.getMainEmploymentContract().getPayCompany();
    } else {
        company = user.getActiveCompany();
    }
    String timeLoggingPreferenceSelect = employee == null ? null : employee.getTimeLoggingPreferenceSelect();
    timesheet.setTimeLoggingPreferenceSelect(timeLoggingPreferenceSelect);
    timesheet.setCompany(company);
    timesheet.setFromDate(fromDate);
    timesheet.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
    timesheet.setFullName(computeFullName(timesheet));
    return timesheet;
}
Also used : Company(com.axelor.apps.base.db.Company) Employee(com.axelor.apps.hr.db.Employee) Timesheet(com.axelor.apps.hr.db.Timesheet) AppTimesheet(com.axelor.apps.base.db.AppTimesheet)

Example 4 with Timesheet

use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.

the class TimesheetController method cancel.

public void cancel(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
        Message message = Beans.get(TimesheetService.class).cancelAndSendCancellationEmail(timesheet);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

Example 5 with Timesheet

use of com.axelor.apps.hr.db.Timesheet in project axelor-open-suite by axelor.

the class TimesheetController method confirm.

/**
 * Action called when confirming a timesheet. Changing status + Sending mail to Manager
 *
 * @param request
 * @param response
 */
public void confirm(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
        Message message = Beans.get(TimesheetService.class).confirmAndSendConfirmationEmail(timesheet);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(e);
        response.setError(e.getMessage());
    }
}
Also used : Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

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