using GestionIntegral.Api.Dtos.Reportes.ViewModels; using QuestPDF.Fluent; using QuestPDF.Helpers; using QuestPDF.Infrastructure; using System.Linq; namespace GestionIntegral.Api.Controllers.Reportes.PdfTemplates { public class TiradasPublicacionesSeccionesDocument : IDocument { public TiradasPublicacionesSeccionesViewModel Model { get; } public TiradasPublicacionesSeccionesDocument(TiradasPublicacionesSeccionesViewModel model) { Model = model; } public DocumentMetadata GetMetadata() => DocumentMetadata.Default; public void Compose(IDocumentContainer container) { container.Page(page => { page.Margin(1, Unit.Centimetre); page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(9)); page.Header().Element(ComposeHeader); page.Content().Element(ComposeContent); page.Footer().AlignCenter().Text(x => { x.Span("Página "); x.CurrentPageNumber(); }); }); } void ComposeHeader(IContainer container) { container.Column(column => { column.Spacing(5); column.Item().AlignCenter().Text("Reporte de Tiradas por Publicación Mensual").SemiBold().FontSize(14); // Título secundario dinámico string subTitle = Model.EsConsolidado ? $"Consolidado - Publicación: {Model.NombrePublicacion}" : $"Planta: {Model.NombrePlanta} - Publicación: {Model.NombrePublicacion}"; column.Item().AlignCenter().Text(subTitle).FontSize(12); column.Item().PaddingTop(5, Unit.Millimetre).Row(row => { row.RelativeItem().Text(text => { text.Span("Fecha del Reporte: ").SemiBold(); text.Span(Model.FechaReporte); }); row.RelativeItem().AlignRight().Text(text => { text.Span("Mes Consultado: ").SemiBold(); text.Span(Model.MesConsultado); }); }); }); } void ComposeContent(IContainer container) { container.PaddingTop(5, Unit.Millimetre).Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(2.5f); // Nombre Seccion columns.RelativeColumn(1.5f); // Páginas Impresas columns.RelativeColumn(1); // Total Ediciones columns.RelativeColumn(1.5f); // Pág. Por Edición columns.RelativeColumn(1.2f); // Total Ejemplares columns.RelativeColumn(1.5f); // Pág. Ejemplar }); table.Header(header => { header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).Text("Nombre Sección"); header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Páginas Impresas"); header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Total Ediciones"); header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Prom. Pág/Edición"); header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Total Ejemplares"); header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Prom. Pág/Ejemplar"); }); foreach (var item in Model.Detalles.OrderBy(x => x.NombreSeccion)) { table.Cell().Border(1).Padding(3).Text(item.NombreSeccion); table.Cell().Border(1).Padding(3).AlignRight().Text(item.TotalPaginasImpresas.ToString("N0")); table.Cell().Border(1).Padding(3).AlignRight().Text(item.CantidadTiradas.ToString("N0")); table.Cell().Border(1).Padding(3).AlignRight().Text(item.TotalPaginasEjemplares.ToString("N0")); table.Cell().Border(1).Padding(3).AlignRight().Text(item.TotalEjemplares.ToString("N0")); table.Cell().Border(1).Padding(3).AlignRight().Text(item.PromedioPaginasPorEjemplar.ToString("N0")); } // Fila de Totales var style = TextStyle.Default.SemiBold(); table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span("Totales").Style(style)); table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.TotalPaginasImpresas).ToString("N0")).Style(style)); table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.CantidadTiradas).ToString("N0")).Style(style)); table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.TotalPaginasEjemplares).ToString("N0")).Style(style)); table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.TotalEjemplares).ToString("N0")).Style(style)); table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.PromedioPaginasPorEjemplar).ToString("N0")).Style(style)); }); } } }