Search in sources :

Example 51 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.

the class ProductionPerShiftDetailsHooks method updateAutoFillButtonState.

private void updateAutoFillButtonState(ViewDefinitionState view) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonActionItem button = window.getRibbon().getGroupByName("autoFill").getItemByName("planProgressForDays");
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    if (!automaticPpsParametersService.isAutomaticPlanForShiftOn()) {
        button.setEnabled(false);
        button.requestUpdate(true);
        window.requestRibbonRender();
        return;
    }
    Entity formEntity = form.getPersistedEntityWithIncludedFormValues();
    Date orderStartDate = formEntity.getBelongsToField(ProductionPerShiftFields.ORDER).getDateField(OrderFields.START_DATE);
    String orderState = formEntity.getBelongsToField(ProductionPerShiftFields.ORDER).getStringField(OrderFields.STATE);
    if (orderStartDate != null && OrderStateStringValues.PENDING.equals(orderState)) {
        button.setEnabled(true);
    } else {
        button.setEnabled(false);
    }
    button.requestUpdate(true);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) WindowComponent(com.qcadoo.view.api.components.WindowComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) Date(java.util.Date)

Example 52 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.

the class GenerateBalanceListeners method generateBalance.

public void generateBalance(final ViewDefinitionState viewState, final ComponentState formState, final String[] args) {
    FormComponent form = (FormComponent) formState;
    Entity contextEntity = form.getPersistedEntityWithIncludedFormValues();
    // We don't want to reuse contexts - in case of the user working with many browser tabs to compare a couple of results
    contextEntity.setId(null);
    contextEntity.setField(BalanceContextFields.BALANCES, Collections.<Entity>emptyList());
    // Call validation
    contextEntity = contextEntity.getDataDefinition().save(contextEntity);
    if (!contextEntity.isValid()) {
        form.setEntity(contextEntity);
        return;
    }
    BalanceGenerationStrategy strategy = resolveBalanceGenerationStrategy(contextEntity);
    List<Entity> balances = productionBalancePerShiftGenerator.generate(strategy);
    contextEntity.setField(BalanceContextFields.BALANCES, balances);
    Entity persistedContext = contextEntity.getDataDefinition().save(contextEntity);
    if (persistedContext.isValid()) {
        // Show 'balances' tab
        WindowComponent window = (WindowComponent) viewState.getComponentByReference(QcadooViewConstants.L_WINDOW);
        window.setActiveTab("balances");
    }
    form.setEntity(persistedContext);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) BalanceGenerationStrategy(com.qcadoo.mes.productionPerShift.BalanceGenerationStrategy) WindowComponent(com.qcadoo.view.api.components.WindowComponent)

Example 53 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.

the class ProgressPerShiftViewSaver method showValidationErrors.

private void showValidationErrors(final ViewDefinitionState view, final Iterable<ErrorMessage> errorMessages) {
    FormComponent form = getFormComponent(view);
    form.addMessage("qcadooView.message.saveFailedMessage", ComponentState.MessageType.FAILURE);
    for (ErrorMessage errorMessage : errorMessages) {
        form.addMessage(errorMessage.getMessage(), ComponentState.MessageType.FAILURE, errorMessage.getVars());
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Example 54 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.

the class OperationDurationDetailsInOrderListeners method generateRealizationTime.

@Transactional
public void generateRealizationTime(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) {
    FormComponent orderForm = (FormComponent) viewDefinitionState.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent startTimeField = (FieldComponent) viewDefinitionState.getComponentByReference(L_START_TIME);
    LookupComponent prodLine = (LookupComponent) viewDefinitionState.getComponentByReference(OrderFields.PRODUCTION_LINE);
    if (!StringUtils.hasText((String) startTimeField.getFieldValue())) {
        startTimeField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    if (prodLine.isEmpty()) {
        prodLine.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    FieldComponent plannedQuantityField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PLANNED_QUANTITY);
    FieldComponent productionLineLookup = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PRODUCTION_LINE);
    FieldComponent generatedEndDateField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.GENERATED_END_DATE);
    FieldComponent includeTpzField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_TPZ);
    FieldComponent includeAdditionalTimeField = (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_ADDITIONAL_TIME);
    boolean isGenerated = false;
    Entity productionLine = dataDefinitionService.get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE).get((Long) productionLineLookup.getFieldValue());
    Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderForm.getEntity().getId());
    // copy of technology from order
    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
    Validate.notNull(technology, "technology is null");
    BigDecimal quantity = orderRealizationTimeService.getBigDecimalFromField(plannedQuantityField.getFieldValue(), viewDefinitionState.getLocale());
    // Included in work time
    boolean includeTpz = "1".equals(includeTpzField.getFieldValue());
    boolean includeAdditionalTime = "1".equals(includeAdditionalTimeField.getFieldValue());
    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    productQuantitiesService.getProductComponentQuantities(technology, quantity, operationRuns);
    operationWorkTimeService.deleteOperCompTimeCalculations(order);
    OperationWorkTime workTime = operationWorkTimeService.estimateTotalWorkTimeForOrder(order, operationRuns, includeTpz, includeAdditionalTime, true);
    fillWorkTimeFields(viewDefinitionState, workTime);
    order = getActualOrderWithChanges(order);
    int maxPathTime = orderRealizationTimeService.estimateMaxOperationTimeConsumptionForWorkstation(order, technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(), quantity, includeTpz, includeAdditionalTime, productionLine);
    if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) {
        state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", MessageType.FAILURE);
        generatedEndDateField.setFieldValue(null);
    } else {
        order.setField(OrderFieldsPS.REALIZATION_TIME, maxPathTime);
        Date startTime = order.getDateField(OrderFields.DATE_FROM);
        if (startTime == null) {
            startTimeField.addMessage("orders.validate.global.error.dateFromIsNull", MessageType.FAILURE);
        } else {
            if (maxPathTime == 0) {
                orderForm.addMessage("productionScheduling.timenorms.isZero", MessageType.FAILURE, false);
                generatedEndDateField.setFieldValue(null);
            } else {
                productionSchedulingService.scheduleOrder(order.getId());
                isGenerated = true;
            }
            orderForm.addMessage("orders.dateFrom.info.dateFromSetToFirstPossible", MessageType.INFO, false);
        }
    }
    generatedEndDateField.requestComponentUpdateState();
    if (isGenerated) {
        order = getActualOrderWithChanges(order);
        Entity orderTimeCalculation = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().add(SearchRestrictions.belongsTo(OrderTimeCalculationFields.ORDER, order)).setMaxResults(1).uniqueResult();
        order.setField(OrderFields.START_DATE, orderRealizationTimeService.setDateToField(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_FROM)));
        order.setField(OrderFieldsPS.GENERATED_END_DATE, orderRealizationTimeService.setDateToField(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO)));
        order = order.getDataDefinition().save(order);
        orderForm.setEntity(order);
        orderForm.addMessage("productionScheduling.info.calculationGenerated", MessageType.SUCCESS);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.

the class OrderTimePredictionListeners method changeRealizationTime.

@Transactional
public void changeRealizationTime(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent orderForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent technologyLookup = (FieldComponent) view.getComponentByReference(OrderFields.TECHNOLOGY);
    FieldComponent plannedQuantityField = (FieldComponent) view.getComponentByReference(OrderFields.PLANNED_QUANTITY);
    FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_FROM);
    FieldComponent dateToField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_TO);
    FieldComponent productionLineLookup = (FieldComponent) view.getComponentByReference(OrderFields.PRODUCTION_LINE);
    boolean isGenerated = false;
    if (technologyLookup.getFieldValue() == null) {
        technologyLookup.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    if (!StringUtils.hasText((String) dateFromField.getFieldValue())) {
        dateFromField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    if (!StringUtils.hasText((String) plannedQuantityField.getFieldValue())) {
        plannedQuantityField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    if (productionLineLookup.getFieldValue() == null) {
        productionLineLookup.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);
        return;
    }
    BigDecimal quantity;
    Object value = plannedQuantityField.getFieldValue();
    if (value instanceof BigDecimal) {
        quantity = (BigDecimal) value;
    } else if (value.toString().matches(".*[a-zA-Z].*")) {
        plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidNumericFormat", MessageType.FAILURE);
        return;
    } else {
        try {
            ParsePosition parsePosition = new ParsePosition(0);
            String trimmedValue = value.toString().replaceAll(" ", "");
            DecimalFormat formatter = (DecimalFormat) NumberFormat.getNumberInstance(view.getLocale());
            formatter.setParseBigDecimal(true);
            quantity = new BigDecimal(String.valueOf(formatter.parseObject(trimmedValue, parsePosition)));
        } catch (NumberFormatException e) {
            plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidNumericFormat", MessageType.FAILURE);
            return;
        }
    }
    int scale = quantity.scale();
    if (scale > MAX) {
        plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidScale.max", MessageType.FAILURE, MAX.toString());
        return;
    }
    int presicion = quantity.precision() - scale;
    if (presicion > MAX) {
        plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidPrecision.max", MessageType.FAILURE, MAX.toString());
        return;
    }
    if (BigDecimal.ZERO.compareTo(quantity) >= 0) {
        plannedQuantityField.addMessage("qcadooView.validate.field.error.outOfRange.toSmall", MessageType.FAILURE);
        return;
    }
    Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).get((Long) technologyLookup.getFieldValue());
    Validate.notNull(technology, "technology is null");
    if (technology.getStringField(TechnologyFields.STATE).equals(TechnologyState.DRAFT.getStringValue()) || technology.getStringField(TechnologyFields.STATE).equals(TechnologyState.OUTDATED.getStringValue())) {
        technologyLookup.addMessage("productionScheduling.technology.incorrectState", MessageType.FAILURE);
        return;
    }
    FieldComponent laborWorkTimeField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.LABOR_WORK_TIME);
    FieldComponent machineWorkTimeField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.MACHINE_WORK_TIME);
    FieldComponent includeTpzField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.INCLUDE_TPZ);
    FieldComponent includeAdditionalTimeField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.INCLUDE_ADDITIONAL_TIME);
    boolean includeTpz = "1".equals(includeTpzField.getFieldValue());
    boolean includeAdditionalTime = "1".equals(includeAdditionalTimeField.getFieldValue());
    Entity productionLine = dataDefinitionService.get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE).get((Long) productionLineLookup.getFieldValue());
    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    productQuantitiesService.getProductComponentQuantities(technology, quantity, operationRuns);
    OperationWorkTime workTime = operationWorkTimeService.estimateTotalWorkTimeForTechnology(technology, operationRuns, includeTpz, includeAdditionalTime, true);
    laborWorkTimeField.setFieldValue(workTime.getLaborWorkTime());
    machineWorkTimeField.setFieldValue(workTime.getMachineWorkTime());
    int maxPathTime = orderRealizationTimeService.estimateOperationTimeConsumption(technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(), quantity, includeTpz, includeAdditionalTime, productionLine);
    if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) {
        state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", MessageType.FAILURE);
        dateToField.setFieldValue(null);
    } else {
        Date startTime = DateUtils.parseDate(dateFromField.getFieldValue());
        if (startTime == null) {
            dateFromField.addMessage("orders.validate.global.error.dateFromIsNull", MessageType.FAILURE);
        } else {
            if (maxPathTime == 0) {
                orderForm.addMessage("productionScheduling.timenorms.isZero", MessageType.FAILURE, false);
                dateToField.setFieldValue(null);
            } else {
                Date stopTime = shiftsService.findDateToForProductionLine(startTime, maxPathTime, productionLine);
                dateToField.setFieldValue(orderRealizationTimeService.setDateToField(stopTime));
                Optional<DateTime> startTimeOptional = shiftsService.getNearestWorkingDate(new DateTime(startTime), productionLine);
                startTimeOptional.ifPresent(e -> {
                    scheduleOperationComponents(technology.getId(), startTime, productionLine);
                    orderForm.addMessage("orders.dateFrom.info.dateFromSetToFirstPossible", MessageType.INFO, false);
                });
                isGenerated = true;
            }
        }
    }
    laborWorkTimeField.requestComponentUpdateState();
    machineWorkTimeField.requestComponentUpdateState();
    dateFromField.requestComponentUpdateState();
    dateToField.requestComponentUpdateState();
    orderForm.setEntity(orderForm.getEntity());
    state.performEvent(view, "refresh");
    if (isGenerated) {
        orderForm.addMessage("productionScheduling.info.calculationGenerated", MessageType.SUCCESS);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal) Date(java.util.Date) DateTime(org.joda.time.DateTime) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) ParsePosition(java.text.ParsePosition) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FormComponent (com.qcadoo.view.api.components.FormComponent)644 Entity (com.qcadoo.model.api.Entity)501 FieldComponent (com.qcadoo.view.api.components.FieldComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)104 GridComponent (com.qcadoo.view.api.components.GridComponent)83 BigDecimal (java.math.BigDecimal)55 WindowComponent (com.qcadoo.view.api.components.WindowComponent)52 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)45 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)42 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)39 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)36 Date (java.util.Date)33 DataDefinition (com.qcadoo.model.api.DataDefinition)29 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)28 JSONObject (org.json.JSONObject)28 ComponentState (com.qcadoo.view.api.ComponentState)27 Transactional (org.springframework.transaction.annotation.Transactional)20 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)17 Optional (com.google.common.base.Optional)16 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)16