Search in sources :

Example 36 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class PlannedEventDetailsListeners method onRemoveRelatedEvents.

public void onRemoveRelatedEvents(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent relatedEventsGrid = (GridComponent) view.getComponentByReference(PlannedEventFields.RELATED_EVENTS);
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity currentEvent = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT).get(form.getEntityId());
    List<Entity> relatedEventsForCurrentEvent = Lists.newArrayList(currentEvent.getManyToManyField(PlannedEventFields.RELATED_EVENTS));
    List<Entity> relatedEventsToDelete = relatedEventsGrid.getSelectedEntities();
    for (Entity relatedEventToDelete : relatedEventsToDelete) {
        List<Entity> relatedEvents = Lists.newArrayList(relatedEventToDelete.getManyToManyField(PlannedEventFields.RELATED_EVENTS));
        Optional<Entity> eventToDelete = relatedEvents.stream().filter(event -> event.getId().compareTo(currentEvent.getId()) == 0).findFirst();
        if (eventToDelete.isPresent()) {
            relatedEvents.remove(eventToDelete.get());
            relatedEventToDelete.setField(PlannedEventFields.RELATED_EVENTS, relatedEvents);
            relatedEventToDelete.getDataDefinition().save(relatedEventToDelete);
        }
        Optional<Entity> eventToDeleteFromCurrent = relatedEventsForCurrentEvent.stream().filter(event -> event.getId().compareTo(relatedEventToDelete.getId()) == 0).findFirst();
        if (eventToDeleteFromCurrent.isPresent()) {
            relatedEventsForCurrentEvent.remove(eventToDeleteFromCurrent.get());
        }
    }
    currentEvent.setField(PlannedEventFields.RELATED_EVENTS, relatedEventsForCurrentEvent);
    currentEvent.getDataDefinition().save(currentEvent);
    Entity formEntity = form.getEntity();
    formEntity = formEntity.getDataDefinition().get(formEntity.getId());
    form.setEntity(formEntity);
    view.performEvent(view, "refresh");
}
Also used : PlannedEventDetailsHooks(com.qcadoo.mes.cmmsMachineParts.hooks.PlannedEventDetailsHooks) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) EventHooks(com.qcadoo.mes.cmmsMachineParts.hooks.EventHooks) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CmmsMachinePartsConstants(com.qcadoo.mes.cmmsMachineParts.constants.CmmsMachinePartsConstants) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponent(com.qcadoo.view.api.components.GridComponent) PlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) JSONException(org.json.JSONException) List(java.util.List) Lists(com.google.common.collect.Lists) LookupUtils(com.qcadoo.mes.basic.LookupUtils) JSONObject(org.json.JSONObject) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) Optional(java.util.Optional) ActionForPlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.ActionForPlannedEventFields) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 37 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class DeliveryDetailsListeners method getSelectedProducts.

private List<Entity> getSelectedProducts(final ViewDefinitionState view) {
    GridComponent orderedProductGrid = (GridComponent) view.getComponentByReference(DeliveryFields.ORDERED_PRODUCTS);
    List<Entity> result = Lists.newArrayList();
    Set<Long> ids = orderedProductGrid.getSelectedEntitiesIds();
    if (Objects.nonNull(ids) && !ids.isEmpty()) {
        final SearchCriteriaBuilder searchCriteria = deliveriesService.getOrderedProductDD().find();
        searchCriteria.add(SearchRestrictions.in("id", ids));
        result = searchCriteria.list().getEntities();
        if (!result.isEmpty()) {
            String numbersFilter = orderedProductGrid.getFilters().get("productNumber");
            String numberAndAdditionalCodeFilter = orderedProductGrid.getFilters().get("mergedProductNumberAndAdditionalCode");
            if (StringUtils.isNotBlank(numbersFilter) && numbersFilter.startsWith("[") && numbersFilter.endsWith("]")) {
                List<String> numbersOrder = Lists.newArrayList(numbersFilter.replace("[", "").replace("]", "").split(","));
                result.sort((o1, o2) -> {
                    String number1 = o1.getBelongsToField(OrderedProductFields.PRODUCT).getStringField(ProductFields.NUMBER);
                    String number2 = o2.getBelongsToField(OrderedProductFields.PRODUCT).getStringField(ProductFields.NUMBER);
                    return Integer.valueOf(numbersOrder.indexOf(number1)).compareTo(numbersOrder.indexOf(number2));
                });
            } else if (StringUtils.isNotBlank(numberAndAdditionalCodeFilter) && numberAndAdditionalCodeFilter.startsWith("[") && numberAndAdditionalCodeFilter.endsWith("]")) {
                List<String> numbersOrder = Lists.newArrayList(numberAndAdditionalCodeFilter.replace("[", "").replace("]", "").split(","));
                result.sort((o1, o2) -> {
                    String number1 = Optional.ofNullable(o1.getBelongsToField(OrderedProductFields.ADDITIONAL_CODE)).map(ac -> ac.getStringField(AdditionalCodeFields.CODE)).orElse(o1.getBelongsToField(OrderedProductFields.PRODUCT).getStringField(ProductFields.NUMBER));
                    String number2 = Optional.ofNullable(o2.getBelongsToField(OrderedProductFields.ADDITIONAL_CODE)).map(ac -> ac.getStringField(AdditionalCodeFields.CODE)).orElse(o2.getBelongsToField(OrderedProductFields.PRODUCT).getStringField(ProductFields.NUMBER));
                    return Integer.valueOf(numbersOrder.indexOf(number1)).compareTo(numbersOrder.indexOf(number2));
                });
            }
        }
    }
    return result;
}
Also used : MessageType(com.qcadoo.view.api.ComponentState.MessageType) java.util(java.util) CurrencyService(com.qcadoo.mes.basic.util.CurrencyService) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) LoggerFactory(org.slf4j.LoggerFactory) com.qcadoo.mes.deliveries.constants(com.qcadoo.mes.deliveries.constants) Autowired(org.springframework.beans.factory.annotation.Autowired) UnitConversionService(com.qcadoo.model.api.units.UnitConversionService) ReservationService(com.qcadoo.mes.deliveries.ReservationService) StringUtils(org.apache.commons.lang3.StringUtils) com.qcadoo.model.api(com.qcadoo.model.api) FileService(com.qcadoo.model.api.file.FileService) DeliveriesService(com.qcadoo.mes.deliveries.DeliveriesService) DeliveryStateStringValues(com.qcadoo.mes.deliveries.states.constants.DeliveryStateStringValues) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) ProductFieldsCNFP(com.qcadoo.mes.costNormsForProduct.constants.ProductFieldsCNFP) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) PdfHelper(com.qcadoo.report.api.pdf.PdfHelper) FormComponent(com.qcadoo.view.api.components.FormComponent) PluginUtils(com.qcadoo.plugin.api.PluginUtils) DeliveredProductMultiPositionService(com.qcadoo.mes.deliveries.DeliveredProductMultiPositionService) OrderReportPdf(com.qcadoo.mes.deliveries.print.OrderReportPdf) com.qcadoo.model.api.search(com.qcadoo.model.api.search) SearchProjections.field(com.qcadoo.model.api.search.SearchProjections.field) Logger(org.slf4j.Logger) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) File(java.io.File) Component(org.springframework.stereotype.Component) ParameterService(com.qcadoo.mes.basic.ParameterService) FieldComponent(com.qcadoo.view.api.components.FieldComponent) com.qcadoo.mes.basic.constants(com.qcadoo.mes.basic.constants) LookupComponent(com.qcadoo.view.api.components.LookupComponent) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) SearchProjections.alias(com.qcadoo.model.api.search.SearchProjections.alias) DeliveryReportPdf(com.qcadoo.mes.deliveries.print.DeliveryReportPdf) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 38 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class ProductsToIssueDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent productToIssueForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent locationFromLabel = (FieldComponent) view.getComponentByReference("locationFromLabel");
    FieldComponent helperField = (FieldComponent) view.getComponentByReference("generated");
    Entity helper = productToIssueForm.getEntity();
    Entity locationFrom = helper.getBelongsToField("locationFrom");
    if (Objects.nonNull(locationFrom)) {
        locationFromLabel.setFieldValue(translationService.translate("productFlowThruDivision.productsToIssueHelperDetails.window.mainTab.form.locationFromLabel.label", LocaleContextHolder.getLocale(), locationFrom.getStringField(LocationFields.NUMBER)));
        locationFromLabel.setRequired(true);
    }
    if (view.isViewAfterRedirect() && helper.getHasManyField("issues").isEmpty()) {
        String idsStr = helper.getStringField("productsToIssueIds");
        String[] split = idsStr.split(",");
        List<Long> ids = Lists.newArrayList(split).stream().map(Long::valueOf).collect(Collectors.toList());
        Multimap<Entity, Entity> locationFromProductMultimap = HashMultimap.create();
        Multimap<Entity, Entity> locationToProductMultimap = HashMultimap.create();
        List<Entity> createdIssues = Lists.newArrayList();
        for (Long id : ids) {
            Entity productToIssue = getProductToIssueDD().get(id);
            Entity product = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT);
            locationFromProductMultimap.put(productToIssue.getBelongsToField(ProductsToIssueFields.WAREHOUSE_ISSUE).getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE), product);
            locationToProductMultimap.put(productToIssue.getBelongsToField(ProductsToIssueFields.LOCATION), product);
            createdIssues.add(createIssue(getIssueDD(), productToIssue));
        }
        Map<Long, Map<Long, BigDecimal>> stockForWarehousesFrom = getStockForWarehouses(locationFromProductMultimap);
        Map<Long, Map<Long, BigDecimal>> stockForWarehousesTo = getStockForWarehouses(locationToProductMultimap);
        fillLocationQuantity(createdIssues, stockForWarehousesFrom, stockForWarehousesTo);
        helper.setField("issues", sortIssuesBasedOnFilter(view, createdIssues));
        productToIssueForm.setEntity(helper);
    } else {
        List<Entity> issues = helper.getHasManyField("issues");
        if (!issues.isEmpty() && issues.stream().allMatch(issue -> Objects.nonNull(issue.getId()))) {
            WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
            Ribbon ribbon = window.getRibbon();
            RibbonGroup group = ribbon.getGroupByName("actions");
            RibbonActionItem createDocumentsItem = group.getItemByName("createDocuments");
            RibbonActionItem createDocumentsAndGoBackItem = group.getItemByName("createDocumentsAndGoBack");
            createDocumentsItem.setEnabled(!Boolean.valueOf((String) helperField.getFieldValue()));
            createDocumentsItem.requestUpdate(true);
            createDocumentsAndGoBackItem.setEnabled(!Boolean.valueOf((String) helperField.getFieldValue()));
            createDocumentsAndGoBackItem.requestUpdate(true);
        }
        fillQuantitiesInAdditionalUnit(view);
    }
    fillUnits(view);
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) Arrays(java.util.Arrays) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) ResourceStockDtoFields(com.qcadoo.mes.materialFlowResources.constants.ResourceStockDtoFields) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) BigDecimal(java.math.BigDecimal) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) HashMultimap(com.google.common.collect.HashMultimap) Optional(com.google.common.base.Optional) Map(java.util.Map) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) FieldComponent(com.qcadoo.view.api.components.FieldComponent) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) WindowComponent(com.qcadoo.view.api.components.WindowComponent) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) Multimap(com.google.common.collect.Multimap) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) ArrayList(java.util.ArrayList) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) LinkedHashSet(java.util.LinkedHashSet) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) Either(com.qcadoo.commons.functional.Either) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) Comparator(java.util.Comparator) StringUtils(org.springframework.util.StringUtils) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) Map(java.util.Map) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Example 39 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class ProductsToIssueHelperDetailsListeners method copyPositionMessages.

private void copyPositionMessages(Entity invalidPosition, final ViewDefinitionState componentMessagesHolder) {
    if (componentMessagesHolder == null) {
        return;
    }
    Locale locale = LocaleContextHolder.getLocale();
    String productNumber = Optional.of(invalidPosition).map(ip -> ip.getBelongsToField(PositionFields.PRODUCT)).map(p -> p.getStringField(ProductFields.NUMBER)).orElse("???");
    for (ErrorMessage errorMessage : invalidPosition.getGlobalErrors()) {
        String translatedMessage = translationService.translate(errorMessage.getMessage(), locale, errorMessage.getVars());
        translatedMessage = translationService.translate("productFlowThruDivision.issue.documentBuild.position.error", locale, translatedMessage, productNumber);
        componentMessagesHolder.addTranslatedMessage(translatedMessage, ComponentState.MessageType.FAILURE, errorMessage.getAutoClose(), errorMessage.isExtraLarge());
    }
    for (ErrorMessage errorMessage : invalidPosition.getErrors().values()) {
        String translatedMessage = translationService.translate(errorMessage.getMessage(), locale, errorMessage.getVars());
        translatedMessage = translationService.translate("productFlowThruDivision.issue.documentBuild.position.error", locale, translatedMessage, productNumber);
        componentMessagesHolder.addTranslatedMessage(translatedMessage, ComponentState.MessageType.FAILURE, errorMessage.getAutoClose(), errorMessage.isExtraLarge());
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) java.util(java.util) RuntimeExceptionWithArguments(com.qcadoo.model.api.exception.RuntimeExceptionWithArguments) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) com.qcadoo.model.api(com.qcadoo.model.api) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) WarehouseIssueService(com.qcadoo.mes.productFlowThruDivision.service.WarehouseIssueService) Service(org.springframework.stereotype.Service) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) GlobalMessage(com.qcadoo.model.api.validators.GlobalMessage) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) RoundingMode(java.math.RoundingMode) ProductsToIssueDetailsHooks(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.hooks.ProductsToIssueDetailsHooks) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) IssueValidators(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.validators.IssueValidators) PositionFields(com.qcadoo.mes.materialFlowResources.constants.PositionFields) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException) TranslationService(com.qcadoo.localization.api.TranslationService) com.qcadoo.view.api.components(com.qcadoo.view.api.components) Either(com.qcadoo.commons.functional.Either) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) UpdateIssuesLocationsQuantityStatusHolder(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder) Transactional(org.springframework.transaction.annotation.Transactional) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Example 40 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState 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);
        }
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) java.util(java.util) RuntimeExceptionWithArguments(com.qcadoo.model.api.exception.RuntimeExceptionWithArguments) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) com.qcadoo.model.api(com.qcadoo.model.api) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) WarehouseIssueService(com.qcadoo.mes.productFlowThruDivision.service.WarehouseIssueService) Service(org.springframework.stereotype.Service) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) GlobalMessage(com.qcadoo.model.api.validators.GlobalMessage) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) RoundingMode(java.math.RoundingMode) ProductsToIssueDetailsHooks(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.hooks.ProductsToIssueDetailsHooks) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) IssueValidators(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.validators.IssueValidators) PositionFields(com.qcadoo.mes.materialFlowResources.constants.PositionFields) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException) TranslationService(com.qcadoo.localization.api.TranslationService) com.qcadoo.view.api.components(com.qcadoo.view.api.components) Either(com.qcadoo.commons.functional.Either) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) UpdateIssuesLocationsQuantityStatusHolder(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder) Transactional(org.springframework.transaction.annotation.Transactional) BigDecimal(java.math.BigDecimal)

Aggregations

ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)50 Autowired (org.springframework.beans.factory.annotation.Autowired)35 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)32 Service (org.springframework.stereotype.Service)31 ComponentState (com.qcadoo.view.api.ComponentState)29 Collectors (java.util.stream.Collectors)28 Entity (com.qcadoo.model.api.Entity)27 Lists (com.google.common.collect.Lists)25 GridComponent (com.qcadoo.view.api.components.GridComponent)25 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)24 FormComponent (com.qcadoo.view.api.components.FormComponent)23 BigDecimal (java.math.BigDecimal)21 List (java.util.List)21 Maps (com.google.common.collect.Maps)18 Map (java.util.Map)18 DataDefinition (com.qcadoo.model.api.DataDefinition)16 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)15 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)13 FieldComponent (com.qcadoo.view.api.components.FieldComponent)11 Objects (java.util.Objects)11