Search in sources :

Example 86 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class OperationDurationDetailsInOrderListeners method scheduleOrder.

private void scheduleOrder(final Long orderId) {
    Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderId);
    if (order == null) {
        return;
    }
    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
    if (technology == null) {
        return;
    }
    List<Date> operationStartDates = Lists.newArrayList();
    List<Date> operationEndDates = Lists.newArrayList();
    DataDefinition technologyOperationComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT);
    List<Entity> operations = technologyOperationComponentDD.find().add(SearchRestrictions.belongsTo(TechnologyOperationComponentFields.TECHNOLOGY, technology)).list().getEntities();
    Date orderStartDate = order.getDateField(OrderFields.START_DATE);
    for (Entity operation : operations) {
        Entity operCompTimeCalculation = operationWorkTimeService.createOrGetOperCompTimeCalculation(order, operation);
        if (operCompTimeCalculation == null) {
            continue;
        }
        Integer offset = operCompTimeCalculation.getIntegerField(OperCompTimeCalculationsFields.OPERATION_OFF_SET);
        Integer duration = operCompTimeCalculation.getIntegerField(OperCompTimeCalculationsFields.EFFECTIVE_OPERATION_REALIZATION_TIME);
        operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_FROM, null);
        operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_TO, null);
        if (offset == null || duration == null) {
            continue;
        }
        if (duration.equals(0)) {
            duration = duration + 1;
        }
        Date dateFrom = productionSchedulingService.getStartDate(order, orderStartDate, offset);
        if (dateFrom == null) {
            continue;
        }
        Date dateTo = productionSchedulingService.getFinishDate(order, orderStartDate, (long) offset + duration);
        operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_FROM, dateFrom);
        operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_TO, dateTo);
        operationStartDates.add(dateFrom);
        operationEndDates.add(dateTo);
        operCompTimeCalculation.getDataDefinition().save(operCompTimeCalculation);
    }
    Entity orderTimeCalculation = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().add(SearchRestrictions.belongsTo("order", order)).setMaxResults(1).uniqueResult();
    orderTimeCalculation.setField(OrderTimeCalculationFields.EFFECTIVE_DATE_FROM, operationStartDates.stream().min(Comparator.naturalOrder()).get());
    orderTimeCalculation.setField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO, operationEndDates.stream().max(Comparator.naturalOrder()).get());
    orderTimeCalculation.getDataDefinition().save(orderTimeCalculation);
    order.setField(OrderFieldsPS.GENERATED_END_DATE, orderRealizationTimeService.setDateToField(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO)));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Date(java.util.Date)

Example 87 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class OperationXlsxImportService method validateProductionLine.

private void validateProductionLine(final Entity operation, final DataDefinition operationDD) {
    Entity productionLine = operation.getBelongsToField(OperationFields.PRODUCTION_LINE);
    Entity division = operation.getBelongsToField(OperationFields.DIVISION);
    if (Objects.nonNull(productionLine)) {
        if (Objects.isNull(division)) {
            operation.addError(operationDD.getField(OperationFields.DIVISION), L_QCADOO_VIEW_VALIDATE_FIELD_ERROR_MISSING);
        } else {
            List<Entity> divisionProductionLines = division.getHasManyField(DivisionFieldsPL.PRODUCTION_LINES);
            Optional<Entity> mayBeProductionLine = divisionProductionLines.stream().filter(divisionProductionLine -> divisionProductionLine.getId().equals(productionLine.getId())).findAny();
            if (!mayBeProductionLine.isPresent()) {
                operation.addError(operationDD.getField(OperationFields.PRODUCTION_LINE), L_QCADOO_VIEW_VALIDATE_FIELD_ERROR_CUSTOM);
            }
        }
    }
}
Also used : WorkstationFieldsPL(com.qcadoo.mes.productionLines.constants.WorkstationFieldsPL) AssignedToOperation(com.qcadoo.mes.technologies.constants.AssignedToOperation) XlsxImportService(com.qcadoo.mes.basic.imports.services.XlsxImportService) Autowired(org.springframework.beans.factory.annotation.Autowired) DivisionFieldsPL(com.qcadoo.mes.productionLines.constants.DivisionFieldsPL) DataDefinition(com.qcadoo.model.api.DataDefinition) OperationFields(com.qcadoo.mes.technologies.constants.OperationFields) Objects(java.util.Objects) ParameterFields(com.qcadoo.mes.basic.constants.ParameterFields) BigDecimal(java.math.BigDecimal) List(java.util.List) Entity(com.qcadoo.model.api.Entity) Lists(com.google.common.collect.Lists) ParameterService(com.qcadoo.mes.basic.ParameterService) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) Entity(com.qcadoo.model.api.Entity)

Example 88 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class TechnologyComponentsFlowServiceImpl method getComponentLocation.

@Override
public Optional<Entity> getComponentLocation(Entity technology, Entity product) {
    Preconditions.checkArgument(technology != null, "Technology is required.");
    Preconditions.checkArgument(technology != null, "Product is required.");
    DataDefinition operationProductInComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    Entity operationProductInComponent = operationProductInComponentDD.find().createAlias(OperationProductInComponentFields.OPERATION_COMPONENT, "c", JoinType.INNER).add(belongsTo(OperationProductInComponentFields.PRODUCT, product)).add(belongsTo("c." + TechnologyOperationComponentFields.TECHNOLOGY, technology)).setMaxResults(1).uniqueResult();
    if (technologyService.isIntermediateProduct(operationProductInComponent)) {
        return Optional.absent();
    }
    return Optional.fromNullable(operationProductInComponent.getBelongsToField(OperationProductInComponentFieldsPFTD.COMPONENTS_LOCATION));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 89 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class TechnologyComponentsFlowServiceImpl method getComponentsStock.

@Override
public Map<Long, BigDecimal> getComponentsStock(Entity technology, boolean externalNumberShouldBeNull) {
    Preconditions.checkArgument(technology != null, "Technology is required.");
    DataDefinition operationProductInComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    SearchCriteriaBuilder scb = operationProductInComponentDD.find().createAlias(OperationProductInComponentFields.OPERATION_COMPONENT, "c", JoinType.INNER).createAlias(OperationProductInComponentFieldsPFTD.COMPONENTS_LOCATION, "w", JoinType.LEFT).createAlias("w." + LocationFieldsMFR.RESOURCES, "r", JoinType.LEFT).add(eqField("r." + ResourceFields.PRODUCT, OperationProductInComponentFields.PRODUCT)).add(belongsTo("c." + TechnologyOperationComponentFields.TECHNOLOGY, technology));
    if (externalNumberShouldBeNull) {
        scb.add(isNull("w." + LocationFields.EXTERNAL_NUMBER));
    }
    scb.setProjection(list().add(alias(groupField(OperationProductInComponentFields.PRODUCT), OperationProductInComponentFields.PRODUCT)).add(alias(sum("r." + ResourceFields.QUANTITY), ResourceFields.QUANTITY))).addOrder(SearchOrders.asc(ResourceFields.QUANTITY));
    List<Entity> componentsStock = scb.list().getEntities();
    Map<Long, BigDecimal> stockMap = Maps.newHashMap();
    for (Entity componentStock : componentsStock) {
        stockMap.put(componentStock.getBelongsToField(OperationProductInComponentFields.PRODUCT).getId(), componentStock.getDecimalField(ResourceFields.QUANTITY));
    }
    return stockMap;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal)

Example 90 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class OrderStatesListenerServicePFTD method updateDocumentQuantities.

private void updateDocumentQuantities(Entity order) {
    DataDefinition ptDD = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING);
    List<Entity> productionTrackings = ptDD.find().add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order)).add(SearchRestrictions.eq(ProductionTrackingFields.STATE, ProductionTrackingStateStringValues.ACCEPTED)).list().getEntities();
    List<Entity> trackingOperationProductOutComponents = Lists.newArrayList();
    for (Entity productionTracking : productionTrackings) {
        trackingOperationProductOutComponents.addAll(Lists.newArrayList(productionTracking.getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS)));
    }
    Multimap<Long, Entity> groupedRecordOutProducts = productionTrackingDocumentsHelper.fillFromBPCProductOut(trackingOperationProductOutComponents, order, true);
    for (Long warehouseId : groupedRecordOutProducts.keySet()) {
        Entity locationTo = getLocationDD().get(warehouseId);
        List<Entity> finalProductRecord = Lists.newArrayList();
        Collection<Entity> intermediateRecords = Lists.newArrayList();
        for (Entity trackingOperationProductOutComponent : trackingOperationProductOutComponents) {
            if (isFinalProductForOrder(order, trackingOperationProductOutComponent.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCT))) {
                finalProductRecord.add(trackingOperationProductOutComponent);
            } else {
                intermediateRecords.add(trackingOperationProductOutComponent);
            }
        }
        Entity existingInboundDocument = getDocumentDD().find().add(SearchRestrictions.belongsTo(DocumentFieldsPFTD.ORDER, order)).add(SearchRestrictions.belongsTo(DocumentFields.LOCATION_TO, locationTo)).add(SearchRestrictions.eq(DocumentFields.STATE, DocumentState.DRAFT.getStringValue())).add(SearchRestrictions.eq(DocumentFields.TYPE, DocumentType.INTERNAL_INBOUND.getStringValue())).setMaxResults(1).uniqueResult();
        if (Objects.nonNull(existingInboundDocument)) {
            if (Objects.nonNull(finalProductRecord)) {
                productionTrackingListenerServicePFTD.updateInternalInboundDocumentForFinalProducts(order, existingInboundDocument, finalProductRecord, true, true);
            } else {
                productionTrackingListenerServicePFTD.updateInternalInboundDocumentForFinalProducts(order, existingInboundDocument, intermediateRecords, false, true);
            }
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)415 Entity (com.qcadoo.model.api.Entity)285 Test (org.junit.Test)165 BigDecimal (java.math.BigDecimal)53 FieldDefinition (com.qcadoo.model.api.FieldDefinition)48 List (java.util.List)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 Service (org.springframework.stereotype.Service)31 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Date (java.util.Date)26 Map (java.util.Map)26 Collectors (java.util.stream.Collectors)26 FormComponent (com.qcadoo.view.api.components.FormComponent)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)22 IOException (java.io.IOException)21 Objects (java.util.Objects)21 GridComponent (com.qcadoo.view.api.components.GridComponent)20 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)20 Lists (com.google.common.collect.Lists)16