use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class ResourcesListHooks method applyFilters.
public void applyFilters(ViewDefinitionState view) {
boolean isShortFilter = ((CheckBoxComponent) view.getComponentByReference(ResourceDtoFields.IS_SHORT_FILTER)).isChecked();
boolean isDeadlineFilter = ((CheckBoxComponent) view.getComponentByReference(ResourceDtoFields.IS_DEADLINE_FILTER)).isChecked();
GridComponent resourcesGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
Integer shortExpiryDate = dataDefinitionService.get(MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER, MaterialFlowResourcesConstants.MODEL_DOCUMENT_POSITION_PARAMETERS).find().setMaxResults(1).uniqueResult().getIntegerField(DocumentPositionParametersFields.SHORT_EXPIRY_DATE);
if (isShortFilter) {
if (shortExpiryDate == null) {
resourcesGrid.addMessage("materialFlowResources.resource.missing.parameter.shortExpiryDate.error", ComponentState.MessageType.FAILURE);
} else {
resourcesGrid.setCustomRestriction(searchBuilder -> searchBuilder.add(SearchRestrictions.and(SearchRestrictions.ge(ResourceDtoFields.EXPIRATION_DATE, DateTime.now().withTimeAtStartOfDay().toDate()), SearchRestrictions.le(ResourceDtoFields.EXPIRATION_DATE, DateTime.now().withTimeAtStartOfDay().plusDays(shortExpiryDate).toDate()))));
}
} else if (isDeadlineFilter) {
resourcesGrid.setCustomRestriction(searchBuilder -> searchBuilder.add(SearchRestrictions.lt(ResourceDtoFields.EXPIRATION_DATE, DateTime.now().withTimeAtStartOfDay().toDate())));
}
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class PalletStorageStateListHooks method applyFilters.
public void applyFilters(ViewDefinitionState view) {
boolean isShiftFilter = ((CheckBoxComponent) view.getComponentByReference(PalletStorageStateDtoFields.IS_SHIFT_FILTER)).isChecked();
boolean isFreeFilter = ((CheckBoxComponent) view.getComponentByReference(PalletStorageStateDtoFields.IS_FREE_FILTER)).isChecked();
GridComponent palletGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
Integer palletToShift = dataDefinitionService.get(MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER, MaterialFlowResourcesConstants.MODEL_DOCUMENT_POSITION_PARAMETERS).find().setMaxResults(1).uniqueResult().getIntegerField(DocumentPositionParametersItemValues.PALLET_TO_SHIFT);
Integer palletWithFreePlace = dataDefinitionService.get(MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER, MaterialFlowResourcesConstants.MODEL_DOCUMENT_POSITION_PARAMETERS).find().setMaxResults(1).uniqueResult().getIntegerField(DocumentPositionParametersItemValues.PALLET_WITH_FREE_PALECE);
if (isShiftFilter) {
if (palletToShift == null) {
palletGrid.addMessage("materialFlowResources.pallet.missing.parameter.palletToShift.error", ComponentState.MessageType.FAILURE);
} else {
palletGrid.setCustomRestriction(searchBuilder -> searchBuilder.add(SearchRestrictions.lt(PalletStorageStateDtoFields.TOTAL_QUANTITY, BigDecimal.valueOf(palletToShift))));
}
} else if (isFreeFilter) {
if (palletWithFreePlace == null) {
palletGrid.addMessage("materialFlowResources.pallet.missing.parameter.palletWithFreeSpace.error", ComponentState.MessageType.FAILURE);
} else {
palletGrid.setCustomRestriction(searchBuilder -> searchBuilder.add(SearchRestrictions.lt(PalletStorageStateDtoFields.TOTAL_QUANTITY, BigDecimal.valueOf(palletWithFreePlace))));
}
}
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class GenerateMaterialRequirementCoverageListeners method createDelivery.
/**
* createOffer event handler
*
* @param view
* @param state
* @param args
*/
public void createDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args) {
init();
GridComponent grid = (GridComponent) view.getComponentByReference(L_GRID);
Entity parameter = parameterService.getParameter();
Entity systemCurrency = parameter.getBelongsToField(ParameterFields.CURRENCY);
DataDefinition companyDataDefinition = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_COMPANY);
Map<Optional<Integer>, List<Entity>> groupedCoverageProducts = grid.getSelectedEntities().stream().collect(Collectors.groupingBy(e -> Optional.ofNullable(e.getIntegerField("companyId"))));
StringBuilder deliveryNumbers = new StringBuilder();
for (Map.Entry<Optional<Integer>, List<Entity>> entry : groupedCoverageProducts.entrySet()) {
String number = numberGeneratorService.generateNumber(DeliveriesConstants.PLUGIN_IDENTIFIER, DeliveriesConstants.MODEL_DELIVERY);
Entity delivery = deliveriesService.getDeliveryDD().create();
delivery.setField(NUMBER, number);
Entity currency = null;
if (entry.getKey().isPresent()) {
Entity supplier = companyDataDefinition.get(entry.getKey().get().longValue());
delivery.setField(SUPPLIER, supplier);
currency = supplier.getBelongsToField(CompanyFieldsD.CURRENCY);
}
if (currency == null) {
currency = systemCurrency;
}
delivery.setField(CURRENCY, currency);
delivery.setField(EXTERNAL_SYNCHRONIZED, true);
Entity saved = deliveriesService.getDeliveryDD().save(delivery);
if (saved.isValid()) {
deliveryNumbers.append("<br/>").append(number);
entry.getValue().forEach(coverageProduct -> {
Integer product = coverageProduct.getIntegerField("productId");
BigDecimal reserveMissingQuantity = coverageProduct.getDecimalField(CoverageProductFields.RESERVE_MISSING_QUANTITY);
BigDecimal orderedQuantity = reserveMissingQuantity.min(BigDecimal.ZERO).abs();
BigDecimal conversion = getConversion(product);
Entity orderedProduct = orderedProductDataDefinition.create();
orderedProduct.setField("delivery", saved);
orderedProduct.setField("product", product.longValue());
orderedProduct.setField("orderedQuantity", reserveMissingQuantity.min(BigDecimal.ZERO).abs());
orderedProduct.setField(OrderedProductFields.CONVERSION, conversion);
orderedProduct.setField(OrderedProductFields.ADDITIONAL_QUANTITY, orderedQuantity.multiply(conversion, numberService.getMathContext()));
orderedProductDataDefinition.save(orderedProduct);
});
}
if (parameter.getBooleanField(L_REQUIRE_SUPPLIER_IDENTIFICATION) && Objects.isNull(delivery.getBelongsToField(SUPPLIER))) {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.requireSupplierIdentification", MessageType.INFO, false);
}
}
if (StringUtils.isNoneEmpty(deliveryNumbers.toString())) {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.created", MessageType.SUCCESS, false, deliveryNumbers.toString());
} else {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.notCreated", MessageType.INFO, false);
}
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class GenerateMaterialRequirementCoverageListeners method showReplacementsAvailability.
public void showReplacementsAvailability(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent materialRequirementCoverageForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Long materialRequirementCoverageId = materialRequirementCoverageForm.getEntityId();
Entity materialRequirement = dataDefinitionService.get(OrderSuppliesConstants.PLUGIN_IDENTIFIER, OrderSuppliesConstants.MODEL_MATERIAL_REQUIREMENT_COVERAGE).get(materialRequirementCoverageId);
GridComponent grid = (GridComponent) view.getComponentByReference("coverageProducts");
Long cpId = grid.getSelectedEntitiesIds().stream().findFirst().get();
Entity cp = dataDefinitionService.get(OrderSuppliesConstants.PLUGIN_IDENTIFIER, OrderSuppliesConstants.MODEL_COVERAGE_PRODUCT).get(cpId);
Entity product = cp.getBelongsToField(CoverageProductFields.PRODUCT);
JSONObject json = new JSONObject();
try {
json.put("product.id", product.getId());
json.put("locationsIds", Lists.newArrayList(materialRequirement.getHasManyField(MaterialRequirementCoverageFields.COVERAGE_LOCATIONS).stream().map(cl -> cl.getBelongsToField(CoverageLocationFields.LOCATION).getId()).collect(Collectors.toList())));
} catch (JSONException e) {
throw new IllegalStateException(e);
}
String url = "/page/productFlowThruDivision/materialReplacementsAvailabilityList.html?context=" + json.toString();
view.redirectTo(url, false, true);
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class OrderPacksSingleOrderListListeners method printLabels.
public void printLabels(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
Set<Long> packsIds = grid.getSelectedEntitiesIds();
if (packsIds.isEmpty()) {
view.addMessage("orders.packs.notSelected", ComponentState.MessageType.INFO);
} else {
view.redirectTo("/orders/packsLabels.pdf?" + packsIds.stream().map(id -> "ids=" + id.toString()).collect(Collectors.joining("&")), true, false);
}
}
Aggregations