improvised tarball report, and tarball pdf

This commit is contained in:
misya 2025-03-28 10:31:41 +08:00
parent 00b0e6eb0c
commit 526acc406b
7 changed files with 380 additions and 194 deletions

View File

@ -26,14 +26,35 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
{ {
var document = new TarBallPDF(); var document = new TarBallPDF();
var pdf = document.GeneratePdf(); 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) catch (Exception ex)
{ {
// Log the error (use a logger if configured) // Log the error (use a logger if configured)
Console.WriteLine(ex.Message); 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);
}
}
} }
} }

View File

@ -1,81 +1,277 @@
using Microsoft.AspNetCore.Mvc; using QuestPDF.Fluent;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
using QuestPDF.Helpers;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
public class TarBallPDF : IDocument 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) 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 row.RelativeItem(1).Element(CellStyle).Column(column =>
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(12));
// Header Section
page.Header().Column(column =>
{ {
column.Spacing(10); column.Item()
.AlignMiddle() // Ensures vertical centering
// Logo and Title .AlignCenter() // Ensures horizontal centering
column.Item().AlignCenter().Text("Company Logo Placeholder").FontSize(12).Italic(); .Text("Logo Placeholder"); // Placeholder for the logo
// 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);
}); });
// Content Section row.RelativeItem(1).Element(CellStyle)
page.Content().Column(column => .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 // Document Row
column.Item().Table(table => column.Item().Row(innerRow =>
{ {
table.ColumnsDefinition(columns => innerRow.RelativeItem(1).Element(CellStyle).Text("Document:")
{ .AlignLeft();
columns.RelativeColumn(1); // Column 1 innerRow.RelativeItem(1).Element(CellStyle).Text("F-MM06")
columns.RelativeColumn(2); // Column 2 .AlignLeft().Bold();
}); });
column.Item().Row(innerRow =>
table.Cell().Text("STATE").Bold(); {
table.Cell().Text("Your State Data Here"); innerRow.RelativeItem(1).Element(CellStyle).Text("Effective Date:")
.AlignLeft();
table.Cell().Text("STATION ID").Bold(); innerRow.RelativeItem(1).Element(CellStyle).Text("1 April 2025")
table.Cell().Text("Your Station ID Here"); .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 // Define styles
page.Footer().AlignCenter().Text(x => 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 "); container
x.CurrentPageNumber(); .PaddingTop(20) // Adds space above the text
x.Span(" of "); .PaddingBottom(10)
x.TotalPages(); .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) // Footer Section
{ page.Footer().AlignCenter().Text(text =>
// Log the exception (you can use any logging framework or method you prefer) {
Console.WriteLine($"Error generating PDF: {ex.Message}"); text.Span("Page ");
} text.CurrentPageNumber();
text.Span(" of ");
text.TotalPages();
});
static IContainer CellStyle(IContainer container) => container.Border(0.5f)
.Padding(5);
});
} }
} }
;

View File

@ -1,5 +1,5 @@
@{ @{
ViewData["Title"] = "Tar Ball Sampling Form"; ViewData["Title"] = "Tarball Report";
Layout = "~/Views/Shared/_Layout.cshtml"; Layout = "~/Views/Shared/_Layout.cshtml";
} }
<!DOCTYPE html> <!DOCTYPE html>
@ -8,13 +8,9 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> <title>
<h3>Tarball Sampling Form</h3> <h3>Tarball Report</h3>
</title> </title>
<style> <style>
div {
padding-top:10px;
padding-bottom:10px:
}
.container { .container {
width: 1200px; /* Approximate width for A4 aspect ratio */ width: 1200px; /* Approximate width for A4 aspect ratio */
margin: 20px auto; margin: 20px auto;
@ -22,160 +18,118 @@
background-color: #fff; background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
overflow: hidden; overflow: hidden;
.details-cell
} }
.form-header { div {
display: table; padding-top: 10px;
width: 100%; padding-bottom: 10px;
border-collapse: collapse;
margin-bottom: 20px;
} }
.form-header th, .form-header td { h4 {
border: 1px solid #ccc; padding-top: 15px;
padding: 10px; padding-bottom: 5px;
text-align: center;
}
.logo-cell {
width: 40%;
text-align: center;
vertical-align: middle;
}
.logo-cell img {
max-width: 20%; /*limit the cell's width*/
height: auto;
}
.title-cell {
width: 40%;
vertical-align: middle;
font-size: 14px;
}
.details-cell {
width: 10%;
text-align: left;
font-size: 14px;
} }
table { table {
width:100%;
}
datatable {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
}
th, td {
border: 1px solid #ccc; border: 1px solid #ccc;
padding: 10px;
text-align: left;
} }
th { tr {
background-color: #f2f2f2; border: 1px solid #ccc;
text-align: center; padding:10px;
} }
td { th{
background-color: #fff; border: 1px solid #ccc;
padding:10px;
} }
tbhead {
text-align:center;
}
</style> </style>
</head> </head>
<!--to be updated later for user input,etc--> <!--to be updated later for user input,db connection, etc-->
<body> <body>
<div>
<a href="/MMS/Marine/GenerateReport" class="btn btn-primary">Download PDF</a>
</div>
<div class="container"> <div class="container">
<table class="form-header">
<tr>
<td class="logo-cell" rowspan="4">
<!-- Replace with company logo -->
<img src="company-logo.png" alt="Company Logo">
</td>
<td class="details-cell" rowspan="4">
<h3>TARBALL SAMPLING FORM</h3>
</td>
</tr>
<tr>
<td class="details-cell">Document: </td>
<td class="details-cell"><strong>F-MM06</strong></td>
</tr>
<tr>
<td class="details-cell">Effective Date: </td>
<td class="details-cell"><strong>1 April 2025</strong></td>
</tr>
<tr>
<td class="details-cell">Revision No.: </td>
<td class="details-cell"><strong>02</strong></td>
</tr>
</table>
<div> <div>
<!-- --> <h4>Month</h4>
<p>Please be informed that we have observed the following conditions:</p> <select name="month" id="month" style="width: 100%; padding: 5px;">
<option value="default" selected disabled>Filter by Month</option>
<option value="january">January</option>
<option value="february">February</option>
<option value="march">March</option>
<option value="april">April</option>
<option value="may">May</option>
<option value="june">June</option>
<option value="july">July</option>
<option value="august">August</option>
<option value="september">September</option>
<option value="october">October</option>
<option value="november">November</option>
<option value="december">December</option>
</select>
<h4>Year</h4>
<select name="year" id="year" style="width: 100%; padding: 5px;">
<option value="default" selected disabled>Filter by Year</option>
<option value="January">January</option>
<!--based on database?-->
</select>
</div> </div>
<div>
<div class="datatable">
<table> <table>
<tr> <tr class="tbhead">
<td> <th>???</th>
<p>STATE</p> <th>Date</th>
</td> <th>Station</th>
<td> <th>Approval Status</th>
<p></p> <th>PDF</th>
</td>
</tr> </tr>
<tr> <tr>
<td> <th></th>
<p>STATION ID</p> <th></th>
</td> <th></th>
<td> <th>
<p></p> <button class="btn btn-success">Approve</button>
</td> <button class="btn btn-danger">Reject</button>
</tr> </th>
<tr> <th>
<td> <a href="/MMS/Marine/ViewPDF" class="btn btn-primary" target="_blank">View PDF</a>
<p>LOCATION</p> <a href="/MMS/Marine/GenerateReport" class="btn btn-primary">Download PDF</a>
</td> </th>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>TARBALL SURVEY LOCATION LONGITUDE & LATITUDE </p>
</td>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>DATE / TIME</p>
</td>
<td>
<p></p>
</td>
</tr> </tr>
</table> </table>
</div> </div>
<form> </div> <!--CONTAINER END-->
<p><strong>SURVEY FINDING:</strong></p>
<p>Tar Ball</p>
<input type="radio" id="yes" name="tarball" value="yes">
<label for="yes">YES</label>
<input type="radio" id="no" name="tarball" value="no">
<label for="no">NO</label>
<br><br>
<p>If YES, Tar Ball falls under the Classification of:</p>
<input type="checkbox" id="sand" name="classification" value="sand">
<label for="sand">Sand</label>
<input type="checkbox" id="non-sandy" name="classification" value="non-sandy">
<label for="non-sandy">Non-sandy</label>
<input type="checkbox" id="coquina" name="classification" value="coquina">
<label for="coquina">Coquina</label>
<br><br>
<p><em>*Tick wherever applicable</em></p>
</form>
</div> <!--A4 CONTAINER-->
</body> </body>
</html> </html>
@section Scripts {
<script>
document.addEventListener("DOMContentLoaded", function () {
const monthDropdown = document.getElementById("month");
const yearDropdown = document.getElementById("year");
monthDropdown.addEventListener("change", filterData);
yearDropdown.addEventListener("change", filterData);
function filterData() {
const selectedMonth = monthDropdown.value;
const selectedYear = yearDropdown.value;
console.log("Selected Month:", selectedMonth);
console.log("Selected Year:", selectedYear);
// Logic for updating or sorting data goes here
}
});
</script>
}

View File

@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace PSTW_CentralSystem.Controllers.API
{
[Route("api/[controller]")]
[ApiController]
public class MarineAPI : ControllerBase
{
}
}

View File

@ -5,6 +5,8 @@ using PSTW_CentralSystem.CustomPolicy;
using PSTW_CentralSystem.DBContext; using PSTW_CentralSystem.DBContext;
using PSTW_CentralSystem.Models; using PSTW_CentralSystem.Models;
using Serilog; using Serilog;
using QuestPDF;
using QuestPDF.Infrastructure;
internal class Program internal class Program
{ {
@ -12,6 +14,8 @@ internal class Program
{ {
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var centralConnectionString = builder.Configuration.GetConnectionString("CentralConnnection"); var centralConnectionString = builder.Configuration.GetConnectionString("CentralConnnection");
Settings.License = LicenseType.Community;
//var inventoryConnectionString = builder.Configuration.GetConnectionString("InventoryConnection"); //var inventoryConnectionString = builder.Configuration.GetConnectionString("InventoryConnection");
// Add services to the container. // Add services to the container.

View File

@ -514,7 +514,7 @@
<li class="sidebar-item"> <li class="sidebar-item">
<a class="sidebar-link waves-effect waves-dark" <a class="sidebar-link waves-effect waves-dark"
asp-area="MMS" asp-controller="Marine" asp-action="TarBallForm" aria-expanded="false"> asp-area="MMS" asp-controller="Marine" asp-action="TarBallForm" aria-expanded="false">
<i class="mdi mdi-view-dashboard"></i><span class="hide-menu">Tar Ball Sampling Form</span> <i class="mdi mdi-view-dashboard"></i><span class="hide-menu">Tarball Report</span>
</a> </a>
</li> </li>
</ul> </ul>

BIN
document.pdf Normal file

Binary file not shown.