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);
}
}
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();
}
}
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();
}
}
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);
}
}
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();
}
}
Aggregations