private string BuildMessageBody(ForecastSummary fs) { System.Text.StringBuilder body = new System.Text.StringBuilder(); string rowMask = "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td></tr>"; // Start Table body.AppendLine("<body>"); body.AppendLine("<table style=\"width: 90%; font-family: Arial, Helvetica, sans-serif; font-size: smaller;\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">"); body.AppendLine("<tbody>"); // Build Header body.AppendLine(String.Format(rowMask, "<b>Forecast Name</b>", "<b>Assigned To</b>", "<b>Amount</b>", "<b>Pipeline</b>", "<b>Closed-Won</b>", "<b>Quota</b>", "<b>% To Forecast</b>", "<b>% To Quota</b>" )); foreach (ForecastInfo fi in fs.forecasts) { body.AppendLine(String.Format(rowMask, fi.ForecastName, fi.AssignedTo, Decimal.Round(fi.Amount, 0), Decimal.Round(fi.Pipeline, 0), Decimal.Round(fi.ClosedWon, 0), Decimal.Round(fi.Quota, 0), Decimal.Round(fi.PercentToForecast, 2).ToString() + "%", Decimal.Round(fi.PercentToQuota, 2).ToString() + "%" )); } // Build Footer body.AppendLine(String.Format(rowMask, "<b>Total</b>", "<b></b>", "<b>" + Decimal.Round(fs.AmountTotal, 0) + "</b>", "<b>" + Decimal.Round(fs.PipelineTotal, 0) + "</b>", "<b>" + Decimal.Round(fs.ClosedWonTotal, 0) + "</b>", "<b>" + Decimal.Round(fs.QuotaTotal, 0) + "</b>", "<b>" + Decimal.Round(fs.PercentToForecast, 2).ToString() + "%" + "</b>", "<b>" + Decimal.Round(fs.PercentToQuota, 2).ToString() + "%" + "</b>" )); // End Table body.AppendLine("</tbody>"); body.AppendLine("</table>"); body.AppendLine("</body>"); return(body.ToString()); }
private void WeeklyForecastSummary(IBulletin bulletin) { DateTime today = DateTime.UtcNow; ForecastSummary fs = new ForecastSummary(); Progress = 0; decimal counter = 0; using (var session = new SessionScopeWrapper()) { IList <IForecast> forecasts = session.QueryOver <IForecast>() .Where(x => today >= x.BeginDate && today <= x.EndDate && x.Active == true) .List <IForecast>(); foreach (IForecast f in forecasts) { ForecastInfo fi = new ForecastInfo(); fi.ForecastName = f.Description; fi.AssignedTo = f.AssignedTo.UserInfo.NameLF; fi.Amount = Convert.ToDecimal(f.Amount); fi.Pipeline = (decimal)f.PeriodPipelineAmt("Avg"); fi.ClosedWon = (decimal)f.PeriodClosedWonAmt(); fi.Quota = GetQuotaAmtforUser(f.AssignedTo, today); fs.forecasts.Add(fi); Progress = (100M * ++counter / forecasts.Count) / 2; } } counter = 0; if (fs.forecasts.Count > 0) { string msgBody = BuildMessageBody(fs); string subject = "Weekly Forecast Summary"; IDeliveryItem di = Sage.Platform.EntityFactory.Create <IDeliveryItem>(); di.Body = msgBody; di.Subject = subject; di.DeliverySystem = bulletin.DeliverySystem; di.Status = "To Be Processed"; foreach (IBulletinSubscriber subscriber in bulletin.Subscribers) { IDeliveryItemTarget target = EntityFactory.Create <IDeliveryItemTarget>(); target.DeliveryItem = di; target.Address = subscriber.Subscriber.UserInfo.Email; target.Type = "TO"; di.DeliveryItemTargets.Add(target); di.Save(); Progress = 50M + (50M * ++counter / bulletin.Subscribers.Count); } } }