Esempio n. 1
0
            /// <summary>
            /// Gets the maximum retail price of the item.
            /// </summary>
            /// <returns>The maximum retail price of the item.</returns>
            private decimal GetItemMaxRetailPrice()
            {
                decimal   maxRetailPrice = decimal.Zero;
                SalesLine salesLine      = this.TaxableEntity as SalesLine;

                if (salesLine != null)
                {
                    // get maximum retail price from trade agreement
                    try
                    {
                        Customer customer = null;
                        if (!string.IsNullOrWhiteSpace(this.Transaction.CustomerId))
                        {
                            var getCustomerDataRequest  = new GetCustomerDataRequest(this.Transaction.CustomerId);
                            var getCustomerDataResponse = this.RequestContext.Execute <SingleEntityDataServiceResponse <Customer> >(getCustomerDataRequest);
                            customer = getCustomerDataResponse.Entity;
                        }

                        string priceGroup = customer != null ? customer.PriceGroup : string.Empty;
                        this.indiaPriceHelper = new IndiaPriceHelper(this.RequestContext.GetChannelConfiguration(), new PricingDataServiceManager(this.RequestContext), this.Transaction, priceGroup);
                    }
                    catch (ArgumentException)
                    {
                        maxRetailPrice = decimal.Zero;
                    }

                    if (this.indiaPriceHelper != null)
                    {
                        maxRetailPrice = this.indiaPriceHelper.GetMaximumRetailPriceFromTradeAgreement(salesLine, this.RequestContext);
                    }
                }

                if (maxRetailPrice == decimal.Zero)
                {
                    // No maximum retail price was defined in trade agreement, then use maximum retail price defined in item master.
                    GetItemMaxRetailPriceDataRequest dataRequest = new GetItemMaxRetailPriceDataRequest(this.TaxableEntity.ItemId);
                    dataRequest.QueryResultSettings = new QueryResultSettings(new ColumnSet("MAXIMUMRETAILPRICE_IN"), PagingInfo.AllRecords);
                    maxRetailPrice = this.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <ItemMaxRetailPriceIndia> >(dataRequest, this.RequestContext).Entity.MaximumRetailPrice;
                }

                return(maxRetailPrice);
            }
Esempio n. 2
0
            private static SingleEntityDataServiceResponse <ItemMaxRetailPriceIndia> GetItemMaxRetailPrice(GetItemMaxRetailPriceDataRequest request)
            {
                string         itemId  = request.ItemId;
                RequestContext context = request.RequestContext;

                ThrowIf.Null(itemId, "itemId");
                ThrowIf.Null(context, "context");
                ColumnSet columnSet = request.QueryResultSettings != null ? request.QueryResultSettings.ColumnSet : new ColumnSet();

                ItemL2CacheDataStoreAccessor level2CacheDataAccessor = GetCacheAccessor(context);

                bool found;
                bool updateL2Cache;
                ItemMaxRetailPriceIndia result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetItemMaxRetailPrice(itemId, columnSet), out found, out updateL2Cache);

                if (!found)
                {
                    var query = new SqlPagedQuery(QueryResultSettings.SingleRecord)
                    {
                        Select = columnSet,
                        From   = ItemsMaxRetailPricesIndiaViewName,
                        Where  = string.Format("{0} = {1} AND {2} = {3}", ItemIdColumnName, ItemIdVariableName, DataAreaIdColumnName, DataAreaIdVariableName),
                    };

                    query.Parameters[ItemIdVariableName]     = itemId;
                    query.Parameters[DataAreaIdVariableName] = context.GetChannelConfiguration().InventLocationDataAreaId;

                    using (DatabaseContext databaseContext = new DatabaseContext(context))
                    {
                        result = databaseContext.ReadEntity <ItemMaxRetailPriceIndia>(query).SingleOrDefault();
                    }

                    updateL2Cache &= result != null;
                }

                if (updateL2Cache)
                {
                    level2CacheDataAccessor.PutItemMaxRetailPrice(itemId, columnSet, result);
                }

                return(new SingleEntityDataServiceResponse <ItemMaxRetailPriceIndia>(result));
            }