private ParseUser GetAgent(Purchase purchase)
        {
            ParseUser agent = null;
            var teacher = new ParseUser();

            if (purchase.ClipKey != null)
            {
                teacher = purchase.ClipKey.Teacher;
            }

            if (purchase.BundleKey != null)
            {
                teacher = purchase.BundleKey.Teacher;
            }

            var userAdminData = teacher.GetPointerObject<UserAdminData>("adminData");
            if (userAdminData != null && userAdminData.Agent != null)
            {
                agent = userAdminData.Agent;
            }
            return agent;
        }
Esempio n. 2
0
        private static void InitPuchaseView(ParseUser loggedInUser, CheckoutViewModel checkoutViewModel)
        {
            var adminData = loggedInUser.GetPointerObject<UserAdminData>("adminData");
            adminData.PurchaseCount = 0;
            Task.Run(() => adminData.SaveAsync());

            checkoutViewModel.PaymentSuccess = true;
            checkoutViewModel.PurchasesForUser = new CheckoutPurchaseViewModel[0];
        }
        private UserAdminData GetTeacherAdminData(Purchase purchase)
        {
            var teacher = new ParseUser();

            if (purchase.ClipKey != null)
            {
                teacher = purchase.ClipKey.Teacher;
            }

            if (purchase.BundleKey != null)
            {
                teacher = purchase.BundleKey.Teacher;
            }
            return teacher.GetPointerObject<UserAdminData>("adminData");
        }
 private void SetPurchases(ParseRepository repository, ParseUser user)
 {
     var userPurchases = repository.FindUserPurchases(user.ObjectId);
     var userAdminData = user.GetPointerObject<UserAdminData>("adminData");
     userAdminData.PurchaseCount = userPurchases.Count(x => x.BundleKey != null || x.ClipKey != null);
     Task.Run(() => userAdminData.SaveAsync()).Wait();
 }
        private  AccountStatementDto TeacherAccountCreditStatement(CreateCouponViewModel createCouponVm, AccountStatementBuilder accountStatementBuilder, 
            double paymentTransaction, List<AccountStatementDto> accountStatements, ParseUser teacher, CurrencyRetriver currencyRetriever)
        {
            var currentCurrencyDto = currencyRetriever.GetCurrent();
            // add creding + debit record for teacher            
            var teacherAccountCreditStatement =  accountStatementBuilder.SetAccountStatement(
                teacher,
                paymentTransaction, 
                0,
                TransactionType.CouponBuyerPayment,
                DateTime.Now,
                currentCurrencyDto);

            var teacherAccountDebitStatement =  accountStatementBuilder.SetAccountStatement(
                teacher, 
                0,
                createCouponVm.TeacherData.GapToPay, 
                TransactionType.CouponBuyerDebit,
                DateTime.Now,
                currentCurrencyDto);

            createCouponVm.TeacherData.Balance = teacher.GetPointerObject<UserAdminData>("adminData").Balance;
            accountStatements.AddRange(new[]
            {
                teacherAccountCreditStatement,
                teacherAccountDebitStatement,
            });
            return teacherAccountCreditStatement;
        }
        private void SiteAccountCreditStatement(CreateCouponViewModel createCouponVm, AccountStatementBuilder accountStatementBuilder, double amountForSiteAccountCredit, List<AccountStatementDto> accountStatements, ParseUser siteAccount, CurrencyRetriver currencyRetriever)
        {
            var siteAccountCreditStatement =  accountStatementBuilder.SetAccountStatement(
                siteAccount,
                amountForSiteAccountCredit,
                0,
                TransactionType.CouponSiteCredit,
                DateTime.Now,
                currencyRetriever.GetCurrent());

            createCouponVm.SiteAccountBalance = siteAccount.GetPointerObject<UserAdminData>("adminData").Balance;
            accountStatements.Add(siteAccountCreditStatement);
        }
        private static void VatCreditStatement(CreateCouponViewModel createCouponVm, double maamPaymentCredit, AccountStatementBuilder accountStatementBuilder, List<AccountStatementDto> accountStatements, AccountStatementDto teacherAccountCreditStatement, double maam, double maamFromBalance, ParseUser maamAccount, ParseUser maamBalanceAccount, CurrencyRetriver currencyRetriever)
        {
            if (maamPaymentCredit > 0)
            {
                // add record for mamm account
                var maamAccountCreditStatement =  accountStatementBuilder.SetAccountStatement(
                   maamAccount,
                    maamPaymentCredit,
                    0,
                    TransactionType.CouponVatCredit,
                    DateTime.Now,
                    currencyRetriever.GetCurrent());
                
                accountStatements.Add(maamAccountCreditStatement);
                createCouponVm.MaamAccountBalance = maamAccount.GetPointerObject<UserAdminData>("adminData").Balance;
                if (teacherAccountCreditStatement != null)
                {
                    teacherAccountCreditStatement.IncludingVat = maam;
                }
            }

            if (maamFromBalance > 0)
            {
                // add record for mamm balance account מעמ יתרות
                var maamBalanceAccountCreditStatement =  accountStatementBuilder.SetAccountStatement(
                   maamBalanceAccount,
                    maamFromBalance,
                    0,
                    TransactionType.CouponVatCredit,
                    DateTime.Now,
                    currencyRetriever.GetCurrent());

                accountStatements.Add(maamBalanceAccountCreditStatement);
                createCouponVm.MaamBalanceAccountBalance = maamBalanceAccount.GetPointerObject<UserAdminData>("adminData").Balance;
            }
        }
        private void AgentCreditStatement(CreateCouponViewModel createCouponVm, IMyMentorRepository repository, ParseUser agentAccount, ParseUser teacher, ParseUser siteAccount, CommissionsDto globalCommissionsTable, AccountStatementBuilder accountStatementBuilder, List<AccountStatementDto> accountStatements, CurrencyRetriver currencyRetriever)
        {
            if (agentAccount == null)
            {
                //agent user not found ,send email
                //var missingAgent = teacher.GetPointerObject<UserAdminData>("adminData").GetPointerObject<ParseUser>("agent");
                SendErrorEmail(createCouponVm,MyMentorResources.couponErrAgentNotFound);
               // Mailer.SendAgentNotFound(missingAgent.Username,teacher.Username,createCouponVm.EventId);
                return;
            }

            var userAdminData = agentAccount.GetPointerObject<UserAdminData>("adminData");
            var acpAgentCommission = userAdminData.AcpTeacherCommission == Global.NoCommission ? 
                globalCommissionsTable.AgentCommission :
                userAdminData.AcpTeacherCommission;

            var agentSugOsek         = agentAccount.GetPointerObject<SugOsek>("sugOsek");
            var agentGetVat          = agentSugOsek.GetVat ? 1: 0;
            var agentPayVat          = agentSugOsek.PayVat ? 1 :0;
          
            var teacherSugOsek       = teacher.GetPointerObject<SugOsek>("sugOsek");
            var teacherPayVat        = teacherSugOsek.PayVat? 1: 0;            
            var maamFlag             = teacherPayVat == agentGetVat  ? 0 : 1;
            var teachertCurrency     = teacher.GetPointerObject<Currency>("currency").ConvertToCurrencyDto();
            var agentCurrency        = agentAccount.GetPointerObject<Currency>("currency").ConvertToCurrencyDto();
            var emlatHamaraFlag      = agentCurrency.ObjectId != teachertCurrency.ObjectId;
            var conversionCommission = globalCommissionsTable.ConversionCommission;
            var maam                 = globalCommissionsTable.Maam;
            var gapToPay             = createCouponVm.TeacherData.GapToPay;
            var totalCommission      = (gapToPay + (maamFlag * ((-gapToPay/(100 +maam)* maam * teacherPayVat)+(gapToPay*maam/100 *agentGetVat)))) * acpAgentCommission;            
            var agentIncludingVat    = agentSugOsek.GetVat ? maam : 0;
            double emlatHamara;
            
            // זיכוי סוכן
            var agentCreditAccountStatement = accountStatementBuilder.SetAccountStatement(
                agentAccount,
                totalCommission,
                0,
                TransactionType.CouponAgentCommission,
                DateTime.Now,
                currencyRetriever.GetCurrent(),
                includingVAT: agentIncludingVat);
            accountStatements.Add(agentCreditAccountStatement);
            createCouponVm.AgentBalance = agentAccount.GetPointerObject<UserAdminData>("adminData").Balance;

            // חיוב סוכן בעמלת המרה
            if (emlatHamaraFlag)
            {
                emlatHamara = totalCommission*conversionCommission;
                var agentDebitAccountStatement = accountStatementBuilder.SetAccountStatement(
                    agentAccount,
                    0,
                    emlatHamara,
                    TransactionType.CouponAgentExCommission,
                    DateTime.Now,
                    currencyRetriever.GetCurrent(),
                    includingVAT: agentIncludingVat);

                accountStatements.Add(agentDebitAccountStatement);
                createCouponVm.AgentBalance = agentAccount.GetPointerObject<UserAdminData>("adminData").Balance;
            }

            //חיוב האתר בעמלת הסוכן
            maamFlag = 0 == teacherPayVat ? 0 : 1;
            totalCommission = (gapToPay + (maamFlag * ((-gapToPay / (100 + maam) * maam * teacherPayVat) + (gapToPay * maam / 100 * 0)))) * acpAgentCommission;
            var siteAccountDebitStatement = accountStatementBuilder.SetAccountStatement(
                siteAccount,
                0,
                totalCommission,
                TransactionType.CouponAgentCommission,
                DateTime.Now,
                currencyRetriever.GetCurrent());
            accountStatements.Add(siteAccountDebitStatement);
            createCouponVm.SiteAccountBalance = siteAccount.GetPointerObject<UserAdminData>("adminData").Balance;

            if (emlatHamaraFlag)
            {
                //זיכוי האתר בעמלת המרה של הסוכן
                emlatHamara = totalCommission*conversionCommission;
                siteAccountDebitStatement = accountStatementBuilder.SetAccountStatement(
                    siteAccount,
                    emlatHamara,
                    0,
                    TransactionType.CouponAgentExCommission,
                    DateTime.Now,
                    currencyRetriever.GetCurrent());
                accountStatements.Add(siteAccountDebitStatement);
                createCouponVm.SiteAccountBalance = siteAccount.GetPointerObject<UserAdminData>("adminData").Balance; ;
            }
        }