/// <summary> /// Determines whether payments are failed and specified company is in grace period. /// </summary> /// <param name="companyId">The company identifier.</param> /// <returns></returns> public bool IsCompanyInPaymentFailedGracePeriod(int companyId) { int gracePeriodCompanyStatusCodeId = Utils.GetCodeIdByCodeValue("CompanyStatus", "GRACEPERIOD"); bool isPaymentFailedInvoiceExists = ProjectFinanceHandler.IsPaymentFailedInvoicesExistForCompany(companyId); return(DataContext.Companies.Where(c => c.CompanyId == companyId && c.CompanyStatusCodeId == gracePeriodCompanyStatusCodeId).FirstOrDefault() != null && isPaymentFailedInvoiceExists); }
/// <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> /// Performs business logic actions specified for this task handler. /// </summary> protected override void PerformActions() { int dayToRun = int.Parse(Utils.GetSystemValue("MonthlyFinanceProcessDay")); DateTime dateToConsider = new DateTime(Utils.Today.Year, Utils.Today.Month, dayToRun); TimeSpan ts; if (TimeSpan.TryParse(Utils.GetSystemValue("AgentExecutionTime"), out ts)) { if (Utils.Now < dateToConsider + ts) { dateToConsider = dateToConsider.AddMonths(-1); } } ProjectFinanceHandler.ProcessInvoicesAndPayments(0, dateToConsider, true, 0); }
/// <summary> /// Configures the company status. /// </summary> private void ConfigureCompanyStatus() { Data.Company company = this.GetBL <CompanyBL>().GetCompany(CompanyId); int companyStatusCodeId = company.CompanyStatusCodeId; int companyGracePeriodCodeId = Utils.GetCodeIdByCodeValue("CompanyStatus", "GRACEPERIOD"); if (this.GetBL <CompanyBL>().HasCompanySuspendedbySBAdmin(CompanyId)) { string msgCompanySuspended = "<strong>Company activity is suspended by StageBitz Admin</strong>"; multStatusCompany.ActiveViewIndex = 0; ltrlStatus.Text = msgCompanySuspended; if (this.GetBL <CompanyBL>().IsCompanyInPaymentFailedGracePeriod(CompanyId) || this.GetBL <CompanyBL>().IsCompanyPaymentFailed(CompanyId)) { multStatusCompany.ActiveViewIndex = 2; View activeView = multStatusCompany.GetActiveView(); Literal ltrlExpiresOn = (Literal)activeView.FindControl("ltrlExpiresOn"); ltrlExpiresOn.Text = msgCompanySuspended + " | Payment Failed"; imgPaymentFailed.ToolTip = ProjectFinanceHandler.GetCompanyPaymentFailureDetails(CompanyId); } } else if (IsPaymentFailedInvoicesExistForCompany) { multStatusCompany.ActiveViewIndex = 2; View activeView = multStatusCompany.GetActiveView(); Literal ltrlExpiresOn = (Literal)activeView.FindControl("ltrlExpiresOn"); Image imgPaymentFailed = (Image)activeView.FindControl("imgPaymentFailed"); imgPaymentFailed.ToolTip = ProjectFinanceHandler.GetCompanyPaymentFailureDetails(CompanyId); if (company.CompanyStatusCodeId == companyGracePeriodCodeId && IsPaymentFailedInvoicesExistForCompany) { ltrlExpiresOn.Text = string.Format("Payment Failed (Company will become read-only on {0})", Support.FormatDate(company.ExpirationDate)); } else if (IsPaymentFailedCompany) { if (companyStatusCodeId == paymentFailed) { ltrlExpiresOn.Text = "<strong>Company activity is suspended</strong>"; } else { ltrlExpiresOn.Text = Utils.GetCodeDescription(companyStatusCodeId); } } } }
/// <summary> /// Makes the payment. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="CommandEventArgs"/> instance containing the event data.</param> protected void MakePayment(object sender, CommandEventArgs e) { if (!StopProcessing) { popupMakePayment.HidePopup(); //Make the payment bool isPaymentSuccess = ProjectFinanceHandler.ProcessInvoicesAndPayments(CompanyId, Today, false, UserID); if (!isPaymentSuccess) { popupNotification.Title = "Payment failed"; ltrlNotification.Text = "Payment failed. Please verify the payment details and retry."; popupNotification.ShowPopup(); return; } //Refresh the UI Response.Redirect(Request.Url.ToString()); } }
/// <summary> /// Returns the warning status of the project based on it's current status and expiration details. /// </summary> public static CompanyWarningInfo GetCompanyWarningStatus(int companyId, int companyStatusCodeId, DateTime?expirationDate) { using (StageBitzDB dataContext = new StageBitzDB()) { CompanyBL companyBL = new CompanyBL(dataContext); FinanceBL financeBL = new FinanceBL(dataContext); string statusCode = Utils.GetCodeByCodeId(companyStatusCodeId).Value; double remainingDays = (statusCode == "ACTIVE" || expirationDate == null) ? -1 : (expirationDate.Value.Date - Utils.Today).TotalDays; CompanyWarningStatus warningStatus = CompanyWarningStatus.NoWarning; if (companyBL.HasCompanySuspendedbySBAdmin(companyId)) { warningStatus = CompanyWarningStatus.SBAdminSuspended; } else if (statusCode == "GRACEPERIOD" && ProjectFinanceHandler.IsPaymentFailedInvoicesExistForCompany(companyId)) { warningStatus = CompanyWarningStatus.PaymentFailedGracePeriod; } else if (statusCode == "SUSPENDEDFORPAYMENTFAILED") { warningStatus = CompanyWarningStatus.PaymentFailed; } else if (!financeBL.HasPackageSelectedForFreeTrailEndedCompany(companyId)) { warningStatus = CompanyWarningStatus.FreeTrailEndNoPaymentPackage; } else if (statusCode == "SUSPENDEDFORNOPAYMENTOPTIONS") { warningStatus = CompanyWarningStatus.SuspendedForNoPaymentOptions; } return(new CompanyWarningInfo(warningStatus, (int)Math.Round(remainingDays, 0))); } }
protected void gvTransactions_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem dataItem = (GridDataItem)e.Item; dynamic transaction = (dynamic)dataItem.DataItem; HyperLink lnkCompanyName = (HyperLink)e.Item.FindControl("lnkCompanyName"); lnkCompanyName.Text = Support.TruncateString(transaction.CompanyName, 30); if (transaction.CompanyName.Length > 30) { lnkCompanyName.ToolTip = transaction.CompanyName; } lnkCompanyName.NavigateUrl = string.Format("~/Company/CompanyDetails.aspx?CompanyID={0}", transaction.CompanyId); dataItem["Country"].Text = Support.TruncateString(transaction.CountryName, 12); if (transaction.CountryName.Length > 12) { dataItem["Country"].ToolTip = transaction.CountryName; } dataItem["Amount"].Text = Support.FormatCurrency(transaction.Invoice.Amount); dataItem["InvoiceDate"].Text = Support.FormatDate(transaction.Invoice.InvoiceDate); dataItem["FromDate"].Text = Support.FormatDate(transaction.Invoice.FromDate); dataItem["ToDate"].Text = Support.FormatDate(transaction.Invoice.ToDate); if (transaction.ReceiptID != 0) { //dataItem["ReceiptNo"].Text = transaction.ReceiptID.ToString(); dataItem["ReceiptDate"].Text = Support.FormatDate(transaction.ReceiptDate); } Image imgInfo = (Image)e.Item.FindControl("imgInfo"); Image imgError = (Image)e.Item.FindControl("imgError"); string paymentLogRefNoString = (string.IsNullOrEmpty(transaction.PaymentLogReferenceNumber) ? string.Empty : string.Format(", Ref. No: {0}", transaction.PaymentLogReferenceNumber)); if (transaction.ReceiptID == 0) //Failed payment { imgError.Visible = true; imgInfo.Visible = false; imgError.ToolTip = string.Format("Unpaid Invoice (Invoice No: {0:000000}{1}) - {2}", transaction.Invoice.InvoiceID, paymentLogRefNoString, ProjectFinanceHandler.GetCompanyPaymentFailureDetails(transaction.CompanyId)); } else { imgError.Visible = false; imgInfo.Visible = true; imgInfo.ToolTip = string.Format("Invoice No: {0:000000}, Receipt No: {1:000000}{2}", transaction.Invoice.InvoiceID, transaction.ReceiptID, paymentLogRefNoString); } } }
/// <summary> /// Handles the ItemDataBound event of the gvTransactions control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Telerik.Web.UI.GridItemEventArgs"/> instance containing the event data.</param> protected void gvTransactions_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem dataItem = (GridDataItem)e.Item; dynamic transaction = (dynamic)dataItem.DataItem; var globalizationSection = WebConfigurationManager.GetSection("system.web/globalization") as GlobalizationSection; dataItem["Amount"].Text = Support.FormatCurrency(transaction.Amount, globalizationSection.Culture); dataItem["InvoiceDate"].Text = Support.FormatDate(transaction.InvoiceDate); dataItem["FromDate"].Text = Support.FormatDate(transaction.FromDate); dataItem["ToDate"].Text = Support.FormatDate(transaction.ToDate); if (transaction.ReceiptID != 0) { dataItem["ReceiptDate"].Text = Support.FormatDate(transaction.ReceiptDate); } Image imgInfo = (Image)e.Item.FindControl("imgInfo"); Image imgError = (Image)e.Item.FindControl("imgError"); string paymentLogRefNoString = (string.IsNullOrEmpty(transaction.PaymentLogReferenceNumber) ? string.Empty : string.Format(", Ref. No: {0}", transaction.PaymentLogReferenceNumber)); if (transaction.InvoiceID != 0) { if (transaction.ReceiptID == 0) //Failed payment { imgError.Visible = true; imgInfo.Visible = false; imgError.ToolTip = string.Format("Unpaid Invoice (Invoice No: {0:000000}{1}) - {2}", transaction.InvoiceID, paymentLogRefNoString, ProjectFinanceHandler.GetCompanyPaymentFailureDetails(this.RelatedId)); } else { imgError.Visible = false; imgInfo.Visible = true; imgInfo.ToolTip = string.Format("Invoice No: {0:000000}, Receipt No: {1:000000}{2}", transaction.InvoiceID, transaction.ReceiptID, paymentLogRefNoString); } } else { imgError.Visible = false; imgInfo.Visible = true; imgInfo.ToolTip = "Invoice request transaction. An invoice will have been posted to you. Receipt dates for posted invoices do not appear here."; } } }