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