@php use Illuminate\Support\Str; $kpis = is_array($analysis->kpis) ? array_values($analysis->kpis) : []; $charts = $charts ?? []; $isRtl = in_array(strtolower((string) ($analysis->language ?? '')), ['ar', 'arabic'], true); $primary = $branding['primary_color'] ?? '#1e3a8a'; $accent = $branding['accent_color'] ?? '#0f172a'; $firm = $branding['firm_name'] ?? config('platform.name', config('app.name')); $tagline = $branding['tagline'] ?? __('Research & Analysis'); $footer = $branding['footer_text'] ?? null; $hex2rgb = function (string $h): array { $h = ltrim($h, '#'); if (strlen($h) === 3) $h = $h[0].$h[0].$h[1].$h[1].$h[2].$h[2]; return [hexdec(substr($h,0,2)), hexdec(substr($h,2,2)), hexdec(substr($h,4,2))]; }; [$pr,$pg,$pb] = $hex2rgb($primary); $primaryFaint = sprintf('rgba(%d,%d,%d,0.05)', $pr,$pg,$pb); $primarySoft = sprintf('rgba(%d,%d,%d,0.08)', $pr,$pg,$pb); $primaryRule = sprintf('rgba(%d,%d,%d,0.20)', $pr,$pg,$pb); // First three KPIs become the hero "stat cards"; next seven the secondary strip; // anything beyond goes in the detail table. $heroKpis = array_slice($kpis, 0, 3); $stripKpis = array_slice($kpis, 3, 7); $tableKpis = array_slice($kpis, 10); $bullets = array_values(array_filter($kpis, fn ($k) => ! empty($k['comment'] ?? null))); $reportDate = ($analysis->finished_at ?? $analysis->created_at ?? now())->format('d M Y'); $reportRef = 'REF-'.str_pad((string) $analysis->id, 6, '0', STR_PAD_LEFT); // Analyst signature: who triggered the analysis (tenant admin user). $analyst = $analysis->trigger ?? null; // Headline ribbon: when the analysis carries KPIs, the AI is instructed // to put the highest-priority indicator first — promote that into the // "investment recommendation" box on the cover. For valuation runs we // try to surface up to three KPIs in a Low/Base/High triptych. $isValuation = in_array($analysis->analysis_type, ['valuation', 'forecast'], true); $ribbonKpis = $isValuation ? array_slice($kpis, 0, 3) : array_slice($kpis, 0, 1); // Trend → glyph + color. The AI is instructed to emit `trend` ∈ {up,down,flat,null}. // We render a green ▲ for up, red ▼ for down, slate → for flat. Direction is // a heuristic — the comment carries the interpretive nuance. $trendGlyph = function (?string $t): array { return match ($t) { 'up' => ['▲', '#16a34a'], // green-600 'down' => ['▼', '#dc2626'], // red-600 'flat' => ['→', '#64748b'], // slate-500 default => [null, null], }; }; // TOC entries — only sections that actually render. $toc = []; if ($analysis->summary) { $toc[] = __('Executive summary'); } if (! empty($heroKpis)) { $toc[] = __('Headline indicators'); } if (! empty($stripKpis)) { $toc[] = __('Indicators at a glance'); } if (! empty($bullets)) { $toc[] = __('Key takeaways'); } if (! empty($tableKpis)) { $toc[] = __('Detailed indicators'); } if (! empty($charts)) { $toc[] = __('Charts'); } if ($analysis->explanation_html){ $toc[] = __('Fundamental analysis'); } $toc[] = __('Disclaimer'); // Fallback disclaimer text — institutional research-note boilerplate. // Tenants can override via settings.branding.disclaimer_html. $disclaimer = $branding['disclaimer_html'] ?? null; @endphp {{ $submission->title ?? __('Analysis report') }} {{-- ──────── Running page header / footer (every page incl. cover) ──────── --}} {{-- ──────── COVER PAGE ──────── --}}
{{ $analysis->typeLabel() }}{{ $analysis->isCombined() ? ' · '.__('Combined report') : '' }}
{{ $submission->title ?? __('Analysis report') }}
{{ $reportDate }} · {{ strtoupper((string) ($analysis->language ?? app()->getLocale())) }} @if($submission->original_name) ·{{ $submission->original_name }} @endif ·{{ $reportRef }}
@if(! empty($ribbonKpis))
@foreach($ribbonKpis as $i => $k) @php [$g, $gc] = $trendGlyph($k['trend'] ?? null); @endphp
{{ $k['label'] ?? '' }} {{ (string) ($k['value'] ?? '') }} @if(! empty($k['unit'])){{ $k['unit'] }}@endif @if($g){{ $g }}@endif
@endforeach
@endif
{{ __('Document type') }} {{ $analysis->typeLabel() }}
{{ __('Reference') }} {{ $reportRef }}
{{ __('Issued') }} {{ $reportDate }}
@if($submission->original_name)
{{ __('Source file') }} {{ $submission->original_name }}
@endif
{{ __('Language') }} {{ strtoupper((string) ($analysis->language ?? app()->getLocale())) }}
{{ __('Prepared by') }}
{{ $analyst->name ?? $firm }}
@if($analyst && ! empty($analyst->email)) @endif
{{ $firm }} · {{ $tagline }}
{{-- ──────── TABLE OF CONTENTS ──────── --}}

{{ __('Contents') }}

    @foreach($toc as $entry)
  1. {{ $entry }}
  2. @endforeach
{{-- ──────── Hero (page after TOC) ──────── --}}
{{ $analysis->typeLabel() }}

{{ $submission->title ?? __('Analysis report') }}

@if(! empty($branding['hero_subtitle']))
{{ $branding['hero_subtitle'] }}
@elseif($analysis->summary)
{{ Str::limit(strip_tags((string) $analysis->summary), 220) }}
@endif
{{ $reportDate }} @if($submission->original_name)·{{ $submission->original_name }}@endif ·{{ $reportRef }}
@if(! empty($heroKpis))
@foreach($heroKpis as $k) @php $val = (string) ($k['value'] ?? ''); $unit = (string) ($k['unit'] ?? ''); [$g, $gc] = $trendGlyph($k['trend'] ?? null); @endphp
{{ $k['label'] ?? '' }} {{ $val }} @if($unit !== ''){{ $unit }}@endif @if($g){{ $g }}@endif
@endforeach
@endif
{{-- ──────── Secondary KPI strip ──────── --}} @if(! empty($stripKpis))
{{ __('Indicators at a glance') }}
@foreach($stripKpis as $k) @php [$g, $gc] = $trendGlyph($k['trend'] ?? null); @endphp
{{ $k['label'] ?? '' }} {{ trim(($k['value'] ?? '').' '.($k['unit'] ?? '')) }}@if($g){{ $g }}@endif
@endforeach
@endif {{-- ──────── Executive summary ──────── --}} @if($analysis->summary)
{{ __('Executive summary') }}
{{ $analysis->summary }}
@endif {{-- ──────── Key takeaways ──────── --}} @if(! empty($bullets))
{{ __('Key takeaways') }}
@foreach(array_slice($bullets, 0, 6) as $b)
{{ $b['label'] ?? '' }} — {{ $b['comment'] }}
@endforeach
@endif {{-- ──────── KPI overflow table ──────── --}} @if(! empty($tableKpis))
{{ __('Detailed indicators') }}
@foreach($tableKpis as $kpi) @php [$g, $gc] = $trendGlyph($kpi['trend'] ?? null); @endphp @endforeach
{{ __('Indicator') }} {{ __('Value') }} {{ __('Comment') }}
{{ $kpi['label'] ?? '' }} {{ trim(($kpi['value'] ?? '').' '.($kpi['unit'] ?? '')) }}@if($g){{ $g }}@endif {{ $kpi['comment'] ?? '' }}
@endif {{-- ──────── Charts ──────── --}} @if(! empty($charts))
{{ __('Charts') }}
@foreach($charts as $c)
@if(! empty($c['title']))

{{ $c['title'] }}

@endif {!! $c['html'] !!} @if(! empty($c['source_ref']))
{{ __('Source') }}: {{ $c['source_ref'] }}
@endif
@endforeach
@endif {{-- ──────── Detailed explanation ──────── --}} @if($analysis->explanation_html)
{{ __('Fundamental analysis') }}
{!! $analysis->explanation_html !!}
@endif {{-- ──────── DISCLAIMER PAGE (always last) ──────── --}}

{{ __('Disclaimer') }}

@if($disclaimer) {!! $disclaimer !!} @else

{{ __('Information purposes only') }}

{{ __('This report is produced by :firm using automated analytical tools and is provided to the recipient for information purposes only. Nothing contained in this document constitutes an offer, solicitation, or recommendation to buy or sell any security, financial product, or investment, nor does it constitute investment, legal, accounting, or tax advice.', ['firm' => $firm]) }}

{{ __('Sources & methodology') }}

{{ __('The analysis is grounded strictly in the source document supplied by the requesting party. Figures are either copied verbatim from that document or derived through arithmetic operations on figures from that document. No external comparators, peer benchmarks, or market data are used as factual claims about the subject; where industry benchmarks are referenced, they are explicitly flagged as general anchors.') }}

{{ __('Forward-looking statements') }}

{{ __('Any forward-looking statements, scenarios, or projections in this report are based on assumptions stated in the body of the document. Actual results may differ materially from those projected. Past performance is not indicative of future results. No guarantee, express or implied, is given as to the accuracy or completeness of any projection.') }}

{{ __('No fiduciary relationship') }}

{{ __(':firm has no fiduciary, advisory, or contractual relationship with any reader of this report unless explicitly agreed in writing. The recipient is solely responsible for any decision taken on the basis of the information contained herein and should consult independent professional advisors prior to acting.', ['firm' => $firm]) }}

{{ __('Confidentiality') }}

{{ __('This document is confidential and intended for the named recipient only. Reproduction, redistribution, or quotation of any part of this report without prior written consent of :firm is prohibited.', ['firm' => $firm]) }}

@endif