Beispiel #1
0
        private async Task AddDealConditionMetAsync(int orderLineNumber, string conditionID)
        {
            try
            {
                this.LogDebug("== :AddDealConditionMet - Start: " + orderLineNumber + " => " + conditionID);

                // Use to get the DC header and later use it to get the type
                IList <string> conditionIDs = new List <string>()
                {
                    conditionID
                };

                if (!dealConditionsMetList.ContainsKey(conditionID))
                {
                    this.LogDebug("== :AddDealConditionMet before FindDealConditionHeader");

                    var result = await DealConditionDAL.FindDealConditionHeadersByDealConditionIDWithoutDateCheckAsync(conditionIDs).ConfigureAwait(false);

                    if (result != null)
                    {
                        if (result.Count > 0)
                        {
                            this.LogDebug("== :AddDealConditionMet result found - add then");

                            dealConditionsMetList.Add(conditionID, result[0]);
                        }
                    }
                }

                this.LogDebug("== :AddDealConditionMet add to lineItemConditionMet. ");

                if (!lineItemConditionMet.ContainsKey(orderLineNumber))
                {
                    lineItemConditionMet.Add(orderLineNumber, conditionID);
                }

                this.LogDebug("== :AddDealConditionMet Met Exit. ");
            }
            catch (Exception all)
            {
                this.LogDebug("== :AddDealConditionMet " + all.Message);
                this.LogError(all);
            }
        }
Beispiel #2
0
        /*
         * // this method is used for loading data asynchronously
         * public async override Task InitializeAsync()
         * {
         *  // load data from base InvoiceReport
         *  await base.InitializeAsync();
         * }
         */


        public async override Task <PricingResultEntity> PriceOrderAsync(VisitEntity visit, ActivityEntity activity, OrderEntity order, IList <OrderItemEntity> orderItems, IList <DocumentCondBO> conditions)
        {
            // init conditions met and message for every order been priced.
            WarningMessage = "Se han aplicado más de una promoción sobre los materiales:";
            warningMet     = false;

            if (dealConditionsMetList != null)
            {
                dealConditionsMetList.Clear();
                lineItemConditionMet.Clear();
            }
            else
            {
                dealConditionsMetList = new Dictionary <string, DealConditionHeaderBO>();
                lineItemConditionMet  = new Dictionary <int, string>();
            }

            // First add item level:
            if (conditions != null)
            {
                foreach (DocumentCondBO conditionBO in conditions)
                {
                    var item = orderItems.FirstOrDefault(it => it.DocumentItemNumber == conditionBO.ItemNumber);
                    if (item != null && item.ActualQuantity > 0)
                    {
                        this.LogDebug("* ZPricingManager:PriceOrderAsync:ConditionItemLevel " + conditionBO.ItemNumber + "-" + conditionBO.DealConditionNumber);
                        await AddDealConditionMetAsync(item.DocumentItemNumber, conditionBO.DealConditionNumber);
                    }
                }
            }

            if (orderItems != null)
            {
                // Then add conditions met because of free goods:
                foreach (OrderItemEntity orderItem in orderItems)
                {
                    if (orderItem.IsPromotionResult && orderItem.ActualQuantity > 0)
                    {
                        this.LogDebug("* ZPricingManager:PriceOrderAsync:PromotionResultFG " + orderItem.DocumentItemNumber + "-" + orderItem.PromotionNumber);
                        await AddDealConditionMetAsync(orderItem.DocumentItemNumber, orderItem.PromotionNumber);
                    }
                }


                // Now lets check preconditions
                IEnumerator <OrderItemEntity> itemEnum = orderItems.GetEnumerator();

                // VALIDATION: Check if multiple DC were met because of same material using preconditions
                try
                {
                    this.LogDebug("* ZPricingManager:Check Pre-conditions for DC");

                    if (itemEnum != null)
                    {
                        while (itemEnum.MoveNext())
                        {
                            OrderItemEntity currentItem = itemEnum.Current;
                            int             count       = 0; // count conditions met

                            if (!currentItem.IsPromotionResult && currentItem.ActualQuantity > 0)
                            {
                                this.LogDebug("* ZPricingManager:PriceOrderAsync:CheckPre-Cond. " + currentItem.DocumentItemNumber + "-" + currentItem.MaterialNumber);

                                foreach (string conditionID in dealConditionsMetList.Keys)
                                {
                                    // Get Preconditions for DC
                                    IList <DealConditionPreconditionBO> preConditions = await DealConditionDAL.FindDealConditionPreconditionsByDealConditionIDAsync(conditionID);

                                    if (preConditions.Count > 0)
                                    {
                                        foreach (DealConditionPreconditionBO preCondition in preConditions)
                                        {
                                            this.LogDebug("*** DC:PreCondMaterial " + preCondition.MaterialNumber);

                                            // Precondition material is the same as current item
                                            if (currentItem.MaterialNumber.Equals(preCondition.MaterialNumber))
                                            {
                                                await AddDealConditionMetAsync(currentItem.DocumentItemNumber, conditionID);

                                                count++;
                                            }
                                        }
                                    }
                                }


                                // A warning is present for current item don't procee more items
                                if (count > 1)
                                {
                                    this.LogDebug("*** :ERROR - Material met more than once in a DC pre-conditions");
                                    //throw new PricingException("No es permitido mas de una condición de ventas activa para el producto [" + currentItem.MaterialNumber + "]");
                                    WarningMessage = WarningMessage + "\n" + currentItem.MaterialNumber + " - (" + count + ")";
                                    warningMet     = true;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    if (itemEnum != null)
                    {
                        itemEnum.Dispose();
                    }
                }
            }

            return(await base.PriceOrderAsync(visit, activity, order, orderItems, conditions));
        }