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 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);
}
}
}
}

View File

@ -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 =>
{
// Page Setup
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(12));
page.Margin(1.1f, Unit.Centimetre);
page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(10));
// Header Section
page.Header().Column(column =>
page.Header().Row(row =>
{
column.Spacing(10);
row.RelativeItem(1).Element(CellStyle).Column(column =>
{
column.Item()
.AlignMiddle() // Ensures vertical centering
.AlignCenter() // Ensures horizontal centering
.Text("Logo Placeholder"); // Placeholder for the logo
});
// Logo and Title
column.Item().AlignCenter().Text("Company Logo Placeholder").FontSize(12).Italic();
row.RelativeItem(1).Element(CellStyle)
.AlignMiddle() // Ensures vertical centering
.AlignCenter() // Ensures horizontal centering
.Text("TARBALL SAMPLING FORM")
.FontSize(16)
.FontColor("#4B0082");
// 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);
row.RelativeItem(1).Column(column =>
{
column.Spacing(0); // Adds consistent spacing between rows
// Document Row
column.Item().Row(innerRow =>
{
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();
});
});
// Define styles
static IContainer CellStyle(IContainer container)
=> container.Border(0.5f).Padding(5); // Retains padding for text
});
// Content Section
page.Content().Column(column =>
{
column.Spacing(20);
// Table Section
// Observations Table
column.Item().Element(container =>
{
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(1); // Column 1
columns.RelativeColumn(2); // Column 2
columns.RelativeColumn(3); // Label/Header column
columns.RelativeColumn(3); // Data Entry column
});
table.Cell().Text("STATE").Bold();
table.Cell().Text("Your State Data Here");
// 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().Text("STATION ID").Bold();
table.Cell().Text("Your Station ID Here");
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
});
// 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");
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);
});
});
// Footer Section
page.Footer().AlignCenter().Text(x =>
page.Footer().AlignCenter().Text(text =>
{
x.Span("Page ");
x.CurrentPageNumber();
x.Span(" of ");
x.TotalPages();
text.Span("Page ");
text.CurrentPageNumber();
text.Span(" of ");
text.TotalPages();
});
static IContainer CellStyle(IContainer container) => container.Border(0.5f)
.Padding(5);
});
}
catch (Exception ex)
{
// Log the exception (you can use any logging framework or method you prefer)
Console.WriteLine($"Error generating PDF: {ex.Message}");
}
}
}
;

View File

@ -1,5 +1,5 @@
@{
ViewData["Title"] = "Tar Ball Sampling Form";
ViewData["Title"] = "Tarball Report";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
@ -8,13 +8,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
<h3>Tarball Sampling Form</h3>
<h3>Tarball Report</h3>
</title>
<style>
div {
padding-top:10px;
padding-bottom:10px:
}
.container {
width: 1200px; /* Approximate width for A4 aspect ratio */
margin: 20px auto;
@ -22,160 +18,118 @@
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
.details-cell
}
.form-header {
display: table;
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
div {
padding-top: 10px;
padding-bottom: 10px;
}
.form-header th, .form-header td {
border: 1px solid #ccc;
padding: 10px;
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;
h4 {
padding-top: 15px;
padding-bottom: 5px;
}
table {
width:100%;
}
datatable {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
text-align: center;
tr {
border: 1px solid #ccc;
padding:10px;
}
td {
background-color: #fff;
th{
border: 1px solid #ccc;
padding:10px;
}
tbhead {
text-align:center;
}
</style>
</head>
<!--to be updated later for user input,etc-->
<!--to be updated later for user input,db connection, etc-->
<body>
<div>
<a href="/MMS/Marine/GenerateReport" class="btn btn-primary">Download PDF</a>
</div>
<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>
<!-- -->
<p>Please be informed that we have observed the following conditions:</p>
</div>
<div>
<table>
<tr>
<td>
<p>STATE</p>
</td>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>STATION ID</p>
</td>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>LOCATION</p>
</td>
<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>
</table>
</div>
<form>
<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>
<h4>Month</h4>
<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>
</div> <!--A4 CONTAINER-->
<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 class="datatable">
<table>
<tr class="tbhead">
<th>???</th>
<th>Date</th>
<th>Station</th>
<th>Approval Status</th>
<th>PDF</th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th>
<button class="btn btn-success">Approve</button>
<button class="btn btn-danger">Reject</button>
</th>
<th>
<a href="/MMS/Marine/ViewPDF" class="btn btn-primary" target="_blank">View PDF</a>
<a href="/MMS/Marine/GenerateReport" class="btn btn-primary">Download PDF</a>
</th>
</tr>
</table>
</div>
</div> <!--CONTAINER END-->
</body>
</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.Models;
using Serilog;
using QuestPDF;
using QuestPDF.Infrastructure;
internal class Program
{
@ -12,6 +14,8 @@ internal class Program
{
var builder = WebApplication.CreateBuilder(args);
var centralConnectionString = builder.Configuration.GetConnectionString("CentralConnnection");
Settings.License = LicenseType.Community;
//var inventoryConnectionString = builder.Configuration.GetConnectionString("InventoryConnection");
// Add services to the container.

View File

@ -514,7 +514,7 @@
<li class="sidebar-item">
<a class="sidebar-link waves-effect waves-dark"
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>
</li>
</ul>

BIN
document.pdf Normal file

Binary file not shown.