@extends('layouts.app') @section('title', __('Compare results')) @section('page-title', __('Compare results')) @section('page-subtitle', $analysis->typeLabel()) @php use App\Services\AnalysisComparisonService; // Mode-specific labels for the tabs. $modeLabels = [ AnalysisComparisonService::MODE_PERIOD => __('Period-over-period'), AnalysisComparisonService::MODE_ANNUAL => __('Year-over-year'), AnalysisComparisonService::MODE_MULTI_YEAR => __('Multi-year trend'), AnalysisComparisonService::MODE_BUDGET => __('Budget vs Actual'), AnalysisComparisonService::MODE_SECTOR => __('Sector benchmark'), ]; $modeBlurbs = [ AnalysisComparisonService::MODE_PERIOD => __('Compare against month/quarter/semester/year-ago.'), AnalysisComparisonService::MODE_ANNUAL => __('Strict year-over-year against the closest year-ago delivery.'), AnalysisComparisonService::MODE_MULTI_YEAR => __('Trend line across multiple year-spaced analyses.'), AnalysisComparisonService::MODE_BUDGET => __('Tag one analysis as the budget, the other as the actual.'), AnalysisComparisonService::MODE_SECTOR => __('Benchmark this analysis against typical industry ranges.'), ]; $periodChips = [ 'month' => __('1 month ago'), 'quarter' => __('3 months ago'), 'semester' => __('6 months ago'), 'year' => __('1 year ago'), ]; // Numeric formatter shared with the pair table. $fmtVal = function ($v, $unit = '') { if ($v === null || $v === '' || ! is_scalar($v)) return '—'; if (is_numeric($v)) { $n = (float) $v; $abs = abs($n); $formatted = $abs >= 1000 ? number_format($n, 0, '.', ' ') : (floor($n) == $n ? number_format($n, 0) : number_format($n, 2)); return trim($formatted.' '.$unit); } return (string) $v; }; $changePhrase = function ($row) { if ($row['direction'] === 'missing') return __('Not comparable'); if ($row['direction'] === 'flat') return __('About the same'); $verb = $row['direction'] === 'improved' ? __('Better') : __('Worse'); if (isset($row['pct']) && $row['pct'] !== null) { $abs = abs((float) $row['pct']); return $verb.' '.__('by :n%', ['n' => number_format($abs, $abs >= 10 ? 0 : 1)]); } return $verb; }; $compareWithId = $right && $left ? ($right->id === $analysis->id ? $left->id : $right->id) : null; @endphp @push('head') @endpush @section('content')
{{-- ── Header strip + mode tabs ────────────────────────────────────── --}}
{{ __('Back to submission') }} {{ $analysis->typeLabel() }}
{{-- Mode tabs --}}
@foreach($modes as $m) @php $active = $mode === $m; @endphp {{ $modeLabels[$m] }} @endforeach

{{ $modeBlurbs[$mode] ?? '' }}

{{-- ── Flash banners (success / error / warnings) ───────────────────── --}} @if(session('status'))
{{ session('status') }}
@endif @if(session('error'))
{{ session('error') }}
@endif @if($mode === AnalysisComparisonService::MODE_SECTOR) @include('tenant.analyses._compare_sector', [ 'analysis' => $analysis, 'sectorPayload' => $sectorPayload ?? null, ]) @elseif($mode === AnalysisComparisonService::MODE_MULTI_YEAR) @include('tenant.analyses._compare_multiyear', [ 'analysis' => $analysis, 'candidates' => $candidates, 'diff' => $diff, 'multiYear' => $multiYear, ]) @else {{-- PERIOD / ANNUAL / BUDGET modes ─────────────────────────────── --}} @if(($noCandidate ?? false))
{{ __('No other analysis of the same type to compare against yet.') }}
{{ __('Run another analysis of this type first.') }}
@else @include('tenant.analyses._compare_pair', [ 'analysis' => $analysis, 'left' => $left, 'right' => $right, 'mode' => $mode, 'candidates' => $candidates, 'diff' => $diff, 'narrative' => $narrative, 'period' => $period, 'periods' => $periods, 'periodChips' => $periodChips, 'compareWithId' => $compareWithId, 'fmtVal' => $fmtVal, 'changePhrase' => $changePhrase, ]) @endif @endif {{-- ── Free-form Q&A panel (available in every mode) ─────────────────── --}}
{{ __('Ask a question') }}

{{ __('Have a question about these numbers?') }}

{{ __('Examples: “Why did profitability drop in Q3?” · “Explain the working capital evolution.” · “What are the major financial risks?”') }}

@csrf @if($compareWithId)@endif
{{ __('Answers are generated automatically.') }}
@if($qaAnswer ?? null)
{{ __('Your question') }}

“{{ $qaAnswer['question'] }}”


{{ __('Answer') }}
{!! $qaAnswer['answer']['html'] !!}
@if(!empty($qaAnswer['answer']['model'])) {{ __('Model') }}: {{ $qaAnswer['answer']['model'] }} @endif @if(!empty($qaAnswer['answer']['tokens'])) · {{ number_format($qaAnswer['answer']['tokens']) }} {{ __('tokens') }} @endif @if(!empty($qaAnswer['answer']['provider'])) · {{ strtoupper($qaAnswer['answer']['provider']) }} @endif
@endif
@endsection