@extends('backend.layouts.app') @section('content') @php $buyerLat = $userInquiry->latitude ?? 0; $buyerLng = $userInquiry->longitude ?? 0; $categoryName = $userInquiry->category->name ?? 'N/A'; $isMatched = $userInquiry->seller_id ? true : false; $assignedShop = $userInquiry->seller_id ? \App\Models\Shop::where('user_id',$userInquiry->seller_id)->first() : null; @endphp {{-- Enquiry Info Card --}}
Buyer
{{ $userInquiry->buyer_name ?? 'Guest' }}
{{ $userInquiry->buyer_phone }}
Category
{{ $categoryName }}
@if($userInquiry->product_name)
{{ Str::limit($userInquiry->product_name,30) }}
@endif
Location
{{ $userInquiry->city ?? 'N/A' }}
{{ $userInquiry->district }}, {{ $userInquiry->state }}
@if($buyerLat && $buyerLng)
📍 {{ $buyerLat }}, {{ $buyerLng }}
@endif
Enquiry Status
@if($isMatched) ✅ Assigned: {{ $assignedShop->name ?? 'Unknown' }} @else ⚠️ Unmatched — needs assignment @endif
{{ $userInquiry->created_at->format('d M Y h:i A') }}
{{-- Sellers List --}}
Nearby Sellers for "{{ $categoryName }}" {{ $sellerList->total() }} found
Sorted by distance from buyer location
@if($sellerList->count() > 0) @php $rank = 1; @endphp @foreach($sellerList as $seller) @php $shop = $seller->shop ?? null; $plan = $shop ? $shop->seller_package : null; $shopPhone = preg_replace('/\D/','',$seller->phone ?? ''); $dist = isset($seller->distance) ? round($seller->distance, 1) : null; $radius = $plan->radius_range ?? 0; $leadsLimit = $plan->leads_limit ?? 0; $planExpiry = $shop->package_invalid_at ?? null; $isExpired = $planExpiry && \Carbon\Carbon::parse($planExpiry)->isPast(); $isWithin = $dist !== null && $radius > 0 && $dist <= $radius; $isAssigned = $userInquiry->seller_id == $seller->id; // Today leads count $todayLeads = \App\Models\CustomerInquiry::where('seller_id',$seller->id) ->whereDate('created_at', today())->count(); // Plan badge if(!$plan) { $planClass = 'pb-noplan'; $planText = '⚠️ No Plan'; } elseif($isExpired) { $planClass = 'pb-expired'; $planText = '❌ Expired'; } else { $planClass = 'pb-premium'; $planText = '✅ '.$plan->name; } @endphp
{{-- Rank + Checkbox --}}
#{{ $rank }}
{{-- Shop Logo --}} @if($shop && $shop->logo) @endif {{-- Main Info --}}
{{ $shop->name ?? $seller->name }} @if($isAssigned) ✅ Currently Assigned @endif {{ $planText }}
{{-- Key metrics row --}}
{{-- Distance --}}
Distance
@if($dist !== null) 📍 {{ $dist }} km @else N/A @endif
{{-- Radius --}}
Plan Radius
@if($radius == 0) ⚠️ 0 km (no limit set) @else {{ $radius }} km @if($dist !== null) {{ $isWithin ? '✅ within range' : '❌ out of range' }} @endif @endif
{{-- Leads --}}
Leads (today/limit)
{{ $todayLeads }} / {{ $leadsLimit == 0 ? '∞' : $leadsLimit }} @if($leadsLimit > 0 && $todayLeads >= $leadsLimit) ⚠️ limit reached @endif
{{-- Plan expiry --}} @if($planExpiry)
Plan Valid Till
{{ \Carbon\Carbon::parse($planExpiry)->format('d M Y') }} {{ $isExpired ? '❌ Expired' : '✅' }}
@endif {{-- Location --}}
Seller Location
{{ $seller->city ?? '' }} {{ $seller->state ? ', '.$seller->state : '' }}
{{-- Warnings --}} @if($radius == 0)
⚠️ Radius = 0 km — automatic leads వెళ్ళవు. Admin manually assign చేయాలి లేదా plan update చేయాలి.
@elseif(!$isWithin && $dist !== null)
⚠️ Buyer {{ $dist }} km దూరంలో ఉన్నారు, seller radius {{ $radius }} km మాత్రమే — range బయట ఉంది.
@endif @if($isExpired)
❌ Plan expired — automatic leads వెళ్ళవు.
@endif {{-- Actions --}}
@if(!$isAssigned) @endif @if($seller->phone) 📞 Call 💬 WhatsApp @endif
@php $rank++; @endphp @endforeach
{{ $sellerList->links() }}
@else
🔍
No sellers found for "{{ $categoryName }}"

ఈ category లో sellers లేరు లేదా location data లేదు.

@endif
{{-- Toast --}} @endsection @section('script') @endsection