use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class ProductToIssueCorrectionHelperHooks method setWarehouseCriteriaModifier.
private void setWarehouseCriteriaModifier(final ViewDefinitionState view, Entity helper) {
LookupComponent warehouseLookup = (LookupComponent) view.getComponentByReference("locationTo");
Entity placeOfIssue = helper.getBelongsToField("placeOfIssue");
OptionalLong locationTo = helper.getHasManyField("corrections").stream().mapToLong(correction -> correction.getBelongsToField(ProductToIssueCorrectionFields.LOCATION).getId()).findAny();
FilterValueHolder filter = warehouseLookup.getFilterValue();
filter.put("locationFrom", placeOfIssue.getId());
if (locationTo.isPresent()) {
filter.put("locationTo", locationTo.getAsLong());
}
warehouseLookup.setFilterValue(filter);
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class ModifyTechnologyDetailsHooks method onBeforeRender.
public final void onBeforeRender(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
if (view.isViewAfterRedirect()) {
Entity mt = form.getEntity().getDataDefinition().get(form.getEntityId());
LookupComponent replaceProductLookup = (LookupComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT);
replaceProductLookup.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getId());
replaceProductLookup.requestComponentUpdateState();
String selectedEntities = mt.getStringField(ModifyTechnologyHelperFields.SELECTED_ENTITIES);
List<Long> ids = Lists.newArrayList(selectedEntities.split(",")).stream().map(Long::valueOf).collect(Collectors.toList());
boolean sizeProduct = mt.getBooleanField("sizeProduct");
if (sizeProduct) {
List<Entity> producstBySize = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_PRODUCT_BY_SIZE_GROUP).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
Set<BigDecimal> quantities = producstBySize.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
if (quantities.size() == 1) {
FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
qnt.setFieldValue(quantities.stream().findFirst().get());
qnt.requestComponentUpdateState();
}
} else {
List<Entity> opicDtos = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT_DTO).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
Set<BigDecimal> quantities = opicDtos.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
if (quantities.size() == 1) {
FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
qnt.setFieldValue(quantities.stream().findFirst().get());
qnt.requestComponentUpdateState();
}
}
FieldComponent replaceProductUnit = (FieldComponent) view.getComponentByReference(L_REPLACE_PRODUCT_UNIT);
replaceProductUnit.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getStringField(ProductFields.UNIT));
}
setForm(view);
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class TOCDetailsHooks method disableViewForState.
private void disableViewForState(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity toc = form.getEntity();
if (toc.getId() == null) {
return;
}
toc = getTechnologyOperationComponentDD().get(toc.getId());
Entity technology = toc.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) {
WindowComponent windowComponent = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
Ribbon ribbon = windowComponent.getRibbon();
ribbon.getGroups().stream().filter(group -> !group.getName().equals(L_NAVIGATION)).forEach(group -> group.getItems().forEach(item -> {
item.setEnabled(false);
item.requestUpdate(true);
}));
form.setFormEnabled(false);
}
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class TechnologiesListListenersCC method createCostCalculation.
public final void createCostCalculation(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
List<Entity> selectedEntities = grid.getSelectedEntities();
if (!selectedEntities.isEmpty()) {
DataDefinition technologyDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY);
List<Entity> technologies = selectedEntities.stream().map(e -> technologyDD.get(e.getId())).collect(Collectors.toList());
DataDefinition costCalculationDD = dataDefinitionService.get(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COST_CALCULATION);
Entity costCalculation = costCalculationDD.create();
costCalculation.setField(CostCalculationFields.TECHNOLOGIES, technologies);
costCalculation.setField(CostCalculationFields.QUANTITY, BigDecimal.ONE);
Entity parameter = parameterService.getParameter();
costCalculation.setField(CostCalculationFields.MATERIAL_COSTS_USED, parameter.getStringField(CostCalculationFields.MATERIAL_COSTS_USED) != null ? parameter.getStringField(CostCalculationFields.MATERIAL_COSTS_USED) : MaterialCostsUsed.NOMINAL.getStringValue());
costCalculation.setField(CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED, parameter.getBooleanField(CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED));
costCalculation.setField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS, parameter.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS) != null ? parameter.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS) : SourceOfOperationCosts.TECHNOLOGY_OPERATION.getStringValue());
costCalculation.setField(CostCalculationFields.STANDARD_LABOR_COST, parameter.getBelongsToField(CostCalculationFields.STANDARD_LABOR_COST));
costCalculation.setField(CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST, parameter.getDecimalField(CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST));
costCalculation.setField(CostCalculationFields.AVERAGE_LABOR_HOURLY_COST, parameter.getDecimalField(CostCalculationFields.AVERAGE_LABOR_HOURLY_COST));
costCalculation.setField(CostCalculationFields.INCLUDE_TPZ, parameter.getBooleanField(CostCalculationFields.INCLUDE_TPZ));
costCalculation.setField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME, parameter.getBooleanField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME));
costCalculation.setField(CostCalculationFields.MATERIAL_COST_MARGIN, parameter.getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN));
costCalculation.setField(CostCalculationFields.PRODUCTION_COST_MARGIN, parameter.getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN));
costCalculation.setField(CostCalculationFields.ADDITIONAL_OVERHEAD, parameter.getDecimalField(CostCalculationFields.ADDITIONAL_OVERHEAD));
costCalculation.setField(CostCalculationFields.REGISTRATION_PRICE_OVERHEAD, parameter.getDecimalField(CostCalculationFields.REGISTRATION_PRICE_OVERHEAD));
costCalculation.setField(CostCalculationFields.TECHNICAL_PRODUCTION_COST_OVERHEAD, parameter.getDecimalField(CostCalculationFields.TECHNICAL_PRODUCTION_COST_OVERHEAD));
costCalculation.setField(CostCalculationFields.PROFIT, parameter.getDecimalField(CostCalculationFields.PROFIT));
costCalculation.setField(CostCalculationFields.NUMBER, numberGeneratorService.generateNumber(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COST_CALCULATION));
costCalculation = costCalculationDD.save(costCalculation);
String url = "../page/costCalculation/costCalculationDetails.html";
Map<String, Object> parameters = Maps.newHashMap();
parameters.put("form.id", costCalculation.getId());
view.redirectTo(url, false, true, parameters);
}
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class DeliveryDetailsListeners method changeStorageLocations.
public final void changeStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent deliveryForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
GridComponent deliveredProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.DELIVERED_PRODUCTS);
List<Entity> selectedProducts = deliveredProductsGrid.getSelectedEntities();
Set<Long> selectedProductsIds = deliveredProductsGrid.getSelectedEntitiesIds();
Entity delivery = deliveryForm.getPersistedEntityWithIncludedFormValues();
List<Entity> deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
for (Entity selectedProduct : selectedProducts) {
String palletNumber = selectedProduct.getStringField(DeliveredProductFields.PALLET_NUMBER);
if (Objects.nonNull(palletNumber)) {
List<Long> notSelectedMatchingProducts = deliveredProducts.stream().filter(deliveredProduct -> Objects.nonNull(deliveredProduct.getBelongsToField(DeliveredProductFields.PALLET_NUMBER)) && deliveredProduct.getBelongsToField(DeliveredProductFields.PALLET_NUMBER).getStringField(PalletNumberFields.NUMBER).equals(palletNumber)).map(Entity::getId).filter(deliveredProduct -> !selectedProductsIds.contains(deliveredProduct)).collect(Collectors.toList());
selectedProductsIds.addAll(notSelectedMatchingProducts);
}
}
String url = "../page/deliveries/changeStorageLocationHelper.html?context={\"form.deliveredProductIds\":\"" + selectedProductsIds.stream().map(Object::toString).collect(Collectors.joining(",")) + "\"," + "\"form.delivery\":\"" + delivery.getId() + "\"}";
view.openModal(url);
}
Aggregations