use of com.qcadoo.view.api.components.AwesomeDynamicListComponent in project mes by qcadoo.
the class OrderDetailsHooks method changedEnabledAwesomeDynamicListComponents.
private void changedEnabledAwesomeDynamicListComponents(final ViewDefinitionState view, final List<String> references, final boolean enabled) {
for (String reference : references) {
AwesomeDynamicListComponent awesomeDynamicListComponent = (AwesomeDynamicListComponent) view.getComponentByReference(reference);
awesomeDynamicListComponent.setEnabled(enabled);
awesomeDynamicListComponent.requestComponentUpdateState();
for (FormComponent formComponent : awesomeDynamicListComponent.getFormComponents()) {
FieldComponent fieldComponent = formComponent.findFieldComponentByName(L_REASON_TYPE_OF_CHANGING_ORDER_STATE);
fieldComponent.setEnabled(enabled);
fieldComponent.requestComponentUpdateState();
}
}
}
use of com.qcadoo.view.api.components.AwesomeDynamicListComponent in project mes by qcadoo.
the class DivideOrderTechnologicalProcessListeners method onAddRow.
public void onAddRow(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent orderTechnologicalProcessForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
AwesomeDynamicListComponent orderTechnologicalProcessPartsADL = (AwesomeDynamicListComponent) view.getComponentByReference(OrderTechnologicalProcessFields.ORDER_TECHNOLOGICAL_PROCESS_PARTS);
Entity orderTechnologicalProcess = orderTechnologicalProcessForm.getEntity();
Long orderTechnologicalProcessId = orderTechnologicalProcess.getId();
orderTechnologicalProcess = orderTechnologicalProcess.getDataDefinition().get(orderTechnologicalProcessId);
Entity product = orderTechnologicalProcess.getBelongsToField(OrderTechnologicalProcessFields.PRODUCT);
String productUnit = product.getStringField(ProductFields.UNIT);
List<FormComponent> orderTechnologicalProcessPartForms = orderTechnologicalProcessPartsADL.getFormComponents();
for (FormComponent orderTechnologicalProcessPartForm : orderTechnologicalProcessPartForms) {
FieldComponent numberField = orderTechnologicalProcessPartForm.findFieldComponentByName(OrderTechnologicalProcessPartFields.NUMBER);
FieldComponent unitField = orderTechnologicalProcessPartForm.findFieldComponentByName(OrderTechnologicalProcessPartFields.UNIT);
String number = (String) numberField.getFieldValue();
String unit = (String) unitField.getFieldValue();
if (StringUtils.isEmpty(number)) {
numberField.setFieldValue(String.valueOf(orderTechnologicalProcessPartForms.size()));
}
numberField.requestComponentUpdateState();
if (StringUtils.isEmpty(unit)) {
unitField.setFieldValue(productUnit);
}
unitField.requestComponentUpdateState();
}
}
use of com.qcadoo.view.api.components.AwesomeDynamicListComponent in project mes by qcadoo.
the class ProductsToIssueDetailsHooks method fillUnits.
public void fillUnits(final ViewDefinitionState view) {
AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues");
for (FormComponent form : adl.getFormComponents()) {
Entity issue = form.getPersistedEntityWithIncludedFormValues();
Entity product = issue.getBelongsToField(IssueFields.PRODUCT);
if (Objects.nonNull(product)) {
FieldComponent unitField = form.findFieldComponentByName(ProductFields.UNIT);
FieldComponent additionalUnitField = form.findFieldComponentByName(ProductFields.ADDITIONAL_UNIT);
unitField.setFieldValue(product.getStringField(ProductFields.UNIT));
String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
if (StringUtils.isEmpty(additionalUnit)) {
additionalUnitField.setFieldValue(product.getStringField(ProductFields.UNIT));
} else {
additionalUnitField.setFieldValue(additionalUnit);
}
}
}
}
use of com.qcadoo.view.api.components.AwesomeDynamicListComponent in project mes by qcadoo.
the class ProductToIssueCorrectionDetailsListeners method correct.
public void correct(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity helper = form.getPersistedEntityWithIncludedFormValues();
Entity locationTo = helper.getBelongsToField("locationTo");
if (locationTo == null) {
FieldComponent locationToField = (FieldComponent) view.getComponentByReference("locationTo");
locationToField.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.error.locationToRequired", ComponentState.MessageType.FAILURE);
return;
}
List<Entity> corrections = helper.getHasManyField("corrections");
List<Entity> savedCorrections = Lists.newArrayList();
corrections.forEach(correction -> savedCorrections.add(correction.getDataDefinition().save(correction)));
helper.setField("corrections", savedCorrections);
form.setEntity(helper);
if (savedCorrections.stream().anyMatch(correction -> !correction.isValid())) {
AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("corrections");
for (FormComponent formComponent : adl.getFormComponents()) {
Entity formEntity = formComponent.getEntity();
formEntity.getErrors().forEach((field, errorMessage) -> {
FieldComponent fieldComponent = formComponent.findFieldComponentByName(field);
fieldComponent.addMessage(errorMessage);
});
}
view.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.error", ComponentState.MessageType.FAILURE);
} else {
try {
List<Entity> newWarehouseIssues = productToIssueCorrectionService.correctProductsToIssue(helper, savedCorrections);
helper.setField("corrections", savedCorrections);
form.setEntity(helper);
form.setFormEnabled(false);
view.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.success", ComponentState.MessageType.SUCCESS, newWarehouseIssues.stream().map(issue -> issue.getStringField(WarehouseIssueFields.NUMBER)).collect(Collectors.joining(", ")));
afterSuccessfulCreateCorrectionsHooks(view, savedCorrections);
} catch (IllegalStateException e) {
view.addMessage("productFlowThruDivision.productToIssueCorrectionHelperDetails.correction.error.newWarehouseIssue", ComponentState.MessageType.FAILURE);
}
}
}
use of com.qcadoo.view.api.components.AwesomeDynamicListComponent in project mes by qcadoo.
the class ProductToIssueCorrectionDetailsListeners method additionalQuantityChanged.
public void additionalQuantityChanged(final ViewDefinitionState view, final ComponentState state, final String[] args) {
AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("corrections");
List<FormComponent> formComponenets = adl.getFormComponents();
for (FormComponent formComponent : formComponenets) {
FieldComponent additionalQuantityField = formComponent.findFieldComponentByName("correctionQuantityInAdditionalUnit");
Entity formEntity = formComponent.getPersistedEntityWithIncludedFormValues();
BigDecimal conversion = formEntity.getDecimalField(ProductToIssueCorrectionFields.CONVERSION);
FieldComponent quantity = formComponent.findFieldComponentByName("correctionQuantity");
if (additionalQuantityField.getUuid().equals(state.getUuid())) {
Either<Exception, com.google.common.base.Optional<BigDecimal>> maybeAdditionalQuantity = BigDecimalUtils.tryParse(additionalQuantityField.getFieldValue().toString(), LocaleContextHolder.getLocale());
if (conversion != null && maybeAdditionalQuantity.isRight() && maybeAdditionalQuantity.getRight().isPresent()) {
BigDecimal additionalQuantity = maybeAdditionalQuantity.getRight().get();
BigDecimal newQuantity = additionalQuantity.divide(conversion, numberService.getMathContext());
newQuantity = newQuantity.setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP);
quantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newQuantity, 0));
quantity.requestComponentUpdateState();
} else if (maybeAdditionalQuantity.isLeft()) {
additionalQuantityField.setFieldValue(quantity.getFieldValue());
additionalQuantityField.addMessage("productFlowThruDivision.productsToIssueHelperDetails.error.invalidQuantity", ComponentState.MessageType.FAILURE);
} else {
quantity.setFieldValue(null);
}
}
}
}
Aggregations