Merge pull request #571 from ok236449/development-2

More information on admin overview
This commit is contained in:
Dennis 2022-08-20 22:36:40 +02:00 committed by GitHub
commit d738803f14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 174 additions and 3 deletions

View file

@ -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
]);
}

View file

@ -90,7 +90,7 @@
<div class="info-box-content">
<span class="info-box-text">{{__('Payments')}}</span>
<span class="info-box-number">{{$counters['payments']}}</span>
<span class="info-box-number">{{$counters['payments']->total}}</span>
</div>
<!-- /.info-box-content -->
</div>
@ -142,6 +142,42 @@
<span><i class="fas fa-sync mr-2"></i>{{__('Last updated :date', ['date' => $syncLastUpdate])}}</span>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="d-flex justify-content-between">
<div class="card-title ">
<span><i class="fas fa-ticket-alt mr-2"></i>{{__('Latest tickets')}}</span>
</div>
</div>
</div>
<div class="card-body py-1">
@if(!$tickets->count())<span style="font-size: 16px; font-weight:700">{{__('There are no tickets')}}.</span>
@else
<table class="table">
<thead>
<tr>
<th>{{__('Title')}}</th>
<th>{{__('User')}}</th>
<th>{{__('Status')}}</th>
<th>{{__('Last updated')}}</th>
</tr>
</thead>
<tbody>
@foreach($tickets as $ticket_id => $ticket)
<tr>
<td><a class="text-info" href="{{route('moderator.ticket.show', ['ticket_id' => $ticket_id])}}">#{{$ticket_id}} - {{$ticket->title}}</td>
<td><a href="{{route('admin.users.show', $ticket->user_id)}}">{{$ticket->user}}</a></td>
<td><span class="badge {{$ticket->statusBadgeColor}}">{{$ticket->status}}</span></td>
<td>{{$ticket->last_updated}}</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
</div>
<div class="card">
<div class="card-header">
<div class="d-flex justify-content-between">
@ -163,7 +199,7 @@
<div class="card-header">
<div class="d-flex justify-content-between">
<div class="card-title ">
<span><i class="fas fa-file-invoice-dollar mr-2"></i>{{__('Individual nodes')}}</span>
<span><i class="fas fa-server mr-2"></i>{{__('Individual nodes')}}</span>
</div>
</div>
</div>
@ -209,6 +245,71 @@
</table>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="d-flex justify-content-between">
<div class="card-title ">
<span><i class="fas fa-file-invoice-dollar mr-2"></i>{{__('Latest payments')}}</span>
</div>
</div>
</div>
<div class="card-body py-1">
<div class="row">
<div class="col-md-6" style="border-right:1px solid #6c757d">
<span style="margin:auto; display:table; font-size: 18px; font-weight:700">{{__('Last month')}}:
<i data-toggle="popover" data-trigger="hover" data-html="true"
data-content="{{ __('Payments in this time window') }}:<br>{{$counters['payments']['lastMonth']->timeStart}} - {{$counters['payments']['lastMonth']->timeEnd}}"
class="fas fa-info-circle"></i>
</span>
<table class="table">
<thead>
<tr>
<th><b>{{__('Currency')}}</b></th>
<th>{{__('Number of payments')}}</th>
<th>{{__('Total income')}}</th>
</tr>
</thead>
<tbody>
@foreach($counters['payments']['lastMonth'] as $currency => $income)
<tr>
<td>{{$currency}}</td>
<td>{{$income->count}}</td>
<td>{{$income->total}}</td>
</tr>
@endforeach
</tbody>
</table>
<hr style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-top: -16px">
</div><div class="col-md-6">
<span style="margin:auto; display:table; font-size: 18px; font-weight:700">{{__('This month')}}:
<i data-toggle="popover" data-trigger="hover" data-html="true"
data-content="{{ __('Payments in this time window') }}:<br>{{$counters['payments']['thisMonth']->timeStart}} - {{$counters['payments']['thisMonth']->timeEnd}}"
class="fas fa-info-circle"></i>
</span>
<table class="table">
<thead>
<tr>
<th><b>{{__('Currency')}}</b></th>
<th>{{__('Number of payments')}}</th>
<th>{{__('Total income')}}</th>
</tr>
</thead>
<tbody>
@foreach($counters['payments']['thisMonth'] as $currency => $income)
<tr>
<td>{{$currency}}</td>
<td>{{$income->count}}</td>
<td>{{$income->total}}</td>
</tr>
@endforeach
</tbody>
</table>
<hr style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-top: -16px">
</div>
</div>
</div>
</div>
</div>
</div>

View file

@ -51,11 +51,13 @@
@endif
</p>
<p><b>Created on:</b> {{ $ticket->created_at->diffForHumans() }}</p>
@if($ticket->status!='Closed')
<form class="d-inline" method="post" action="{{route('moderator.ticket.close', ['ticket_id' => $ticket->ticket_id ])}}">
{{csrf_field()}}
{{method_field("POST") }}
<button data-content="{{__("Close")}}" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-times"></i>{{__("Close")}}</button>
</form>
@endif
</div>
</div>
</div>