Advertisement
Guest User

GetPromotions

a guest
Jan 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.17 KB | None | 0 0
  1. public PromotionCollection GetPromotionsForOrder()
  2.         {
  3.             //get an array of promotions that this order qualifies for
  4.  
  5.             if (Id <= 0)
  6.                 return new PromotionCollection();
  7.  
  8.             //only regular orders qualifies for promotions
  9.             if (OrderTypeId != OrderType.Regular)
  10.                 return new PromotionCollection();
  11.  
  12.             bool FirstOrderCondition = Order.ValidateOnlyForFirstOrderCondition(DistributorId);
  13.  
  14.             //load the order line items
  15.             OrderLineItemCollection coll = OrderLineItem.GetOrderLineItemsForOrder(Id);
  16.  
  17.             if (coll == null)
  18.                 return new PromotionCollection();
  19.  
  20.             PromotionCollection retVal = new PromotionCollection();
  21.             Single totalPVValue = 0;
  22.  
  23.             //first determine the totalPV - we need it for the promotions
  24.             foreach (OrderLineItem oli in coll)
  25.             {
  26.                 //add the total PV
  27.                 totalPVValue += oli.PVSubtotal;
  28.             }
  29.  
  30.             //get the list of currently running promotions in the country
  31.             PromotionCollection runningPromotions = Promotion.Promotion.GetRunningPromotionsInCountry(CountryId);
  32.  
  33.             foreach (Promotion.Promotion promo in runningPromotions)
  34.             {
  35.                 //if the requirements are passed or not
  36.                 bool isValid = true;
  37.  
  38.                 PromotionCondition promoCond = promo.ConditionDetails;
  39.  
  40.                 //if OnlyForFirstOrder is enforced
  41.                 if (promoCond.OnlyForFirstOrder == true)
  42.                     if (FirstOrderCondition == false)
  43.                         isValid = false;
  44.  
  45.                 //if the conditions are not met -> skip this promotion
  46.                 if (isValid == false)
  47.                     continue;
  48.  
  49.                 //if RulePerDistributor is enforced
  50.                 if (promoCond.RulePerDistributor > 0)
  51.                 {
  52.                     if (promo.PromotionConditionTypeId == PromotionConditionType.Place_the_n_order_of_X_PV_in_month)
  53.                     {
  54.                         if (Order.ValidateRulePerDistributorConditionInCurrentMonth(promo.Id, DistributorId, promoCond.RulePerDistributor) == false)
  55.                             isValid = false;
  56.                     }
  57.                     else
  58.                     {
  59.                         if (Order.ValidateRulePerDistributorCondition(promo.Id, DistributorId, promoCond.RulePerDistributor) == false)
  60.                             isValid = false;
  61.                     }
  62.                 }
  63.  
  64.                 //if the conditions are not met -> skip this promotion
  65.                 if (isValid == false)
  66.                     continue;
  67.  
  68.                 //if IsManagence is enforced
  69.                 if (promoCond.IsManagence == true)
  70.                     if (Order.ValidateMustBeManagenceCondition(DistributorId) == false)
  71.                         isValid = false;
  72.  
  73.                 //if the conditions are not met -> skip this promotion
  74.                 if (isValid == false)
  75.                     continue;
  76.  
  77.                 //if HasActiveSeneSite is enforced
  78.                 if (promoCond.HasActiveSeneSite == true)
  79.                     if (Order.ValidateMustHaveActiveSeneSiteCondition(DistributorId) == false)
  80.                         isValid = false;
  81.  
  82.                 //if the conditions are not met -> skip this promotion
  83.                 if (isValid == false)
  84.                     continue;
  85.  
  86.                 //if MinimumRank is enforced
  87.                 if (promoCond.MinimumRank > DistributorRank.None)
  88.                     if (Order.ValidateMinimumRankCondition(DistributorId, promoCond.MinimumRank) == false)
  89.                         isValid = false;
  90.  
  91.                 //if the conditions are not met -> skip this promotion
  92.                 if (isValid == false)
  93.                     continue;
  94.  
  95.                 //now validate the actual condition of the PromotionCondition
  96.                 if (promo.PromotionConditionTypeId == PromotionConditionType.Place_X_PV_Order)
  97.                 {
  98.                     //if the condition type is "Place X PV Order"
  99.                     if (totalPVValue < promoCond.ConditionValue)
  100.                         isValid = false;
  101.  
  102.                     //if we need to give her a free kit -> make sure she does not have one in any previous orders
  103.                     if (promo.ConditionDetails.OnlyForFirstOrder == true &&
  104.                         promo.PromotionItemTypeId == PromotionItemType.Receive_X_free_items)
  105.                     {
  106.                         Product.Product productDetails = Product.Product.GetProductById(promo.ItemDetails.ProductId);
  107.                         if (productDetails == null)
  108.                             continue;
  109.  
  110.                         if (productDetails.ItemNumber.ToUpper() == "MKS4010" ||
  111.                             productDetails.ItemNumber.ToUpper() == "MKS4013" ||
  112.                             productDetails.ItemNumber.ToUpper() == "MKS4020")
  113.                         {
  114.                             // if( Distributor.GetCountOfSeneCeuticalsForDistributor( DistributorId ) > 0 )
  115.                             continue;
  116.                         }
  117.                     }
  118.  
  119.                     //for these promotions we need to verify if they bought a SPF too
  120.                     if (promo.Id == 187)
  121.                     {
  122.                         bool hasSPF = false;
  123.  
  124.                         foreach (OrderLineItem oli in coll)
  125.                             if (oli.ItemNumber == "3385" && oli.Quantity > 0 && oli.PromotionId <= 0)
  126.                                 hasSPF = true;
  127.  
  128.                         if (hasSPF == false)
  129.                             isValid = false;
  130.                     }
  131.  
  132.                     if (promo.Id == 188 || promo.Id == 189 || promo.Id == 190 || promo.Id == 191 || promo.Id == 192)
  133.                     {
  134.                         bool hasKit = false;
  135.  
  136.                         foreach (OrderLineItem oli in coll)
  137.                             if (oli.ItemNumber == "4053" && oli.Quantity > 0 && oli.PromotionId <= 0)
  138.                                 hasKit = true;
  139.  
  140.                         if (hasKit == false)
  141.                             isValid = false;
  142.                     }
  143.                 }
  144.                 else if (promo.PromotionConditionTypeId == PromotionConditionType.Buy_X_of_an_item)
  145.                 {
  146.                     //if the condition type is "Buy X of an item"
  147.                     if (ValidateBuyXOfAnItemCondition(coll, promoCond.ProductId, promoCond.ConditionValue) == false)
  148.                         isValid = false;
  149.                 }
  150.                 else if (promo.PromotionConditionTypeId == PromotionConditionType.Place_the_n_order_of_X_PV_in_month)
  151.                 {
  152.                     //if the condition type is "Place the n-th order of X PV in a month"
  153.                     //if this order is at least X PV
  154.                     if (totalPVValue >= promoCond.ConditionValue)
  155.                     {
  156.                         if (ValidatePlaceNOrderOfXPVInAMonth(DistributorId, promoCond.ConditionValue, promoCond.MonthlyOrderNumber) == false)
  157.                             isValid = false;
  158.                     }
  159.                     else
  160.                         isValid = false;
  161.                 }
  162.                 else if (promo.PromotionConditionTypeId == PromotionConditionType.Place_XY_PV_order_within_period_after_buying_an_item)
  163.                 {
  164.                     //if the condition type is "Place [X-Y) PV order within a period of time after buying an item"
  165.                     //TODO
  166.                 }
  167.                 else
  168.                 {
  169.                     //unknown condition type -> do not qualify
  170.                     isValid = false;
  171.                 }
  172.  
  173.                 Product.Product productDetails2 = Product.Product.GetProductById(promo.ItemDetails.ProductId);
  174.  
  175.                 if (productDetails2.ItemNumber.ToUpper() == "MKS4025" ||
  176.                     productDetails2.ItemNumber.ToUpper() == "MKS4026" ||
  177.                     productDetails2.ItemNumber.ToUpper() == "MKS4027")
  178.                 {
  179.                     isValid = false;
  180.  
  181.                     if (DateTime.Now > new DateTime(2009, 2, 17, 0, 0, 0))
  182.                     {
  183.                         if (this.OrderTypeId == 1)
  184.                         {
  185.                             int DistributorshipLengthInDays = SenegenceDataAccess.BussinessObjects.Distributor.GetDistributorshipLengthInDays(DistributorId);
  186.                             Decimal TotalPVForLifeOfDistributor = SenegenceDataAccess.BussinessObjects.Distributor.GetTotalPVForLifeOfDistributor(DistributorId);
  187.  
  188.                             if (productDetails2.ItemNumber.ToUpper() == "MKS4025" && ((TotalPVForLifeOfDistributor + Convert.ToDecimal(totalPVValue)) >= 1000M) && DistributorshipLengthInDays <= 30)
  189.                             {
  190.                                 if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributor(DistributorId, "MKS4025") == 0)
  191.                                 {
  192.                                     isValid = true;
  193.                                 }
  194.                             }
  195.  
  196.                             if (productDetails2.ItemNumber.ToUpper() == "MKS4026" && ((TotalPVForLifeOfDistributor + Convert.ToDecimal(totalPVValue)) >= 2000M) && DistributorshipLengthInDays <= 60)
  197.                             {
  198.                                 if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributor(DistributorId, "MKS4026") == 0)
  199.                                 {
  200.                                     isValid = true;
  201.                                 }
  202.                             }
  203.  
  204.                             if (productDetails2.ItemNumber.ToUpper() == "MKS4027" && ((TotalPVForLifeOfDistributor + Convert.ToDecimal(totalPVValue)) >= 3000M) && DistributorshipLengthInDays <= 90)
  205.                             {
  206.                                 if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributor(DistributorId, "MKS4027") == 0)
  207.                                 {
  208.                                     isValid = true;
  209.                                 }
  210.                             }
  211.                         }
  212.                     }
  213.                     else
  214.                     {
  215.                         isValid = false;
  216.                     }
  217.                 }
  218.  
  219.                 Product.Product productDetails3 = Product.Product.GetProductById(promo.ItemDetails.ProductId);
  220.  
  221.                 if (productDetails3.ItemNumber.ToUpper() == "MKS2015G")
  222.                 {
  223.                     isValid = false;
  224.  
  225.                     if (IsSkuInOrder(Id, "MKS2015") != 0)
  226.                     {
  227.                         if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributorAfterDate(DistributorId, "MKS2015", "10/19/2009") == 0)
  228.                         {
  229.                             isValid = true;
  230.                         }
  231.                     }
  232.                 }
  233.  
  234.                 //if the requirements are passed -> add it
  235.                 if (isValid == true)
  236.                     retVal.Add(promo);
  237.             }
  238.  
  239.             return retVal;
  240.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement