public UpsertModel CreatePaymentsReport(IEnumerable <Student> students) { var upsert = new UpsertModel(); try { string docName = @"Payments_Report.pdf"; docName = FileService.RemoveIllegalCharacters(docName, true); string destinationFolder = "~/App_Data";//Settings.DOCFOLDER; string logo = HttpContext.Current.Server.MapPath("~/Content/Imgs/ss_logo.png"); // Create a temp folder if not there string temp_folder = FileService.CreateFolder(string.Format(@"{0}\Reports\Temp", destinationFolder)); // Work on the Temp File string abs_TempDoc = String.Format(@"{0}\{1}", temp_folder, docName); destinationFolder = Settings.DOCFOLDER; // Save to New File string abs_NewDoc = String.Format(@"{0}\Reports\{1}", destinationFolder, docName); // Delete the old temp file FileService.DeleteFile(abs_TempDoc); // Create a document var doc = new Document(PageSize.A4); // Make landscape doc.SetPageSize(PageSize.A4.Rotate()); // Create the document object PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(abs_TempDoc, FileMode.Create)); // Events ITextEvents header = new ITextEvents(); writer.PageEvent = header; // Open for editing/creation doc.Open(); // Lets go! // ++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++ START ++++++++++++++++++++ PdfPTable table; List <float> cellWidths; PdfPCell cell; //Paragraph paragraph; //Chunk chunk; //SteppingStone Logo doc.Add(ImageCell(logo)); doc.Add(ParseHeading(string.Format("{0} Fees Report ", Settings.COMPANY_NAME))); cellWidths = new List <float> { 3f, 17f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f }; table = SetTable(cellWidths.ToArray(), true, true); table.AddCell(SmallBlackLabelCell("#")); table.AddCell(SmallBlackLabelCell("Pupil name")); table.AddCell(SmallBlackLabelCell("1st Installment")); table.AddCell(SmallBlackLabelCell("2nd Installment")); table.AddCell(SmallBlackLabelCell("Transport")); table.AddCell(SmallBlackLabelCell("Swimming")); table.AddCell(SmallBlackLabelCell("Old Debt")); table.AddCell(SmallBlackLabelCell("Total")); table.AddCell(SmallBlackLabelCell("Total Pay't")); table.AddCell(SmallBlackLabelCell("Total Balance")); int counter = 0; double OldDebt = 0; double AmountToPay = 0; double PaymentsTotal = 0; double Outstanding = 0; double firstPayts = 0; double otherPayts = 0; double Transport = 0; double Swimming = 0; foreach (var student in students) { counter++; table.AddCell(DefaultCell(counter.ToString())); table.AddCell(DefaultCell(student.FullName)); table.AddCell(DefaultCell(student.FirstCurrentTermPayment.ToString("n0"))); firstPayts = firstPayts + student.FirstCurrentTermPayment; table.AddCell(DefaultCell(student.OtherCurrentTermPayments.ToString("n0"))); otherPayts = otherPayts + student.OtherCurrentTermPayments; table.AddCell(DefaultCell(student.Transport.ToString("n0"))); Transport = Transport + student.Transport; table.AddCell(DefaultCell(student.Swimming.ToString("n0"))); Swimming = Swimming + student.Swimming; // increment totals table.AddCell(DefaultCell(student.OldDebt.ToString("n0"))); OldDebt = OldDebt + student.OldDebt; table.AddCell(DefaultCell(student.AmountToPay.ToString("n0"))); AmountToPay = AmountToPay + student.AmountToPay; table.AddCell(DefaultCell(student.StudentTermPaymentsTotal().ToString("n0"))); PaymentsTotal = PaymentsTotal + student.StudentTermPaymentsTotal(); table.AddCell(DefaultCell(student.Outstanding.ToString("n0"))); Outstanding = Outstanding + student.Outstanding; } cell = SmallBlackLabelCell(counter.ToString() + " Pupils"); cell.Colspan = 2; table.AddCell(cell); table.AddCell(SmallBlackLabelCell(firstPayts.ToString("n0"))); table.AddCell(SmallBlackLabelCell(otherPayts.ToString("n0"))); table.AddCell(SmallBlackLabelCell(Transport.ToString("n0"))); table.AddCell(SmallBlackLabelCell(Swimming.ToString("n0"))); table.AddCell(SmallBlackLabelCell(OldDebt.ToString("n0"))); table.AddCell(SmallBlackLabelCell(AmountToPay.ToString("n0"))); table.AddCell(SmallBlackLabelCell(PaymentsTotal.ToString("n0"))); table.AddCell(SmallBlackLabelCell(Outstanding.ToString("n0"))); doc.Add(table); // +++++++++++++++++ FINISH +++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++ // Close and Save the document doc.Close(); doc.Dispose(); writer.Dispose(); // Delete the saved file FileService.DeleteFile(abs_NewDoc); // Save the temp file to the save file File.Copy(abs_TempDoc, abs_NewDoc); upsert.RecordId = 1.ToString(); upsert.ErrorMsg = docName; } catch (Exception ex) { upsert.ErrorMsg = ex.Message; } return(upsert); }
public UpsertModel CreateClassesReport(IEnumerable <ClassLevel> classes) { var upsert = new UpsertModel(); try { string docName = @"Classes_Report.pdf"; docName = FileService.RemoveIllegalCharacters(docName, true); string destinationFolder = Settings.DOCFOLDER; string logo = HttpContext.Current.Server.MapPath("~/Content/Imgs/glo_ss_logo.png"); // Create a temp folder if not there string temp_folder = FileService.CreateFolder(string.Format(@"{0}\Reports\Temp", destinationFolder)); // Work on the Temp File string abs_TempDoc = String.Format(@"{0}\{1}", temp_folder, docName); // Save to New File string abs_NewDoc = String.Format(@"{0}\Reports\{1}", destinationFolder, docName); // Delete the old temp file FileService.DeleteFile(abs_TempDoc); // Create a document var doc = new Document(PageSize.A4); // Make landscape doc.SetPageSize(PageSize.A4.Rotate()); // Create the document object PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(abs_TempDoc, FileMode.Create)); // Events ITextEvents header = new ITextEvents(); writer.PageEvent = header; // Open for editing/creation doc.Open(); // Lets go! // ++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++ START ++++++++++++++++++++ PdfPTable table; List <float> cellWidths; PdfPCell cell; //Paragraph paragraph; //Chunk chunk; //SteppingStone Logo doc.Add(ImageCell(logo)); doc.Add(ParseHeading(string.Format("{0} Class Report ", Settings.COMPANY_NAME))); cellWidths = new List <float> { 3f, 17f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f }; table = SetTable(cellWidths.ToArray(), true, true); table.AddCell(SmallBlackLabelCell("#")); table.AddCell(SmallBlackLabelCell("Class")); table.AddCell(SmallBlackLabelCell("No. Pupils")); table.AddCell(SmallBlackLabelCell("Total Payments (Ugx)")); table.AddCell(SmallBlackLabelCell("Balance (Ugx)")); table.AddCell(SmallBlackLabelCell("Payment Ratio")); int counter = 0; double PaymentsTotal = 0; double Outstanding = 0; double Students = 0; foreach (var classLevel in classes) { counter++; table.AddCell(DefaultCell(counter.ToString())); table.AddCell(DefaultCell(classLevel.GetClass())); table.AddCell(DefaultCell(classLevel.StudentsThisTerm.Count().ToString())); Students = Students + classLevel.StudentsThisTerm.Count(); table.AddCell(DefaultCell(classLevel.GetTermTotal())); PaymentsTotal = PaymentsTotal + classLevel.TotalRevenue; table.AddCell(DefaultCell(classLevel.Outstanding.ToString("n0"))); Outstanding = Outstanding + classLevel.Outstanding; table.AddCell(DefaultCell(classLevel.Ratio.ToString())); } cell = SmallBlackLabelCell(counter.ToString() + " Classes"); cell.Colspan = 2; table.AddCell(cell); table.AddCell(SmallBlackLabelCell(Students.ToString("n0"))); table.AddCell(SmallBlackLabelCell(PaymentsTotal.ToString("n0"))); table.AddCell(SmallBlackLabelCell(Outstanding.ToString("n0"))); doc.Add(table); // +++++++++++++++++ FINISH +++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++ // Close and Save the document doc.Close(); doc.Dispose(); writer.Dispose(); // Delete the saved file FileService.DeleteFile(abs_NewDoc); // Save the temp file to the save file File.Copy(abs_TempDoc, abs_NewDoc); upsert.RecordId = 1.ToString(); upsert.ErrorMsg = docName; } catch (Exception ex) { upsert.ErrorMsg = ex.Message; } return(upsert); }