Files
dmolinari 229eb937f5
All checks were successful
Optimized Build and Deploy / remote-build-and-deploy (push) Successful in 7m55s
QuestPdf Implementado en la totalidad de reportes.
2025-06-24 12:52:37 -03:00

126 lines
6.2 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 ControlDevolucionesDocument : IDocument
{
public ControlDevolucionesViewModel Model { get; }
public ControlDevolucionesDocument(ControlDevolucionesViewModel 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(11));
page.Header().Element(ComposeHeader);
page.Content().Element(ComposeContent);
});
}
void ComposeHeader(IContainer container)
{
container.Column(column =>
{
column.Item().AlignCenter().Text("Control de Devoluciones").SemiBold().FontSize(16);
column.Item().AlignCenter().Text("Canillas / Accionistas").FontSize(13);
});
}
void ComposeContent(IContainer container)
{
container.PaddingTop(1, Unit.Centimetre).Column(column =>
{
column.Spacing(15);
column.Item().Row(row =>
{
row.RelativeItem().Text(text =>
{
text.Span("Fecha Consultada: ").SemiBold();
text.Span(Model.FechaConsultada);
});
row.RelativeItem().AlignRight().Text(text =>
{
text.Span("Cantidad Canillas: ").SemiBold();
text.Span(Model.CantidadCanillas.ToString());
});
});
column.Item().PaddingTop(5).Border(1).Background(Colors.Grey.Lighten3).AlignCenter().Padding(2).Text(Model.NombreEmpresa).SemiBold();
column.Item().Border(1).Padding(10).Column(innerCol =>
{
innerCol.Spacing(5);
// Fila de "Ingresados por Remito" con borde inferior sólido.
innerCol.Item().BorderBottom(1, Unit.Point).BorderColor(Colors.Grey.Medium).Row(row =>
{
row.RelativeItem().Text("Ingresados por Remito:").SemiBold();
row.RelativeItem().AlignRight().Text(Model.TotalIngresadosPorRemito.ToString("N0"));
}); // <-- SOLUCIÓN: Borde sólido simple.
foreach (var item in Model.Detalles)
{
var totalSeccion = item.Devueltos - item.Llevados;
innerCol.Item().PaddingTop(5).Row(row =>
{
row.ConstantItem(100).Text(item.Tipo).SemiBold();
row.RelativeItem().Column(sub =>
{
sub.Spacing(2);
sub.Item().Row(r => {
r.RelativeItem().Text("Llevados");
r.RelativeItem().AlignRight().Text($"-{item.Llevados:N0}");
});
sub.Item().Row(r => {
r.RelativeItem().Text("Devueltos");
r.RelativeItem().AlignRight().Text($"{item.Devueltos:N0}");
});
sub.Item().BorderTop(1.5f).BorderColor(Colors.Black).PaddingTop(2).Row(r => {
r.RelativeItem().Text(t => t.Span("Total").SemiBold());
r.RelativeItem().AlignRight().Text(t => t.Span(totalSeccion.ToString("N0")).SemiBold());
});
});
});
}
});
column.Item().PaddingTop(10).Column(finalCol =>
{
finalCol.Spacing(2);
Action<RowDescriptor, string, string, bool> AddTotalRow = (row, label, value, isBold) =>
{
var text = row.RelativeItem().Text(label);
if (isBold) text.SemiBold();
var valueText = row.ConstantItem(80).AlignRight().Text(value);
if (isBold) valueText.SemiBold();
};
// Usamos bordes superiores para separar las líneas de total
finalCol.Item().BorderTop(2f).BorderColor(Colors.Black).PaddingTop(2).Row(row => AddTotalRow(row, "Total Devolución a la Fecha", Model.TotalDevolucionALaFecha.ToString("N0"), false));
finalCol.Item().BorderTop(1).BorderColor(Colors.Grey.Lighten2).PaddingTop(2).Row(row => AddTotalRow(row, "Total Devolución Días Anteriores", Model.TotalDevolucionDiasAnteriores.ToString("N0"), false));
finalCol.Item().BorderTop(1).BorderColor(Colors.Grey.Lighten2).PaddingTop(2).Row(row => AddTotalRow(row, "Total Devolución", Model.TotalDevolucionGeneral.ToString("N0"), false));
finalCol.Item().BorderTop(2f).BorderColor(Colors.Black).PaddingTop(5).Row(row => AddTotalRow(row, "Sin Cargo", Model.TotalSinCargo.ToString("N0"), false));
finalCol.Item().BorderTop(1).BorderColor(Colors.Grey.Lighten2).PaddingTop(2).Row(row => AddTotalRow(row, "Sobrantes", $"-{Model.TotalSobrantes.ToString("N0")}", false));
finalCol.Item().BorderTop(1).BorderColor(Colors.Grey.Lighten2).BorderBottom(1).BorderColor(Colors.Grey.Lighten2).PaddingTop(5).Row(row => AddTotalRow(row, "Diferencia", Model.DiferenciaFinal.ToString("N0"), true));
});
});
}
}
}