diff --git a/app/Http/Controllers/Admin/OverViewController.php b/app/Http/Controllers/Admin/OverViewController.php
index 19608455..178e4822 100644
--- a/app/Http/Controllers/Admin/OverViewController.php
+++ b/app/Http/Controllers/Admin/OverViewController.php
@@ -13,6 +13,8 @@ use App\Models\User;
use Illuminate\Support\Facades\Cache;
use App\Classes\Pterodactyl;
use App\Models\Product;
+use App\Models\Ticket;
+use Carbon\Carbon;
class OverViewController extends Controller
{
@@ -22,6 +24,7 @@ class OverViewController extends Controller
{
$counters = Cache::remember('counters', self::TTL, function () {
$output = collect();
+ //Set basic variables in the collection
$output->put('users', User::query()->count());
$output->put('credits', number_format(User::query()->where("role","!=","admin")->sum('credits'), 2, '.', ''));
$output->put('payments', Payment::query()->count());
@@ -29,6 +32,7 @@ class OverViewController extends Controller
$output->put('nests', Nest::query()->count());
$output->put('locations', Location::query()->count());
+ //Prepare for counting
$output->put('servers', collect());
$output['servers']->active = 0;
$output['servers']->total = 0;
@@ -36,6 +40,41 @@ class OverViewController extends Controller
$output['earnings']->active = 0;
$output['earnings']->total = 0;
$output->put('totalUsagePercent', 0);
+
+ //Prepare subCollection 'payments'
+ $output->put('payments', collect());
+ //Get and save payments from last 2 months for later filtering and looping
+ $payments = Payment::query()->where('created_at', '>=', Carbon::today()->startOfMonth()->subMonth())->where('status', 'paid')->get();
+ //Prepare collections and set a few variables
+ $output['payments']->put('thisMonth', collect());
+ $output['payments']->put('lastMonth', collect());
+ $output['payments']['thisMonth']->timeStart = Carbon::today()->startOfMonth()->toDateString();
+ $output['payments']['thisMonth']->timeEnd = Carbon::today()->toDateString();
+ $output['payments']['lastMonth']->timeStart = Carbon::today()->startOfMonth()->subMonth()->toDateString();
+ $output['payments']['lastMonth']->timeEnd = Carbon::today()->endOfMonth()->subMonth()->toDateString();
+
+ //Fill out variables for each currency separately
+ foreach($payments->where('created_at', '>=', Carbon::today()->startOfMonth()) as $payment){
+ $paymentCurrency = $payment->currency_code;
+ if(!isset($output['payments']['thisMonth'][$paymentCurrency])){
+ $output['payments']['thisMonth']->put($paymentCurrency, collect());
+ $output['payments']['thisMonth'][$paymentCurrency]->total = 0;
+ $output['payments']['thisMonth'][$paymentCurrency]->count = 0;
+ }
+ $output['payments']['thisMonth'][$paymentCurrency]->total += $payment->total_price;
+ $output['payments']['thisMonth'][$paymentCurrency]->count ++;
+ }
+ foreach($payments->where('created_at', '<', Carbon::today()->startOfMonth()) as $payment){
+ $paymentCurrency = $payment->currency_code;
+ if(!isset($output['payments']['lastMonth'][$paymentCurrency])){
+ $output['payments']['lastMonth']->put($paymentCurrency, collect());
+ $output['payments']['lastMonth'][$paymentCurrency]->total = 0;
+ $output['payments']['lastMonth'][$paymentCurrency]->count = 0;
+ }
+ $output['payments']['lastMonth'][$paymentCurrency]->total += $payment->total_price;
+ $output['payments']['lastMonth'][$paymentCurrency]->count ++;
+ }
+ $output['payments']->total = Payment::query()->count();
return $output;
});
@@ -80,11 +119,40 @@ class OverViewController extends Controller
return $output;
});
+ $tickets = Cache::remember('tickets', self::TTL, function(){
+ $output = collect();
+ foreach(Ticket::query()->latest()->take(3)->get() as $ticket){
+ $output->put($ticket->ticket_id, collect());
+ $output[$ticket->ticket_id]->title = $ticket->title;
+ $user = User::query()->where('id', $ticket->user_id)->first();
+ $output[$ticket->ticket_id]->user_id = $user->id;
+ $output[$ticket->ticket_id]->user = $user->name;
+ $output[$ticket->ticket_id]->status = $ticket->status;
+ $output[$ticket->ticket_id]->last_updated = $ticket->updated_at->diffForHumans();
+ switch ($ticket->status) {
+ case 'Open':
+ $output[$ticket->ticket_id]->statusBadgeColor = 'badge-success';
+ break;
+ case 'Closed':
+ $output[$ticket->ticket_id]->statusBadgeColor = 'badge-danger';
+ break;
+ case 'Answered':
+ $output[$ticket->ticket_id]->statusBadgeColor = 'badge-info';
+ break;
+ default:
+ $output[$ticket->ticket_id]->statusBadgeColor = 'badge-warning';
+ break;
+ }
+ }
+ return $output;
+ });
+ //dd($counters);
return view('admin.overview.index', [
'counters' => $counters,
'nodes' => $nodes,
'syncLastUpdate' => $syncLastUpdate,
- 'perPageLimit' => ($counters['servers']->total != Server::query()->count())?true:false
+ 'perPageLimit' => ($counters['servers']->total != Server::query()->count())?true:false,
+ 'tickets' => $tickets
]);
}
diff --git a/resources/views/admin/overview/index.blade.php b/resources/views/admin/overview/index.blade.php
index fa9c9124..d7c70c7e 100644
--- a/resources/views/admin/overview/index.blade.php
+++ b/resources/views/admin/overview/index.blade.php
@@ -90,7 +90,7 @@
{{__('Payments')}}
- {{$counters['payments']}}
+ {{$counters['payments']->total}}
@@ -142,6 +142,42 @@
{{__('Last updated :date', ['date' => $syncLastUpdate])}}
+
+
+
+ @if(!$tickets->count())
{{__('There are no tickets')}}.
+ @else
+
+
+
+ {{__('Title')}} |
+ {{__('User')}} |
+ {{__('Status')}} |
+ {{__('Last updated')}} |
+
+
+
+
+ @foreach($tickets as $ticket_id => $ticket)
+
+ #{{$ticket_id}} - {{$ticket->title}} |
+ {{$ticket->user}} |
+ {{$ticket->status}} |
+ {{$ticket->last_updated}} |
+
+ @endforeach
+
+
+
+ @endif
+
+
+
+
+
+
+
+
{{__('Last month')}}:
+
+
+
+
+
+ {{__('Currency')}} |
+ {{__('Number of payments')}} |
+ {{__('Total income')}} |
+
+
+
+ @foreach($counters['payments']['lastMonth'] as $currency => $income)
+
+ {{$currency}} |
+ {{$income->count}} |
+ {{$income->total}} |
+
+ @endforeach
+
+
+
+
+
{{__('This month')}}:
+
+
+
+
+
+ {{__('Currency')}} |
+ {{__('Number of payments')}} |
+ {{__('Total income')}} |
+
+
+
+ @foreach($counters['payments']['thisMonth'] as $currency => $income)
+
+ {{$currency}} |
+ {{$income->count}} |
+ {{$income->total}} |
+
+ @endforeach
+
+
+
+
+
+
+
+
diff --git a/resources/views/moderator/ticket/show.blade.php b/resources/views/moderator/ticket/show.blade.php
index 22bd2ea1..f6a309f2 100644
--- a/resources/views/moderator/ticket/show.blade.php
+++ b/resources/views/moderator/ticket/show.blade.php
@@ -51,11 +51,13 @@
@endif
Created on: {{ $ticket->created_at->diffForHumans() }}
+ @if($ticket->status!='Closed')
+ @endif