114 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			114 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
|  | using GestionIntegral.Api.Dtos.Reportes.ViewModels; | ||
|  | using QuestPDF.Fluent; | ||
|  | using QuestPDF.Helpers; | ||
|  | using QuestPDF.Infrastructure; | ||
|  | using System.Globalization; | ||
|  | using System.Linq; | ||
|  | 
 | ||
|  | namespace GestionIntegral.Api.Controllers.Reportes.PdfTemplates | ||
|  | { | ||
|  |   public class ComparativaConsumoBobinasDocument : IDocument | ||
|  |   { | ||
|  |     public ComparativaConsumoBobinasViewModel Model { get; } | ||
|  | 
 | ||
|  |     public ComparativaConsumoBobinasDocument(ComparativaConsumoBobinasViewModel 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 Consumo de Bobinas - Comparativa Mensual").SemiBold().FontSize(14); | ||
|  | 
 | ||
|  |         string subTitle = Model.EsConsolidado ? "Consolidado" : $"Planta: {Model.NombrePlanta}"; | ||
|  |         column.Item().AlignCenter().Text(subTitle).FontSize(12); | ||
|  | 
 | ||
|  |         column.Item().PaddingTop(5, Unit.Millimetre).Row(row => | ||
|  |       { | ||
|  |           // Le damos una proporción menor al texto de la izquierda (que es corto y fijo). | ||
|  |             row.RelativeItem(1).Text(text => | ||
|  |           { | ||
|  |                 text.Span("Fecha del Reporte: ").SemiBold().FontSize(12); | ||
|  |                 text.Span(Model.FechaReporte); | ||
|  |               }); | ||
|  | 
 | ||
|  |           // Le damos una proporción mayor al texto de la derecha (que es largo y variable). | ||
|  |           // El factor "2" significa que tendrá el doble de espacio disponible que el item con factor "1". | ||
|  |             row.RelativeItem(2).AlignRight().Text(text => | ||
|  |           { | ||
|  |                 text.Span("Meses: ").SemiBold().FontSize(12); | ||
|  |                 text.Span($"{Model.MesA} (Mes A) contra {Model.MesB} (Mes B)").FontSize(12); | ||
|  |               }); | ||
|  |           }); | ||
|  |       }); | ||
|  |     } | ||
|  | 
 | ||
|  |     void ComposeContent(IContainer container) | ||
|  |     { | ||
|  |       container.PaddingTop(5, Unit.Millimetre).Table(table => | ||
|  |       { | ||
|  |         table.ColumnsDefinition(columns => | ||
|  |               { | ||
|  |             columns.RelativeColumn(3); // Tipo Bobina | ||
|  |             columns.RelativeColumn(1); columns.RelativeColumn(1); columns.RelativeColumn(1); // Grupo Cantidad | ||
|  |             columns.RelativeColumn(1); columns.RelativeColumn(1); columns.RelativeColumn(1); // Grupo Kilos | ||
|  |           }); | ||
|  | 
 | ||
|  |         table.Header(header => | ||
|  |               { | ||
|  |                 // Fila 1 del Encabezado | ||
|  |             header.Cell().RowSpan(2).Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignMiddle().Text("Tipo Bobina").SemiBold(); | ||
|  |             header.Cell().ColumnSpan(3).Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignCenter().Text("Cantidad Bobinas").SemiBold(); | ||
|  |             header.Cell().ColumnSpan(3).Border(1).Background(Colors.Grey.Lighten3).Padding(4).AlignCenter().Text("Kilos Utilizados").SemiBold(); | ||
|  | 
 | ||
|  |                 // Fila 2 del Encabezado | ||
|  |             header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(2).AlignRight().Text("Mes A").SemiBold(); | ||
|  |             header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(2).AlignRight().Text("Mes B").SemiBold(); | ||
|  |             header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(2).AlignRight().Text("Diferencia").SemiBold(); | ||
|  |             header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(2).AlignRight().Text("Kg Mes A").SemiBold(); | ||
|  |             header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(2).AlignRight().Text("Kg Mes B").SemiBold(); | ||
|  |             header.Cell().Border(1).Background(Colors.Grey.Lighten3).Padding(2).AlignRight().Text("Diferencia").SemiBold(); | ||
|  |           }); | ||
|  | 
 | ||
|  |         foreach (var item in Model.Detalles.OrderBy(x => x.TipoBobina)) | ||
|  |         { | ||
|  |           table.Cell().Border(1).Padding(3).Text(item.TipoBobina); | ||
|  |           table.Cell().Border(1).Padding(3).AlignRight().Text(item.BobinasUtilizadasMesA.ToString("N0")); | ||
|  |           table.Cell().Border(1).Padding(3).AlignRight().Text(item.BobinasUtilizadasMesB.ToString("N0")); | ||
|  |           table.Cell().Border(1).Padding(3).AlignRight().Text(item.DiferenciaBobinasUtilizadas.ToString("N0")); | ||
|  |           table.Cell().Border(1).Padding(3).AlignRight().Text(item.KilosUtilizadosMesA.ToString("N0")); | ||
|  |           table.Cell().Border(1).Padding(3).AlignRight().Text(item.KilosUtilizadosMesB.ToString("N0")); | ||
|  |           table.Cell().Border(1).Padding(3).AlignRight().Text(item.DiferenciaKilosUtilizados.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.BobinasUtilizadasMesA).ToString("N0")).Style(style)); | ||
|  |         table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.BobinasUtilizadasMesB).ToString("N0")).Style(style)); | ||
|  |         table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.DiferenciaBobinasUtilizadas).ToString("N0")).Style(style)); | ||
|  |         table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.KilosUtilizadosMesA).ToString("N0")).Style(style)); | ||
|  |         table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.KilosUtilizadosMesB).ToString("N0")).Style(style)); | ||
|  |         table.Cell().Border(1).Padding(3).AlignRight().Text(text => text.Span(Model.Detalles.Sum(x => x.DiferenciaKilosUtilizados).ToString("N0")).Style(style)); | ||
|  |       }); | ||
|  |     } | ||
|  |   } | ||
|  | } |