Search in sources :

Example 51 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent 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)

Example 52 with FieldComponent

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

the class AllStoppagesFormListeners method calculateDuration.

public void calculateDuration(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FieldComponent dateFromFieldComponent = (FieldComponent) view.getComponentByReference(StoppageFields.DATE_FROM);
    FieldComponent dateToFieldComponent = (FieldComponent) view.getComponentByReference(StoppageFields.DATE_TO);
    FieldComponent durationFieldComponent = (FieldComponent) view.getComponentByReference(StoppageFields.DURATION);
    Date dateFrom = DateUtils.parseDate(dateFromFieldComponent.getFieldValue());
    Date dateTo = DateUtils.parseDate(dateToFieldComponent.getFieldValue());
    if (dateFrom != null && dateTo != null) {
        if (dateFrom.before(dateTo)) {
            Seconds seconds = Seconds.secondsBetween(new DateTime(dateFrom), new DateTime(dateTo));
            durationFieldComponent.setFieldValue(seconds.getSeconds());
        }
        durationFieldComponent.requestComponentUpdateState();
    } else {
        durationFieldComponent.setFieldValue(null);
        durationFieldComponent.requestComponentUpdateState();
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) Seconds(org.joda.time.Seconds) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 53 with FieldComponent

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

the class OrderedProductDetailsHooksSN method fillPricePerUnit.

public void fillPricePerUnit(final ViewDefinitionState view) {
    LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderedProductFields.PRODUCT);
    LookupComponent offerLookup = (LookupComponent) view.getComponentByReference(OrderedProductFieldsSN.OFFER);
    Entity product = productLookup.getEntity();
    Entity offer = offerLookup.getEntity();
    if ((product != null) && (offer != null)) {
        FieldComponent pricePerUnitField = (FieldComponent) view.getComponentByReference(OrderedProductFields.PRICE_PER_UNIT);
        FieldComponent totalPriceField = (FieldComponent) view.getComponentByReference(OrderedProductFields.TOTAL_PRICE);
        FieldComponent quantityField = (FieldComponent) view.getComponentByReference(OrderedProductFields.ORDERED_QUANTITY);
        BigDecimal quantity = deliveriesService.getBigDecimalFromField(quantityField, view.getLocale());
        BigDecimal pricePerUnit = supplyNegotiationsService.getPricePerUnit(offer, product);
        if ((quantity != null) && (pricePerUnit != null)) {
            BigDecimal totalPrice = quantity.multiply(pricePerUnit, numberService.getMathContext());
            pricePerUnitField.setFieldValue(numberService.format(pricePerUnit));
            totalPriceField.setFieldValue(numberService.format(totalPrice));
        } else {
            if (pricePerUnit == null) {
                pricePerUnitField.setFieldValue(null);
            } else {
                pricePerUnitField.setFieldValue(numberService.format(pricePerUnit));
            }
            totalPriceField.setFieldValue(null);
        }
        totalPriceField.requestComponentUpdateState();
        pricePerUnitField.requestComponentUpdateState();
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal)

Example 54 with FieldComponent

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

the class OrderedProductDetailsHooksSN method disabledFieldWhenOfferIsSelected.

public void disabledFieldWhenOfferIsSelected(final ViewDefinitionState view) {
    LookupComponent offerLookup = (LookupComponent) view.getComponentByReference(OrderedProductFieldsSN.OFFER);
    Entity offer = offerLookup.getEntity();
    FieldComponent pricePerUnitField = (FieldComponent) view.getComponentByReference(OrderedProductFields.PRICE_PER_UNIT);
    FieldComponent totalPriceField = (FieldComponent) view.getComponentByReference(OrderedProductFields.TOTAL_PRICE);
    if (offer == null) {
        pricePerUnitField.setEnabled(true);
        totalPriceField.setEnabled(true);
    } else {
        pricePerUnitField.setEnabled(false);
        totalPriceField.setEnabled(false);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 55 with FieldComponent

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

the class ProductDetailsHooksSN method disabledFieldAboutCostFromOffer.

public void disabledFieldAboutCostFromOffer(final ViewDefinitionState view) {
    for (String reference : Arrays.asList("lastOfferCost", "averageOfferCost")) {
        FieldComponent field = (FieldComponent) view.getComponentByReference(reference);
        field.setEnabled(false);
        field.requestComponentUpdateState();
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Aggregations

FieldComponent (com.qcadoo.view.api.components.FieldComponent)443 Entity (com.qcadoo.model.api.Entity)201 FormComponent (com.qcadoo.view.api.components.FormComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)107 BigDecimal (java.math.BigDecimal)47 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)31 Date (java.util.Date)30 Optional (com.google.common.base.Optional)18 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)14 ComponentState (com.qcadoo.view.api.ComponentState)13 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)13 WindowComponent (com.qcadoo.view.api.components.WindowComponent)12 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)11 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)9 PossibleUnitConversions (com.qcadoo.model.api.units.PossibleUnitConversions)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)6 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)6 Collectors (java.util.stream.Collectors)6