{{-- resources/views/agent/files/archive.blade.php --}} @extends('layouts.contentLayoutMaster') @section('title', 'Lead Archives') @php use Illuminate\Support\Facades\Route as Routes; use Illuminate\Support\Str; // ── Defensive defaults ───────────────────────────────────────────────────── $leads = $leads ?? collect(); $f_leadType = $f_leadType ?? strtolower((string) request('lead_type', '')); // assigned|personal|purchased|social $f_group = $f_group ?? strtolower((string) request('group', '')); // life|mortgage|health $f_state = strtoupper((string) request('state', '')); // 2-letter state code $f_archived_from = $f_archived_from ?? (string) request('archived_from', ''); // Y-m-d $f_archived_to = $f_archived_to ?? (string) request('archived_to', ''); // Y-m-d $rowsPer = isset($rowsPer) ? (int) $rowsPer : max(25, min((int) request('per', 100), 1000)); // Derived helpers $hasFilters = (bool) ($f_leadType || $f_group || $f_state || $f_archived_from || $f_archived_to); $backUrl = Routes::has('agent.files') ? route('agent.files') : url()->previous(); $routeArchiveIndex = Routes::has('agent.files.archive') ? route('agent.files.archive') : url()->current(); // POST target for "View Selected": prefer named route; fallback to URL. $viewSelectedRoute = Routes::has('agent.leads.archived.view-selected') ? route('agent.leads.archived.view-selected') : url('/agent/leads/archived/view-selected'); // 50 U.S. states $states = [ 'AL'=>'Alabama','AK'=>'Alaska','AZ'=>'Arizona','AR'=>'Arkansas','CA'=>'California','CO'=>'Colorado', 'CT'=>'Connecticut','DE'=>'Delaware','FL'=>'Florida','GA'=>'Georgia','HI'=>'Hawaii','ID'=>'Idaho', 'IL'=>'Illinois','IN'=>'Indiana','IA'=>'Iowa','KS'=>'Kansas','KY'=>'Kentucky','LA'=>'Louisiana', 'ME'=>'Maine','MD'=>'Maryland','MA'=>'Massachusetts','MI'=>'Michigan','MN'=>'Minnesota','MS'=>'Mississippi', 'MO'=>'Missouri','MT'=>'Montana','NE'=>'Nebraska','NV'=>'Nevada','NH'=>'New Hampshire','NJ'=>'New Jersey', 'NM'=>'New Mexico','NY'=>'New York','NC'=>'North Carolina','ND'=>'North Dakota','OH'=>'Ohio','OK'=>'Oklahoma', 'OR'=>'Oregon','PA'=>'Pennsylvania','RI'=>'Rhode Island','SC'=>'South Carolina','SD'=>'South Dakota', 'TN'=>'Tennessee','TX'=>'Texas','UT'=>'Utah','VT'=>'Vermont','VA'=>'Virginia','WA'=>'Washington', 'WV'=>'West Virginia','WI'=>'Wisconsin','WY'=>'Wyoming', ]; @endphp @section('content')
{{-- Header row: title, rows preview, actions, back --}}

Lead Archives

{{-- Rows preview (used when forwarding to edit page) --}}
Rows
{{-- Actions dropdown --}} {{-- Hidden POST form for "View Selected" (opens in new tab to keep this page) --}} Back to Files
{{-- FILTERS --}}
{{-- State filter (to the right of Group) --}}
Clear
{{-- Empty-state / Results --}} @if (!$hasFilters)
Use the filters above and click Apply Filters to see archived leads.
@else
{{-- State column --}} {{-- REPLACED: Group -> Status --}} @forelse(($leads ?? collect()) as $lead) @php $lt = strtolower((string) ($lead->lead_type ?? 'purchased')); // Keep group internally (used for tabs/filters) but not displayed in the table now $grp = strtolower((string) ($lead->group ?? '')); if (in_array($grp, ['mortgage protection', 'mortgage_protection', 'mp'], true)) { $grp = 'mortgage'; } $archDt = $lead->archived_at ?? ($lead->archive_date ?? null); $archYmd = $archDt ? \Illuminate\Support\Carbon::parse($archDt)->format('Y-m-d') : null; $first = $lead->first_name ?? ($lead->fname ?? '—'); $last = $lead->last_name ?? ($lead->lname ?? '—'); $phone = $lead->phone_number ?? ($lead->phone ?? '—'); $email = $lead->email ?? '—'; $dob = $lead->date_of_birth ?? ($lead->dob ?? null); // Try common state fields; uppercase if present $state = strtoupper((string) ( $lead->state ?? $lead->st ?? $lead->state_code ?? $lead->province ?? '' )); // Status for display only (NOT used for retrieval/keys) $status = strtolower((string) ( $lead->status ?? $lead->lead_status ?? $lead->status_text ?? 'archived' )); // Build value for checkbox: prefer "table:id", else plain id $srcTable = $lead->src_table ?? ''; $ckValue = $srcTable ? ($srcTable . ':' . $lead->id) : $lead->id; @endphp {{-- include data-table (src_table) so delete is table-aware --}} {{-- State cell --}} {{-- NEW: Status cell (display-only) --}} @empty {{-- colspan: checkbox + 9 columns = 10 --}} @endforelse
First Name Last Name Phone Number Email Date of BirthState Lead TypeStatus Archived Date
{{-- Checkbox posts ids/keys only (status is NOT used as a key) --}} {{ $first ?: '—' }} {{ $last ?: '—' }} {{ $phone ?: '—' }} {{ $email ?: '—' }} @if ($dob) {{ \Illuminate\Support\Carbon::parse($dob)->format('Y-m-d') }} @else — @endif {{ $state ?: '—' }} {{ $lt ?: '—' }}{{ $status ?: '—' }} {{ $archDt ? \Illuminate\Support\Carbon::parse($archDt)->format('Y-m-d H:i') : '—' }}
No archived leads matched your filters.
@endif {{-- Hidden form to DELETE selected (posts back to archive route with do=delete) --}}
@csrf
{{-- CSRF token for JS if you need it in future --}} @endsection