From 850ad93894edebd1d95043295ba3eaa2a90bc1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna-Sara=20S=C3=A9lea?= Date: Sun, 21 Sep 2025 10:07:31 +0200 Subject: [PATCH] Added reservation chart to admin --- app/Filament/Widgets/AdminWidget.php | 3 +- app/Filament/Widgets/ReservationsChart.php | 54 +++++++++++++++ composer.json | 1 + composer.lock | 76 +++++++++++++++++++++- lang/vendor/filament-panels/sv.json | 6 +- 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 app/Filament/Widgets/ReservationsChart.php diff --git a/app/Filament/Widgets/AdminWidget.php b/app/Filament/Widgets/AdminWidget.php index 75ec9eb..124b647 100644 --- a/app/Filament/Widgets/AdminWidget.php +++ b/app/Filament/Widgets/AdminWidget.php @@ -19,7 +19,8 @@ class AdminWidget extends BaseWidget //Card::make(__('Total number of users'), User::count() ), Card::make(__('Total number of games'), Item::where('type', 'game')->count() ), Card::make(__('Total number of items'), Item::where('type', 'item')->count() ), - Card::make(__('Reserved games and items'), Reserveditem::count() ), + Card::make(__('Reservations at the moment'), Reserveditem::where('returned_date', null)->withTrashed()->count() ), + Card::make(__('Reservations over time'), Reserveditem::withTrashed()->count() ), ]; } diff --git a/app/Filament/Widgets/ReservationsChart.php b/app/Filament/Widgets/ReservationsChart.php new file mode 100644 index 0000000..9e0d2c2 --- /dev/null +++ b/app/Filament/Widgets/ReservationsChart.php @@ -0,0 +1,54 @@ +withTrashed()) + ->dateColumn('reserved_date') + ->between( + start: now()->startOfYear(), + end: now()->endOfYear(), + ) + ->perMonth() + ->count(); + + return [ + 'datasets' => [ + [ + 'label' => __('Reservations'), + 'data' => $data->map(fn (TrendValue $value) => $value->aggregate), + ], + ], + 'labels' => $data->map(fn (TrendValue $value) => $value->date), + ]; + } + + + + protected function getType(): string + { + return 'line'; + } + + public static function canView(): bool + { + if (auth()->user()->is_admin==true) { + return true; + } else { + return false; + } + } +} diff --git a/composer.json b/composer.json index 6e9e2b3..3f704a7 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "php": "^8.2", "bezhansalleh/filament-language-switch": "^3.1", "filament/filament": "^3.2", + "flowframe/laravel-trend": "^0.4.0", "inertiajs/inertia-laravel": "^2.0", "laravel/framework": "^11.31", "laravel/pulse": "^1.4", diff --git a/composer.lock b/composer.lock index d23f735..7087973 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "879b4c253bc9b358fdf8beaa57e929cf", + "content-hash": "7deae3e88555bf85dd431c5048c67408", "packages": [ { "name": "anourvalar/eloquent-serialize", @@ -1544,6 +1544,80 @@ }, "time": "2025-03-11T16:33:32+00:00" }, + { + "name": "flowframe/laravel-trend", + "version": "v0.4.0", + "source": { + "type": "git", + "url": "https://github.com/Flowframe/laravel-trend.git", + "reference": "5ace11d3075932652dc48963faa732c043aeb14d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Flowframe/laravel-trend/zipball/5ace11d3075932652dc48963faa732c043aeb14d", + "reference": "5ace11d3075932652dc48963faa732c043aeb14d", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^8.37|^9|^10.0|^11.0|^12.0", + "php": "^8.2", + "spatie/laravel-package-tools": "^1.4.3" + }, + "require-dev": { + "nunomaduro/collision": "^5.3|^6.1|^8.0", + "orchestra/testbench": "^6.15|^7.0|^8.0|^9.0|^10.0", + "pestphp/pest": "^1.18|^2.34|^3.7", + "pestphp/pest-plugin-laravel": "^1.1|^2.3|^3.1", + "spatie/laravel-ray": "^1.23", + "vimeo/psalm": "^4.8|^5.6|^6.5" + }, + "type": "library", + "extra": { + "laravel": { + "aliases": { + "Trend": "Flowframe\\Trend\\TrendFacade" + }, + "providers": [ + "Flowframe\\Trend\\TrendServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Flowframe\\Trend\\": "src", + "Flowframe\\Trend\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Lars Klopstra", + "email": "lars@flowframe.nl", + "role": "Developer" + } + ], + "description": "Easily generate model trends", + "homepage": "https://github.com/flowframe/laravel-trend", + "keywords": [ + "Flowframe", + "laravel", + "laravel-trend" + ], + "support": { + "issues": "https://github.com/Flowframe/laravel-trend/issues", + "source": "https://github.com/Flowframe/laravel-trend/tree/v0.4.0" + }, + "funding": [ + { + "url": "https://github.com/larsklopstra", + "type": "github" + } + ], + "time": "2025-02-25T11:13:23+00:00" + }, { "name": "fruitcake/php-cors", "version": "v1.3.0", diff --git a/lang/vendor/filament-panels/sv.json b/lang/vendor/filament-panels/sv.json index 2c2a052..a4d6bb4 100644 --- a/lang/vendor/filament-panels/sv.json +++ b/lang/vendor/filament-panels/sv.json @@ -35,10 +35,12 @@ "Email verified at": "Email verifierad den", "Total number of games": "Totalt antal spel i lager", "Total number of items": "Totalt antal saker i lager", - "Reserved games and items": "Reserverade spel och saker", + "Reservations at the moment": "Nuvarande reservationer", + "Reservations over time": "Alla reservationer", "Phone": "Telefonnummer", "Literature": "Litteratur", "Category literature": "Kategori litteratur", "Category games": "Kategori spel", - "Category items": "Kategori saker" + "Category items": "Kategori saker", + "Reservations by month": "Reservationer per månad" } \ No newline at end of file