{{-- Tab "Doanh thu" của /statistics (nạp bằng AJAX khi bấm tab / lọc): so sánh chi nhánh, top dịch vụ theo doanh thu, giờ & thứ cao điểm. Dữ liệu từ StatisticReportService, cùng bộ lọc ngày / chi nhánh / cụm khu vực. --}} @php $branchTotalIncome = max(1, $branches->sum('income')); $serviceMax = max(1, (float) $topServices->max('revenue')); $branchChart = [ 'labels' => $branches->pluck('name')->values(), 'sales' => $branches->pluck('sales')->values(), 'income' => $branches->pluck('income')->values(), ]; // Ô đông nhất để gợi ý xếp ca $peak = null; foreach ($heatmap['cells'] as $d => $hours) { foreach ($hours as $h => $cell) { if (!$peak || $cell['orders'] > $peak['orders']) { $peak = ['day' => $heatmap['days'][$d], 'hour' => $h] + $cell; } } } @endphp
{{-- ===== So sánh chi nhánh ===== --}}

Doanh thu theo chi nhánh

Thực thu = tiền mặt + thẻ + CK + trả góp − hoàn tiền + nạp ví
@if($branches->count() > 1)
@endif
@foreach($branches as $branch) @php($share = $branch->income / $branchTotalIncome * 100) @endforeach @if($branches->count() > 1) @endif
Chi nhánh Khách mới Số đơn Doanh số Thực thu
{{ $branch->name }} {{ number_format($branch->customers) }} {{ number_format($branch->orders) }} {{ number_format($branch->sales) }} {{ number_format($branch->income) }}
Tổng {{ number_format($branches->sum('customers')) }} {{ number_format($branches->sum('orders')) }} {{ number_format($branches->sum('sales')) }} {{ number_format($branches->sum('income')) }}
{{-- ===== Top dịch vụ theo doanh thu ===== --}}

Top 10 dịch vụ / sản phẩm theo doanh thu

Theo giá trị dòng đơn tạo trong kỳ
@if($topServices->count())
@foreach($topServices as $i => $service) @endforeach
# Dịch vụ / sản phẩm Loại Số lượng Số đơn
{{ $i + 1 }} {{ $service->name }} {{ $service->type_text }} {{ number_format($service->quantity) }} {{ number_format($service->orders) }}
@else
Chưa có dữ liệu
@endif
{{-- ===== Giờ & thứ cao điểm ===== --}}

Giờ & thứ cao điểm (theo giờ tạo đơn)

@if($peak) Đông nhất: {{ $peak['day'] }}, {{ $peak['hour'] }}h–{{ $peak['hour'] + 1 }}h ({{ number_format($peak['orders']) }} đơn) @endif
@if($heatmap['max'] > 0)
@foreach($heatmap['hours'] as $hour) @endforeach @foreach($heatmap['days'] as $d => $dayName) @foreach($heatmap['hours'] as $hour) @php($cell = $heatmap['cells'][$d][$hour] ?? null) @php($level = $cell ? max(0.12, $cell['orders'] / $heatmap['max']) : 0) @endforeach @endforeach
{{ $hour }}h
{{ $dayName }} {{ $cell ? $cell['orders'] : '' }}
Ít đơnNhiều đơn
@else
Chưa có dữ liệu
@endif