@extends('crm.layouts.master') @section('title','Client Detail — '.$leads->fname.' '.$leads->lname) @section('page-css') @endsection @section('main-content')
@if(session('warning')) @endif {{-- Back link and accessible client navigation --}}
Back to {{ $leads->is_client ? 'Clients' : 'Leads' }} @if($leads->is_client) @endif
{{-- ══ Profile Header Card ══ --}} @php $mainCurrency = $leads->is_client ? 'USD' : ($leads->main_currency ?? 'USD'); @endphp
{{-- ── LEFT: avatar + name + meta ── --}}
{{ strtoupper(substr($leads->fname,0,1).substr($leads->lname,0,1)) }}
{{ $leads->is_client ? 'CRM Client' : 'Lead' }}

{{ $leads->fname }} {{ $leads->lname }}

@if($leads->email) {{ $leads->email }} @endif @if($leads->phone) {{ $leads->phone }} @endif @if($leads->country) {{ $leads->country }} @endif {{ $leads->is_client ? 'Client' : 'Lead' }} ID: {{ $leads->id }} @if($leads->create_date) {{ $leads->create_date }} @endif @if($leads->is_client) Last login: {{ $leads->last_portal_login_at ? $leads->last_portal_login_at->timezone(config('app.timezone'))->format('Y-m-d H:i') : 'Never' }} @php $portalOnline = $leads->last_portal_activity_at && $leads->last_portal_activity_at->gte(now()->subMinutes(5)); @endphp @php $portalStatus = $portalOnline ? 'Online' : 'Offline'; @endphp {{ $portalStatus }} @endif
{{-- ── RIGHT: icon actions + total paid ── --}}
{{-- Icon-only action buttons --}}
@if($userAccess->can_call_lead == 'Yes') @endif @if(!$leads->is_client && $canCreateLeadFtd) @endif @if($leads->is_client && in_array(Auth::user()->access_level, ['Admin','Office Manager','Desk Manager','Agent'])) @if($canCreateDeposit) @endif @if(Auth::user()->access_level === 'Admin') @endif @endif @if($userAccess->can_delete_lead == 'Yes') @endif
{{-- Current wallet cash box --}}
Cash balance
USD {{ number_format($portfolio['totalCash'], 2) }}
Current wallet cash
{{-- ══ Portal Access Panel ══ --}}
{{-- ══ Tab Navigation ══ --}}
{{-- ══ Tab Content ══ --}}

Client Details

@if(Auth::user()->access_level === 'Admin') @endif
{{ $leads->fname }} {{ $leads->lname }}
{{ $leads->email ?: 'Not provided' }}
{{ $leads->phone ?: 'Not provided' }}
{{ $leads->country ?: 'Not provided' }}
{{ $leads->address ?: 'Not provided' }}
{{ $leads->brand ?: 'Not assigned' }}
@php $detailStatuses = \App\Support\LeadStatusRegistry::forClient((bool) $leads->is_client); if ($leads->status && !in_array($leads->status, $detailStatuses, true)) array_unshift($detailStatuses, $leads->status); @endphp
@if((int) $leads->is_client === 1 && $leads->status === 'Recovery')
@endif
{{ $leads->is_client ? 'Client' : 'Lead' }}
{{ $leads->is_client ? 'USD' : ($leads->main_currency ?: 'USD') }}
{{ $leads->create_date ?: 'Unknown' }}

CRM Assignment & Account

{{ $leads->office?->name ?: 'Unassigned' }}
{{ $leads->desk?->name ?: 'Unassigned' }}
{{ $leads->id }}
@if($canAssignRecord) @else {{ $leads->user?->name ?: 'Unassigned' }} @endif
{{ $leads->listInfo?->list_name ?: 'Not assigned' }}
{{ $leads->funnel_name ?: 'Not provided' }}
{{ $leads->aff_source_id ?: 'Not provided' }}
{{ str_replace('_',' ', $leads->kyc_status ?: 'not submitted') }}
{{ $leads->portal_access ? 'Enabled' : 'Disabled' }}
USD {{ number_format($financialSummary['approved_amount_usd'], 2) }}

Approved Deposits

{{ $financialSummary['approved_conversion_complete'] ? $financialSummary['approved_count'].' approved' : 'FX conversion incomplete' }}
USD {{ number_format($portfolio['totalCash'], 2) }}

Cash Balance

{{ $portfolio['wallets']->count() }} {{ Str::plural('wallet', $portfolio['wallets']->count()) }}
USD {{ number_format($valuation['position_market_value'], 2) }}

Position Value

{{ $valuation['counts']['total'] }} open
USD {{ number_format($valuation['equity'], 2) }}

Total Equity

{{ $mainCurrency }}

Open Positions ({{ $valuation['counts']['total'] }} open)

@if($leads->is_client && in_array(Auth::user()->access_level, ['Admin','Office Manager','Desk Manager','Agent']))View Full Portfolio@endif
@if(!$valuation['is_complete'])
Some position values use delayed or fallback pricing.
@endif @if($valuation['counts']['total'] === 0)
No open positions in this portfolio.
@else
@foreach($valuation['regular_rows'] as $row) @php $pnl = (float)($row['value'] ?? 0) - (float)($row['cost'] ?? 0); @endphp @endforeach @foreach($valuation['leveraged_rows'] as $row) @endforeach @foreach($valuation['prediction_rows'] as $row) @php $pnl = (float)($row['value'] ?? 0) - (float)($row['cost'] ?? 0); @endphp @endforeach @foreach($valuation['binary_rows'] as $row) @endforeach
TypeInstrument / MarketPositionEntry / StrikeCurrentValueP&L / Status
Asset{{ $row['position']->symbol?->name ?? 'Unknown' }}{{ rtrim(rtrim(number_format($row['quantity'], 8), '0'), '.') }} units{{ number_format($row['average'], $row['position']->symbol?->decimal_places ?? 4) }}{{ number_format($row['latest'], $row['position']->symbol?->decimal_places ?? 4) }}USD {{ number_format($row['value'] ?? 0, 2) }}{{ $pnl >= 0 ? '+' : '' }}USD {{ number_format($pnl, 2) }}
Leveraged{{ $row['position']->symbol?->name ?? 'Unknown' }}{{ strtoupper($row['position']->direction) }} · {{ $row['position']->leverage }}×{{ number_format($row['position']->entry_price, $row['position']->symbol?->decimal_places ?? 4) }}{{ number_format($row['latest'], $row['position']->symbol?->decimal_places ?? 4) }} {{ $row['priceStatus'] }}USD {{ number_format($row['value'], 2) }}{{ $row['pnl'] >= 0 ? '+' : '' }}USD {{ number_format($row['pnl'], 2) }}
Prediction{{ $row['position']->question }}{{ $row['position']->outcome }} · {{ rtrim(rtrim(number_format($row['shares'], 8), '0'), '.') }} shares{{ number_format($row['average'] * 100, 2) }}¢{{ number_format($row['latest'] * 100, 2) }}¢ {{ $row['priceStatus'] }}USD {{ number_format($row['value'] ?? 0, 2) }}{{ $pnl >= 0 ? '+' : '' }}USD {{ number_format($pnl, 2) }}
Binary{{ $row['option']->symbol?->name ?? 'Unknown' }}{{ strtoupper($row['option']->direction) }} · stake USD {{ number_format($row['stake'] ?? 0, 2) }}{{ number_format($row['option']->strike_price, $row['option']->symbol?->decimal_places ?? 4) }}Open until {{ $row['option']->expires_at?->format('M j, H:i') ?? '—' }}USD {{ number_format($row['stake'] ?? 0, 2) }}Open
@endif

Financial Activity ({{ $financialEntries->count() }} records)

@if($leads->is_client)Credit: USD {{ number_format($creditBalance, 2) }}@endif @if(Auth::user()->access_level === 'Admin' && $leads->is_client)@endif
@if($financialEntries->isEmpty())
No financial activity recorded for this client.
@else
@if($canReviewDeposits)@endif @foreach($financialEntries as $entry) @if($canReviewDeposits)@endif @endforeach
ReferenceDateSourceAmountStatusCreated byActions
{{ $entry['reference'] ?: '—' }}{{ $entry['date'] ?: 'Unknown' }}{{ $entry['source'] }}{{ !empty($entry['negative']) ? '−' : '+' }}{{ $entry['currency'] }} {{ number_format($entry['amount'], 2) }}{{ $entry['status'] }}{{ $entry['created_by'] ?: 'System' }}@if($entry['source'] === 'Deposit' && strtolower($entry['status']) === 'pending' && !empty($entry['source_id']))
@csrf
@csrf
@else—@endif
No financial activity matches the selected filters.
@endif
@php($canReviewKyc = in_array(Auth::user()->access_level, ['Admin', 'Office Manager'], true))

Complete KYC for Client

{{ str_replace('_',' ', $leads->kyc_status ?: 'not submitted') }}
@csrf
JPG, PNG, or PDF. Maximum 10 MB.

Submitted Documents

{{ $kycDocuments->count() }} {{ Str::plural('document', $kycDocuments->count()) }}
@if($kycDocuments->isEmpty())
No KYC documents submitted.
@else
@foreach($kycDocuments as $document) @endforeach
DocumentFileStatusReviewerReviewedReasonActions
{{ ucwords(str_replace('_',' ', $document->document_type)) }}{{ $document->original_name }}{{ str_replace('_',' ', $document->status) }}{{ $document->reviewer?->name ?: '—' }}{{ $document->reviewed_at ?: '—' }}{{ $document->rejection_reason ?: '—' }}
View @if($canReviewKyc) @if($document->status !== 'approved')
@csrf
@endif @endif
@if($canReviewKyc && $document->status !== 'approved')
@csrf
@endif
@endif

Support tickets

@if($tickets->isEmpty())
No support tickets opened by this client.
@else
@foreach($tickets as $ticket)@endforeach
SubjectDepartmentPriorityStatusAssigned toCreated
{{ $ticket->subject }}{{ $ticket->department ?: '—' }}{{ ucfirst($ticket->priority) }}{{ $ticket->status }}{{ $ticket->assignee?->name ?: 'Unassigned' }}{{ $ticket->created_at }}
@endif
The CRM currently stores WhatsApp activity events, not complete message bodies.

WhatsApp activity

@if($whatsappHistory->isEmpty())
No WhatsApp activity recorded for this client.
@else
@foreach($whatsappHistory as $entry)@endforeach
DateActivityUser
{{ $entry->created_at ?: 'Unknown' }}{{ $entry->description }}{{ $entry->user?->name ?: 'System' }}
@endif
@if($leads->is_client)

Client Chat

Open the tab to load messages
Messages will load when this tab opens.
@endif

Activity log

@if($history->isEmpty())
No activity has been recorded for this client.
@else
@foreach($history as $entry)@endforeach
DateEventUser
{{ $entry->created_at ?: 'Unknown' }}{{ $entry->description }}{{ $entry->user?->name ?: 'System' }}
@endif
Recorded calls will load when this tab opens.
Email history will load when this tab opens.

Client notes

@if($userAccess->can_add_lead_notes === 'Yes')@endif
@if($notes->isEmpty())
No notes have been added for this client.
@else
@if($userAccess->can_delete_lead_notes === 'Yes')@endif@foreach($notes as $note)@if($userAccess->can_delete_lead_notes === 'Yes')@endif@endforeach
Date and timeNoteAuthorAction
{{ $note->created_at?->format('Y-m-d H:i') ?: ($note->create_date ?: 'Unknown') }}{{ $note->message }}{{ $note->user?->name ?: 'System' }}
@endif
{{-- /tab-content --}}
{{-- /ld-wrap --}} {{-- ═══ MODALS ═══ --}} {{-- Add Note Modal --}} @if($userAccess->can_add_lead_notes === 'Yes') @endif @if($canResetClientPassword) @endif @if(Auth::user()->access_level === 'Admin') @endif @if(!$leads->is_client) @endif @if($canCreateDeposit) @endif @if($leads->is_client) @endif @endsection @section('page-js') @endsection