Search in sources :

Example 31 with LookupComponent

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

the class AllStoppagesFormHooks method onBeforeRender.

public final void onBeforeRender(final ViewDefinitionState view) throws JSONException {
    if (Objects.isNull(((FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM)).getEntityId())) {
        JSONObject context = view.getJsonContext();
        if (view.isViewAfterRedirect() && context.has(L_CONTEXT_KEY_PRODUCTION_TRACKING)) {
            Long productionTrackingId = context.getLong(L_CONTEXT_KEY_PRODUCTION_TRACKING);
            Long orderId = context.getLong(L_CONTEXT_KEY_ORDER);
            LookupComponent orderLookupComponent = (LookupComponent) view.getComponentByReference(L_ORDER);
            orderLookupComponent.setFieldValue(orderId);
            orderLookupComponent.setEnabled(false);
            orderLookupComponent.requestComponentUpdateState();
            LookupComponent productionTrackingComponent = (LookupComponent) view.getComponentByReference(L_PRODUCTION_TRACKING);
            productionTrackingComponent.setFieldValue(productionTrackingId);
            productionTrackingComponent.setEnabled(false);
            productionTrackingComponent.requestComponentUpdateState();
        } else if (view.isViewAfterRedirect() && context.has(L_CONTEXT_KEY_ORDER)) {
            Long orderId = context.getLong(L_CONTEXT_KEY_ORDER);
            LookupComponent orderLookupComponent = (LookupComponent) view.getComponentByReference(L_ORDER);
            orderLookupComponent.setFieldValue(orderId);
            orderLookupComponent.setEnabled(false);
            orderLookupComponent.requestComponentUpdateState();
        }
    } else {
        LookupComponent orderLookupComponent = (LookupComponent) view.getComponentByReference(L_ORDER);
        LookupComponent productionTrackingComponent = (LookupComponent) view.getComponentByReference(L_PRODUCTION_TRACKING);
        JSONObject context = view.getJsonContext();
        if (Objects.nonNull(context) && context.has(L_CONTEXT_KEY_PRODUCTION_TRACKING)) {
            orderLookupComponent.setEnabled(false);
            productionTrackingComponent.setEnabled(false);
        }
        Entity order = orderLookupComponent.getEntity();
        if (order != null) {
            FilterValueHolder holder = productionTrackingComponent.getFilterValue();
            holder.put(StoppageFields.ORDER, order.getId());
            productionTrackingComponent.setFilterValue(holder);
        }
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 32 with LookupComponent

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

the class StoppageForOrderFormHooks method onBeforeRender.

public final void onBeforeRender(final ViewDefinitionState view) throws JSONException {
    LookupComponent orderLookupComponent = (LookupComponent) view.getComponentByReference(L_ORDER);
    orderLookupComponent.setEnabled(false);
    if (Objects.isNull(((FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM)).getEntityId())) {
        JSONObject context = view.getJsonContext();
        if (view.isViewAfterRedirect() && context.has(L_CONTEXT_KEY_ORDER)) {
            Long orderId = context.getLong(L_CONTEXT_KEY_ORDER);
            orderLookupComponent.setFieldValue(orderId);
            orderLookupComponent.requestComponentUpdateState();
            LookupComponent productionTrackingComponent = (LookupComponent) view.getComponentByReference(L_PRODUCTION_TRACKING);
            FilterValueHolder holder = productionTrackingComponent.getFilterValue();
            holder.put(StoppageFields.ORDER, orderId);
            productionTrackingComponent.setFilterValue(holder);
        }
    } else {
        LookupComponent productionTrackingComponent = (LookupComponent) view.getComponentByReference(L_PRODUCTION_TRACKING);
        Entity order = orderLookupComponent.getEntity();
        if (order != null) {
            FilterValueHolder holder = productionTrackingComponent.getFilterValue();
            holder.put(StoppageFields.ORDER, order.getId());
            productionTrackingComponent.setFilterValue(holder);
        }
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 33 with LookupComponent

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

the class AllStoppagesFormListeners method changeOrder.

public void changeOrder(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(StoppageFields.ORDER);
    LookupComponent productionTrackingLookup = (LookupComponent) view.getComponentByReference(StoppageFields.PRODUCTION_TRACKING);
    Entity order = orderLookup.getEntity();
    if (order != null) {
        FilterValueHolder holder = productionTrackingLookup.getFilterValue();
        holder.put(StoppageFields.ORDER, order.getId());
        productionTrackingLookup.setFilterValue(holder);
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 34 with LookupComponent

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

the class SupplyNegotiationsServiceImpl method fillOffer.

@Override
public void fillOffer(final ViewDefinitionState view, final Entity offer) {
    LookupComponent offerLookup = (LookupComponent) view.getComponentByReference(L_OFFER);
    if (offer == null) {
        offerLookup.setFieldValue(null);
    } else {
        offerLookup.setFieldValue(offer.getId());
    }
    offerLookup.requestComponentUpdateState();
}
Also used : LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 35 with LookupComponent

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

the class OrderedProductDetailsHooksSN method fillPricePerUnit.

public void fillPricePerUnit(final ViewDefinitionState view) {
    LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderedProductFields.PRODUCT);
    LookupComponent offerLookup = (LookupComponent) view.getComponentByReference(OrderedProductFieldsSN.OFFER);
    Entity product = productLookup.getEntity();
    Entity offer = offerLookup.getEntity();
    if ((product != null) && (offer != null)) {
        FieldComponent pricePerUnitField = (FieldComponent) view.getComponentByReference(OrderedProductFields.PRICE_PER_UNIT);
        FieldComponent totalPriceField = (FieldComponent) view.getComponentByReference(OrderedProductFields.TOTAL_PRICE);
        FieldComponent quantityField = (FieldComponent) view.getComponentByReference(OrderedProductFields.ORDERED_QUANTITY);
        BigDecimal quantity = deliveriesService.getBigDecimalFromField(quantityField, view.getLocale());
        BigDecimal pricePerUnit = supplyNegotiationsService.getPricePerUnit(offer, product);
        if ((quantity != null) && (pricePerUnit != null)) {
            BigDecimal totalPrice = quantity.multiply(pricePerUnit, numberService.getMathContext());
            pricePerUnitField.setFieldValue(numberService.format(pricePerUnit));
            totalPriceField.setFieldValue(numberService.format(totalPrice));
        } else {
            if (pricePerUnit == null) {
                pricePerUnitField.setFieldValue(null);
            } else {
                pricePerUnitField.setFieldValue(numberService.format(pricePerUnit));
            }
            totalPriceField.setFieldValue(null);
        }
        totalPriceField.requestComponentUpdateState();
        pricePerUnitField.requestComponentUpdateState();
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal)

Aggregations

LookupComponent (com.qcadoo.view.api.components.LookupComponent)277 Entity (com.qcadoo.model.api.Entity)182 FieldComponent (com.qcadoo.view.api.components.FieldComponent)105 FormComponent (com.qcadoo.view.api.components.FormComponent)102 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)69 BigDecimal (java.math.BigDecimal)16 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)12 GridComponent (com.qcadoo.view.api.components.GridComponent)11 WindowComponent (com.qcadoo.view.api.components.WindowComponent)8 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)7 Date (java.util.Date)6 JSONObject (org.json.JSONObject)6 ComponentState (com.qcadoo.view.api.ComponentState)5 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)5 JSONException (org.json.JSONException)5 DataDefinition (com.qcadoo.model.api.DataDefinition)3 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)3 Optional (com.google.common.base.Optional)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2