Search in sources :

Example 36 with EntityList

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

the class OrderedProductHooks method calculateReservationQuantities.

private void calculateReservationQuantities(final Entity orderedProduct) {
    EntityList reservations = orderedProduct.getHasManyField(OrderedProductFields.RESERVATIONS);
    if (Objects.nonNull(reservations)) {
        BigDecimal conversion = orderedProduct.getDecimalField(OrderedProductFields.CONVERSION);
        for (Entity reservation : reservations) {
            BigDecimal orderedQuantity = reservation.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY);
            BigDecimal newAdditionalQuantity = orderedQuantity.multiply(conversion, numberService.getMathContext());
            newAdditionalQuantity = newAdditionalQuantity.setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP);
            reservation.setField(OrderedProductReservationFields.ADDITIONAL_QUANTITY, newAdditionalQuantity);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) BigDecimal(java.math.BigDecimal)

Example 37 with EntityList

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

the class ReservationService method validateDeliveryOrderedProductsAgainstReservations.

private boolean validateDeliveryOrderedProductsAgainstReservations(final Entity delivery) {
    Entity deliveryLocation = delivery.getBelongsToField(DeliveryFields.LOCATION);
    EntityList orderedProducts = delivery.getHasManyField(DeliveryFields.ORDERED_PRODUCTS);
    if (Objects.nonNull(orderedProducts) && Objects.nonNull(deliveryLocation)) {
        for (Entity orderedProduct : orderedProducts) {
            EntityList reservations = orderedProduct.getHasManyField(OrderedProductFields.RESERVATIONS);
            if (Objects.nonNull(reservations)) {
                for (Entity reservation : reservations) {
                    Entity reservationLocation = reservation.getBelongsToField(OrderedProductReservationFields.LOCATION);
                    if (deliveryLocation.getId().equals(reservationLocation.getId())) {
                        FieldDefinition locationField = delivery.getDataDefinition().getField(DeliveryFields.LOCATION);
                        delivery.addError(locationField, "deliveries.delivery.error.locationNotUniqueToDelivery", deliveryLocation.getStringField(LocationFields.NUMBER));
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) EntityList(com.qcadoo.model.api.EntityList)

Example 38 with EntityList

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

the class ReservationService method validateDeliveryDeliveredProductsAgainstReservations.

private boolean validateDeliveryDeliveredProductsAgainstReservations(final Entity delivery) {
    Entity deliveryLocation = delivery.getBelongsToField(DeliveryFields.LOCATION);
    EntityList deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
    if (Objects.nonNull(deliveredProducts) && Objects.nonNull(deliveryLocation)) {
        for (Entity deliveredProduct : deliveredProducts) {
            EntityList reservations = deliveredProduct.getHasManyField(DeliveredProductFields.RESERVATIONS);
            if (Objects.nonNull(reservations)) {
                for (Entity reservation : reservations) {
                    Entity reservationLocation = reservation.getBelongsToField(DeliveredProductReservationFields.LOCATION);
                    if (deliveryLocation.getId().equals(reservationLocation.getId())) {
                        FieldDefinition locationField = delivery.getDataDefinition().getField(DeliveryFields.LOCATION);
                        delivery.addError(locationField, "deliveries.delivery.error.locationNotUniqueToDelivery", deliveryLocation.getStringField(LocationFields.NUMBER));
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) EntityList(com.qcadoo.model.api.EntityList)

Example 39 with EntityList

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

the class ReservationService method deletePreviousReservations.

private boolean deletePreviousReservations(final List<Entity> orderedOrDeliveredProducts) {
    int countReservations = 0;
    for (Entity p : orderedOrDeliveredProducts) {
        EntityList reservations = p.getHasManyField(DeliveredProductFields.RESERVATIONS);
        countReservations += reservations.size();
        reservations.stream().forEach(reservation -> reservation.getDataDefinition().delete(reservation.getId()));
    }
    return countReservations > 0;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList)

Example 40 with EntityList

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

the class DeliveriesCriteriaModifier method restrictToUserLocations.

public void restrictToUserLocations(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) {
    Long currentUserId = securityService.getCurrentUserId();
    if (Objects.nonNull(currentUserId)) {
        EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS);
        if (!userLocations.isEmpty()) {
            Set<Long> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)).map(Entity::getId).collect(Collectors.toSet());
            scb.add(SearchRestrictions.in("location.id", locationIds));
        }
    }
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Aggregations

EntityList (com.qcadoo.model.api.EntityList)103 Entity (com.qcadoo.model.api.Entity)52 Test (org.junit.Test)27 DataDefinition (com.qcadoo.model.api.DataDefinition)16 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 Before (org.junit.Before)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 Objects (java.util.Objects)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Service (org.springframework.stereotype.Service)10 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)9 BigDecimal (java.math.BigDecimal)9 StateChangeTest (com.qcadoo.mes.states.StateChangeTest)5