Add Logo Resources + Convert
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 8m15s
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 8m15s
This commit is contained in:
parent
b401941fe1
commit
a0a87ab306
@ -1,19 +1,16 @@
|
|||||||
using Documents.Interfaces;
|
using Documents.Interfaces;
|
||||||
using Documents.Models;
|
using Documents.Models;
|
||||||
|
using Domain.Dtos;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Transversal.Interfaces;
|
using Transversal.Interfaces;
|
||||||
|
|
||||||
namespace Documents.Services
|
|
||||||
{
|
|
||||||
public class DocumentTemplateService : IDocumentTemplateService
|
public class DocumentTemplateService : IDocumentTemplateService
|
||||||
{
|
{
|
||||||
private readonly ITemplateRenderer _templateRenderer;
|
private readonly ITemplateRenderer _templateRenderer;
|
||||||
private readonly IPdfGeneratorService _pdfGeneratorService;
|
private readonly IPdfGeneratorService _pdfGeneratorService;
|
||||||
|
|
||||||
public DocumentTemplateService(
|
public DocumentTemplateService(ITemplateRenderer templateRenderer, IPdfGeneratorService pdfGeneratorService)
|
||||||
ITemplateRenderer templateRenderer,
|
|
||||||
IPdfGeneratorService pdfGeneratorService)
|
|
||||||
{
|
{
|
||||||
_templateRenderer = templateRenderer;
|
_templateRenderer = templateRenderer;
|
||||||
_pdfGeneratorService = pdfGeneratorService;
|
_pdfGeneratorService = pdfGeneratorService;
|
||||||
@ -21,11 +18,66 @@ namespace Documents.Services
|
|||||||
|
|
||||||
public async Task<byte[]> GenerateDocumentAsync(DocumentGenerationRequest request)
|
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);
|
string html = await _templateRenderer.RenderAsync("Quotes/Template_v1.cshtml", request.Model);
|
||||||
// 👉 Generar PDF desde el HTML
|
|
||||||
return await _pdfGeneratorService.GeneratePdfFromHtmlAsync(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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|||||||
@ -87,9 +87,13 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<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>
|
<p>Fecha de emisión: @Model.IssueDate.ToString("dd/MM/yyyy")</p>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col izquierda">
|
<div class="col izquierda">
|
||||||
<!-- Datos del Cliente -->
|
<!-- Datos del Cliente -->
|
||||||
@ -127,10 +131,10 @@
|
|||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Descripción</th>
|
<th style="width: 40%;">Descripción</th>
|
||||||
<th>Cantidad</th>
|
<th style="width: 15%; text-align: center;">Cantidad</th>
|
||||||
<th>Precio Unitario</th>
|
<th style="width: 20%; text-align: right;">Precio Unitario</th>
|
||||||
<th>Subtotal</th>
|
<th style="width: 25%; text-align: right;">Subtotal</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -138,9 +142,9 @@
|
|||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>@item.Description</td>
|
<td>@item.Description</td>
|
||||||
<td>@item.Quantity</td>
|
<td style="text-align: center;">@item.Quantity</td>
|
||||||
<td>@item.UnitPrice.ToString("C", culture)</td>
|
<td style="text-align: right;">@item.UnitPrice.ToString("C", culture)</td>
|
||||||
<td>@item.Total.ToString("C", culture)</td>
|
<td style="text-align: right;">@item.Total.ToString("C", culture)</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@ -90,5 +90,10 @@
|
|||||||
/// Datos comerciales del cliente.
|
/// Datos comerciales del cliente.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public QuoteCustomerDto Customer { get; set; } = new();
|
public QuoteCustomerDto Customer { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logo de la compañia.
|
||||||
|
/// </summary>
|
||||||
|
public string LogoBase64 { get; set; } = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,4 +56,6 @@ RUN dotnet publish "./phronCare.API.csproj" -c $BUILD_CONFIGURATION -o /app/publ
|
|||||||
FROM base AS final
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=publish /app/publish .
|
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"]
|
ENTRYPOINT ["dotnet", "phronCare.API.dll"]
|
||||||
BIN
phronCare.API/Resources/logo.png
Normal file
BIN
phronCare.API/Resources/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 176 KiB |
@ -13,6 +13,14 @@
|
|||||||
<Content Remove="App.Config" />
|
<Content Remove="App.Config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="Resources\logo.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Resources\logo.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.Config" />
|
<None Include="App.Config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user