topnotch_ordersystem/app/Http/Controllers/InvoiceController.php

32 lines
972 B
PHP
Raw Normal View History

2024-11-09 15:13:04 -05:00
<?php
namespace App\Http\Controllers;
use App\Models\Invoice;
use Spatie\Browsershot\Browsershot;
use Spatie\LaravelPdf\Facades\Pdf;
class InvoiceController extends Controller
{
public function pdf(int $id)
{
$invoice = Invoice::find($id);
$firstOrderPo = $invoice->orders()->first()->customer_po ?? '';
$firstOrderPo = preg_replace('/[\\\\\/:*?"<>|]/', '', $firstOrderPo); // Remove invalid characters
$firstOrderPo = str_replace(' ', '-', $firstOrderPo);
$url = strtolower($invoice->internal_id.'-'.$invoice->customer->company_name.'-'.$firstOrderPo.'.pdf');
2024-11-09 15:13:04 -05:00
Pdf::view('pdf.invoice', ['invoice' => $invoice])
->withBrowsershot(function (Browsershot $browsershot) {
$browsershot->noSandbox();
})
->margins(8, 8, 15, 8)
->footerView('pdf.invoice-footer', ['invoice' => $invoice])
->save($url);
return redirect($url);
}
}