use of de.metas.pricing.PriceListVersionId in project metasfresh-webui-api by metasfresh.
the class BPartnerProductsProposalViewFactory method createRowsLoaderFromRecord.
@Override
protected ProductsProposalRowsLoader createRowsLoaderFromRecord(TableRecordReference recordRef) {
final IBPartnerDAO bpartnersRepo = Services.get(IBPartnerDAO.class);
final IPriceListDAO priceListsRepo = Services.get(IPriceListDAO.class);
recordRef.assertTableName(I_C_BPartner.Table_Name);
final BPartnerId bpartnerId = BPartnerId.ofRepoId(recordRef.getRecord_ID());
final Set<CountryId> countryIds = bpartnersRepo.retrieveBPartnerLocationCountryIds(bpartnerId);
if (countryIds.isEmpty()) {
throw new AdempiereException("@NotFound@ @C_BPartner_Location_ID@");
}
final I_C_BPartner bpartnerRecord = bpartnersRepo.getById(bpartnerId);
PricingSystemId pricingSystemId = null;
SOTrx soTrx = null;
if (bpartnerRecord.isCustomer()) {
pricingSystemId = PricingSystemId.ofRepoIdOrNull(bpartnerRecord.getM_PricingSystem_ID());
soTrx = SOTrx.SALES;
}
if (pricingSystemId == null && bpartnerRecord.isVendor()) {
pricingSystemId = PricingSystemId.ofRepoIdOrNull(bpartnerRecord.getPO_PricingSystem_ID());
soTrx = SOTrx.PURCHASE;
}
if (pricingSystemId == null) {
throw new AdempiereException("@NotFound@ @M_PricingSystem_ID@");
}
final ZonedDateTime today = SystemTime.asZonedDateTime();
final Set<PriceListVersionId> priceListVersionIds = priceListsRepo.retrievePriceListsCollectionByPricingSystemId(pricingSystemId).filterAndStreamIds(countryIds).map(priceListId -> priceListsRepo.retrievePriceListVersionId(priceListId, today)).collect(ImmutableSet.toImmutableSet());
return ProductsProposalRowsLoader.builder().bpartnerProductStatsService(bpartnerProductStatsService).priceListVersionIds(priceListVersionIds).bpartnerId(bpartnerId).soTrx(soTrx).build();
}
use of de.metas.pricing.PriceListVersionId in project metasfresh-webui-api by metasfresh.
the class ProductsProposalRowsLoader method extractProductProposalPrice.
private ProductProposalPrice extractProductProposalPrice(final I_M_ProductPrice record) {
final PriceListVersionId priceListVersionId = PriceListVersionId.ofRepoId(record.getM_PriceList_Version_ID());
final Amount priceListPrice = Amount.of(record.getPriceStd(), getCurrencyCode(priceListVersionId));
final ProductId productId = ProductId.ofRepoId(record.getM_Product_ID());
final ProductProposalCampaignPrice campaignPrice = campaignPriceProvider.getCampaignPrice(productId).orElse(null);
return ProductProposalPrice.builder().priceListPrice(priceListPrice).campaignPrice(campaignPrice).build();
}
use of de.metas.pricing.PriceListVersionId in project metasfresh-webui-api by metasfresh.
the class ProductLookupDescriptor method appendFilterByPriceList.
private void appendFilterByPriceList(@NonNull final StringBuilder sqlWhereClause, @NonNull final SqlParamsCollector sqlWhereClauseParams, @NonNull final LookupDataSourceContext evalCtx) {
final PriceListVersionId priceListVersionId = getPriceListVersionId(evalCtx);
if (priceListVersionId == null) {
return;
}
final IPriceListDAO priceListsRepo = Services.get(IPriceListDAO.class);
final List<PriceListVersionId> allPriceListVersionIds = priceListsRepo.getPriceListVersionIdsUpToBase(priceListVersionId, getEffectivePricingDate(evalCtx));
sqlWhereClause.append("\n AND EXISTS (").append("SELECT 1 FROM " + I_M_ProductPrice.Table_Name + " pp WHERE pp.M_Product_ID=p." + I_M_Product_Lookup_V.COLUMNNAME_M_Product_ID).append(" AND pp.").append(I_M_ProductPrice.COLUMNNAME_M_PriceList_Version_ID).append(" IN ").append(DB.buildSqlList(allPriceListVersionIds, sqlWhereClauseParams::collectAll)).append(" AND pp.IsActive=").append(sqlWhereClauseParams.placeholder(true)).append(")");
}
use of de.metas.pricing.PriceListVersionId in project metasfresh-webui-api by metasfresh.
the class BasePLVProductsProposalViewFactory method createView.
public final ProductsProposalView createView(@NonNull final ProductsProposalView parentView) {
final PriceListVersionId basePriceListVersionId = parentView.getBasePriceListVersionIdOrFail();
final ProductsProposalRowsData rowsData = ProductsProposalRowsLoader.builder().bpartnerProductStatsService(bpartnerProductStatsService).priceListVersionId(basePriceListVersionId).productIdsToExclude(parentView.getProductIds()).bpartnerId(parentView.getBpartnerId().orElse(null)).soTrx(parentView.getSoTrx()).build().load();
logger.debug("loaded ProductsProposalRowsData with size={} for basePriceListVersionId={}", basePriceListVersionId, rowsData.size());
final ProductsProposalView view = ProductsProposalView.builder().windowId(getWindowId()).rowsData(rowsData).processes(getRelatedProcessDescriptors()).initialViewId(parentView.getInitialViewId()).build();
put(view);
return view;
}
use of de.metas.pricing.PriceListVersionId in project metasfresh-webui-api by metasfresh.
the class ProductsProposalRowsLoader method load.
public ProductsProposalRowsData load() {
List<ProductsProposalRow> rows = loadRows();
logger.debug("loaded {} productsProposalRows for priceListVersionIds={}", rows.size(), priceListVersionIds);
rows = updateLastShipmentDays(rows);
final PriceListVersionId singlePriceListVersionId = priceListVersionIds.size() == 1 ? priceListVersionIds.iterator().next() : null;
final PriceListVersionId basePriceListVersionId;
if (singlePriceListVersionId != null) {
final ZonedDateTime datePromised = order == null ? SystemTime.asZonedDateTime() : order.getDatePromised();
basePriceListVersionId = priceListsRepo.getBasePriceListVersionIdForPricingCalculationOrNull(singlePriceListVersionId, datePromised);
logger.debug("singlePriceListVersionId={} and datePromised={}; -> basePriceListVersionId={}", PriceListVersionId.toRepoId(singlePriceListVersionId), datePromised, PriceListVersionId.toRepoId(basePriceListVersionId));
} else {
basePriceListVersionId = null;
}
//
final ViewHeaderPropertiesBuilder headerProperties = ViewHeaderProperties.builder();
if (order != null) {
logger.debug("order!=null; -> add bpartnerName={} to headerProperties", order.getBpartnerName());
headerProperties.entry(ViewHeaderProperty.builder().caption(msgBL.translatable("C_BPartner_ID")).value(order.getBpartnerName()).build());
}
return ProductsProposalRowsData.builder().nextRowIdSequence(nextRowIdSequence).campaignPriceProvider(campaignPriceProvider).singlePriceListVersionId(singlePriceListVersionId).basePriceListVersionId(basePriceListVersionId).order(order).bpartnerId(bpartnerId).soTrx(soTrx).headerProperties(headerProperties.build()).rows(rows).build();
}
Aggregations