@extends('includes.layout') @section('content') {{-- ============================================================ Global Search results view — shown only while an active search/filter is applied. Normal Account Closure page content (below) is hidden while this is visible, and restored once the search box + filters are cleared. ============================================================ --}} {{-- ============================================================ Normal Account Closure page content (unchanged) — hidden while a search/filter is active above. ============================================================ --}}

Account Closure OTL Forms


@php // ---- Process checks (step 2: FSA user, step 3: outstanding earnings) ---- // Run once for ALL rows (3 queries total) instead of once per row. $__DB = \Illuminate\Support\Facades\DB::class; $__uids = collect($data)->pluck('userID')->filter()->unique()->values()->all(); // Users that have fraud flags $__flagged = $__DB::table('flag_comment') ->whereIn('uid', $__uids) ->whereIn('flagtype', ['FraudStrike', 'fraud_streaming']) ->distinct()->pluck('uid')->map(fn ($v) => (string) $v)->all(); // ...of those, the ones whose fraud flags are all cleared (=> fsacheck 'No') $__cleared = $__DB::table('users') ->whereIn('uid', $__flagged) ->where('possible_fraud', 0) ->where('under_investigation', 0) ->where('paypal_issue', 0) ->where('indianpaypal', 0) ->where('fraud_streaming', 0) ->where(function ($q) { $q->whereNull('bank_transfer')->orWhere('bank_transfer', 0); }) ->where('uk_vat_flag', 0) ->pluck('uid')->map(fn ($v) => (string) $v)->all(); // FSA users = flagged and not cleared (=> fsacheck 'Yes') $__fsaUsers = array_values(array_diff($__flagged, $__cleared)); // Outstanding earnings per uid $__outstanding = $__DB::table('user_account_report') ->whereIn('uid', $__uids) ->select('uid', 'outstand_amount') ->get()->groupBy('uid') ->map(fn ($rows) => (float) ($rows->first()->outstand_amount ?? 0))->all(); // Forms that have at least one Slack message (comm_slack) - one query for all rows $__slackForms = $__DB::table('comm_slack') ->whereIn('form_id', collect($data)->pluck('form_id')->filter()->unique()->values()->all()) ->pluck('form_id')->map(fn ($v) => (string) $v)->unique()->values()->all(); @endphp @foreach ($data as $item) @php $coolingOffDays = 10; $submittedDate = \Carbon\Carbon::parse($item->form_submitted_at)->startOfDay(); $expiryDate = $submittedDate->copy()->addDays($coolingOffDays); $today = now()->startOfDay(); $daysPassed = $today->diffInDays($submittedDate); $daysRemaining = max(0, $coolingOffDays - $daysPassed); // expedite_deletion = 1 (comm_account_closure): admin cancelled the cooling-off period, so processing starts now $isExpedited = (string) ($item->closure_expedite_deletion ?? $item->expedite_deletion ?? 0) === '1'; $isExpired = $isExpedited || $daysPassed >= $coolingOffDays; $isOutstanding = ($item->status == ''); // Default table order (Cooling Off column sort key): // group 0 = open, cooling-off expired -> oldest expiry first // group 1 = open, still cooling off -> soonest expiry first // group 2 = completed (approved / rejected / info requested) -> newest first $__sortGroup = $isOutstanding ? ($isExpired ? 0 : 1) : 2; $__sortKey = $__sortGroup * 10000000000 + ($__sortGroup === 2 ? (9999999999 - $submittedDate->timestamp) : ($isExpired ? min($expiryDate->timestamp, now()->timestamp) : $expiryDate->timestamp)); @endphp @php $assignedUid = $item->assigned_uid ?? ''; $isAssigned = (!empty($assignedUid) || (!empty($item->assigned_user_name) && $item->assigned_user_name != 'Luna AI')); @endphp @php $__uid = (string) ($item->userID ?? ''); $__isFsa = in_array($__uid, $__fsaUsers, true); $__fsaVal = (string) ($item->fsaverfify ?? '0'); $__hasOut = ((float) ($__outstanding[$__uid] ?? 0)) > 0; $__paypal = (string) ($item->verify_paypal ?? '') === '1'; $__outStep = ($__isFsa || $__fsaVal !== '0') ? 3 : 2; // Outstanding earnings is Step 2 when the FSA step doesn't apply $__blockedStep = null; $__blockedMsg = ''; if ($__fsaVal === '3') { // Reviewed and remaining on the fraud payment list -> process stops $__blockedStep = 2; $__blockedMsg = 'Process stopped: user remains on the fraud payment list (Step 2)'; } elseif ($isExpired && $__isFsa && $__fsaVal === '0') { // Cooling-off complete, FSA user, admin action not done yet $__blockedStep = 2; $__blockedMsg = 'Admin action needed: FSA security check (Step 2)'; } elseif ($isExpired && $__hasOut && !$__paypal) { // Cooling-off complete, outstanding earnings, admin action (verify_paypal = 1) not done yet $__blockedStep = 3; $__blockedMsg = 'Admin action needed: outstanding earnings (Step ' . $__outStep . ')'; } @endphp @php // ---- Event History data for this row ---- $__fmt = fn ($d) => $d ? \Carbon\Carbon::parse($d)->format('Y-m-d H:i:s') : '-'; $__st = (string) ($item->status ?? ''); // Cancelled = delete_status 1 on the closure table, and never for a request that already has a final decision. // Prefer the aliased column (closure_delete_status) so a joined table can't overwrite it. $__cancelled = (string) ($item->closure_delete_status ?? $item->delete_status ?? 0) === '1' && !in_array($__st, ['approve', 'reject']); $__ev = []; // 1. Request received $__ev[] = ['title' => 'Request received', 'color' => 'blue', 'when' => 'Submitted on ' . $__fmt($item->form_submitted_at), 'sub' => 'By (' . ($item->username ?? '') . ')']; // 2. Cooling-off period if ($isExpedited) { $__ev[] = ['title' => 'Cooling-off period', 'color' => 'amber', 'chip' => ['Cancelled', 'info'], 'when' => 'Expedited', 'sub' => 'Started ' . $submittedDate->format('Y-m-d') . ' · cooling-off period cancelled · process started']; } else { $__ev[] = ['title' => 'Cooling-off period', 'color' => 'amber', 'chip' => [$isExpired ? 'Expired' : 'Running', $isExpired ? 'ok' : 'wait'], 'when' => ($isExpired ? 'Expired on ' : 'Expires on ') . $expiryDate->format('Y-m-d'), 'sub' => 'Started ' . $submittedDate->format('Y-m-d') . ($isExpired ? '' : ' · ' . $daysRemaining . ' day(s) remaining')]; } if ($__cancelled) { // 3. Cancelled -> history ends here, no further steps $__ev[] = ['title' => 'Request cancelled', 'color' => 'red', 'chip' => ['Cancelled', 'stop'], 'when' => !empty($item->deleted_at) ? $__fmt($item->deleted_at) : 'Date not recorded', 'sub' => 'Request cancelled and email sent to the user. No further steps.']; $__badge = ['Cancelled', 'stop']; } else { // 3. Processing: step 2 (FSA) and step 3 (outstanding earnings) $__s2 = ['label' => 'Step 2 · Security check for FSA user']; $__s3 = ['label' => 'Step ' . $__outStep . ' · Outstanding earnings' . ($__hasOut ? ' ($' . number_format($__outstanding[$__uid], 2) . ')' : '')]; // Step 2 only applies to FSA users (or when an admin already acted on it). Otherwise it is not shown at all. $__showS2 = $__isFsa || $__fsaVal !== '0'; if (!$isExpired) { $__s2 += ['state' => 'mute', 'text' => 'Not started']; $__s3 += ['state' => 'mute', 'text' => 'Not started']; } else { if ($__fsaVal === '3') { $__s2 += ['state' => 'stop', 'text' => 'Stopped']; } elseif ($__isFsa && $__fsaVal === '0') { $__s2 += ['state' => 'wait', 'text' => 'Pending']; } else { $__s2 += ['state' => 'ok', 'text' => $__isFsa ? 'Done' : 'Not an FSA user']; } if ($__s2['state'] !== 'ok') { $__s3 += ['state' => 'mute', 'text' => 'Not started']; } elseif ($__hasOut && !$__paypal) { $__s3 += ['state' => 'wait', 'text' => 'Pending']; } else { $__s3 += ['state' => 'ok', 'text' => $__hasOut ? 'Done' : 'No outstanding earnings']; } } $__checks = $__showS2 ? [$__s2, $__s3] : [$__s3]; $__total = count($__checks); $__done = ($__showS2 && $__s2['state'] === 'ok' ? 1 : 0) + ($__s3['state'] === 'ok' ? 1 : 0); $__proc = ['title' => 'Processing', 'color' => 'grey', 'checks' => $__checks]; if (!$isExpired) { $__proc['chip'] = ['Waiting for cooling-off', 'mute']; $__proc['when'] = 'Starts after cooling-off ends'; } elseif ($__blockedStep) { $__proc['chip'] = [$__fsaVal === '3' ? 'Stopped' : $__done . ' of ' . $__total . ($__total === 1 ? ' check' : ' checks') . ' done', $__fsaVal === '3' ? 'stop' : 'wait']; $__proc['color'] = $__fsaVal === '3' ? 'red' : 'amber'; $__proc['tip'] = $__blockedMsg; } else { $__proc['chip'] = ['All checks done', 'ok']; $__proc['color'] = 'green'; } $__ev[] = $__proc; // 4. Final decision if ($__st === 'approve') { $__ev[] = ['title' => 'Final decision', 'color' => 'green', 'chip' => ['Approved', 'ok'], 'when' => !empty($item->status_submitted_at) ? $__fmt($item->status_submitted_at) : '']; $__badge = ['Approved', 'ok']; } elseif ($__st === 'reject') { $__ev[] = ['title' => 'Final decision', 'color' => 'red', 'chip' => ['Rejected', 'stop'], 'when' => !empty($item->status_submitted_at) ? $__fmt($item->status_submitted_at) : '']; $__badge = ['Rejected', 'stop']; } elseif ($__st === 'request') { $__ev[] = ['title' => 'Final decision', 'color' => 'amber', 'chip' => ['Information requested', 'wait'], 'sub' => '']; $__badge = ['Info requested', 'wait']; } else { $__ev[] = ['title' => 'Final decision', 'color' => 'grey', 'chip' => ['Waiting', 'mute'], 'when' => 'Approved or Rejected', 'sub' => '']; $__badge = ['Open', 'info']; } } foreach ($__ev as $__i => $__e) { $__ev[$__i]['n'] = $__i + 1; } $__history = [ 'id' => $item->type == '1' ? $item->id : $item->form_id, 'username' => $item->username ?? '', 'badge' => $__badge, 'events' => $__ev, ]; @endphp @if($item->type == '1') @else @endif @endforeach
# Assignee UserName Date Status Confirmation Email Cooling Off Period Smarthub Report Cancel Request View
{{ $item->id }}{{ $item->form_id }} @if(!empty($item->assigned_user_name) && $item->assigned_user_name != 'Luna AI')
{{ strtoupper(substr($item->assigned_user_name, 0, 2)) }} {{ $item->assigned_user_name }}
@else
! Unassigned
@endif
{{ $item->username }}
Submitted On: {{ $item->form_submitted_at }}
Archived On: @if(in_array($item->status, ['approve', 'reject']) && !empty($item->status_submitted_at)) {{ $item->status_submitted_at }} @else - @endif
@if($item->status == 'approve') Archived @elseif($item->status == 'reject') Archived @elseif($item->status == '') @if($__blockedStep) ! Open @else Open @endif @elseif($item->status == 'request') Archived @else {{ $item->status }} @endif @if ($item->hard_delete) @if ($isExpired) {{ $isExpedited ? 'Expedited' : 'Completed' }} Delete Account @else {{ $daysRemaining }} day(s) remaining Delete Account @endif @else @if ($isExpired) {{ $isExpedited ? 'Expedited' : 'Completed' }} Close Account @else {{ $daysRemaining }} day(s) remaining Close Account @endif @endif @if($item->status == '') @else @endif