use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class OperationOrderServiceImpl method chargeByMachineDays.
public List<Map<String, Object>> chargeByMachineDays(LocalDateTime fromDateTime, LocalDateTime toDateTime) throws AxelorException {
List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
fromDateTime = fromDateTime.withHour(0).withMinute(0);
toDateTime = toDateTime.withHour(23).withMinute(59);
LocalDateTime itDateTime = LocalDateTime.parse(fromDateTime.toString(), DateTimeFormatter.ISO_DATE_TIME);
if (Duration.between(fromDateTime, toDateTime).toDays() > 500) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS));
}
List<OperationOrder> operationOrderListTemp = Beans.get(OperationOrderRepository.class).all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime).fetch();
Set<String> machineNameList = new HashSet<String>();
for (OperationOrder operationOrder : operationOrderListTemp) {
if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) {
machineNameList.add(operationOrder.getWorkCenter().getMachine().getName());
}
}
}
while (!itDateTime.isAfter(toDateTime)) {
List<OperationOrder> operationOrderList = Beans.get(OperationOrderRepository.class).all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)).fetch();
Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
WeeklyPlanningService weeklyPlanningService = Beans.get(WeeklyPlanningService.class);
for (OperationOrder operationOrder : operationOrderList) {
if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
String machine = operationOrder.getWorkCenter().getMachine().getName();
long numberOfMinutes = 0;
if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) {
numberOfMinutes = Duration.between(itDateTime, operationOrder.getPlannedEndDateT()).toMinutes();
} else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) {
numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)).toMinutes();
} else {
numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).toMinutes();
}
if (numberOfMinutes > 60) {
numberOfMinutes = 60;
}
long numberOfMinutesPerDay = 0;
if (operationOrder.getWorkCenter().getMachine().getWeeklyPlanning() != null) {
DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(operationOrder.getWorkCenter().getMachine().getWeeklyPlanning(), LocalDateTime.parse(itDateTime.toString(), DateTimeFormatter.ISO_DATE_TIME).toLocalDate());
if (dayPlanning != null) {
if (dayPlanning.getMorningFrom() != null && dayPlanning.getMorningTo() != null) {
numberOfMinutesPerDay = Duration.between(dayPlanning.getMorningFrom(), dayPlanning.getMorningTo()).toMinutes();
}
if (dayPlanning.getAfternoonFrom() != null && dayPlanning.getAfternoonTo() != null) {
numberOfMinutesPerDay += Duration.between(dayPlanning.getAfternoonFrom(), dayPlanning.getAfternoonTo()).toMinutes();
}
if (dayPlanning.getMorningFrom() != null && dayPlanning.getMorningTo() == null && dayPlanning.getAfternoonFrom() == null && dayPlanning.getAfternoonTo() != null) {
numberOfMinutesPerDay += Duration.between(dayPlanning.getMorningFrom(), dayPlanning.getAfternoonTo()).toMinutes();
}
} else {
numberOfMinutesPerDay = 0;
}
} else {
numberOfMinutesPerDay = 60 * 24;
}
if (numberOfMinutesPerDay != 0) {
BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)).divide(new BigDecimal(numberOfMinutesPerDay), 2, RoundingMode.HALF_UP);
if (map.containsKey(machine)) {
map.put(machine, map.get(machine).add(percentage));
} else {
map.put(machine, percentage);
}
}
}
}
Set<String> keyList = map.keySet();
for (String key : machineNameList) {
if (keyList.contains(key)) {
int found = 0;
for (Map<String, Object> mapIt : dataList) {
if (mapIt.get("dateTime").equals((Object) itDateTime.format(DATE_FORMAT)) && mapIt.get("machine").equals((Object) key)) {
mapIt.put("charge", new BigDecimal(mapIt.get("charge").toString()).add(map.get(key)));
found = 1;
break;
}
}
if (found == 0) {
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("dateTime", (Object) itDateTime.format(DATE_FORMAT));
dataMap.put("charge", (Object) map.get(key));
dataMap.put("machine", (Object) key);
dataList.add(dataMap);
}
}
}
itDateTime = itDateTime.plusHours(1);
}
return dataList;
}
use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class OperationOrderWorkflowService method searchForNextWorkingDay.
public void searchForNextWorkingDay(OperationOrder operationOrder, WeeklyPlanning weeklyPlanning, LocalDateTime startDate) {
int daysToAddNbr = 0;
DayPlanning nextDayPlanning;
/* We will find the next DayPlanning with at least one working period. */
do {
daysToAddNbr++;
nextDayPlanning = weeklyPlanningService.findDayPlanning(weeklyPlanning, startDate.toLocalDate().plusDays(daysToAddNbr));
} while (nextDayPlanning.getAfternoonFrom() == null && nextDayPlanning.getMorningFrom() == null);
/*
* We will add the nbr of days to retrieve the working day, and set the time to either the first
* morning period or the first afternoon period.
*/
if (nextDayPlanning.getMorningFrom() != null) {
operationOrder.setPlannedStartDateT(startDate.toLocalDate().plusDays(daysToAddNbr).atTime(nextDayPlanning.getMorningFrom()));
} else if (nextDayPlanning.getAfternoonFrom() != null) {
operationOrder.setPlannedStartDateT(startDate.toLocalDate().plusDays(daysToAddNbr).atTime(nextDayPlanning.getAfternoonFrom()));
}
}
use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class WeeklyPlanningServiceImp method getWorkingDayValueInDaysWithSelect.
@Override
public double getWorkingDayValueInDaysWithSelect(WeeklyPlanning planning, LocalDate date, boolean morning, boolean afternoon) {
double value = 0;
DayPlanning dayPlanning = findDayPlanning(planning, date);
if (dayPlanning == null) {
return value;
}
if (morning && dayPlanning.getMorningFrom() != null && dayPlanning.getMorningTo() != null) {
value += 0.5;
}
if (afternoon && dayPlanning.getAfternoonFrom() != null && dayPlanning.getAfternoonTo() != null) {
value += 0.5;
}
return value;
}
use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class WeeklyPlanningServiceImp method getWorkingDayValueInHours.
@Override
public BigDecimal getWorkingDayValueInHours(WeeklyPlanning weeklyPlanning, LocalDate date, LocalTime from, LocalTime to) {
double value = 0;
DayPlanning dayPlanning = this.findDayPlanning(weeklyPlanning, date);
if (dayPlanning == null) {
return BigDecimal.valueOf(value);
}
// Compute morning leave duration
LocalTime morningFrom = dayPlanning.getMorningFrom();
LocalTime morningTo = dayPlanning.getMorningTo();
if (morningFrom != null && morningTo != null) {
LocalTime morningBegin = from != null && from.isAfter(morningFrom) ? from : morningFrom;
LocalTime morningEnd = to != null && to.isBefore(morningTo) ? to : morningTo;
if (to != null && to.isBefore(morningBegin)) {
return BigDecimal.ZERO;
} else if (from == null || from.isBefore(morningEnd)) {
value += ChronoUnit.MINUTES.between(morningBegin, morningEnd);
}
}
// Compute afternoon leave duration
LocalTime afternoonFrom = dayPlanning.getAfternoonFrom();
LocalTime afternoonTo = dayPlanning.getAfternoonTo();
if (afternoonFrom != null && afternoonTo != null) {
LocalTime afternoonBegin = from != null && from.isAfter(afternoonFrom) ? from : afternoonFrom;
LocalTime afternoonEnd = to != null && to.isBefore(afternoonTo) ? to : afternoonTo;
if (from != null && from.isAfter(afternoonEnd)) {
return BigDecimal.ZERO;
} else if (to == null || to.isAfter(afternoonBegin)) {
value += ChronoUnit.MINUTES.between(afternoonBegin, afternoonEnd);
}
}
return BigDecimal.valueOf(value).divide(BigDecimal.valueOf(60), DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP);
}
use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class WeeklyPlanningServiceImp method getWorkingDayValueInDays.
@Override
public double getWorkingDayValueInDays(WeeklyPlanning planning, LocalDate date) {
double value = 0;
DayPlanning dayPlanning = findDayPlanning(planning, date);
if (dayPlanning == null) {
return value;
}
if (dayPlanning.getMorningFrom() != null && dayPlanning.getMorningTo() != null) {
value += 0.5;
}
if (dayPlanning.getAfternoonFrom() != null && dayPlanning.getAfternoonTo() != null) {
value += 0.5;
}
return value;
}
Aggregations