Add Logo Resources + Convert
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 8m15s

This commit is contained in:
Leandro Hernan Rojas 2025-05-16 19:20:31 -03:00
parent b401941fe1
commit a0a87ab306
6 changed files with 96 additions and 25 deletions

View File

@ -1,19 +1,16 @@
using Documents.Interfaces;
using Documents.Models;
using Domain.Dtos;
using System.Reflection;
using System.Text;
using Transversal.Interfaces;
namespace Documents.Services
public class DocumentTemplateService : IDocumentTemplateService
{
public class DocumentTemplateService : IDocumentTemplateService
{
private readonly ITemplateRenderer _templateRenderer;
private readonly IPdfGeneratorService _pdfGeneratorService;
public DocumentTemplateService(
ITemplateRenderer templateRenderer,
IPdfGeneratorService pdfGeneratorService)
public DocumentTemplateService(ITemplateRenderer templateRenderer, IPdfGeneratorService pdfGeneratorService)
{
_templateRenderer = templateRenderer;
_pdfGeneratorService = pdfGeneratorService;
@ -21,11 +18,66 @@ namespace Documents.Services
public async Task<byte[]> GenerateDocumentAsync(DocumentGenerationRequest request)
{
// 👉 Renderizar HTML usando RazorLight
// Leer logo
var logoPath = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "logo.png");
var logoBase64 = GetImageBase64(logoPath);
// Inyectar al modelo si corresponde
if (request.Model is QuoteDto quote)
{
quote.LogoBase64 = logoBase64;
}
string html = await _templateRenderer.RenderAsync("Quotes/Template_v1.cshtml", request.Model);
// 👉 Generar PDF desde el HTML
return await _pdfGeneratorService.GeneratePdfFromHtmlAsync(html);
}
private static string GetImageBase64(string imagePath)
{
if (!File.Exists(imagePath))
return "";
byte[] imageBytes = File.ReadAllBytes(imagePath);
return Convert.ToBase64String(imageBytes);
}
}
//using Documents.Interfaces;
//using Documents.Models;
//using System.Reflection;
//using System.Text;
//using Transversal.Interfaces;
//namespace Documents.Services
//{
// public class DocumentTemplateService : IDocumentTemplateService
// {
// private readonly ITemplateRenderer _templateRenderer;
// private readonly IPdfGeneratorService _pdfGeneratorService;
// public DocumentTemplateService(
// ITemplateRenderer templateRenderer,
// IPdfGeneratorService pdfGeneratorService)
// {
// _templateRenderer = templateRenderer;
// _pdfGeneratorService = pdfGeneratorService;
// }
// public async Task<byte[]> GenerateDocumentAsync(DocumentGenerationRequest request)
// {
// // 👉 Renderizar HTML usando RazorLight
// string html = await _templateRenderer.RenderAsync("Quotes/Template_v1.cshtml", request.Model);
// // 👉 Generar PDF desde el HTML
// return await _pdfGeneratorService.GeneratePdfFromHtmlAsync(html);
// }
// private static string GetImageBase64(string imagePath)
// {
// if (!File.Exists(imagePath))
// return "";
// byte[] imageBytes = File.ReadAllBytes(imagePath);
// return Convert.ToBase64String(imageBytes);
// }
// }
//}

View File

@ -87,9 +87,13 @@
</head>
<body>
<div class="header">
<h2>Presupuesto Nº @Model.Quotenumber</h2>
<img src="data:image/png;base64,@Model.LogoBase64" alt="Logo" style="height: 60px; float: left;" />
<div style="margin-left: 70px;">
<h2>Presupuesto</h2>
<h2>@Model.Quotenumber</h2>
<p>Fecha de emisión: @Model.IssueDate.ToString("dd/MM/yyyy")</p>
</div>
</div>
<div class="row">
<div class="col izquierda">
<!-- Datos del Cliente -->
@ -127,10 +131,10 @@
<table>
<thead>
<tr>
<th>Descripción</th>
<th>Cantidad</th>
<th>Precio Unitario</th>
<th>Subtotal</th>
<th style="width: 40%;">Descripción</th>
<th style="width: 15%; text-align: center;">Cantidad</th>
<th style="width: 20%; text-align: right;">Precio Unitario</th>
<th style="width: 25%; text-align: right;">Subtotal</th>
</tr>
</thead>
<tbody>
@ -138,9 +142,9 @@
{
<tr>
<td>@item.Description</td>
<td>@item.Quantity</td>
<td>@item.UnitPrice.ToString("C", culture)</td>
<td>@item.Total.ToString("C", culture)</td>
<td style="text-align: center;">@item.Quantity</td>
<td style="text-align: right;">@item.UnitPrice.ToString("C", culture)</td>
<td style="text-align: right;">@item.Total.ToString("C", culture)</td>
</tr>
}
</tbody>

View File

@ -90,5 +90,10 @@
/// Datos comerciales del cliente.
/// </summary>
public QuoteCustomerDto Customer { get; set; } = new();
/// <summary>
/// Logo de la compañia.
/// </summary>
public string LogoBase64 { get; set; } = "";
}
}

View File

@ -56,4 +56,6 @@ RUN dotnet publish "./phronCare.API.csproj" -c $BUILD_CONFIGURATION -o /app/publ
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
# ✅ Copiar el logo al contenedor final
COPY phronCare.API/Resources/logo.png /app/Resources/logo.png
ENTRYPOINT ["dotnet", "phronCare.API.dll"]

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

View File

@ -13,6 +13,14 @@
<Content Remove="App.Config" />
</ItemGroup>
<ItemGroup>
<None Remove="Resources\logo.png" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\logo.png" />
</ItemGroup>
<ItemGroup>
<None Include="App.Config" />
</ItemGroup>