Search in sources :

Example 31 with AwesomeDynamicListComponent

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

the class OrderDetailsHooks method changedEnabledAwesomeDynamicListComponents.

private void changedEnabledAwesomeDynamicListComponents(final ViewDefinitionState view, final List<String> references, final boolean enabled) {
    for (String reference : references) {
        AwesomeDynamicListComponent awesomeDynamicListComponent = (AwesomeDynamicListComponent) view.getComponentByReference(reference);
        awesomeDynamicListComponent.setEnabled(enabled);
        awesomeDynamicListComponent.requestComponentUpdateState();
        for (FormComponent formComponent : awesomeDynamicListComponent.getFormComponents()) {
            FieldComponent fieldComponent = formComponent.findFieldComponentByName(L_REASON_TYPE_OF_CHANGING_ORDER_STATE);
            fieldComponent.setEnabled(enabled);
            fieldComponent.requestComponentUpdateState();
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

Example 32 with AwesomeDynamicListComponent

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

the class DivideOrderTechnologicalProcessListeners method onAddRow.

public void onAddRow(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent orderTechnologicalProcessForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    AwesomeDynamicListComponent orderTechnologicalProcessPartsADL = (AwesomeDynamicListComponent) view.getComponentByReference(OrderTechnologicalProcessFields.ORDER_TECHNOLOGICAL_PROCESS_PARTS);
    Entity orderTechnologicalProcess = orderTechnologicalProcessForm.getEntity();
    Long orderTechnologicalProcessId = orderTechnologicalProcess.getId();
    orderTechnologicalProcess = orderTechnologicalProcess.getDataDefinition().get(orderTechnologicalProcessId);
    Entity product = orderTechnologicalProcess.getBelongsToField(OrderTechnologicalProcessFields.PRODUCT);
    String productUnit = product.getStringField(ProductFields.UNIT);
    List<FormComponent> orderTechnologicalProcessPartForms = orderTechnologicalProcessPartsADL.getFormComponents();
    for (FormComponent orderTechnologicalProcessPartForm : orderTechnologicalProcessPartForms) {
        FieldComponent numberField = orderTechnologicalProcessPartForm.findFieldComponentByName(OrderTechnologicalProcessPartFields.NUMBER);
        FieldComponent unitField = orderTechnologicalProcessPartForm.findFieldComponentByName(OrderTechnologicalProcessPartFields.UNIT);
        String number = (String) numberField.getFieldValue();
        String unit = (String) unitField.getFieldValue();
        if (StringUtils.isEmpty(number)) {
            numberField.setFieldValue(String.valueOf(orderTechnologicalProcessPartForms.size()));
        }
        numberField.requestComponentUpdateState();
        if (StringUtils.isEmpty(unit)) {
            unitField.setFieldValue(productUnit);
        }
        unitField.requestComponentUpdateState();
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

Example 33 with AwesomeDynamicListComponent

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

the class ProductsToIssueDetailsHooks method fillUnits.

public void fillUnits(final ViewDefinitionState view) {
    AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues");
    for (FormComponent form : adl.getFormComponents()) {
        Entity issue = form.getPersistedEntityWithIncludedFormValues();
        Entity product = issue.getBelongsToField(IssueFields.PRODUCT);
        if (Objects.nonNull(product)) {
            FieldComponent unitField = form.findFieldComponentByName(ProductFields.UNIT);
            FieldComponent additionalUnitField = form.findFieldComponentByName(ProductFields.ADDITIONAL_UNIT);
            unitField.setFieldValue(product.getStringField(ProductFields.UNIT));
            String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
            if (StringUtils.isEmpty(additionalUnit)) {
                additionalUnitField.setFieldValue(product.getStringField(ProductFields.UNIT));
            } else {
                additionalUnitField.setFieldValue(additionalUnit);
            }
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

Example 34 with AwesomeDynamicListComponent

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

the class ProductToIssueCorrectionDetailsListeners method correct.

public void correct(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity helper = form.getPersistedEntityWithIncludedFormValues();
    Entity locationTo = helper.getBelongsToField("locationTo");
    if (locationTo == null) {
        FieldComponent locationToField = (FieldComponent) view.getComponentByReference("locationTo");
        locationToField.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.error.locationToRequired", ComponentState.MessageType.FAILURE);
        return;
    }
    List<Entity> corrections = helper.getHasManyField("corrections");
    List<Entity> savedCorrections = Lists.newArrayList();
    corrections.forEach(correction -> savedCorrections.add(correction.getDataDefinition().save(correction)));
    helper.setField("corrections", savedCorrections);
    form.setEntity(helper);
    if (savedCorrections.stream().anyMatch(correction -> !correction.isValid())) {
        AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("corrections");
        for (FormComponent formComponent : adl.getFormComponents()) {
            Entity formEntity = formComponent.getEntity();
            formEntity.getErrors().forEach((field, errorMessage) -> {
                FieldComponent fieldComponent = formComponent.findFieldComponentByName(field);
                fieldComponent.addMessage(errorMessage);
            });
        }
        view.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.error", ComponentState.MessageType.FAILURE);
    } else {
        try {
            List<Entity> newWarehouseIssues = productToIssueCorrectionService.correctProductsToIssue(helper, savedCorrections);
            helper.setField("corrections", savedCorrections);
            form.setEntity(helper);
            form.setFormEnabled(false);
            view.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.success", ComponentState.MessageType.SUCCESS, newWarehouseIssues.stream().map(issue -> issue.getStringField(WarehouseIssueFields.NUMBER)).collect(Collectors.joining(", ")));
            afterSuccessfulCreateCorrectionsHooks(view, savedCorrections);
        } catch (IllegalStateException e) {
            view.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.error.newWarehouseIssue", ComponentState.MessageType.FAILURE);
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

Example 35 with AwesomeDynamicListComponent

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

the class ProductToIssueCorrectionDetailsListeners method additionalQuantityChanged.

public void additionalQuantityChanged(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("corrections");
    List<FormComponent> formComponenets = adl.getFormComponents();
    for (FormComponent formComponent : formComponenets) {
        FieldComponent additionalQuantityField = formComponent.findFieldComponentByName("correctionQuantityInAdditionalUnit");
        Entity formEntity = formComponent.getPersistedEntityWithIncludedFormValues();
        BigDecimal conversion = formEntity.getDecimalField(ProductToIssueCorrectionFields.CONVERSION);
        FieldComponent quantity = formComponent.findFieldComponentByName("correctionQuantity");
        if (additionalQuantityField.getUuid().equals(state.getUuid())) {
            Either<Exception, com.google.common.base.Optional<BigDecimal>> maybeAdditionalQuantity = BigDecimalUtils.tryParse(additionalQuantityField.getFieldValue().toString(), LocaleContextHolder.getLocale());
            if (conversion != null && maybeAdditionalQuantity.isRight() && maybeAdditionalQuantity.getRight().isPresent()) {
                BigDecimal additionalQuantity = maybeAdditionalQuantity.getRight().get();
                BigDecimal newQuantity = additionalQuantity.divide(conversion, numberService.getMathContext());
                newQuantity = newQuantity.setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP);
                quantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newQuantity, 0));
                quantity.requestComponentUpdateState();
            } else if (maybeAdditionalQuantity.isLeft()) {
                additionalQuantityField.setFieldValue(quantity.getFieldValue());
                additionalQuantityField.addMessage("productFlowThruDivision.productsToIssueHelperDetails.error.invalidQuantity", ComponentState.MessageType.FAILURE);
            } else {
                quantity.setFieldValue(null);
            }
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) BigDecimal(java.math.BigDecimal)

Aggregations

AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)36 FormComponent (com.qcadoo.view.api.components.FormComponent)26 Entity (com.qcadoo.model.api.Entity)24 FieldComponent (com.qcadoo.view.api.components.FieldComponent)12 BigDecimal (java.math.BigDecimal)6 ProgressType (com.qcadoo.mes.productionPerShift.constants.ProgressType)4 LookupComponent (com.qcadoo.view.api.components.LookupComponent)4 Optional (com.google.common.base.Optional)2 OrderState (com.qcadoo.mes.orders.states.constants.OrderState)2 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)2 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)2 Function (com.google.common.base.Function)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 EntityRuntimeException (com.qcadoo.model.api.exception.EntityRuntimeException)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 BigInteger (java.math.BigInteger)1 Around (org.aspectj.lang.annotation.Around)1 JSONException (org.json.JSONException)1 Transactional (org.springframework.transaction.annotation.Transactional)1