Search in sources :

Example 1 with TimesheetService

use of com.axelor.apps.hr.service.timesheet.TimesheetService in project axelor-open-suite by axelor.

the class TimesheetController method updateTimeLoggingPreference.

/**
 * Called from timesheet form, on user change. Call {@link
 * TimesheetService#updateTimeLoggingPreference(Timesheet)} to update the timesheet, and update
 * the dummy field $periodTotalConvert
 *
 * @param request
 * @param response
 */
public void updateTimeLoggingPreference(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        Beans.get(TimesheetService.class).updateTimeLoggingPreference(timesheet);
        response.setAttr("$periodTotalConvert", "hidden", false);
        response.setAttr("$periodTotalConvert", "value", Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheet.getPeriodTotal(), false));
        response.setAttr("$periodTotalConvert", "title", Beans.get(TimesheetService.class).getPeriodTotalConvertTitle(timesheet));
        response.setValue("timeLoggingPreferenceSelect", timesheet.getTimeLoggingPreferenceSelect());
        response.setValue("timesheetLineList", timesheet.getTimesheetLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

Example 2 with TimesheetService

use of com.axelor.apps.hr.service.timesheet.TimesheetService in project axelor-open-suite by axelor.

the class TimesheetController method draft.

/**
 * Called from timesheet form view, on clicking "return to draft" button. <br>
 * Call {@link TimesheetService#draft(Timesheet)}
 *
 * @param request
 * @param response
 */
public void draft(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
        Beans.get(TimesheetService.class).draft(timesheet);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

Example 3 with TimesheetService

use of com.axelor.apps.hr.service.timesheet.TimesheetService in project axelor-open-suite by axelor.

the class TimesheetController method timesheetPeriodTotalController.

public void timesheetPeriodTotalController(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        TimesheetService timesheetService = Beans.get(TimesheetService.class);
        BigDecimal periodTotal = timesheetService.computePeriodTotal(timesheet);
        response.setAttr("periodTotal", "value", periodTotal);
        response.setAttr("$periodTotalConvert", "hidden", false);
        response.setAttr("$periodTotalConvert", "value", Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, periodTotal, false));
        response.setAttr("$periodTotalConvert", "title", timesheetService.getPeriodTotalConvertTitle(timesheet));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 4 with TimesheetService

use of com.axelor.apps.hr.service.timesheet.TimesheetService in project axelor-open-suite by axelor.

the class HumanResourceMobileController method insertOrUpdateTSLine.

/*
   * This method is used in mobile application.
   * It was in TimesheetServiceImpl
   * @param request
   * @param response
   *
   * POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
   * Content-Type: application/json
   *
   * URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
   * fields: (id,) project, activity, date, duration, comments
   *
   * payload:
   * { "data": {
   * 		"action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine",
   *        "id": 1,
   * 		"project": 1,
   * 		"activity": 2,
   * 		"date": "2018-02-22",
   * 		"duration": 10,
   * 		"comments": "no"
   * } }
   */
@Transactional
public void insertOrUpdateTSLine(ActionRequest request, ActionResponse response) {
    // insert TimesheetLine
    try {
        Map<String, Object> requestData = request.getData();
        User user = AuthUtils.getUser();
        Project project = Beans.get(ProjectRepository.class).find(new Long(request.getData().get("project").toString()));
        Product product = Beans.get(ProductRepository.class).find(new Long(request.getData().get("activity").toString()));
        LocalDate date = LocalDate.parse(request.getData().get("date").toString(), DateTimeFormatter.ISO_DATE);
        TimesheetRepository timesheetRepository = Beans.get(TimesheetRepository.class);
        TimesheetService timesheetService = Beans.get(TimesheetService.class);
        TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
        if (user != null) {
            Timesheet timesheet = timesheetRepository.all().filter("self.statusSelect = 1 AND self.user.id = ?1", user.getId()).order("-id").fetchOne();
            if (timesheet == null) {
                timesheet = timesheetService.createTimesheet(user, date, date);
            }
            BigDecimal hours = new BigDecimal(request.getData().get("duration").toString());
            TimesheetLine line;
            Object idO = requestData.get("id");
            if (idO != null) {
                line = timesheetLineService.updateTimesheetLine(Beans.get(TimesheetLineRepository.class).find(Long.valueOf(idO.toString())), project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
            } else {
                line = timesheetLineService.createTimesheetLine(project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
            }
            // convert hours to what is defined in timeLoggingPreferenceSelect
            BigDecimal duration = timesheetLineService.computeHoursDuration(timesheet, hours, false);
            line.setDuration(duration);
            timesheet.addTimesheetLineListItem(line);
            timesheetRepository.save(timesheet);
            response.setTotal(1);
            HashMap<String, Object> data = new HashMap<>();
            data.put("id", line.getId());
            response.setData(data);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
}
Also used : User(com.axelor.auth.db.User) ProjectRepository(com.axelor.apps.project.db.repo.ProjectRepository) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) HashMap(java.util.HashMap) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Timesheet(com.axelor.apps.hr.db.Timesheet) Product(com.axelor.apps.base.db.Product) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Project(com.axelor.apps.project.db.Project) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) Transactional(com.google.inject.persist.Transactional)

Example 5 with TimesheetService

use of com.axelor.apps.hr.service.timesheet.TimesheetService 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)

Aggregations

Timesheet (com.axelor.apps.hr.db.Timesheet)5 TimesheetService (com.axelor.apps.hr.service.timesheet.TimesheetService)5 AxelorException (com.axelor.exception.AxelorException)5 BigDecimal (java.math.BigDecimal)2 Product (com.axelor.apps.base.db.Product)1 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 PeriodService (com.axelor.apps.base.service.PeriodService)1 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)1 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)1 TimesheetLineRepository (com.axelor.apps.hr.db.repo.TimesheetLineRepository)1 TimesheetRepository (com.axelor.apps.hr.db.repo.TimesheetRepository)1 TimesheetLineService (com.axelor.apps.hr.service.timesheet.TimesheetLineService)1 Message (com.axelor.apps.message.db.Message)1 Project (com.axelor.apps.project.db.Project)1 ProjectRepository (com.axelor.apps.project.db.repo.ProjectRepository)1 User (com.axelor.auth.db.User)1 Transactional (com.google.inject.persist.Transactional)1 LocalDate (java.time.LocalDate)1 HashMap (java.util.HashMap)1