@php $tabMeta = [ 'programme' => ['label' => __('Referrals'), 'icon' => 'user-plus'], 'reviews' => ['label' => __('Reviews'), 'icon' => 'star'], 'settings' => ['label' => __('Settings'), 'icon' => 'cog-6-tooth'], ]; $money = fn (?float $amount): string => $amount === null ? __('Not available') : $currency.' '.number_format($amount, 2); $metrics = [ ['label' => __('Referred enquiries'), 'value' => number_format($summary['enquiries']), 'icon' => 'user-plus', 'accent' => '#4f46e5', 'sub' => __('From personal links')], ['label' => __('Won value'), 'value' => $money($summary['won_value']), 'icon' => 'banknotes', 'accent' => '#059669', 'sub' => __('Confirmed and paid in full')], ['label' => __('Rewards credited'), 'value' => $currency.' '.number_format($summary['rewards'], 2), 'icon' => 'gift', 'accent' => '#d97706', 'sub' => __('Customer credit, after approval')], ['label' => __('Review links offered'), 'value' => number_format($summary['reviews_offered']), 'icon' => 'star', 'accent' => '#0284c7', 'sub' => __(':count below 4 stars, no link', ['count' => number_format($summary['reviews_withheld'])])], ['label' => __('Review links opened'), 'value' => number_format($summary['reviews_clicked']), 'icon' => 'arrow-up-right', 'accent' => '#7c3aed', 'sub' => __('Times the Google link was opened')], ]; $tz = config('app.display_timezone'); @endphp
@foreach ($metrics as $m)

{{ $m['label'] }}

{{ $m['value'] }}

{{ $m['sub'] }}
@endforeach
@foreach ($tabMeta as $key => $meta) @endforeach
@if ($tab === 'programme') @if ($canIssue)

{{ __('Give a contact their link') }}

{{ __('Each contact has one personal link. People who use it are recorded as their referrals.') }}

@if ($contacts->isNotEmpty())
    @foreach ($contacts as $contact)
  • {{ $contact->name }}

    {{ $contact->customer?->name }}

    @if ($contact->referralLink) {{ $contact->referralLink->is_active ? __('Link is on') : __('Link is off') }} @else @endif
  • @endforeach
@endif
@endif

{{ __('Referrers') }}

{{ __('Who shared a link, the enquiries it brought in, the value of jobs paid in full, and the credit a director has approved') }}

@forelse ($summary['by_referrer'] as $row) @empty @endforelse
{{ __('Referrer') }} {{ __('Enquiries') }} {{ __('Won value') }} {{ __('Rewards credited') }}

{{ $row['name'] }}

@if ($row['organisation'])

{{ $row['organisation'] }}

@endif @if ($row['token'])

{{ route('crm.referral-link', $row['token']) }}

@endif
{{ number_format($row['enquiries']) }} {{ $money($row['won_value']) }} {{ $currency }} {{ number_format($row['rewards'], 2) }}

{{ __('Referred enquiries') }}

{{ __('Credit is issued only after the job is confirmed and paid in full, and only when a director approves it') }}

@forelse ($referrals as $referral) @php $value = in_array($referral->status, ['won', 'rewarded'], true) ? app(\App\Services\Crm\Referrals\ReferralProgramme::class)->jobValueBase($referral->job) : null; @endphp @empty @endforelse
{{ __('Referrer') }} {{ __('Enquiry') }} {{ __('Status') }} {{ __('Won value') }} {{ __('Reward') }} {{ __('Actions') }}
{{ $referral->referrer?->name ?? __('Unknown contact') }} @if ($referral->opportunity) {{ $referral->opportunity->title }} @else {{ $referral->customer?->name ?? __('Not available') }} @endif

{{ $referral->created_at?->timezone($tz)->format('j M Y') }}

{{ \App\Models\Crm\Referral::STATUSES[$referral->status] ?? $referral->status }} {{ in_array($referral->status, ['won', 'rewarded'], true) ? $money($value) : __('Not available') }} @if ($referral->credit) {{ $referral->credit->currency_code }} {{ number_format((float) $referral->credit->amount, 2) }} @elseif ($referral->status === 'won') {{ __('Waiting for a director') }} @else {{ __('Not available') }} @endif @if ($isDirector && in_array($referral->status, ['enquiry', 'won'], true))
@if ($referral->status === 'won') @endif
@endif
{{ $referrals->links() }}
@if ($canIssue && $links->isNotEmpty())

{{ __('Links') }}

{{ __('Turning a link off stops new enquiries. Ones already recorded stay on the list.') }}

@foreach ($links as $link) @endforeach
{{ __('Contact') }} {{ __('Link') }} {{ __('Status') }} {{ __('Actions') }}
{{ $link->contact?->name ?? __('Unknown contact') }} {{ route('crm.referral-link', $link->token) }} {{ $link->is_active ? __('On') : __('Off') }}
@endif @elseif ($tab === 'reviews')

{{ __('Google review requests') }}

{{ __('The lowest of quality, turnaround and service decides. 4 or 5 stars may see the Google link, once per job. 1 to 3 stars go to the owner and a director, and the link is not shown. Nothing is offered in return.') }}

@forelse ($reviews as $review) @empty @endforelse
{{ __('Job') }} {{ __('Client') }} {{ __('Lowest score') }} {{ __('Status') }} {{ __('Offered') }} {{ __('Opened') }}
{{ $review->job?->job_number ?? __('Not available') }} {{ $review->customer?->name ?? __('Not available') }} {{ $review->rating }} {{ \App\Models\Crm\ReviewRequest::STATUSES[$review->status] ?? $review->status }} {{ $review->offered_at?->timezone($tz)->format('j M Y') ?? __('Not available') }} {{ $review->clicked_at?->timezone($tz)->format('j M Y') ?? __('Not available') }}
{{ $reviews->links() }}
@else

{{ __('Review link and referral reward') }}

{{ __('Directors set both. The Google link is offered only after a 4 or 5 star rating, and never with a reward. The referral reward is customer credit, and it is credited only when a director approves a confirmed, paid job.') }}

{{ __('Leave this blank and no review link is offered, even for a 5 star rating.') }}

@if ($isDirector)
{{ __('Save') }} {{ __('Saving…') }}
@else

{{ __('Only a director can change these.') }}

@endif
@endif {{ __('Approve referral reward') }}

{{ __('This credits the referrer\'s organisation. It is customer credit, not cash, and it is not a reward for a review.') }}

@if ($approving)

{{ $approving->referrer?->name }}

@endif
{{ __('Cancel') }} {{ __('Credit the reward') }} {{ __('Crediting…') }}