Search in sources :

Example 1 with IPriceListDAO

use of de.metas.pricing.service.IPriceListDAO 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 IPriceListDAO

use of de.metas.pricing.service.IPriceListDAO 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)

Aggregations

PriceListVersionId (de.metas.pricing.PriceListVersionId)2 IPriceListDAO (de.metas.pricing.service.IPriceListDAO)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 BPartnerId (de.metas.bpartner.BPartnerId)1 BPartnerProductStatsService (de.metas.bpartner.product.stats.BPartnerProductStatsService)1 IBPartnerDAO (de.metas.bpartner.service.IBPartnerDAO)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 SOTrx (de.metas.lang.SOTrx)1 CountryId (de.metas.location.CountryId)1 PricingSystemId (de.metas.pricing.PricingSystemId)1 RelatedProcessDescriptor (de.metas.process.RelatedProcessDescriptor)1 ProductsProposalRow (de.metas.ui.web.order.products_proposal.model.ProductsProposalRow)1 ProductsProposalRowsLoader (de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsLoader)1 WEBUI_BPartner_ProductsProposal_Launcher (de.metas.ui.web.order.products_proposal.process.WEBUI_BPartner_ProductsProposal_Launcher)1 WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion (de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion)1 WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList (de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList)1 ViewCloseAction (de.metas.ui.web.view.ViewCloseAction)1 ViewFactory (de.metas.ui.web.view.ViewFactory)1 ViewLayout (de.metas.ui.web.view.descriptor.ViewLayout)1