// // GET: /FileDownload/ public virtual System.Web.Mvc.FileContentResult GenerateStatementPDF(StatementReportModel statementReportData) { var assembly = Assembly.GetExecutingAssembly(); var reportStatementResource = Properties.Settings.Default.StatementRptResource.ToString(); var reportStockResource = Properties.Settings.Default.StockRptResource.ToString(); var reportTransactionResource = Properties.Settings.Default.TransactionRptResource.ToString(); LocalReport localReport = new LocalReport(); // string[] names = assembly.GetManifestResourceNames(); var statementFile = assembly.GetManifestResourceStream(reportStatementResource); var stocksFile = assembly.GetManifestResourceStream(reportStockResource); var transactionFile = assembly.GetManifestResourceStream(reportTransactionResource); localReport.LoadReportDefinition(statementFile); localReport.LoadSubreportDefinition("Stock", stocksFile); localReport.LoadSubreportDefinition("Transaction", transactionFile); var datasource = new List <StatementReportModel> { statementReportData }; localReport.DataSources.Add(new ReportDataSource("StatementDataSet", datasource)); localReport.SubreportProcessing += (o, args) => { if (args.ReportPath == "Stock") { args.DataSources.Add( new ReportDataSource("StocksDataSet", datasource.First().Stocks)); } else if (args.ReportPath == "Transaction") { var stockId = args.Parameters["StockId"].Values[0]; var transactions = datasource.First() .Stocks.FirstOrDefault(x => x.InstrumentCode == stockId) .Transactions; args.DataSources.Add(new ReportDataSource("TransactionDataSet", transactions)); } }; statementFile.Close(); stocksFile.Close(); transactionFile.Close(); string FileName = "Portfolio_" + Guid.NewGuid().ToString().Replace("-", "") + ".pdf"; return(this.File(localReport.Render("pdf"), "application/pdf")); }
public System.Web.Mvc.FileContentResult PortfolioDownload(string AccountNumber, string StartDate, string EndDate, string Token, string Token2) { FileDownloadController file = new FileDownloadController(); DateTime sDate = new DateTime(); DateTime eDate = new DateTime(); bool start = DateTime.TryParse(StartDate, out sDate); bool end = DateTime.TryParse(EndDate, out eDate); /* if (start && end) * { * DateTime sDate = Convert.ToDateTime(StartDate); * DateTime eDate = Convert.ToDateTime(EndDate); * } */ var reportData = GetPortfolio(AccountNumber, StartDate, EndDate, ""); AccountServicesController ac = new AccountServicesController(); List <AccountInfoView> AccView = ac.GetAccountInfo(AccountNumber); var customer = AccView.FirstOrDefault(); if (reportData != null) { decimal temp, temp1; var statementData = new StatementReportModel { DateRun = DateTime.Now, FromDate = sDate, //StartDate, ToDate = eDate, UserRunFor = null, //identity.UserName, Stocks = new List <StockModel>(), ClientName = reportData.AccountDetails.Name, AccountNumber = reportData.AccountDetails.Account, GrandTotal = reportData.GrandTotal != null && reportData.GrandTotal.Any() && decimal.TryParse(reportData.GrandTotal.First().GrandTotalAmount, out temp) ? temp.ToString("N2") + " " + reportData.GrandTotal.First().GrandTotalCurrency : null, GrandTotal2 = reportData.GrandTotal != null && reportData.GrandTotal.Count > 1 && decimal.TryParse(reportData.GrandTotal.Skip(1).First().GrandTotalAmount, out temp) ? temp.ToString("N2") + " " + reportData.GrandTotal.Skip(1).First().GrandTotalCurrency : null, customer = customer != null ? new CustomerModel { AccountHolder = customer.AccountOwnerList, AccountNumber = customer.AccountReference } : new CustomerModel() }; if (reportData.InstrumentInfo != null) { foreach (var instrumentInfo in reportData.InstrumentInfo) { var usCulture = new CultureInfo("en-US"); statementData.Stocks.Add( new StockModel { BroughtForwardAmount = decimal.TryParse(instrumentInfo.BroughtForwardAmount, out temp) ? temp : 0, BroughtForwardDate = DateTime.Parse(instrumentInfo.BroughtForwardDate, usCulture), InstrumentCode = instrumentInfo.InstrumentCode, InstrumentName = instrumentInfo.InstrumentName, InstrumentsSINCode = instrumentInfo.InstrumentISINCode, NetActivity = decimal.Parse(instrumentInfo.NetActivityAmount), CarriedForward = decimal.Parse(instrumentInfo.CarryForwardAmount), PledgeEndingValue = decimal.Parse(instrumentInfo.PledgeEndingBalance), PledgeStartingValue = decimal.Parse(instrumentInfo.PlegeStartingBalance), Price = decimal.Parse(instrumentInfo.Price), Transactions = instrumentInfo.TransactionActivity.Select( x => new TransactionModel { Description = x.TransType, Quantity = Convert.ToInt32(decimal.Parse(x.Quantity)), TransactionDate = DateTime.Parse(x.TransactionDate, usCulture), TransactionNumber = x.TransactionID }).ToList(), Value = decimal.TryParse(instrumentInfo.Value, out temp1) ? temp1 : 0M }); } statementData.Stocks.ForEach(x => x.Transactions.Insert(0, new TransactionModel { Description = "Brought Forward", TransactionDate = x.BroughtForwardDate, Quantity = Convert.ToInt32(x.BroughtForwardAmount) })); } //return GenerateStatementPDF(statementData); return(file.GenerateStatementPDF(statementData)); } else { return(file.GenerateStatementPDF(null)); // return GenerateStatementPDF(null); } }