CaiWuXiTong/app/Support/CourierQuotePdf.php
limeng 9a25db91cc feat(报价管理): 存量报价整本批量录入及签署原图归档 (#346)
保留各家工作表报价原文、公式、独立执行日期及签署原件;审核后按执行日期管理版本。33项测试、336项断言通过。生产业务迁移已获明确授权,服务器私有备份已完成并逐条校验。
2026-10-16 14:56:44 +08:00

47 lines
1.5 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'],
'temporaryNote' => $data['temporary_note'] ?? null,
'billingRules' => $version->billing_rules,
'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;
}
}