251 lines
11 KiB
C#
251 lines
11 KiB
C#
using System;
|
|
using System.IO;
|
|
using MLL;
|
|
using QuestPDF.Fluent;
|
|
using QuestPDF.Helpers;
|
|
using QuestPDF.Infrastructure;
|
|
using Color = QuestPDF.Infrastructure.Color;
|
|
|
|
namespace TLL
|
|
{
|
|
public static class FichaFuncionarioPDF
|
|
{
|
|
static FichaFuncionarioPDF()
|
|
{
|
|
QuestPDF.Settings.License = LicenseType.Community;
|
|
}
|
|
|
|
public static FichaPDFResultado GerarEAbrir(ModeloFuncionarios f, string? pastaDestino = null)
|
|
{
|
|
var resultado = Gerar(f, pastaDestino);
|
|
|
|
if (resultado.Sucesso && resultado.Caminho != null)
|
|
{
|
|
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
|
|
{
|
|
FileName = resultado.Caminho,
|
|
UseShellExecute = true
|
|
});
|
|
}
|
|
|
|
return resultado;
|
|
}
|
|
|
|
public static FichaPDFResultado Gerar(ModeloFuncionarios f, string? pastaDestino = null)
|
|
{
|
|
try
|
|
{
|
|
pastaDestino ??= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Docs");
|
|
Directory.CreateDirectory(pastaDestino);
|
|
|
|
string nomeLimpo = f.NOME?.Replace(" ", "_") ?? "funcionario";
|
|
string caminho = Path.Combine(pastaDestino,
|
|
$"Funcionario_{nomeLimpo}_{DateTime.Now:yyyyMMdd_HHmmss}.pdf");
|
|
|
|
// ── Conversões antecipadas ────────────────────────────────────
|
|
string demitido = f.DEMITIDO ? "SIM" : "NÃO";
|
|
string masterUser = f.MASTERUSER ? "SIM" : "NÃO";
|
|
string vendedor = f.VENDEDOR ? "SIM" : "NÃO";
|
|
string tecnico = f.TECNICO ? "SIM" : "NÃO";
|
|
|
|
string dataAdm = f.DATA_ADM?.ToString("dd/MM/yyyy") ?? "—";
|
|
string dataDem = f.DATA_DEM?.ToString("dd/MM/yyyy") ?? "—";
|
|
string aniver = f.ANIVER?.ToString("dd/MM/yyyy") ?? "—";
|
|
|
|
Document.Create(container =>
|
|
{
|
|
container.Page(page =>
|
|
{
|
|
page.Size(PageSizes.A4);
|
|
page.Margin(2, Unit.Centimetre);
|
|
page.DefaultTextStyle(x => x.FontSize(10).FontFamily("Arial"));
|
|
|
|
// ── HEADER ────────────────────────────────────────────
|
|
page.Header().Column(col =>
|
|
{
|
|
col.Item().Row(row =>
|
|
{
|
|
row.RelativeItem().Column(c =>
|
|
{
|
|
c.Item().Text("FICHA DO FUNCIONÁRIO")
|
|
.FontSize(16).Bold()
|
|
.FontColor(Color.FromHex("#2563EB"));
|
|
|
|
c.Item().Text(f.NOME ?? "")
|
|
.FontSize(13).Bold()
|
|
.FontColor(Color.FromHex("#1E293B"));
|
|
|
|
c.Item().Text($"CPF: {f.CPF ?? ""}")
|
|
.FontSize(9)
|
|
.FontColor(Color.FromHex("#64748B"));
|
|
});
|
|
|
|
row.ConstantItem(120).AlignRight().Column(c =>
|
|
{
|
|
c.Item().Text("Status")
|
|
.FontSize(8).FontColor(Color.FromHex("#94A3B8"));
|
|
|
|
c.Item().Text(f.DEMITIDO ? "DEMITIDO" : "ATIVO")
|
|
.FontSize(10).Bold()
|
|
.FontColor(f.DEMITIDO
|
|
? Color.FromHex("#DC2626")
|
|
: Color.FromHex("#16A34A"));
|
|
|
|
c.Item().Text(DateTime.Now.ToString("dd/MM/yyyy HH:mm"))
|
|
.FontSize(8)
|
|
.FontColor(Color.FromHex("#64748B"));
|
|
});
|
|
});
|
|
|
|
col.Item().PaddingTop(6).LineHorizontal(1)
|
|
.LineColor(Color.FromHex("#E2E8F0"));
|
|
});
|
|
|
|
// ── CONTENT ───────────────────────────────────────────
|
|
page.Content().PaddingTop(10).Column(col =>
|
|
{
|
|
Secao(col, "DADOS PESSOAIS");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("Código", f.CODIGO, "Nome", f.NOME),
|
|
("CPF", f.CPF, "RG", f.CI),
|
|
("Pai", f.PAI, "Mãe", f.MAE),
|
|
("Estado Civil", f.ECIVIL, "Regime", f.REGIME)
|
|
});
|
|
|
|
Secao(col, "DOCUMENTOS");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("CTPS", f.CTPS, "CNH", f.CNH),
|
|
("Categoria CNH", f.CAT_CNH, "", null)
|
|
});
|
|
|
|
Secao(col, "ENDEREÇO");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("Endereço", f.ENDERECO, "Bairro", f.BAIRRO),
|
|
("Cidade", f.CIDADE, "UF", f.UF)
|
|
});
|
|
|
|
Secao(col, "CONTATO");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("Telefone", f.TELEFONE, "", null)
|
|
});
|
|
|
|
Secao(col, "BANCÁRIO");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("Banco", f.BANCO, "Agência", f.AGENCIA),
|
|
("Conta", f.CONTA, "", null)
|
|
});
|
|
|
|
Secao(col, "FUNÇÕES");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("Master User", masterUser, "Vendedor", vendedor),
|
|
("Técnico", tecnico, "Demitido", demitido)
|
|
});
|
|
|
|
Secao(col, "DATAS");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("Admissão", dataAdm, "Demissão", dataDem),
|
|
("Aniversário", aniver, "", null)
|
|
});
|
|
|
|
if (!string.IsNullOrWhiteSpace(f.OBSERV))
|
|
{
|
|
Secao(col, "OBSERVAÇÕES");
|
|
col.Item()
|
|
.Background(Color.FromHex("#F8FAFC"))
|
|
.Padding(8)
|
|
.Border(0.5f)
|
|
.BorderColor(Color.FromHex("#E2E8F0"))
|
|
.Text(f.OBSERV)
|
|
.FontSize(9)
|
|
.FontColor(Color.FromHex("#475569"));
|
|
}
|
|
|
|
Secao(col, "REGISTRO");
|
|
Grid(col, new (string, string?, string, string?)[]
|
|
{
|
|
("ID", f.ID_FUNCIONARIO.ToString(), "", null)
|
|
});
|
|
});
|
|
|
|
// ── FOOTER ────────────────────────────────────────────
|
|
page.Footer().AlignCenter().Text(text =>
|
|
{
|
|
text.Span("LevelOS • Documento gerado em ")
|
|
.FontSize(8).FontColor(Color.FromHex("#94A3B8"));
|
|
|
|
text.Span(DateTime.Now.ToString("dd/MM/yyyy HH:mm"))
|
|
.FontSize(8).FontColor(Color.FromHex("#94A3B8"));
|
|
});
|
|
});
|
|
}).GeneratePdf(caminho);
|
|
|
|
return new FichaPDFResultado
|
|
{
|
|
Sucesso = true,
|
|
Caminho = caminho,
|
|
Mensagem = "Ficha gerada com sucesso!"
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new FichaPDFResultado
|
|
{
|
|
Sucesso = false,
|
|
Mensagem = ex.Message
|
|
};
|
|
}
|
|
}
|
|
|
|
private static void Secao(ColumnDescriptor col, string titulo)
|
|
{
|
|
col.Item().PaddingTop(10).Text(titulo)
|
|
.FontSize(9).Bold()
|
|
.FontColor(Color.FromHex("#2563EB"));
|
|
|
|
col.Item().LineHorizontal(0.5f)
|
|
.LineColor(Color.FromHex("#E2E8F0"));
|
|
}
|
|
|
|
private static void Grid(ColumnDescriptor col,
|
|
(string l1, string? v1, string l2, string? v2)[] linhas)
|
|
{
|
|
foreach (var (l1, v1, l2, v2) in linhas)
|
|
{
|
|
col.Item().PaddingTop(4).Row(row =>
|
|
{
|
|
row.RelativeItem().Column(c =>
|
|
{
|
|
c.Item().Text(l1)
|
|
.FontSize(7)
|
|
.FontColor(Color.FromHex("#94A3B8"));
|
|
|
|
c.Item().Text(v1 ?? "—")
|
|
.FontSize(10)
|
|
.FontColor(Color.FromHex("#1E293B"));
|
|
});
|
|
|
|
if (!string.IsNullOrEmpty(l2))
|
|
{
|
|
row.RelativeItem().Column(c =>
|
|
{
|
|
c.Item().Text(l2)
|
|
.FontSize(7)
|
|
.FontColor(Color.FromHex("#94A3B8"));
|
|
|
|
c.Item().Text(v2 ?? "—")
|
|
.FontSize(10)
|
|
.FontColor(Color.FromHex("#1E293B"));
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
} |