Send invoices by email.

This commit is contained in:
2025-01-09 11:18:12 +01:00
parent 8da6da471d
commit 6235112f74
19 changed files with 468 additions and 23 deletions

View File

@@ -9,10 +9,29 @@ use Illuminate\Http\Response;
class PdfController extends Controller
{
/**
* Return an invoice as download for the specified resource.
*/
public function downloadInvoice(int $invoice_id): Response
{
return $this->buildInvoicePdf($invoice_id)->stream();
}
/**
* Return a rendered pdf invoice as string to build an email attachment from it for the specified resource.
*/
public function attachInvoice(int $invoice_id): string
{
return $this->buildInvoicePdf($invoice_id)->output();
}
/**
* Render the pdf view for the given invoice.
*/
protected function buildInvoicePdf(int $invoice_id): \Barryvdh\DomPDF\PDF
{
$invoice = Invoice::find($invoice_id);
return Pdf::loadView('pdfs.invoice', ['invoice' => $invoice->load(['address', 'delivery']), 'options' => Option::optionsAsObject()])->stream();
return Pdf::loadView('pdfs.invoice', ['invoice' => $invoice->load(['address', 'delivery']), 'options' => Option::optionsAsObject()]);
}
}