32 lines
1.2 KiB
PHP
32 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\LegacyInvoice;
|
|
use App\Services\Billing\LegacyInvoicePdfRenderer;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class LegacyInvoicePdfController extends Controller
|
|
{
|
|
public function __invoke(LegacyInvoice $legacyInvoice, LegacyInvoicePdfRenderer $renderer): Response
|
|
{
|
|
Gate::authorize('downloadPdf', $legacyInvoice);
|
|
|
|
if (filled($legacyInvoice->pdf_path) && Storage::disk('local')->exists($legacyInvoice->pdf_path)) {
|
|
return response()->file(Storage::disk('local')->path($legacyInvoice->pdf_path), [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'inline; filename="'.$renderer->filename($legacyInvoice).'"',
|
|
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
|
]);
|
|
}
|
|
|
|
if (Schema::hasColumn('legacy_invoices', 'pdf_generated_at')) {
|
|
$legacyInvoice->forceFill(['pdf_generated_at' => now()])->save();
|
|
}
|
|
|
|
return $renderer->inlineResponse($legacyInvoice);
|
|
}
|
|
}
|