mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-01 12:51:00 +00:00
34 lines
958 B
PHP
34 lines
958 B
PHP
<?php
|
|
|
|
namespace App\Domains\Receivables\Http\Controllers;
|
|
|
|
use App\Domains\Receivables\Contracts\PaymentPdfDataProvider;
|
|
use App\Domains\Receivables\Models\Payment;
|
|
use App\Platform\Http\Controller;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Serves the receipt behind a payment's public hash.
|
|
*
|
|
* Asking for a preview short-circuits to the view data the template is
|
|
* rendered from, so the layout can be looked at without a PDF engine in
|
|
* the loop; every other caller gets the file itself.
|
|
*/
|
|
class PaymentPdfController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly PaymentPdfDataProvider $paymentPdfDataProvider,
|
|
) {}
|
|
|
|
public function __invoke(Request $request, Payment $payment): mixed
|
|
{
|
|
if ($request->has('preview')) {
|
|
return $this->paymentPdfDataProvider->getPdfData($payment);
|
|
}
|
|
|
|
$receipt = $payment->getGeneratedPDFOrStream('payment');
|
|
|
|
return $receipt;
|
|
}
|
|
}
|