Search in sources :

Example 11 with DayPlanning

use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.

the class LeaveServiceImpl method getDefaultStart.

protected LocalDateTime getDefaultStart(WeeklyPlanning weeklyPlanning, LeaveRequest leave) {
    int startTimeHour = 0;
    int startTimeMin = 0;
    DayPlanning startDay = weeklyPlanningService.findDayPlanning(weeklyPlanning, leave.getFromDateT().toLocalDate());
    if (leave.getStartOnSelect() == LeaveRequestRepository.SELECT_MORNING) {
        if (startDay != null && startDay.getMorningFrom() != null) {
            startTimeHour = startDay.getMorningFrom().getHour();
            startTimeMin = startDay.getMorningFrom().getMinute();
        } else {
            startTimeHour = 8;
            startTimeMin = 0;
        }
    } else {
        if (startDay != null && startDay.getAfternoonFrom() != null) {
            startTimeHour = startDay.getAfternoonFrom().getHour();
            startTimeMin = startDay.getAfternoonFrom().getMinute();
        } else {
            startTimeHour = 14;
            startTimeMin = 0;
        }
    }
    return LocalDateTime.of(leave.getFromDateT().toLocalDate(), LocalTime.of(startTimeHour, startTimeMin));
}
Also used : DayPlanning(com.axelor.apps.base.db.DayPlanning)

Example 12 with DayPlanning

use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.

the class OperationOrderWorkflowService method manageDurationWithMachinePlanning.

@Transactional
public void manageDurationWithMachinePlanning(OperationOrder operationOrder, WeeklyPlanning weeklyPlanning, Long duration) throws AxelorException {
    LocalDateTime startDate = operationOrder.getPlannedStartDateT();
    LocalDateTime endDate = operationOrder.getPlannedEndDateT();
    DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(weeklyPlanning, startDate.toLocalDate());
    if (dayPlanning != null) {
        LocalTime firstPeriodFrom = dayPlanning.getMorningFrom();
        LocalTime firstPeriodTo = dayPlanning.getMorningTo();
        LocalTime secondPeriodFrom = dayPlanning.getAfternoonFrom();
        LocalTime secondPeriodTo = dayPlanning.getAfternoonTo();
        LocalTime startDateTime = startDate.toLocalTime();
        LocalTime endDateTime = endDate.toLocalTime();
        /*
       * If operation begins inside one period of the machine but finished after that period, then
       * we split the operation
       */
        if (firstPeriodTo != null && startDateTime.isBefore(firstPeriodTo) && endDateTime.isAfter(firstPeriodTo)) {
            LocalDateTime plannedEndDate = startDate.toLocalDate().atTime(firstPeriodTo);
            Long plannedDuration = DurationTool.getSecondsDuration(Duration.between(startDate, plannedEndDate));
            operationOrder.setPlannedDuration(plannedDuration);
            operationOrder.setPlannedEndDateT(plannedEndDate);
            operationOrderRepo.save(operationOrder);
            OperationOrder otherOperationOrder = JPA.copy(operationOrder, true);
            otherOperationOrder.setPlannedStartDateT(plannedEndDate);
            if (secondPeriodFrom != null) {
                otherOperationOrder.setPlannedStartDateT(startDate.toLocalDate().atTime(secondPeriodFrom));
            } else {
                this.searchForNextWorkingDay(otherOperationOrder, weeklyPlanning, plannedEndDate);
            }
            operationOrderRepo.save(otherOperationOrder);
            this.plan(otherOperationOrder, operationOrder.getPlannedDuration());
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) DayPlanning(com.axelor.apps.base.db.DayPlanning) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 13 with DayPlanning

use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.

the class OperationOrderWorkflowService method planWithPlanning.

/**
 * Set the planned start date of the operation order according to the planning of the machine
 *
 * @param weeklyPlanning
 * @param operationOrder
 */
public void planWithPlanning(OperationOrder operationOrder, WeeklyPlanning weeklyPlanning) {
    LocalDateTime startDate = operationOrder.getPlannedStartDateT();
    DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(weeklyPlanning, startDate.toLocalDate());
    if (dayPlanning != null) {
        LocalTime firstPeriodFrom = dayPlanning.getMorningFrom();
        LocalTime firstPeriodTo = dayPlanning.getMorningTo();
        LocalTime secondPeriodFrom = dayPlanning.getAfternoonFrom();
        LocalTime secondPeriodTo = dayPlanning.getAfternoonTo();
        LocalTime startDateTime = startDate.toLocalTime();
        /*
       * If the start date is before the start time of the machine (or equal, then the operation
       * order will begins at the same time than the machine Example: Machine begins at 8am. We set
       * the date to 6am. Then the planned start date will be set to 8am.
       */
        if (firstPeriodFrom != null && (startDateTime.isBefore(firstPeriodFrom) || startDateTime.equals(firstPeriodFrom))) {
            operationOrder.setPlannedStartDateT(startDate.toLocalDate().atTime(firstPeriodFrom));
        } else /*
       * If the machine has two periods, with a break between them, and the operation is planned
       * inside this period of time, then we will start the operation at the beginning of the
       * machine second period. Example: Machine hours is 8am to 12 am. 2pm to 6pm. We try to begins
       * at 1pm. The operation planned start date will be set to 2pm.
       */
        if (firstPeriodTo != null && secondPeriodFrom != null && (startDateTime.isAfter(firstPeriodTo) || startDateTime.equals(firstPeriodTo)) && (startDateTime.isBefore(secondPeriodFrom) || startDateTime.equals(secondPeriodFrom))) {
            operationOrder.setPlannedStartDateT(startDate.toLocalDate().atTime(secondPeriodFrom));
        } else /*
       * If the start date is planned after working hours, or during a day off, then we will search
       * for the first period of the machine available. Example: Machine on Friday is 6am to 8 pm.
       * We set the date to 9pm. The next working day is Monday 8am. Then the planned start date
       * will be set to Monday 8am.
       */
        if ((firstPeriodTo != null && secondPeriodFrom == null && (startDateTime.isAfter(firstPeriodTo) || startDateTime.equals(firstPeriodTo))) || (secondPeriodTo != null && (startDateTime.isAfter(secondPeriodTo) || startDateTime.equals(secondPeriodTo))) || (firstPeriodFrom == null && secondPeriodFrom == null)) {
            this.searchForNextWorkingDay(operationOrder, weeklyPlanning, startDate);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) DayPlanning(com.axelor.apps.base.db.DayPlanning)

Aggregations

DayPlanning (com.axelor.apps.base.db.DayPlanning)13 AxelorException (com.axelor.exception.AxelorException)4 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)3 Employee (com.axelor.apps.hr.db.Employee)3 User (com.axelor.auth.db.User)3 LocalDate (java.time.LocalDate)3 LocalDateTime (java.time.LocalDateTime)3 LocalTime (java.time.LocalTime)3 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)2 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)2 PublicHolidayHrService (com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService)2 OperationOrder (com.axelor.apps.production.db.OperationOrder)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 WeeklyPlanningService (com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService)1 TimesheetReport (com.axelor.apps.hr.db.TimesheetReport)1 OperationOrderRepository (com.axelor.apps.production.db.repo.OperationOrderRepository)1