@extends('user.layout')
@php
$default = \App\Models\User\Language::where('is_default', 1)->first();
$user = Auth::guard('web')->user();
$package = \App\Http\Helpers\UserPermissionHelper::currentPackagePermission($user->id);
if (!empty($user)) {
$permissions = \App\Http\Helpers\UserPermissionHelper::packagePermission($user->id);
$permissions = json_decode($permissions, true);
}
@endphp
@section('styles')
@endsection
@section('content')
{{-- ===== WELCOME ===== --}}
{{ __('Welcome back') }}, {{ $user->first_name ?? $user->username }}! 👋
{{ __("Here's what's happening with your store today.") }}
@php
$isPlanInactive = empty($current_package) || empty($current_membership);
@endphp
@if ($isPlanInactive)
@php
$pendingMemb = \App\Models\Membership::query()
->where([['user_id', '=', Auth::id()], ['status', 0]])
->whereYear('start_date', '<>', '9999')
->orderBy('id', 'DESC')->first();
$pendingPackage = isset($pendingMemb) ? \App\Models\Package::query()->find($pendingMemb->package_id) : null;
$lastExpiredMemb = \App\Models\Membership::query()
->where('user_id', Auth::id())
->orderBy('expire_date', 'DESC')->first();
@endphp
@if ($pendingPackage)
{{ __('Package Request Under Review') }}
{{ __('You have requested the package:') }} {{ $pendingPackage->title }} ({{ $pendingPackage->term }}). {{ __('Our team is reviewing your payment and will activate it shortly.') }}
{{ __('Decision Pending') }}
@else
{{ __('Plan Expired') }}
@if($lastExpiredMemb && !empty($lastExpiredMemb->expire_date))
{{ __('Expired on') }}: {{ \Carbon\Carbon::parse($lastExpiredMemb->expire_date)->format('M d, Y h:i A') }}
@endif
{{ __('Your plan is expired. Please contact the admin or renew your plan.') }}
{{ __('Your store features and public storefront are temporarily suspended. Renew your subscription now to immediately reactivate your catalog, accept orders, and bring your store back online.') }}
@endif
@else
@php
$pLimitVal = $current_package->product_limit ?? 0;
$oLimitVal = $current_package->order_limit ?? 0;
$prodLimitLabel = $pLimitVal == 999999
? __('Unlimited Products')
: __('Up to :count Products', ['count' => number_format($pLimitVal)]);
$orderLimitLabel = $oLimitVal == 999999
? __('Unlimited Orders')
: __('Up to :count Orders', ['count' => number_format($oLimitVal)]);
$packageFeatures = !empty($current_package->features) ? (json_decode($current_package->features, true) ?? []) : [];
$isUnlimitedOrders = ($oLimitVal == 999999);
$orderPercent = $isUnlimitedOrders ? 0 : ($oLimitVal > 0 ? min(($total_orders / $oLimitVal) * 100, 100) : 0);
@endphp
{{-- ===== PLAN BANNER ===== --}}
{{-- Container 1: Current Plan Details --}}
{{ __('Current Plan') }}
{{ $current_package->title }}
{{ ucfirst($current_package->term) }}
@php
$planPriceVal = (float)($current_membership->price ?? $current_package->price ?? 0);
@endphp
{{ $planPriceVal == 0 ? __('Free') : format_price($planPriceVal) }}
@if(!empty($current_membership->ai_engine))
AI: {{ strtoupper($current_membership->ai_engine) }}
@endif
{{ __('Expires on') }}
{{ $current_package->term === 'lifetime' ? __('Lifetime') : \Carbon\Carbon::parse($current_membership->expire_date)->format('d M, Y') }}
{{ __('Manage Plan') }}
{{-- Container 2: Limit Container --}}
@php
if (\Schema::hasTable('package_features')) {
$allFeatures = \App\Models\PackageFeature::orderBy('serial_number', 'asc')->get();
} else {
$allFeatures = collect();
}
$activeFeatureLabels = [];
if ($allFeatures->isEmpty()) {
$activeFeatureLabels[] = $prodLimitLabel;
$activeFeatureLabels[] = $orderLimitLabel;
if (is_array($packageFeatures) && in_array('Custom Domain', $packageFeatures)) {
$activeFeatureLabels[] = __('Custom Domain');
}
if (is_array($packageFeatures) && in_array('Subdomain', $packageFeatures)) {
$activeFeatureLabels[] = __('Subdomain');
}
} else {
foreach ($allFeatures as $feature) {
if ($feature->type === 'limit') {
$limitVal = $current_package->{$feature->limit_key} ?? 0;
if ($limitVal > 0 || $limitVal == 999999) {
$formattedVal = ($limitVal == 999999) ? __('Unlimited') : $limitVal;
if ($feature->limit_key === 'order_limit' && $limitVal != 999999) {
$formattedVal .= '/' . ($current_package->term == 'monthly' ? 'm' : 'yr');
}
$activeFeatureLabels[] = str_replace('{limit}', $formattedVal, $feature->name);
}
} elseif ($feature->type === 'standard') {
if (is_array($packageFeatures) && in_array($feature->keyword, $packageFeatures)) {
$text = $feature->name;
if (!empty($feature->limit_key)) {
$limitVal = $current_package->{$feature->limit_key} ?? 0;
$formattedVal = ($limitVal == 999999) ? __('Unlimited') : $limitVal;
$text = str_replace('{limit}', $formattedVal, $text);
}
$activeFeatureLabels[] = $text;
}
} elseif ($feature->type === 'custom') {
if (is_array($packageFeatures) && in_array($feature->name, $packageFeatures)) {
$activeFeatureLabels[] = $feature->name;
}
}
}
}
@endphp
@foreach($activeFeatureLabels as $label)
{{ __($label) }}
@endforeach
{{-- Container 3: Orders This Month --}}
{{ __('Orders This Month') }}
{{ $total_orders }}
/ {{ $isUnlimitedOrders ? __('Unlimited') : number_format($oLimitVal) }}
@if($isUnlimitedOrders) {{ __('Unlimited') }}
@else {{ number_format($orderPercent, 1) }}%
@endif
{{ __('View Usage Details') }}
{{-- end plan-banner --}}
@endif
{{-- ===== STATS ROW 1 (Total Products, Orders, Customers, Revenue) ===== --}}
{{ __('Total Products') }}
{{ $total_items }}
{{ __('Orders') }}
{{ $total_orders }}
{{ __('Customers') }}
{{ $total_customers }}
{{ __('Revenue') }}
{{ $user_currency ? $user_currency->symbol : '₹' }}{{ number_format($total_revenue, 2) }}
{{-- ===== STATS ROW 2 (Conversion Rate, Subscribers, Blogs, Custom Pages) ===== --}}
{{ __('Conversion Rate') }}
{{ $conversion_rate }}%
{{ __('Subscribers') }}
{{ $total_subscribers }}
{{ __('Blogs') }}
{{ $blogs }}
{{ __('Custom Pages') }}
{{ $total_custom_pages }}
{{-- ===== CHARTS ROW ===== --}}
{{-- Sales Overview --}}
{{ __('Sales Overview') }}
{{-- Revenue Analytics --}}
{{ __('Revenue Analytics') }}
{{-- Order Trend --}}
{{-- Traffic Sources --}}
{{ __('Traffic Sources') }}
{{-- ===== BOTTOM ROW: 5 columns ===== --}}
{{-- Recent Orders --}}
@if(count($orders) == 0)
{{ __('No orders yet.') }}
@else
{{ __('Order') }}
{{ __('Customer') }}
{{ __('Total') }}
{{ __('Status') }}
{{ __('Date') }}
@foreach($orders->take(5) as $order)
#{{ $order->order_number }}
{{ $order->billing_fname }} {{ $order->billing_lname }}
{{ round($order->total, 2) }}{{ $order->currency_code }}
{{ ucfirst($order->order_status) }}
{{ $order->created_at->format('j M, Y') }}
@endforeach
@endif
{{-- Payment Logs --}}
@if(count($memberships) == 0)
{{ __('No payment logs yet.') }}
@else
{{ __('Transaction') }}
{{ __('Amount') }}
{{ __('Status') }}
{{ __('Date') }}
@foreach($memberships->take(5) as $membership)
{{ strlen($membership->transaction_id) > 10 ? mb_substr($membership->transaction_id, 0, 10, 'UTF-8').'...' : $membership->transaction_id }}
{{ $membership->price == 0 ? __('Free') : format_price($membership->price) }}
@if($membership->status == 1)
{{ __('Success') }}
@elseif($membership->status == 0)
{{ __('Pending') }}
@else
{{ __('Rejected') }}
@endif
{{ $membership->created_at->format('j M, Y') }}
@endforeach
@endif
{{-- Low Stock Alerts --}}
@if(count($low_stock_items) == 0)
{{ __('All products healthy.') }}
@else
{{ __('Product') }}
{{ __('Stock') }}
{{ __('State') }}
@foreach($low_stock_items as $item)
@if(!empty($item->thumbnail))
@else
@endif
{{ $item->title }}
{{ $item->stock }}
@if($item->stock == 0)
{{ __('Out of Stock') }}
@else
{{ __('Low Stock') }}
@endif
@endforeach
@endif
{{-- Recent Customers --}}
@if(count($recent_customers) == 0)
{{ __('No customers yet.') }}
@else
@foreach($recent_customers as $cust)
{{ strtoupper(substr($cust->first_name ?? $cust->username ?? 'C', 0, 1)) }}
{{ $cust->first_name }} {{ $cust->last_name }}
{{ $cust->email }}
{{ $cust->created_at->format('j M, Y') }}
@endforeach
@endif
{{-- Quick Actions --}}
{{-- end bottom-row --}}
{{-- ===== AI ENGINE CARDS GRID (Package-wise AI Usage) - Moved Below Low Stock, Recent Customers, Quick Actions ===== --}}
@if (!empty($aiEngineStats))
@foreach ($aiEngineStats as $key => $stat)
@php
$engineName = strtoupper($stat['engine']);
$cardClass = str_contains($engineName, 'OPENAI') ? 'p-orange' : (str_contains($engineName, 'POLLINATIONS') ? 'p-red' : 'p-purple');
@endphp
{{ __('AI ENGINE') }} : {{ $engineName }}
{{ __('Required AI Tokens') }} : {{ $stat['token_required'] }}
{{ __('Used AI Tokens') }} : {{ $stat['token_used'] }}
{{ __('Remaining AI Tokens') }} : {{ $stat['token_remaining'] }}
{{ $stat['token_percent'] }}%
@endforeach
@foreach ($aiEngineStats as $key => $stat)
@php
$engineName = strtoupper($stat['engine']);
$cardClass = str_contains($engineName, 'OPENAI') ? 'p-blue' : (str_contains($engineName, 'POLLINATIONS') ? 'p-red' : 'p-indigo');
@endphp
{{ __('AI IMAGE ENGINE') }} : {{ $engineName }}
{{ __('Required AI Images') }} : {{ $stat['image_required'] }}
{{ __('Used AI Images') }} : {{ $stat['image_used'] }}
{{ __('Remaining AI Images') }} : {{ $stat['image_remaining'] }}
{{ $stat['image_percent'] }}%
@endforeach
@endif
{{-- end dash-wrapper --}}
@endsection
@section('scripts')
@endsection