- Implement AdminDomainOrderTest to cover admin functionalities for domain orders including listing, confirming registration, KYC updates, activation, rejection, and refunds. - Implement ClientDomainOrderTest to cover client functionalities for placing domain orders, including validation for balance, duplicate orders, and domain normalization. - Ensure proper handling of domain pricing and service statuses throughout the tests.
67 lines
2.1 KiB
PHP
67 lines
2.1 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' => $this->resolvePdfImagePath($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';
|
|
}
|
|
|
|
private function resolvePdfImagePath(?string $path): string
|
|
{
|
|
if (!$path) {
|
|
return '';
|
|
}
|
|
|
|
$urlPath = parse_url($path, PHP_URL_PATH) ?: $path;
|
|
|
|
if (str_starts_with($urlPath, '/storage/')) {
|
|
$localPath = storage_path('app/public/' . ltrim(substr($urlPath, strlen('/storage/')), '/'));
|
|
|
|
return file_exists($localPath) ? $localPath : $path;
|
|
}
|
|
|
|
if (str_starts_with($path, 'storage/')) {
|
|
$localPath = storage_path('app/public/' . substr($path, strlen('storage/')));
|
|
|
|
return file_exists($localPath) ? $localPath : $path;
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
}
|