Search in sources :

Example 11 with DateTimeRange

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;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) ShiftEfficiencyCalculationHolder(com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder) Entity(com.qcadoo.model.api.Entity) DailyProgressKey(com.qcadoo.mes.productionPerShift.domain.DailyProgressKey) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) DailyProgressContainer(com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime)

Example 12 with DateTimeRange

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;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 13 with DateTimeRange

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;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) Date(java.util.Date) Interval(org.joda.time.Interval)

Example 14 with DateTimeRange

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;
}
Also used : DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) GanttChartItem(com.qcadoo.view.api.components.ganttChart.GanttChartItem)

Aggregations

DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)14 Shift (com.qcadoo.mes.basic.shift.Shift)9 DateTime (org.joda.time.DateTime)8 TimeRange (com.qcadoo.commons.dateTime.TimeRange)4 Entity (com.qcadoo.model.api.Entity)3 BigDecimal (java.math.BigDecimal)3 Date (java.util.Date)3 Interval (org.joda.time.Interval)2 Period (org.joda.time.Period)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 BasicConstants (com.qcadoo.mes.basic.constants.BasicConstants)1 ShiftFields (com.qcadoo.mes.basic.constants.ShiftFields)1 TimetableExceptionType (com.qcadoo.mes.basic.constants.TimetableExceptionType)1 DailyProgressContainer (com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer)1 DailyProgressKey (com.qcadoo.mes.productionPerShift.domain.DailyProgressKey)1 ShiftEfficiencyCalculationHolder (com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)1