Search in sources :

Example 1 with SearchProjection

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

the class ProductValidatorsTNFO method findCorruptedTechnologyNumbers.

// HQL form:
// -----------------------
// select
// toc.id as id,
// t.number as techNumber
// 
// from
// #technologies_technologyOperationComponent toc
// inner join toc.operationProductOutComponents opoc
// inner join opoc.product as p
// inner join toc.technology t
// left join toc.parent parentToc
// left join parentToc.operationProductInComponents opic
// 
// where
// (opoc.product.id = opic.product.id or (toc.parent is null and t.product.id = p.id))
// and t.state in ('02accepted', '05checked')
// and p.unit <> toc.productionInOneCycleUNIT
// and p.id = :productId
// 
// order by toc.id desc
private List<Entity> findCorruptedTechnologyNumbers(final Long productID) {
    MasterOutputProductCriteria criteria = MasterOutputProductCriteria.empty().withProdCriteria(idEq(productID)).withTechCriteria(in(TechnologyFields.STATE, Lists.newArrayList(TechnologyStateStringValues.ACCEPTED, TechnologyStateStringValues.CHECKED)));
    SearchCriteriaBuilder scb = mainTocOutputProductCriteriaBuilder.create(criteria);
    scb.add(neField(Aliases.OPERATION_OUTPUT_PRODUCT + "." + ProductFields.UNIT, Aliases.TOC + "." + TechnologyOperationComponentFieldsTNFO.PRODUCTION_IN_ONE_CYCLE_UNIT));
    scb.addOrder(desc("id"));
    SearchProjection techNumProjection = alias(field(Aliases.TECHNOLOGY + "." + TechnologyFields.NUMBER), "techNumber");
    SearchProjection projection = SearchProjections.list().add(techNumProjection).add(alias(id(), "id"));
    scb.setProjection(SearchProjections.distinct(projection));
    return scb.list().getEntities();
}
Also used : MasterOutputProductCriteria(com.qcadoo.mes.technologies.tree.traversing.MasterOutputProductCriteria) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchProjection(com.qcadoo.model.api.search.SearchProjection)

Example 2 with SearchProjection

use of com.qcadoo.model.api.search.SearchProjection 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 3 with SearchProjection

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

the class MasterOrderOrdersDataProvider method sumBelongingOrdersPlannedQuantities.

public BigDecimal sumBelongingOrdersPlannedQuantities(final Entity masterOrder, final Entity product) {
    SearchProjection quantitiesSumProjection = list().add(alias(sum(OrderFields.PLANNED_QUANTITY), QUANTITIES_SUM_ALIAS)).add(rowCount());
    SearchCriterion productCriterion = belongsTo(OrderFields.PRODUCT, product);
    List<Entity> quantitiesSumProjectionResults = findBelongingOrders(masterOrder, quantitiesSumProjection, productCriterion, SearchOrders.desc(QUANTITIES_SUM_ALIAS));
    for (Entity entity : quantitiesSumProjectionResults) {
        return entity.getDecimalField(QUANTITIES_SUM_ALIAS);
    }
    return BigDecimal.ZERO;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchProjection(com.qcadoo.model.api.search.SearchProjection) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 4 with SearchProjection

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

the class MasterOrderOrdersDataProvider method sumBelongingOrdersDoneQuantities.

public BigDecimal sumBelongingOrdersDoneQuantities(final Entity masterOrder, final Entity product) {
    SearchProjection quantitiesSumProjection = list().add(alias(sum(OrderFields.DONE_QUANTITY), QUANTITIES_SUM_ALIAS)).add(rowCount());
    SearchCriterion productCriterion = belongsTo(OrderFields.PRODUCT, product);
    List<Entity> quantitiesSumProjectionResults = findBelongingOrders(masterOrder, quantitiesSumProjection, productCriterion, SearchOrders.desc(QUANTITIES_SUM_ALIAS));
    for (Entity entity : quantitiesSumProjectionResults) {
        return entity.getDecimalField(QUANTITIES_SUM_ALIAS);
    }
    return BigDecimal.ZERO;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchProjection(com.qcadoo.model.api.search.SearchProjection) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 5 with SearchProjection

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

the class OrderedProductReservationHooks method sumIsNotExceeded.

private boolean sumIsNotExceeded(final Entity orderedProductReservation) {
    Entity orderedProduct = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.ORDERED_PRODUCT);
    BigDecimal productOrderedQuantity = orderedProduct.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY);
    BigDecimal reservationOrderedQuantity = orderedProductReservation.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY);
    SearchCriteriaBuilder searchCriteriaBuilder = orderedProductReservation.getDataDefinition().find();
    SearchProjection sumOfQuantityProjection = SearchProjections.alias(SearchProjections.sum(OrderedProductReservationFields.ORDERED_QUANTITY), L_SUM_OF_QUANTITY);
    searchCriteriaBuilder.setProjection(SearchProjections.list().add(sumOfQuantityProjection).add(SearchProjections.rowCount()));
    SearchCriterion criterion;
    SearchCriterion criterionOrderedProduct = SearchRestrictions.belongsTo(OrderedProductReservationFields.ORDERED_PRODUCT, orderedProduct);
    Long orderedProductReservationId = orderedProductReservation.getId();
    if (Objects.isNull(orderedProductReservationId)) {
        criterion = criterionOrderedProduct;
    } else {
        SearchCriterion criterionId = SearchRestrictions.idNe(orderedProductReservationId);
        criterion = SearchRestrictions.and(criterionOrderedProduct, 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);
    boolean sumIsNotExceeded = productOrderedQuantity.compareTo(reservationOrderedQuantity.add(sumOfQuantity)) >= 0;
    if (!sumIsNotExceeded) {
        FieldDefinition orderedQuantityField = orderedProductReservation.getDataDefinition().getField(OrderedProductReservationFields.ORDERED_QUANTITY);
        orderedProductReservation.addError(orderedQuantityField, "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)

Aggregations

SearchProjection (com.qcadoo.model.api.search.SearchProjection)6 Entity (com.qcadoo.model.api.Entity)5 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)4 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 SearchResult (com.qcadoo.model.api.search.SearchResult)2 BigDecimal (java.math.BigDecimal)2 MasterOutputProductCriteria (com.qcadoo.mes.technologies.tree.traversing.MasterOutputProductCriteria)1