Update UI. GeneratePDF
Some checks failed
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Failing after 2m18s
Some checks failed
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Failing after 2m18s
This commit is contained in:
parent
b85796600b
commit
05aa480f27
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user