All checks were successful
		
		
	
	Optimized Build and Deploy / remote-build-and-deploy (push) Successful in 7m55s
				
			
		
			
				
	
	
		
			98 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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 ConsumoBobinasPublicacionDocument : IDocument
 | |
|     {
 | |
|         public ConsumoBobinasPublicacionViewModel Model { get; }
 | |
| 
 | |
|         public ConsumoBobinasPublicacionDocument(ConsumoBobinasPublicacionViewModel model)
 | |
|         {
 | |
|             Model = model;
 | |
|         }
 | |
| 
 | |
|         public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
 | |
| 
 | |
|         public void Compose(IDocumentContainer container)
 | |
|         {
 | |
|             container.Page(page =>
 | |
|             {
 | |
|                 page.Margin(1.5f, Unit.Centimetre);
 | |
|                 page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(10));
 | |
|                 
 | |
|                 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 Consumo de Bobinas por Publicaciones").SemiBold().FontSize(14);
 | |
|                 
 | |
|                 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("Periodo: ").SemiBold(); text.Span($"{Model.FechaDesde} - {Model.FechaHasta}"); });
 | |
|                 });
 | |
|             });
 | |
|         }
 | |
|         
 | |
|         void ComposeContent(IContainer container)
 | |
|         {
 | |
|             container.PaddingTop(1, Unit.Centimetre).Table(table =>
 | |
|             {
 | |
|                 table.ColumnsDefinition(columns =>
 | |
|                 {
 | |
|                     columns.RelativeColumn(2);   // Planta
 | |
|                     columns.RelativeColumn(3);   // Publicación
 | |
|                     columns.RelativeColumn(1.5f);  // Kilos
 | |
|                     columns.RelativeColumn(1.5f);  // Cant. Bobinas
 | |
|                 });
 | |
| 
 | |
|                 table.Header(header =>
 | |
|                 {
 | |
|                     header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).Text("Planta");
 | |
|                     header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).Text("Publicación");
 | |
|                     header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Kilos");
 | |
|                     header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Cant. Bobinas");
 | |
|                 });
 | |
|                 
 | |
|                 var gruposPorPlanta = Model.Detalles.GroupBy(p => p.NombrePlanta);
 | |
| 
 | |
|                 foreach (var grupoPlanta in gruposPorPlanta)
 | |
|                 {
 | |
|                     var primeraFilaDePlanta = true;
 | |
|                     foreach (var detalle in grupoPlanta.OrderBy(d => d.NombrePublicacion))
 | |
|                     {
 | |
|                         // Celda de Planta (solo en la primera fila del grupo)
 | |
|                         if (primeraFilaDePlanta)
 | |
|                         {
 | |
|                             table.Cell().RowSpan((uint)grupoPlanta.Count()).Border(1).Padding(3).AlignTop().Text(grupoPlanta.Key).SemiBold();
 | |
|                             primeraFilaDePlanta = false;
 | |
|                         }
 | |
| 
 | |
|                         table.Cell().Border(1).Padding(3).Text(detalle.NombrePublicacion);
 | |
|                         table.Cell().Border(1).Padding(3).AlignRight().Text(detalle.TotalKilos.ToString("N0"));
 | |
|                         table.Cell().Border(1).Padding(3).AlignRight().Text(detalle.CantidadBobinas.ToString("N0"));
 | |
|                     }
 | |
|                 }
 | |
|                 
 | |
|                 // Fila de Totales Generales
 | |
|                 var totalGeneralKilos = Model.Detalles.Sum(d => d.TotalKilos);
 | |
|                 var totalGeneralBobinas = Model.Detalles.Sum(d => d.CantidadBobinas);
 | |
| 
 | |
|                 table.Cell().ColumnSpan(2).BorderTop(1.5f).BorderColor(Colors.Black).Padding(3).AlignRight().Text("Totales").ExtraBold();
 | |
|                 table.Cell().BorderTop(1.5f).BorderColor(Colors.Black).Padding(3).AlignRight().Text(t => t.Span(totalGeneralKilos.ToString("N0")).ExtraBold());
 | |
|                 table.Cell().BorderTop(1.5f).BorderColor(Colors.Black).Padding(3).AlignRight().Text(t => t.Span(totalGeneralBobinas.ToString("N0")).ExtraBold());
 | |
|             });
 | |
|         }
 | |
|     }
 | |
| } |