Search in sources :

Example 1 with OrderRealizationDay

use of com.qcadoo.mes.productionPerShift.dates.OrderRealizationDay 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

Predicate (com.google.common.base.Predicate)1 Shift (com.qcadoo.mes.basic.shift.Shift)1 OrderDates (com.qcadoo.mes.orders.dates.OrderDates)1 ProgressType (com.qcadoo.mes.productionPerShift.constants.ProgressType)1 OrderRealizationDay (com.qcadoo.mes.productionPerShift.dates.OrderRealizationDay)1 Entity (com.qcadoo.model.api.Entity)1