Search in sources :

Example 16 with Timesheet

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

the class TimesheetLineController method updateOperationOrder.

/**
 * Called from timesheet line form view, on save. <br>
 * Call {@link OperationOrderTimesheetService#updateOperationOrders(Timesheet)}.
 *
 * @param request
 * @param response
 */
public void updateOperationOrder(ActionRequest request, ActionResponse response) {
    try {
        TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
        Timesheet timesheet = timesheetLine.getTimesheet();
        if (timesheet == null && request.getContext().getParent() != null) {
            timesheet = request.getContext().getParent().asType(Timesheet.class);
        }
        if (timesheet != null) {
            Beans.get(OperationOrderTimesheetService.class).updateOperationOrders(timesheet);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : OperationOrderTimesheetService(com.axelor.apps.businessproduction.service.OperationOrderTimesheetService) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet)

Example 17 with Timesheet

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

the class TimesheetLineServiceImpl method setTimesheet.

@Transactional
public TimesheetLine setTimesheet(TimesheetLine timesheetLine) {
    Timesheet timesheet = timesheetRepository.all().filter("self.user = ?1 AND self.company = ?2 AND (self.statusSelect = 1 OR self.statusSelect = 2) AND ((?3 BETWEEN self.fromDate AND self.toDate) OR (self.toDate = null)) ORDER BY self.id ASC", timesheetLine.getUser(), timesheetLine.getProject().getCompany(), timesheetLine.getDate()).fetchOne();
    if (timesheet == null) {
        Timesheet lastTimesheet = timesheetRepository.all().filter("self.user = ?1 AND self.statusSelect != ?2 ORDER BY self.toDate DESC", timesheetLine.getUser(), TimesheetRepository.STATUS_CANCELED).fetchOne();
        timesheet = timesheetService.createTimesheet(timesheetLine.getUser(), lastTimesheet != null && lastTimesheet.getToDate() != null ? lastTimesheet.getToDate().plusDays(1) : timesheetLine.getDate(), null);
        timesheet = timesheetHRRepository.save(timesheet);
    }
    timesheetLine.setTimesheet(timesheet);
    return timesheetLine;
}
Also used : Timesheet(com.axelor.apps.hr.db.Timesheet) Transactional(com.google.inject.persist.Transactional)

Example 18 with Timesheet

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

the class TimesheetController method generateLinesFromExpectedPlanning.

public void generateLinesFromExpectedPlanning(ActionRequest request, ActionResponse response) {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
        Beans.get(TimesheetService.class).generateLinesFromExpectedProjectPlanning(timesheet);
        response.setReload(true);
    } 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)

Example 19 with Timesheet

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

the class TimesheetController method removeAfterToDateTimesheetLines.

public void removeAfterToDateTimesheetLines(ActionRequest request, ActionResponse response) {
    Timesheet timesheet = request.getContext().asType(Timesheet.class);
    if (timesheet.getTimesheetLineList() != null && !timesheet.getTimesheetLineList().isEmpty()) {
        Beans.get(TimesheetService.class).removeAfterToDateTimesheetLines(timesheet);
    }
    response.setValues(timesheet);
}
Also used : Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService)

Example 20 with Timesheet

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

the class TimesheetController method generateLines.

@SuppressWarnings("unchecked")
public void generateLines(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        Context context = request.getContext();
        LocalDate fromGenerationDate = null;
        if (context.get("fromGenerationDate") != null)
            fromGenerationDate = LocalDate.parse(context.get("fromGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
        LocalDate toGenerationDate = null;
        if (context.get("toGenerationDate") != null)
            toGenerationDate = LocalDate.parse(context.get("toGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
        BigDecimal logTime = BigDecimal.ZERO;
        if (context.get("logTime") != null)
            logTime = new BigDecimal(context.get("logTime").toString());
        Map<String, Object> projectContext = (Map<String, Object>) context.get("project");
        Project project = null;
        if (projectContext != null) {
            project = Beans.get(ProjectRepository.class).find(((Integer) projectContext.get("id")).longValue());
        }
        Map<String, Object> productContext = (Map<String, Object>) context.get("product");
        Product product = null;
        if (productContext != null) {
            product = Beans.get(ProductRepository.class).find(((Integer) productContext.get("id")).longValue());
        }
        if (context.get("showActivity") == null || !(Boolean) context.get("showActivity")) {
            product = Beans.get(UserHrService.class).getTimesheetProduct(timesheet.getUser());
        }
        timesheet = Beans.get(TimesheetService.class).generateLines(timesheet, fromGenerationDate, toGenerationDate, logTime, project, product);
        response.setValue("timesheetLineList", timesheet.getTimesheetLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Timesheet(com.axelor.apps.hr.db.Timesheet) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Project(com.axelor.apps.project.db.Project) Map(java.util.Map)

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