use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class DeviationReportGeneratorViewHooks method setDefaultDateRange.
private void setDefaultDateRange(final ViewDefinitionState view) {
for (ComponentState dateFromComponent : view.tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_FROM).asSet()) {
Date firstDayOfCurrentMonth = LocalDate.now().withDayOfMonth(1).toDate();
dateFromComponent.setFieldValue(DateUtils.toDateString(firstDayOfCurrentMonth));
}
Optional<ComponentState> maybeDateFromComponent = view.tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_TO);
for (ComponentState dateFromComponent : maybeDateFromComponent.asSet()) {
Date today = LocalDate.now().toDate();
dateFromComponent.setFieldValue(DateUtils.toDateString(today));
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class QuantityService method checkMinimalQuantityValue.
private void checkMinimalQuantityValue(final ViewDefinitionState view, final Entity technologyEntity) {
FieldComponent plannedQuantityComponent = (FieldComponent) view.getComponentByReference("plannedQuantity");
BigDecimal plannedQuantity = getBigDecimalFromField(plannedQuantityComponent.getFieldValue(), view.getLocale());
BigDecimal minimalQuantity = getBigDecimalFromField(technologyEntity.getField("minimalQuantity"), view.getLocale());
Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(technologyEntity.getBelongsToField("product").getId());
if (plannedQuantity == null || minimalQuantity == null) {
return;
}
String unit = product.getStringField("unit");
if (plannedQuantity.compareTo(minimalQuantity) < 0) {
ComponentState form = (ComponentState) view.getComponentByReference(QcadooViewConstants.L_FORM);
form.addMessage("orders.order.report.minimalQuantity", MessageType.INFO, false, minimalQuantity.toString(), unit);
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class OrderDetailsHooks method changePredefinedTechnologyFieldsVisibility.
private void changePredefinedTechnologyFieldsVisibility(final ViewDefinitionState view) {
for (String reference : OrderDetailsHooks.L_PREDEFINED_TECHNOLOGY_FIELDS) {
ComponentState componentState = view.getComponentByReference(reference);
componentState.setVisible(true);
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class ProductsToIssueHelperDetailsListeners method updateQuantities.
public void updateQuantities(final ViewDefinitionState view, final ComponentState state, final String[] args) {
AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference(L_ISSUES);
Long changedId = (Long) state.getFieldValue();
for (FormComponent form : adl.getFormComponents()) {
Entity issue = form.getPersistedEntityWithIncludedFormValues();
Entity product = issue.getBelongsToField(IssueFields.PRODUCT);
if (product != null && product.getId().equals(changedId)) {
Entity locationTo = issue.getBelongsToField(IssueFields.LOCATION);
Entity warehouseIssue = issue.getBelongsToField(IssueFields.WAREHOUSE_ISSUE);
Entity locationFrom = warehouseIssue.getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE);
Optional<Entity> maybeProductToIssue = warehouseIssue.getHasManyField(WarehouseIssueFields.PRODUCTS_TO_ISSUES).stream().filter(p -> p.getBelongsToField(ProductsToIssueFields.PRODUCT).getId().equals(product.getId()) && p.getBelongsToField(ProductsToIssueFields.LOCATION).getId().equals(locationTo.getId())).findFirst();
BigDecimal quantityFrom = materialFlowResourcesService.getResourcesQuantityForLocationAndProduct(locationFrom, product);
BigDecimal quantityTo = materialFlowResourcesService.getResourcesQuantityForLocationAndProduct(locationTo, product);
if (maybeProductToIssue.isPresent()) {
Entity productToIssue = maybeProductToIssue.get();
BigDecimal demandQuantity = productToIssue.getDecimalField(ProductsToIssueFields.DEMAND_QUANTITY);
BigDecimal issuedQuantity = productToIssue.getDecimalField(ProductsToIssueFields.ISSUE_QUANTITY);
issue.setField(IssueFields.ADDITIONAL_CODE, productToIssue.getBelongsToField(ProductsToIssueFields.ADDITIONAL_CODE));
issue.setField(IssueFields.STORAGE_LOCATION, productToIssue.getBelongsToField(ProductsToIssueFields.STORAGE_LOCATION));
BigDecimal quantityPerUnit = null;
BigDecimal issueQuantity = BigDecimal.ZERO;
if (warehouseIssueParameterService.issueForOrder()) {
Entity order = warehouseIssue.getBelongsToField(WarehouseIssueFields.ORDER);
BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
if (plannedQuantity != null && demandQuantity != null) {
quantityPerUnit = demandQuantity.divide(plannedQuantity, numberService.getMathContext());
}
}
if (demandQuantity != null && issuedQuantity != null) {
issueQuantity = demandQuantity.subtract(issuedQuantity);
}
if (issueQuantity.compareTo(BigDecimal.ZERO) == -1) {
issueQuantity = BigDecimal.ZERO;
}
issue.setField(IssueFields.DEMAND_QUANTITY, demandQuantity);
issue.setField(IssueFields.QUANTITY_PER_UNIT, quantityPerUnit);
issue.setField(IssueFields.ISSUE_QUANTITY, issueQuantity);
BigDecimal conversion = productToIssue.getDecimalField(ProductsToIssueFields.CONVERSION);
if (conversion != null) {
issue.setField(IssueFields.CONVERSION, conversion);
String unit = product.getStringField(ProductFields.UNIT);
String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
BigDecimal newAdditionalQuantity = calculationQuantityService.calculateAdditionalQuantity(demandQuantity, conversion, Optional.ofNullable(additionalUnit).orElse(unit));
issue.setField(IssueFields.ADDITIONAL_DEMAND_QUANTITY, newAdditionalQuantity);
}
} else {
issue.setField(IssueFields.DEMAND_QUANTITY, BigDecimal.ZERO);
issue.setField(IssueFields.QUANTITY_PER_UNIT, BigDecimal.ZERO);
}
issue.setField(IssueFields.LOCATIONS_QUANTITY, quantityFrom);
issue.setField(IssueFields.LOCATION_TO_QUANTITY, quantityTo);
form.setEntity(issue);
}
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class WarehouseIssueDetailsListeners method fillProductsToIssue.
public void fillProductsToIssue(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent issueForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
FieldComponent collectionProductsField = (FieldComponent) view.getComponentByReference(WarehouseIssueFields.COLLECTION_PRODUCTS);
LookupComponent operation = (LookupComponent) view.getComponentByReference(WarehouseIssueFields.TECHNOLOGY_OPERATION_COMPONENT);
LookupComponent division = (LookupComponent) view.getComponentByReference(WarehouseIssueFields.DIVISION);
Long warehouseIssueId = issueForm.getEntityId();
Entity toc = operation.getEntity();
Entity divisionEntity = division.getEntity();
List<Entity> createdProducts = warehouseIssueService.fillProductsToIssue(warehouseIssueId, CollectionProducts.fromStringValue(collectionProductsField.getFieldValue().toString()), toc, divisionEntity);
if (createdProducts != null) {
List<Entity> invalidProducts = createdProducts.stream().filter(productToIssue -> !productToIssue.isValid()).collect(Collectors.toList());
if (invalidProducts.isEmpty()) {
view.addMessage("productFlowThruDivision.issue.downloadedProducts", ComponentState.MessageType.SUCCESS);
} else {
Multimap<String, String> errors = ArrayListMultimap.create();
for (Entity productToIssue : invalidProducts) {
String number = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT).getStringField(ProductFields.NUMBER);
Map<String, ErrorMessage> errorMessages = productToIssue.getErrors();
errorMessages.entrySet().stream().forEach(entry -> errors.put(entry.getValue().getMessage(), number));
productToIssue.getGlobalErrors().stream().forEach(error -> errors.put(error.getMessage(), number));
}
view.addMessage("productFlowThruDivision.issue.downloadedProductsError", ComponentState.MessageType.INFO, false);
for (String message : errors.keySet()) {
String translatedMessage = translationService.translate(message, LocaleContextHolder.getLocale());
String products = errors.get(message).stream().collect(Collectors.joining(", "));
if ((translatedMessage + products).length() < 255) {
view.addMessage("productFlowThruDivision.issue.downloadedProductsErrorMessages", ComponentState.MessageType.FAILURE, false, translatedMessage, products);
}
}
}
} else {
view.addMessage("productFlowThruDivision.issue.noProductsToDownload", ComponentState.MessageType.INFO);
}
}
Aggregations