refactor(chart): prop outlets dikirim dari parent
This commit is contained in:
parent
49b3d60c53
commit
9cfb5b75a7
@ -16,19 +16,15 @@ class ChannelRevenue extends Component
|
||||
|
||||
public array $borderColors = [];
|
||||
|
||||
public function mount()
|
||||
public function mount(array $outlets)
|
||||
{
|
||||
$outlets = auth()->user()->outlets()->pluck('name', 'outlets.id');
|
||||
|
||||
$orders = Order::select('channel', 'total')
|
||||
->whereIn('outlet_id', $outlets->keys())
|
||||
->whereIn('outlet_id', array_keys($outlets))
|
||||
->get()
|
||||
->groupBy('channel');
|
||||
|
||||
$data = [];
|
||||
|
||||
$count = count(OrderChannel::cases());
|
||||
|
||||
foreach (OrderChannel::cases() as $channel) {
|
||||
$channelOrders = $orders[$channel->value] ?? collect();
|
||||
$total = $channelOrders->sum('total');
|
||||
@ -39,6 +35,8 @@ public function mount()
|
||||
|
||||
$this->revenues = $data;
|
||||
|
||||
// random colors
|
||||
$count = count(OrderChannel::cases());
|
||||
$this->backgroundColors = randomColors($count, 0.2);
|
||||
$this->borderColors = randomColors($count, 1.0);
|
||||
}
|
||||
|
||||
@ -17,10 +17,8 @@ class OutletExpense extends Component
|
||||
|
||||
public array $borderColors = [];
|
||||
|
||||
public function mount()
|
||||
public function mount(array $outlets)
|
||||
{
|
||||
$outlets = auth()->user()->outlets()->pluck('name', 'outlets.id');
|
||||
|
||||
$expensesData = [];
|
||||
|
||||
foreach ($outlets as $id => $name) {
|
||||
@ -35,10 +33,11 @@ public function mount()
|
||||
$expensesData[$name] = $total;
|
||||
}
|
||||
|
||||
$this->outlets = array_keys($expensesData);
|
||||
$this->outlets = array_values($outlets);
|
||||
|
||||
$this->expenses = array_values($expensesData);
|
||||
|
||||
// random colors
|
||||
$count = count($this->outlets);
|
||||
$this->backgroundColors = randomColors($count, 0.2);
|
||||
$this->borderColors = randomColors($count, 1.0);
|
||||
|
||||
@ -15,20 +15,19 @@ class OutletRevenue extends Component
|
||||
|
||||
public array $borderColors = [];
|
||||
|
||||
public function mount()
|
||||
public function mount(array $outlets)
|
||||
{
|
||||
$outlets = auth()->user()->outlets()->pluck('name', 'outlets.id');
|
||||
|
||||
$revenues = DB::table('orders')
|
||||
->select('outlet_id', DB::raw('SUM(total) as total_revenue'))
|
||||
->whereIn('outlet_id', $outlets->keys())
|
||||
->whereIn('outlet_id', array_keys($outlets))
|
||||
->groupBy('outlet_id')
|
||||
->pluck('total_revenue', 'outlet_id');
|
||||
|
||||
$this->outlets = $outlets->values()->toArray();
|
||||
$this->outlets = array_values($outlets);
|
||||
|
||||
$this->revenues = $outlets->map(fn ($name, $id) => $revenues[$id] ?? 0)->values()->toArray();
|
||||
$this->revenues = collect($outlets)->map(fn ($name, $id) => $revenues[$id] ?? 0)->values()->toArray();
|
||||
|
||||
// random colors
|
||||
$count = count($this->outlets);
|
||||
$this->backgroundColors = randomColors($count, 0.2);
|
||||
$this->borderColors = randomColors($count, 1.0);
|
||||
|
||||
@ -16,10 +16,8 @@ class OutletRevenueExpense extends Component
|
||||
|
||||
public array $expenses = [];
|
||||
|
||||
public function mount()
|
||||
public function mount(array $outlets)
|
||||
{
|
||||
$outlets = auth()->user()->outlets()->pluck('name', 'outlets.id');
|
||||
|
||||
$revenueData = [];
|
||||
|
||||
$expenseData = [];
|
||||
@ -34,7 +32,7 @@ public function mount()
|
||||
$expenseData[$name] = $expenseTotal + $purchaseTotal + $payrollTotal;
|
||||
}
|
||||
|
||||
$this->outlets = $outlets->values()->toArray();
|
||||
$this->outlets = array_values($outlets);
|
||||
|
||||
$this->revenues = array_values($revenueData);
|
||||
|
||||
|
||||
@ -127,10 +127,10 @@
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6 mt-2">
|
||||
<livewire:chart.outlet-revenue />
|
||||
<livewire:chart.outlet-expense />
|
||||
<livewire:chart.channel-revenue />
|
||||
<livewire:chart.outlet-revenue :outlets="$outlets" />
|
||||
<livewire:chart.outlet-expense :outlets="$outlets" />
|
||||
<livewire:chart.channel-revenue :outlets="$outlets" />
|
||||
</div>
|
||||
<livewire:chart.outlet-revenue-expense />
|
||||
<livewire:chart.outlet-revenue-expense :outlets="$outlets" />
|
||||
</div>
|
||||
</flux:main>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user