From 88944235f2a6a5b9e20643125e0c29b88479bf43 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Mon, 8 Nov 2021 11:52:09 +0100 Subject: [PATCH 1/4] Show Client running out of Credits in Admin overview --- app/Http/Controllers/Admin/UserController.php | 2 +- app/Models/User.php | 14 ++++++++++++++ resources/views/admin/users/index.blade.php | 2 +- resources/views/admin/users/show.blade.php | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 50c4fc5e..7a58dc3b 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -251,7 +251,7 @@ class UserController extends Controller return ' ' . $user->credits(); }) ->addColumn('usage', function (User $user) { - return ' ' . $user->creditUsage(); + return ' ' . $user->creditUsage(). ' ('.$user->outOfCredits().')'; }) ->addColumn('verified', function (User $user) { return $user->getVerifiedStatus(); diff --git a/app/Models/User.php b/app/Models/User.php index 9c1d8568..b82c4a03 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -242,6 +242,20 @@ class User extends Authenticatable implements MustVerifyEmail return number_format($usage, 2, '.', ''); } + public function outOfCredits() + { + $usage = $this->creditUsage(); + $credits = $this->credits; + $timeLeft = number_format(($credits*30)/$usage); + $unit = "days"; + + if($timeLeft < 1){ + $timeLeft = number_format(($credits*30)/$usage*24,2); + $unit = "hours"; + } + return $timeLeft." ".$unit; + } + /** * @return array|string|string[] */ diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index 885b1c31..2e5704d0 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -46,7 +46,7 @@ Role Email {{CREDITS_DISPLAY_NAME}} - Usage + Usage (Out of Credits in..) Servers Verified Last seen diff --git a/resources/views/admin/users/show.blade.php b/resources/views/admin/users/show.blade.php index f18dbd65..fc8f1798 100644 --- a/resources/views/admin/users/show.blade.php +++ b/resources/views/admin/users/show.blade.php @@ -184,6 +184,7 @@ +
@@ -197,6 +198,19 @@
+
+
+
+ +
+
+ + {{$user->OutOfCredits()}} + +
+
+
+
From feb3f10074de4f7a134f9d58206ecf46f0960a1d Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Mon, 8 Nov 2021 11:54:59 +0100 Subject: [PATCH 2/4] DocBlocks --- app/Models/User.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Models/User.php b/app/Models/User.php index b82c4a03..1835183e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -242,6 +242,12 @@ class User extends Authenticatable implements MustVerifyEmail return number_format($usage, 2, '.', ''); } + + /** + * @description Returns the Users "out of Credits" time + * + * @return string + */ public function outOfCredits() { $usage = $this->creditUsage(); From 6e398c3ddf0aa761de251b2dec76b0bbc14b2a91 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Thu, 11 Nov 2021 15:44:52 +0100 Subject: [PATCH 3/4] CTRL + ALT + L --- app/Models/User.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 1835183e..327db57a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -80,9 +80,9 @@ class User extends Authenticatable implements MustVerifyEmail */ protected $casts = [ 'email_verified_at' => 'datetime', - 'last_seen' => 'datetime', - 'credits' => 'float', - 'server_limit' => 'float', + 'last_seen' => 'datetime', + 'credits' => 'float', + 'server_limit' => 'float', ]; /** @@ -248,18 +248,20 @@ class User extends Authenticatable implements MustVerifyEmail * * @return string */ + * @return string + */ public function outOfCredits() { $usage = $this->creditUsage(); $credits = $this->credits; - $timeLeft = number_format(($credits*30)/$usage); + $timeLeft = number_format(($credits * 30) / $usage); $unit = "days"; - if($timeLeft < 1){ - $timeLeft = number_format(($credits*30)/$usage*24,2); - $unit = "hours"; + if ($timeLeft < 1) { + $timeLeft = number_format(($credits * 30) / $usage * 24, 2); + $unit = "hours"; } - return $timeLeft." ".$unit; + return $timeLeft . " " . $unit; } /** From fd89a4bc915ee034bfafb8a22c0ee0a95d60f0c3 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 12 Nov 2021 18:45:10 +0100 Subject: [PATCH 4/4] fixed PHPStorm being PHPStorm --- app/Models/User.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 327db57a..c4c2a71d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -248,8 +248,6 @@ class User extends Authenticatable implements MustVerifyEmail * * @return string */ - * @return string - */ public function outOfCredits() { $usage = $this->creditUsage();