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");
}
}
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);
}
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);
}
}
}
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);
}
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);
}
Aggregations