129 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			129 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 
								 | 
							
								using GestionIntegral.Api.Dtos.Reportes.ViewModels;
							 | 
						||
| 
								 | 
							
								using QuestPDF.Fluent;
							 | 
						||
| 
								 | 
							
								using QuestPDF.Helpers;
							 | 
						||
| 
								 | 
							
								using QuestPDF.Infrastructure;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace GestionIntegral.Api.Controllers.Reportes.PdfTemplates
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								  public class MovimientoBobinasEstadoDocument : IDocument
							 | 
						||
| 
								 | 
							
								  {
							 | 
						||
| 
								 | 
							
								    public MovimientoBobinasEstadoViewModel Model { get; }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public MovimientoBobinasEstadoDocument(MovimientoBobinasEstadoViewModel model)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								      Model = model;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
							 | 
						||
| 
								 | 
							
								    public DocumentSettings GetSettings() => DocumentSettings.Default;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public void Compose(IDocumentContainer container)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								      container
							 | 
						||
| 
								 | 
							
								          .Page(page =>
							 | 
						||
| 
								 | 
							
								          {
							 | 
						||
| 
								 | 
							
								            page.Margin(1, Unit.Centimetre);
							 | 
						||
| 
								 | 
							
								            page.DefaultTextStyle(x => x.FontFamily("Roboto").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 Movimiento de Bobinas por Estados").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).Column(column =>
							 | 
						||
| 
								 | 
							
								      {
							 | 
						||
| 
								 | 
							
								        // Primera tabla: Detalle de Movimientos
							 | 
						||
| 
								 | 
							
								        column.Item().Table(table =>
							 | 
						||
| 
								 | 
							
								              {
							 | 
						||
| 
								 | 
							
								            table.ColumnsDefinition(columns =>
							 | 
						||
| 
								 | 
							
								                  {
							 | 
						||
| 
								 | 
							
								                columns.RelativeColumn(3); // Tipo Bobina
							 | 
						||
| 
								 | 
							
								                columns.RelativeColumn(2); // Remito
							 | 
						||
| 
								 | 
							
								                columns.ConstantColumn(80);  // Fecha
							 | 
						||
| 
								 | 
							
								                columns.ConstantColumn(60);  // Cantidad
							 | 
						||
| 
								 | 
							
								                columns.RelativeColumn(2); // Tipo Movimiento
							 | 
						||
| 
								 | 
							
								              });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            table.Header(header =>
							 | 
						||
| 
								 | 
							
								                  {
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).Text("Tipo Bobina");
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).Text("N° Remito");
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).AlignCenter().Text("Fecha Mov.");
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Cantidad");
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).Text("Tipo Movimiento");
							 | 
						||
| 
								 | 
							
								              });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            foreach (var item in Model.Detalles)
							 | 
						||
| 
								 | 
							
								            {
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).Text(item.TipoBobina);
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).Text(item.NumeroRemito);
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).AlignCenter().Text(item.FechaMovimiento.ToString("dd/MM/yyyy"));
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).AlignRight().Text(item.Cantidad.ToString("N0"));
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).Text(item.TipoMovimiento);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								          });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // Espacio entre tablas
							 | 
						||
| 
								 | 
							
								        column.Item().PaddingTop(1, Unit.Centimetre);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // Segunda tabla: Totales
							 | 
						||
| 
								 | 
							
								        column.Item().AlignLeft().Table(table => // Alineamos la tabla a la izquierda para que no ocupe todo el ancho
							 | 
						||
| 
								 | 
							
								              {
							 | 
						||
| 
								 | 
							
								            table.ColumnsDefinition(columns =>
							 | 
						||
| 
								 | 
							
								                  {
							 | 
						||
| 
								 | 
							
								                columns.ConstantColumn(120); // Tipo Movimiento
							 | 
						||
| 
								 | 
							
								                columns.ConstantColumn(80);  // Total Bobinas
							 | 
						||
| 
								 | 
							
								                columns.ConstantColumn(80);  // Total Kilos
							 | 
						||
| 
								 | 
							
								              });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            table.Header(header =>
							 | 
						||
| 
								 | 
							
								                  {
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).Text("Totales por Movimiento");
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Total Bobinas");
							 | 
						||
| 
								 | 
							
								                header.Cell().Background(Colors.Grey.Lighten3).Padding(4).AlignRight().Text("Total Kilos");
							 | 
						||
| 
								 | 
							
								              });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            foreach (var total in Model.Totales)
							 | 
						||
| 
								 | 
							
								            {
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).Text(total.TipoMovimiento);
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).AlignRight().Text(total.TotalBobinas.ToString("N0"));
							 | 
						||
| 
								 | 
							
								              table.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).AlignRight().Text(total.TotalKilos.ToString("N0"));
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								          });
							 | 
						||
| 
								 | 
							
								      });
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 |