@php $headerCompany = $company ?? (\App\Models\Company::first()); $headerDocument = $document ?? null; $headerEstablishment = $establishment ?? null; if (!$headerEstablishment && $headerDocument && isset($headerDocument->establishment)) { $headerEstablishment = $headerDocument->establishment; } $headerEstablishmentId = null; if ($headerEstablishment && isset($headerEstablishment->id)) { $headerEstablishmentId = $headerEstablishment->id; } elseif ($headerDocument && isset($headerDocument->establishment_id)) { $headerEstablishmentId = $headerDocument->establishment_id; } elseif (auth()->check() && auth()->user()->establishment_id) { $headerEstablishmentId = auth()->user()->establishment_id; } $headerLogoPath = null; $logoBases = [base_path('media/logos'), public_path('logos_de_sistema')]; if ($headerEstablishmentId) { $nameCandidates = [ "logosuc_{$headerEstablishmentId}.jpg", "logosuc_{$headerEstablishmentId}.jpeg", "logosuc_{$headerEstablishmentId}.png", "logosuc_{$headerEstablishmentId}.webp", "avatar_logosuc_{$headerEstablishmentId}.jpg", "avatar_logosuc_{$headerEstablishmentId}.jpeg", "avatar_logosuc_{$headerEstablishmentId}.png", "avatar_logosuc_{$headerEstablishmentId}.webp", ]; foreach ($logoBases as $baseDir) { foreach ($nameCandidates as $fileName) { $candidate = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $fileName; if (file_exists($candidate) && is_readable($candidate)) { $headerLogoPath = $candidate; break 2; } } } } if (!$headerLogoPath && $headerCompany && !empty($headerCompany->logo)) { $companyLogo = ltrim((string) $headerCompany->logo, '/\\'); $companyCandidates = [ base_path($companyLogo), public_path($companyLogo), ]; foreach ($companyCandidates as $candidate) { if (file_exists($candidate) && is_readable($candidate)) { $headerLogoPath = $candidate; break; } } } if (!$headerLogoPath) { foreach ($logoBases as $baseDir) { foreach (['logo_sistema.jpg', 'logo_sistema.jpeg', 'logo_sistema.png', 'logo_sistema.webp'] as $fileName) { $candidate = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $fileName; if (file_exists($candidate) && is_readable($candidate)) { $headerLogoPath = $candidate; break 2; } } } } $headerAddress = ''; if ($headerEstablishment) { $trade = trim((string)($headerEstablishment->trade_address ?? '')); $addr = trim((string)($headerEstablishment->address ?? '')); // Prioridad: direccion comercial (trade_address), luego address. // Si un valor parece solo numerico/codigo (ej: 326631-3), se descarta. $isCodeLike = function ($value) { return $value !== '' && preg_match('/^[0-9\-\.\s]+$/', $value); }; if ($trade !== '' && $trade !== '-' && !$isCodeLike($trade)) { $headerAddress = $trade; } elseif ($addr !== '' && $addr !== '-' && !$isCodeLike($addr)) { $headerAddress = $addr; } elseif ($trade !== '' && $trade !== '-') { $headerAddress = $trade; } elseif ($addr !== '' && $addr !== '-') { $headerAddress = $addr; } } // Resolver nombre de establecimiento directamente desde DB para evitar valores vacios/inconsistentes. $dbEstablishment = null; if ($headerEstablishmentId) { $dbEstablishment = \App\Models\Establishment::query() ->select('id', 'description', 'trade_address', 'address', 'telephone') ->find($headerEstablishmentId); } $headerEstablishmentName = ''; if ($dbEstablishment && !empty($dbEstablishment->description) && $dbEstablishment->description !== '-') { $headerEstablishmentName = (string) $dbEstablishment->description; } elseif ($headerEstablishment && !empty($headerEstablishment->description) && $headerEstablishment->description !== '-') { $headerEstablishmentName = (string) $headerEstablishment->description; } else { $headerEstablishmentName = 'SIN ESTABLECIMIENTO'; } $headerPhone = ''; if ($headerEstablishment && !empty($headerEstablishment->telephone) && $headerEstablishment->telephone !== '-') { $headerPhone = (string) $headerEstablishment->telephone; } $ticketTitle = $title ?? ''; $ticketCode = $code ?? ''; $headerFontSize = $header_font_size ?? '10px'; $titleFontSize = $title_font_size ?? '12px'; $codeFontSize = $code_font_size ?? '11px'; $logoMaxWidth = $logo_max_width ?? '280px'; $logoMaxHeight = $logo_max_height ?? '150px'; @endphp
@if($headerLogoPath)
{{ $headerEstablishmentName }}
@endif @if($headerAddress !== '')
DIRECCION: {{ $headerAddress }}
@endif
ESTABLECIMIENTO: {{ $headerEstablishmentName }}
@if($headerPhone !== '')
TELEFONO: {{ $headerPhone }}
@endif @if($ticketTitle !== '')
{{ $ticketTitle }}
@endif @if($ticketCode !== '')
{{ $ticketCode }}
@endif