use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.
the class CompanyDefaultProductsListeners method addMultipleDefaultProducts.
public final void addMultipleDefaultProducts(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
JSONObject obj = view.getJsonContext();
if (obj.has("window.mainTab.product.companyId")) {
CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
Long companyId = obj.getLong("window.mainTab.product.companyId");
try {
tryCreatePositions(grid, companyId);
view.addMessage("basic.companyDefaultProducts.info.generationSuccess", ComponentState.MessageType.SUCCESS);
generated.setChecked(true);
} catch (EntityRuntimeException ere) {
generated.setChecked(false);
view.addMessage("basic.companyDefaultProducts.error.defaultExists", ComponentState.MessageType.FAILURE, ere.getEntity().getBelongsToField(L_PRODUCT).getStringField(ProductFields.NUMBER));
}
}
}
use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.
the class OrdersGenerationService method tryGeneratePPS.
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Date tryGeneratePPS(final Entity order, final Date date) {
Date startDate = findStartDate(order, date);
generateEmptyPpsForOrder(order);
order.setField("generatePPS", true);
order.setField(OrderFields.START_DATE, startDate);
order.setField(OrderFields.FINISH_DATE, new DateTime(order.getDateField(OrderFields.START_DATE)).plusDays(1).toDate());
Entity storedOrder = order.getDataDefinition().save(order);
if (!storedOrder.isValid()) {
throw new EntityRuntimeException(storedOrder);
}
return order.getDateField(OrderFields.FINISH_DATE);
}
use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.
the class ProductsBySizeController method tryCreateSPPositions.
@Transactional
public void tryCreateSPPositions(Entity salesPlan, List<Entity> helperEntries, List<ProductBySizePosition> positions) {
for (ProductBySizePosition position : positions) {
Entity product = helperEntries.stream().filter(e -> e.getId().equals(position.getId())).findAny().get().getBelongsToField("product");
Entity spProduct = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_PRODUCT).create();
spProduct.setField(SalesPlanProductFields.SALES_PLAN, salesPlan);
spProduct.setField(SalesPlanProductFields.PRODUCT, product);
spProduct.setField(SalesPlanProductFields.TECHNOLOGY, technologyServiceO.getDefaultTechnology(spProduct.getBelongsToField(SalesPlanProductFields.PRODUCT)));
spProduct.setField(SalesPlanProductFields.PLANNED_QUANTITY, position.getValue());
spProduct.setField(SalesPlanProductFields.ORDERED_QUANTITY, 0);
spProduct.setField(SalesPlanProductFields.ORDERED_TO_WAREHOUSE, 0);
spProduct.setField(SalesPlanProductFields.SURPLUS_FROM_PLAN, position.getValue());
spProduct = spProduct.getDataDefinition().save(spProduct);
if (!spProduct.isValid()) {
throw new EntityRuntimeException(spProduct);
}
}
}
use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.
the class PositionAddMultiListeners method tryCreatePositions.
public void tryCreatePositions(ViewDefinitionState view, Set<Long> selectedEntities) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity helper = form.getPersistedEntityWithIncludedFormValues();
Entity document = getDocumentDD().get(helper.getLongField(L_DOCUMENT_ID));
List<String> errorNumbers = Lists.newArrayList();
for (Long resourceId : selectedEntities) {
Entity resource = getResourceDD().get(resourceId);
try {
Entity newPosition = createPosition(document, resource);
if (!newPosition.isValid()) {
errorNumbers.add(resource.getStringField(ResourceFields.NUMBER));
}
} catch (EntityRuntimeException ere) {
Entity pos = ere.getEntity();
view.addMessage("documentPositions.error.position.quantity.notEnoughResources", ComponentState.MessageType.FAILURE, pos.getBelongsToField(PositionFields.PRODUCT).getStringField(ProductFields.NUMBER), pos.getBelongsToField(PositionFields.RESOURCE).getStringField(ResourceFields.NUMBER));
}
}
if (!errorNumbers.isEmpty()) {
view.addMessage("materialFlowResources.positionAddMulti.errorForResource", ComponentState.MessageType.INFO, String.join(", ", errorNumbers));
}
}
use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.
the class PositionAddMultiListeners method createPosition.
private Entity createPosition(final Entity document, final Entity resource) {
DataDefinition positionDD = getPositionDD();
Entity newPosition = positionDD.create();
BigDecimal conversion = resource.getDecimalField(ResourceFields.CONVERSION);
BigDecimal availableQuantity = resource.getDecimalField(ResourceFields.AVAILABLE_QUANTITY);
BigDecimal givenQuantity = availableQuantity.multiply(conversion, numberService.getMathContext());
newPosition.setField(PositionFields.DOCUMENT, document);
newPosition.setField(PositionFields.PRODUCT, resource.getBelongsToField(ResourceFields.PRODUCT));
newPosition.setField(PositionFields.QUANTITY, availableQuantity);
newPosition.setField(PositionFields.GIVEN_QUANTITY, givenQuantity);
newPosition.setField(PositionFields.GIVEN_UNIT, resource.getStringField(ResourceFields.GIVEN_UNIT));
newPosition.setField(PositionFields.PRICE, resource.getField(ResourceFields.PRICE));
newPosition.setField(PositionFields.BATCH, resource.getField(ResourceFields.BATCH));
newPosition.setField(PositionFields.PRODUCTION_DATE, resource.getField(ResourceFields.PRODUCTION_DATE));
newPosition.setField(PositionFields.EXPIRATION_DATE, resource.getField(ResourceFields.EXPIRATION_DATE));
newPosition.setField(PositionFields.RESOURCE, resource);
newPosition.setField(PositionFields.RESOURCE_NUMBER, resource.getStringField(ResourceFields.NUMBER));
newPosition.setField(PositionFields.STORAGE_LOCATION, resource.getField(ResourceFields.STORAGE_LOCATION));
newPosition.setField(PositionFields.ADDITIONAL_CODE, resource.getField(ResourceFields.ADDITIONAL_CODE));
newPosition.setField(PositionFields.CONVERSION, conversion);
newPosition.setField(PositionFields.PALLET_NUMBER, resource.getField(ResourceFields.PALLET_NUMBER));
newPosition.setField(PositionFields.TYPE_OF_PALLET, resource.getField(ResourceFields.TYPE_OF_PALLET));
newPosition.setField(PositionFields.WASTE, resource.getField(ResourceFields.WASTE));
if (!validateAvailableQuantity(document, newPosition)) {
throw new EntityRuntimeException(newPosition);
}
return positionDD.save(newPosition);
}
Aggregations