Search in sources :

Example 1 with PriceListVersionId

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();
}
Also used : CountryId(de.metas.location.CountryId) IBPartnerDAO(de.metas.bpartner.service.IBPartnerDAO) ViewFactory(de.metas.ui.web.view.ViewFactory) ZonedDateTime(java.time.ZonedDateTime) PriceListVersionId(de.metas.pricing.PriceListVersionId) ImmutableList(com.google.common.collect.ImmutableList) BPartnerProductStatsService(de.metas.bpartner.product.stats.BPartnerProductStatsService) ViewLayout(de.metas.ui.web.view.descriptor.ViewLayout) ViewCloseAction(de.metas.ui.web.view.ViewCloseAction) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) I_C_BPartner(org.compiere.model.I_C_BPartner) CountryId(de.metas.location.CountryId) ImmutableSet(com.google.common.collect.ImmutableSet) WEBUI_BPartner_ProductsProposal_Launcher(de.metas.ui.web.order.products_proposal.process.WEBUI_BPartner_ProductsProposal_Launcher) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) RelatedProcessDescriptor(de.metas.process.RelatedProcessDescriptor) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) ProductsProposalRowsLoader(de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsLoader) Services(de.metas.util.Services) SOTrx(de.metas.lang.SOTrx) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList(de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList) BPartnerId(de.metas.bpartner.BPartnerId) ProductsProposalRow(de.metas.ui.web.order.products_proposal.model.ProductsProposalRow) PricingSystemId(de.metas.pricing.PricingSystemId) IPriceListDAO(de.metas.pricing.service.IPriceListDAO) WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion(de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion) SystemTime(de.metas.util.time.SystemTime) IPriceListDAO(de.metas.pricing.service.IPriceListDAO) SOTrx(de.metas.lang.SOTrx) PriceListVersionId(de.metas.pricing.PriceListVersionId) IBPartnerDAO(de.metas.bpartner.service.IBPartnerDAO) ZonedDateTime(java.time.ZonedDateTime) AdempiereException(org.adempiere.exceptions.AdempiereException) BPartnerId(de.metas.bpartner.BPartnerId) PricingSystemId(de.metas.pricing.PricingSystemId) I_C_BPartner(org.compiere.model.I_C_BPartner)

Example 2 with PriceListVersionId

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();
}
Also used : Amount(de.metas.currency.Amount) ProductId(de.metas.product.ProductId) HUPIItemProductId(de.metas.handlingunits.HUPIItemProductId) PriceListVersionId(de.metas.pricing.PriceListVersionId)

Example 3 with PriceListVersionId

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(")");
}
Also used : IPriceListDAO(de.metas.pricing.service.IPriceListDAO) PriceListVersionId(de.metas.pricing.PriceListVersionId)

Example 4 with PriceListVersionId

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;
}
Also used : ProductsProposalRowsData(de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsData) PriceListVersionId(de.metas.pricing.PriceListVersionId)

Example 5 with PriceListVersionId

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();
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ViewHeaderPropertiesBuilder(de.metas.ui.web.view.ViewHeaderProperties.ViewHeaderPropertiesBuilder) PriceListVersionId(de.metas.pricing.PriceListVersionId)

Aggregations

PriceListVersionId (de.metas.pricing.PriceListVersionId)6 ZonedDateTime (java.time.ZonedDateTime)3 BPartnerId (de.metas.bpartner.BPartnerId)2 IPriceListDAO (de.metas.pricing.service.IPriceListDAO)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 BPartnerProductStatsService (de.metas.bpartner.product.stats.BPartnerProductStatsService)1 IBPartnerDAO (de.metas.bpartner.service.IBPartnerDAO)1 Amount (de.metas.currency.Amount)1 HUPIItemProductId (de.metas.handlingunits.HUPIItemProductId)1 I_C_OrderLine (de.metas.handlingunits.model.I_C_OrderLine)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 SOTrx (de.metas.lang.SOTrx)1 CountryId (de.metas.location.CountryId)1 PriceListId (de.metas.pricing.PriceListId)1 PricingSystemId (de.metas.pricing.PricingSystemId)1 RelatedProcessDescriptor (de.metas.process.RelatedProcessDescriptor)1 ProductId (de.metas.product.ProductId)1 ProductsProposalRow (de.metas.ui.web.order.products_proposal.model.ProductsProposalRow)1 ProductsProposalRowsData (de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsData)1