use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class ProductionPerShiftDetailsHooks method fillOrderDateComponents.
void fillOrderDateComponents(final ViewDefinitionState view, final Entity order) {
for (ImmutableMap.Entry<String, String> modelFieldToViewReference : ORDER_DATE_FIELDS_TO_VIEW_COMPONENTS.entrySet()) {
FieldComponent dateComponent = (FieldComponent) view.getComponentByReference(modelFieldToViewReference.getValue());
Date date = order.getDateField(modelFieldToViewReference.getKey());
dateComponent.setFieldValue(DateUtils.toDateTimeString(date));
dateComponent.requestComponentUpdateState();
}
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class GenerateBalanceListeners method onFilterCheckboxChange.
public void onFilterCheckboxChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
CheckBoxComponent plannedRequiredCheckbox = (CheckBoxComponent) view.getComponentByReference("plannedQuantityRequired");
CheckBoxComponent deviationRequiredCheckbox = (CheckBoxComponent) view.getComponentByReference("deviationRequired");
FieldComponent deviationThreshold = (FieldComponent) view.getComponentByReference("deviationThreshold");
if (plannedRequiredCheckbox == null || deviationRequiredCheckbox == null) {
return;
}
deviationRequiredCheckbox.setEnabled(plannedRequiredCheckbox.isChecked());
if (!plannedRequiredCheckbox.isChecked()) {
deviationRequiredCheckbox.setChecked(false);
}
boolean thresholdEnabled = plannedRequiredCheckbox.isChecked() && deviationRequiredCheckbox.isChecked();
deviationThreshold.setEnabled(thresholdEnabled);
deviationThreshold.setRequired(thresholdEnabled);
if (!(plannedRequiredCheckbox.isChecked() && deviationRequiredCheckbox.isChecked())) {
deviationThreshold.setFieldValue(null);
}
}
use of com.qcadoo.view.api.components.FieldComponent 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);
}
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class GenerateBalanceViewHooks method fillDeviationThresholdUnit.
private void fillDeviationThresholdUnit(final ViewDefinitionState viewState) {
FieldComponent deviationThresholdUnitComponent = (FieldComponent) findComponent(viewState, "deviationThresholdUnit");
deviationThresholdUnitComponent.setFieldValue("%");
deviationThresholdUnitComponent.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class OrderTimePredictionListeners method fillUnitField.
public void fillUnitField(final ViewDefinitionState view, final ComponentState state, final String[] args) {
LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY);
FieldComponent unitField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.OPERATION_DURATION_QUANTITY_UNIT);
Entity technology = technologyLookup.getEntity();
if (technology != null) {
Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
if (product != null) {
unitField.setFieldValue(product.getField(ProductFields.UNIT));
unitField.requestComponentUpdateState();
}
}
}
Aggregations