Search in sources :

Example 11 with Timesheet

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

the class TimesheetLineController method setStoredDuration.

/**
 * Called from timesheet line editable grid or form. Get the timesheet corresponding to
 * timesheetline and call {@link TimesheetLineService#computeHoursDuration(Timesheet, BigDecimal,
 * boolean)}
 *
 * @param request
 * @param response
 */
public void setStoredDuration(ActionRequest request, ActionResponse response) {
    try {
        TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
        Timesheet timesheet;
        Context parent = request.getContext().getParent();
        if (parent != null && parent.getContextClass().equals(Timesheet.class)) {
            timesheet = parent.asType(Timesheet.class);
        } else {
            timesheet = timesheetLine.getTimesheet();
        }
        BigDecimal hoursDuration = Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getDuration(), true);
        response.setValue(HOURS_DURATION_FIELD, hoursDuration);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) BigDecimal(java.math.BigDecimal)

Example 12 with Timesheet

use of com.axelor.apps.hr.db.Timesheet 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 13 with Timesheet

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

the class BatchTimesheetReminder method sendReminderUsingTimesheets.

protected void sendReminderUsingTimesheets(Template template) throws AxelorException, MessagingException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    for (Employee employee : getEmployeesWithoutRecentTimesheet(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)).stream().filter(Objects::nonNull).collect(Collectors.toList())) {
        if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        Timesheet timeSheet = getRecentEmployeeTimesheet(employee);
        if (timeSheet != null) {
            Message message = templateMessageService.generateMessage(timeSheet, template);
            messageService.sendByEmail(message);
        } else {
            throw new AxelorException(Timesheet.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.NO_TIMESHEET_FOUND_FOR_EMPLOYEE), employee.getName());
        }
        incrementDone();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet)

Example 14 with Timesheet

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

the class BatchTimesheetValidationReminder method generateEmail.

public void generateEmail() {
    List<Timesheet> timesheetList = Beans.get(CompanyRepository.class).all().count() > 1 ? Beans.get(TimesheetRepository.class).all().filter("self.company.id = ?1 AND self.statusSelect = 1 AND self.user.employee.timesheetReminder = true", batch.getMailBatch().getCompany().getId()).fetch() : Beans.get(TimesheetRepository.class).all().filter("self.statusSelect = 1 AND self.user.employee.timesheetReminder = true").fetch();
    for (Timesheet timesheet : timesheetList) {
        try {
            Employee employee = timesheet.getUser().getEmployee();
            if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
                continue;
            }
            generateAndSendMessage(employee);
            incrementDone();
        } catch (Exception e) {
            incrementAnomaly();
            TraceBackService.trace(new Exception(e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
        }
    }
}
Also used : Employee(com.axelor.apps.hr.db.Employee) Timesheet(com.axelor.apps.hr.db.Timesheet) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 15 with Timesheet

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

the class TimesheetController method updateOperationOrders.

/**
 * Called from timesheet form view, on save. <br>
 * Call {@link OperationOrderTimesheetService#updateAllRealDuration(List)}.
 *
 * @param request
 * @param response
 */
public void updateOperationOrders(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        Beans.get(OperationOrderTimesheetService.class).updateOperationOrders(timesheet);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : OperationOrderTimesheetService(com.axelor.apps.businessproduction.service.OperationOrderTimesheetService) 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