Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public PromotionCollection GetPromotionsForOrder()
- {
- //get an array of promotions that this order qualifies for
- if (Id <= 0)
- return new PromotionCollection();
- //only regular orders qualifies for promotions
- if (OrderTypeId != OrderType.Regular)
- return new PromotionCollection();
- bool FirstOrderCondition = Order.ValidateOnlyForFirstOrderCondition(DistributorId);
- //load the order line items
- OrderLineItemCollection coll = OrderLineItem.GetOrderLineItemsForOrder(Id);
- if (coll == null)
- return new PromotionCollection();
- PromotionCollection retVal = new PromotionCollection();
- Single totalPVValue = 0;
- //first determine the totalPV - we need it for the promotions
- foreach (OrderLineItem oli in coll)
- {
- //add the total PV
- totalPVValue += oli.PVSubtotal;
- }
- //get the list of currently running promotions in the country
- PromotionCollection runningPromotions = Promotion.Promotion.GetRunningPromotionsInCountry(CountryId);
- foreach (Promotion.Promotion promo in runningPromotions)
- {
- //if the requirements are passed or not
- bool isValid = true;
- PromotionCondition promoCond = promo.ConditionDetails;
- //if OnlyForFirstOrder is enforced
- if (promoCond.OnlyForFirstOrder == true)
- if (FirstOrderCondition == false)
- isValid = false;
- //if the conditions are not met -> skip this promotion
- if (isValid == false)
- continue;
- //if RulePerDistributor is enforced
- if (promoCond.RulePerDistributor > 0)
- {
- if (promo.PromotionConditionTypeId == PromotionConditionType.Place_the_n_order_of_X_PV_in_month)
- {
- if (Order.ValidateRulePerDistributorConditionInCurrentMonth(promo.Id, DistributorId, promoCond.RulePerDistributor) == false)
- isValid = false;
- }
- else
- {
- if (Order.ValidateRulePerDistributorCondition(promo.Id, DistributorId, promoCond.RulePerDistributor) == false)
- isValid = false;
- }
- }
- //if the conditions are not met -> skip this promotion
- if (isValid == false)
- continue;
- //if IsManagence is enforced
- if (promoCond.IsManagence == true)
- if (Order.ValidateMustBeManagenceCondition(DistributorId) == false)
- isValid = false;
- //if the conditions are not met -> skip this promotion
- if (isValid == false)
- continue;
- //if HasActiveSeneSite is enforced
- if (promoCond.HasActiveSeneSite == true)
- if (Order.ValidateMustHaveActiveSeneSiteCondition(DistributorId) == false)
- isValid = false;
- //if the conditions are not met -> skip this promotion
- if (isValid == false)
- continue;
- //if MinimumRank is enforced
- if (promoCond.MinimumRank > DistributorRank.None)
- if (Order.ValidateMinimumRankCondition(DistributorId, promoCond.MinimumRank) == false)
- isValid = false;
- //if the conditions are not met -> skip this promotion
- if (isValid == false)
- continue;
- //now validate the actual condition of the PromotionCondition
- if (promo.PromotionConditionTypeId == PromotionConditionType.Place_X_PV_Order)
- {
- //if the condition type is "Place X PV Order"
- if (totalPVValue < promoCond.ConditionValue)
- isValid = false;
- //if we need to give her a free kit -> make sure she does not have one in any previous orders
- if (promo.ConditionDetails.OnlyForFirstOrder == true &&
- promo.PromotionItemTypeId == PromotionItemType.Receive_X_free_items)
- {
- Product.Product productDetails = Product.Product.GetProductById(promo.ItemDetails.ProductId);
- if (productDetails == null)
- continue;
- if (productDetails.ItemNumber.ToUpper() == "MKS4010" ||
- productDetails.ItemNumber.ToUpper() == "MKS4013" ||
- productDetails.ItemNumber.ToUpper() == "MKS4020")
- {
- // if( Distributor.GetCountOfSeneCeuticalsForDistributor( DistributorId ) > 0 )
- continue;
- }
- }
- //for these promotions we need to verify if they bought a SPF too
- if (promo.Id == 187)
- {
- bool hasSPF = false;
- foreach (OrderLineItem oli in coll)
- if (oli.ItemNumber == "3385" && oli.Quantity > 0 && oli.PromotionId <= 0)
- hasSPF = true;
- if (hasSPF == false)
- isValid = false;
- }
- if (promo.Id == 188 || promo.Id == 189 || promo.Id == 190 || promo.Id == 191 || promo.Id == 192)
- {
- bool hasKit = false;
- foreach (OrderLineItem oli in coll)
- if (oli.ItemNumber == "4053" && oli.Quantity > 0 && oli.PromotionId <= 0)
- hasKit = true;
- if (hasKit == false)
- isValid = false;
- }
- }
- else if (promo.PromotionConditionTypeId == PromotionConditionType.Buy_X_of_an_item)
- {
- //if the condition type is "Buy X of an item"
- if (ValidateBuyXOfAnItemCondition(coll, promoCond.ProductId, promoCond.ConditionValue) == false)
- isValid = false;
- }
- else if (promo.PromotionConditionTypeId == PromotionConditionType.Place_the_n_order_of_X_PV_in_month)
- {
- //if the condition type is "Place the n-th order of X PV in a month"
- //if this order is at least X PV
- if (totalPVValue >= promoCond.ConditionValue)
- {
- if (ValidatePlaceNOrderOfXPVInAMonth(DistributorId, promoCond.ConditionValue, promoCond.MonthlyOrderNumber) == false)
- isValid = false;
- }
- else
- isValid = false;
- }
- else if (promo.PromotionConditionTypeId == PromotionConditionType.Place_XY_PV_order_within_period_after_buying_an_item)
- {
- //if the condition type is "Place [X-Y) PV order within a period of time after buying an item"
- //TODO
- }
- else
- {
- //unknown condition type -> do not qualify
- isValid = false;
- }
- Product.Product productDetails2 = Product.Product.GetProductById(promo.ItemDetails.ProductId);
- if (productDetails2.ItemNumber.ToUpper() == "MKS4025" ||
- productDetails2.ItemNumber.ToUpper() == "MKS4026" ||
- productDetails2.ItemNumber.ToUpper() == "MKS4027")
- {
- isValid = false;
- if (DateTime.Now > new DateTime(2009, 2, 17, 0, 0, 0))
- {
- if (this.OrderTypeId == 1)
- {
- int DistributorshipLengthInDays = SenegenceDataAccess.BussinessObjects.Distributor.GetDistributorshipLengthInDays(DistributorId);
- Decimal TotalPVForLifeOfDistributor = SenegenceDataAccess.BussinessObjects.Distributor.GetTotalPVForLifeOfDistributor(DistributorId);
- if (productDetails2.ItemNumber.ToUpper() == "MKS4025" && ((TotalPVForLifeOfDistributor + Convert.ToDecimal(totalPVValue)) >= 1000M) && DistributorshipLengthInDays <= 30)
- {
- if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributor(DistributorId, "MKS4025") == 0)
- {
- isValid = true;
- }
- }
- if (productDetails2.ItemNumber.ToUpper() == "MKS4026" && ((TotalPVForLifeOfDistributor + Convert.ToDecimal(totalPVValue)) >= 2000M) && DistributorshipLengthInDays <= 60)
- {
- if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributor(DistributorId, "MKS4026") == 0)
- {
- isValid = true;
- }
- }
- if (productDetails2.ItemNumber.ToUpper() == "MKS4027" && ((TotalPVForLifeOfDistributor + Convert.ToDecimal(totalPVValue)) >= 3000M) && DistributorshipLengthInDays <= 90)
- {
- if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributor(DistributorId, "MKS4027") == 0)
- {
- isValid = true;
- }
- }
- }
- }
- else
- {
- isValid = false;
- }
- }
- Product.Product productDetails3 = Product.Product.GetProductById(promo.ItemDetails.ProductId);
- if (productDetails3.ItemNumber.ToUpper() == "MKS2015G")
- {
- isValid = false;
- if (IsSkuInOrder(Id, "MKS2015") != 0)
- {
- if (SenegenceDataAccess.BussinessObjects.Distributor.GetQuantityOfSKUBoughtByDistributorAfterDate(DistributorId, "MKS2015", "10/19/2009") == 0)
- {
- isValid = true;
- }
- }
- }
- //if the requirements are passed -> add it
- if (isValid == true)
- retVal.Add(promo);
- }
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement