mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-12-24 12:57:13 +01:00
Compare commits
No commits in common. "bac1ee1b59f9746ff355cc2161e8137d2d9cdeac" and "12c22f5069bda9a0e821493e06008150446b8d70" have entirely different histories.
bac1ee1b59
...
12c22f5069
1 changed files with 56 additions and 0 deletions
56
app/Filament/Widgets/PopularCategoryChart.php
Normal file
56
app/Filament/Widgets/PopularCategoryChart.php
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use Filament\Widgets\ChartWidget;
|
||||||
|
use App\Models\Reserveditem;
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Item;
|
||||||
|
|
||||||
|
|
||||||
|
class PopularCategoryChart extends ChartWidget
|
||||||
|
{
|
||||||
|
protected static ?string $heading = 'Reservations by category';
|
||||||
|
protected static ?string $maxHeight = '275px';
|
||||||
|
|
||||||
|
protected static ?array $options = [
|
||||||
|
'scales' => [
|
||||||
|
'x' => [
|
||||||
|
'display' => false,
|
||||||
|
],
|
||||||
|
'y' => [
|
||||||
|
'display' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function getData(): array
|
||||||
|
{
|
||||||
|
$categories = Category::get()->sortBy('id')->pluck('name');
|
||||||
|
|
||||||
|
$items = Reserveditem::withTrashed()->with('item')->get()->groupBy('item.category_id')->orderBy('item.category_id', 'desc');
|
||||||
|
$itemCategoriesCount = [];
|
||||||
|
|
||||||
|
foreach ($items as $item){
|
||||||
|
$itemCategoriesCount[] = count($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'datasets' => [
|
||||||
|
[
|
||||||
|
'label' => __('Reservation Category'),
|
||||||
|
'data' => $itemCategoriesCount,
|
||||||
|
'backgroundColor' => ["#03045e","#0077b6","#00b4d8","#90e0ef","#caf0f8"],
|
||||||
|
"hoverOffset" => 4,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'labels' => $categories,
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getType(): string
|
||||||
|
{
|
||||||
|
return 'pie';
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue