Search in sources :

Example 1 with AwesomeDynamicListComponent

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

the class ProductsToIssueDetailsHooks method fillQuantitiesInAdditionalUnit.

public void fillQuantitiesInAdditionalUnit(final ViewDefinitionState view) {
    AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues");
    for (FormComponent form : adl.getFormComponents()) {
        Entity issue = form.getPersistedEntityWithIncludedFormValues();
        FieldComponent quantityField = form.findFieldComponentByName("issueQuantity");
        Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse(quantityField.getFieldValue().toString(), LocaleContextHolder.getLocale());
        BigDecimal conversion = issue.getDecimalField(IssueFields.CONVERSION);
        if (Objects.nonNull(conversion) && maybeQuantity.isRight() && maybeQuantity.getRight().isPresent()) {
            Entity product = issue.getBelongsToField(IssueFields.PRODUCT);
            String unit = product.getStringField(ProductFields.UNIT);
            String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
            BigDecimal issueQuantity = maybeQuantity.getRight().get();
            BigDecimal issuedQuantityAdditionalUnit = calculationQuantityService.calculateAdditionalQuantity(issueQuantity, conversion, Optional.fromNullable(additionalUnit).or(unit));
            issue.setField(IssueFields.ISSUE_QUANTITY_ADDITIONAL_UNIT, issuedQuantityAdditionalUnit);
            form.setEntity(issue);
        }
    }
}
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) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) JSONException(org.json.JSONException) BigDecimal(java.math.BigDecimal)

Example 2 with AwesomeDynamicListComponent

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

the class AnomalyProductionTrackingDetailsListeners method createAnomalies.

private void createAnomalies(final ViewDefinitionState view) {
    AwesomeDynamicListComponent anomalyProductionTrackingEntriesADL = (AwesomeDynamicListComponent) view.getComponentByReference("anomalyProductionTrackingEntries");
    List<Entity> entities = anomalyProductionTrackingEntriesADL.getEntities();
    for (Entity entity : entities) {
        createAnomaly(entity);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

Example 3 with AwesomeDynamicListComponent

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

the class AnomalyProductionTrackingDetailsListeners method validate.

private boolean validate(final ViewDefinitionState view) {
    AwesomeDynamicListComponent anomalyProductionTrackingEntriesADL = (AwesomeDynamicListComponent) view.getComponentByReference("anomalyProductionTrackingEntries");
    List<Entity> entities = anomalyProductionTrackingEntriesADL.getEntities();
    boolean valid = Boolean.TRUE;
    for (Entity entry : entities) {
        List<Entity> anomalyContainers = entry.getHasManyField("anomalyReasons");
        if (anomalyContainers.isEmpty()) {
            valid = Boolean.FALSE;
        }
        for (Entity ac : anomalyContainers) {
            if (Objects.isNull(ac.getBelongsToField("anomalyReason"))) {
                valid = Boolean.FALSE;
            }
        }
    }
    return valid;
}
Also used : Entity(com.qcadoo.model.api.Entity) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

Example 4 with AwesomeDynamicListComponent

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

the class AnomalyProductionTrackingDetailsListeners method clearQuantitiesInRR.

private void clearQuantitiesInRR(ViewDefinitionState view) {
    AwesomeDynamicListComponent anomalyProductionTrackingEntriesADL = (AwesomeDynamicListComponent) view.getComponentByReference("anomalyProductionTrackingEntries");
    List<Entity> entities = anomalyProductionTrackingEntriesADL.getEntities();
    for (Entity entity : entities) {
        Entity trackingOperationProductInComponent = entity.getBelongsToField("trackingOperationProductInComponent");
        trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.USED_QUANTITY, BigDecimal.ZERO);
        trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, BigDecimal.ZERO);
        trackingOperationProductInComponent = trackingOperationProductInComponent.getDataDefinition().save(trackingOperationProductInComponent);
        if (!trackingOperationProductInComponent.isValid()) {
            throw new EntityRuntimeException(trackingOperationProductInComponent);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

Example 5 with AwesomeDynamicListComponent

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

the class AnomalyProductionTrackingDetailsHooks method updateADLState.

private void updateADLState(final ViewDefinitionState view, final List<Entity> entries) {
    AwesomeDynamicListComponent anomalyProductionTrackingEntriesADL = (AwesomeDynamicListComponent) view.getComponentByReference("anomalyProductionTrackingEntries");
    anomalyProductionTrackingEntriesADL.setFieldValue(entries);
    anomalyProductionTrackingEntriesADL.requestComponentUpdateState();
}
Also used : AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent)

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