|
@@ -0,0 +1,396 @@
|
|
|
+using iText.Kernel.Colors;
|
|
|
+using iText.Kernel.Font;
|
|
|
+using iText.Kernel.Pdf;
|
|
|
+using iText.Layout;
|
|
|
+using iText.Layout.Element;
|
|
|
+using iText.Layout.Properties;
|
|
|
+using MTWorkHR.Core.Entities;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using DevExpress.CodeParser;
|
|
|
+using iText.Kernel.Events;
|
|
|
+using Event = iText.Kernel.Events.Event;
|
|
|
+using MTWorkHR.Core.Global;
|
|
|
+using MTWorkHR.Infrastructure.Entities;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+
|
|
|
+namespace MTWorkHR.Infrastructure.Reports
|
|
|
+{
|
|
|
+ public class ContractPdfGenerator
|
|
|
+ {
|
|
|
+ public async Task<byte[]> GenerateContractPdf(string outputPath, ContractDetail contractData)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+
|
|
|
+ using (MemoryStream memoryStream = new MemoryStream())
|
|
|
+ {
|
|
|
+ using (PdfWriter writer = new PdfWriter(memoryStream))
|
|
|
+ using (PdfDocument pdf = new PdfDocument(writer))
|
|
|
+ using (Document document = new Document(pdf))
|
|
|
+ {
|
|
|
+ PdfFont boldFont = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA_BOLD);
|
|
|
+ PdfFont regularFont = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA);
|
|
|
+
|
|
|
+
|
|
|
+ document.Add(new Paragraph($"{DateTime.Now:dd/MM/yyyy HH:mm:ss} .")
|
|
|
+ .SetFont(regularFont)
|
|
|
+ .SetFontSize(10));
|
|
|
+ document.Add(new Paragraph("Employee Contract")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(20)
|
|
|
+ .SetMarginBottom(20)
|
|
|
+ .SetTextAlignment(TextAlignment.CENTER));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Company Information:")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12));
|
|
|
+ Table companyTable = new Table(new float[] { 1, 3, 1, 1 }).UseAllAvailableWidth();
|
|
|
+ companyTable.AddCell(CreateCell("Name:", boldFont));
|
|
|
+ companyTable.AddCell(CreateCell(contractData.CompanyName, regularFont));
|
|
|
+ companyTable.AddCell(CreateCell("CR:", boldFont));
|
|
|
+ companyTable.AddCell(CreateCell(contractData.CompanyCR, regularFont));
|
|
|
+ companyTable.AddCell(CreateCell("Email:", boldFont));
|
|
|
+ companyTable.AddCell(CreateCell(contractData.CompanyEmail, regularFont));
|
|
|
+ companyTable.AddCell(CreateCell("Phone:", boldFont));
|
|
|
+ companyTable.AddCell(CreateCell(contractData.CompanyPhone, regularFont));
|
|
|
+ companyTable.AddCell(CreateCell("Address:", boldFont));
|
|
|
+ companyTable.AddCell(CreateCell(contractData.CompanyAddress, regularFont, 3));
|
|
|
+ document.Add(companyTable);
|
|
|
+
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Company Representative:")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+
|
|
|
+
|
|
|
+ Table repTable = new Table(new float[] { 1, 3 }).UseAllAvailableWidth();
|
|
|
+
|
|
|
+
|
|
|
+ repTable.AddCell(CreateCell("Name:", boldFont));
|
|
|
+ repTable.AddCell(CreateCell(contractData.CompanyRepresentativeName, regularFont));
|
|
|
+
|
|
|
+
|
|
|
+ repTable.AddCell(CreateCell("Passport:", boldFont));
|
|
|
+ repTable.AddCell(CreateCell(contractData.CompanyRepresentativePassport, regularFont));
|
|
|
+
|
|
|
+
|
|
|
+ repTable.AddCell(CreateCell("Phone:", boldFont));
|
|
|
+ repTable.AddCell(CreateCell(contractData.CompanyRepresentativePhone, regularFont));
|
|
|
+
|
|
|
+
|
|
|
+ repTable.AddCell(CreateCell("Email:", boldFont));
|
|
|
+ repTable.AddCell(CreateCell(contractData.CompanyRepresentativeEmail, regularFont));
|
|
|
+
|
|
|
+
|
|
|
+ repTable.AddCell(CreateCell("Position:", boldFont));
|
|
|
+ repTable.AddCell(CreateCell(contractData.CompanyRepresentativePosition, regularFont));
|
|
|
+
|
|
|
+ document.Add(repTable);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Employee Information:")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+ document.Add(new Paragraph($"Name: \t {contractData.EmployeeName}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Passport: \t {contractData.EmployeePassport}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Date Of Birth: \t {contractData.EmployeeDateOfBirth:dd/MM/yyyy}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Phone: \t {contractData.EmployeePhone}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"University: \t {contractData.EmployeeUniversity}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Work Country: \t {contractData.WorkCountry}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Job: \t {contractData.JobTitleName}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Job Number: \t {contractData.JobNumber}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Job Description: \t {contractData.JobDescription}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Contract")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+ Table contractTable = new Table(new float[] { 1, 3, 1, 3 }).UseAllAvailableWidth();
|
|
|
+ contractTable.AddCell(CreateCell("Start Date:", boldFont));
|
|
|
+ contractTable.AddCell(CreateCell($"{contractData.StartDate:dd/MM/yyyy}", regularFont));
|
|
|
+ contractTable.AddCell(CreateCell("End Date:", boldFont));
|
|
|
+ contractTable.AddCell(CreateCell($"{contractData.EndDate:dd/MM/yyyy}", regularFont));
|
|
|
+ contractTable.AddCell(CreateCell("Duration:", boldFont));
|
|
|
+ contractTable.AddCell(CreateCell($"{contractData.ContractDuration}", regularFont));
|
|
|
+ contractTable.AddCell(CreateCell("Contract Type:", boldFont));
|
|
|
+ contractTable.AddCell(CreateCell((ContractTypeEnum)contractData.ContractTypeId + "", regularFont));
|
|
|
+ contractTable.AddCell(CreateCell("Vacation Days:", boldFont));
|
|
|
+ contractTable.AddCell(CreateCell($"{contractData.VacationDays}", regularFont));
|
|
|
+ contractTable.AddCell(CreateCell("Trial Period:", boldFont));
|
|
|
+ contractTable.AddCell(CreateCell($"{contractData.TrialPeriod}", regularFont));
|
|
|
+ contractTable.AddCell(CreateCell("Termination Notice Period:", boldFont));
|
|
|
+ contractTable.AddCell(CreateCell($"{contractData.NoticePeriodBeforeTermination}", regularFont));
|
|
|
+ document.Add(contractTable);
|
|
|
+
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Work Time")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+ document.Add(new Paragraph($"Working Days: \t {contractData.WorkingDays}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+ document.Add(new Paragraph($"Working Hours: \t {contractData.WorkingHours}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Salary")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+ document.Add(new Paragraph($"Amount: \t {contractData.Salary:F2} {contractData.Currency}")
|
|
|
+ .SetFont(regularFont));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (contractData.FixedAllowances != null && contractData.FixedAllowances.Count > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Allowances")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+
|
|
|
+ Table allowanceTable = new Table(new float[] { 2, 1, 2, 1 }).UseAllAvailableWidth();
|
|
|
+ allowanceTable.AddHeaderCell(CreateCell("Type", boldFont));
|
|
|
+ allowanceTable.AddHeaderCell(CreateCell("Rate", boldFont));
|
|
|
+ allowanceTable.AddHeaderCell(CreateCell("Amount", boldFont));
|
|
|
+ allowanceTable.AddHeaderCell(CreateCell("Frequency", boldFont));
|
|
|
+ foreach (var allowance in contractData.FixedAllowances)
|
|
|
+ {
|
|
|
+ allowanceTable.AddCell(CreateCell(allowance.AllowanceType + "", regularFont));
|
|
|
+ allowanceTable.AddCell(CreateCell($"{allowance.PaymentType:F2}", regularFont));
|
|
|
+ allowanceTable.AddCell(CreateCell($"{allowance.EntitlementAmount:F2}", regularFont));
|
|
|
+ allowanceTable.AddCell(CreateCell($"{allowance.EntitlementPercent}", regularFont));
|
|
|
+ }
|
|
|
+ document.Add(allowanceTable);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (contractData.ProjectStages != null && contractData.ProjectStages.Count >0)
|
|
|
+ {
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Project Stages")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+ Table ProjectStagesTable = new Table(new float[] { 1, 3 }).UseAllAvailableWidth();
|
|
|
+ ProjectStagesTable.AddHeaderCell(CreateCell("Title", boldFont));
|
|
|
+ ProjectStagesTable.AddHeaderCell(CreateCell("Scope of work", boldFont));
|
|
|
+ foreach (var allowance in contractData.ProjectStages)
|
|
|
+ {
|
|
|
+ ProjectStagesTable.AddCell(CreateCell(allowance.Title + "", regularFont));
|
|
|
+ ProjectStagesTable.AddCell(CreateCell($"{allowance.ScopeOfWork:F2}", regularFont));
|
|
|
+ }
|
|
|
+ document.Add(ProjectStagesTable);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (contractData.ContractTasks != null && contractData.ContractTasks.Count > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ document.Add(new Paragraph("Contract Tasks")
|
|
|
+ .SetFont(boldFont)
|
|
|
+ .SetFontSize(12)
|
|
|
+ .SetMarginTop(10));
|
|
|
+ Table ContractTasksTable = new Table(new float[] { 1, 3, 1, 3 }).UseAllAvailableWidth();
|
|
|
+ ContractTasksTable.AddHeaderCell(CreateCell("Title", boldFont));
|
|
|
+ ContractTasksTable.AddHeaderCell(CreateCell("Scope of work", boldFont));
|
|
|
+ ContractTasksTable.AddHeaderCell(CreateCell("StartDate", boldFont));
|
|
|
+ ContractTasksTable.AddHeaderCell(CreateCell("Amount", boldFont));
|
|
|
+ foreach (var allowance in contractData.ContractTasks)
|
|
|
+ {
|
|
|
+ ContractTasksTable.AddCell(CreateCell(allowance.Title + "", regularFont));
|
|
|
+ ContractTasksTable.AddCell(CreateCell($"{allowance.ScopeOfWork:F2}", regularFont));
|
|
|
+ ContractTasksTable.AddCell(CreateCell($"{allowance.StartDate:dd/MM/yyyy}", regularFont));
|
|
|
+ ContractTasksTable.AddCell(CreateCell($"{allowance.Amount:F2}", regularFont));
|
|
|
+ }
|
|
|
+ document.Add(ContractTasksTable);
|
|
|
+ }
|
|
|
+
|
|
|
+ pdf.AddEventHandler(PdfDocumentEvent.END_PAGE, new PageNumberEventHandler(document));
|
|
|
+ }
|
|
|
+ byte[] pdfBytes = memoryStream.ToArray();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return pdfBytes;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public byte[] GeneratePdf()
|
|
|
+ {
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var stream = new MemoryStream())
|
|
|
+ {
|
|
|
+ PdfWriter writer = new PdfWriter(stream);
|
|
|
+ PdfDocument pdf = new PdfDocument(writer);
|
|
|
+ Document document = new Document(pdf);
|
|
|
+ document.Add(new Paragraph("Hello, Azure App Service!"));
|
|
|
+ document.Close();
|
|
|
+
|
|
|
+ return stream.ToArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Cell CreateCell(string text, PdfFont font, int colspan = 1)
|
|
|
+ {
|
|
|
+ return new Cell(1, colspan).Add(new Paragraph(text).SetFont(font).SetFontSize(10));
|
|
|
+ }
|
|
|
+
|
|
|
+ private class PageNumberEventHandler : IEventHandler
|
|
|
+ {
|
|
|
+ private readonly Document _document;
|
|
|
+
|
|
|
+ public PageNumberEventHandler(Document document)
|
|
|
+ {
|
|
|
+ _document = document;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void HandleEvent(Event @event)
|
|
|
+ {
|
|
|
+ PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
|
|
|
+ PdfDocument pdf = docEvent.GetDocument();
|
|
|
+ PdfPage page = docEvent.GetPage();
|
|
|
+ int pageNumber = pdf.GetPageNumber(page);
|
|
|
+ PdfFont font = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA);
|
|
|
+
|
|
|
+ _document.ShowTextAligned(
|
|
|
+ new Paragraph($"Page {pageNumber}").SetFont(font).SetFontSize(10),
|
|
|
+ 550, 20, pageNumber, TextAlignment.RIGHT, VerticalAlignment.BOTTOM, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|