@extends('seller.layouts.app')
@section('panel_content')
@php
$total = $inquiries->count();
$newCount = $inquiries->where('IsRead',0)->count();
$quotedCount= $inquiries->whereNotNull('quoted_amount')->count();
$interested = $inquiries->where('lead_status','interested')->count();
$called = $inquiries->where('lead_status','called')->count();
$completed = $inquiries->where('lead_status','completed')->count();
$closed = $inquiries->where('is_closed',1)->count();
$convRate = $total > 0 ? round(($completed/$total)*100) : 0;
@endphp
{{-- Stats --}}
{{ $quotedCount }}
Quoted
{{ $interested }}
Interested
{{-- Header --}}
{{-- Filter Tabs --}}
@if($inquiries->count() > 0)
@php $sellerLat = Auth::user()->latitude ?? 0; $sellerLng = Auth::user()->longitude ?? 0; @endphp
@foreach($inquiries->sortByDesc('created_at') as $key => $inq)
@php
$isNew = $inq->IsRead == 0;
$isClosed = $inq->is_closed ?? false;
$status = $inq->lead_status ?? 'new';
$dist = null;
if($inq->latitude && $inq->longitude && $sellerLat && $sellerLng) {
$dLat = deg2rad($inq->latitude - $sellerLat);
$dLon = deg2rad($inq->longitude - $sellerLng);
$a = sin($dLat/2)*sin($dLat/2) + cos(deg2rad($sellerLat))*cos(deg2rad($inq->latitude))*sin($dLon/2)*sin($dLon/2);
$dist = round(6371 * 2 * atan2(sqrt($a), sqrt(1-$a)), 1);
}
$phone = $inq->buyer_phone ?? '';
$cleanPhone = preg_replace('/\D/','',$phone);
$mapsUrl = ($inq->latitude && $inq->longitude)
? 'https://www.google.com/maps/dir/?api=1&destination='.$inq->latitude.','.$inq->longitude
: null;
$hasQuote = !empty($inq->quoted_amount);
$quoteAccepted = ($inq->quote_status ?? '') == 'accepted';
$note = \DB::table('inquiry_notes')->where('inquiry_id',$inq->id)->where('seller_id',Auth::id())->value('note') ?? '';
// Lead score
$score = 10;
if($status=='interested') $score=60;
elseif($status=='quoted') $score=45;
elseif($status=='called') $score=25;
if($hasQuote) $score+=20;
$score = min(100,$score);
$scoreColor = $score>=70 ? '#27ae60' : ($score>=40 ? '#d97706' : '#6c757d');
// Nearby sellers
$nearbySellers = collect();
if($inq->category_id) {
$cid = $inq->category_id;
$buyLat = $inq->latitude ?? 0; $buyLng = $inq->longitude ?? 0;
$nearbySellers = \App\Models\Shop::with('user')
->where('user_id','!=',Auth::id())
->where(function($q) use ($cid){
$q->where('sub_cat_ids',$cid)
->orWhere('sub_cat_ids','LIKE',$cid.',%')
->orWhere('sub_cat_ids','LIKE','%,'.$cid)
->orWhere('sub_cat_ids','LIKE','%,'.$cid.',%');
})
->limit(8)->get()
->map(function($s) use ($buyLat,$buyLng){
$d = ($buyLat&&$buyLng&&$s->user&&$s->user->latitude) ? round((float)getDistance($s->user->latitude,$s->user->longitude,$buyLat,$buyLng),1) : null;
$s->cd = $d; return $s;
})->sortBy(fn($s)=>$s->cd??99999)->take(3);
}
@endphp
{{-- Header --}}
{{-- Quote Section --}}
@if($hasQuote)
π° Quote Sent
@if($inq->quote_note){{ Str::limit($inq->quote_note,30) }}@endif
βΉ{{ number_format($inq->quoted_amount) }}
@if($quoteAccepted)
β
Quote Accepted!
@else
β³ Awaiting
@endif
@endif
{{-- Closed Banner --}}
@if($isClosed)
π
Requirement Completed!
This enquiry has been closed by the customer
@endif
{{-- Actions --}}
@if(!$isClosed)
{{-- Status --}}
@else
π Enquiry Closed
@endif
@endforeach
@else
π
No inquiries yet
When customers send enquiries, they will appear here.
@endif
{{-- Quote Modal --}}
π° Send Quotation
{{-- Note Modal --}}
π Private Note
Only visible to you
{{-- Templates Modal --}}
β‘ Quick Reply Templates
{{-- Toast --}}
@endsection
@section('script')
@endsection