public static SendableDocumentCategories ToSendableDocumentCategory(ReportLetterTypes reportLetterType) { switch (reportLetterType) { case ReportLetterTypes.Q1: case ReportLetterTypes.Q2: case ReportLetterTypes.Q3: case ReportLetterTypes.Q4: return SendableDocumentCategories.NotasAndQuarterlyReports; case ReportLetterTypes.EOY: return SendableDocumentCategories.YearlyReports; default: throw new ApplicationException(string.Format("Sendable Document Category not known for Report Letter Type {0}.", reportLetterType.ToString())); } }
private static int printReportsForAccounts(int[] accountIds, DateTime beginDate, DateTime endDate, bool portfolioDevelopment, bool portfolioOverview, bool portfolioSummary, bool transactionOverview, bool moneyMutations, bool chartCover, string concerning, string description, int managementCompanyId, int reportLetterYear, ReportLetterTypes reportLetterType, int reportLetterId, bool showLogo) { string periodName = string.Format("{0}_{1}", reportLetterYear, reportLetterType.ToString()); DateTime[] monthDates = new DateTime[] { beginDate, endDate }; int printedCount = 0; if (accountIds.Length > 0) { ReportExecutionWrapper wrapper = getReportWrapper(beginDate, endDate, managementCompanyId, reportLetterType); foreach (int accountId in accountIds) { IDalSession session = NHSessionFactory.CreateSession(); try { IList totalPortfolio = ValuationMapper.GetValuationsTotalPortfolio(session, accountId, monthDates); if (totalPortfolio.Count > 0) { ICustomerAccount account = (ICustomerAccount)AccountMapper.GetAccount(session, accountId); string pdfOnlineReportsFolder = getPdfReportsFolder(account.AccountOwner, "Online", periodName, account.ModelPortfolioName), pdfPostReportsFolder = getPdfReportsFolder(account.AccountOwner, "Post", periodName, account.ModelPortfolioName); string pdfFileName = string.Format("{0:d4}_{1}_{2}_{3}_{4}.pdf", account.AccountHolders.PrimaryAccountHolder.Contact.Key, account.Number, reportLetterType.ToString(), reportLetterId, reportLetterYear); string pdfOnlineFullPath = string.Format(@"{0}\{1}", pdfOnlineReportsFolder, pdfFileName), pdfPostFullPath = string.Format(@"{0}\{1}", pdfPostReportsFolder, pdfFileName); bool needsSendByPost = account.NeedsSendByPost(ReportLetterMapper.ToSendableDocumentCategory(reportLetterType)); DataSet ds = null; string[] paramValues = null; if (reportLetterType == ReportLetterTypes.EOY) { bool accountHasDividend = getDividendCount(session, account.Key, beginDate, endDate); ds = getFiscalYearReportDataSet(session, account, beginDate, endDate); paramValues = new string[] { beginDate.ToShortDateString(), endDate.ToShortDateString(), true.ToString(), concerning, description, reportLetterYear.ToString(), accountHasDividend.ToString(), true.ToString() }; } else { ds = getQuarterReportDataSet(session, portfolioDevelopment, (portfolioOverview || portfolioSummary), transactionOverview, moneyMutations, account, beginDate, endDate); paramValues = new string[] { beginDate.ToShortDateString(), endDate.ToShortDateString(), portfolioDevelopment.ToString(), portfolioOverview.ToString(), portfolioSummary.ToString(), transactionOverview.ToString(), moneyMutations.ToString(), chartCover.ToString(), concerning, description, true.ToString() }; } wrapper.Run(ds, pdfOnlineFullPath, paramValues); if (needsSendByPost) { if (showLogo) File.Copy(pdfOnlineFullPath, pdfPostFullPath, true); else { // "ShowLogo" is the last parameter (for now) paramValues[paramValues.Length - 1] = showLogo.ToString(); wrapper.Run(ds, pdfPostFullPath, paramValues); } } session.Close(); logReport(accountId, reportLetterYear, reportLetterType, reportLetterId, ReportStatuses.PrintSuccess, "", pdfFileName, pdfOnlineReportsFolder, needsSendByPost); printedCount++; } else logReport(accountId, reportLetterYear, reportLetterType, reportLetterId, ReportStatuses.NoValuations, "", null, null, null); } catch (Exception ex) { logReport(accountId, reportLetterYear, reportLetterType, reportLetterId, ReportStatuses.Error, ex.Message, null, null, null); } finally { if (session.IsOpen) session.Close(); } } } else throw new ApplicationException("No accounts were specified for printing reports."); return printedCount; }