@extends('layouts.app') @section('title', 'Dashboard') @section('content')
Server DateTime
{{ now()->format('Y-m-d H:i:s') }}
{{ config('app.timezone') }}
Total Orders
{{ number_format($periodStats['combined_orders']) }}
@if(isset($periodStats['historical_orders']) && $periodStats['historical_orders'] > 0)
Includes {{ number_format($periodStats['historical_orders']) }} historical orders
@endif
{{ $periodStats['completed_orders'] + $periodStats['completed_cod_orders'] }} completed • {{ $periodStats['processing_orders'] }} processing
Total Revenue
@php $primaryCurrency = $periodStats['primary_currency'] ?? 'MYR'; $currencySymbol = match(strtoupper($primaryCurrency)) { 'MYR' => 'RM', 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'JPY' => '¥', 'CNY' => '¥', 'SGD' => 'S$', 'THB' => '฿', 'IDR' => 'Rp', 'PHP' => '₱', 'VND' => '₫', 'KRW' => '₩', 'INR' => '₹', 'AUD' => 'A$', 'CAD' => 'C$', 'HKD' => 'HK$', 'NZD' => 'NZ$', default => $primaryCurrency . ' ', }; // Use combined revenue (completed + processing) $displayRevenue = $periodStats['combined_revenue'] ?? 0; // Determine font size based on number length $revenueLength = strlen(number_format($displayRevenue, 2, '.', ',')); $fontClass = match(true) { $revenueLength <= 10 => 'text-2xl', // RM999.99 $revenueLength <= 14 => 'text-xl', // RM99,999.99 $revenueLength <= 17 => 'text-lg', // RM9,999,999.99 default => 'text-base' // RM10,000,000.00+ }; @endphp
{{ $currencySymbol }}{{ number_format($displayRevenue, 2) }}
@if(isset($periodStats['historical_revenue']) && $periodStats['historical_revenue'] > 0)
Includes {{ $currencySymbol }}{{ number_format($periodStats['historical_revenue'], 2) }} historical data
@endif
All active orders (excl. cancelled)
Avg Order Value
@php $primaryCurrency = $periodStats['primary_currency'] ?? 'MYR'; $currencySymbol = match(strtoupper($primaryCurrency)) { 'MYR' => 'RM', 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'JPY' => '¥', 'CNY' => '¥', 'SGD' => 'S$', 'THB' => '฿', 'IDR' => 'Rp', 'PHP' => '₱', 'VND' => '₫', 'KRW' => '₩', 'INR' => '₹', 'AUD' => 'A$', 'CAD' => 'C$', 'HKD' => 'HK$', 'NZD' => 'NZ$', default => $primaryCurrency . ' ', }; // Use combined average order value (completed + processing) $avgOrderValue = $periodStats['average_order_value'] ?? 0; @endphp {{ $currencySymbol }}{{ number_format($avgOrderValue, 2) }}
Per order average

Confirmed Revenue

Completed
@php $primaryCurrency = $periodStats['primary_currency'] ?? 'MYR'; $currencySymbol = match(strtoupper($primaryCurrency)) { 'MYR' => 'RM', 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'JPY' => '¥', 'CNY' => '¥', 'SGD' => 'S$', 'THB' => '฿', 'IDR' => 'Rp', 'PHP' => '₱', 'VND' => '₫', 'KRW' => '₩', 'INR' => '₹', 'AUD' => 'A$', 'CAD' => 'C$', 'HKD' => 'HK$', 'NZD' => 'NZ$', default => $primaryCurrency . ' ', }; @endphp {{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['completed'] ?? 0, 0) }}
Processing
{{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['processing'] ?? 0, 0) }}
Pending
{{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['pending'] ?? 0, 0) }}
On Hold
{{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['on_hold'] ?? 0, 0) }}

COD Revenue

Completed COD
{{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['completed_cod'] ?? 0, 0) }}
Processing COD
{{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['processing_cod'] ?? 0, 0) }}
Pending COD
{{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['pending_cod'] ?? 0, 0) }}
On Hold COD
{{ $currencySymbol }}{{ number_format($periodStats['revenue_breakdown_legacy']['on_hold_cod'] ?? 0, 0) }}

Orders by Status

Completed
{{ number_format($periodStats['completed_orders']) }}
Processing
{{ number_format($periodStats['processing_orders']) }}
Pending
{{ number_format($periodStats['pending_orders']) }}
Cancelled
{{ number_format($periodStats['cancelled_orders']) }}

Time Period

{{ $periodStats['period_label'] }}: {{ $periodStats['start_date'] }}@if($periodStats['start_date'] != $periodStats['end_date']) - {{ $periodStats['end_date'] }}@endif
@if(count($periodStats['daily_breakdown']) > 1)

Revenue Trend @if(isset($periodStats['chart_title']))({{ $periodStats['chart_title'] }})@endif

@php $maxRevenue = max(array_column($periodStats['daily_breakdown'], 'revenue')); $barCount = count($periodStats['daily_breakdown']); $barWidth = $barCount > 20 ? 'w-2' : ($barCount > 10 ? 'w-3' : 'w-4'); $primaryCurrency = $periodStats['primary_currency'] ?? 'MYR'; $currencySymbol = match(strtoupper($primaryCurrency)) { 'MYR' => 'RM', 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'JPY' => '¥', 'CNY' => '¥', 'SGD' => 'S$', 'THB' => '฿', 'IDR' => 'Rp', 'PHP' => '₱', 'VND' => '₫', 'KRW' => '₩', 'INR' => '₹', 'AUD' => 'A$', 'CAD' => 'C$', 'HKD' => 'HK$', 'NZD' => 'NZ$', default => $primaryCurrency . ' ', }; @endphp @foreach($periodStats['daily_breakdown'] as $day) @php $tooltipText = $day['full_date'] . ': ' . $currencySymbol . number_format($day['revenue'], 2) . ' (' . $day['orders'] . ' orders)'; @endphp
@endforeach
Tap bars for date details
Total: @php $totalRevenue = array_sum(array_column($periodStats['daily_breakdown'], 'revenue')); @endphp {{ $currencySymbol }}{{ number_format($totalRevenue, 2) }}
@endif

Advanced Analytics

@if($analyticsSource && $analyticsSource !== 'all')

@if(strpos($analyticsSource, 'store_') === 0) @php $store = \App\Models\Store::find(str_replace('store_', '', $analyticsSource)); @endphp 📍 Showing data for: {{ $store->name ?? 'Unknown Store' }} @elseif(strpos($analyticsSource, 'webhook_') === 0) @php $webhook = \App\Models\WebhookSource::find(str_replace('webhook_', '', $analyticsSource)); @endphp 📍 Showing data for: {{ $webhook->name ?? 'Unknown Webhook' }} @endif

@endif
@if(auth()->user()->isAdmin())
@if($period === 'custom') @endif
@endif Export XLSX
@php $showTikTok = false; if (auth()->user()->isAdmin()) { // Admin sees all TikTok data $showTikTok = isset($periodStats['tiktok_orders']); } elseif (auth()->user()->isManager() && auth()->user()->can_manage_tiktok_shop) { // Manager only sees TikTok if they have permission $showTikTok = isset($periodStats['tiktok_orders']); } @endphp @if($showTikTok)

📱 TikTok Shop

View →
@if($periodStats['tiktok_orders'] > 0)
{{ number_format($periodStats['tiktok_orders']) }}
orders settled
Bank Transfer: {{ $currencySymbol }}{{ number_format($periodStats['tiktok_revenue'], 2) }}
After refunds & TikTok fees
Settlement period: {{ $periodStats['start_date'] }} - {{ $periodStats['end_date'] }}
@else

No TikTok settlements in this period

@endif
@endif

📦 Estimated Shipping Costs

@if($shippingCosts['total_orders'] > 0)
RM {{ number_format($shippingCosts['total_cost'], 2) }}
{{ $shippingCosts['total_orders'] }} orders shipped
Avg per Order: RM {{ number_format($shippingCosts['avg_per_order'], 2) }}
@if(isset($periodStats['combined_revenue']) && $periodStats['combined_revenue'] > 0)
% of Revenue: {{ number_format(($shippingCosts['total_cost'] / $periodStats['combined_revenue']) * 100, 1) }}%
@endif
Breakdown:
@foreach(['completed' => '✅', 'printed' => '🖨️', 'approval' => '📋', 'processing' => '⚙️'] as $status => $icon) @if($shippingCosts['breakdown'][$status]['count'] > 0)
{{ $icon }} {{ ucfirst($status) }}: RM {{ number_format($shippingCosts['breakdown'][$status]['cost'], 2) }} ({{ $shippingCosts['breakdown'][$status]['count'] }})
@endif @endforeach
Current Rates:
• Online: RM {{ number_format($shippingCosts['rates']['online_payment'], 2) }}
• COD East: RM {{ number_format($shippingCosts['rates']['cod_east_malaysia'], 2) }}
• COD Peninsular: RM {{ number_format($shippingCosts['rates']['cod_peninsular'], 2) }}
@else

No orders with tracking numbers in this period

@endif

💰 ROI Calculator

Total Sales ({{ $periodStats['period_label'] }})
{{ $periodStats['primary_currency'] }} {{ number_format($periodStats['combined_revenue'], 2) }}

📊 Delivery by State

@if(count($advancedAnalytics['delivery_by_state']['data']) > 0)
@foreach(array_slice($advancedAnalytics['delivery_by_state']['data'], 0, 15) as $state)
{{ $state['state'] }}
{{ $state['percentage'] }}% ({{ $state['count'] }})
@endforeach
Total Deliveries: {{ number_format($advancedAnalytics['delivery_by_state']['total']) }}
@else

No delivery data available

@endif

🏆 Top Products

@if(count($advancedAnalytics['top_products']) > 0)
@foreach(array_slice($advancedAnalytics['top_products'], 0, 20) as $index => $product)
#{{ $index + 1 }} {{ $product['sku'] }}
{{ Str::limit($product['name'], 30) }}
{{ $product['orders'] }} orders
{{ number_format($product['units']) }} units
@endforeach
@else

No product data available

@endif

📦 Units Out (by SKU)

@if(count($advancedAnalytics['units_out']['data']) > 0)
@foreach(array_slice($advancedAnalytics['units_out']['data'], 0, 25) as $sku)
{{ $sku['sku'] }} {{ number_format($sku['units']) }}
@endforeach
Total Units: {{ number_format($advancedAnalytics['units_out']['total_units']) }}
@else

No units data available

@endif

👥 Repeat Customers

@if(count($advancedAnalytics['repeat_customers']['data']) > 0)
{{ $advancedAnalytics['repeat_customers']['total_repeat_customers'] }} repeat customers ({{ $advancedAnalytics['repeat_customers']['repeat_rate'] }}% repeat rate)
@foreach(array_slice($advancedAnalytics['repeat_customers']['data'], 0, 30) as $customer)
{{ $customer['name'] ?: 'Unknown' }}
📱 {{ $customer['phone'] ?: $customer['email'] }}
{{ $customer['order_count'] }} orders
@php $primaryCurrency = $periodStats['primary_currency'] ?? 'MYR'; $currencySymbol = match(strtoupper($primaryCurrency)) { 'MYR' => 'RM', 'USD' => '$', default => $primaryCurrency . ' ', }; @endphp {{ $currencySymbol }}{{ number_format($customer['total_spent'], 0) }}
@endforeach
@else

No repeat customers in this period

@endif

📈 Sales Insights

@if(count($advancedAnalytics['delivery_by_state']['data']) > 0)
Top Delivery State
{{ $advancedAnalytics['delivery_by_state']['data'][0]['state'] }}
{{ $advancedAnalytics['delivery_by_state']['data'][0]['percentage'] }}% of all deliveries
@endif @if(count($advancedAnalytics['top_products']) > 0)
Best Seller
{{ $advancedAnalytics['top_products'][0]['sku'] }}
{{ number_format($advancedAnalytics['top_products'][0]['units']) }} units sold
@endif
Customer Loyalty
{{ $advancedAnalytics['repeat_customers']['repeat_rate'] }}% Repeat Rate
{{ $advancedAnalytics['repeat_customers']['total_repeat_customers'] }} of {{ $advancedAnalytics['repeat_customers']['total_customers'] }} customers

🎯 Focus Areas

@php $focusAreas = []; // Low repeat rate if($advancedAnalytics['repeat_customers']['repeat_rate'] < 20) { $focusAreas[] = ['icon' => '⚠️', 'title' => 'Low Repeat Rate', 'desc' => 'Focus on customer retention strategies']; } // High concentration in one state if(count($advancedAnalytics['delivery_by_state']['data']) > 0 && $advancedAnalytics['delivery_by_state']['data'][0]['percentage'] > 40) { $focusAreas[] = ['icon' => '🗺️', 'title' => 'Geographic Concentration', 'desc' => 'Consider expanding to other states']; } // Top products if(count($advancedAnalytics['top_products']) > 0) { $focusAreas[] = ['icon' => '✅', 'title' => 'Stock Top Sellers', 'desc' => 'Ensure inventory for SKU: ' . $advancedAnalytics['top_products'][0]['sku']]; } // Good repeat rate if($advancedAnalytics['repeat_customers']['repeat_rate'] >= 30) { $focusAreas[] = ['icon' => '🎉', 'title' => 'Good Customer Loyalty', 'desc' => 'Maintain quality and service levels']; } @endphp @if(count($focusAreas) > 0) @foreach($focusAreas as $area)
{{ $area['icon'] }}
{{ $area['title'] }}
{{ $area['desc'] }}
@endforeach @else

Keep monitoring your metrics

@endif
@if($topSales !== null)

Top Sales Performance

{{ $dateRange['label'] }}
@if($topSales->count() > 0)
@foreach($topSales as $index => $seller) @endforeach
Rank Seller Name Total Orders Total Revenue Avg Order Value
@if($index === 0) 🥇 @elseif($index === 1) 🥈 @elseif($index === 2) 🥉 @else {{ $index + 1 }} @endif
{{ $seller->name }} @if(isset($seller->has_historical_data) && $seller->has_historical_data) @endif
{{ $seller->email }}
{{ number_format($seller->total_orders) }}
RM {{ number_format($seller->total_revenue, 2) }}
RM {{ number_format($seller->avg_order_value, 2) }}
@else

No sales data available for the selected period.

@endif
@endif
@endsection