public void Finish(bool isSave = true)
        {
            FinishDate = AppSettings.ServerTime;
            Status     = PlanStatus.Finished;

            if (!AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled)
            {
                var user         = Member.CurrentInCache;
                var crediter     = new InvestmentPlanCrediter(user);
                var platformPlan = new InvestmentPlatformPlan(PlanId);
                var note         = string.Format("Finished plan: {0}", platformPlan.Name);

                if (TitanFeatures.IsRetireYoung)
                {
                    crediter.CreditPlan(MoneyInSystem + platformPlan.Price, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformWithdrawal);
                }
                else
                {
                    crediter.CreditPlan(MoneyInSystem, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformWithdrawal);
                }

                //BONUS
                if (MoneyInSystem >= MoneyToReturn && LastWithdrawalDate == null)
                {
                    var bonus = platformPlan.EndBonus;

                    if (bonus > Money.Zero)
                    {
                        note = string.Format(U6010.BONUSFORFINISHEDPLAN, platformPlan.Name);
                        crediter.CreditPlan(bonus, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformWithdrawal);

                        var historyNote = string.Format("{0} ({1}/{2})", note, bonus.ToString(), RetireyoungManager.GetAggregate(user.Id));
                        History.AddEntry(user.Name, HistoryType.InvestmentPlatformBonus, historyNote);
                    }
                }

                MoneyInSystem = Money.Zero;
            }

            if (isSave)
            {
                Save();
            }
        }
        public void TryToWidthdrawlMoneyFromSystem(bool multipleTransfer = false)
        {
            var user = Member.CurrentInCache;

            if (AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled)
            {
                if (multipleTransfer)
                {
                    return;
                }
                else
                {
                    throw new MsgException(U6010.INVPLATFORMCANTTRANSFER);
                }
            }

            if (MoneyInSystem == Money.Zero)
            {
                if (multipleTransfer)
                {
                    return;
                }
                else
                {
                    throw new MsgException(U6010.INVPLATFORMNOTHINGTOTRANSFER);
                }
            }

            if (MoneyInSystem < user.Membership.InvestmentPlatformMinAmountToCredited)
            {
                if (multipleTransfer)
                {
                    return;
                }
                else
                {
                    throw new MsgException(U6006.MINAMOUNTTOPAYOUT + ": " + user.Membership.InvestmentPlatformMinAmountToCredited);
                }
            }


            var note     = string.Format("Widthdraw from {0}", new InvestmentPlatformPlan(PlanId).Name);
            var crediter = new InvestmentPlanCrediter(user);

            crediter.CreditPlan(MoneyInSystem, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformWithdrawal);

            MoneyInSystem      = Money.Zero;
            LastWithdrawalDate = AppSettings.ServerTime;
            Save();
        }
Exemple #3
0
        public static void CRON()
        {
            try
            {
                if (AppSettings.InvestmentPlatform.InvestmentPlatformEnabled)
                {
                    var activePlans = GetAllActivePlans();

                    foreach (var plan in activePlans)
                    {
                        var usersPlans = GetAllUsersActivePlans().FindAll(x => x.PlanId == plan.Id);

                        if (usersPlans.Count == 0 || plan.Roi == 0 || plan.Time == 0 || plan.Price == Money.Zero)
                        {
                            continue;
                        }

                        var note = plan.Name + " credit";

                        foreach (var userPlan in usersPlans)
                        {
                            if (userPlan.PurchaseDate.AddDays(plan.EarningDaysDelay) > DateTime.Now)
                            {
                                continue;
                            }

                            var dailyPool = userPlan.Price * plan.Roi / 100 / plan.Time;

                            //start
                            userPlan.TakeMoneyFromFinishedPlans();

                            userPlan.MoneyReturned += dailyPool;
                            userPlan.MoneyInSystem += dailyPool;

                            Member user = new Member(userPlan.UserId);

                            if (AppSettings.InvestmentPlatform.InvestmentPlatformCreditingPolicy == CreditingPolicy.Automatic && userPlan.MoneyInSystem > GetMembershipMinAmountToCredit(user))
                            {
                                Money creditAmount;

                                //Monthly check
                                if (userPlan.CurrentMonthPayout > DateTime.Now.Day * plan.DailyLimit)
                                {
                                    userPlan.CurrentMonthPayout = Money.Zero;
                                }

                                if (!AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled || userPlan.CurrentMonthPayout < plan.MonthlyLimit)
                                {
                                    if (AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled && userPlan.MoneyInSystem > plan.DailyLimit)
                                    {
                                        creditAmount            = plan.DailyLimit;
                                        userPlan.MoneyInSystem -= plan.DailyLimit;
                                    }
                                    else
                                    {
                                        creditAmount           = userPlan.MoneyInSystem;
                                        userPlan.MoneyInSystem = Money.Zero;
                                    }

                                    //Monthly limit
                                    var leftInMonth = plan.MonthlyLimit - userPlan.CurrentMonthPayout;
                                    if (AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled && creditAmount > leftInMonth)
                                    {
                                        userPlan.MoneyInSystem += (creditAmount - leftInMonth);
                                        creditAmount            = leftInMonth;
                                    }

                                    userPlan.CurrentMonthPayout += creditAmount;

                                    var crediter = new InvestmentPlanCrediter(user);
                                    crediter.CreditPlan(creditAmount, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformPlanCrediting);
                                    //TO DO AFTER ENABLE INVESTMENT BALANCE
                                    //if (AppSettings.InvestmentPlatform.CreditToInvestmentBalanceEnabled)
                                    //    user.AddToInvestmentBalance(creditAmount, note);
                                    //else
                                    //    user.AddToMainBalance(creditAmount, note);

                                    user.SaveBalances();
                                }
                            }

                            if (userPlan.MoneyReturned >= userPlan.MoneyToReturn)
                            {
                                var overPlus = userPlan.MoneyReturned - userPlan.MoneyToReturn;

                                userPlan.MoneyInSystem += overPlus;
                                userPlan.MoneyReturned  = userPlan.MoneyToReturn;
                                userPlan.Finish(false);
                            }
                            userPlan.Save();

                            string historyNote;
                            if (TitanFeatures.IsRetireYoung)
                            {
                                historyNote = string.Format("{0} ({1}/{2}) ", note, dailyPool.ToString(), RetireyoungManager.GetAggregate(user.Id));
                            }
                            else
                            {
                                historyNote = string.Format("{0}: {1}", note, dailyPool.ToString());
                            }
                            History.AddEntry(user.Name, HistoryType.InvestmentPlatformDailyCredit, historyNote);
                            //end
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLogger.Log(e);
            }
        }