示例#1
0
        /// <summary>
        /// Updates the payment summary for free trial company.
        /// </summary>
        /// <param name="companyId">The company identifier.</param>
        /// <param name="discountCodeUsage">The discount code usage.</param>
        /// <param name="isCompanySuspend">The is company suspend.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="dataContext">The data context.</param>
        public static void UpdatePaymentSummaryForFreeTrialCompany(int companyId, DiscountCodeUsage discountCodeUsage, bool?isCompanySuspend, int userId, StageBitzDB dataContext)
        {
            CompanyBL companyBL = new CompanyBL(dataContext);

            if (companyBL.IsFreeTrialStatusIncludedFortheDay(companyId, Utils.Today))
            {
                if (isCompanySuspend != null)
                {
                    CompanyPaymentSummary existingCompanyPackageSummary = GetCurrentCompanyPaymentSummary(companyId, dataContext);
                    if (existingCompanyPackageSummary != null)
                    {
                        existingCompanyPackageSummary.ShouldProcess   = !isCompanySuspend.Value;
                        existingCompanyPackageSummary.LastUpdatedDate = Utils.Today;
                        existingCompanyPackageSummary.LastUpdatedBy   = userId;
                    }
                }
                else
                {
                    FinanceBL             financeBL             = new FinanceBL(dataContext);
                    CompanyPaymentPackage companyPaymentPackage = financeBL.GetCurrentPaymentPackageFortheCompanyIncludingFreeTrial(companyId);

                    if (companyPaymentPackage != null)
                    {
                        PaymentSummaryDetails paymentSummaryDetails = new PaymentSummaryDetails()
                        {
                            CompanyPaymentPackage = companyPaymentPackage,
                            CompanyId             = companyId,
                            ShouldProcess         = true,
                            UserId                        = userId,
                            PackageStartDate              = companyPaymentPackage.StartDate,
                            PaymentMethodCodeId           = companyPaymentPackage.PaymentMethodCodeId,
                            HasPackageChanged             = false,
                            ProjectPaymentPackageTypeId   = companyPaymentPackage.ProjectPaymentPackageTypeId,
                            InventoryPaymentPackageTypeId = companyPaymentPackage.InventoryPaymentPackageTypeId,
                            IsEducationPackage            = companyPaymentPackage.IsEducationalPackage,
                            PaymentDurationTypeCodeId     = companyPaymentPackage.PaymentDurationCodeId,
                        };

                        if (!companyPaymentPackage.IsEducationalPackage) //we should only include the discound usage to summary if the company is not educational
                        {
                            paymentSummaryDetails.DiscountCodeUsageToApply = discountCodeUsage;
                        }

                        CreateCompanyPaymentSummaries(paymentSummaryDetails, Utils.Today, dataContext);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Creates the company payment summaries.
        /// This method will be called when a user selects/upgrades/downgrades a pricing plan . Also when the payment cycle ends Daily agent will call it for the repeat payments
        /// </summary>
        /// <param name="paymentSummaryDetail">The payment summary detail.</param>
        /// <param name="dateToConsider">The date to consider.</param>
        /// <param name="dataContext">The data context.</param>
        public static void CreateCompanyPaymentSummaries(PaymentSummaryDetails paymentSummaryDetail, DateTime dateToConsider, StageBitzDB dataContext)
        {
            CompanyBL             companyBL = new CompanyBL(dataContext);
            CompanyPaymentSummary existingCompanyPackageSummary = GetCurrentCompanyPaymentSummary(paymentSummaryDetail.CompanyId, dataContext);

            List <CompanyPaymentSummary> paymentPackageSummaries = GetPaymentPackageSummaries(paymentSummaryDetail, dateToConsider, dataContext);

            if (paymentPackageSummaries.Count > 0)
            {
                //check whether there is an upgrade/downgrade during the freetrial
                if (existingCompanyPackageSummary != null && companyBL.IsFreeTrialStatusIncludedFortheDay(paymentSummaryDetail.CompanyId, dateToConsider))
                {
                    dataContext.CompanyPaymentSummaries.DeleteObject(existingCompanyPackageSummary);
                }

                foreach (CompanyPaymentSummary companyPaymentSummary in paymentPackageSummaries)
                {
                    dataContext.CompanyPaymentSummaries.AddObject(companyPaymentSummary);
                }
            }

            //TODO - for invoice option we need to send an email to SB admin (Invoice Request) Repeat Payment Email
        }
示例#3
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        public void LoadData()
        {
            if (CompanyId > 0)
            {
                Data.Company company = this.GetBL <CompanyBL>().GetCompany(CompanyId);
                CompanyStatusHandler.CompanyWarningInfo warningInfo = CompanyStatusHandler.GetCompanyWarningStatus(CompanyId, company.CompanyStatusCodeId, company.ExpirationDate);
                if (warningInfo.WarningStatus == CompanyStatusHandler.CompanyWarningStatus.NoWarning)
                {
                    var                   globalizationSection  = WebConfigurationManager.GetSection("system.web/globalization") as GlobalizationSection;
                    int                   anualDurationCodeId   = (int)Utils.GetCodeIdByCodeValue("PaymentPackageDuration", "ANUAL");
                    int                   monthlyDurationCodeId = Utils.GetCodeIdByCodeValue("PaymentPackageDuration", "MONTHLY");
                    CompanyBL             companyBL             = new CompanyBL(DataContext);
                    CompanyPaymentPackage oldPackage            = this.GetBL <FinanceBL>().GetCurrentPaymentPackageFortheCompanyIncludingFreeTrial(CompanyId);

                    if (!((companyBL.IsFreeTrialStatusIncludedFortheDay(CompanyId, Utils.Today)) || oldPackage == null))  //free trial scenario and first time configuration. In this case no banners to display.
                    {
                        //comming from a popup. Refer PBI 14218.If user changes from yearly->monthly and downgrading or upgrading we should display banners in AC2,AC3.5. Else if it is a downgrade, display the banner in AC 3.4. If it is just an option change or upgrade with option change, then display banner in AC1.
                        if (PricePlanDetails != null)
                        {
                            divNotifyFutureRequest.Style.Add("Width", Width.ToString() + "px");

                            #region Calculations

                            int      durationDifference = this.GetBL <FinanceBL>().GetDurationDifference(oldPackage.StartDate, Utils.Today, oldPackage.PaymentDurationCodeId);
                            DateTime endDate            = Utils.Today;
                            DateTime newBillingDate     = Utils.Today;
                            DateTime virtualBillingDate = Utils.Today;
                            string   newOption          = PricePlanDetails.PaymentDurationCodeId == (int)Utils.GetCodeIdByCodeValue("PaymentPackageDuration", "ANUAL") ? "yearly" : "monthly";
                            string   currentOption      = oldPackage.PaymentDurationCodeId == (int)Utils.GetCodeIdByCodeValue("PaymentPackageDuration", "ANUAL") ? "yearly" : "monthly";

                            //In order to find whether it is an upgrade or downgrade,
                            decimal newAmount = this.GetBL <FinanceBL>().CalculateALLPackageAmountsByPeriod(PricePlanDetails.ProjectPaymentPackageTypeId, PricePlanDetails.InventoryPaymentPackageTypeId, oldPackage.PaymentDurationCodeId);
                            decimal oldAmount = this.GetBL <FinanceBL>().CalculateALLPackageAmountsByPeriod(oldPackage.ProjectPaymentPackageTypeId, oldPackage.InventoryPaymentPackageTypeId, oldPackage.PaymentDurationCodeId);
                            int     dayToRun  = int.Parse(Utils.GetSystemValue("MonthlyFinanceProcessDay"));

                            if (oldPackage.PaymentDurationCodeId == anualDurationCodeId)
                            {
                                endDate = oldPackage.EndDate != null ? (DateTime)oldPackage.EndDate : (DateTime)oldPackage.StartDate.AddYears(durationDifference);

                                if (PricePlanDetails.PaymentDurationCodeId == monthlyDurationCodeId)
                                {
                                    virtualBillingDate = new DateTime(endDate.Year, endDate.Month, dayToRun);
                                    newBillingDate     = virtualBillingDate > endDate ? virtualBillingDate : virtualBillingDate.AddMonths(1);
                                }
                            }
                            else
                            {
                                endDate = oldPackage.EndDate != null ? (DateTime)oldPackage.EndDate : (DateTime)oldPackage.StartDate.AddMonths(durationDifference);

                                if (PricePlanDetails.PaymentDurationCodeId == anualDurationCodeId)
                                {
                                    virtualBillingDate = new DateTime(endDate.Year, endDate.Month, dayToRun);
                                    newBillingDate     = virtualBillingDate > endDate ? virtualBillingDate : virtualBillingDate.AddMonths(1);
                                }
                            }

                            #endregion Calculations

                            #region creating banners

                            if (endDate == Utils.Today)
                            {
                                pnlNotifyFutureRequest.Visible = false;
                            }
                            else if (PricePlanDetails.PaymentDurationCodeId != oldPackage.PaymentDurationCodeId) //Duration change
                            {
                                string displayText = string.Empty;
                                if (PricePlanDetails.PaymentDurationCodeId == monthlyDurationCodeId && newAmount != oldAmount)
                                {
                                    if (newAmount < oldAmount)  //downgrade yearly->monthly
                                    {
                                        displayText = string.Format("<b>A little note on downgrades…</b> We’re glad you’ve found the levels that are right for you in StageBitz, but we do need to let you know that we can’t offer refunds, as Yearly subscriptions are paid in advance. " +
                                                                    "You’re currently paid up until {0}. Your choice will be effective immediately so if you would like to continue to enjoy the higher subscription level until that date please downgrade later." +
                                                                    " After that, we’ll change your billing to the lower level you’ve chosen. Your {1} charges will start on {2}.", Utils.FormatDate(endDate), newOption, Utils.FormatDate(newBillingDate));
                                    }
                                    else if (newAmount > oldAmount)  //upgrade yearly->monthly
                                    {
                                        PaymentSummaryDetails paymentSummaryDetail = this.GetBL <FinanceBL>().GetPaymentSummaryDetailRecord(PricePlanDetails, true);
                                        int     totalDays     = (int)(endDate - Utils.Today).TotalDays;
                                        decimal prorataAmount = ProjectUsageHandler.GetProrataAmount(paymentSummaryDetail, oldPackage, this.GetBL <FinanceBL>().GetLatestDiscountCodeUsage(CompanyId), newAmount, oldAmount, endDate, totalDays);

                                        StringBuilder upgradeText = new StringBuilder();
                                        upgradeText.Append(string.Format("You have selected to upgrade your plan and pay {0}. ", newOption));
                                        if (prorataAmount > 0)
                                        {
                                            upgradeText.Append(string.Format("You will be charged a pro-rata amount of {0} for your upgrade. ", Utils.FormatCurrency(prorataAmount, globalizationSection.Culture)));
                                        }
                                        upgradeText.Append(string.Format("Your {0} charges will start on {1}.", newOption, Utils.FormatDate(newBillingDate)));
                                        displayText = upgradeText.ToString();
                                    }
                                }
                                else
                                {
                                    if (newAmount < oldAmount)//even for monthly->yearly downgrade we should display downgrade banner
                                    {
                                        displayText = string.Format("<b>A little note on downgrades…</b> We’re glad you’ve found the levels that are right for you in StageBitz, but we do need to let you know that we can’t offer refunds, as subscriptions are paid in advance. " +
                                                                    "You’re currently paid up until {0}. Your choice will be effective immediately so if you would like to continue to enjoy the higher subscription level until that date please downgrade later.", Utils.FormatDate(endDate));
                                    }
                                    else//only an option change (yearly->monthly or monthly->yearly).Even if it is a monthly->yearly upgrade we display this banner.
                                    {
                                        displayText = string.Format("You are currently paying {0}, but you have opted to pay {1} as of {2}.",
                                                                    currentOption, newOption, Utils.FormatDate(endDate));
                                    }
                                }
                                divNotifyFutureRequest.InnerHtml = displayText;
                                pnlNotifyFutureRequest.Visible   = true;
                            }
                            else
                            {
                                if (newAmount < oldAmount)  //downgrade only.
                                {
                                    string downgradeOnlyText = string.Format("<b>A little note on downgrades…</b> We’re glad you’ve found the levels that are right for you in StageBitz, but we do need to let you know that we can’t offer refunds, as subscriptions are paid in advance. " +
                                                                             "You’re currently paid up until {0}. Your choice will be effective immediately so if you would like to continue to enjoy the higher subscription level until that date please downgrade later.", Utils.FormatDate(endDate));
                                    divNotifyFutureRequest.InnerHtml = downgradeOnlyText;
                                    pnlNotifyFutureRequest.Visible   = true;
                                }
                                else
                                {
                                    pnlNotifyFutureRequest.Visible = false;
                                }
                            }

                            #endregion creating banners
                        }
                        else  //Comming from company billing or price plan page
                        {
                            CompanyPaymentPackage futurePackage = this.GetBL <FinanceBL>().GetLatestRequestForTheCompany(CompanyId);
                            DateTime newDurationStartDate       = Utils.Today;
                            if (futurePackage != null && oldPackage != null && futurePackage.PaymentDurationCodeId != oldPackage.PaymentDurationCodeId)
                            {
                                string currentPaymentDuration = string.Empty;
                                string newPaymentDuration     = string.Empty;
                                int    durationDifference     = this.GetBL <FinanceBL>().GetDurationDifference(oldPackage.StartDate, Utils.Today, oldPackage.PaymentDurationCodeId);

                                if (oldPackage.PaymentDurationCodeId == anualDurationCodeId)
                                {
                                    currentPaymentDuration = "yearly";
                                    newPaymentDuration     = "monthly";
                                    newDurationStartDate   = oldPackage.EndDate != null ? (DateTime)oldPackage.EndDate : (DateTime)oldPackage.StartDate.AddMonths(durationDifference);
                                }
                                else
                                {
                                    currentPaymentDuration = "monthly";
                                    newPaymentDuration     = "yearly";
                                    newDurationStartDate   = oldPackage.EndDate != null ? (DateTime)oldPackage.EndDate : (DateTime)oldPackage.StartDate.AddYears(durationDifference);
                                }
                                string optionChangedText = string.Format("You are currently paying {0}, but you have opted to pay {1} as of {2}.", currentPaymentDuration, newPaymentDuration, Utils.FormatDate(newDurationStartDate));
                                divNotifyFutureRequest.InnerHtml = optionChangedText;
                                pnlNotifyFutureRequest.Visible   = true;
                            }
                            else
                            {
                                pnlNotifyFutureRequest.Visible = false;
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.ApplicationException">You do not have administrator rights to view this page.</exception>
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check for permissions
            if (!IsPostBack)
            {
                if (!Support.IsCompanyAdministrator(CompanyId))
                {
                    throw new ApplicationException("You do not have administrator rights to view this page.");
                }

                string companyName = Support.GetCompanyNameById(CompanyId);

                lnkCreateNewProject.CompanyId = this.CompanyId;
                lnkCreateNewProject.LoadData();
                lnkFinancialHistory.HRef = string.Format("~/Company/CompanyFinanceHistory.aspx?companyid={0}", CompanyId);
                lnkCompanyInventory.HRef = string.Format("~/Inventory/CompanyInventory.aspx?companyid={0}", CompanyId);

                sbPackageLimitsValidation.CompanyId   = CompanyId;
                sbPackageLimitsValidation.DisplayMode = UserWeb.Controls.Company.PackageLimitsValidation.ViewMode.ReactivateProjects;
                sbPackageLimitsValidation.LoadData();

                bool isReadOnly = HasCompanySuspendedBySBAdmin || this.GetBL <CompanyBL>().IsCompanyPaymentFailed(CompanyId);
                spnCreateNewProject.Visible = !isReadOnly;
                LoadBreadCrumbs(companyName);

                gvProjects.DataBind();

                CompanyPaymentPackage currentPaymentPackage = this.GetBL <FinanceBL>().GetCurrentPaymentPackageFortheCompanyIncludingFreeTrial(CompanyId);
                if (currentPaymentPackage != null)
                {
                    int      anualDurationCodeId   = Utils.GetCodeIdByCodeValue("PaymentPackageDuration", "ANUAL");
                    int      monthlyDurationCodeId = Utils.GetCodeIdByCodeValue("PaymentPackageDuration", "MONTHLY");
                    DateTime newPackageStartDate   = Utils.Today;
                    string   period             = string.Empty;
                    int      durationDifference = this.GetBL <FinanceBL>().GetDurationDifference(currentPaymentPackage.StartDate, Utils.Today, currentPaymentPackage.PaymentDurationCodeId);

                    if (currentPaymentPackage.PaymentDurationCodeId == anualDurationCodeId)
                    {
                        period = "Yearly";
                        newPackageStartDate = currentPaymentPackage.EndDate != null ? (DateTime)currentPaymentPackage.EndDate : (DateTime)currentPaymentPackage.StartDate.AddYears(durationDifference);
                    }
                    else
                    {
                        period = "Monthly";
                        newPackageStartDate = currentPaymentPackage.EndDate != null ? (DateTime)currentPaymentPackage.EndDate : (DateTime)currentPaymentPackage.StartDate.AddMonths(durationDifference);
                    }
                    CompanyBL companyBL = new CompanyBL(DataContext);
                    if (companyBL.IsFreeTrialStatusIncludedFortheDay(CompanyId, Utils.Today))
                    {
                        newPackageStartDate = currentPaymentPackage.StartDate;
                    }

                    if (newPackageStartDate == Utils.Today)
                    {
                        if (currentPaymentPackage.PaymentDurationCodeId == anualDurationCodeId)
                        {
                            newPackageStartDate = newPackageStartDate.AddYears(1);
                        }
                        else
                        {
                            newPackageStartDate = newPackageStartDate.AddMonths(1);
                        }
                    }
                    lblRenewsOn.Text              = Utils.FormatDate(newPackageStartDate);
                    lblSubscriptionPeriod.Text    = period;
                    divSubscriptionPeriod.Visible = true;
                    divRenewsOn.Visible           = true;
                }
                else
                {
                    divSubscriptionPeriod.Visible = false;
                    divRenewsOn.Visible           = false;
                }
                setUpCreditCardDetails.CompanyId    = CompanyId;
                setUpCreditCardDetails.RelatedTable = "Company";
                setUpCreditCardDetails.DisplayMode  = SetupCreditCardDetails.ViewMode.CompanyBilling;
                Data.CreditCardToken creditCardToken = this.GetBL <FinanceBL>().GetCreditCardToken(CompanyId);
                SetUISettings(creditCardToken);
                planMonitor.CompanyId = CompanyId;

                sbCompanyWarningDisplay.CompanyID = CompanyId;
                sbCompanyWarningDisplay.LoadData();
                sbFutureRequestNotificationMessage.CompanyId = CompanyId;
                sbFutureRequestNotificationMessage.LoadData();

                ConfigureCompanyStatus();
            }
        }