Search in sources :

Example 46 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class ProductionPerShiftDetailsHooks method fillOrderDateComponents.

void fillOrderDateComponents(final ViewDefinitionState view, final Entity order) {
    for (ImmutableMap.Entry<String, String> modelFieldToViewReference : ORDER_DATE_FIELDS_TO_VIEW_COMPONENTS.entrySet()) {
        FieldComponent dateComponent = (FieldComponent) view.getComponentByReference(modelFieldToViewReference.getValue());
        Date date = order.getDateField(modelFieldToViewReference.getKey());
        dateComponent.setFieldValue(DateUtils.toDateTimeString(date));
        dateComponent.requestComponentUpdateState();
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) ImmutableMap(com.google.common.collect.ImmutableMap) Date(java.util.Date)

Example 47 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class GenerateBalanceListeners method onFilterCheckboxChange.

public void onFilterCheckboxChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
    CheckBoxComponent plannedRequiredCheckbox = (CheckBoxComponent) view.getComponentByReference("plannedQuantityRequired");
    CheckBoxComponent deviationRequiredCheckbox = (CheckBoxComponent) view.getComponentByReference("deviationRequired");
    FieldComponent deviationThreshold = (FieldComponent) view.getComponentByReference("deviationThreshold");
    if (plannedRequiredCheckbox == null || deviationRequiredCheckbox == null) {
        return;
    }
    deviationRequiredCheckbox.setEnabled(plannedRequiredCheckbox.isChecked());
    if (!plannedRequiredCheckbox.isChecked()) {
        deviationRequiredCheckbox.setChecked(false);
    }
    boolean thresholdEnabled = plannedRequiredCheckbox.isChecked() && deviationRequiredCheckbox.isChecked();
    deviationThreshold.setEnabled(thresholdEnabled);
    deviationThreshold.setRequired(thresholdEnabled);
    if (!(plannedRequiredCheckbox.isChecked() && deviationRequiredCheckbox.isChecked())) {
        deviationThreshold.setFieldValue(null);
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 48 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class OperationDurationDetailsInOrderListeners method generateRealizationTime.

@Transactional
public void generateRealizationTime(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) {
    FormComponent orderForm = (FormComponent) viewDefinitionState.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent startTimeField = (FieldComponent) viewDefinitionState.getComponentByReference(L_START_TIME);
    LookupComponent prodLine = (LookupComponent) viewDefinitionState.getComponentByReference(OrderFields.PRODUCTION_LINE);
    if (!StringUtils.hasText((String) startTimeField.getFieldValue())) {
        startTimeField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    if (prodLine.isEmpty()) {
        prodLine.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    FieldComponent plannedQuantityField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PLANNED_QUANTITY);
    FieldComponent productionLineLookup = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PRODUCTION_LINE);
    FieldComponent generatedEndDateField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.GENERATED_END_DATE);
    FieldComponent includeTpzField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_TPZ);
    FieldComponent includeAdditionalTimeField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_ADDITIONAL_TIME);
    boolean isGenerated = false;
    Entity productionLine = dataDefinitionService.get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE).get((Long) productionLineLookup.getFieldValue());
    Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderForm.getEntity().getId());
    // copy of technology from order
    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
    Validate.notNull(technology, "technology is null");
    BigDecimal quantity = orderRealizationTimeService.getBigDecimalFromField(plannedQuantityField.getFieldValue(), viewDefinitionState.getLocale());
    // Included in work time
    boolean includeTpz = "1".equals(includeTpzField.getFieldValue());
    boolean includeAdditionalTime = "1".equals(includeAdditionalTimeField.getFieldValue());
    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    productQuantitiesService.getProductComponentQuantities(technology, quantity, operationRuns);
    operationWorkTimeService.deleteOperCompTimeCalculations(order);
    OperationWorkTime workTime = operationWorkTimeService.estimateTotalWorkTimeForOrder(order, operationRuns, includeTpz, includeAdditionalTime, true);
    fillWorkTimeFields(viewDefinitionState, workTime);
    order = getActualOrderWithChanges(order);
    int maxPathTime = orderRealizationTimeService.estimateMaxOperationTimeConsumptionForWorkstation(order, technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(), quantity, includeTpz, includeAdditionalTime, productionLine);
    if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) {
        state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", MessageType.FAILURE);
        generatedEndDateField.setFieldValue(null);
    } else {
        order.setField(OrderFieldsPS.REALIZATION_TIME, maxPathTime);
        Date startTime = order.getDateField(OrderFields.DATE_FROM);
        if (startTime == null) {
            startTimeField.addMessage("orders.validate.global.error.dateFromIsNull", MessageType.FAILURE);
        } else {
            if (maxPathTime == 0) {
                orderForm.addMessage("productionScheduling.timenorms.isZero", MessageType.FAILURE, false);
                generatedEndDateField.setFieldValue(null);
            } else {
                productionSchedulingService.scheduleOrder(order.getId());
                isGenerated = true;
            }
            orderForm.addMessage("orders.dateFrom.info.dateFromSetToFirstPossible", MessageType.INFO, false);
        }
    }
    generatedEndDateField.requestComponentUpdateState();
    if (isGenerated) {
        order = getActualOrderWithChanges(order);
        Entity orderTimeCalculation = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().add(SearchRestrictions.belongsTo(OrderTimeCalculationFields.ORDER, order)).setMaxResults(1).uniqueResult();
        order.setField(OrderFields.START_DATE, orderRealizationTimeService.setDateToField(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_FROM)));
        order.setField(OrderFieldsPS.GENERATED_END_DATE, orderRealizationTimeService.setDateToField(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO)));
        order = order.getDataDefinition().save(order);
        orderForm.setEntity(order);
        orderForm.addMessage("productionScheduling.info.calculationGenerated", MessageType.SUCCESS);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class GenerateBalanceViewHooks method fillDeviationThresholdUnit.

private void fillDeviationThresholdUnit(final ViewDefinitionState viewState) {
    FieldComponent deviationThresholdUnitComponent = (FieldComponent) findComponent(viewState, "deviationThresholdUnit");
    deviationThresholdUnitComponent.setFieldValue("%");
    deviationThresholdUnitComponent.requestComponentUpdateState();
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 50 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class OrderTimePredictionListeners method fillUnitField.

public void fillUnitField(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY);
    FieldComponent unitField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.OPERATION_DURATION_QUANTITY_UNIT);
    Entity technology = technologyLookup.getEntity();
    if (technology != null) {
        Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
        if (product != null) {
            unitField.setFieldValue(product.getField(ProductFields.UNIT));
            unitField.requestComponentUpdateState();
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Aggregations

FieldComponent (com.qcadoo.view.api.components.FieldComponent)443 Entity (com.qcadoo.model.api.Entity)201 FormComponent (com.qcadoo.view.api.components.FormComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)107 BigDecimal (java.math.BigDecimal)47 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)31 Date (java.util.Date)30 Optional (com.google.common.base.Optional)18 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)14 ComponentState (com.qcadoo.view.api.ComponentState)13 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)13 WindowComponent (com.qcadoo.view.api.components.WindowComponent)12 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)11 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)9 PossibleUnitConversions (com.qcadoo.model.api.units.PossibleUnitConversions)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)6 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)6 Collectors (java.util.stream.Collectors)6