using General_Ledger_Service.DTOs.Reports; using QuestPDF.Fluent; using QuestPDF.Helpers; using QuestPDF.Infrastructure; namespace General_Ledger_Service.Services.PdfDocuments { // One continuous table of transaction lines, no grouping by account: each row carries its own // account (code + name), same layout as the CSV and the on-screen report. // Response is already sorted by accountCode then entryDate - no re-sorting needed here. public class GeneralLedgerPdfDocument(string companyName, string currencyCode, DateOnly periodStart, DateOnly periodEnd, 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, "General Ledger", ReportPageHeader.RangePeriodLine(periodStart, periodEnd), currencyCode); page.Content().PaddingTop(10).Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(2); columns.RelativeColumn(4); columns.RelativeColumn(4); columns.RelativeColumn(3); columns.RelativeColumn(2); columns.RelativeColumn(2); }); table.Header(header => { header.Cell().Text("Date").Bold(); header.Cell().Text("Account").Bold(); header.Cell().Text("Particulars").Bold(); header.Cell().Text("Description/Reference (J.R.)").Bold(); header.Cell().AlignRight().Text("Debit").Bold(); header.Cell().AlignRight().Text("Credit").Bold(); header.Cell().ColumnSpan(6).PaddingTop(3).LineHorizontal(1); }); foreach (var row in rows) { table.Cell().Text(row.EntryDate.ToString("yyyy-MM-dd")); table.Cell().Text($"{row.AccountCode} {row.AccountName}"); table.Cell().Text(row.Narration ?? string.Empty); table.Cell().Text(row.JournalNo); table.Cell().AlignRight().Text(PdfFormatting.FormatAmountOrBlank(row.DebitAmount)); table.Cell().AlignRight().Text(PdfFormatting.FormatAmountOrBlank(row.CreditAmount)); } table.Cell().ColumnSpan(6).PaddingTop(3).LineHorizontal(1); }); }); } } }