adrema/app/Http/Views/HomeView.php

31 lines
970 B
PHP
Raw Normal View History

2021-07-04 23:27:00 +02:00
<?php
namespace App\Http\Views;
2022-11-16 22:04:37 +01:00
use App\Home\Queries\GroupQuery;
2021-07-04 23:27:00 +02:00
use App\Member\Member;
2021-08-23 01:26:46 +02:00
use App\Payment\Payment;
use Illuminate\Http\Request;
2021-07-04 23:27:00 +02:00
2022-03-11 20:19:17 +01:00
class HomeView
{
2022-02-12 16:16:56 +01:00
public function index(Request $request): array
{
2022-01-02 12:32:57 +01:00
/** @var object{a: string} */
$amount = Payment::whereNeedsPayment()->selectRaw('sum(subscriptions.amount) AS a')->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')->first();
2021-07-04 23:27:00 +02:00
$members = Member::whereHasPendingPayment()->count();
return [
'data' => [
'payments' => [
'users' => $members,
'all_users' => Member::count(),
2022-03-11 20:19:17 +01:00
'amount' => number_format($amount->a / 100, 2, ',', '.').' €',
2021-08-23 01:26:46 +02:00
],
2022-11-16 22:04:37 +01:00
'groups' => app(GroupQuery::class)->execute()->getResult(),
2021-08-23 01:59:53 +02:00
'ending_tries' => MemberTriesResource::collection(Member::endingTries()->get()),
2022-03-11 20:19:17 +01:00
],
2021-07-04 23:27:00 +02:00
];
}
}