268 lines
10 KiB
PHP
268 lines
10 KiB
PHP
<?php
|
|
|
|
use App\Models\Partner;
|
|
use App\Models\User;
|
|
use App\Models\RegistrationCode;
|
|
use App\Helpers\ThemeHelper;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Volt\Component;
|
|
|
|
new class extends Component {
|
|
public $userRole = '';
|
|
public $roleIcon = 'shield-check';
|
|
public $roleName = '';
|
|
|
|
// Admin KPIs
|
|
public $activeHubs = 0;
|
|
public $plannedHubs = 0;
|
|
public $totalPartners = 0;
|
|
public $partnersThisMonth = 0;
|
|
public $platformRevenue = 0;
|
|
public $systemStatus = 'green';
|
|
public $pendingInvitations = 0;
|
|
public $totalCustomers = 0;
|
|
public array $data = [];
|
|
|
|
// Retailer KPIs
|
|
public $openOrders = 0;
|
|
public $monthlyRevenue = 0;
|
|
public $productViews = 0;
|
|
public $stockWarnings = 0;
|
|
public $myCustomers = 0;
|
|
|
|
// Manufacturer KPIs
|
|
public $brandReach = 0;
|
|
public $activeProducts = 0;
|
|
public $draftProducts = 0;
|
|
public $totalViews = 0;
|
|
|
|
// Broker KPIs
|
|
public $totalCommission = 0;
|
|
public $pendingPayout = 0;
|
|
public $generatedLeads = 0;
|
|
public $referralLink = '';
|
|
public $brokerCustomers = 0;
|
|
|
|
// Customer Brand Data
|
|
public $customerBrand = 'b2in';
|
|
public $customerBrandName = 'B2IN';
|
|
public $customerBrandLogo = '';
|
|
public $customerBrandColors = [];
|
|
public $customerBrokerName = '';
|
|
public $topOffers = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = Auth::user();
|
|
$role = $user->roles->first();
|
|
|
|
if ($role) {
|
|
$this->userRole = strtolower(str_replace('-', '', $role->name));
|
|
$this->roleIcon = $role->icon ?? 'shield-check';
|
|
$this->roleName = $role->display_name ?? $role->name;
|
|
}
|
|
|
|
// Lade rollenspezifische Daten
|
|
match ($this->userRole) {
|
|
'admin', 'superadmin' => $this->loadAdminData(),
|
|
'retailer' => $this->loadRetailerData($user),
|
|
'manufacturer' => $this->loadManufacturerData($user),
|
|
'broker', 'estateagent' => $this->loadBrokerData($user),
|
|
'customer' => $this->loadCustomerData($user),
|
|
default => null,
|
|
};
|
|
}
|
|
|
|
private function loadAdminData(): void
|
|
{
|
|
// Platzhalter: Aktive Hubs (später aus Hub-Tabelle)
|
|
$this->activeHubs = 3;
|
|
$this->plannedHubs = 2;
|
|
|
|
// Partner-Wachstum
|
|
$this->totalPartners = Partner::whereIn('type', ['Retailer', 'Manufacturer', 'Broker', 'Estate-Agent'])->count();
|
|
$this->partnersThisMonth = Partner::whereIn('type', ['Retailer', 'Manufacturer', 'Broker', 'Estate-Agent'])
|
|
->whereMonth('created_at', now()->month)
|
|
->count();
|
|
|
|
// Platzhalter: Plattform-Umsatz
|
|
$this->platformRevenue = 125000; // Später aus Order-Tabelle
|
|
|
|
// System-Status (Platzhalter)
|
|
$this->systemStatus = 'green';
|
|
|
|
// Onboarding-Pipeline: Codes ohne registrierte User
|
|
$this->pendingInvitations = RegistrationCode::whereNull('used_at')->count();
|
|
|
|
// Kunden gesamt
|
|
$this->totalCustomers = Partner::where('type', 'Customer')->count();
|
|
|
|
$this->data = [
|
|
['date' => '2025-12-11', 'visitors' => 50],
|
|
['date' => '2025-12-12', 'visitors' => 70],
|
|
['date' => '2025-12-13', 'visitors' => 100],
|
|
['date' => '2025-12-14', 'visitors' => 210],
|
|
['date' => '2025-12-15', 'visitors' => 198],
|
|
['date' => '2025-12-16', 'visitors' => 269],
|
|
['date' => '2025-12-17', 'visitors' => 259],
|
|
['date' => '2025-12-18', 'visitors' => 267],
|
|
];
|
|
}
|
|
|
|
private function loadRetailerData(User $user): void
|
|
{
|
|
// Platzhalter: Offene Bestellungen
|
|
$this->openOrders = 5; // Später aus Order-Tabelle
|
|
|
|
// Platzhalter: Umsatz diesen Monat
|
|
$this->monthlyRevenue = 15500; // Später aus Order-Tabelle
|
|
|
|
// Platzhalter: Produkt-Views
|
|
$this->productViews = 1250; // Später aus Analytics
|
|
|
|
// Platzhalter: Lager-Warnungen
|
|
$this->stockWarnings = 3; // Später aus Product-Tabelle (stock < min_stock)
|
|
|
|
// Meine Kunden (Kunden die diesem Händler zugeordnet sind)
|
|
if ($user->partner_id) {
|
|
$this->myCustomers = Partner::where('type', 'Customer')
|
|
->where('parent_partner_id', $user->partner_id)
|
|
->count();
|
|
}
|
|
}
|
|
|
|
private function loadManufacturerData(User $user): void
|
|
{
|
|
// Platzhalter: Marken-Reichweite (Händler die meine Produkte führen)
|
|
$this->brandReach = 12; // Später aus Produkt-Zuordnungen
|
|
|
|
// Platzhalter: Katalog-Status
|
|
$this->activeProducts = 45; // Später aus Product-Tabelle (is_active = true)
|
|
$this->draftProducts = 7; // Später aus Product-Tabelle (is_active = false)
|
|
|
|
// Platzhalter: Gesamt-Views
|
|
$this->totalViews = 8900; // Später aus Analytics
|
|
}
|
|
|
|
private function loadBrokerData(User $user): void
|
|
{
|
|
// Platzhalter: Verdiente Provision
|
|
$this->totalCommission = 4250.50; // Später aus Commission-Tabelle
|
|
|
|
// Platzhalter: Offene Auszahlung
|
|
$this->pendingPayout = 850.00; // Später aus Payout-Tabelle
|
|
|
|
// Generierte Leads (Kunden über diesen Makler)
|
|
if ($user->partner_id) {
|
|
$this->generatedLeads = Partner::where('type', 'Customer')
|
|
->where('parent_partner_id', $user->partner_id)
|
|
->count();
|
|
|
|
$this->brokerCustomers = $this->generatedLeads;
|
|
}
|
|
|
|
// Empfehlungs-Link (Platzhalter)
|
|
$partner = Partner::find($user->partner_id);
|
|
if ($partner) {
|
|
$this->referralLink = url('/register?ref=' . $partner->partner_number);
|
|
}
|
|
}
|
|
|
|
private function loadCustomerData(User $user): void
|
|
{
|
|
// Kunde: Lade Brand-Daten vom Partner
|
|
if ($user->partner_id) {
|
|
$partner = Partner::find($user->partner_id);
|
|
|
|
if ($partner) {
|
|
// Brand aus Partner-Datensatz
|
|
$this->customerBrand = $partner->brand ?? 'b2in';
|
|
$this->customerBrandName = ThemeHelper::getBrandName($this->customerBrand);
|
|
$this->customerBrandLogo = ThemeHelper::getLogoPathForBrand($this->customerBrand, 'positive');
|
|
$this->customerBrandColors = ThemeHelper::getBrandColors($this->customerBrand);
|
|
|
|
// Makler/Händler-Namen laden, falls vorhanden
|
|
if ($partner->parent_partner_id) {
|
|
$parentPartner = Partner::find($partner->parent_partner_id);
|
|
if ($parentPartner) {
|
|
$this->customerBrokerName = $parentPartner->display_name ?? $parentPartner->company_name ?? '';
|
|
}
|
|
}
|
|
|
|
// Top-Angebote laden (Platzhalter - später aus Product-Tabelle)
|
|
$this->topOffers = [
|
|
[
|
|
'id' => 1,
|
|
'name' => 'Designer Sofa "Luna"',
|
|
'description' => 'Modernes 3-Sitzer Sofa mit Samtbezug',
|
|
'price' => 1899.00,
|
|
'original_price' => 2499.00,
|
|
'discount' => 24,
|
|
'image' => 'https://images.unsplash.com/photo-1555041469-a586c61ea9bc?w=400&h=300&fit=crop',
|
|
'category' => 'Wohnzimmer',
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'name' => 'Esstisch "Nordic"',
|
|
'description' => 'Massivholz Esstisch für 6-8 Personen',
|
|
'price' => 899.00,
|
|
'original_price' => 1299.00,
|
|
'discount' => 31,
|
|
'image' => 'https://images.unsplash.com/photo-1617806118233-18e1de247200?w=400&h=300&fit=crop',
|
|
'category' => 'Esszimmer',
|
|
],
|
|
[
|
|
'id' => 3,
|
|
'name' => 'Boxspringbett "Royal"',
|
|
'description' => 'Premium Boxspringbett 180x200 cm',
|
|
'price' => 1599.00,
|
|
'original_price' => 2199.00,
|
|
'discount' => 27,
|
|
'image' => 'https://images.unsplash.com/photo-1505693416388-ac5ce068fe85?w=400&h=300&fit=crop',
|
|
'category' => 'Schlafzimmer',
|
|
],
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}; ?>
|
|
|
|
<x-layouts.app title="Dashboard">
|
|
@volt('dashboard')
|
|
<div class="space-y-6">
|
|
{{-- Header mit Rollenbadge --}}
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<flux:heading size="xl">{{ __('Dashboard') }} (Beispiel)</flux:heading>
|
|
<flux:subheading>{{ __('Willkommen zurück') }}, {{ Auth::user()->name }}!</flux:subheading>
|
|
</div>
|
|
<div class="flex items-center gap-2 px-3 py-2 bg-accent-50 dark:bg-accent-900/20 rounded-lg">
|
|
@svg('heroicon-o-'.$roleIcon, 'w-5 h-5 text-accent-600 dark:text-accent-400')
|
|
<span class="text-sm font-medium text-accent-700 dark:text-accent-300">
|
|
{{ $roleName }}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
{{-- Rollenspezifisches Dashboard laden --}}
|
|
@if(in_array($userRole, ['admin', 'superadmin']))
|
|
@include('admin.dashboards.admin')
|
|
@elseif($userRole === 'retailer')
|
|
@include('admin.dashboards.retailer')
|
|
@elseif($userRole === 'manufacturer')
|
|
@include('admin.dashboards.manufacturer')
|
|
@elseif(in_array($userRole, ['broker', 'estateagent']))
|
|
@include('admin.dashboards.broker')
|
|
@elseif($userRole === 'customer')
|
|
@include('admin.dashboards.customer')
|
|
@else
|
|
<flux:card>
|
|
<div class="text-center py-8">
|
|
<div class="text-zinc-500">{{ __('Dashboard für Ihre Rolle wird noch entwickelt.') }}</div>
|
|
</div>
|
|
</flux:card>
|
|
@endif
|
|
</div>
|
|
@endvolt
|
|
</x-layouts.app>
|