Search in sources :

Example 26 with FieldComponent

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

the class TechnologyDetailsHooksPC method setRegisterPieceworkEnabledAndValue.

private void setRegisterPieceworkEnabledAndValue(final ViewDefinitionState view, final boolean isEnabled, final boolean value) {
    FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(TechnologyFieldsPC.REGISTER_PIECEWORK);
    fieldComponent.setEnabled(isEnabled);
    fieldComponent.setFieldValue(value);
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 27 with FieldComponent

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

the class StaffWorkTimeDetailsListeners method calculateLaborTime.

public void calculateLaborTime(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FieldComponent startDateFieldComponent = (FieldComponent) view.getComponentByReference(StaffWorkTimeFields.EFFECTIVE_EXECUTION_TIME_START);
    FieldComponent endDateFieldComponent = (FieldComponent) view.getComponentByReference(StaffWorkTimeFields.EFFECTIVE_EXECUTION_TIME_END);
    FieldComponent laborTimeFieldComponent = (FieldComponent) view.getComponentByReference(StaffWorkTimeFields.LABOR_TIME);
    Date start = DateUtils.parseDate(startDateFieldComponent.getFieldValue());
    Date end = DateUtils.parseDate(endDateFieldComponent.getFieldValue());
    if (start != null && end != null) {
        if (start.before(end)) {
            Seconds seconds = Seconds.secondsBetween(new DateTime(start), new DateTime(end));
            laborTimeFieldComponent.setFieldValue(Integer.valueOf(seconds.getSeconds()));
        }
        laborTimeFieldComponent.requestComponentUpdateState();
    } else {
        laborTimeFieldComponent.setFieldValue(null);
        laborTimeFieldComponent.requestComponentUpdateState();
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) Seconds(org.joda.time.Seconds) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 28 with FieldComponent

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

the class TrackingOperationProductComponentDetailsListeners method calculateQuantityToGiven.

public void calculateQuantityToGiven(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity productComponent = form.getPersistedEntityWithIncludedFormValues();
    Entity product = productComponent.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
    if (product == null) {
        return;
    }
    String unit = product.getStringField(ProductFields.UNIT);
    FieldComponent quantityField = (FieldComponent) view.getComponentByReference(TrackingOperationProductInComponentFields.USED_QUANTITY);
    if (StringUtils.isEmpty(unit) || quantityField.getFieldValue() == null) {
        return;
    }
    Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse((String) quantityField.getFieldValue(), view.getLocale());
    if (maybeQuantity.isRight()) {
        if (maybeQuantity.getRight().isPresent()) {
            BigDecimal quantity = maybeQuantity.getRight().get();
            String givenUnit = productComponent.getStringField(TrackingOperationProductInComponentFields.GIVEN_UNIT);
            if (givenUnit.equals(unit)) {
                productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, quantity);
            } else {
                PossibleUnitConversions unitConversions = unitConversionService.getPossibleConversions(unit, searchCriteriaBuilder -> searchCriteriaBuilder.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, product)));
                if (unitConversions.isDefinedFor(givenUnit)) {
                    BigDecimal convertedQuantity = unitConversions.convertTo(quantity, givenUnit, BigDecimal.ROUND_FLOOR);
                    productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, convertedQuantity);
                } else {
                    productComponent.addError(productComponent.getDataDefinition().getField(TrackingOperationProductInComponentFields.USED_QUANTITY), "technologies.operationProductInComponent.validate.error.missingUnitConversion");
                    productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, null);
                }
            }
        } else {
            productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, null);
        }
    } else {
        productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, null);
    }
    form.setEntity(productComponent);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) Optional(com.google.common.base.Optional) FieldComponent(com.qcadoo.view.api.components.FieldComponent) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) BigDecimal(java.math.BigDecimal)

Example 29 with FieldComponent

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

the class TrackingOperationProductComponentDetailsListeners method fillUnits.

private void fillUnits(final ViewDefinitionState view, final Entity productEntity) {
    String unit = productEntity.getStringField(ProductFields.UNIT);
    String additionalUnit = productEntity.getStringField(ProductFields.ADDITIONAL_UNIT);
    for (String componentReferenceName : UNIT_COMPONENT_REFERENCES) {
        FieldComponent unitComponent = (FieldComponent) view.getComponentByReference(componentReferenceName);
        if (unitComponent != null && StringUtils.isEmpty((String) unitComponent.getFieldValue())) {
            unitComponent.setFieldValue(unit);
            unitComponent.requestComponentUpdateState();
        }
    }
    if (!StringUtils.isEmpty(additionalUnit)) {
        FieldComponent givenUnit = (FieldComponent) view.getComponentByReference("givenUnit");
        givenUnit.setFieldValue(additionalUnit);
        givenUnit.setEnabled(false);
        givenUnit.requestComponentUpdateState();
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 30 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent 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)

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