Search in sources :

Example 6 with CheckBoxComponent

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

the class TrackingOperationProductInComponentDetailsListeners method onWasteUsedOnlyChange.

public void onWasteUsedOnlyChange(final ViewDefinitionState view, final ComponentState wasteUsedOnly, final String[] args) {
    if (((CheckBoxComponent) wasteUsedOnly).isChecked()) {
        Entity entity = getFormEntity(view);
        Entity savedEntity = entity.getDataDefinition().get(entity.getId());
        BigDecimal savedUsedQuantity = savedEntity.getDecimalField(TrackingOperationProductInComponentFields.USED_QUANTITY);
        BigDecimal savedWasteUsed = convertNullToZero(savedEntity.getDecimalField(TrackingOperationProductInComponentFields.WASTE_USED_QUANTITY));
        if (savedUsedQuantity != null && savedUsedQuantity.compareTo(BigDecimal.ZERO) > 0) {
            FieldComponent usedQuantity = (FieldComponent) view.getComponentByReference(L_USED_QUANTITY);
            FieldComponent wasteUsedQuantity = (FieldComponent) view.getComponentByReference(L_WASTE_USED_QUANTITY);
            BigDecimal newValue = savedUsedQuantity.add(savedWasteUsed, numberService.getMathContext());
            wasteUsedQuantity.setFieldValue(numberService.format(newValue));
            usedQuantity.setFieldValue(numberService.format(BigDecimal.ZERO));
            trackingOperationProductComponentDetailsListeners.calculateQuantityToGiven(view, usedQuantity, ArrayUtils.EMPTY_STRING_ARRAY);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 7 with CheckBoxComponent

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

the class UseReplacementListeners method addReplacement.

public void addReplacement(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
    generated.setChecked(false);
    Entity entity = form.getPersistedEntityWithIncludedFormValues();
    entity = entity.getDataDefinition().validate(entity);
    if (!entity.isValid()) {
        form.setEntity(entity);
        return;
    }
    JSONObject context = view.getJsonContext();
    Long productionTrackingId = context.getLong(WINDOW_MAIN_TAB_FORM_PRODUCTION_TRACKING);
    Long basicProductId = context.getLong(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT);
    Entity productionTracking = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING).get(productionTrackingId);
    Entity productIn = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_TRACKING_OPERATION_PRODUCT_IN_COMPONENT).find().add(SearchRestrictions.belongsTo(TrackingOperationProductInComponentFields.PRODUCTION_TRACKING, productionTracking)).add(SearchRestrictions.belongsTo(TrackingOperationProductInComponentFields.PRODUCT, entity.getBelongsToField(PRODUCT))).setMaxResults(1).uniqueResult();
    if (Objects.isNull(productIn)) {
        Entity in = createInProductTracking(entity, productionTracking, basicProductId);
        if (!in.isValid()) {
            view.addMessage("productionCounting.useReplacement.error", ComponentState.MessageType.FAILURE);
        } else {
            generated.setChecked(true);
        }
    } else {
        view.addMessage("productionCounting.useReplacement.productExists", ComponentState.MessageType.FAILURE, false);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 8 with CheckBoxComponent

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

the class ProductionCountingParametersListeners method onReleaseOfMaterialsChange.

public void onReleaseOfMaterialsChange(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    CheckBoxComponent consumptionOfRawMaterialsBasedOnStandards = (CheckBoxComponent) view.getComponentByReference(ParameterFieldsPC.CONSUMPTION_OF_RAW_MATERIALS_BASED_ON_STANDARDS);
    FieldComponent releaseOfMaterials = (FieldComponent) view.getComponentByReference(ParameterFieldsPC.RELEASE_OF_MATERIALS);
    if (ReleaseOfMaterials.MANUALLY_TO_ORDER_OR_GROUP.getStringValue().equals(releaseOfMaterials.getFieldValue().toString())) {
        consumptionOfRawMaterialsBasedOnStandards.setChecked(false);
        consumptionOfRawMaterialsBasedOnStandards.setEnabled(false);
    } else {
        consumptionOfRawMaterialsBasedOnStandards.setEnabled(true);
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 9 with CheckBoxComponent

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

the class AnomalyExplanationDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity entity = form.getEntity();
    if (view.isViewAfterRedirect()) {
        initializeFormValues(view, entity);
    }
    boolean useWaste = ((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked();
    LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
    productLookup.setEnabled(!useWaste);
    view.getComponentByReference("location").setEnabled(!useWaste);
    ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
    String givenUnit = (String) givenUnitComponent.getFieldValue();
    Entity selectedProduct = productLookup.getEntity();
    boolean shouldAdditionalUnitBeEnabled = true;
    if (selectedProduct != null) {
        String selectedProductAdditionalUnit = selectedProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
        if (isNotBlank(selectedProductAdditionalUnit) && isNotBlank(givenUnit) && selectedProductAdditionalUnit.equals(givenUnit)) {
            shouldAdditionalUnitBeEnabled = false;
        }
    }
    givenUnitComponent.setEnabled(shouldAdditionalUnitBeEnabled);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 10 with CheckBoxComponent

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

the class AnomalyExplanationDetailsHooks method initializeFormValues.

private void initializeFormValues(ViewDefinitionState view, Entity entity) {
    LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
    if (entity.getId() == null) {
        Entity anomaly = entity.getBelongsToField(AnomalyExplanationFields.ANOMALY);
        Entity anomalyProduct = anomaly.getBelongsToField(AnomalyFields.PRODUCT);
        productLookup.setFieldValue(anomalyProduct.getId());
        String selectedProductUnit = anomalyProduct.getStringField(ProductFields.UNIT);
        String additionalSelectedProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
        ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
        if (isNotBlank(additionalSelectedProductUnit)) {
            givenUnitComponent.setFieldValue(additionalSelectedProductUnit);
        } else {
            givenUnitComponent.setFieldValue(selectedProductUnit);
        }
        BigDecimal anomalyUsedQuantity = anomaly.getDecimalField(AnomalyFields.USED_QUANTITY);
        view.getComponentByReference("usedQuantity").setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
        String additionalAnomalyProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
        ComponentState givenQuantityComponent = view.getComponentByReference("givenQuantity");
        if (isNotBlank(additionalAnomalyProductUnit)) {
            productUnitsConversionService.forProduct(anomalyProduct).fromPrimaryUnit().to(additionalAnomalyProductUnit).convertValue(anomalyUsedQuantity).ifPresent(convertedValue -> {
                givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(convertedValue, 0));
            });
        } else {
            givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
        }
        Entity anomalyLocation = anomaly.getBelongsToField(AnomalyFields.LOCATION);
        view.getComponentByReference("location").setFieldValue(ofNullable(anomalyLocation).map(Entity::getId).orElse(null));
    }
    Entity selectedProduct = productLookup.getEntity();
    ComponentState productUnit = view.getComponentByReference("productUnit");
    ComponentState usedQuantity = view.getComponentByReference("usedQuantity");
    if (selectedProduct != null) {
        productUnit.setFieldValue(selectedProduct.getStringField(ProductFields.UNIT));
        usedQuantity.setEnabled(true);
    } else {
        if (((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked()) {
            productUnit.setFieldValue(entity.getStringField(AnomalyExplanationFields.GIVEN_UNIT));
        } else {
            productUnit.setFieldValue(null);
        }
        usedQuantity.setEnabled(false);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) BigDecimal(java.math.BigDecimal) ComponentState(com.qcadoo.view.api.ComponentState) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Aggregations

CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)100 FormComponent (com.qcadoo.view.api.components.FormComponent)38 Entity (com.qcadoo.model.api.Entity)33 FieldComponent (com.qcadoo.view.api.components.FieldComponent)30 GridComponent (com.qcadoo.view.api.components.GridComponent)19 LookupComponent (com.qcadoo.view.api.components.LookupComponent)11 Date (java.util.Date)7 JSONObject (org.json.JSONObject)7 BigDecimal (java.math.BigDecimal)6 ComponentState (com.qcadoo.view.api.ComponentState)4 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)4 IOException (java.io.IOException)4 MaterialFlowResourcesConstants (com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants)2 DataDefinition (com.qcadoo.model.api.DataDefinition)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)2 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)2