Search in sources :

Example 1 with CreationDocumentResponse

use of com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse in project mes by qcadoo.

the class WarehouseIssueDocumentsService method build.

private CreationDocumentResponse build(final DocumentsStatus documentsStatus, final DocumentBuilder documentBuilder) {
    Entity document;
    try {
        if (DocumentsStatus.ACCEPTED.getStrValue().equals(documentsStatus.getStrValue())) {
            document = documentBuilder.setAccepted().buildWithEntityRuntimeException();
        } else {
            document = documentBuilder.buildWithEntityRuntimeException();
        }
        if (!document.isValid()) {
            List<ErrorMessage> errors = Lists.newArrayList();
            errors.addAll(document.getGlobalErrors());
            return new CreationDocumentResponse(false, errors);
        }
        CreationDocumentResponse creationDocumentResponse = new CreationDocumentResponse(true);
        creationDocumentResponse.setDocument(document);
        return creationDocumentResponse;
    } catch (DocumentBuildException e) {
        return new CreationDocumentResponse(false, e.getGlobalErrors());
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) CreationDocumentResponse(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)

Example 2 with CreationDocumentResponse

use of com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse in project mes by qcadoo.

the class WarehouseIssueDocumentsService method createWarehouseDocument.

public CreationDocumentResponse createWarehouseDocument(final Entity locationFrom, final Entity locationTo, final Collection positions, final String additionalInfo) {
    List<Entity> _issues = Lists.newArrayList(positions);
    for (Entity issue : _issues) {
        reservationsServiceForProductsToIssue.onIssue(issue);
    }
    DrawnDocuments drawnDocument = warehouseIssueParameterService.getDrawnDocument();
    DocumentsStatus documentsStatus = warehouseIssueParameterService.getDocuemtStatusCreatedDocuemnt();
    CreationDocumentResponse response = null;
    switch(drawnDocument) {
        case RECEIPT_RELEASE:
            response = buildReceiptReleasePairDocuments(locationFrom, locationTo, positions, documentsStatus, additionalInfo);
            break;
        case TRANSFER:
            response = buildTransferDocument(locationFrom, locationTo, positions, documentsStatus, additionalInfo);
            break;
    }
    if (response == null) {
        response = new CreationDocumentResponse(false);
    }
    if (!response.isValid()) {
        for (Entity issue : _issues) {
            reservationsServiceForProductsToIssue.onIssueCompensation(issue);
        }
    }
    return response;
}
Also used : Entity(com.qcadoo.model.api.Entity) DrawnDocuments(com.qcadoo.mes.productFlowThruDivision.constants.DrawnDocuments) DocumentsStatus(com.qcadoo.mes.productFlowThruDivision.constants.DocumentsStatus) CreationDocumentResponse(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse)

Example 3 with CreationDocumentResponse

use of com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse in project mes by qcadoo.

the class WarehouseIssueService method createWarehouseDocumentsForPositions.

public List<Entity> createWarehouseDocumentsForPositions(final ViewDefinitionState view, final List<Entity> issues, final Entity locationFrom, final Optional<String> additionalInfo) {
    List<Entity> validDocuments = Lists.newArrayList();
    if (!checkIfAllIssueQuantityGraterThanZero(issues)) {
        throw new RuntimeException("productFlowThruDivision.issue.state.accept.error.issueForZero");
    }
    UpdateIssuesLocationsQuantityStatusHolder updateIssuesStatus = tryUpdateIssuesLocationsQuantity(locationFrom, issues);
    if (!updateIssuesStatus.isUpdated()) {
        throw new RuntimeExceptionWithArguments("productFlowThruDivision.issue.state.accept.error.noProductsOnLocation", updateIssuesStatus.getMessage(), locationFrom.getStringField(LocationFields.NUMBER));
    } else {
        MultiMap warehouseIssuesMap = new MultiHashMap();
        for (Entity issue : issues) {
            warehouseIssuesMap.put(issue.getBelongsToField(L_LOCATION).getId(), issue);
        }
        for (Object key : warehouseIssuesMap.keySet()) {
            Long id = (Long) key;
            Entity locationTo = getLocationDD().get(id);
            Collection coll = (Collection) warehouseIssuesMap.get(key);
            CreationDocumentResponse response;
            if (additionalInfo.isPresent()) {
                response = createWarehouseDocumentForPositions(coll, locationFrom, locationTo, additionalInfo.get());
            } else {
                response = createWarehouseDocumentForPositions(coll, locationFrom, locationTo);
            }
            if (response.isValid()) {
                validDocuments.add(response.getDocument());
            } else {
                if (!response.getErrors().isEmpty()) {
                    response.getErrors().forEach(er -> view.addMessage(er));
                }
                throw new RuntimeExceptionWithArguments("productFlowThruDivision.issue.state.accept.error.documentsNotCreated");
            }
            updateIssuePosition(coll, response.getDocument());
        }
        Set<Entity> warehouseIssues = extractWarehouseIssues(issues);
        updateProductsToIssues(warehouseIssues, issues);
        updateWarehouseIssuesState(warehouseIssues);
        view.addMessage("productFlowThruDivision.issue.documentGeneration.success", ComponentState.MessageType.SUCCESS);
        return validDocuments;
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) MultiMap(org.apache.commons.collections.MultiMap) UpdateIssuesLocationsQuantityStatusHolder(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder) RuntimeExceptionWithArguments(com.qcadoo.model.api.exception.RuntimeExceptionWithArguments) Collection(java.util.Collection) MultiHashMap(org.apache.commons.collections.MultiHashMap) CreationDocumentResponse(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse)

Example 4 with CreationDocumentResponse

use of com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse in project mes by qcadoo.

the class WarehouseIssueStateService method createWarehouseDocuments.

private void createWarehouseDocuments(final StateChangeContext stateChangeContext, final Entity warehouseIssue, final List<Entity> issues) {
    MultiMap warehouseIssuesMap = new MultiHashMap();
    for (Entity issue : issues) {
        warehouseIssuesMap.put(issue.getBelongsToField(IssueFields.LOCATION).getId(), issue);
    }
    for (Object key : warehouseIssuesMap.keySet()) {
        Long id = (Long) key;
        Entity locationTo = getLocationDD().get(id);
        Entity locationFrom = warehouseIssue.getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE);
        Entity order = null;
        if (warehouseIssueParameterService.issueForOrder()) {
            order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(warehouseIssue.getBelongsToField(WarehouseIssueFields.ORDER).getId());
        }
        Collection coll = (Collection) warehouseIssuesMap.get(key);
        List<Entity> _issues = Lists.newArrayList(coll);
        CreationDocumentResponse response = warehouseIssueService.createWarehouseDocument(locationFrom, locationTo, order, coll);
        if (!response.isValid()) {
            stateChangeContext.addValidationError("productFlowThruDivision.issue.state.accept.error.documentsNotCreated");
            if (Objects.nonNull(response.getErrors())) {
                response.getErrors().forEach(er -> stateChangeContext.addValidationError(er.getMessage(), er.getVars()));
            }
            stateChangeContext.setStatus(StateChangeStatus.FAILURE);
        } else {
            warehouseIssueService.updateIssuePosition(coll, response.getDocument());
            warehouseIssueService.updateProductsToIssues(Sets.newHashSet(warehouseIssue), _issues);
        }
    }
}
Also used : MultiMap(org.apache.commons.collections.MultiMap) Entity(com.qcadoo.model.api.Entity) Collection(java.util.Collection) MultiHashMap(org.apache.commons.collections.MultiHashMap) CreationDocumentResponse(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse)

Aggregations

CreationDocumentResponse (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse)4 Entity (com.qcadoo.model.api.Entity)4 Collection (java.util.Collection)2 MultiHashMap (org.apache.commons.collections.MultiHashMap)2 MultiMap (org.apache.commons.collections.MultiMap)2 DocumentBuildException (com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)1 DocumentsStatus (com.qcadoo.mes.productFlowThruDivision.constants.DocumentsStatus)1 DrawnDocuments (com.qcadoo.mes.productFlowThruDivision.constants.DrawnDocuments)1 UpdateIssuesLocationsQuantityStatusHolder (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder)1 RuntimeExceptionWithArguments (com.qcadoo.model.api.exception.RuntimeExceptionWithArguments)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1