Search in sources :

Example 1 with CreationWarehouseIssueState

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

the class DeliveryStatePFTDService method tryCreateIssuesForDeliveriesReservations.

public void tryCreateIssuesForDeliveriesReservations(final StateChangeContext context) {
    if (warehouseIssueParameterService.generateWarehouseIssuesToDeliveries()) {
        Entity delivery = context.getOwner();
        List<Entity> reservationsForDelivery = findReservationsForDelivery(delivery);
        if (reservationsForDelivery.isEmpty()) {
            return;
        }
        Multimap<Long, Entity> reservationsMapGroupedByWarehouse = ArrayListMultimap.create();
        for (Entity res : reservationsForDelivery) {
            reservationsMapGroupedByWarehouse.put(res.getBelongsToField(DeliveredProductReservationFields.LOCATION).getId(), res);
        }
        CreationWarehouseIssueState creationWarehouseIssueState = new CreationWarehouseIssueState();
        createWarehouseIssues(creationWarehouseIssueState, delivery, delivery.getBelongsToField(DeliveryFields.LOCATION), reservationsMapGroupedByWarehouse);
        context.addMessage("productFlowThruDivision.deliveries.warehouseIssue.issuesCreated.success", StateMessageType.SUCCESS);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) CreationWarehouseIssueState(com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.CreationWarehouseIssueState)

Example 2 with CreationWarehouseIssueState

use of com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.CreationWarehouseIssueState 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

CreationWarehouseIssueState (com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.CreationWarehouseIssueState)2 Entity (com.qcadoo.model.api.Entity)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 DeliveredProductReservationKeyObject (com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationKeyObject)1 DeliveredProductReservationObject (com.qcadoo.mes.productFlowThruDivision.deliveries.helpers.DeliveredProductReservationObject)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 ProductsToIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields)1