mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Merge InvoicePdfController, EstimatePdfController, PaymentPdfController into DocumentPdfController with invoice(), estimate(), payment() methods. Delete DownloadInvoicePdfController and DownloadPaymentPdfController (dead code — not mapped in any routes). Move DownloadReceiptController logic to ExpensesController::downloadReceipt() (expense receipts, not PDF documents).
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Pdf;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Estimate;
|
|
use App\Models\Invoice;
|
|
use App\Models\Payment;
|
|
use App\Services\EstimateService;
|
|
use App\Services\InvoiceService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DocumentPdfController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly InvoiceService $invoiceService,
|
|
private readonly EstimateService $estimateService,
|
|
) {}
|
|
|
|
public function invoice(Request $request, Invoice $invoice)
|
|
{
|
|
if ($request->has('preview')) {
|
|
return $this->invoiceService->getPdfData($invoice);
|
|
}
|
|
|
|
return $invoice->getGeneratedPDFOrStream('invoice');
|
|
}
|
|
|
|
public function estimate(Request $request, Estimate $estimate)
|
|
{
|
|
if ($request->has('preview')) {
|
|
return $this->estimateService->getPdfData($estimate);
|
|
}
|
|
|
|
return $estimate->getGeneratedPDFOrStream('estimate');
|
|
}
|
|
|
|
public function payment(Request $request, Payment $payment)
|
|
{
|
|
if ($request->has('preview')) {
|
|
return view('app.pdf.payment.payment');
|
|
}
|
|
|
|
return $payment->getGeneratedPDFOrStream('payment');
|
|
}
|
|
}
|