/// <summary> /// Performs business logic actions specified for this task handler. /// </summary> protected override void PerformActions() { ClearTemporaryDocumentMedia(); DateTime dateToConsider = Utils.Today.Date; TimeSpan ts; if (TimeSpan.TryParse(Utils.GetSystemValue("AgentExecutionTime"), out ts)) { if (Utils.Now < (Utils.Today + ts)) { dateToConsider = dateToConsider.AddDays(-1); } } ProjectUsageHandler.CreatePaymentSummaries(dateToConsider); //Monthly retry process with in the Graceperiod ProjectFinanceHandler.ProcessInvoicesAndPayments(0, dateToConsider, false, 0); // Run CompanyStatusHandler and ProjectStatusHandler in same datacontext using (StageBitzDB dataContext = new StageBitzDB()) { ProjectStatusHandler.UpdateProjectExpirations(dateToConsider, dataContext); CompanyStatusHandler.UpdateCompanyExpirations(dateToConsider, dataContext); dataContext.SaveChanges(); } CompanyStatusHandler.SuspendNoPaymentOptionCompanies(dateToConsider); SendUserEmailNotifications(dateToConsider); SendBookingNotifications(); SendBookingOverdueAndDelayedEmails(dateToConsider.AddDays(1)); DeleteOldExportedZipFiles(); }
/// <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; } } } } } }
/// <summary> /// Loads the data. /// </summary> public void LoadData() { var company = GetBL <CompanyBL>().GetCompany(this.CompanyID); if (company == null) { return; } bool isCompanyAdmin = Support.IsCompanyAdministrator(CompanyID); User primaryAdmin = this.GetBL <CompanyBL>().GetCompanyPrimaryAdministrator(this.CompanyID); string primaryAdminName = string.Concat(primaryAdmin.FirstName, " ", primaryAdmin.LastName); string primaryAdminEmailUrl = string.Concat("mailto:", primaryAdmin.Email1); CompanyStatusHandler.CompanyWarningInfo warningInfo = CompanyStatusHandler.GetCompanyWarningStatus(CompanyID, company.CompanyStatusCodeId, company.ExpirationDate); if (warningInfo.WarningStatus == CompanyStatusHandler.CompanyWarningStatus.NoWarning) { noticesMultiView.Visible = false; } else { noticesMultiView.Visible = true; switch (warningInfo.WarningStatus) { case CompanyStatusHandler.CompanyWarningStatus.SBAdminSuspended: if (isCompanyAdmin) { noticesMultiView.ActiveViewIndex = (int)NoticeType.SBAdminSuspendedCompanyAdmin; lblCompanyNameSBAdminSuspendCA.Text = company.CompanyName; string feedbackEmail = Support.GetSystemValue("FeedbackEmail"); string feedbackEmailUrl = string.Concat("mailto:", feedbackEmail); lnkContactSBSupport.Text = feedbackEmail; lnkContactSBSupport.NavigateUrl = feedbackEmailUrl; } else { noticesMultiView.ActiveViewIndex = (int)NoticeType.SBAdminSuspendedNonCompanyAdmin; lblCompanyNameSBAdminSuspendNonCA.Text = company.CompanyName; if (primaryAdmin != null) { lnkPrimaryComapnyAdmin.Text = primaryAdminName; lnkPrimaryComapnyAdmin.NavigateUrl = primaryAdminEmailUrl; } } break; case CompanyStatusHandler.CompanyWarningStatus.PaymentFailed: if (isCompanyAdmin) { noticesMultiView.ActiveViewIndex = (int)NoticeType.PaymentFailedCompanyAdmin; ucCompanyPaymentFailedWarningPaymentFailedCompanyAdmin.CompanyID = CompanyID; ucCompanyPaymentFailedWarningPaymentFailedCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.CompanyAdministrator, CompanyPaymentFailedWarning.DisplayMode.PaymentFailed); } else { noticesMultiView.ActiveViewIndex = (int)NoticeType.PaymentFailedNonCompanyAdmin; ucCompanyPaymentFailedWarningPaymentFailedNonCompanyAdmin.CompanyID = CompanyID; ucCompanyPaymentFailedWarningPaymentFailedNonCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.NonCompanyAdministrator, CompanyPaymentFailedWarning.DisplayMode.PaymentFailed); } break; case CompanyStatusHandler.CompanyWarningStatus.PaymentFailedGracePeriod: if (isCompanyAdmin) { noticesMultiView.ActiveViewIndex = (int)NoticeType.GracePeriodCompanyAdmin; ucCompanyPaymentFailedWarningGracePeriodCompanyAdmin.CompanyID = CompanyID; ucCompanyPaymentFailedWarningGracePeriodCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.CompanyAdministrator, CompanyPaymentFailedWarning.DisplayMode.PaymentFailedGracePeriod); } else { noticesMultiView.ActiveViewIndex = (int)NoticeType.GracePeriodNonCompanyAdmin; ucCompanyPaymentFailedWarningGracePeriodNonCompanyAdmin.CompanyID = CompanyID; ucCompanyPaymentFailedWarningGracePeriodNonCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.NonCompanyAdministrator, CompanyPaymentFailedWarning.DisplayMode.PaymentFailedGracePeriod); } break; case CompanyStatusHandler.CompanyWarningStatus.FreeTrailEndNoPaymentPackage: noticesMultiView.ActiveViewIndex = (int)NoticeType.FreeTrailEndNoPaymentPackage; if (isCompanyAdmin) { divFreeTrialEndedCA.Visible = true; divFreeTrialEndedNonCA.Visible = false; lnkPricingPlanPage.NavigateUrl = string.Format("~/Company/CompanyPricingPlans.aspx?companyId={0}", this.CompanyID); } else { divFreeTrialEndedCA.Visible = false; divFreeTrialEndedNonCA.Visible = true; lblFreeTrialEndedCompanyName.Text = company.CompanyName; lnkFreeTrialEndedContactPrimaryComapnyAdmin.Text = primaryAdminName; lnkFreeTrialEndedContactPrimaryComapnyAdmin.NavigateUrl = primaryAdminEmailUrl; } break; case CompanyStatusHandler.CompanyWarningStatus.SuspendedForNoPaymentOptions: noticesMultiView.ActiveViewIndex = (int)NoticeType.SuspendedForNoPaymentOptions; if (isCompanyAdmin) { divNopamentOptionCA.Visible = true; divNopamentOptionNonCA.Visible = false; lnkNopamentOptionPricingPlanPage.NavigateUrl = string.Format("~/Company/CompanyPricingPlans.aspx?companyId={0}", this.CompanyID); } else { divNopamentOptionCA.Visible = false; divNopamentOptionNonCA.Visible = true; lblNoPaymentOptionCompanyName.Text = company.CompanyName; if (primaryAdmin != null) { lnkNopamentOptionContactPrimaryComapnyAdmin.Text = primaryAdminName; lnkNopamentOptionContactPrimaryComapnyAdmin.NavigateUrl = primaryAdminEmailUrl; } } break; } } upnlCompanyWarningDisplay.Update(); }
/// <summary> /// Saves the creadit fatzibra card token. /// </summary> /// <param name="ucCreditCardDetails">The credit card details control.</param> /// <param name="commit">if set to <c>true</c> [commit to database].</param> private void SaveCreaditCardToken(CreditCardDetails ucCreditCardDetails, bool commit) { // If credit card not validated if (Response == null) { ValidateCardDetails(ucCreditCardDetails); } if (Response != null && Response.Successful) { #region Update existing token details if available CreditCardToken creditCardToken = GetCreditCardToken(); if (creditCardToken != null) { creditCardToken.IsActive = false; creditCardToken.LastUpdatedBy = UserID; creditCardToken.LastUpdatedDate = Now; } #endregion Update existing token details if available #region Add New token details CreditCardToken newCreditCardToken = new CreditCardToken(); newCreditCardToken.Token = Utils.EncryptStringAES(Response.Result.ID); newCreditCardToken.CreatedBy = UserID; newCreditCardToken.LastUpdatedBy = UserID; newCreditCardToken.LastUpdatedDate = Now; newCreditCardToken.CreatedDate = Now; newCreditCardToken.IsActive = true; newCreditCardToken.RelatedTableName = RelatedTable; newCreditCardToken.RelatedId = CompanyId; creditCardNumber = ucCreditCardDetails.CreditCardNumber; newCreditCardToken.LastFourDigitsCreditCardNumber = Utils.EncryptStringAES(creditCardNumber.Substring(creditCardNumber.Length - 4)); DataContext.CreditCardTokens.AddObject(newCreditCardToken); #endregion Add New token details #region Check the company status and reactivate it var company = GetBL <CompanyBL>().GetCompany(CompanyId); if (company != null) { CompanyStatusHandler.CompanyWarningInfo warningInfo = CompanyStatusHandler.GetCompanyWarningStatus(CompanyId, company.CompanyStatusCodeId, company.ExpirationDate); if (warningInfo.WarningStatus == CompanyStatusHandler.CompanyWarningStatus.SuspendedForNoPaymentOptions) { CompanyPaymentPackage companyPaymentPackage = GetBL <FinanceBL>().GetCurrentPaymentPackageFortheCompanyIncludingFreeTrial(company.CompanyId); companyPaymentPackage.PaymentMethodCodeId = Support.GetCodeIdByCodeValue("PaymentMethod", "CREDITCARD"); company.CompanyStatusCodeId = Support.GetCodeIdByCodeValue("CompanyStatus", "ACTIVE"); //update if there is summary for the period CompanyPaymentSummary companyPaymentSummary = this.GetBL <FinanceBL>().GetPaymentSummaryToShouldProcess(company.CompanyId); if (companyPaymentSummary != null) { companyPaymentSummary.ShouldProcess = true; } } } #endregion Check the company status and reactivate it if (commit) { DataContext.SaveChanges(); } ucCreditCardDetails.ClearValues(); if (DisplayMode == ViewMode.CompanyBilling) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "HideDiv", "HidePaymentSuccessMessage();", true); } popupConfirmPaymentDetails.HidePopup(); } else { StringBuilder sb = new StringBuilder(); if (Response != null && Response.Errors.Count > 0) { sb.Append(string.Join("<br />", Response.Errors)); ucCreditCardDetails.SetNotification(sb.ToString().Length == 0 ? "Failed to set up payment details. Please verify the payment details and retry" : sb.ToString()); } popupConfirmPaymentDetails.ShowPopup(); } }