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