{{-- Tab "Khách hàng & công nợ" của /statistics (nạp bằng AJAX): khách mới / quay lại, giá trị đơn trung bình, top khách (theo khoảng ngày); công nợ và liệu trình tồn (tính đến hiện tại, chỉ theo chi nhánh). Dữ liệu từ StatisticReportService. --}} @php $returningRate = $retention['buyers'] ? round($retention['returning'] / $retention['buyers'] * 100, 1) : 0; $debtOver90 = collect($debts['buckets'])->last(); $debtMax = max(1, collect($debts['buckets'])->max('amount')); $mixChart = [ 'labels' => ['Khách mua lần đầu', 'Khách quay lại'], 'values' => [(float) $retention['new_sales'], (float) $retention['returning_sales']], ]; @endphp
{{-- ===== Chỉ số chính ===== --}}
Khách mua hàng trong kỳ
{{ number_format($retention['buyers']) }}
  • Mua lần đầu{{ number_format($retention['new']) }}
  • Khách quay lại{{ number_format($retention['returning']) }}
  • Tỷ lệ quay lại{{ $returningRate }}%
Giá trị đơn trung bình
{{ number_format($retention['aov']) }}VNĐ
  • Số đơn{{ number_format($retention['orders']) }}
  • Doanh số{{ number_format($retention['sales']) }}
  • Đơn / khách{{ number_format($retention['orders_per_buyer'], 2) }}
Công nợ hiện tại
{{ number_format($debts['amount']) }}VNĐ
  • Số đơn còn nợ{{ number_format($debts['orders']) }}
  • Nợ quá 90 ngày{{ number_format($debtOver90['amount']) }}
  • Tính đến{{ date('d/m/Y') }}
Buổi liệu trình chưa làm
{{ number_format($treatments['sessions']) }}buổi
  • Liệu trình còn buổi{{ number_format($treatments['orders']) }}
  • Khách đang có liệu trình{{ number_format($treatments['customers']) }}
  • Bỏ dở > {{ $treatments['idle_days'] }} ngày{{ number_format($treatments['idle_count']) }}
{{-- ===== Khách mới / quay lại & top khách ===== --}}

Doanh số: khách mới & quay lại

@if(array_sum($mixChart['values']) > 0)
  • Mua lần đầu · {{ number_format($retention['new']) }} khách{{ number_format($retention['new_sales']) }}
  • Khách quay lại · {{ number_format($retention['returning']) }} khách{{ number_format($retention['returning_sales']) }}
  • Doanh số TB / khách quay lại{{ number_format($retention['returning'] ? $retention['returning_sales'] / $retention['returning'] : 0) }}
  • Doanh số TB / khách mới{{ number_format($retention['new'] ? $retention['new_sales'] / $retention['new'] : 0) }}
@else
Chưa có dữ liệu
@endif

Top 10 khách chi tiêu nhiều nhất

@if($retention['top']->count())
@foreach($retention['top'] as $row) @endforeach
Khách hàngĐơnDoanh sốĐã trả
@if($row->customer) {{ $row->customer->full_name }}
{{ $row->customer->account_code }}
@else KH #{{ $row->member_id }} @endif @if($row->is_returning) Quay lại @endif
{{ number_format($row->total_orders) }} {{ number_format($row->sales) }} {{ number_format($row->paid) }}
@else
Chưa có dữ liệu
@endif
{{-- ===== Công nợ ===== --}}

Công nợ theo tuổi nợ

Tính đến hôm nay, tuổi nợ tính từ ngày tạo đơn · không phụ thuộc khoảng ngày lọc
@foreach($debts['buckets'] as $i => $bucket)
{{ $bucket['label'] }} · {{ $bucket['orders'] }} đơn{{ number_format($bucket['amount']) }}
@endforeach
@if($debts['top']->count())
@foreach($debts['top'] as $order) @endforeach
Đơn hàngKhách hàngNgày tạoTổng đơnĐã trảCòn nợTuổi nợ
{{ $order->code }} @if($order->customer) {{ $order->customer->full_name }} @endif {{ $order->created_at->format('d/m/Y') }} {{ number_format($order->all_total) }} {{ number_format($order->gross_revenue) }} {{ number_format($order->the_rest) }} {{ $order->age }} ngày
@if($debts['orders'] > $debts['top']->count())

Đang hiện {{ $debts['top']->count() }}/{{ number_format($debts['orders']) }} đơn nợ nhiều nhất.

@endif @endif
{{-- ===== Liệu trình tồn ===== --}}

Buổi liệu trình chưa làm theo dịch vụ

@if($treatments['by_service']->count())
@foreach($treatments['by_service'] as $row) @endforeach
Dịch vụBuổi còn lạiSố khách
{{ $row->name }} {{ number_format($row->sessions) }} {{ number_format($row->customers) }}
@else
Không có liệu trình còn buổi
@endif

Khách bỏ dở liệu trình (> {{ $treatments['idle_days'] }} ngày)

Nên gọi chăm sóc lại
@if($treatments['idle']->count())
@foreach($treatments['idle'] as $order) @endforeach
Khách hàngĐơnBuổi cònChưa quay lại
@if($order->customer) {{ $order->customer->full_name }}
{{ $order->customer->phone }}
@endif
{{ $order->code }} {{ number_format($order->count_day) }} {{ $order->idle_days }} ngày
@if($treatments['idle_count'] > $treatments['idle']->count())

Đang hiện {{ $treatments['idle']->count() }}/{{ number_format($treatments['idle_count']) }} khách bỏ dở lâu nhất.

@endif @else
Không có khách bỏ dở liệu trình
@endif