Search in sources :

Example 96 with DataDefinition

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

the class UsedBatchHooks method onSave.

public void onSave(final DataDefinition usedBatchDD, final Entity usedBatch) {
    Entity trackingOperationProductInComponent = usedBatch.getBelongsToField(UsedBatchFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENT);
    List<Entity> usedBathes = trackingOperationProductInComponent.getHasManyField(TrackingOperationProductInComponentFields.USED_BATCHES);
    if (Objects.nonNull(usedBatch.getId())) {
        usedBathes = usedBathes.stream().filter(entity -> !entity.getId().equals(usedBatch.getId())).collect(Collectors.toList());
    }
    BigDecimal sumUsedBatchesQuantity = usedBathes.stream().map(ub -> ub.getDecimalField(UsedBatchFields.QUANTITY)).reduce(BigDecimal.ZERO, BigDecimal::add);
    sumUsedBatchesQuantity = sumUsedBatchesQuantity.add(usedBatch.getDecimalField(UsedBatchFields.QUANTITY));
    trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.USED_QUANTITY, sumUsedBatchesQuantity);
    Optional<BigDecimal> givenQuantity = productionTrackingService.calculateGivenQuantity(trackingOperationProductInComponent, sumUsedBatchesQuantity);
    givenQuantity.ifPresent(gq -> trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, gq));
    Entity trackingOperationProductInComponentDb = trackingOperationProductInComponent.getDataDefinition().save(trackingOperationProductInComponent);
    if (!trackingOperationProductInComponentDb.isValid()) {
        usedBatch.addGlobalError("productionCounting.usedBatch.error.sumUsedBatchesQuantityToBig", false);
    }
}
Also used : TrackingOperationProductInComponentFields(com.qcadoo.mes.productionCounting.constants.TrackingOperationProductInComponentFields) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductionTrackingService(com.qcadoo.mes.productionCounting.ProductionTrackingService) DataDefinition(com.qcadoo.model.api.DataDefinition) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BigDecimal(java.math.BigDecimal) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) NumberService(com.qcadoo.model.api.NumberService) Optional(java.util.Optional) UsedBatchFields(com.qcadoo.mes.productionCounting.constants.UsedBatchFields) Entity(com.qcadoo.model.api.Entity) BigDecimal(java.math.BigDecimal)

Example 97 with DataDefinition

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

the class AnomalyExplanationDetailsListeners method onRemoveSelectedEntity.

public void onRemoveSelectedEntity(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent anomalyExplanationsGrid = (GridComponent) view.getComponentByReference("anomalyExplanations");
    DataDefinition dataDefinition = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_ANOMALY_EXPLANATION);
    dataDefinition.delete(toArray(anomalyExplanationsGrid.getSelectedEntitiesIds(), Long.class));
    FormComponent documentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    documentForm.performEvent(view, "reset");
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 98 with DataDefinition

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

the class AnomalyListListeners method completeWithoutIssue.

public void completeWithoutIssue(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent gridComponent = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    for (Long anomalyId : gridComponent.getSelectedEntitiesIds()) {
        DataDefinition anomalyDD = getAnomalyDD();
        Entity anomaly = anomalyDD.get(anomalyId);
        anomaly.setField(AnomalyFields.STATE, AnomalyFields.State.COMPLETED);
        anomaly.setField(AnomalyFields.ISSUED, false);
        anomalyDD.save(anomaly);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 99 with DataDefinition

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

the class PPSHelper method getPpsIdForOrder.

public Long getPpsIdForOrder(final Long orderId) {
    DataDefinition ppsDateDef = getProductionPerShiftDD();
    String query = "select id as ppsId from #productionPerShift_productionPerShift where order.id = :orderId";
    Entity projectionResults = ppsDateDef.find(query).setLong("orderId", orderId).setMaxResults(1).uniqueResult();
    if (projectionResults == null) {
        return null;
    }
    return (Long) projectionResults.getField("ppsId");
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 100 with DataDefinition

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

the class PPSHelper method createPpsForOrderAndReturnId.

public Long createPpsForOrderAndReturnId(final Long orderId) {
    DataDefinition productionPerShiftDD = getProductionPerShiftDD();
    Entity productionPerShift = productionPerShiftDD.create();
    productionPerShift.setField(ProductionPerShiftFields.ORDER, orderId);
    productionPerShift.setField(ProductionPerShiftFields.PLANNED_PROGRESS_TYPE, ProgressType.PLANNED.getStringValue());
    return productionPerShiftDD.save(productionPerShift).getId();
}
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