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);
}
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();
}
}
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);
}
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();
}
}
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);
}
}
}
Aggregations