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();
                }
            }
        }
Exemple #2
0
        public static bool IsUserHaveActivePlan(Member user, out InvestmentUsersPlans planId)
        {
            planId = GetUserPlanId(user);

            return(planId != null ? true : false);
        }
Exemple #3
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);
            }
        }