Search in sources :

Example 86 with GridComponent

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

the class MasterOrderPositionsListListeners method goToGenerateOrders.

public void goToGenerateOrders(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent masterOrderPositionGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    Set<Long> selected = masterOrderPositionGrid.getSelectedEntitiesIds();
    boolean createCollectiveOrders = parameterService.getParameter().getBooleanField(L_CREATE_COLLECTIVE_ORDERS);
    if (createCollectiveOrders) {
        Entity generatingOrders = getGeneratingOrdersHelperDD().create();
        generatingOrders.setField(GeneratingOrdersHelperFields.SELECTED_ENTITIES, selected.stream().map(Object::toString).collect(Collectors.joining(",")));
        generatingOrders = generatingOrders.getDataDefinition().save(generatingOrders);
        Map<String, Object> parameters = Maps.newHashMap();
        parameters.put("form.id", generatingOrders.getId());
        String url = "../page/masterOrders/generatingOrders.html";
        view.openModal(url, parameters);
    } else {
        List<Entity> masterOrderProducts = getMasterOrderPositionDtoDD().find().add(SearchRestrictions.in("id", selected)).list().getEntities();
        ordersGenerationService.generateOrders(masterOrderProducts, null, null, true).showMessage(view);
        state.performEvent(view, "reset");
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 87 with GridComponent

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

the class MasterOrderPositionsListListeners method showGroupedByProduct.

public void showGroupedByProduct(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent masterOrderPositionGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put("positionsIds", masterOrderPositionGrid.getSelectedEntitiesIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
    String url = "../page/masterOrders/masterOrderPositionsGroupedByProductList.html";
    view.redirectTo(url, false, true, parameters);
}
Also used : GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 88 with GridComponent

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

the class MasterOrdersListListeners method changeState.

public void changeState(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent gridComponent = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    for (Long masterOrderId : gridComponent.getSelectedEntitiesIds()) {
        Entity masterOrderDB = getMasterOrderDD().get(masterOrderId);
        String status = args[0];
        if (status.equals(MasterOrderState.COMPLETED.getStringValue())) {
            masterOrderDB.setField(MasterOrderFields.STATE, MasterOrderState.COMPLETED.getStringValue());
            masterOrderDB.getDataDefinition().save(masterOrderDB);
        } else if (status.equals(MasterOrderState.DECLINED.getStringValue())) {
            masterOrderDB.setField(MasterOrderFields.STATE, MasterOrderState.DECLINED.getStringValue());
            masterOrderDB.getDataDefinition().save(masterOrderDB);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 89 with GridComponent

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

the class SalesPlanDetailsListeners method createOrders.

public void createOrders(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent salesPlanForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    GridComponent productsGrid = (GridComponent) view.getComponentByReference(SalesPlanFields.PRODUCTS);
    Entity salesPlan = salesPlanForm.getEntity().getDataDefinition().get(salesPlanForm.getEntityId());
    Entity salesPlanOrdersGroupHelper = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_HELPER).create();
    salesPlanOrdersGroupHelper.setField(SalesPlanOrdersGroupHelperFields.SALES_PLAN, salesPlanForm.getEntityId());
    salesPlanOrdersGroupHelper = salesPlanOrdersGroupHelper.getDataDefinition().save(salesPlanOrdersGroupHelper);
    Entity finalSalesPlanOrdersGroupHelper = salesPlanOrdersGroupHelper;
    productsGrid.getSelectedEntitiesIds().forEach(salesPlanProductDtoId -> {
        Entity salesPlanProduct = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_PRODUCT).get(salesPlanProductDtoId);
        Entity salesPlanProductDto = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_PRODUCT_DTO).get(salesPlanProductDtoId);
        Entity product = salesPlanProduct.getBelongsToField(SalesPlanProductFields.PRODUCT);
        if (ProductFamilyElementType.PARTICULAR_PRODUCT.getStringValue().equals(product.getStringField(ProductFields.ENTITY_TYPE))) {
            Entity salesPlanOrdersGroupEntry = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_ENTRY_HELPER).create();
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.SALES_PLAN_ORDERS_GROUP_HELPER, finalSalesPlanOrdersGroupHelper);
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT, product);
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.TECHNOLOGY, salesPlanProduct.getBelongsToField(SalesPlanProductFields.TECHNOLOGY));
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT_FAMILY, product.getBelongsToField(ProductFields.PARENT));
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDERED_QUANTITY, salesPlanProduct.getDecimalField(SalesPlanProductFields.ORDERED_QUANTITY).add(salesPlanProduct.getDecimalField(SalesPlanProductFields.ORDERED_TO_WAREHOUSE)));
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PLANNED_QUANTITY, salesPlanProduct.getDecimalField(SalesPlanProductFields.PLANNED_QUANTITY));
            BigDecimal orderQuantity = salesPlanProductDto.getDecimalField("plannedQuantity").subtract(salesPlanProductDto.getDecimalField("ordersPlannedQuantity"), MathContext.DECIMAL64);
            if (orderQuantity.compareTo(BigDecimal.ZERO) < 0) {
                orderQuantity = BigDecimal.ZERO;
            }
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDER_QUANTITY, orderQuantity);
            salesPlanOrdersGroupEntry = salesPlanOrdersGroupEntry.getDataDefinition().save(salesPlanOrdersGroupEntry);
        } else {
            List<Entity> children = product.getHasManyField(ProductFields.CHILDREN);
            for (Entity child : children) {
                if (Objects.nonNull(child.getBelongsToField(ProductFields.SIZE))) {
                    Entity salesPlanOrdersGroupEntry = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_ENTRY_HELPER).create();
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.SALES_PLAN_ORDERS_GROUP_HELPER, finalSalesPlanOrdersGroupHelper);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT, child);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.TECHNOLOGY, salesPlanProduct.getBelongsToField(SalesPlanProductFields.TECHNOLOGY));
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT_FAMILY, product);
                    BigDecimal moProductQuantity = getMasterOrderProductQuantity(salesPlan, child);
                    BigDecimal orderedQuantity = getOrderedQuantity(salesPlan, child);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDERED_QUANTITY, moProductQuantity);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PLANNED_QUANTITY, salesPlanProduct.getDecimalField(SalesPlanProductFields.PLANNED_QUANTITY));
                    BigDecimal orderQuantity = moProductQuantity.subtract(orderedQuantity, MathContext.DECIMAL64);
                    if (orderQuantity.compareTo(BigDecimal.ZERO) < 0) {
                        orderQuantity = BigDecimal.ZERO;
                    }
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDER_QUANTITY, orderQuantity);
                    salesPlanOrdersGroupEntry = salesPlanOrdersGroupEntry.getDataDefinition().save(salesPlanOrdersGroupEntry);
                }
            }
        }
    });
    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put("form.id", salesPlanOrdersGroupHelper.getId());
    String url = "../page/masterOrders/salesPlanOrders.html";
    view.openModal(url, parameters);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) JSONObject(org.json.JSONObject) BigDecimal(java.math.BigDecimal)

Example 90 with GridComponent

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

the class SalesPlanDetailsListeners method createOrderGroup.

public void createOrderGroup(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent salesPlanForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    GridComponent productsGrid = (GridComponent) view.getComponentByReference(SalesPlanFields.PRODUCTS);
    Entity salesPlan = salesPlanForm.getEntity().getDataDefinition().get(salesPlanForm.getEntityId());
    Entity salesPlanOrdersGroupHelper = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_HELPER).create();
    salesPlanOrdersGroupHelper.setField(SalesPlanOrdersGroupHelperFields.SALES_PLAN, salesPlanForm.getEntityId());
    salesPlanOrdersGroupHelper = salesPlanOrdersGroupHelper.getDataDefinition().save(salesPlanOrdersGroupHelper);
    Entity finalSalesPlanOrdersGroupHelper = salesPlanOrdersGroupHelper;
    productsGrid.getSelectedEntitiesIds().forEach(salesPlanProductDtoId -> {
        Entity salesPlanProduct = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_PRODUCT).get(salesPlanProductDtoId);
        Entity product = salesPlanProduct.getBelongsToField(SalesPlanProductFields.PRODUCT);
        if (ProductFamilyElementType.PARTICULAR_PRODUCT.getStringValue().equals(product.getStringField(ProductFields.ENTITY_TYPE))) {
            Entity salesPlanOrdersGroupEntry = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_ENTRY_HELPER).create();
            Entity salesPlanProductDto = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_PRODUCT_DTO).get(salesPlanProductDtoId);
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.SALES_PLAN_ORDERS_GROUP_HELPER, finalSalesPlanOrdersGroupHelper);
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT, product);
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.TECHNOLOGY, salesPlanProduct.getBelongsToField(SalesPlanProductFields.TECHNOLOGY));
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT_FAMILY, product.getBelongsToField(ProductFields.PARENT));
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDERED_QUANTITY, salesPlanProduct.getDecimalField(SalesPlanProductFields.ORDERED_QUANTITY).add(salesPlanProduct.getDecimalField(SalesPlanProductFields.ORDERED_TO_WAREHOUSE)));
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PLANNED_QUANTITY, salesPlanProduct.getDecimalField(SalesPlanProductFields.PLANNED_QUANTITY));
            BigDecimal orderQuantity = salesPlanProductDto.getDecimalField("plannedQuantity").subtract(salesPlanProductDto.getDecimalField("ordersPlannedQuantity"), MathContext.DECIMAL64);
            if (orderQuantity.compareTo(BigDecimal.ZERO) < 0) {
                orderQuantity = BigDecimal.ZERO;
            }
            salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDER_QUANTITY, orderQuantity);
            salesPlanOrdersGroupEntry = salesPlanOrdersGroupEntry.getDataDefinition().save(salesPlanOrdersGroupEntry);
        } else {
            List<Entity> children = product.getHasManyField(ProductFields.CHILDREN);
            for (Entity child : children) {
                if (Objects.nonNull(child.getBelongsToField(ProductFields.SIZE))) {
                    Entity salesPlanOrdersGroupEntry = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_ENTRY_HELPER).create();
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.SALES_PLAN_ORDERS_GROUP_HELPER, finalSalesPlanOrdersGroupHelper);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT, child);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.TECHNOLOGY, salesPlanProduct.getBelongsToField(SalesPlanProductFields.TECHNOLOGY));
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PRODUCT_FAMILY, product);
                    BigDecimal moProductQuantity = getMasterOrderProductQuantity(salesPlan, child);
                    BigDecimal orderedQuantity = getOrderedQuantity(salesPlan, child);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDERED_QUANTITY, moProductQuantity);
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.PLANNED_QUANTITY, salesPlanProduct.getDecimalField(SalesPlanProductFields.PLANNED_QUANTITY));
                    BigDecimal orderQuantity = moProductQuantity.subtract(orderedQuantity, MathContext.DECIMAL64);
                    if (orderQuantity.compareTo(BigDecimal.ZERO) < 0) {
                        orderQuantity = BigDecimal.ZERO;
                    }
                    salesPlanOrdersGroupEntry.setField(SalesPlanOrdersGroupEntryHelperFields.ORDER_QUANTITY, orderQuantity);
                    salesPlanOrdersGroupEntry = salesPlanOrdersGroupEntry.getDataDefinition().save(salesPlanOrdersGroupEntry);
                }
            }
        }
    });
    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put("form.id", salesPlanOrdersGroupHelper.getId());
    String url = "../page/masterOrders/salesPlanOrdersGroup.html";
    view.openModal(url, parameters);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) JSONObject(org.json.JSONObject) BigDecimal(java.math.BigDecimal)

Aggregations

GridComponent (com.qcadoo.view.api.components.GridComponent)260 Entity (com.qcadoo.model.api.Entity)131 FormComponent (com.qcadoo.view.api.components.FormComponent)85 FieldComponent (com.qcadoo.view.api.components.FieldComponent)33 WindowComponent (com.qcadoo.view.api.components.WindowComponent)30 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)29 JSONObject (org.json.JSONObject)28 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)26 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)24 ComponentState (com.qcadoo.view.api.ComponentState)23 DataDefinition (com.qcadoo.model.api.DataDefinition)22 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)22 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)20 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)19 Autowired (org.springframework.beans.factory.annotation.Autowired)19 BigDecimal (java.math.BigDecimal)16 Service (org.springframework.stereotype.Service)16 LookupComponent (com.qcadoo.view.api.components.LookupComponent)15 Collectors (java.util.stream.Collectors)15 Lists (com.google.common.collect.Lists)12