use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class ProductsToIssueDetailsHooks method fillQuantitiesInAdditionalUnit.
public void fillQuantitiesInAdditionalUnit(final ViewDefinitionState view) {
AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues");
for (FormComponent form : adl.getFormComponents()) {
Entity issue = form.getPersistedEntityWithIncludedFormValues();
FieldComponent quantityField = form.findFieldComponentByName("issueQuantity");
Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse(quantityField.getFieldValue().toString(), LocaleContextHolder.getLocale());
BigDecimal conversion = issue.getDecimalField(IssueFields.CONVERSION);
if (Objects.nonNull(conversion) && maybeQuantity.isRight() && maybeQuantity.getRight().isPresent()) {
Entity product = issue.getBelongsToField(IssueFields.PRODUCT);
String unit = product.getStringField(ProductFields.UNIT);
String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
BigDecimal issueQuantity = maybeQuantity.getRight().get();
BigDecimal issuedQuantityAdditionalUnit = calculationQuantityService.calculateAdditionalQuantity(issueQuantity, conversion, Optional.fromNullable(additionalUnit).or(unit));
issue.setField(IssueFields.ISSUE_QUANTITY_ADDITIONAL_UNIT, issuedQuantityAdditionalUnit);
form.setEntity(issue);
}
}
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class WarehouseIssueDetailHooks method processProductsToIssueMode.
private void processProductsToIssueMode(final ViewDefinitionState view) {
FieldComponent component = (FieldComponent) view.getComponentByReference(WarehouseIssueFields.PRODUCTS_TO_ISSUE_MODE);
if (!warehouseIssueParameterService.issueForOrder()) {
component.setVisible(false);
component.requestComponentUpdateState();
return;
}
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
if (view.isViewAfterRedirect() && Objects.isNull(form.getEntityId())) {
component.setFieldValue(warehouseIssueParameterService.getProductsToIssue().getStrValue());
}
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class ProductsToIssueDetailsListeners method onAdditionalDemandQuantityChange.
public void onAdditionalDemandQuantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity productToIssue = form.getPersistedEntityWithIncludedFormValues();
if (!checkIfDecimalFieldsCorrect(productToIssue, form)) {
return;
}
BigDecimal conversion = productToIssue.getDecimalField(ProductsToIssueFields.CONVERSION);
BigDecimal additionalDemandQuantity = productToIssue.getDecimalField(ProductsToIssueFields.ADDITIONAL_DEMAND_QUANTITY);
if (conversion != null && additionalDemandQuantity != null) {
FieldComponent demandQuantity = (FieldComponent) view.getComponentByReference(ProductsToIssueFields.DEMAND_QUANTITY);
Entity product = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT);
BigDecimal newDemandQuantity = calculationQuantityService.calculateQuantity(additionalDemandQuantity, conversion, product.getStringField(ProductFields.UNIT));
demandQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newDemandQuantity, 0));
demandQuantity.requestComponentUpdateState();
}
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class TOCDetailsHooksPFTD method onBeforeRender.
public void onBeforeRender(final ViewDefinitionState view) {
FormComponent tocForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
if (tocForm.getEntityId() == null) {
return;
}
Entity technology = tocForm.getPersistedEntityWithIncludedFormValues().getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
LookupComponent divisionLookupComponent = (LookupComponent) view.getComponentByReference("division");
divisionLookupComponent.setEnabled(!Range.ONE_DIVISION.getStringValue().equals(technology.getStringField(TechnologyFieldsPFTD.RANGE)));
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class TechnologyDetailsHooksPFTD method changeRibbonState.
private void changeRibbonState(final ViewDefinitionState view) {
FormComponent technologyForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Long technologyId = technologyForm.getEntityId();
if (Objects.isNull(technologyId)) {
return;
}
Entity technology = technologyForm.getPersistedEntityWithIncludedFormValues();
WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
RibbonGroup flow = window.getRibbon().getGroupByName(L_PRODUCTS_FLOW);
RibbonActionItem fillLocationsInComponents = flow.getItemByName(L_FILL_LOCATIONS_IN_COMPONENTS);
RibbonGroup modelCard = window.getRibbon().getGroupByName(MODEL_CARD);
RibbonGroup productionLines = window.getRibbon().getGroupByName(PRODUCTION_LINES);
RibbonActionItem addMultipleProductionLines = productionLines.getItemByName(ADD_MULTIPLE_PRODUCTION_LINES);
String state = technology.getStringField(TechnologyFields.STATE);
boolean isTemplateAccepted = technology.getBooleanField(TechnologyFields.IS_TEMPLATE_ACCEPTED);
fillLocationsInComponents.setEnabled(!isTemplateAccepted && TechnologyState.DRAFT.getStringValue().equals(state));
fillLocationsInComponents.requestUpdate(true);
addMultipleProductionLines.setEnabled(!isTemplateAccepted && TechnologyState.DRAFT.getStringValue().equals(state));
addMultipleProductionLines.requestUpdate(true);
if (Objects.nonNull(modelCard)) {
RibbonActionItem createModelCard = modelCard.getItemByName(CREATE_MODEL_CARD);
createModelCard.setEnabled(TechnologyState.CHECKED.getStringValue().equals(state) || TechnologyState.ACCEPTED.getStringValue().equals(state));
createModelCard.requestUpdate(true);
}
window.requestRibbonRender();
}
Aggregations