Search in sources :

Example 26 with Timesheet

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

the class TimesheetController method valid.

/**
 * Action called when validating a timesheet. Changing status + Sending mail to Applicant
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void valid(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
        TimesheetService timesheetService = Beans.get(TimesheetService.class);
        timesheetService.checkEmptyPeriod(timesheet);
        computeTimeSpent(request, response);
        Message message = timesheetService.validateAndSendValidationEmail(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)));
        }
        Beans.get(PeriodService.class).checkPeriod(timesheet.getCompany(), timesheet.getToDate(), timesheet.getFromDate());
    } 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) PeriodService(com.axelor.apps.base.service.PeriodService) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

Example 27 with Timesheet

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

the class TimesheetController method editTimesheetSelected.

public void editTimesheetSelected(ActionRequest request, ActionResponse response) {
    Map<?, ?> timesheetMap = (Map<?, ?>) request.getContext().get("timesheetSelect");
    Timesheet timesheet = Beans.get(TimesheetRepository.class).find(Long.valueOf((Integer) timesheetMap.get("id")));
    response.setView(ActionView.define("Timesheet").model(Timesheet.class.getName()).add("form", "timesheet-form").param("forceEdit", "true").domain("self.id = " + timesheetMap.get("id")).context("_showRecord", String.valueOf(timesheet.getId())).map());
}
Also used : TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) Timesheet(com.axelor.apps.hr.db.Timesheet) Map(java.util.Map)

Example 28 with Timesheet

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

the class TimesheetController method setShowActivity.

public void setShowActivity(ActionRequest request, ActionResponse response) {
    Timesheet timesheet = request.getContext().asType(Timesheet.class);
    boolean showActivity = true;
    User user = timesheet.getUser();
    if (user != null) {
        Company company = user.getActiveCompany();
        if (company != null && company.getHrConfig() != null) {
            showActivity = !company.getHrConfig().getUseUniqueProductForTimesheet();
        }
    }
    response.setValue("$showActivity", showActivity);
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) Timesheet(com.axelor.apps.hr.db.Timesheet)

Example 29 with Timesheet

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

the class TimesheetController method prefillLines.

public void prefillLines(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        Beans.get(TimesheetService.class).prefillLines(timesheet);
        response.setValues(timesheet);
    } catch (AxelorException e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService)

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