122 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			122 lines
		
	
	
		
			6.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 MovimientoBobinasDocument : IDocument
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        public MovimientoBobinasViewModel Model { get; }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        public MovimientoBobinasDocument(MovimientoBobinasViewModel model)
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            Model = model;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
							 | 
						||
| 
								 | 
							
								        public DocumentSettings GetSettings() => DocumentSettings.Default;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        public void Compose(IDocumentContainer container)
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            container
							 | 
						||
| 
								 | 
							
								                .Page(page =>
							 | 
						||
| 
								 | 
							
								                {
							 | 
						||
| 
								 | 
							
								                    // Configuramos la página en modo apaisado (landscape)
							 | 
						||
| 
								 | 
							
								                    page.Size(PageSizes.A4.Landscape());
							 | 
						||
| 
								 | 
							
								                    page.Margin(1, Unit.Centimetre);
							 | 
						||
| 
								 | 
							
								                    page.DefaultTextStyle(x => x.FontFamily("Roboto").FontSize(9)); // Un poco más pequeño por la cantidad de columnas
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								                    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 Movimiento de Bobinas").SemiBold().FontSize(14);
							 | 
						||
| 
								 | 
							
								                column.Item().AlignCenter().Text($"Planta: {Model.NombrePlanta}").FontSize(12);
							 | 
						||
| 
								 | 
							
								                
							 | 
						||
| 
								 | 
							
								                column.Item().PaddingTop(2, Unit.Millimetre).Row(row =>
							 | 
						||
| 
								 | 
							
								                {
							 | 
						||
| 
								 | 
							
								                     row.RelativeItem().Column(col =>
							 | 
						||
| 
								 | 
							
								                    {
							 | 
						||
| 
								 | 
							
								                        col.Item().Text(text =>
							 | 
						||
| 
								 | 
							
								                        {
							 | 
						||
| 
								 | 
							
								                            text.Span("Fecha del Reporte: ").SemiBold();
							 | 
						||
| 
								 | 
							
								                            text.Span(Model.FechaReporte);
							 | 
						||
| 
								 | 
							
								                        });
							 | 
						||
| 
								 | 
							
								                         col.Item().Text($"Periodo Consultado: Desde {Model.FechaDesde} Hasta {Model.FechaHasta}");
							 | 
						||
| 
								 | 
							
								                    });
							 | 
						||
| 
								 | 
							
								                });
							 | 
						||
| 
								 | 
							
								            });
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        void ComposeContent(IContainer container)
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            container.PaddingTop(1, Unit.Centimetre).Table(table =>
							 | 
						||
| 
								 | 
							
								            {
							 | 
						||
| 
								 | 
							
								                // Definimos 11 columnas. Usamos una combinación de relativas y constantes
							 | 
						||
| 
								 | 
							
								                table.ColumnsDefinition(columns =>
							 | 
						||
| 
								 | 
							
								                {
							 | 
						||
| 
								 | 
							
								                    columns.RelativeColumn(2.5f); // Tipo
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(50);   // Cant. Inicial
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(60);   // Kg Iniciales
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(50);   // Compradas
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(60);   // Kg Comprados
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(50);   // Consumidas
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(60);   // Kg Consumidos
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(50);   // Dañadas
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(60);   // Kg Dañados
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(50);   // Cant. Final
							 | 
						||
| 
								 | 
							
								                    columns.ConstantColumn(60);   // Kg Final
							 | 
						||
| 
								 | 
							
								                });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								                // Encabezado de la tabla
							 | 
						||
| 
								 | 
							
								                table.Header(header =>
							 | 
						||
| 
								 | 
							
								                {
							 | 
						||
| 
								 | 
							
								                    // Celda por celda para control total
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).Text("Tipo");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Cant. Inicial");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Kg Inicial");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Compradas");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Kg Comprados");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Consumidas");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Kg Consumidos");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Dañadas");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Kg Dañados");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Cant. Final");
							 | 
						||
| 
								 | 
							
								                    header.Cell().Background(Colors.Grey.Lighten3).Padding(2).AlignCenter().Text("Kg Final");
							 | 
						||
| 
								 | 
							
								                });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								                // Filas de datos
							 | 
						||
| 
								 | 
							
								                foreach (var item in Model.Movimientos)
							 | 
						||
| 
								 | 
							
								                {
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).Text(item.TipoBobina);
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.BobinasIniciales.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.KilosIniciales.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.BobinasCompradas.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.KilosComprados.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.BobinasConsumidas.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.KilosConsumidos.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.BobinasDaniadas.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.KilosDaniados.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.BobinasFinales.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                    table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(2).AlignCenter().Text(item.KilosFinales.ToString("N0"));
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            });
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |