use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class CostNormsGeneratorListeners method updateCostNorms.
public void updateCostNorms(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent costNormsGeneratorForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity costNormsGenerator = costNormsGeneratorForm.getPersistedEntityWithIncludedFormValues();
String costsSource = costNormsGenerator.getStringField(CostNormsGeneratorFields.COSTS_SOURCE);
if ("01mes".equals(costsSource)) {
boolean allProducts = ProductsToUpdate.of(costNormsGenerator).compareTo(ProductsToUpdate.ALL) == 0;
List<Entity> products = Lists.newArrayList();
if (!allProducts) {
products = costNormsGenerator.getHasManyField(CostNormsGeneratorFields.PRODUCTS);
if (products.isEmpty()) {
view.addMessage("materialFlowResources.info.costNormsNotUpdated", ComponentState.MessageType.INFO);
return;
}
}
List<Entity> warehouses = costNormsGenerator.getHasManyField(CostNormsGeneratorFields.WAREHOUSES).stream().map(warehouse -> warehouse.getBelongsToField(CostNormsLocationFields.LOCATION)).collect(Collectors.toList());
costNormsService.updateCostNormsForProductsFromWarehouses(products, warehouses);
}
view.addMessage("materialFlowResources.success.costNormsUpdated", ComponentState.MessageType.SUCCESS);
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class DocumentDetailsHooks method lockNumberAndTypeChange.
private void lockNumberAndTypeChange(final ViewDefinitionState view) {
FormComponent documentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
ComponentState typeComponent = view.getComponentByReference(DocumentFields.TYPE);
if (documentForm.getEntityId() != null) {
typeComponent.setEnabled(false);
} else {
typeComponent.setEnabled(true);
}
FieldComponent numberField = (FieldComponent) view.getComponentByReference(DocumentFields.NUMBER);
numberField.setEnabled(false);
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class DocumentDetailsHooks method fetchNameAndNumberFromDatabase.
private void fetchNameAndNumberFromDatabase(final ViewDefinitionState view) {
FormComponent documentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
if (documentForm.getEntityId() != null) {
ComponentState numberField = view.getComponentByReference(DocumentFields.NUMBER);
ComponentState nameField = view.getComponentByReference(DocumentFields.NAME);
String nameFieldValue = (String) nameField.getFieldValue();
String numberFieldValue = (String) numberField.getFieldValue();
if (!numberFieldValue.contains("/")) {
Entity document = getDocumentDD().get(documentForm.getEntityId());
if (!numberFieldValue.contains("/")) {
numberField.setFieldValue(document.getField(DocumentFields.NUMBER));
}
if (Strings.isNullOrEmpty(nameFieldValue)) {
nameField.setFieldValue(document.getField(DocumentFields.NAME));
}
}
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class MaterialRequirementDetailsListeners method generateMaterialRequirement.
@Transactional
public void generateMaterialRequirement(final ViewDefinitionState view, final ComponentState state, final String[] args) {
if (state instanceof FormComponent) {
ComponentState generated = view.getComponentByReference("generated");
ComponentState date = view.getComponentByReference("date");
ComponentState worker = view.getComponentByReference("worker");
Entity materialRequirement = dataDefinitionService.get(MaterialRequirementsConstants.PLUGIN_IDENTIFIER, MaterialRequirementsConstants.MODEL_MATERIAL_REQUIREMENT).get((Long) state.getFieldValue());
if (materialRequirement == null) {
state.addMessage("qcadooView.message.entityNotFound", MessageType.FAILURE);
return;
} else if (StringUtils.isNotBlank(materialRequirement.getStringField("fileName"))) {
state.addMessage("materialRequirements.materialRequirementDetails.window.materialRequirement.documentsWasGenerated", MessageType.FAILURE);
return;
}
List<Entity> orders = materialRequirement.getManyToManyField("orders");
if (orders.isEmpty()) {
state.addMessage("materialRequirements.materialRequirementDetails.window.materialRequirement.missingAssosiatedOrders", MessageType.FAILURE);
return;
}
List<String> numbersOfOrdersWithoutTechnology = orderHelperService.getOrdersWithoutTechnology(orders);
if (!numbersOfOrdersWithoutTechnology.isEmpty()) {
state.addMessage("materialRequirements.materialRequirementDetails.window.materialRequirement.missingTechnologyInOrders", MessageType.FAILURE, StringUtils.join(numbersOfOrdersWithoutTechnology, ",<br>"));
return;
}
if ("0".equals(generated.getFieldValue())) {
worker.setFieldValue(securityService.getCurrentUserName());
generated.setFieldValue("1");
date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, LocaleContextHolder.getLocale()).format(new Date()));
}
state.performEvent(view, "save");
if (state.getFieldValue() == null || !((FormComponent) state).isValid()) {
worker.setFieldValue(null);
generated.setFieldValue("0");
date.setFieldValue(null);
return;
}
materialRequirement = dataDefinitionService.get(MaterialRequirementsConstants.PLUGIN_IDENTIFIER, MaterialRequirementsConstants.MODEL_MATERIAL_REQUIREMENT).get((Long) state.getFieldValue());
try {
materialRequirementService.generateMaterialRequirementDocuments(state, materialRequirement);
state.performEvent(view, "reset");
} catch (IOException | DocumentException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class GenerateMaterialRequirementCoverageListeners method createDelivery.
/**
* createOffer event handler
*
* @param view
* @param state
* @param args
*/
public void createDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args) {
init();
GridComponent grid = (GridComponent) view.getComponentByReference(L_GRID);
Entity parameter = parameterService.getParameter();
Entity systemCurrency = parameter.getBelongsToField(ParameterFields.CURRENCY);
DataDefinition companyDataDefinition = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_COMPANY);
Map<Optional<Integer>, List<Entity>> groupedCoverageProducts = grid.getSelectedEntities().stream().collect(Collectors.groupingBy(e -> Optional.ofNullable(e.getIntegerField("companyId"))));
StringBuilder deliveryNumbers = new StringBuilder();
for (Map.Entry<Optional<Integer>, List<Entity>> entry : groupedCoverageProducts.entrySet()) {
String number = numberGeneratorService.generateNumber(DeliveriesConstants.PLUGIN_IDENTIFIER, DeliveriesConstants.MODEL_DELIVERY);
Entity delivery = deliveriesService.getDeliveryDD().create();
delivery.setField(NUMBER, number);
Entity currency = null;
if (entry.getKey().isPresent()) {
Entity supplier = companyDataDefinition.get(entry.getKey().get().longValue());
delivery.setField(SUPPLIER, supplier);
currency = supplier.getBelongsToField(CompanyFieldsD.CURRENCY);
}
if (currency == null) {
currency = systemCurrency;
}
delivery.setField(CURRENCY, currency);
delivery.setField(EXTERNAL_SYNCHRONIZED, true);
Entity saved = deliveriesService.getDeliveryDD().save(delivery);
if (saved.isValid()) {
deliveryNumbers.append("<br/>").append(number);
entry.getValue().forEach(coverageProduct -> {
Integer product = coverageProduct.getIntegerField("productId");
BigDecimal reserveMissingQuantity = coverageProduct.getDecimalField(CoverageProductFields.RESERVE_MISSING_QUANTITY);
BigDecimal orderedQuantity = reserveMissingQuantity.min(BigDecimal.ZERO).abs();
BigDecimal conversion = getConversion(product);
Entity orderedProduct = orderedProductDataDefinition.create();
orderedProduct.setField("delivery", saved);
orderedProduct.setField("product", product.longValue());
orderedProduct.setField("orderedQuantity", reserveMissingQuantity.min(BigDecimal.ZERO).abs());
orderedProduct.setField(OrderedProductFields.CONVERSION, conversion);
orderedProduct.setField(OrderedProductFields.ADDITIONAL_QUANTITY, orderedQuantity.multiply(conversion, numberService.getMathContext()));
orderedProductDataDefinition.save(orderedProduct);
});
}
if (parameter.getBooleanField(L_REQUIRE_SUPPLIER_IDENTIFICATION) && Objects.isNull(delivery.getBelongsToField(SUPPLIER))) {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.requireSupplierIdentification", MessageType.INFO, false);
}
}
if (StringUtils.isNoneEmpty(deliveryNumbers.toString())) {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.created", MessageType.SUCCESS, false, deliveryNumbers.toString());
} else {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.notCreated", MessageType.INFO, false);
}
}
Aggregations