backoffice first commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\Preventivo;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PreventivoPdf
|
||||
{
|
||||
/**
|
||||
* Genera (o rigenera) il PDF del preventivo, lo salva sul disk 'local' e ritorna il path relativo.
|
||||
*/
|
||||
public static function genera(Preventivo $preventivo): string
|
||||
{
|
||||
$preventivo->loadMissing('cliente', 'items');
|
||||
|
||||
$pdf = Pdf::loadView('pdf.preventivo', [
|
||||
'preventivo' => $preventivo,
|
||||
'formatter' => ConfigurazioneFormatter::class,
|
||||
])->setPaper('a4');
|
||||
|
||||
$path = 'preventivi/preventivo-'.$preventivo->id.'.pdf';
|
||||
Storage::disk('local')->put($path, $pdf->output());
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/** Path assoluto del PDF sul filesystem (per allegati email). */
|
||||
public static function pathAssoluto(Preventivo $preventivo): ?string
|
||||
{
|
||||
if (! $preventivo->pdf_path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('local')->path($preventivo->pdf_path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user