{{-- resources/views/agent/leads/partials/purchased.blade.php --}} @php use Illuminate\Support\Facades\Route; // Safe fallback if the controller didn't pass $data $purchasedData = is_array($data ?? null) ? $data : []; // Tabs we support $types = [ 'life' => 'Life', 'mortgage' => 'Mortgage Protection', 'health' => 'Health', ]; // ── Archive normalization ──────────────────────────────────────────────── // These are safe defaults; controller can pass $fromArchive and $activeGroup $fromArchive = isset($fromArchive) ? (bool) $fromArchive : false; // Normalize any requested group label $__ag = isset($activeGroup) ? strtolower(trim((string) $activeGroup)) : null; if ($__ag === 'mortgage protection' || $__ag === 'mortgage_protection' || $__ag === 'mp') { $__ag = 'mortgage'; } $activeGroup = in_array($__ag, ['life', 'mortgage', 'health'], true) ? $__ag : 'life'; // If at least one dataset exists, start there; else default to Life. // If $activeGroup is provided and valid, force that as the initial tab. $available = array_values(array_filter(array_keys($types), fn($k) => array_key_exists($k, $purchasedData))); $firstActive = $activeGroup && isset($types[$activeGroup]) ? $activeGroup : $available[0] ?? 'life'; // Unique IDs so these don't collide with the outer tabs (closures for PHP 7.3+ compat) $paneId = function ($key) { return "purchased-{$key}"; }; $tabId = function ($key) { return "purchased-{$key}-tab"; }; // Toolbar links $purchaseUrl = Route::has('agent.leads.purchase') ? route('agent.leads.purchase') : url('/agent/leads/purchase'); // Export $exportRouteName = Route::has('agent.leads.purchased.export') ? 'agent.leads.purchased.export' : (Route::has('agent.purchased.export') ? 'agent.purchased.export' : null); $exportHref = $exportRouteName ? route($exportRouteName, ['type' => $firstActive]) : null; $exportLabel = 'Export ' . ($types[$firstActive] ?? ucfirst($firstActive)) . ' (CSV)'; $exportUrls = []; if ($exportRouteName) { foreach (array_keys($types) as $k) { $exportUrls[$k] = route($exportRouteName, ['type' => $k]); } } // Bulk Update (Save) – outer form action $bulkUpdateAction = Route::has('agent.purchased.bulkUpdate') ? route('agent.purchased.bulkUpdate') : url('/agent/leads/purchased/bulk-update'); // Row-level Convert endpoint (per-row) $rowConvertBase = function ($key, $id) { return Route::has('agent.leads.purchased.convert') ? route('agent.leads.purchased.convert', ['type' => $key, 'lead' => $id]) : url("/agent/leads/purchased/{$key}/{$id}/convert"); }; // Per-group Insurance Types (Mortgage Protection removed as selectable type itself) $insuranceTypesByGroup = [ 'life' => ['Term Life', 'Whole Life', 'Final Expense', 'Universal Life', 'Other'], 'mortgage' => ['Term Life', 'Final Expense', 'Universal Life', 'Other'], 'health' => ['Dental Insurance', 'Medicare', 'ACA', 'Supplemental', 'Other'], ]; // Generic Statuses (shared across all groups) $statusOptions = [ 'new' => 'New', 'contacted' => 'Contacted', 'follow_up' => 'Follow Up', 'interested' => 'Interested', 'not_interested' => 'Not Interested', 'converted' => 'Converted', 'archived' => 'Archived', ]; $norm = fn($v) => strtolower(preg_replace('/\s+/', '_', trim((string) $v))); // Optional: when opened from an archive, controller can pass the archive file id $archiveFileId = $archiveFileId ?? ($archive_file_id ?? null); @endphp {{-- Toolbar --}}
{{-- Lead Archive dropdown (only when viewing from an archive and we know the file id) --}} @if ($fromArchive && $archiveFileId)
@endif {{-- Generic actions for leads currently on screen --}}
@if ($fromArchive && Route::has('agent.files.archive')) Back to Lead Archives @endif Purchase Lead @if ($exportRouteName) {{ $exportLabel }} @endif
Changes saved.
{{-- Hidden ARCHIVE form (create a new archive snapshot of current tab) --}}
@csrf
{{-- Hidden delete form for leads (unchanged server contract) --}}
@csrf
{{-- JS appends --}}
{{-- Hidden delete form for the archive FILE (only rendered when we know file id) --}} @if ($fromArchive && $archiveFileId && Route::has('agent.files.archive.delete'))
@csrf @method('DELETE')
@endif {{-- silent target to keep page in place on delete --}}
@csrf
{{-- INNER TABS (always show all tabs) --}}
@foreach ($types as $key => $label) @php $rows = $purchasedData[$key]['rows'] ?? collect(); @endphp
@if ( ($rows instanceof \Illuminate\Support\Collection && $rows->isEmpty()) || ($rows instanceof \Illuminate\Pagination\AbstractPaginator && $rows->count() === 0))
No {{ strtolower($label) }} leads yet.
@else
@foreach ($rows as $idx => $lead) @php $insNorm = $norm($lead->insurance_type ?? ''); $statusNorm = $norm($lead->status ?? 'new'); $purchaseDate = $lead->purchase_date ?? null; $purchaseDateShort = $purchaseDate ? \Illuminate\Support\Str::of($purchaseDate)->substr(0, 10) : ''; $rowId = "row-{$key}-{$lead->id}"; $rowConvertUrl = $rowConvertBase($key, $lead->id); @endphp {{-- Placeholders for missing names --}} {{-- More safe placeholders to keep grid tidy --}} {{-- Lead Type cell (Purchased) --}} @endforeach
First Name Last Name Phone Email Age Date of Birth Street Address City State Zipcode County Insurance Type Lead Type Status Convert To Client Purchase Date
{{ $lead->first_name ?: '—' }} {{ $lead->last_name ?: '—' }}{{ $lead->phone_number ?: '—' }} {{ $lead->email ?: '—' }} {{ isset($lead->age) ? $lead->age : '—' }} {{ $lead->date_of_birth ?: '—' }} {{ $lead->street_address ?? $lead->address ?: '—' }} {{ $lead->city ?: '—' }} {{ $lead->state ?: '—' }} {{ $lead->zipcode ?: '—' }} {{ $lead->county ?: '—' }} @php $options = $insuranceTypesByGroup[$key] ?? []; @endphp Purchased {{ $purchaseDateShort ?: '—' }}
@endif
@endforeach