Spaces:
Runtime error
Runtime error
Download src/SCM.Infrastructure/Relatorios/PdfReportService.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 6.61 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Relatorios/PdfReportService.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Infrastructure/Relatorios/PdfReportService.cs
-
curl -L -o PdfReportService.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Relatorios/PdfReportService.cs
6.61 kB
| using QuestPDF.Fluent; | |
| using QuestPDF.Helpers; | |
| using QuestPDF.Infrastructure; | |
| using SCM.Application.Controle; | |
| using SCM.Application.Medicao; | |
| using SCM.Application.Qualidade; | |
| using SCM.Application.Relatorios; | |
| namespace SCM.Infrastructure.Relatorios; | |
| /// <summary> | |
| /// Geração de PDFs com QuestPDF (licença Community). Layouts simples A4 — cabeçalho do | |
| /// documento, tabelas e totais. Substitui os relatórios impressos do legado (sem o subsistema | |
| /// proprietário de relatórios). | |
| /// </summary> | |
| public sealed class PdfReportService : IPdfReportService | |
| { | |
| static PdfReportService() | |
| { | |
| QuestPDF.Settings.License = LicenseType.Community; | |
| } | |
| public byte[] Faturamento(FaturamentoResponse f) | |
| { | |
| return Document.Create(doc => | |
| { | |
| doc.Page(page => | |
| { | |
| Pagina(page, "Relatório de Faturamento por EAP", | |
| $"Contrato {f.ContratoId} · Valor do contrato R$ {f.ValorContrato:N2}"); | |
| page.Content().Column(col => | |
| { | |
| col.Spacing(8); | |
| col.Item().Text($"Total previsto: R$ {f.TotalPrevisto:N2}").Bold(); | |
| col.Item().Text($"Total apropriado: R$ {f.TotalApropriado:N2}").Bold(); | |
| col.Item().Table(t => | |
| { | |
| t.ColumnsDefinition(c => | |
| { | |
| c.RelativeColumn(2); // EAP | |
| c.RelativeColumn(1); // tipo | |
| c.RelativeColumn(1); // % | |
| c.RelativeColumn(2); // previsto | |
| c.RelativeColumn(1); // fração | |
| c.RelativeColumn(2); // apropriado | |
| }); | |
| Cabecalho(t, "EAP", "Tipo", "% Item", "Previsto", "Fração", "Apropriado"); | |
| foreach (var i in f.Itens) | |
| { | |
| Celula(t, i.EapCodigo); | |
| Celula(t, i.TipoCalculo); | |
| Celula(t, $"{i.PercentualItem:N2}"); | |
| Celula(t, $"R$ {i.ValorPrevisto:N2}"); | |
| Celula(t, $"{i.FracaoFisica:P2}"); | |
| Celula(t, $"R$ {i.ValorApropriado:N2}"); | |
| } | |
| }); | |
| }); | |
| }); | |
| }).GeneratePdf(); | |
| } | |
| public byte[] Acompanhamento(FotoAcompanhamentoResponse foto, IReadOnlyList<HistAcompanhamentoResponse> historico) | |
| { | |
| return Document.Create(doc => | |
| { | |
| doc.Page(page => | |
| { | |
| Pagina(page, "Resumo de Acompanhamento Físico", | |
| $"Obra {foto.ObraId} · Data {foto.Data:dd/MM/yyyy}"); | |
| page.Content().Column(col => | |
| { | |
| col.Spacing(8); | |
| col.Item().Text("Foto atual").Bold().FontSize(12); | |
| col.Item().Text($"Liberado: {foto.QtLiberada:N2} Não liberado: {foto.QtNaoLiberada:N2} Total: {foto.QtTotal:N2}"); | |
| col.Item().Text($"Avançado: {foto.QtAvancada:N2} Cadastrado: {foto.QtCadastrada:N2}"); | |
| col.Item().Text($"Itens liberados: {foto.ItensLiberados} Itens não liberados: {foto.ItensNaoLiberados}"); | |
| col.Item().PaddingTop(10).Text("Histórico").Bold().FontSize(12); | |
| col.Item().Table(t => | |
| { | |
| t.ColumnsDefinition(c => | |
| { | |
| c.RelativeColumn(2); | |
| c.RelativeColumn(1); | |
| c.RelativeColumn(1); | |
| c.RelativeColumn(1); | |
| c.RelativeColumn(1); | |
| }); | |
| Cabecalho(t, "Data", "Liberado", "Não lib.", "Avançado", "Cadastrado"); | |
| foreach (var h in historico) | |
| { | |
| Celula(t, h.Data.ToString("dd/MM/yyyy")); | |
| Celula(t, $"{h.QtLiberada:N2}"); | |
| Celula(t, $"{h.QtNaoLiberada:N2}"); | |
| Celula(t, $"{h.QtAvancada:N2}"); | |
| Celula(t, $"{h.QtCadastrada:N2}"); | |
| } | |
| }); | |
| }); | |
| }); | |
| }).GeneratePdf(); | |
| } | |
| public byte[] RelatorioTecnico(RelatorioTecnicoResponse r) | |
| { | |
| var tipoExt = r.Tipo == "Q" ? "Controle de Qualidade (CQ)" : "Produção (PRD)"; | |
| return Document.Create(doc => | |
| { | |
| doc.Page(page => | |
| { | |
| Pagina(page, $"Relatório Técnico nº {r.Numero}", tipoExt); | |
| page.Content().Column(col => | |
| { | |
| col.Spacing(6); | |
| col.Item().Text($"Obra: {r.ObraId}"); | |
| col.Item().Text($"Agente: {(r.AgenteId?.ToString() ?? "—")}"); | |
| col.Item().Text($"Produção: {(r.ProducaoId?.ToString() ?? "—")}"); | |
| col.Item().Text($"Tipo: {r.Tipo} Número: {r.Numero}"); | |
| col.Item().Text($"Status: {r.Status}"); | |
| col.Item().Text($"Emitido em: {r.DataEmissao:dd/MM/yyyy HH:mm}"); | |
| }); | |
| }); | |
| }).GeneratePdf(); | |
| } | |
| private static void Pagina(PageDescriptor page, string titulo, string subtitulo) | |
| { | |
| page.Size(PageSizes.A4); | |
| page.Margin(36); | |
| page.DefaultTextStyle(x => x.FontSize(10)); | |
| page.Header().Column(col => | |
| { | |
| col.Item().Text("SCM 2.0").FontSize(9).FontColor(Colors.Grey.Medium); | |
| col.Item().Text(titulo).Bold().FontSize(16); | |
| col.Item().Text(subtitulo).FontSize(10).FontColor(Colors.Grey.Darken1); | |
| col.Item().PaddingTop(4).LineHorizontal(1).LineColor(Colors.Grey.Lighten1); | |
| }); | |
| page.Footer().AlignRight().Text(x => | |
| { | |
| x.Span("Página "); | |
| x.CurrentPageNumber(); | |
| x.Span(" / "); | |
| x.TotalPages(); | |
| }); | |
| } | |
| private static void Cabecalho(TableDescriptor t, params string[] titulos) | |
| { | |
| t.Header(h => | |
| { | |
| foreach (var titulo in titulos) | |
| h.Cell().Background(Colors.Grey.Lighten3).Padding(4).Text(titulo).Bold(); | |
| }); | |
| } | |
| private static void Celula(TableDescriptor t, string valor) | |
| => t.Cell().BorderBottom(1).BorderColor(Colors.Grey.Lighten2).Padding(4).Text(valor); | |
| } | |