Esempio n. 1
0
    public void MoveMoneyForTomorrow()
    {
        DailyPool tomorrowPool = Get(this.DailyPoolType, AppSettings.ServerTime.AddDays(1).Date);

        tomorrowPool.SumAmount += this.SumAmount;
        tomorrowPool.Save();
        this.SumAmount = Money.Zero;
    }
Esempio n. 2
0
    /// <summary>
    /// Gets the pool basing on the type. If pool is not present in the DB, it is being created
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static DailyPool Get(int poolId, DateTime date)
    {
        var where = TableHelper.MakeDictionary("DailyPoolType", poolId);
        where.Add("DateDay", date.Date);

        var results = TableHelper.SelectRows <DailyPool>(where);

        if (results.Count > 0)
        {
            return(results[0]);
        }

        DailyPool NewPool = new DailyPool();

        NewPool.DailyPoolType = poolId;
        NewPool.SumAmount     = new Money(0);
        NewPool.DateDay       = date.Date;
        NewPool.Save();

        return(NewPool);
    }
    private static void DailyDistribution(bool HourDistribution = false, bool FinalDistributionButHourly = false)
    {
        DailyPool Pool = DailyPool.GetYesterdayPool(PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn));

        String RaportMessage    = String.Empty;
        Int32  ActiveAdPacks    = 0;
        Money  TotalDistributed = Money.Zero;
        Money  PerUnit          = Money.Zero;
        Money  InThePool        = Pool.SumAmount;

        using (var bridge = ParserPool.Acquire(Database.Client))
        {
            DistributionSQLHelper DistributionHelper = new DistributionSQLHelper(bridge.Instance);
            DistributionHelper.SetStartingDistributionPriority();
            ActiveAdPacks = DistributionHelper.GetSumOfActiveAdPacks();

            try
            {
                if (AppSettings.RevShare.AdPack.GroupPolicy == GroupPolicy.Classic)
                {
                    //Classic
                    //Nothing to change
                }
                if (AppSettings.RevShare.AdPack.GroupPolicy == GroupPolicy.CustomGroups ||
                    AppSettings.RevShare.AdPack.GroupPolicy == GroupPolicy.AutomaticAndCustomGroups)
                {
                    //CustomGrups
                    if (AppSettings.RevShare.AdPack.CustomReturnOption == CustomReturnOption.Accelerate)
                    {
                        DistributionHelper.UpdatePrioritiesCustomGroups();
                    }
                }
                if (AppSettings.RevShare.AdPack.GroupPolicy == GroupPolicy.AutomaticGroups ||
                    AppSettings.RevShare.AdPack.GroupPolicy == GroupPolicy.AutomaticAndCustomGroups)
                {
                    //AutomaticGroups
                    DistributionHelper.UpdatePrioritiesAutomaticGroups();
                }

                Decimal priorities = DistributionHelper.GetSumOfPriorities();

                if (ActiveAdPacks == 0)
                {
                    throw new MsgException("No active AdPacks with active members. " + GetNoDistributionMessage(HourDistribution));
                }

                //Make the distribution
                var adPackTypes = AdPackTypeManager.GetAllTypes();

                foreach (var adPackType in adPackTypes)
                {
                    var returnedPercentage = 0.0m;

                    if (AppSettings.RevShare.AdPack.DistributionPolicy == DistributionPolicy.Fixed)
                    {
                        PerUnit            = GetMoneyPerUnit(GetMoneyPerUnitFixed(adPackType), HourDistribution, FinalDistributionButHourly, adPackType);
                        returnedPercentage = adPackType.FixedDistributionValuePercent;
                    }
                    else if (AppSettings.RevShare.AdPack.DistributionPolicy == DistributionPolicy.Pools)
                    {
                        PerUnit            = GetMoneyPerUnit(GetMoneyPerUnitPools(InThePool, priorities), HourDistribution, FinalDistributionButHourly, adPackType);
                        returnedPercentage = PerUnit.ToDecimal() / adPackType.Price.ToDecimal();
                    }

                    RaportMessage += "<b>" + adPackType.Name + "</b> for priority 1.00 (no acceleration): <b>" + PerUnit.ToClearString() + "</b>. <br/>";

                    if (PerUnit > Money.Zero)
                    {
                        TotalDistributed += DistributionHelper.DistributeUsingPriority(PerUnit, adPackType.Id);
                    }

                    RevShareManager.AddAdPackTypePercentageHistory(adPackType.Id, returnedPercentage);
                }
                if (TitanFeatures.isAri)
                {
                    AriRevShareDistribution.CreditAriRevShareDistribution();
                }
            }
            catch (MsgException ex)
            {
                RaportMessage += ex.Message;
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }

            Pool.SumAmount -= TotalDistributed;

            if (HourDistribution == false)
            {
                if (AppSettings.RevShare.AdPack.DistributionPolicy == DistributionPolicy.Pools)
                {
                    RaportMessage += "Money moved to the next day pool: " + Pool.SumAmount.ToClearString() + ". ";
                }

                Pool.MoveMoneyForTomorrow();
            }

            Pool.Save();

            Report.Add(ActiveAdPacks, InThePool, TotalDistributed, RaportMessage);

            CustomGroupManager.TrySetGroupsAsExpired();
        }
    }