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());
}
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());
}
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;
}
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;
}
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));
}
Aggregations