Search in sources :

Example 51 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class SourceCostService method findDefaultSourceCodeForFactory.

public Optional<Entity> findDefaultSourceCodeForFactory(final Entity factory) {
    SearchCriteriaBuilder scb = getSourceCostDD().find();
    scb.add(SearchRestrictions.belongsTo(SourceCostFields.FACTORY, factory)).add(SearchRestrictions.eq(SourceCostFields.ACTIVE, true)).add(SearchRestrictions.eq(SourceCostFields.DEFAULT_COST, true));
    return Optional.ofNullable(scb.setMaxResults(1).uniqueResult());
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 52 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class SourceCostService method findDefaultSourceCode.

public Optional<Entity> findDefaultSourceCode() {
    SearchCriteriaBuilder scb = getSourceCostDD().find();
    scb.add(SearchRestrictions.isNull(SourceCostFields.FACTORY)).add(SearchRestrictions.eq(SourceCostFields.ACTIVE, true)).add(SearchRestrictions.eq(SourceCostFields.DEFAULT_COST, true));
    return Optional.ofNullable(scb.setMaxResults(1).uniqueResult());
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 53 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class ProductValidators method productWithEanAlreadyExists.

private boolean productWithEanAlreadyExists(final DataDefinition productDD, final String notEmptyEan) {
    SearchCriteriaBuilder scb = productDD.find();
    scb.setProjection(SearchProjections.id());
    scb.add(SearchRestrictions.eq(ProductFields.EAN, notEmptyEan));
    return scb.setMaxResults(1).uniqueResult() != null;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 54 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class DeliveredProductReservationHooks method sumIsNotExceeded.

private boolean sumIsNotExceeded(final Entity deliveredProductReservation) {
    Entity deliveredProduct = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT);
    BigDecimal productDeliveredQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.DELIVERED_QUANTITY);
    if (Objects.isNull(productDeliveredQuantity)) {
        return true;
    }
    BigDecimal reservationDeliveredQuantity = deliveredProductReservation.getDecimalField(DeliveredProductReservationFields.DELIVERED_QUANTITY);
    SearchCriteriaBuilder searchCriteriaBuilder = deliveredProductReservation.getDataDefinition().find();
    SearchProjection sumOfQuantityProjection = SearchProjections.alias(SearchProjections.sum(DeliveredProductReservationFields.DELIVERED_QUANTITY), L_SUM_OF_QUANTITY);
    searchCriteriaBuilder.setProjection(SearchProjections.list().add(sumOfQuantityProjection).add(SearchProjections.rowCount()));
    SearchCriterion criterion;
    SearchCriterion criterionDeliveredProduct = SearchRestrictions.belongsTo(DeliveredProductReservationFields.DELIVERED_PRODUCT, deliveredProduct);
    Long deliveredProductReservationId = deliveredProductReservation.getId();
    if (Objects.isNull(deliveredProductReservationId)) {
        criterion = criterionDeliveredProduct;
    } else {
        SearchCriterion criterionId = SearchRestrictions.idNe(deliveredProductReservationId);
        criterion = SearchRestrictions.and(criterionDeliveredProduct, criterionId);
    }
    searchCriteriaBuilder.add(criterion);
    searchCriteriaBuilder.addOrder(SearchOrders.asc(L_SUM_OF_QUANTITY));
    SearchResult resList = searchCriteriaBuilder.setMaxResults(1).list();
    BigDecimal sumOfQuantity = (resList.getTotalNumberOfEntities() == 0) ? BigDecimal.ZERO : resList.getEntities().get(0).getDecimalField(L_SUM_OF_QUANTITY);
    sumOfQuantity = BigDecimalUtils.convertNullToZero(sumOfQuantity);
    BigDecimal damagedQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.DAMAGED_QUANTITY);
    damagedQuantity = BigDecimalUtils.convertNullToZero(damagedQuantity);
    productDeliveredQuantity = productDeliveredQuantity.subtract(damagedQuantity);
    boolean sumIsNotExceeded = productDeliveredQuantity.compareTo(reservationDeliveredQuantity.add(sumOfQuantity)) >= 0;
    if (!sumIsNotExceeded) {
        FieldDefinition deliveredQuantityField = deliveredProductReservation.getDataDefinition().getField(DeliveredProductReservationFields.DELIVERED_QUANTITY);
        deliveredProductReservation.addError(deliveredQuantityField, "deliveries.deliveredProductReservation.error.sumIsExceeded");
    }
    return sumIsNotExceeded;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchProjection(com.qcadoo.model.api.search.SearchProjection) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) SearchResult(com.qcadoo.model.api.search.SearchResult) BigDecimal(java.math.BigDecimal)

Example 55 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class DeliveredProductMultiPositionService method findOrderedQuantity.

public BigDecimal findOrderedQuantity(final Entity delivery, final Entity product, final Entity additionalCode) {
    SearchCriteriaBuilder searchCriteriaBuilder = dataDefinitionService.get(DeliveriesConstants.PLUGIN_IDENTIFIER, DeliveriesConstants.MODEL_ORDERED_PRODUCT).find().add(SearchRestrictions.belongsTo(DELIVERY, delivery)).add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(ADDITIONAL_CODE, additionalCode));
    Entity orderedProductFromDB = searchCriteriaBuilder.setMaxResults(1).uniqueResult();
    if (Objects.isNull(orderedProductFromDB)) {
        return BigDecimal.ZERO;
    }
    return BigDecimalUtils.convertNullToZero(orderedProductFromDB.getDecimalField(OrderedProductFields.ORDERED_QUANTITY));
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Aggregations

SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)176 Entity (com.qcadoo.model.api.Entity)82 DataDefinition (com.qcadoo.model.api.DataDefinition)26 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Service (org.springframework.stereotype.Service)19 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)18 EntityList (com.qcadoo.model.api.EntityList)17 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)17 Collectors (java.util.stream.Collectors)17 SearchResult (com.qcadoo.model.api.search.SearchResult)16 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)14 Objects (java.util.Objects)14 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)11 BigDecimal (java.math.BigDecimal)11 Set (java.util.Set)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 CustomRestriction (com.qcadoo.model.api.search.CustomRestriction)8