Search in sources :

Example 1 with DeliveredProductReservationObject

use of com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationObject in project mes by qcadoo.

the class DeliveryStatePFTDService method flatReservations.

private Multimap<DeliveredProductReservationKeyObject, DeliveredProductReservationObject> flatReservations(final List<Entity> reservations) {
    Multimap<DeliveredProductReservationKeyObject, DeliveredProductReservationObject> reservationsMapGroupedByWarehouse = ArrayListMultimap.create();
    reservations.forEach(res -> {
        Entity deliveredProduct = res.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT);
        Entity product = deliveredProduct.getBelongsToField(DeliveredProductFields.PRODUCT);
        Entity additionalCode = deliveredProduct.getBelongsToField(DeliveredProductFields.ADDITIONAL_CODE);
        BigDecimal conversion = deliveredProduct.getDecimalField(DeliveredProductFields.CONVERSION);
        DeliveredProductReservationKeyObject key = new DeliveredProductReservationKeyObject(product, additionalCode, conversion);
        DeliveredProductReservationObject value = new DeliveredProductReservationObject(deliveredProduct, res);
        reservationsMapGroupedByWarehouse.put(key, value);
    });
    return reservationsMapGroupedByWarehouse;
}
Also used : DeliveredProductReservationKeyObject(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationKeyObject) Entity(com.qcadoo.model.api.Entity) DeliveredProductReservationObject(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationObject) BigDecimal(java.math.BigDecimal)

Example 2 with DeliveredProductReservationObject

use of com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationObject in project mes by qcadoo.

the class DeliveryStatePFTDService method createWarehouseIssue.

private void createWarehouseIssue(final Long warehouse, final List<Entity> reservations, final CreationWarehouseIssueState creationWarehouseIssueState, final Entity delivery, final Entity placeOfIssue) {
    Multimap<DeliveredProductReservationKeyObject, DeliveredProductReservationObject> flatReservations = flatReservations(reservations);
    Map<DeliveredProductReservationKeyObject, Collection<DeliveredProductReservationObject>> simpleFlatReservations = flatReservations.asMap();
    Entity warehouseIssue = createNewWarehouseIssue(placeOfIssue, delivery);
    if (!warehouseIssue.isValid()) {
        for (Map.Entry<String, ErrorMessage> entry : warehouseIssue.getErrors().entrySet()) {
            creationWarehouseIssueState.getErrors().add(entry.getValue());
        }
        throw new IllegalStateException("Undone creation warehouse issue for delivery : " + delivery.getStringField(DeliveryFields.NUMBER));
    }
    Entity location = getLocationDD().get(warehouse);
    List<Entity> createdProductsToIssue = Lists.newArrayList();
    for (Map.Entry<DeliveredProductReservationKeyObject, Collection<DeliveredProductReservationObject>> entry : simpleFlatReservations.entrySet()) {
        DeliveredProductReservationKeyObject key = entry.getKey();
        Collection<DeliveredProductReservationObject> value = entry.getValue();
        Entity product = key.getProduct();
        Entity productToIssue = getProductsToIssueDD().create();
        productToIssue.setField(ProductsToIssueFields.PRODUCT, product);
        productToIssue.setField(ProductsToIssueFields.ADDITIONAL_CODE, key.getAdditionalCode());
        productToIssue.setField(ProductsToIssueFields.CONVERSION, key.getConversion());
        productToIssue.setField(ProductsToIssueFields.LOCATION, location);
        if (productAlreadyCreated(createdProductsToIssue, product.getId(), Optional.ofNullable(key.getAdditionalCode()).orElse(productToIssue).getId(), location.getId(), key.getConversion())) {
            warehouseIssue = createNewWarehouseIssue(placeOfIssue, delivery);
            if (!warehouseIssue.isValid()) {
                for (Map.Entry<String, ErrorMessage> e : warehouseIssue.getErrors().entrySet()) {
                    creationWarehouseIssueState.getErrors().add(e.getValue());
                }
                throw new IllegalStateException("Undone creation warehouse issue for delivery : " + delivery.getStringField(DeliveryFields.NUMBER));
            }
            createdProductsToIssue = Lists.newArrayList();
        }
        productToIssue.setField(ProductsToIssueFields.WAREHOUSE_ISSUE, warehouseIssue);
        Optional<Entity> storageLocation = findStorageLocationForProduct(product, location);
        if (storageLocation.isPresent()) {
            productToIssue.setField(ProductsToIssueFields.STORAGE_LOCATION, storageLocation.get());
        }
        BigDecimal dQuantity = value.stream().filter(Objects::nonNull).map(val -> val.getReservationForDeliveredProduct().getDecimalField(DeliveredProductReservationFields.DELIVERED_QUANTITY)).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal aQuantity = value.stream().filter(Objects::nonNull).map(val -> val.getReservationForDeliveredProduct().getDecimalField(DeliveredProductReservationFields.ADDITIONAL_QUANTITY)).reduce(BigDecimal.ZERO, BigDecimal::add);
        productToIssue.setField(ProductsToIssueFields.DEMAND_QUANTITY, dQuantity);
        productToIssue.setField(ProductsToIssueFields.ADDITIONAL_DEMAND_QUANTITY, aQuantity);
        productToIssue = productToIssue.getDataDefinition().save(productToIssue);
        createdProductsToIssue.add(productToIssue);
        if (!productToIssue.isValid()) {
            for (Map.Entry<String, ErrorMessage> e : productToIssue.getErrors().entrySet()) {
                creationWarehouseIssueState.getErrors().add(e.getValue());
            }
            throw new IllegalStateException("Undone creation warehouse issue for delivery : " + delivery.getStringField(DeliveryFields.NUMBER));
        }
    }
}
Also used : DeliveredProductReservationKeyObject(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationKeyObject) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) MaterialFlowConstants(com.qcadoo.mes.materialFlow.constants.MaterialFlowConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) CreationWarehouseIssueState(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.CreationWarehouseIssueState) Multimap(com.google.common.collect.Multimap) DeliveredProductReservationKeyObject(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationKeyObject) StateMessageType(com.qcadoo.mes.states.messages.constants.StateMessageType) BigDecimal(java.math.BigDecimal) MaterialFlowResourcesConstants(com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) WarehouseIssueGenerator(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueGenerator) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) DeliveredProductReservationFields(com.qcadoo.mes.deliveries.constants.DeliveredProductReservationFields) DeliveriesConstants(com.qcadoo.mes.deliveries.constants.DeliveriesConstants) Collection(java.util.Collection) DeliveryFields(com.qcadoo.mes.deliveries.constants.DeliveryFields) TranslationService(com.qcadoo.localization.api.TranslationService) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) DeliveredProductFields(com.qcadoo.mes.deliveries.constants.DeliveredProductFields) DeliveredProductReservationObject(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationObject) List(java.util.List) Entity(com.qcadoo.model.api.Entity) WarehouseIssueState(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.states.constants.WarehouseIssueState) CollectionProducts(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.CollectionProducts) Optional(java.util.Optional) StorageLocationFields(com.qcadoo.mes.materialFlowResources.constants.StorageLocationFields) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) Entity(com.qcadoo.model.api.Entity) BigDecimal(java.math.BigDecimal) Objects(java.util.Objects) Collection(java.util.Collection) DeliveredProductReservationObject(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationObject) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Map(java.util.Map)

Aggregations

DeliveredProductReservationKeyObject (com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationKeyObject)2 DeliveredProductReservationObject (com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationObject)2 Entity (com.qcadoo.model.api.Entity)2 BigDecimal (java.math.BigDecimal)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 TranslationService (com.qcadoo.localization.api.TranslationService)1 DeliveredProductFields (com.qcadoo.mes.deliveries.constants.DeliveredProductFields)1 DeliveredProductReservationFields (com.qcadoo.mes.deliveries.constants.DeliveredProductReservationFields)1 DeliveriesConstants (com.qcadoo.mes.deliveries.constants.DeliveriesConstants)1 DeliveryFields (com.qcadoo.mes.deliveries.constants.DeliveryFields)1 MaterialFlowConstants (com.qcadoo.mes.materialFlow.constants.MaterialFlowConstants)1 MaterialFlowResourcesConstants (com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants)1 StorageLocationFields (com.qcadoo.mes.materialFlowResources.constants.StorageLocationFields)1 ProductFlowThruDivisionConstants (com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants)1 CreationWarehouseIssueState (com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.CreationWarehouseIssueState)1 WarehouseIssueGenerator (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueGenerator)1 WarehouseIssueParameterService (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService)1 CollectionProducts (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.CollectionProducts)1