Search in sources :

Example 6 with EntityRuntimeException

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));
        }
    }
}
Also used : JSONObject(org.json.JSONObject) GridComponent(com.qcadoo.view.api.components.GridComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

Example 7 with EntityRuntimeException

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) Date(java.util.Date) DateTime(org.joda.time.DateTime) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with EntityRuntimeException

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);
        }
    }
}
Also used : SizeFields(com.qcadoo.mes.basic.constants.SizeFields) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) ProductsBySizeHelperFields(com.qcadoo.mes.masterOrders.constants.ProductsBySizeHelperFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SalesPlanProductFields(com.qcadoo.mes.masterOrders.constants.SalesPlanProductFields) MediaType(org.springframework.http.MediaType) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) TranslationService(com.qcadoo.localization.api.TranslationService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) MasterOrdersConstants(com.qcadoo.mes.masterOrders.constants.MasterOrdersConstants) RequestBody(org.springframework.web.bind.annotation.RequestBody) TechnologyServiceO(com.qcadoo.mes.orders.TechnologyServiceO) List(java.util.List) Entity(com.qcadoo.model.api.Entity) MasterOrderProductFields(com.qcadoo.mes.masterOrders.constants.MasterOrderProductFields) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional) Entity(com.qcadoo.model.api.Entity) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with EntityRuntimeException

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));
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

Example 10 with EntityRuntimeException

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

Aggregations

EntityRuntimeException (com.qcadoo.model.api.exception.EntityRuntimeException)11 Entity (com.qcadoo.model.api.Entity)10 Transactional (org.springframework.transaction.annotation.Transactional)5 TranslationService (com.qcadoo.localization.api.TranslationService)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 SizeFields (com.qcadoo.mes.basic.constants.SizeFields)2 MasterOrderProductFields (com.qcadoo.mes.masterOrders.constants.MasterOrderProductFields)2 MasterOrdersConstants (com.qcadoo.mes.masterOrders.constants.MasterOrdersConstants)2 ProductsBySizeHelperFields (com.qcadoo.mes.masterOrders.constants.ProductsBySizeHelperFields)2 SalesPlanProductFields (com.qcadoo.mes.masterOrders.constants.SalesPlanProductFields)2 TechnologyServiceO (com.qcadoo.mes.orders.TechnologyServiceO)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2 GridComponent (com.qcadoo.view.api.components.GridComponent)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 LocaleContextHolder (org.springframework.context.i18n.LocaleContextHolder)2 MediaType (org.springframework.http.MediaType)2 Controller (org.springframework.stereotype.Controller)2 RequestBody (org.springframework.web.bind.annotation.RequestBody)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2