45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\Business\CourierQuoteVersion;
|
|
use Illuminate\Support\Carbon;
|
|
use RuntimeException;
|
|
|
|
final class CourierQuotePdf
|
|
{
|
|
public function __construct(private readonly CourierQuoteConfirmation $confirmation)
|
|
{
|
|
}
|
|
|
|
public function render(CourierQuoteVersion $version, ?string $signatureDate = null): string
|
|
{
|
|
$data = $this->confirmation->data($version);
|
|
$signatureDate = Carbon::parse($signatureDate ?: now())->format('Y年n月j日');
|
|
$html = view('business.pdf.courier-quote', [
|
|
'version' => $version,
|
|
'change' => $version->change,
|
|
'values' => $data['values'],
|
|
'formulas' => $data['formulas'],
|
|
'partyA' => $data['party_a'],
|
|
'expiryDate' => $data['expiry_date'],
|
|
'faceFee' => $data['face_fee'],
|
|
'bubbleCoefficient' => $data['bubble_coefficient'],
|
|
'signatureDate' => $signatureDate,
|
|
'generatedAt' => now(),
|
|
'fontPath' => str_replace('\\', '/', resource_path('fonts/DroidSansFallback.ttf')),
|
|
])->render();
|
|
|
|
$pdf = app('dompdf.wrapper');
|
|
$pdf->setPaper('a4', 'landscape');
|
|
$pdf->loadHTML($html, 'UTF-8');
|
|
$bytes = $pdf->output();
|
|
|
|
if (! is_string($bytes) || ! str_starts_with($bytes, '%PDF-')) {
|
|
throw new RuntimeException('报价 PDF 生成失败。');
|
|
}
|
|
|
|
return $bytes;
|
|
}
|
|
}
|