mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-26 23:27:13 +01:00
Added chart for games per category
This commit is contained in:
parent
b5844f0f48
commit
a3f3773834
4 changed files with 78 additions and 7 deletions
|
|
@ -8,6 +8,8 @@ use Filament\Widgets\StatsOverviewWidget\Card;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
use App\Models\Reserveditem;
|
use App\Models\Reserveditem;
|
||||||
|
use Filament\Support\Enums\IconPosition;
|
||||||
|
|
||||||
|
|
||||||
class AdminWidget extends BaseWidget
|
class AdminWidget extends BaseWidget
|
||||||
{
|
{
|
||||||
|
|
@ -17,10 +19,10 @@ class AdminWidget extends BaseWidget
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
//Card::make(__('Total number of users'), User::count() ),
|
//Card::make(__('Total number of users'), User::count() ),
|
||||||
Card::make(__('Total number of games'), Item::where('type', 'game')->count() ),
|
Stat::make(__('Total amount of games'), Item::where('type', 'game')->count() ),
|
||||||
Card::make(__('Total number of items'), Item::where('type', 'item')->count() ),
|
Stat::make(__('Total amount of items'), Item::where('type', 'item')->count() ),
|
||||||
Card::make(__('Reservations at the moment'), Reserveditem::where('returned_date', null)->count() ),
|
Stat::make(__('Reservations at the moment'), Reserveditem::where('returned_date', null)->count() ),
|
||||||
Card::make(__('Reservations over time'), Reserveditem::withTrashed()->withTrashed()->count() ),
|
Stat::make(__('Reservations over time'), Reserveditem::withTrashed()->withTrashed()->count() ),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
66
app/Filament/Widgets/PopularCategoryChart.php
Normal file
66
app/Filament/Widgets/PopularCategoryChart.php
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use Filament\Widgets\ChartWidget;
|
||||||
|
use App\Models\Reserveditem;
|
||||||
|
use App\Models\Category;
|
||||||
|
|
||||||
|
|
||||||
|
class PopularCategoryChart extends ChartWidget
|
||||||
|
{
|
||||||
|
protected static ?string $heading = 'Game 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::where('type', 'game')->get();
|
||||||
|
$categoryNames = [];
|
||||||
|
|
||||||
|
foreach ($categories as $obj){
|
||||||
|
$categoryNames[] = $obj->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = Reserveditem::withTrashed()->with('item')->whereHas('item', function($query){
|
||||||
|
return $query->where('type', 'game');
|
||||||
|
})->get()->groupBy('item.category_id');
|
||||||
|
|
||||||
|
|
||||||
|
$itemCategoriesCount = [];
|
||||||
|
|
||||||
|
foreach ($items as $item){
|
||||||
|
|
||||||
|
$itemCategoriesCount[] = $item->count();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'datasets' => [
|
||||||
|
[
|
||||||
|
'label' => __('Reservation Category'),
|
||||||
|
'data' => $itemCategoriesCount,
|
||||||
|
'backgroundColor' => ["#03045e","#0077b6","#00b4d8","#90e0ef","#caf0f8"],
|
||||||
|
"hoverOffset" => 4,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'labels' => $categoryNames,
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getType(): string
|
||||||
|
{
|
||||||
|
return 'pie';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ use App\Models\Reserveditem;
|
||||||
class ReservationsChart extends ChartWidget
|
class ReservationsChart extends ChartWidget
|
||||||
{
|
{
|
||||||
protected static ?string $heading = "Reservations by month";
|
protected static ?string $heading = "Reservations by month";
|
||||||
|
protected static ?string $maxHeight = '300px';
|
||||||
|
|
||||||
|
|
||||||
protected function getData(): array
|
protected function getData(): array
|
||||||
|
|
|
||||||
8
lang/vendor/filament-panels/sv.json
vendored
8
lang/vendor/filament-panels/sv.json
vendored
|
|
@ -33,8 +33,8 @@
|
||||||
"Is admin": "Admin",
|
"Is admin": "Admin",
|
||||||
"Password": "Lösenord",
|
"Password": "Lösenord",
|
||||||
"Email verified at": "Email verifierad den",
|
"Email verified at": "Email verifierad den",
|
||||||
"Total number of games": "Totalt antal spel i lager",
|
"Total amount of games": "Totalt antal spel i lager",
|
||||||
"Total number of items": "Totalt antal saker i lager",
|
"Total amount of items": "Totalt antal saker i lager",
|
||||||
"Reservations at the moment": "Nuvarande reservationer",
|
"Reservations at the moment": "Nuvarande reservationer",
|
||||||
"Reservations over time": "Alla reservationer",
|
"Reservations over time": "Alla reservationer",
|
||||||
"Phone": "Telefonnummer",
|
"Phone": "Telefonnummer",
|
||||||
|
|
@ -42,5 +42,7 @@
|
||||||
"Category literature": "Kategori litteratur",
|
"Category literature": "Kategori litteratur",
|
||||||
"Category games": "Kategori spel",
|
"Category games": "Kategori spel",
|
||||||
"Category items": "Kategori saker",
|
"Category items": "Kategori saker",
|
||||||
"Reservations by month": "Reservationer per månad"
|
"Reservations by month": "Reservationer per månad",
|
||||||
|
"Amount of games in inventory": "Antal spel i lager",
|
||||||
|
"Amount of items in inventory": "Antal saker i lager"
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue