Update UI. GeneratePDF
Some checks failed
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Failing after 2m18s

This commit is contained in:
Leandro Hernan Rojas 2025-05-16 20:57:57 -03:00
parent b85796600b
commit 05aa480f27
2 changed files with 37 additions and 2 deletions

View File

@ -378,8 +378,15 @@
_ => "bg-light text-dark"
};
private void PrintPdf(int quoteId)
private async void PrintPdf(int quoteId)
{
// lógica de impresión...
try
{
await quoteService.ExportPdfAsync(quoteId);
}
catch (Exception ex)
{
toastService.ShowError(ex.Message);
}
}
}

View File

@ -92,6 +92,34 @@ namespace phronCare.UIBlazor.Services.Sales.Quotes
var result = await _http.GetFromJsonAsync<PagedResult<QuoteDto>>(url);
return result!;
}
/// <summary>
/// Obtiene el PDF del presupuesto por ID como array de bytes.
/// </summary>
public async Task ExportPdfAsync(int quoteId)
{
try
{
var response = await _http.GetAsync($"/api/quote/{quoteId}/pdf");
if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync();
throw new Exception($"Error al generar PDF: {error}");
}
var bytes = await response.Content.ReadAsByteArrayAsync();
var base64 = Convert.ToBase64String(bytes);
var fileName = $"Presupuesto_{quoteId}.pdf";
await _js.InvokeVoidAsync("saveAsFile", fileName, base64);
}
catch (Exception ex)
{
var message = ex.Message ?? "No message";
throw new Exception($"ExportPdfAsync: {message}", ex);
}
}
}
public class CreateQuoteResult