public static IReportLetter GetLatestReportLetter(IDalSession session, int managementCompanyId, ReportLetterTypes reportLetterType, int reportLetterYear) { List<ICriterion> expressions = new List<ICriterion>(); List<Order> orderings = new List<Order>(); expressions.Add(Expression.Eq("ManagementCompany.Key", managementCompanyId)); expressions.Add(Expression.Eq("ReportLetterTypeId", (int)reportLetterType)); expressions.Add(Expression.Eq("ReportLetterYear", reportLetterYear)); orderings.Add(Order.Desc("CreationDate")); List<IReportLetter> reportLetters = session.GetTypedList<ReportLetter, IReportLetter>(expressions, orderings, null, null); return (reportLetters.Count > 0 ? reportLetters[0] : null); }
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())); } }
public static IReport GetReport(IDalSession session, int accountId, int reportLetterYear, ReportLetterTypes reportLetterType) { Hashtable parameters = new Hashtable(); parameters.Add("AccountId", accountId); parameters.Add("ReportLetterYear", reportLetterYear); parameters.Add("ReportLetterType", (int)reportLetterType); string hql = @"FROM Report R WHERE R.Account.Key = :AccountId AND R.ReportLetter.ReportLetterYear = :ReportLetterYear AND R.ReportLetter.ReportLetterTypeId = :ReportLetterType ORDER BY R.ReportLetter.CreationDate DESC"; List<IReport> reports = session.GetTypedListByHQL<IReport>(hql, parameters); if (reports.Count == 0) return null; else if (reports.Count == 1) return reports[0]; else throw new ApplicationException(string.Format("More than one Report object found for account {0}, year {1}, and letter type '{2}'", accountId, reportLetterYear, reportLetterType)); }
public static List<IReport> GetReports(IDalSession session, int reportLetterYear, ReportLetterTypes reportLetterType, int? managementCompanyId, int[] accountIds, ReportStatuses? reportStatus) { Hashtable parameters = new Hashtable(); Hashtable parameterLists = new Hashtable(); string hql = @"FROM Report R WHERE R.ReportLetter.ReportLetterYear = :ReportLetterYear AND R.ReportLetter.ReportLetterTypeId = :ReportLetterType"; parameters.Add("ReportLetterYear", reportLetterYear); parameters.Add("ReportLetterType", (int)reportLetterType); if (managementCompanyId != null) { parameters.Add("CompanyId", managementCompanyId); hql += @" AND R.Account.Key IN (SELECT AI.Key FROM AccountTypeInternal AI WHERE AI.AccountOwner.Key = :CompanyId)"; } if (accountIds != null) { if (accountIds.Length == 0) accountIds = new int[] { 0 }; parameterLists.Add("AccountIds", accountIds); hql += " AND R.Account.Key IN (:AccountIds)"; } if (reportStatus != null) { parameters.Add("ReportStatus", (int)reportStatus); hql += " AND R.ReportStatusId = :ReportStatus"; } hql += " ORDER BY R.Account.Number"; return session.GetTypedListByHQL<IReport>(hql, parameters, parameterLists); }
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; }
private static void logReport(int oldAccountId, int oldReportLetterYear, ReportLetterTypes oldReportLetterType, int newReportLetterId, ReportStatuses newReportStatus, string newErrorMessage, string pdfFileName, string pdfFilePath, bool? sentByPost) { IDalSession session = NHSessionFactory.CreateSession(); try { IReportLetter reportLetter = ReportLetterMapper.GetReportLetter(session, newReportLetterId); ICustomerAccount account = AccountMapper.GetAccount(session, oldAccountId) as ICustomerAccount; if (newErrorMessage.Length > 200) newErrorMessage = newErrorMessage.Substring(0, 200); IReport report = ReportMapper.GetReport(session, oldAccountId, oldReportLetterYear, oldReportLetterType); if (report == null) report = Report.CreateReport(account, reportLetter, newReportStatus, newErrorMessage); else { report.ModelPortfolio = account.ModelPortfolio; report.SetContactsNAW(account); report.ReportLetter = reportLetter; report.ReportStatusId = (int)newReportStatus; report.ErrorMessage = newErrorMessage; report.CreationDate = DateTime.Now; } if (pdfFileName != null) { if (report.Document == null) report.Document = new FinancialReportDocument(); report.Document.FileName = pdfFileName; report.Document.FilePath = pdfFilePath; report.Document.SentByPost = (bool)sentByPost; session.InsertOrUpdate(report.Document); } else report.Document = null; session.InsertOrUpdate(report); } finally { session.Close(); } }
private static ReportExecutionWrapper getReportWrapper(DateTime beginDate, DateTime endDate, int managementCompanyId, ReportLetterTypes reportLetterType) { string reportTemplateName; string[] parameterNames; if (reportLetterType == ReportLetterTypes.EOY) { reportTemplateName = ReportReturnClass.FiscalYearReport.ToString(); parameterNames = new string[] { "BeginDate", "EndDate", "FiscalYearDividend", "Betreft", "Omschrijving", "SelectedFiscalYear", "accountHasDividend", "ShowLogo" }; } else { reportTemplateName = ReportReturnClass.QuarterReport.ToString(); parameterNames = new string[] { "BeginDate", "EndDate", "PortfolioDevelopment", "PortfolioOverview", "PortfolioSummary", "TransactionOverview", "MoneyMutations", "Chartcover", "Betreft", "Omschrijving", "ShowLogo" }; } IDalSession session = NHSessionFactory.CreateSession(); try { IManagementCompany managementCompany = ManagementCompanyMapper.GetManagementCompany(session, managementCompanyId); IReportTemplate reportTemplate = ReportTemplateMapper.GetReportTemplate(session, managementCompany, reportTemplateName, true); ReportExecutionWrapper wrapper = new ReportExecutionWrapper(); wrapper.SetReportName(reportTemplate.ReportTemplateName); wrapper.AddParameters(parameterNames); return wrapper; } finally { session.Close(); } }
private static int getLatestReportLetterId(int managementCompanyId, int reportLetterYear, ReportLetterTypes reportLetterType) { IDalSession session = NHSessionFactory.CreateSession(); try { IReportLetter reportLetter = ReportLetterMapper.GetLatestReportLetter(session, managementCompanyId, reportLetterType, reportLetterYear); if (reportLetter != null) return reportLetter.Key; else throw new ApplicationException(string.Format("Could not find {0} report letter for year {1} and company ID {2}.", reportLetterType, reportLetterYear, managementCompanyId)); } finally { session.Close(); } }
private static int[] getAccountIdsByReportStatus(int reportLetterYear, ReportLetterTypes reportLetterType, int[] accountIds, ReportStatuses reportStatus) { IDalSession session = NHSessionFactory.CreateSession(); try { List<IReport> reports = ReportMapper.GetReports(session, reportLetterYear, reportLetterType, accountIds, reportStatus); return reports.ConvertAll<int>(report => report.Account.Key).ToArray(); } finally { session.Close(); } }
public static List<IReport> GetReports(IDalSession session, int reportLetterYear, ReportLetterTypes reportLetterType, int[] accountIds, ReportStatuses reportStatus) { return GetReports(session, reportLetterYear, reportLetterType, null, accountIds, reportStatus); }
public static List<IReport> GetReports(IDalSession session, int reportLetterYear, ReportLetterTypes reportLetterType, int managementCompanyId) { return GetReports(session, reportLetterYear, reportLetterType, managementCompanyId, null, null); }