diff --git a/Documents/Services/DocumentTemplateService.cs b/Documents/Services/DocumentTemplateService.cs index f769059..c909d89 100644 --- a/Documents/Services/DocumentTemplateService.cs +++ b/Documents/Services/DocumentTemplateService.cs @@ -1,31 +1,83 @@ 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) { - private readonly ITemplateRenderer _templateRenderer; - private readonly IPdfGeneratorService _pdfGeneratorService; + _templateRenderer = templateRenderer; + _pdfGeneratorService = pdfGeneratorService; + } - public DocumentTemplateService( - ITemplateRenderer templateRenderer, - IPdfGeneratorService pdfGeneratorService) + public async Task GenerateDocumentAsync(DocumentGenerationRequest request) + { + // 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) { - _templateRenderer = templateRenderer; - _pdfGeneratorService = pdfGeneratorService; + quote.LogoBase64 = logoBase64; } - public async Task 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); - } + string html = await _templateRenderer.RenderAsync("Quotes/Template_v1.cshtml", request.Model); + 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 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); +// } +// } +//} diff --git a/Documents/Templates/Quotes/Template_v1.cshtml b/Documents/Templates/Quotes/Template_v1.cshtml index a892132..663bed0 100644 --- a/Documents/Templates/Quotes/Template_v1.cshtml +++ b/Documents/Templates/Quotes/Template_v1.cshtml @@ -87,8 +87,12 @@
-

Presupuesto Nº @Model.Quotenumber

-

Fecha de emisión: @Model.IssueDate.ToString("dd/MM/yyyy")

+ Logo +
+

Presupuesto

+

@Model.Quotenumber

+

Fecha de emisión: @Model.IssueDate.ToString("dd/MM/yyyy")

+
@@ -127,10 +131,10 @@ - - - - + + + + @@ -138,9 +142,9 @@ { - - - + + + } diff --git a/Domain/Dtos/QuoteDto.cs b/Domain/Dtos/QuoteDto.cs index 43d846c..28d4094 100644 --- a/Domain/Dtos/QuoteDto.cs +++ b/Domain/Dtos/QuoteDto.cs @@ -90,5 +90,10 @@ /// Datos comerciales del cliente. /// public QuoteCustomerDto Customer { get; set; } = new(); + + /// + /// Logo de la compañia. + /// + public string LogoBase64 { get; set; } = ""; } } \ No newline at end of file diff --git a/phronCare.API/Dockerfile b/phronCare.API/Dockerfile index 9987abc..29e1cb0 100644 --- a/phronCare.API/Dockerfile +++ b/phronCare.API/Dockerfile @@ -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"] \ No newline at end of file diff --git a/phronCare.API/Resources/logo.png b/phronCare.API/Resources/logo.png new file mode 100644 index 0000000..8de6de5 Binary files /dev/null and b/phronCare.API/Resources/logo.png differ diff --git a/phronCare.API/phronCare.API.csproj b/phronCare.API/phronCare.API.csproj index f9a9fe7..7dbd028 100644 --- a/phronCare.API/phronCare.API.csproj +++ b/phronCare.API/phronCare.API.csproj @@ -13,6 +13,14 @@ + + + + + + + +
DescripciónCantidadPrecio UnitarioSubtotalDescripciónCantidadPrecio UnitarioSubtotal
@item.Description@item.Quantity@item.UnitPrice.ToString("C", culture)@item.Total.ToString("C", culture)@item.Quantity@item.UnitPrice.ToString("C", culture)@item.Total.ToString("C", culture)