use of com.qcadoo.view.api.components.GridComponent in project mes by qcadoo.
the class DeliveryDetailsListeners method showProduct.
public final void showProduct(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent orderedProductGrid = (GridComponent) view.getComponentByReference(DeliveryFields.ORDERED_PRODUCTS);
GridComponent deliveredProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.DELIVERED_PRODUCTS);
List<Entity> selectedEntities = orderedProductGrid.getSelectedEntities();
if (selectedEntities.isEmpty()) {
selectedEntities = deliveredProductsGrid.getSelectedEntities();
}
Entity selectedEntity = selectedEntities.iterator().next();
selectedEntity = selectedEntity.getDataDefinition().getMasterModelEntity(selectedEntity.getId());
Entity product = selectedEntity.getBelongsToField(L_PRODUCT);
Map<String, Object> parameters = Maps.newHashMap();
parameters.put("form.id", product.getId());
parameters.put(L_WINDOW_ACTIVE_MENU, "basic.products");
String url = "../page/basic/productDetails.html";
view.redirectTo(url, false, true, parameters);
}
use of com.qcadoo.view.api.components.GridComponent in project mes by qcadoo.
the class DeliveryDetailsListeners method changeStorageLocations.
public final void changeStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent deliveryForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
GridComponent deliveredProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.DELIVERED_PRODUCTS);
List<Entity> selectedProducts = deliveredProductsGrid.getSelectedEntities();
Set<Long> selectedProductsIds = deliveredProductsGrid.getSelectedEntitiesIds();
Entity delivery = deliveryForm.getPersistedEntityWithIncludedFormValues();
List<Entity> deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
for (Entity selectedProduct : selectedProducts) {
String palletNumber = selectedProduct.getStringField(DeliveredProductFields.PALLET_NUMBER);
if (Objects.nonNull(palletNumber)) {
List<Long> notSelectedMatchingProducts = deliveredProducts.stream().filter(deliveredProduct -> Objects.nonNull(deliveredProduct.getBelongsToField(DeliveredProductFields.PALLET_NUMBER)) && deliveredProduct.getBelongsToField(DeliveredProductFields.PALLET_NUMBER).getStringField(PalletNumberFields.NUMBER).equals(palletNumber)).map(Entity::getId).filter(deliveredProduct -> !selectedProductsIds.contains(deliveredProduct)).collect(Collectors.toList());
selectedProductsIds.addAll(notSelectedMatchingProducts);
}
}
String url = "../page/deliveries/changeStorageLocationHelper.html?context={\"form.deliveredProductIds\":\"" + selectedProductsIds.stream().map(Object::toString).collect(Collectors.joining(",")) + "\"," + "\"form.delivery\":\"" + delivery.getId() + "\"}";
view.openModal(url);
}
use of com.qcadoo.view.api.components.GridComponent in project mes by qcadoo.
the class DeliveryDetailsListeners method downloadProductAttachment.
public void downloadProductAttachment(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent deliveryForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
GridComponent orderedProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.ORDERED_PRODUCTS);
Set<Long> ids = orderedProductsGrid.getSelectedEntitiesIds();
SearchCriteriaBuilder searchCriteria = deliveriesService.getOrderedProductDD().find().createAlias(BasicConstants.MODEL_PRODUCT, BasicConstants.MODEL_PRODUCT, JoinType.INNER).createAlias(BasicConstants.MODEL_PRODUCT + L_DOT + ProductFields.PRODUCT_ATTACHMENTS, ProductFields.PRODUCT_ATTACHMENTS, JoinType.INNER).setProjection(SearchProjections.list().add(alias(field(ProductFields.PRODUCT_ATTACHMENTS + L_DOT + ProductAttachmentFields.ATTACHMENT), ProductAttachmentFields.ATTACHMENT)));
if (ids.isEmpty()) {
searchCriteria.createAlias(DeliveriesConstants.MODEL_DELIVERY, DeliveriesConstants.MODEL_DELIVERY, JoinType.INNER).add(SearchRestrictions.in(DeliveriesConstants.MODEL_DELIVERY + L_DOT + "id", deliveryForm.getEntityId()));
} else {
searchCriteria.add(SearchRestrictions.in("id", ids));
}
List<Entity> result = searchCriteria.list().getEntities();
if (result.isEmpty()) {
return;
}
List<File> attachments = result.stream().map(productAttachment -> new File(productAttachment.getStringField(ProductAttachmentFields.ATTACHMENT))).collect(Collectors.toList());
File zipFile;
try {
zipFile = fileService.compressToZipFile(attachments, false);
} catch (IOException e) {
LOG.error("Unable to compress documents to zip file.", e);
return;
}
view.redirectTo(fileService.getUrl(zipFile.getAbsolutePath()) + "?clean", true, false);
}
use of com.qcadoo.view.api.components.GridComponent in project mes by qcadoo.
the class DeliveryDetailsListeners method fillBasedOnPricesFromLastDeliveryOffer.
private void fillBasedOnPricesFromLastDeliveryOffer(final ViewDefinitionState view, final boolean deliveryUseNominalCostWhenPriceNotSpecified) {
GridComponent orderedProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.ORDERED_PRODUCTS);
FieldComponent currencyField = (FieldComponent) view.getComponentByReference(DeliveryFields.CURRENCY);
Long deliveryCurrencyId = (Long) currencyField.getFieldValue();
Entity plnCurrency = currencyService.getCurrencyByAlphabeticCode(CurrencyService.PLN);
List<Entity> orderedProducts = deliveriesService.getSelectedOrderedProducts(orderedProductsGrid);
List<Entity> productsToMessage = Lists.newArrayList();
orderedProducts.forEach(orderedProduct -> {
Entity product = orderedProduct.getBelongsToField(OrderedProductFields.PRODUCT);
Entity supplier = orderedProduct.getBelongsToField(OrderedProductFields.DELIVERY).getBelongsToField(DeliveryFields.SUPPLIER);
if (Objects.isNull(supplier)) {
if (deliveryUseNominalCostWhenPriceNotSpecified) {
Entity currency = product.getBelongsToField(ProductFieldsCNFP.NOMINAL_COST_CURRENCY);
BigDecimal pricePerUnit = getPricePerUnit(deliveryCurrencyId, plnCurrency, product, productsToMessage, currency, product.getDecimalField(ProductFieldsCNFP.NOMINAL_COST));
orderedProduct.setField(OrderedProductFields.PRICE_PER_UNIT, pricePerUnit);
orderedProduct.getDataDefinition().save(orderedProduct);
}
return;
}
Entity offerProduct = getLastOfferProduct(supplier, product);
if (Objects.nonNull(offerProduct)) {
Entity currency = currencyService.getCurrentCurrency();
BigDecimal pricePerUnit = getPricePerUnit(deliveryCurrencyId, plnCurrency, product, productsToMessage, currency, offerProduct.getDecimalField(OrderedProductFields.PRICE_PER_UNIT));
orderedProduct.setField(OrderedProductFields.PRICE_PER_UNIT, pricePerUnit);
orderedProduct.setField(L_OFFER, offerProduct.getBelongsToField(L_OFFER));
orderedProduct.getDataDefinition().save(orderedProduct);
} else if (deliveryUseNominalCostWhenPriceNotSpecified) {
Entity currency = product.getBelongsToField(ProductFieldsCNFP.NOMINAL_COST_CURRENCY);
BigDecimal pricePerUnit = getPricePerUnit(deliveryCurrencyId, plnCurrency, product, productsToMessage, currency, product.getDecimalField(ProductFieldsCNFP.NOMINAL_COST));
orderedProduct.setField(OrderedProductFields.PRICE_PER_UNIT, pricePerUnit);
orderedProduct.getDataDefinition().save(orderedProduct);
}
});
if (!productsToMessage.isEmpty()) {
view.addMessage("deliveries.orderedProducts.differentCurrencies", MessageType.INFO, false, productsToMessage.stream().map(e -> e.getStringField(ProductFields.NUMBER)).collect(Collectors.joining(", ")));
}
orderedProductsGrid.reloadEntities();
BigDecimal totalPrice = orderedProducts.stream().filter(orderedProduct -> Objects.nonNull(orderedProduct.getDecimalField(OrderedProductFields.TOTAL_PRICE))).map(orderedProduct -> orderedProduct.getDecimalField(OrderedProductFields.TOTAL_PRICE)).reduce(BigDecimal.ZERO, BigDecimal::add);
FieldComponent totalPriceComponent = (FieldComponent) view.getComponentByReference(L_ORDERED_PRODUCTS_CUMULATED_TOTAL_PRICE);
totalPriceComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(totalPrice, 0));
totalPriceComponent.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.GridComponent in project mes by qcadoo.
the class DeliveryDetailsListeners method fillBasedOnLastPurchasePrice.
private void fillBasedOnLastPurchasePrice(final ViewDefinitionState view, final boolean deliveryUseNominalCostWhenPriceNotSpecified) {
GridComponent orderedProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.ORDERED_PRODUCTS);
FieldComponent currencyField = (FieldComponent) view.getComponentByReference(DeliveryFields.CURRENCY);
Long deliveryCurrencyId = (Long) currencyField.getFieldValue();
Entity plnCurrency = currencyService.getCurrencyByAlphabeticCode(CurrencyService.PLN);
List<Entity> orderedProducts = deliveriesService.getSelectedOrderedProducts(orderedProductsGrid);
List<Entity> productsToMessage = Lists.newArrayList();
orderedProducts.forEach(orderedProduct -> {
Entity product = orderedProduct.getBelongsToField(OrderedProductFields.PRODUCT);
BigDecimal lastPurchaseCost = product.getDecimalField(ProductFieldsCNFP.LAST_PURCHASE_COST);
BigDecimal pricePerUnit;
if (BigDecimalUtils.convertNullToZero(lastPurchaseCost).compareTo(BigDecimal.ZERO) == 0 && deliveryUseNominalCostWhenPriceNotSpecified) {
Entity currency = product.getBelongsToField(ProductFieldsCNFP.NOMINAL_COST_CURRENCY);
pricePerUnit = getPricePerUnit(deliveryCurrencyId, plnCurrency, product, productsToMessage, currency, product.getDecimalField(ProductFieldsCNFP.NOMINAL_COST));
} else {
if (Objects.isNull(lastPurchaseCost)) {
orderedProduct.setField(OrderedProductFields.TOTAL_PRICE, null);
}
Entity currency = product.getBelongsToField(ProductFieldsCNFP.LAST_PURCHASE_COST_CURRENCY);
pricePerUnit = getPricePerUnit(deliveryCurrencyId, plnCurrency, product, productsToMessage, currency, lastPurchaseCost);
}
orderedProduct.setField(OrderedProductFields.PRICE_PER_UNIT, pricePerUnit);
orderedProduct.getDataDefinition().save(orderedProduct);
});
if (!productsToMessage.isEmpty()) {
view.addMessage("deliveries.orderedProducts.differentCurrencies", MessageType.INFO, false, productsToMessage.stream().map(e -> e.getStringField(ProductFields.NUMBER)).collect(Collectors.joining(", ")));
}
orderedProductsGrid.reloadEntities();
BigDecimal totalPrice = orderedProducts.stream().filter(orderedProduct -> Objects.nonNull(orderedProduct.getDecimalField(OrderedProductFields.TOTAL_PRICE))).map(orderedProduct -> orderedProduct.getDecimalField(OrderedProductFields.TOTAL_PRICE)).reduce(BigDecimal.ZERO, BigDecimal::add);
FieldComponent totalPriceComponent = (FieldComponent) view.getComponentByReference(L_ORDERED_PRODUCTS_CUMULATED_TOTAL_PRICE);
totalPriceComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(totalPrice, 0));
totalPriceComponent.requestComponentUpdateState();
}
Aggregations