Search in sources :

Example 6 with FormComponent

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

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

the class WarehouseIssueDetailHooks method processProductsToIssueMode.

private void processProductsToIssueMode(final ViewDefinitionState view) {
    FieldComponent component = (FieldComponent) view.getComponentByReference(WarehouseIssueFields.PRODUCTS_TO_ISSUE_MODE);
    if (!warehouseIssueParameterService.issueForOrder()) {
        component.setVisible(false);
        component.requestComponentUpdateState();
        return;
    }
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    if (view.isViewAfterRedirect() && Objects.isNull(form.getEntityId())) {
        component.setFieldValue(warehouseIssueParameterService.getProductsToIssue().getStrValue());
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 8 with FormComponent

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

the class ProductsToIssueDetailsListeners method onAdditionalDemandQuantityChange.

public void onAdditionalDemandQuantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity productToIssue = form.getPersistedEntityWithIncludedFormValues();
    if (!checkIfDecimalFieldsCorrect(productToIssue, form)) {
        return;
    }
    BigDecimal conversion = productToIssue.getDecimalField(ProductsToIssueFields.CONVERSION);
    BigDecimal additionalDemandQuantity = productToIssue.getDecimalField(ProductsToIssueFields.ADDITIONAL_DEMAND_QUANTITY);
    if (conversion != null && additionalDemandQuantity != null) {
        FieldComponent demandQuantity = (FieldComponent) view.getComponentByReference(ProductsToIssueFields.DEMAND_QUANTITY);
        Entity product = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT);
        BigDecimal newDemandQuantity = calculationQuantityService.calculateQuantity(additionalDemandQuantity, conversion, product.getStringField(ProductFields.UNIT));
        demandQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newDemandQuantity, 0));
        demandQuantity.requestComponentUpdateState();
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal)

Example 9 with FormComponent

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

the class TOCDetailsHooksPFTD method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent tocForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    if (tocForm.getEntityId() == null) {
        return;
    }
    Entity technology = tocForm.getPersistedEntityWithIncludedFormValues().getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
    LookupComponent divisionLookupComponent = (LookupComponent) view.getComponentByReference("division");
    divisionLookupComponent.setEnabled(!Range.ONE_DIVISION.getStringValue().equals(technology.getStringField(TechnologyFieldsPFTD.RANGE)));
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 10 with FormComponent

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

the class TechnologyDetailsHooksPFTD method changeRibbonState.

private void changeRibbonState(final ViewDefinitionState view) {
    FormComponent technologyForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Long technologyId = technologyForm.getEntityId();
    if (Objects.isNull(technologyId)) {
        return;
    }
    Entity technology = technologyForm.getPersistedEntityWithIncludedFormValues();
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonGroup flow = window.getRibbon().getGroupByName(L_PRODUCTS_FLOW);
    RibbonActionItem fillLocationsInComponents = flow.getItemByName(L_FILL_LOCATIONS_IN_COMPONENTS);
    RibbonGroup modelCard = window.getRibbon().getGroupByName(MODEL_CARD);
    RibbonGroup productionLines = window.getRibbon().getGroupByName(PRODUCTION_LINES);
    RibbonActionItem addMultipleProductionLines = productionLines.getItemByName(ADD_MULTIPLE_PRODUCTION_LINES);
    String state = technology.getStringField(TechnologyFields.STATE);
    boolean isTemplateAccepted = technology.getBooleanField(TechnologyFields.IS_TEMPLATE_ACCEPTED);
    fillLocationsInComponents.setEnabled(!isTemplateAccepted && TechnologyState.DRAFT.getStringValue().equals(state));
    fillLocationsInComponents.requestUpdate(true);
    addMultipleProductionLines.setEnabled(!isTemplateAccepted && TechnologyState.DRAFT.getStringValue().equals(state));
    addMultipleProductionLines.requestUpdate(true);
    if (Objects.nonNull(modelCard)) {
        RibbonActionItem createModelCard = modelCard.getItemByName(CREATE_MODEL_CARD);
        createModelCard.setEnabled(TechnologyState.CHECKED.getStringValue().equals(state) || TechnologyState.ACCEPTED.getStringValue().equals(state));
        createModelCard.requestUpdate(true);
    }
    window.requestRibbonRender();
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Aggregations

FormComponent (com.qcadoo.view.api.components.FormComponent)644 Entity (com.qcadoo.model.api.Entity)501 FieldComponent (com.qcadoo.view.api.components.FieldComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)104 GridComponent (com.qcadoo.view.api.components.GridComponent)83 BigDecimal (java.math.BigDecimal)55 WindowComponent (com.qcadoo.view.api.components.WindowComponent)52 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)45 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)42 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)39 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)36 Date (java.util.Date)33 DataDefinition (com.qcadoo.model.api.DataDefinition)29 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)28 JSONObject (org.json.JSONObject)28 ComponentState (com.qcadoo.view.api.ComponentState)27 Transactional (org.springframework.transaction.annotation.Transactional)20 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)17 Optional (com.google.common.base.Optional)16 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)16