{{ $a->typeLabel() }}
@extends('layouts.app')
@section('title', __('My results'))
@section('page-title', __('My results'))
@section('page-subtitle', __('Read-only view of analyses delivered to you. Filter and export.'))
@section('content')
@php
use App\Models\FileSubmission;
$total = method_exists($analyses, 'total') ? $analyses->total() : $analyses->count();
$perPage = method_exists($analyses, 'perPage') ? $analyses->perPage() : 15;
$current = method_exists($analyses, 'currentPage') ? $analyses->currentPage() : 1;
$rangeFrom = $total ? (($current - 1) * $perPage) + 1 : 0;
$rangeTo = min($current * $perPage, $total);
$latestDate = optional($analyses->first())->finished_at;
$newOnPage = $analyses->filter(fn ($a) => optional($a->submission)->status === FileSubmission::STATUS_SENT)->count();
$f = $filters ?? [];
$activeType = $f['type'] ?? '';
$activeFrom = $f['from'] ?? '';
$activeTo = $f['to'] ?? '';
$activeQ = $f['q'] ?? '';
$hasFilter = $activeType || $activeFrom || $activeTo || $activeQ;
// URL helper — preserves all current filters and overrides/removes only what's passed.
$qs = function (array $overrides = []) use ($f) {
$merged = array_merge($f, $overrides);
$merged = array_filter($merged, fn ($v) => $v !== null && $v !== '');
return $merged ? '?'.http_build_query($merged) : '';
};
$today = now()->toDateString();
$sevenAgo = now()->subDays(7)->toDateString();
$thirtyAgo = now()->subDays(30)->toDateString();
$monthStart = now()->startOfMonth()->toDateString();
$isLast7 = $activeFrom === $sevenAgo && (! $activeTo || $activeTo === $today);
$isLast30 = $activeFrom === $thirtyAgo && (! $activeTo || $activeTo === $today);
$isThisMo = $activeFrom === $monthStart && (! $activeTo || $activeTo === $today);
$isAllTime = ! $activeFrom && ! $activeTo;
$periodLabel = $isLast7 ? __('Last 7 days')
: ($isLast30 ? __('Last 30 days')
: ($isThisMo ? __('This month')
: ($activeFrom || $activeTo
? trim(($activeFrom ? \Illuminate\Support\Carbon::parse($activeFrom)->isoFormat('ll') : '…').' → '.($activeTo ? \Illuminate\Support\Carbon::parse($activeTo)->isoFormat('ll') : '…'))
: __('All time'))));
$typeIcons = [
'cashflow' => 'trending-up',
'cash_flow_analysis' => 'trending-up',
'bank_evolution' => 'trending-up',
'balance_sheet_review' => 'chart',
'income_statement_review' => 'receipt',
'profitability_ratios' => 'sparkles',
'liquidity_ratios' => 'droplet',
'solvency_ratios' => 'shield',
'efficiency_ratios' => 'refresh',
'variance_analysis' => 'chart',
'trend_analysis' => 'trending-up',
'common_size' => 'chart',
'dupont_analysis' => 'sparkles',
'altman_z_score' => 'alert',
'beneish_m_score' => 'alert',
'piotroski_f_score' => 'check',
'working_capital' => 'refresh',
];
$iconFor = fn ($k) => $typeIcons[$k] ?? 'chart';
// Smart date: relative for ≤7d, short absolute beyond.
$smartDate = fn ($dt) => ! $dt ? '—' : ($dt->gt(now()->subDays(7)) ? $dt->diffForHumans() : $dt->isoFormat('ll'));
// Group cards by month for visual rhythm — reads more like a timeline.
$grouped = $analyses->getCollection()->groupBy(fn ($a) => optional($a->finished_at)->isoFormat('MMMM YYYY') ?: __('Undated'));
// Restrict the type chips to types that this user actually has, and cap
// visible chips to the first 5 — the rest live behind a "More" popover.
$availableTypes = $availableTypes ?? [];
$typeChips = collect($availableTypes)->keys()->take(5)->all();
$typeOverflow = collect($availableTypes)->keys()->slice(5)->all();
@endphp
{{-- ╭──────────────────────────────────────────────────────────────────╮
│ HERO ── lightweight banner with live counters │
╰──────────────────────────────────────────────────────────────────╯ --}}
@if($latestDate)
{{ __('Latest delivery :when', ['when' => $latestDate->diffForHumans()]) }}
@else
{{ __('Once analyses are sent they will appear here.') }}
@endif
{{ __(':count analyses available', ['count' => $total]) }}
{{ $hasFilter ? __('Try widening the date range or clearing the search.') : __('Once your analyses are sent they will appear here. You can then open them and export reports.') }}
@if($hasFilter)