using General_Ledger_Service.DTOs.Reports; using QuestPDF.Fluent; using QuestPDF.Helpers; using QuestPDF.Infrastructure; namespace General_Ledger_Service.Services.PdfDocuments { // 05_LKAS_Report_PDF_Templates.md Section 7 - not an LKAS statement, a management report. // Flat table including a Period column, since a budget can span multiple periods (Section 7's // own open question - grouping by period is a possible future enhancement, not required here). public class BudgetVsActualPdfDocument(string companyName, string currencyCode, long budgetId, List rows) : IDocument { public DocumentMetadata GetMetadata() => DocumentMetadata.Default; public void Compose(IDocumentContainer container) { container.Page(page => { page.Size(PageSizes.A4); page.Margin(2, Unit.Centimetre); ReportPageHeader.Compose(page, companyName, "Budget vs Actual Report", $"Budget ID: {budgetId}", currencyCode); page.Content().PaddingTop(10).Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(2); columns.RelativeColumn(4); columns.RelativeColumn(1); columns.RelativeColumn(2); columns.RelativeColumn(2); columns.RelativeColumn(2); }); table.Header(header => { header.Cell().Text("Account Code").Bold(); header.Cell().Text("Account Name").Bold(); header.Cell().AlignRight().Text("Period").Bold(); header.Cell().AlignRight().Text("Budgeted").Bold(); header.Cell().AlignRight().Text("Actual").Bold(); header.Cell().AlignRight().Text("Variance").Bold(); header.Cell().ColumnSpan(6).PaddingTop(3).LineHorizontal(1); }); foreach (var row in rows.OrderBy(r => r.PeriodId).ThenBy(r => r.AccountCode)) { table.Cell().Text(row.AccountCode); table.Cell().Text(row.AccountName); table.Cell().AlignRight().Text(row.PeriodId.ToString()); table.Cell().AlignRight().Text(PdfFormatting.FormatAmount(row.BudgetedAmount)); table.Cell().AlignRight().Text(PdfFormatting.FormatAmount(row.ActualAmount)); table.Cell().AlignRight().Text(PdfFormatting.FormatAmount(row.Variance)); } table.Cell().ColumnSpan(6).PaddingTop(3).LineHorizontal(1); table.Cell().Text(""); table.Cell().Text("Total").Bold(); table.Cell().Text(""); table.Cell().AlignRight().Text(PdfFormatting.FormatAmount(rows.Sum(r => r.BudgetedAmount))).Bold(); table.Cell().AlignRight().Text(PdfFormatting.FormatAmount(rows.Sum(r => r.ActualAmount))).Bold(); table.Cell().AlignRight().Text(PdfFormatting.FormatAmount(rows.Sum(r => r.Variance))).Bold(); }); }); } } }