예제 #1
0
        public static void DepositOnLevel(InvestmentPlatformPlan platformPlan, int userPlanId, Member user)
        {
            if (!LevelsEnabled)
            {
                return;
            }

            var ticket = AddNewTicket(platformPlan, user.Id, userPlanId);

            //We want to give users money only on every second deposit
            if (ticket.TicketNumber % 2 == 0)
            {
                var targetTicket  = GetFirstUnpaidTicketFromLevel(ticket.Level);
                var targetUser    = new Member(targetTicket.UserId);
                var targetPP      = platformPlan.PaymentProcessor;
                var payoutManager = new PayoutManager(targetUser, targetTicket.LevelEarnings, targetPP.ToString(), false, 0, string.Empty);

                if (payoutManager.TryMakeInvestmentLevelsPayout())
                {
                    targetTicket.Status = TicketStatus.Finished;
                    targetTicket.Save();

                    var targetPlan = new InvestmentUsersPlans(targetTicket.UserPlanId);
                    targetPlan.Finish();
                }
            }
        }
예제 #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();
            }
        }
예제 #3
0
        public static InvestmentTicket AddNewTicket(InvestmentPlatformPlan platformPlan, int userId, int userPlanId)
        {
            var ticket = new InvestmentTicket
            {
                UserPlanId    = userPlanId,
                UserId        = userId,
                Date          = AppSettings.ServerTime,
                Status        = TicketStatus.WaitingInQueue,
                LevelPrice    = platformPlan.Price,
                LevelFee      = platformPlan.LevelFee,
                LevelEarnings = platformPlan.Price * platformPlan.Roi / 100,
                Level         = platformPlan.Number,
                TicketNumber  = GetTicketNumber(platformPlan.Number)
            };

            ticket.Save();

            return(ticket);
        }
예제 #4
0
        public static List <InvestmentPlatformPlan> GetAllAvailablePlansForUser(int userId)
        {
            var query             = Membership.GetSqlQuerryForMembershipsIdListUnderCurrentMembership();
            var membershipIdsList = TableHelper.GetListFromRawQuery(query);
            var activeUserPlans   = GetUserActivePlans(userId);

            if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.UnlimitedPlans || activeUserPlans.Count == 0)
            {
                return(GetAllActivePlans().FindAll(x => membershipIdsList.Contains(x.RequiredMembershipId)));
            }

            //If PlansPolicy is OneUpgradedPlan users can't have more than 1 active plan!
            if (activeUserPlans.Count > 1)
            {
                throw new MsgException("Inconsistency of data!");
            }

            var plan = new InvestmentPlatformPlan(activeUserPlans[0].PlanId);

            return(GetAllActivePlans().FindAll(x => x.Number > plan.Number && membershipIdsList.Contains(x.RequiredMembershipId)));
        }
예제 #5
0
        public static bool CanUserDepositOnLevel(InvestmentPlatformPlan plan, Member user)
        {
            var timeDiff = AppSettings.InvestmentPlatform.MinimumTimeBetweenDeposits;

            if ((AppSettings.ServerTime - GetLastDepositDate(user.Id)).TotalMinutes <= timeDiff)
            {
                throw new MsgException(string.Format(U6012.MINIMUMTIMEBETWEENDEPOSITS, timeDiff));
            }

            var plansMaxCount = plan.LevelMaxDepositPerDay;

            if (GetTodaysDepositsOnLevel(plan.Number, user.Id) > plansMaxCount)
            {
                throw new MsgException(string.Format(U6012.MAXDAILYDEPOSITED, plansMaxCount));
            }

            if (!IsLevelAvailable(plan))
            {
                throw new MsgException(string.Format(U6013.LEVELNOTAVAILABLEYET, plan.AvailableFromDate));
            }

            return(true);
        }
예제 #6
0
 public static bool IsLevelAvailable(InvestmentPlatformPlan plan)
 {
     return(AppSettings.ServerTime >= plan.AvailableFromDate);
 }
예제 #7
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);
            }
        }
예제 #8
0
        public static void BuyOrUpgradePlan(Member user, PurchaseBalances targetBalance, InvestmentPlatformPlan newPlan, Money targetPrice = null)
        {
            var userActivePlans = GetUserActivePlans(user.Id);
            var moneyDiff       = Money.Zero;

            //UPGRADE
            if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan && userActivePlans.Count == 1)
            {
                var activePlan = userActivePlans[0];
                moneyDiff = newPlan.Price - new InvestmentPlatformPlan(activePlan.PlanId).Price;

                activePlan.Finish();
            }

            BuyPlan(user, targetBalance, newPlan, moneyDiff, targetPrice);
        }