Search in sources :

Example 1 with GenerationOrderResult

use of com.qcadoo.mes.masterOrders.GenerationOrderResult in project mes by qcadoo.

the class SalesPlanOrdersController method generateOrders.

private GenerateOrdersSalePlanResponse generateOrders(GenerateOrdersSalePlanRequest generateOrdersSalePlanRequest) {
    Entity helper = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_HELPER).get(generateOrdersSalePlanRequest.getEntityId());
    List<OrderSalePlanPosition> positionsWithQuantities = generateOrdersSalePlanRequest.getPositions();
    List<Entity> positions = helper.getHasManyField(SalesPlanOrdersGroupHelperFields.SALES_PLAN_ORDERS_GROUP_ENTRY_HELPERS);
    Entity salesPlan = helper.getBelongsToField(SalesPlanOrdersGroupHelperFields.SALES_PLAN);
    GenerationOrderResult result = new GenerationOrderResult(translationService, parameterService);
    try {
        generateOrders(result, salesPlan, positionsWithQuantities, positions);
        GenerateOrdersSalePlanResponse response = new GenerateOrdersSalePlanResponse();
        response.setStatus(GenerateOrdersSalePlanResponse.SimpleResponseStatus.OK);
        response.setMessages(result.extractMessages());
        return response;
    } catch (Exception exc) {
        GenerateOrdersSalePlanResponse response = new GenerateOrdersSalePlanResponse();
        response.setStatus(GenerateOrdersSalePlanResponse.SimpleResponseStatus.ERROR);
        response.setErrorMessages(Lists.newArrayList(translationService.translate("masterOrders.ordersGenerationFromProducts.error.ordersNotGenerated", LocaleContextHolder.getLocale())));
        return response;
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) GenerationOrderResult(com.qcadoo.mes.masterOrders.GenerationOrderResult)

Example 2 with GenerationOrderResult

use of com.qcadoo.mes.masterOrders.GenerationOrderResult in project mes by qcadoo.

the class OrdersGenerationFromProductsListeners method generateOrders.

public void generateOrders(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
    Entity entity = form.getPersistedEntityWithIncludedFormValues();
    entity = entity.getDataDefinition().validate(entity);
    if (!entity.isValid()) {
        form.setEntity(entity);
        return;
    }
    JSONObject context = view.getJsonContext();
    Set<Long> ids = Arrays.stream(context.getString("window.mainTab.form.gridLayout.selectedEntities").replaceAll("[\\[\\]]", "").split(",")).map(Long::valueOf).collect(Collectors.toSet());
    GenerationOrderResult result = new GenerationOrderResult(translationService, parameterService);
    try {
        generateOrders(result, ids, entity);
        result.showMessage(view);
    } catch (Exception exc) {
        view.addMessage("orders.ordersGenerationFromProducts.error.ordersNotGenerated", ComponentState.MessageType.FAILURE);
    }
    generated.setChecked(true);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) GenerationOrderResult(com.qcadoo.mes.masterOrders.GenerationOrderResult) JSONException(org.json.JSONException) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Aggregations

GenerationOrderResult (com.qcadoo.mes.masterOrders.GenerationOrderResult)2 Entity (com.qcadoo.model.api.Entity)2 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)1 FormComponent (com.qcadoo.view.api.components.FormComponent)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1