public bool WritePdf(string fpath, ParametersViewModel parametersViewModel, CUSTOMER_INFO customerInfo, List<GLNODES> glnodess, List<FACILITIES> facilitiess, List<MM_CONTRACT_RETRIEVAL> mmContractRetrievals, List<GUARANTOR> guarantors, string[] accounts, List<LD_KEN> ldKens, List<SECURITIES> securitiess, string loggedUser, string addres,string charge) { //var imageDir = fpath + "/Images/bg-marketing-banner.jpg"; Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled); var filename = r.Replace(customerInfo.CUSTOMER_NAME, String.Empty); var directory = fpath + "/PDFs/" + filename; var appRootDir = fpath + "/PDFs/" + filename + "/" + filename + "_" + parametersViewModel.ReportDate.ToString("dd_MMM_yyyy") + ".pdf"; try { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (File.Exists(appRootDir)) File.Delete(appRootDir); //Font Definition var normalFont = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8); var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 9); var underLine = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 9, Font.UNDERLINE); //Fetching Needed Data //var acc = _repository.Fetch<GLNODES>().Any(p => p.ACCOUNT_N0 == accounts.ToString()); var addressDetails = _repository.Find<AUDITORADDRESS>(parametersViewModel.AddressId); var auditorDetails = _repository.Find<AUDITOR>(addressDetails.AuditorId); var salutaion = _repository.Fetch<SALUTATION>().FirstOrDefault(p=> p.DefaultActive) ?? _repository.Fetch<SALUTATION>().FirstOrDefault() ; var signature = _repository.Fetch<SIGNATURES>().FirstOrDefault(p => p.DefaultActive) ?? _repository.Fetch<SIGNATURES>().FirstOrDefault(); Image signatureImage = default(iTextSharp.text.Image); signatureImage = iTextSharp.text.Image.GetInstance(signature.Signimage); signatureImage.ScaleAbsolute(60f, 40f); var defaultParameters = _repository.Fetch<Parameter>(); // Creating System.IO.FileStream object using (var fs = new FileStream(appRootDir, FileMode.Create, FileAccess.Write, FileShare.None)) // Creating iTextSharp.text.Document object using (var doc = new Document()) { doc.SetMargins(doc.LeftMargin, doc.RightMargin, doc.TopMargin + 80, doc.BottomMargin + 60); // Creating iTextSharp.text.pdf.PdfWriter object // It helps to write the Document to the Specified FileStream using (var writer = PdfWriter.GetInstance(doc, fs)) { //Set Header & Footer Using Page Events with the above class writer.PageEvent = new PdfHeaderFooter(); writer.AddViewerPreference(PdfName.HIDEMENUBAR, new PdfBoolean(true)); writer.ViewerPreferences = PdfWriter.HideMenubar; // Openning the Document doc.Open(); // Adding a paragraph // NOTE: When we want to insert text, then we've to do it through creating paragraph doc.NewPage(); var prSpace = new Paragraph("\n"); var pr1 = new Paragraph(String.Format("{0:MMMM d, yyyy}", DateTime.Now), normalFont); var pr2 = new Paragraph(auditorDetails.AuditorName, normalFont); var pr3 = new Paragraph(addressDetails.Address1, normalFont); var pr4 = new Paragraph(addressDetails.Address2, normalFont); var pr5 = new Paragraph(addressDetails.Address3, normalFont); var pr6 = new Paragraph(addressDetails.Address4, normalFont); var pr7 = new Paragraph(salutaion.SalutationDescription, normalFont); var pr8 = new Paragraph("RE: " + customerInfo.CUSTOMER_NAME, underLine); var pr9 = new Paragraph(Parameters("LETTERINTRO").Paramvalue + " " + parametersViewModel.ReportDate.ToString("dd MMM, yyyy") + ".", normalFont); //Account Balances Section var pr10 = new Paragraph(Parameters("GLNODES").Paramvalue, underLine); var glnodesTable = new PdfPTable(4) { WidthPercentage = 100 }; var widths = new float[] { 20f, 8f, 70f, 19f }; glnodesTable.SetWidths(widths); var cell1 = new PdfPCell(new Phrase("Account Number", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; glnodesTable.AddCell(cell1); var cell2 = new PdfPCell(new Phrase("CCY", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; glnodesTable.AddCell(cell2); var cell3 = new PdfPCell(new Phrase("Account Description", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; glnodesTable.AddCell(cell3); var cell4 = new PdfPCell(new Phrase("Balance", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; cell4.HorizontalAlignment = Element.ALIGN_RIGHT; glnodesTable.AddCell(cell4); foreach (var n in glnodess) { var cell5 = new PdfPCell(new Phrase(n.ACCOUNT_N0, normalFont)) { Colspan = 1 }; glnodesTable.AddCell(cell5); var cell6 = new PdfPCell(new Phrase(n.CCY, normalFont)) { Colspan = 1 }; glnodesTable.AddCell(cell6); var cell7 = new PdfPCell(new Phrase(n.AC_DESC, normalFont)) { Colspan = 1 }; glnodesTable.AddCell(cell7); var txnType = n.CURRENT_LCY_BAL.Contains("-") ? " DR" : " CR"; var amt = n.CCY.ToUpper().Trim() == "KES" ? n.CURRENT_LCY_BAL : n.FCY_BALANCE; var cell8 = new PdfPCell(new Phrase(amt.Replace("-", "") + txnType, normalFont)) { Colspan = 1 }; cell8.HorizontalAlignment = Element.ALIGN_RIGHT; glnodesTable.AddCell(cell8); } //Facilities Section var pr11 = new Paragraph(Parameters("FACILITIES").Paramvalue, underLine); var facilitiesTable = new PdfPTable(5) { WidthPercentage = 100 }; var facilitiesWidths = new float[] { 70f, 50f, 8f, 19f, 18f }; facilitiesTable.SetWidths(facilitiesWidths); var fcell1 = new PdfPCell(new Phrase("Facilities Description", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; facilitiesTable.AddCell(fcell1); var fcell2 = new PdfPCell(new Phrase("Exposure Category", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; facilitiesTable.AddCell(fcell2); var fcellnew = new PdfPCell(new Phrase("CCY", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; facilitiesTable.AddCell(fcellnew); var fcell3 = new PdfPCell(new Phrase("Maximum Limit", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; fcell3.HorizontalAlignment = Element.ALIGN_RIGHT; facilitiesTable.AddCell(fcell3); var fcell4 = new PdfPCell(new Phrase("Tenor", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; facilitiesTable.AddCell(fcell4); foreach (var k in facilitiess) { var fcell5 = new PdfPCell(new Phrase(k.FACILITY_DESCRIPTION, normalFont)) { Colspan = 1 }; facilitiesTable.AddCell(fcell5); var fcell6 = new PdfPCell(new Phrase(k.EXPOSURE_CATEGORY, normalFont)) { Colspan = 1 }; facilitiesTable.AddCell(fcell6); var fcell9 = new PdfPCell(new Phrase(k.CURRENCY.ToUpper(), normalFont)) { Colspan = 1 }; facilitiesTable.AddCell(fcell9); var formatAmt = decimal.Parse(k.AVAILABLE_CCY_AMOUNT); var fcell7 = new PdfPCell(new Phrase(String.Format("{0:C}", formatAmt).Replace("$", ""), normalFont)) { Colspan = 1 }; fcell7.HorizontalAlignment = Element.ALIGN_RIGHT; facilitiesTable.AddCell(fcell7); string tenor = ""; if (k.MAX_TENOR_YEARS != null) tenor = k.MAX_TENOR_YEARS.Trim() == "1" ? k.MAX_TENOR_YEARS.Trim() + " Year " : k.MAX_TENOR_YEARS.Trim() + " Years "; else if (k.MAX_TENOR_MONTHS != null) tenor = k.MAX_TENOR_MONTHS.Trim() == "1" ? tenor + k.MAX_TENOR_MONTHS.Trim() + " Month " : tenor + k.MAX_TENOR_MONTHS.Trim() + " Months "; else if (k.MAX_TENOR_DAYS != null) tenor = k.MAX_TENOR_DAYS.Trim() == "1" ? tenor + k.MAX_TENOR_DAYS.Trim() + " Day" : tenor + k.MAX_TENOR_DAYS.Trim() + " Days"; var fcell8 = new PdfPCell(new Phrase(tenor.Trim() == "" ? "Exp. " + k.EXPIRY_DATE_: tenor, normalFont)) { Colspan = 1 }; facilitiesTable.AddCell(fcell8); } //MM Section For Oustanding Deposits var pr12 = new Paragraph(Parameters("MM_CONTRACT_RETRIEVAL").Paramvalue, underLine); var mmTable = new PdfPTable(7) { WidthPercentage = 100 }; var mmWidths = new float[] { 20f, 20f, 20f, 8f, 18f, 10f, 19f }; mmTable.SetWidths(mmWidths); //Header Cells var mcell1 = new PdfPCell(new Phrase("Reference", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; mmTable.AddCell(mcell1); var mcell2 = new PdfPCell(new Phrase("Value Date", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; mmTable.AddCell(mcell2); var mcell3 = new PdfPCell(new Phrase("Maturity Date", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; mmTable.AddCell(mcell3); var mcell4 = new PdfPCell(new Phrase("CCY", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; mmTable.AddCell(mcell4); var mcell5 = new PdfPCell(new Phrase("Amount", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; mcell5.HorizontalAlignment = Element.ALIGN_RIGHT; mmTable.AddCell(mcell5); var mcell6 = new PdfPCell(new Phrase("Rate", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; mmTable.AddCell(mcell6); var mcell7 = new PdfPCell(new Phrase("Accrued Interest", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; mcell7.HorizontalAlignment = Element.ALIGN_RIGHT; mmTable.AddCell(mcell7); foreach (var q in mmContractRetrievals) { var mcell8 = new PdfPCell(new Phrase(q.CONTRACT_REF_NO, normalFont)) { Colspan = 1 }; mmTable.AddCell(mcell8); var mcell9 = new PdfPCell(new Phrase(q.VALUE_DATE, normalFont)) { Colspan = 1 }; mmTable.AddCell(mcell9); var mcell10 = new PdfPCell(new Phrase(string.IsNullOrEmpty(q.MATURITY_DATE) ? " ON CALL " : q.MATURITY_DATE, normalFont)) { Colspan = 1 }; mmTable.AddCell(mcell10); var mcell11 = new PdfPCell(new Phrase(q.CURRENCY, normalFont)) { Colspan = 1 }; mmTable.AddCell(mcell11); var amt = decimal.Parse(q.PRINCIPAL_AMOUNT); var mcell12 = new PdfPCell(new Phrase(String.Format("{0:C}", amt).Replace("$", ""), normalFont)) { Colspan = 1 }; mcell12.HorizontalAlignment = Element.ALIGN_RIGHT; mmTable.AddCell(mcell12); var mcell13 = new PdfPCell(new Phrase(q.INT_RATE, normalFont)) { Colspan = 1 }; mmTable.AddCell(mcell13); var dayBasis = q.CURRENCY.ToUpper() == "USD" || q.CURRENCY.ToUpper() == "EUR" ? 360 : 365; var myAccrued = Convert.ToDouble(q.PRINCIPAL_AMOUNT) * Convert.ToDouble(q.INT_RATE) / 100 * (parametersViewModel.ReportDate - DateTime.ParseExact(q.VALUE_DATE, "dd/MM/yyyy", CultureInfo.InvariantCulture)).TotalDays / dayBasis; var finAmt = Math.Round(myAccrued, 2); var mcell14 = new PdfPCell(new Phrase(String.Format("{0:C}", finAmt).Replace("$", ""), normalFont)) { Colspan = 1 }; mcell14.HorizontalAlignment = Element.ALIGN_RIGHT; mmTable.AddCell(mcell14); } //Oustanding Loans LD_KEN. I hade made the rest Earlier so there is slight naming change of controls coz am feeling lazy to change wht i had done var pr15 = new Paragraph(Parameters("LDKEN").Paramvalue, underLine); var ldKenTable = new PdfPTable(6) { WidthPercentage = 100 }; var ldKenWidths = new float[] { 20f, 20f, 20f, 8f, 18f, 10f }; ldKenTable.SetWidths(ldKenWidths); //Header Cells var ldcell1 = new PdfPCell(new Phrase("Reference", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; ldKenTable.AddCell(ldcell1); var ldcell2 = new PdfPCell(new Phrase("Value Date", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; ldKenTable.AddCell(ldcell2); var ldcell3 = new PdfPCell(new Phrase("Maturity Date", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; ldKenTable.AddCell(ldcell3); var ldcell4 = new PdfPCell(new Phrase("CCY", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; ldKenTable.AddCell(ldcell4); var ldcell5 = new PdfPCell(new Phrase("Amount", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; ldcell5.HorizontalAlignment = Element.ALIGN_RIGHT; ldKenTable.AddCell(ldcell5); var ldcell6 = new PdfPCell(new Phrase("Rate", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; ldKenTable.AddCell(ldcell6); foreach (var l in ldKens.OrderBy(p => p.CONTRACT_REF_NO)) { var ldcell7 = new PdfPCell(new Phrase(l.CONTRACT_REF_NO, normalFont)) { Colspan = 1 }; ldKenTable.AddCell(ldcell7); var ldcell8 = new PdfPCell(new Phrase(l.VALUE_DATE, normalFont)) { Colspan = 1 }; ldKenTable.AddCell(ldcell8); var ldcell9 = new PdfPCell(new Phrase(string.IsNullOrEmpty(l.MATURITY_DATE) ? " ON CALL " : l.MATURITY_DATE, normalFont)) { Colspan = 1 }; ldKenTable.AddCell(ldcell9); var ldcell10 = new PdfPCell(new Phrase(l.CURRENCY, normalFont)) { Colspan = 1 }; ldKenTable.AddCell(ldcell10); var ldcell11 = new PdfPCell(new Phrase(l.PRINCIPAL_OUTSTANDING, normalFont)) { Colspan = 1 }; ldcell11.HorizontalAlignment = Element.ALIGN_RIGHT; ldKenTable.AddCell(ldcell11); var ldcell12 = new PdfPCell(new Phrase(l.RATE, normalFont)) { Colspan = 1 }; ldKenTable.AddCell(ldcell12); } //Securities Section var pr16 = new Paragraph(Parameters("SECURITIES").Paramvalue, underLine); var scTable = new PdfPTable(6) { WidthPercentage = 100 }; var scWidths = new float[] { 45f, 20f, 20f, 60f, 9f, 19f }; scTable.SetWidths(scWidths); //Header Cells var sccell1 = new PdfPCell(new Phrase("Doc Description", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; scTable.AddCell(sccell1); var sccell2 = new PdfPCell(new Phrase("Doc Date", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; scTable.AddCell(sccell2); var sccell3 = new PdfPCell(new Phrase("Expiry Date", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; scTable.AddCell(sccell3); var sccell4 = new PdfPCell(new Phrase("Item Details", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; scTable.AddCell(sccell4); var sccell5 = new PdfPCell(new Phrase("CCY", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; scTable.AddCell(sccell5); var sccell6 = new PdfPCell(new Phrase("Amount", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; sccell6.HorizontalAlignment = Element.ALIGN_RIGHT; scTable.AddCell(sccell6); foreach (var s in securitiess) { var sccell7 = new PdfPCell(new Phrase(s.DOC_DESCRIPTION, normalFont)) { Colspan = 1 }; scTable.AddCell(sccell7); var sccell8 = new PdfPCell(new Phrase(Convert.ToDateTime(s.DOC_DATE).ToString("dd/MMM/yyyy"), normalFont)) { Colspan = 1 }; scTable.AddCell(sccell8); var sccell9 = new PdfPCell(new Phrase(s.DOC_EXPIRY_DATE, normalFont)) { Colspan = 1 }; scTable.AddCell(sccell9); var sccell10 = new PdfPCell(new Phrase(s.ITEM_DETAILS.ToUpper(), normalFont)) { Colspan = 1 }; scTable.AddCell(sccell10); var sccell11 = new PdfPCell(new Phrase(s.CCY, normalFont)) { Colspan = 1 }; scTable.AddCell(sccell11); var formatAmt = s.AMOUNT ?? "0"; var sccell12 = new PdfPCell(new Phrase(String.Format("{0:C}", decimal.Parse(formatAmt)).Replace("$", ""), normalFont)) { Colspan = 1 }; sccell12.HorizontalAlignment = Element.ALIGN_RIGHT; scTable.AddCell(sccell12); } //Guarantors Section var pr13 = new Paragraph(Parameters("GUARANTOR").Paramvalue, underLine); var gtTable = new PdfPTable(5) { WidthPercentage = 100 }; var gtWidths = new float[] { 30f, 8f, 19f, 20f, 50f }; gtTable.SetWidths(gtWidths); //Header Cells var gtcell1 = new PdfPCell(new Phrase("Reference", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; gtTable.AddCell(gtcell1); var gtcell2 = new PdfPCell(new Phrase("CCY", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; gtTable.AddCell(gtcell2); var gtcell3 = new PdfPCell(new Phrase("Amount", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; gtcell3.HorizontalAlignment = Element.ALIGN_RIGHT; gtTable.AddCell(gtcell3); var gtcell4 = new PdfPCell(new Phrase("Expiry Date", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; gtTable.AddCell(gtcell4); var gtcell5 = new PdfPCell(new Phrase("Beneficiary", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; gtTable.AddCell(gtcell5); foreach (var x in guarantors) { var gtcell6 = new PdfPCell(new Phrase(x.OUR_REF_NUM, normalFont)) { Colspan = 1 }; gtTable.AddCell(gtcell6); var gtcell7 = new PdfPCell(new Phrase(x.TXN_CCY, normalFont)) { Colspan = 1 }; gtTable.AddCell(gtcell7); var formatAmt = x.OST_AMOUNT_ ?? "0"; var gtcell8 = new PdfPCell(new Phrase(String.Format("{0:C}", decimal.Parse(formatAmt)).Replace("$", ""), normalFont)) { Colspan = 1 }; gtcell8.HorizontalAlignment = Element.ALIGN_RIGHT; gtTable.AddCell(gtcell8); var gtcell9 = new PdfPCell(new Phrase(Convert.ToDateTime(x.EXPIRY_DATE).ToString("dd/MMM/yyyy"), normalFont)) { Colspan = 1 }; gtTable.AddCell(gtcell9); var gtcell10 = new PdfPCell(new Phrase(x.BENE_NAME, normalFont)) { Colspan = 1 }; gtTable.AddCell(gtcell10); } //Signatories Section var pr14 = new Paragraph(Parameters("SIGNATORIES").Paramvalue, underLine); var sigTable = new PdfPTable(2) { WidthPercentage = 100 }; var sigWidths = new float[] { 30f, 50f }; sigTable.SetWidths(sigWidths); var sigWritten = false; var sigcell1 = new PdfPCell(new Phrase("Account Number", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; sigTable.AddCell(sigcell1); var sigcell2 = new PdfPCell(new Phrase("Signatory Name & Title", boldFont)) { BackgroundColor = BaseColor.LIGHT_GRAY, Colspan = 1 }; sigTable.AddCell(sigcell2); foreach (var s in accounts) { if (IfThereIsSignatories(s)) { sigWritten = true; var sigcell3 = new PdfPCell(new Phrase(s, normalFont)) { Colspan = 1 }; sigTable.AddCell(sigcell3); foreach (var y in SignatoriesAcc(s, parametersViewModel.ReportDate)) { var sigcell4 = new PdfPCell(new Phrase(y.CIF_SIG_NAME + " - " + y.CIF_SIG_TITLE, normalFont)) { Colspan = 1 }; sigTable.AddCell(sigcell4); var sigcell5 = new PdfPCell(new Phrase(" ", normalFont)) { Colspan = 1 }; sigTable.AddCell(sigcell5); } var sigcell6 = new PdfPCell(new Phrase(" ", normalFont)) { Colspan = 1 }; sigTable.AddCell(sigcell6); } } //Letter Head doc.Add(pr1); doc.Add(prSpace); doc.Add(pr2); doc.Add(pr3); doc.Add(pr4); doc.Add(pr5); doc.Add(pr6); doc.Add(prSpace); doc.Add(pr7); doc.Add(prSpace); doc.Add(pr8); doc.Add(prSpace); doc.Add(pr9); doc.Add(prSpace); // List<GLNODES> glnodess, List<FACILITIES> facilitiess, List<MM_CONTRACT_RETRIEVAL> mmContractRetrievals, //List<GUARANTOR> guarantors, List<SIGNATORIES> signatoriess, List<LD_KEN> ldKens, List<SECURITIES> securitiess //Account Balances if (glnodess.Count > 0) { doc.Add(pr10); doc.Add(prSpace); doc.Add(glnodesTable); doc.Add(prSpace); } //Facilities if (facilitiess.Count > 0) { doc.Add(pr11); doc.Add(prSpace); doc.Add(facilitiesTable); doc.Add(prSpace); } //Deposits if (mmContractRetrievals.Count > 0) { doc.Add(pr12); doc.Add(prSpace); doc.Add(mmTable); doc.Add(prSpace); } //Loans if (ldKens.Count > 0) { doc.Add(pr15); doc.Add(prSpace); doc.Add(ldKenTable); doc.Add(prSpace); if (parametersViewModel.Rate != "") doc.Add(new Paragraph("Loan Rate is " + parametersViewModel.Rate + "%", normalFont)); doc.Add(prSpace); } //Securities if (securitiess.Count > 0) { doc.Add(pr16); doc.Add(prSpace); doc.Add(scTable); doc.Add(prSpace); } //Guarantors if (guarantors.Count > 0) { doc.Add(pr13); doc.Add(prSpace); doc.Add(gtTable); doc.Add(prSpace); } //Signatories if (sigWritten) { doc.Add(pr14); doc.Add(prSpace); doc.Add(sigTable); doc.Add(prSpace); } var outroTable = new PdfPTable(1) { WidthPercentage = 100 }; PdfPCell cell; cell = new PdfPCell(new Paragraph(Parameters("LETTEROUTRO").Paramvalue, normalFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(prSpace)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(signatureImage); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(prSpace)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(signature.Signname, normalFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); //cell = new PdfPCell(new Paragraph(prSpace)); //cell.HorizontalAlignment = Element.ALIGN_LEFT; //cell.Border = PdfPCell.NO_BORDER; //outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(signature.Signtitle, normalFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(prSpace)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(prSpace)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph("CC " + customerInfo.CUSTOMER_NAME, normalFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(" " + customerInfo.ADDRESS_LINE_1, normalFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); cell = new PdfPCell(new Paragraph(" " + customerInfo.ADDRESS_LINE_2, normalFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = PdfPCell.NO_BORDER; outroTable.AddCell(cell); outroTable.KeepTogether = true; doc.Add(outroTable); //Letter Outro ....yes am using album synonames // Closing the Document doc.Close(); //After This we Log the Report and hide the Download Location var ccy = _repository.Fetch<GLNODES>() .Where(p => p.ACCOUNT_N0==charge).Select(n=>n.CCY); // var acc1 = // _repository.Fetch<GLNODES>() // .Where(p => accounts.Contains(p.ACCOUNT_N0) && p.CCY == "KES"); // var acc2 = //_repository.Fetch<GLNODES>() // .Where(p => accounts.Contains(p.ACCOUNT_N0) && p.CCY == "USD"); // //var ccy = acc.Select(p => p.CCY); // foreach (var n in acc.ToList()) // { // if (n.CCY == "KES") // { // return SaveGeneratedReport(appRootDir, parametersViewModel.ReportDate, loggedUser, // addressDetails.Email, fpath, addres, acc1 // .Select(m => m.ACCOUNT_N0).FirstOrDefault()); // } // if (n.CCY == "USD") // { // return SaveGeneratedReport(appRootDir, parametersViewModel.ReportDate, loggedUser, // addressDetails.Email, fpath, addres, acc2 // .Select(m => m.ACCOUNT_N0).FirstOrDefault()); // } // } return SaveGeneratedReport(appRootDir, parametersViewModel.ReportDate, loggedUser, addressDetails.Email, fpath, addres, charge,ccy.FirstOrDefault()); } } } // Catching iTextSharp.text.DocumentException if any catch (DocumentException de) { _logs.LogError(loggedUser, "PDF - DocumentException", "Error: " + de.Message, addres, fpath, "AuditLetters"); } // Catching System.IO.IOException if any catch (IOException ioe) { _logs.LogError(loggedUser, "PDF - IOException", "Error: " + ioe.Message, addres, fpath, "AuditLetters"); } catch (Exception ex) { _logs.LogError(loggedUser, "PDF - Exception", "Error: " + ex.Message, addres, fpath, "AuditLetters"); } return false; }
public ActionResult SetOtherParameters([Bind(Prefix = "id")] Guid auditorAddressId, ParametersViewModel model, string command) { try { var auditorAddress = _repository.Find<AUDITORADDRESS>(auditorAddressId); bool clearSelection = (command == "Clear"); bool commit = (command == "Create"); if (clearSelection) { Session["BaseValues"] = BaseNumbersCollection; } if (commit) { Session["ParametersSelected"] = null; BaseNumbersCollection = (List<SelectListItem>)Session["BaseValues"]; if (auditorAddress != null) { AUDITOR currentAuditor = _repository.Find<AUDITOR>(auditorAddress.AuditorId); ParametersViewModel myModel = new ParametersViewModel() { AuditorAddress = "Letter to: " + currentAuditor.AuditorName + " Address: " + auditorAddress.Address1 + "" + auditorAddress.Address2 + " E-mail: " + auditorAddress.Email, BaseNumber = "", AddressId = auditorAddress.Id, ReportDate = model.ReportDate, BaseNumberList = (List<SelectListItem>)Session["BaseValues"], Rate = model.Rate ?? "" }; Session["ParametersSelected"] = myModel; } getVals.LogAudit(User.Identity.GetUserName(), "Added", Request.UserHostName, "Added Parameters For Audit letter Creation. Values Entered are:" + " BaseNos:" + string.Join(",", (List<SelectListItem>)Session["BaseValues"]) + ": Report Date:" + model.ReportDate, "View", "AuditLetters"); Session["BaseValues"] = null; return RedirectToAction("FetchAuditData"); } else { if (model.BaseNumber != null) { // BaseNumbersCollection.Add(new SelectListItem { Text = model.BaseNumber, Value = model.BaseNumber }); if (Session["BaseValues"] != null) { BaseNumbersCollection = (List<SelectListItem>)Session["BaseValues"]; if (!BaseNumbersCollection.Any(p => p.Value == model.BaseNumber)) { BaseNumbersCollection.Add(new SelectListItem { Text = model.BaseNumber, Value = model.BaseNumber }); } Session["BaseValues"] = BaseNumbersCollection; } else { BaseNumbersCollection.Add(new SelectListItem { Text = model.BaseNumber, Value = model.BaseNumber }); Session["BaseValues"] = BaseNumbersCollection; } } else { Session["BaseValues"] = BaseNumbersCollection; } } if (auditorAddress != null) { AUDITOR currentAuditor = _repository.Find<AUDITOR>(auditorAddress.AuditorId); ParametersViewModel myModel = new ParametersViewModel() { AuditorAddress = "Letter To " + currentAuditor.AuditorName + " Address:" + auditorAddress.Address1 + "" + auditorAddress.Address2, BaseNumber = "", AddressId = auditorAddress.Id, ReportDate = model.ReportDate, BaseNumberList = (List<SelectListItem>)Session["BaseValues"], Rate = model.Rate }; return View(myModel); } return HttpNotFound(); } catch (Exception ex) { _logs.LogError(User.Identity.GetUserName(), "SetOtherParameters", "Error: " + ex.Message, Request.ServerVariables["REMOTE_ADDR"], HttpContext.Server.MapPath("."), "AuditLetters"); return HttpNotFound(); } }