Search in sources :

Example 1 with OrderDates

use of com.qcadoo.mes.orders.dates.OrderDates in project mes by qcadoo.

the class ProductionPerShiftListeners method showNotifications.

private void showNotifications(final ViewDefinitionState view) {
    FormComponent productionPerShiftForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity pps = productionPerShiftForm.getPersistedEntityWithIncludedFormValues();
    for (Entity order : getEntityFromLookup(view, ORDER_LOOKUP_REF).asSet()) {
        progressQuantitiesDeviationNotifier.compareAndNotify(view, pps, detailsHooks.isCorrectedPlan(view));
        for (OrderDates orderDates : OrderDates.of(order).map(Collections::singleton).orElse(Collections.emptySet())) {
            nonWorkingShiftsNotifier.checkAndNotify(view, orderDates.getStart().effectiveWithFallback(), pps, detailsHooks.resolveProgressType(view));
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) OrderDates(com.qcadoo.mes.orders.dates.OrderDates)

Example 2 with OrderDates

use of com.qcadoo.mes.orders.dates.OrderDates in project mes by qcadoo.

the class OrderDetailsHooksPPS method checkOrderDates.

private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
    if (order.getId() == null) {
        return;
    }
    Entity pps = productionPerShiftDataProvider.getProductionPerShiftDD().find().add(SearchRestrictions.belongsTo("order", OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, order.getId())).setMaxResults(1).uniqueResult();
    if (pps != null) {
        boolean shouldBeCorrected = OrderState.of(order).compareTo(OrderState.PENDING) != 0;
        Set<Long> progressForDayIds = productionPerShiftDataProvider.findIdsOfEffectiveProgressForDay(pps, shouldBeCorrected);
        DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY);
        Optional<OrderDates> maybeOrderDates;
        try {
            maybeOrderDates = OrderDates.of(order);
        } catch (IllegalArgumentException e) {
            return;
        }
        DataDefinition orderDD = order.getDataDefinition();
        Entity dbOrder = orderDD.get(order.getId());
        boolean areDatesCorrect = true;
        if (maybeOrderDates.isPresent()) {
            OrderDates orderDates = maybeOrderDates.get();
            Date orderStart = removeTime(orderDates.getStart().effectiveWithFallback().toDate());
            Date orderEnd = orderDates.getEnd().effectiveWithFallback().toDate();
            Date ppsFinishDate = null;
            for (Long id : progressForDayIds) {
                Entity progressForDay = progressForDayDD.get(id);
                Date progressDate = progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY);
                if (progressDate == null) {
                    progressDate = progressForDay.getDateField(ProgressForDayFields.DATE_OF_DAY);
                }
                EntityList dailyProgresses = progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS);
                for (Entity dailyProgress : dailyProgresses) {
                    Date shiftFinishDate = ppsTimeHelper.findFinishDate(dailyProgress, progressDate, dbOrder);
                    if (shiftFinishDate == null) {
                        view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
                        return;
                    }
                    if (ppsFinishDate == null || ppsFinishDate.before(shiftFinishDate)) {
                        ppsFinishDate = shiftFinishDate;
                    }
                    if (shiftFinishDate.before(orderStart)) {
                        areDatesCorrect = false;
                    }
                }
            }
            if (ppsFinishDate != null) {
                if (ppsFinishDate.after(orderEnd)) {
                    view.addMessage("productionPerShift.info.endDateTooLate", MessageType.INFO, false);
                } else if (ppsFinishDate.before(orderEnd)) {
                    view.addMessage("productionPerShift.info.endDateTooEarly", MessageType.INFO, false);
                }
            }
        }
        if (!areDatesCorrect) {
            view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) OrderDates(com.qcadoo.mes.orders.dates.OrderDates) EntityList(com.qcadoo.model.api.EntityList) DataDefinition(com.qcadoo.model.api.DataDefinition) Date(java.util.Date)

Example 3 with OrderDates

use of com.qcadoo.mes.orders.dates.OrderDates in project mes by qcadoo.

the class ProductionPerShiftDetailsHooks method checkOrderDates.

private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
    FormComponent productionPerShiftForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity pps = productionPerShiftForm.getPersistedEntityWithIncludedFormValues();
    boolean shouldBeCorrected = OrderState.of(order).compareTo(OrderState.PENDING) != 0;
    Set<Long> progressForDayIds = productionPerShiftDataProvider.findIdsOfEffectiveProgressForDay(pps, shouldBeCorrected);
    DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY);
    java.util.Optional<OrderDates> maybeOrderDates = OrderDates.of(order);
    DataDefinition orderDD = order.getDataDefinition();
    Entity dbOrder = orderDD.get(order.getId());
    boolean areDatesCorrect = true;
    if (maybeOrderDates.isPresent()) {
        OrderDates orderDates = maybeOrderDates.get();
        Date orderStart = removeTime(orderDates.getStart().effectiveWithFallback().toDate());
        Date orderEnd = orderDates.getEnd().effectiveWithFallback().toDate();
        Date ppsFinishDate = null;
        for (Long id : progressForDayIds) {
            Entity progressForDay = progressForDayDD.get(id);
            Date progressDate = progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY);
            if (progressDate == null) {
                progressDate = progressForDay.getDateField(ProgressForDayFields.DATE_OF_DAY);
            }
            EntityList dailyProgresses = progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS);
            for (Entity dailyProgress : dailyProgresses) {
                Date shiftFinishDate = ppsTimeHelper.findFinishDate(dailyProgress, progressDate, dbOrder);
                if (shiftFinishDate == null) {
                    view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
                    return;
                }
                if (ppsFinishDate == null || ppsFinishDate.before(shiftFinishDate)) {
                    ppsFinishDate = shiftFinishDate;
                }
                if (shiftFinishDate.before(orderStart)) {
                    areDatesCorrect = false;
                }
            }
        }
        if (ppsFinishDate != null) {
            if (ppsFinishDate.after(orderEnd)) {
                view.addMessage("productionPerShift.info.endDateTooLate", MessageType.INFO, false);
            } else if (ppsFinishDate.before(orderEnd)) {
                view.addMessage("productionPerShift.info.endDateTooEarly", MessageType.INFO, false);
            }
        }
    }
    if (!areDatesCorrect) {
        view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) OrderDates(com.qcadoo.mes.orders.dates.OrderDates) EntityList(com.qcadoo.model.api.EntityList) DataDefinition(com.qcadoo.model.api.DataDefinition) Date(java.util.Date)

Example 4 with OrderDates

use of com.qcadoo.mes.orders.dates.OrderDates 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)

Aggregations

OrderDates (com.qcadoo.mes.orders.dates.OrderDates)4 Entity (com.qcadoo.model.api.Entity)4 DataDefinition (com.qcadoo.model.api.DataDefinition)2 EntityList (com.qcadoo.model.api.EntityList)2 Date (java.util.Date)2 Predicate (com.google.common.base.Predicate)1 Shift (com.qcadoo.mes.basic.shift.Shift)1 ProgressType (com.qcadoo.mes.productionPerShift.constants.ProgressType)1 OrderRealizationDay (com.qcadoo.mes.productionPerShift.dates.OrderRealizationDay)1 FormComponent (com.qcadoo.view.api.components.FormComponent)1