Search in sources :

Example 26 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class OrderRealizationDaysResolverTest method shouldResolveRealizationDay4.

@Test
public final void shouldResolveRealizationDay4() {
    // given
    DateTime startDate = new DateTime(2014, 8, 14, 3, 0, 0);
    List<Shift> shifts = ImmutableList.of(shift1, shift2, shift3);
    // when
    // - 3rd order realization day is Saturday,
    // - shift working at given time doesn't work at this date but it's not a first day of order realization,
    OrderRealizationDay realizationDay = orderRealizationDaysResolver.find(startDate, 3, false, shifts);
    // then
    assertRealizationDayState(realizationDay, 5, startDate.toLocalDate().plusDays(4), shifts);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 27 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class PpsBaseAlgorithmService method generateProgressForDays.

public void generateProgressForDays(ProgressForDaysContainer progressForDaysContainer, Entity productionPerShift) {
    Entity order = productionPerShift.getBelongsToField(ProductionPerShiftFields.ORDER);
    if (progressForDaysContainer.getOrder() != null) {
        order = progressForDaysContainer.getOrder();
    }
    Date orderStartDate = order.getDateField(OrderFields.START_DATE);
    if (orderStartDate == null) {
        progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.order.startDateRequired", false));
        throw new IllegalStateException("No start date in order");
    }
    Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE);
    if (productionLine == null) {
        progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.order.productionLineRequired", false));
        throw new IllegalStateException("No production line in order");
    }
    List<Shift> shifts = shiftsService.findAll(productionLine);
    if (shifts.isEmpty()) {
        progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.productionLine.shiftsRequired", false, productionLine.getStringField(ProductionLineFields.NUMBER)));
        throw new IllegalStateException("No shifts assigned to production line");
    }
    boolean allowIncompleteUnits = parameterService.getParameter().getBooleanField(ParameterFieldsPPS.ALLOW_INCOMPLITE_UNITS);
    BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
    if (order.getBooleanField(OrderFields.FINAL_PRODUCTION_TRACKING)) {
        plannedQuantity = basicProductionCountingService.getProducedQuantityFromBasicProductionCountings(order);
    }
    calculateRegisteredQuantity(progressForDaysContainer, order, productionPerShift, plannedQuantity);
    BigDecimal alreadyPlannedQuantity = BigDecimal.ZERO;
    List<Entity> progressForDays = Lists.newLinkedList();
    DateTime currentDate = new DateTime(orderStartDate);
    currentDate = currentDate.minusDays(1);
    currentDate = currentDate.toLocalDate().toDateTimeAtStartOfDay();
    boolean shouldBeCorrected = progressForDaysContainer.isShouldBeCorrected();
    int realizationDayNumber = 0;
    while (progressForDaysContainer.getPlannedQuantity().compareTo(BigDecimal.ZERO) > 0 || progressForDaysContainer.getAlreadyRegisteredQuantity().compareTo(BigDecimal.ZERO) > 0) {
        DailyProgressContainer dailyProgressContainer = fillDailyProgressWithShifts(progressForDaysContainer, productionPerShift, order, shifts, currentDate, orderStartDate, shouldBeCorrected, progressForDays.size(), alreadyPlannedQuantity, allowIncompleteUnits);
        if (dailyProgressContainer.isCalculationError()) {
            progressForDaysContainer.setCalculationError(true);
            return;
        }
        List<Entity> dailyProgress = dailyProgressContainer.getDailyProgress();
        if (!dailyProgress.isEmpty()) {
            progressForDays.add(createComponent(realizationDayNumber, currentDate.toDate(), dailyProgress, shouldBeCorrected));
        }
        currentDate = currentDate.plusDays(1);
        ++realizationDayNumber;
    }
    progressForDaysContainer.setProgressForDays(progressForDays);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) DailyProgressContainer(com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime)

Example 28 with Shift

use of com.qcadoo.mes.basic.shift.Shift 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 29 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class ProductionPerShiftListeners method updateProgressForDays.

public void updateProgressForDays(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    ProgressType progressType = detailsHooks.resolveProgressType(view);
    Entity order = getEntityFromLookup(view, ORDER_LOOKUP_REF).get();
    Optional<OrderDates> maybeOrderDates = resolveOrderDates(order);
    if (!maybeOrderDates.isPresent()) {
        return;
    }
    int lastDay = -1;
    List<Shift> shifts = shiftsService.findAll(order.getBelongsToField(OrderFields.PRODUCTION_LINE));
    LazyStream<OrderRealizationDay> realizationDaysStream = orderRealizationDaysResolver.asStreamFrom(progressType.extractStartDateTimeFrom(maybeOrderDates.get()), shifts);
    AwesomeDynamicListComponent progressForDaysADL = (AwesomeDynamicListComponent) view.getComponentByReference(PROGRESS_ADL_REF);
    for (FormComponent progressForDayForm : progressForDaysADL.getFormComponents()) {
        FieldComponent dayField = progressForDayForm.findFieldComponentByName(DAY_NUMBER_INPUT_REF);
        Integer dayNum = IntegerUtils.parse((String) dayField.getFieldValue());
        if (dayNum == null) {
            final int maxDayNum = lastDay;
            if (realizationDaysStream != null) {
                realizationDaysStream = realizationDaysStream.dropWhile(new Predicate<OrderRealizationDay>() {

                    @Override
                    public boolean apply(final OrderRealizationDay input) {
                        return input.getRealizationDayNumber() > maxDayNum;
                    }
                });
                OrderRealizationDay realizationDay = realizationDaysStream.head();
                setUpProgressForDayRow(progressForDayForm, realizationDay);
                lastDay = realizationDay.getRealizationDayNumber();
            }
        } else {
            lastDay = dayNum;
        }
    }
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) OrderRealizationDay(com.qcadoo.mes.productionPerShift.dates.OrderRealizationDay) Predicate(com.google.common.base.Predicate) OrderDates(com.qcadoo.mes.orders.dates.OrderDates) ProgressType(com.qcadoo.mes.productionPerShift.constants.ProgressType)

Example 30 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class PPSReportXlsHelper method getProductionPerShiftForReport.

public List<Entity> getProductionPerShiftForReport(final Entity goodFoodReport) {
    List<Entity> shifts = shiftsService.getShifts();
    DateTime dateFrom = new DateTime(goodFoodReport.getDateField(PPSReportFields.DATE_FROM));
    Shift shiftFirst = new Shift(shifts.get(0), dateFrom, false);
    List<TimeRange> ranges = shiftFirst.findWorkTimeAt(dateFrom.toLocalDate());
    LocalTime startTime = ranges.get(0).getFrom();
    DateTime firstStartShitTime = dateFrom;
    firstStartShitTime = firstStartShitTime.withHourOfDay(startTime.getHourOfDay());
    firstStartShitTime = firstStartShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
    long dateToInMills = getDateToInMills(goodFoodReport, shifts);
    String sql = "select pps from #productionPerShift_productionPerShift as pps where (" + "(" + "('" + firstStartShitTime.toDate().toString() + "' <= pps.order.finishDate and '" + firstStartShitTime.toDate().toString() + "' >= pps.order.startDate) or " + "('" + new Date(dateToInMills).toString().toString() + "' < pps.order.finishDate and '" + new Date(dateToInMills).toString().toString() + "' > pps.order.startDate)" + ") or " + "(" + "(pps.order.startDate >= '" + firstStartShitTime.toDate().toString() + "' and pps.order.startDate <'" + new Date(dateToInMills).toString().toString() + "') or " + "(pps.order.finishDate >= '" + firstStartShitTime.toDate().toString() + "' and pps.order.finishDate < '" + new Date(dateToInMills).toString().toString() + "') " + ")" + ") and pps.order.state <> '05declined' and pps.order.state <> '07abandoned'  " + "and pps.order.state <> '04completed' and pps.order.active = true";
    return dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PRODUCTION_PER_SHIFT).find(sql).list().getEntities();
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Aggregations

Shift (com.qcadoo.mes.basic.shift.Shift)37 DateTime (org.joda.time.DateTime)30 Entity (com.qcadoo.model.api.Entity)12 Test (org.junit.Test)11 TimeRange (com.qcadoo.commons.dateTime.TimeRange)9 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)8 Date (java.util.Date)7 LocalTime (org.joda.time.LocalTime)7 LocalDate (org.joda.time.LocalDate)6 BigDecimal (java.math.BigDecimal)3 DailyProgressContainer (com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 Calendar (java.util.Calendar)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 Predicate (com.google.common.base.Predicate)1 FluentIterable (com.google.common.collect.FluentIterable)1 Lists (com.google.common.collect.Lists)1 DateRange (com.qcadoo.commons.dateTime.DateRange)1