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));
}
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());
}
}
}
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);
}
}
}
Aggregations