Exemple #1
0
        private static decimal GetMRPFromTradeAgreement(SaleLineItem saleItem)
        {
            RetailTransaction transaction = saleItem.RetailTransaction as RetailTransaction;
            decimal           quantity    = transaction.SaleItems.Where(x => x.ItemId == saleItem.ItemId && !x.Voided).Sum(x => x.Quantity);

            if (quantity == decimal.Zero)
            {
                quantity = 1;
            }

            Price priceService = Price.InternalApplication.Services.Price as Price;

            if (priceService != null)
            {
                PriceResult result = priceService.GetActiveTradeAgreement(transaction, saleItem, quantity);

                return(result.IndiaMRP);
            }

            return(0);
        }
        /// <summary>
        /// This function searches a list of trade agreements (assumed to be sorted with lowest prices first).
        ///   It calculates the price for each trade agreement, returning the lowest amount, and optionally stopping
        ///   early if it encounters a trade agreement with SearchAgain=False.
        /// </summary>
        /// <param name="tradeAgreements">List of price agreements, sorted by Amount ascending</param>
        /// <param name="searchAgain">Out parameter indicating whether SearchAgain=False was hit</param>
        /// <returns>Best price agreement price for the given list of trade agreements</returns>
        private static PriceResult GetBestPriceAgreement(IEnumerable <DE.PriceDiscTable> tradeAgreements, out bool searchAgain)
        {
            bool isIndia = Functions.CountryRegion == SupportedCountryRegion.IN;

            Decimal price    = 0;
            Decimal indiaMRP = 0;

            searchAgain = true;
            foreach (var ta in tradeAgreements)
            {
                Decimal priceUnit    = (ta.PriceUnit != 0) ? ta.PriceUnit : 1;
                Decimal markup       = (ta.ShouldAllocateMarkup != 0) ? ta.Markup : 0;
                Decimal currentPrice = (ta.Amount / priceUnit) + markup;

                if ((price == 0M) || (currentPrice != 0M && price > currentPrice))
                {
                    price = currentPrice;

                    if (isIndia)
                    {
                        indiaMRP = ta.IndiaMRP;
                    }
                }

                if (ta.ShouldSearchAgain == 0)
                {
                    searchAgain = false;
                    break;
                }
            }

            PriceResult result = new PriceResult(price, PriceGroupIncludesTax.NotSpecified);

            if (isIndia)
            {
                result.IndiaMRP = indiaMRP;
            }

            return(result);
        }
        /// <summary>
        /// This function takes arguments (customer, item, currency, etc.) related to price (trade) agreement
        ///  as well as the set of currently enabled trade agreement types. It returns the best trade agreement
        ///  price for the given constraints.
        ///
        /// As in AX, the method searches for a price on the given item which has been given to a
        ///  customer, price group, or anyone (in given precedence order). If a price is found and marked as
        ///  SearchAgain=False, the search will terminate. Otherwise, search for lowest price will continue.
        ///
        /// To recap, the logic is that three searches are done for customer, price group, and all, each bracket
        ///   will return the lowest price it has for the constraints. If it has SearchAgain=True, then the search
        ///   for lowest price continues to the next bracket.
        /// </summary>
        /// <param name="args">Arguments for price agreement search</param>
        /// <param name="priceParameters">Set of enabled price agreement types</param>
        /// <returns>Most applicable price for the given price agreement constraints.</returns>
        public static PriceResult priceAgr(PriceAgreementArgs args, PriceParameters priceParameters)
        {
            PriceResult priceResult = new PriceResult(0M, PriceGroupIncludesTax.NotSpecified);

            for (int idx = 0; idx < 9; idx++)
            {
                // Enum values for ItemCode/AccountCode:  0=Table, 1=Group, 2=All
                PriceDiscItemCode    itemCode    = (PriceDiscItemCode)(idx % 3);    //Mod divsion
                PriceDiscAccountCode accountCode = (PriceDiscAccountCode)(idx / 3); //three possible item-/account-Codes, as described in the ENUMs.

                if (priceParameters.IsRelationActive(accountCode, itemCode))
                {
                    IList <string> accountRelations = args.GetAccountRelations(accountCode);
                    string         itemRelation     = args.GetItemRelation(itemCode);

                    if (accountRelations.All(a => ValidRelation(accountCode, a)) &&
                        (ValidRelation(itemCode, itemRelation)))
                    {
                        bool        searchAgain;
                        PriceResult currentPriceResult = GetBestPriceAgreement(FindPriceAgreements(args, itemCode, accountCode), out searchAgain);

                        if (priceResult.Price == 0M ||
                            (currentPriceResult.Price > 0M && currentPriceResult.Price < priceResult.Price))
                        {
                            priceResult = currentPriceResult;
                        }

                        if (!searchAgain)
                        {
                            break;
                        }
                    }
                }
            }

            return(priceResult);
        }
Exemple #4
0
 /// <summary>
 /// Construct a new PriceResult object by converting an existing PriceResult from one currency to another.
 /// </summary>
 /// <param name="result">existing Price Result instance to be copied</param>
 /// <param name="fromCurrencyCode">currency to convert from</param>
 /// <param name="toCurrencyCode">currency to convert to</param>
 public PriceResult(PriceResult result, string fromCurrencyCode, string toCurrencyCode)
     : this(PriceService.Price.InternalApplication.Services.Currency.CurrencyToCurrency(fromCurrencyCode, toCurrencyCode, result.Price), result.IncludesTax)
 {
 }