Remove Livewire chart components for outlet revenue, expense, and channel, and their dashboard display.

This commit is contained in:
Yoga Pangestu 2026-01-03 00:12:47 +07:00
parent 8518ddb6f2
commit 4cb94e3ed5
5 changed files with 0 additions and 188 deletions

View File

@ -1,48 +0,0 @@
<?php
namespace App\Livewire\Chart;
use App\Enums\OrderChannel;
use App\Models\Order;
use Livewire\Component;
class ChannelRevenue extends Component
{
public array $channels = [];
public array $revenues = [];
public array $backgroundColors = [];
public array $borderColors = [];
public function mount(array $outlets)
{
$orders = Order::select('channel', 'total')
->whereIn('outlet_id', array_keys($outlets))
->get()
->groupBy('channel');
$data = [];
foreach (OrderChannel::cases() as $channel) {
$channelOrders = $orders[$channel->value] ?? collect();
$total = $channelOrders->sum('total');
$data[] = $total;
$this->channels[] = $channel->label();
}
$this->revenues = $data;
// random colors
$count = count(OrderChannel::cases());
$this->backgroundColors = generateRandomRgbaColors($count, 0.2);
$this->borderColors = generateRandomRgbaColors($count, 1.0);
}
public function render()
{
return view('livewire.chart.channel-revenue');
}
}

View File

@ -1,47 +0,0 @@
<?php
namespace App\Livewire\Chart;
use App\Models\Expense;
use App\Models\Payroll;
use Livewire\Component;
class OutletExpense extends Component
{
public array $outlets = [];
public array $expenses = [];
public array $backgroundColors = [];
public array $borderColors = [];
public function mount(array $outlets)
{
$expensesData = [];
foreach ($outlets as $id => $name) {
$expenseTotal = Expense::where('outlet_id', $id)->sum('amount');
$payrollTotal = Payroll::whereHas('user.outlets', fn ($q) => $q->where('outlet_id', $id))->sum('total_salary');
$total = $expenseTotal + $payrollTotal;
$expensesData[$name] = $total;
}
$this->outlets = array_values($outlets);
$this->expenses = array_values($expensesData);
// random colors
$count = count($this->outlets);
$this->backgroundColors = generateRandomRgbaColors($count, 0.2);
$this->borderColors = generateRandomRgbaColors($count, 1.0);
}
public function render()
{
return view('livewire.chart.outlet-expense');
}
}

View File

@ -1,40 +0,0 @@
<?php
namespace App\Livewire\Chart;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
class OutletRevenue extends Component
{
public array $outlets = [];
public array $revenues = [];
public array $backgroundColors = [];
public array $borderColors = [];
public function mount(array $outlets)
{
$revenues = DB::table('orders')
->select('outlet_id', DB::raw('SUM(total) as total_revenue'))
->whereIn('outlet_id', array_keys($outlets))
->groupBy('outlet_id')
->pluck('total_revenue', 'outlet_id');
$this->outlets = array_values($outlets);
$this->revenues = collect($outlets)->map(fn ($name, $id) => $revenues[$id] ?? 0)->values()->toArray();
// random colors
$count = count($this->outlets);
$this->backgroundColors = generateRandomRgbaColors($count, 0.2);
$this->borderColors = generateRandomRgbaColors($count, 1.0);
}
public function render()
{
return view('livewire.chart.outlet-revenue');
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace App\Livewire\Chart;
use App\Models\Expense;
use App\Models\Order;
use App\Models\Payroll;
use Livewire\Component;
class OutletRevenueExpense extends Component
{
public array $outlets = [];
public array $revenues = [];
public array $expenses = [];
public function mount(array $outlets)
{
$revenueData = [];
$expenseData = [];
foreach ($outlets as $id => $name) {
$totalRevenue = Order::where('outlet_id', $id)->sum('total');
$revenueData[$name] = $totalRevenue;
$expenseTotal = Expense::where('outlet_id', $id)->sum('amount');
$payrollTotal = Payroll::whereHas('user.outlets', fn ($q) => $q->where('outlet_id', $id))->sum('total_salary');
$expenseData[$name] = $expenseTotal + $payrollTotal;
}
$this->outlets = array_values($outlets);
$this->revenues = array_values($revenueData);
$this->expenses = array_values($expenseData);
}
public function render()
{
return view('livewire.chart.outlet-revenue-expense');
}
}

View File

@ -156,14 +156,5 @@
</flux:card>
</div>
</div>
@if (auth()->user()->hasRole(['Owner', 'Developer']))
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6 mt-2">
<livewire:chart.outlet-revenue :outlets="$outlets" />
<livewire:chart.outlet-expense :outlets="$outlets" />
<livewire:chart.channel-revenue :outlets="$outlets" />
</div>
<livewire:chart.outlet-revenue-expense :outlets="$outlets" />
@endif
</div>
</flux:main>