Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
0
        private static void BuyPlan(Member user, PurchaseBalances targetBalance, InvestmentPlatformPlan plan, Money planDiff, Money targetPrice = null)
        {
            var price = planDiff == Money.Zero ? plan.Price : planDiff;
            var note  = string.Format("{0} purchase", plan.Name);

            if (targetPrice != null)
            {
                price = targetPrice;
            }

            //IF TARGET BALANCE != (AR || CASH) IT MEANS THAT WE BUY/UPGRADE FROM PAYMENT BUTTONS
            if (targetBalance == PurchaseBalances.Cash || targetBalance == PurchaseBalances.Purchase)
            {
                PurchaseOption.ChargeBalance(user, price, PurchaseOption.Features.InvestmentPlatform.ToString(), targetBalance, note, BalanceLogType.InvestmentPlatformPlanPurchase);
            }
            else
            {
                targetBalance = PurchaseBalances.PaymentProcessor;
            }

            if (AppSettings.InvestmentPlatform.LevelsEnabled)
            {
                InvestmentLevelsManager.CanUserDepositOnLevel(plan, user);
            }

            var userPlan = new InvestmentUsersPlans
            {
                PlanId             = plan.Id,
                UserId             = user.Id,
                Price              = price,
                Status             = PlanStatus.Active,
                BalanceBoughtType  = targetBalance,
                PurchaseDate       = DateTime.Now,
                MoneyReturned      = Money.Zero,
                MoneyToReturn      = Money.MultiplyPercent(price, plan.Roi),
                CurrentMonthPayout = Money.Zero
            };

            userPlan.Save();

            InvestmentLevelsManager.DepositOnLevel(plan, userPlan.Id, user);

            if (AppSettings.InvestmentPlatform.ProofsEnabled)
            {
                HtmlInvestmentProofGenerator proof;

                if (AppSettings.InvestmentPlatform.LevelsEnabled)
                {
                    proof = new HtmlInvestmentProofGenerator(InvestmentTicket.GetTicket(user.Id, userPlan.Id));
                }
                else
                {
                    proof = new HtmlInvestmentProofGenerator(userPlan);
                }

                proof.SendPdfViaEmail();
            }

            MatrixBase.TryAddMemberAndCredit(user, price, AdvertType.InvestmentPlan);

            InvestmentPlanCrediter Crediter = new InvestmentPlanCrediter(user);

            Crediter.CreditStructure(price);

            if (user.HasReferer)
            {
                TryToSpeedUpReferrer(user.ReferrerId, price, user.Name);

                Crediter.CreditReferer(price);
            }
        }