Ejemplo n.º 1
0
 private static void FillPdfDocumentContent(Document document, MonthlyCarUsage monthlyCarUsage)
 {
     document.Add(KilometrowkaTextHelper.GetLeftHightConstText());
     document.Add(KilometrowkaTextHelper.GetHeader());
     document.Add(KilometrowkaTextHelper.GetCarData(monthlyCarUsage.Month.ToString(), monthlyCarUsage.Year.ToString()));
     document.Add(KilometrowkaTextHelper.GetUsageTable(monthlyCarUsage));
 }
Ejemplo n.º 2
0
        private MonthlyCarUsage GenerateRandomizedCarUsage(MonthDate monthDate)
        {
            var monthlyUsage = new MonthlyCarUsage();
            var workDays     = this.GetWorkDays(monthDate);

            for (int i = 0; i < workDays.Count; i++)
            {
                int workDay              = workDays[i];
                var correctDate          = new DateTime(monthDate.Year, monthDate.Month, workDay);
                var chosenTemplateResult = CarUsageRng.GetRandomizedCarUsage();
                monthlyUsage.Month = monthDate.Month;
                monthlyUsage.Year  = monthDate.Year;
                monthlyUsage.CarUsages.Add(new DailyCarUsage()
                {
                    Number                = i + 1,
                    Date                  = correctDate.ToString("dd.MM.yyyy"),
                    KilometersAmount      = chosenTemplateResult.KilometersAmount,
                    RouteDescription      = chosenTemplateResult.RouteDescriptions,
                    TravelPurpose         = chosenTemplateResult.TravelPurposes,
                    OneKilometerRateValue = CarInfoRepository.GetCostRateValue()
                });
            }
            monthlyUsage.RecalculateAll();

            return(monthlyUsage);
        }
Ejemplo n.º 3
0
        private static void GeneratePdfDocument(MonthlyCarUsage monthlyUsage)
        {
            // Prepare paths
            string nowDateSalt = DateTime.Now.ToString("yyyyMMddHHmmss");
            string filePath    = String.Format(@"{0}\kilometrowka_{1}.pdf",
                                               Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase),
                                               nowDateSalt);
            string localPath = new Uri(filePath).LocalPath;

            // Generate pdf
            using (FileStream fileStream = new FileStream(localPath, FileMode.CreateNew))
            {
                Document  document = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20);
                PdfWriter writer   = PdfWriter.GetInstance(document, fileStream);
                document.Open(); //open the document in order to write inside.

                // Fill document content
                FillPdfDocumentContent(document, monthlyUsage);

                document.Close();
            };
        }
Ejemplo n.º 4
0
 public static void GeneratePdfToFile(MonthlyCarUsage monthlyUsage)
 {
     GeneratePdfDocument(monthlyUsage);
 }
        public static PdfPTable GetUsageTable(MonthlyCarUsage monthlyCarUsage)
        {
            // Init values
            string    whiteSpace = " ";
            PdfPTable table      = new PdfPTable(9);

            table.HeaderRows = 1;
            Font headersFont = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1257, 9f, Font.NORMAL);
            Font cellsFont   = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1257, 7f, Font.NORMAL);

            // Header
            table.AddCell(new PdfPCell(new Phrase("Nr kolejny wpisu", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Data wyjazdu", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Opis trasy wyjadu (skąd - dokąd)", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Cel wyjazdu", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Liczba faktycznie przejechanych kilometrów", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Stawka za 1 kilometr przebiegu (zł, gr)", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Wartość (zł, gr)", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Podpis pracodawcy", headersFont)));
            table.AddCell(new PdfPCell(new Phrase("Uwagi", headersFont)));

            // Cells in rows
            foreach (var dailyUsage in monthlyCarUsage.CarUsages)
            {
                table.AddCell(new PdfPCell(new Phrase(dailyUsage.Number.ToString(), cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(dailyUsage.Date, cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(dailyUsage.RouteDescription, cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(dailyUsage.TravelPurpose, cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(dailyUsage.KilometersAmount.ToString(), cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(dailyUsage.OneKilometerRateValue.ToString(), cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(dailyUsage.SummedCostValue.ToString(), cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(whiteSpace, cellsFont)));
                table.AddCell(new PdfPCell(new Phrase(whiteSpace, cellsFont)));
            }

            // Empty row
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);

            // Summary
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);
            table.AddCell(new PdfPCell(new Phrase("Razem", cellsFont)));
            table.AddCell(new PdfPCell(new Phrase(monthlyCarUsage.TotalKilometersAmount.ToString(), cellsFont)));
            table.AddCell(whiteSpace);
            table.AddCell(new PdfPCell(new Phrase(monthlyCarUsage.TotalCostValue.ToString(), cellsFont)));
            table.AddCell(whiteSpace);
            table.AddCell(whiteSpace);

            // Add spacings
            table.SpacingBefore = 25f;

            return(table);
        }