use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.
the class PpsBaseAlgorithmService method fillDailyProgressWithShifts.
private DailyProgressContainer fillDailyProgressWithShifts(ProgressForDaysContainer progressForDaysContainer, Entity productionPerShift, Entity order, List<Shift> shifts, DateTime dateOfDay, Date orderStartDate, boolean shouldBeCorrected, int progressForDayQuantity, BigDecimal alreadyPlannedQuantity, boolean allowIncompleteUnits) {
DailyProgressContainer dailyProgressContainer = new DailyProgressContainer();
List<Entity> dailyProgressWithShifts = Lists.newLinkedList();
for (Shift shift : shifts) {
Entity dailyProgress = null;
if (dailyProgressesWithTrackingRecords != null) {
DailyProgressKey key = new DailyProgressKey(shift.getId(), dateOfDay);
dailyProgress = dailyProgressesWithTrackingRecords.get(key);
}
if (dailyProgress != null) {
BigDecimal producedQuantity = dailyProgress.getDecimalField(DailyProgressFields.QUANTITY);
progressForDaysContainer.setAlreadyRegisteredQuantity(progressForDaysContainer.getAlreadyRegisteredQuantity().subtract(producedQuantity, numberService.getMathContext()));
if (shouldBeCorrected) {
dailyProgress = dailyProgress.copy();
dailyProgress.setId(null);
}
dailyProgressWithShifts.add(dailyProgress);
} else if (progressForDaysContainer.getPlannedQuantity().compareTo(BigDecimal.ZERO) > 0) {
dailyProgress = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_DAILY_PROGRESS).create();
dailyProgress.setField(DailyProgressFields.SHIFT, shift.getEntity());
DateTime orderStartDateDT = new DateTime(orderStartDate, DateTimeZone.getDefault());
BigDecimal shiftEfficiency = BigDecimal.ZERO;
int time = 0;
for (DateTimeRange range : shiftExceptionService.getShiftWorkDateTimes(order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay, true)) {
if (orderStartDate.after(dateOfDay.toDate())) {
range = range.trimBefore(orderStartDateDT);
}
if (range != null) {
ShiftEfficiencyCalculationHolder calculationHolder = calculateShiftEfficiency(progressForDaysContainer, productionPerShift, shift, order, range, shiftEfficiency, progressForDayQuantity, allowIncompleteUnits);
shiftEfficiency = calculationHolder.getShiftEfficiency();
time = time + calculationHolder.getEfficiencyTime();
}
}
if (shiftEfficiency.compareTo(progressForDaysContainer.getPlannedQuantity()) > 0) {
shiftEfficiency = progressForDaysContainer.getPlannedQuantity();
progressForDaysContainer.setPlannedQuantity(BigDecimal.ZERO);
} else {
alreadyPlannedQuantity = alreadyPlannedQuantity.add(shiftEfficiency, numberService.getMathContext());
progressForDaysContainer.setPlannedQuantity(progressForDaysContainer.getPlannedQuantity().subtract(shiftEfficiency, numberService.getMathContext()));
}
if (shiftEfficiency.compareTo(BigDecimal.ZERO) != 0) {
dailyProgress.setField(DailyProgressFields.QUANTITY, numberService.setScaleWithDefaultMathContext(shiftEfficiency));
dailyProgress.setField(DailyProgressFields.EFFICIENCY_TIME, time);
dailyProgressWithShifts.add(dailyProgress);
}
}
}
dailyProgressContainer.setDailyProgress(dailyProgressWithShifts);
return dailyProgressContainer;
}
use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.
the class PpsTimeHelper method findFinishDate.
public Date findFinishDate(final Entity dailyProgress, final Date dateOfDay, final Entity order) {
DateTime endDate = null;
DateTime dateOfDayDT = new DateTime(dateOfDay, DateTimeZone.getDefault());
DateTime orderStartDate = new DateTime(order.getDateField(OrderFields.START_DATE), DateTimeZone.getDefault());
Entity shiftEntity = dailyProgress.getBelongsToField(DailyProgressFields.SHIFT);
Shift shift = new Shift(shiftEntity);
int time = dailyProgress.getIntegerField(DailyProgressFields.EFFICIENCY_TIME);
List<TimeRange> shiftWorkTime = Lists.newArrayList();
List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList();
if (shift.worksAt(dateOfDay.getDay() == 0 ? 7 : dateOfDay.getDay())) {
shiftWorkTime = shift.findWorkTimeAt(new LocalDate(dateOfDay));
}
for (TimeRange range : shiftWorkTime) {
DateTimeRange dateTimeRange = new DateTimeRange(dateOfDayDT, range);
DateTimeRange trimmedRange = dateTimeRange.trimBefore(orderStartDate);
if (trimmedRange != null) {
shiftWorkDateTime.add(trimmedRange);
}
}
shiftWorkDateTime = shiftExceptionService.manageExceptions(shiftWorkDateTime, order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay, true);
for (DateTimeRange range : shiftWorkDateTime) {
if (range.durationInMins() >= time && time > 0) {
endDate = range.getFrom().plusMinutes(time);
time = 0;
} else {
endDate = range.getTo();
time -= range.durationInMins();
}
}
return endDate != null ? endDate.toDate() : null;
}
use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.
the class ShiftIntervalsProvider method getWorkIntervals.
private Set<Interval> getWorkIntervals(final TimeGapsContext context) {
Interval searchInterval = context.getInterval();
Date fromDate = searchInterval.getStart().toDate();
Date toDate = searchInterval.getEnd().toDate();
List<Shift> shifts = shiftsService.findAll();
List<DateTimeRange> dateTimeRanges = shiftsService.getDateTimeRanges(shifts, fromDate, toDate);
Set<Interval> shiftWorkTimeIntervals = Sets.newHashSet();
for (DateTimeRange dateTimeRange : dateTimeRanges) {
Interval shiftWorkTimeInterval = new Interval(dateTimeRange.getFrom(), dateTimeRange.getTo());
shiftWorkTimeIntervals.add(shiftWorkTimeInterval);
}
return shiftWorkTimeIntervals;
}
use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.
the class ShiftsGanttChartItemResolverImpl method getItemsForShift.
private List<GanttChartItem> getItemsForShift(final Shift shift, final GanttChartScale scale) {
String shiftName = shift.getEntity().getStringField(ShiftFields.NAME);
List<DateTimeRange> timeRanges = shiftsService.getDateTimeRanges(Collections.singletonList(shift), scale.getDateFrom(), scale.getDateTo());
List<GanttChartItem> items = new ArrayList<>();
for (DateTimeRange timeRange : timeRanges) {
items.add(scale.createGanttChartItem(shiftName, shiftName, null, timeRange.getFrom().toDate(), timeRange.getTo().toDate()));
}
return items;
}
Aggregations