44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Enums\WebDesign\WebDesignPlatform;
|
|
use App\Models\Setting;
|
|
use App\Models\WebDesignQuote;
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
|
|
class WebDesignQuotePdfService
|
|
{
|
|
public function generate(WebDesignQuote $quote): string
|
|
{
|
|
$quote->load('creator');
|
|
|
|
$setting = Setting::where('key', 'setting')->first();
|
|
$settingValue = $setting ? json_decode((string) $setting->value) : null;
|
|
|
|
$platform = WebDesignPlatform::tryFrom($quote->platform);
|
|
|
|
$data = [
|
|
'quote' => $quote,
|
|
'platformLabel' => $platform?->label() ?? $quote->platform,
|
|
'licenseFeeUsd' => $platform?->annualLicenseFeeUsd() ?? 0,
|
|
'companyName' => $settingValue->company ?? 'Thế Giới Số',
|
|
'companyAddress' => $settingValue->address ?? '',
|
|
'companyPhone' => $settingValue->hotline ?? ($settingValue->tel ?? ''),
|
|
'companyEmail' => $settingValue->email ?? '',
|
|
'companyLogo' => $settingValue->logo ?? '',
|
|
'companyTaxCode' => $settingValue->tax ?? '',
|
|
'brandColor' => $settingValue->brand_color ?? '#1a56db',
|
|
];
|
|
|
|
return Pdf::loadView('pdf.web-design-quote', $data)
|
|
->setPaper('a4', 'portrait')
|
|
->output();
|
|
}
|
|
|
|
public function generateFileName(WebDesignQuote $quote): string
|
|
{
|
|
return 'Bao-gia-' . $quote->quote_number . '.pdf';
|
|
}
|
|
}
|