116 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			116 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
|  | using GestionIntegral.Api.Dtos.Reportes.ViewModels; | ||
|  | using QuestPDF.Elements.Table; | ||
|  | using QuestPDF.Fluent; | ||
|  | using QuestPDF.Helpers; | ||
|  | using QuestPDF.Infrastructure; | ||
|  | using System.Linq; | ||
|  | 
 | ||
|  | namespace GestionIntegral.Api.Controllers.Reportes.PdfTemplates | ||
|  | { | ||
|  |     public class VentaMensualSecretariaTirDevoDocument : IDocument | ||
|  |     { | ||
|  |         public VentaMensualSecretariaTirDevoViewModel Model { get; } | ||
|  | 
 | ||
|  |         public VentaMensualSecretariaTirDevoDocument(VentaMensualSecretariaTirDevoViewModel model) | ||
|  |         { | ||
|  |             Model = model; | ||
|  |         } | ||
|  | 
 | ||
|  |         public DocumentMetadata GetMetadata() => DocumentMetadata.Default; | ||
|  | 
 | ||
|  |         public void Compose(IDocumentContainer container) | ||
|  |         { | ||
|  |             container.Page(page => | ||
|  |             { | ||
|  |                 // CORRECCIÓN: Se aplica Landscape() al tamaño de página. | ||
|  |                 page.Size(PageSizes.A4.Landscape()); | ||
|  |                 page.Margin(1, Unit.Centimetre); | ||
|  |                 page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(12)); | ||
|  |                  | ||
|  |                 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.Item().AlignCenter().Text("TIRADA Y DEVOLUCIÓN").SemiBold().FontSize(18); | ||
|  |                 column.Item().AlignCenter().Text(text => | ||
|  |                 { | ||
|  |                     text.Span("Fecha Consultada: Desde ").SemiBold().FontSize(14); | ||
|  |                     text.Span(Model.FechaDesde).FontSize(14); | ||
|  |                     text.Span(" Hasta ").SemiBold().FontSize(14); | ||
|  |                     text.Span(Model.FechaHasta).FontSize(14); | ||
|  |                 }); | ||
|  |             }); | ||
|  |         } | ||
|  |          | ||
|  |         void ComposeContent(IContainer container) | ||
|  |         { | ||
|  |             container.PaddingTop(5, Unit.Millimetre).Table(table => | ||
|  |             { | ||
|  |                 table.ColumnsDefinition(columns => | ||
|  |                 { | ||
|  |                     columns.ConstantColumn(40); | ||
|  |                     columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); // EL DÍA | ||
|  |                     columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); // POPULAR | ||
|  |                     columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); // CLARÍN | ||
|  |                     columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); // LA NACIÓN | ||
|  |                 }); | ||
|  | 
 | ||
|  |                 table.Header(header => | ||
|  |                 { | ||
|  |                     // CORRECCIÓN: La sintaxis de VerticalAlign es un método. | ||
|  |                     header.Cell().RowSpan(2).Border(1).Background(Colors.Black).AlignCenter().AlignMiddle().Text(text => text.Span("Día").FontColor(Colors.White).SemiBold()); | ||
|  |                      | ||
|  |                     header.Cell().ColumnSpan(3).Border(1).Background(Colors.Black).AlignCenter().Text(text => text.Span("EL DÍA").FontColor(Colors.White).SemiBold()); | ||
|  |                     header.Cell().ColumnSpan(3).Border(1).Background(Colors.Black).AlignCenter().Text(text => text.Span("POPULAR").FontColor(Colors.White).SemiBold()); | ||
|  |                     header.Cell().ColumnSpan(3).Border(1).Background(Colors.Black).AlignCenter().Text(text => text.Span("CLARÍN").FontColor(Colors.White).SemiBold()); | ||
|  |                     header.Cell().ColumnSpan(3).Border(1).Background(Colors.Black).AlignCenter().Text(text => text.Span("LA NACIÓN").FontColor(Colors.White).SemiBold()); | ||
|  |                      | ||
|  |                     // CORRECCIÓN: Se define una función local para crear y estilizar las celdas del sub-encabezado. | ||
|  |                     // Esto evita el error de "multiple child elements". | ||
|  |                     void SubHeaderCell(ITableCellContainer cell, string text) | ||
|  |                     { | ||
|  |                         cell.Border(1) | ||
|  |                             .Background(Colors.Black) | ||
|  |                             .AlignCenter() | ||
|  |                             .Text(txt => txt.Span(text).FontColor(Colors.White).SemiBold()); | ||
|  |                     } | ||
|  | 
 | ||
|  |                     foreach (var _ in Enumerable.Range(0, 4)) | ||
|  |                     { | ||
|  |                         SubHeaderCell(header.Cell(), "TIRADA"); | ||
|  |                         SubHeaderCell(header.Cell(), "DEVOLUC"); | ||
|  |                         SubHeaderCell(header.Cell(), "VENTA"); | ||
|  |                     } | ||
|  |                 }); | ||
|  | 
 | ||
|  |                 // Filas de datos (sin cambios) | ||
|  |                 foreach (var item in Model.VentasDiarias.OrderBy(x => x.Dia)) | ||
|  |                 { | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.Dia.ToString()); | ||
|  |                      | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.TiradaCoop.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.DevolucionCoop.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(t => t.Span(item.VentaCoop.ToString("N0")).SemiBold()); | ||
|  |                      | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.TiradaPopular.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.DevolucionPopular.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(t => t.Span(item.VentaPopular.ToString("N0")).SemiBold()); | ||
|  | 
 | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.TiradaClarin.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.DevolucionClarin.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(t => t.Span(item.VentaClarin.ToString("N0")).SemiBold()); | ||
|  | 
 | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.TiradaNacion.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(item.DevolucionNacion.ToString("N0")); | ||
|  |                     table.Cell().Border(1).Padding(4).AlignCenter().Text(t => t.Span(item.VentaNacion.ToString("N0")).SemiBold()); | ||
|  |                 } | ||
|  |             }); | ||
|  |         } | ||
|  |     } | ||
|  | } |