diff --git a/Areas/MMS/Controllers/MarineController.cs b/Areas/MMS/Controllers/MarineController.cs index 0021d97..c3d1fe2 100644 --- a/Areas/MMS/Controllers/MarineController.cs +++ b/Areas/MMS/Controllers/MarineController.cs @@ -26,14 +26,35 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers { var document = new TarBallPDF(); var pdf = document.GeneratePdf(); - return File(pdf, "application/pdf", "TarBallReport.pdf"); + var fileName = $"TarBallReport_{DateTime.Now:yyyyMMdd_HHmmss}.pdf"; + return File(pdf, "application/pdf", fileName); } catch (Exception ex) { // Log the error (use a logger if configured) Console.WriteLine(ex.Message); - return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while generating the PDF."); + return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while generating the PDF. "+ex.Message); } } + + public IActionResult ViewPDF() + { + try + { + // Generate the PDF document + var document = new TarBallPDF(); + var pdf = document.GeneratePdf(); + + // Return the PDF for inline viewing + return File(pdf, "application/pdf"); + } + catch (Exception ex) + { + // Log the error (use a logger if configured) + Console.WriteLine(ex.Message); + return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while viewing the PDF. " + ex.Message); + } + } + } } diff --git a/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs index ad1aa45..e79fa8f 100644 --- a/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs +++ b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs @@ -1,81 +1,277 @@ -using Microsoft.AspNetCore.Mvc; -using QuestPDF.Fluent; -using QuestPDF.Helpers; +using QuestPDF.Fluent; using QuestPDF.Infrastructure; +using QuestPDF.Helpers; +using Microsoft.EntityFrameworkCore.Metadata.Internal; public class TarBallPDF : IDocument { - public DocumentMetadata GetMetadata() => DocumentMetadata.Default; + public DocumentMetadata GetMetadata() => new DocumentMetadata + { + Title = "TarBall Sampling Form", + Author = "PAKAR SCIENO TW Integrated Environmental Solutions", + Subject = "Environmental Survey and Observations" + }; public void Compose(IDocumentContainer container) { - try + container.Page(page => { - container.Page(page => + // Page Setup + page.Size(PageSizes.A4); + page.Margin(1.1f, Unit.Centimetre); + page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(10)); + + // Header Section + page.Header().Row(row => { - // Page Setup - page.Size(PageSizes.A4); - page.Margin(2, Unit.Centimetre); - page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(12)); - - // Header Section - page.Header().Column(column => + row.RelativeItem(1).Element(CellStyle).Column(column => { - column.Spacing(10); - - // Logo and Title - column.Item().AlignCenter().Text("Company Logo Placeholder").FontSize(12).Italic(); - - // Document Details - column.Item().Text("Document: F-MM06").FontSize(14); - column.Item().Text("Effective Date: 1 April 2025").FontSize(14); - column.Item().Text("Revision No.: 02").FontSize(14); + column.Item() + .AlignMiddle() // Ensures vertical centering + .AlignCenter() // Ensures horizontal centering + .Text("Logo Placeholder"); // Placeholder for the logo }); - // Content Section - page.Content().Column(column => + row.RelativeItem(1).Element(CellStyle) + .AlignMiddle() // Ensures vertical centering + .AlignCenter() // Ensures horizontal centering + .Text("TARBALL SAMPLING FORM") + .FontSize(16) + .FontColor("#4B0082"); + + row.RelativeItem(1).Column(column => { - column.Spacing(20); + column.Spacing(0); // Adds consistent spacing between rows - // Table Section - column.Item().Table(table => + // Document Row + column.Item().Row(innerRow => { - table.ColumnsDefinition(columns => - { - columns.RelativeColumn(1); // Column 1 - columns.RelativeColumn(2); // Column 2 - }); - - table.Cell().Text("STATE").Bold(); - table.Cell().Text("Your State Data Here"); - - table.Cell().Text("STATION ID").Bold(); - table.Cell().Text("Your Station ID Here"); + innerRow.RelativeItem(1).Element(CellStyle).Text("Document:") + .AlignLeft(); + innerRow.RelativeItem(1).Element(CellStyle).Text("F-MM06") + .AlignLeft().Bold(); + }); + column.Item().Row(innerRow => + { + innerRow.RelativeItem(1).Element(CellStyle).Text("Effective Date:") + .AlignLeft(); + innerRow.RelativeItem(1).Element(CellStyle).Text("1 April 2025") + .AlignLeft(); + }); + column.Item().Row(innerRow => + { + innerRow.RelativeItem(1).Element(CellStyle).Text("Revision No.") + .AlignLeft(); + innerRow.RelativeItem(1).Element(CellStyle).Text("02") + .AlignLeft(); }); - // Survey Findings Section - column.Item().Text("SURVEY FINDING").Bold().FontSize(14); - column.Item().Text("Tar Ball ☐ Yes ☐ No"); - column.Item().Text("If YES, Tar Ball falls under the classification of:"); - column.Item().Text("☐ Sand ☐ Non-sandy ☐ Coquina"); }); - // Footer Section - page.Footer().AlignCenter().Text(x => + // Define styles + static IContainer CellStyle(IContainer container) + => container.Border(0.5f).Padding(5); // Retains padding for text + }); + + // Content Section + page.Content().Column(column => + { + // Observations Table + column.Item().Element(container => { - x.Span("Page "); - x.CurrentPageNumber(); - x.Span(" of "); - x.TotalPages(); + container + .PaddingTop(20) // Adds space above the text + .PaddingBottom(10) + .Text("Please be informed that we have observed the following conditions:"); + }); + column.Item().Table(table => + { + column.Spacing(0); + + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(3); // Label/Header column + columns.RelativeColumn(3); // Data Entry column + }); + + // Table Rows + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("STATE") + .Bold(); + table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("STATION ID") + .Bold(); + table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("LOCATION") + .Bold(); + table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("TARBALL SURVEY LOCATION LONGITUDE & LATITUDE") + .Bold(); + table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("DATE / TIME") + .Bold(); + table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry + }); + + column.Spacing(3); + + // Survey Findings + column.Item() + .PaddingTop(10) // Adds space above the text + .PaddingBottom(10) + .Text("SURVEY FINDING:") + .Bold().FontSize(12); + column.Item() + .PaddingBottom(10) + .Text("Tar Ball: [☐] YES [☐] NO").FontSize(10); + column.Item() + .PaddingBottom(10) + .Text("If YES, Tar Ball falls under the classification of:").FontSize(10); + column.Item() + .PaddingBottom(10) + .Text("[☐] Sand [☐] Non-sandy [☐] Coquina").FontSize(10); + column.Item() + .PaddingBottom(10) + .Text("*tick wherever applicable"); + + // Photos Section Title + column.Item() + .PaddingBottom(5) + .Text("PHOTOGRAPHS OF SAMPLING") + .AlignCenter() // Ensures horizontal centering + .Bold() + .FontSize(14); + + // Table for Photos with Existing Heights + column.Item().Table(table => + { + column.Spacing(0); // No extra spacing between rows + + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(1); // First column + columns.RelativeColumn(1); // Second column + }); + + // For pictures + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + table.Cell().Element(CellStyle).Text("Figure 1: Left Side Coastal View").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 2: Right Side Coastal View").FontSize(12).AlignLeft(); + + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + table.Cell().Element(CellStyle).Text("Figure 3: Drawing Vertical Lines").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 4: Drawing Horizontal Lines (Racking)").FontSize(12).AlignLeft(); + }); + + // Page Break + column.Item().PageBreak(); + + // Additional Photos Section + column.Item() + .PaddingBottom(5) + .AlignCenter(); // Ensures horizontal centering + + // Table for Additional Photos + column.Item().Table(table => + { + column.Spacing(0); // No extra spacing between rows + + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(1); // First column + columns.RelativeColumn(1); // Second column + }); + + // Row 1: Empty spaces for pictures + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + // Row 2: Labels for the pictures + table.Cell().Element(CellStyle).Text("Figure 5:").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 6:").FontSize(12).AlignLeft(); + + // Row 3: Empty spaces for pictures + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + // Row 4: Labels for the pictures + table.Cell().Element(CellStyle).Text("Figure 7:").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 8:").FontSize(12).AlignLeft(); + }); + + // Note Section + column.Item() + .PaddingTop(10) + .PaddingBottom(20) + .Text("* If there are any event observe at the current station it is compulsory to add optional photo with description (figure 5 to figure 8)") + .FontSize(10) + .AlignLeft(); + + // Signature Section + column.Item().Table(table => + { + //define how many columns the table has + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(2); // Label column + columns.RelativeColumn(1); // Signature column + columns.RelativeColumn(2); //empty + columns.RelativeColumn(1); // Date column + columns.RelativeColumn(1); //empty + }); + + // Signature Rows + table.Cell().RowSpan(2).Element(CellStyle).Text("REPORTED BY :").Bold().FontSize(12); + table.Cell().Element(CellStyle).Text("Signature").FontSize(12); + table.Cell().Element(CellStyle).Text("").FontSize(12); + table.Cell().Element(CellStyle).Text("Date").FontSize(12); + table.Cell().Element(CellStyle).Text("").FontSize(12); + + table.Cell().Element(CellStyle).Text("Designation").FontSize(12); + table.Cell().ColumnSpan(3).Element(CellStyle).Text("").FontSize(12); + + table.Cell().RowSpan(2).Element(CellStyle).Text("CHECKED BY :").Bold().FontSize(12); + table.Cell().Element(CellStyle).Text("Signature").FontSize(12); + table.Cell().Element(CellStyle).Text("").FontSize(12); + table.Cell().Element(CellStyle).Text("Date").FontSize(12); + table.Cell().Element(CellStyle).Text("").FontSize(12); + + table.Cell().Element(CellStyle).Text("Designation").FontSize(12); + table.Cell().ColumnSpan(3).Element(CellStyle).Text("").FontSize(12); + + table.Cell().RowSpan(2).Element(CellStyle).Text("VERIFIED BY :").Bold().FontSize(12); + table.Cell().Element(CellStyle).Text("Signature").FontSize(12); + table.Cell().Element(CellStyle).Text("").FontSize(12); + table.Cell().Element(CellStyle).Text("Date").FontSize(12); + table.Cell().Element(CellStyle).Text("").FontSize(12); + + table.Cell().Element(CellStyle).Text("Designation").FontSize(12); + table.Cell().ColumnSpan(3).Element(CellStyle).Text("").FontSize(12); }); }); - } - catch (Exception ex) - { - // Log the exception (you can use any logging framework or method you prefer) - Console.WriteLine($"Error generating PDF: {ex.Message}"); - } + + // Footer Section + page.Footer().AlignCenter().Text(text => + { + text.Span("Page "); + text.CurrentPageNumber(); + text.Span(" of "); + text.TotalPages(); + }); + static IContainer CellStyle(IContainer container) => container.Border(0.5f) + .Padding(5); + }); } } -; - diff --git a/Areas/MMS/Views/Marine/TarBallForm.cshtml b/Areas/MMS/Views/Marine/TarBallForm.cshtml index be03193..5c680a4 100644 --- a/Areas/MMS/Views/Marine/TarBallForm.cshtml +++ b/Areas/MMS/Views/Marine/TarBallForm.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "Tar Ball Sampling Form"; + ViewData["Title"] = "Tarball Report"; Layout = "~/Views/Shared/_Layout.cshtml"; } @@ -8,13 +8,9 @@
-
-
- |
-
- TARBALL SAMPLING FORM- |
-
| Document: | -F-MM06 | -
| Effective Date: | -1 April 2025 | -
| Revision No.: | -02 | -
Please be informed that we have observed the following conditions:
+|
- STATE - |
- - - | +|||||
| ??? | +Date | +Station | +Approval Status | +|||
|---|---|---|---|---|---|---|
|
- STATION ID - |
- - - | -|||||
|
- LOCATION - |
- - - | -|||||
|
- TARBALL SURVEY LOCATION LONGITUDE & LATITUDE - |
- - - | -|||||
|
- DATE / TIME - |
- - - | ++ | + | + | + + + | ++ View PDF + Download PDF + |