2021-07-04 23:27:00 +02:00
< ? php
namespace App\Http\Views ;
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
],
'groups' => Member :: select ( 'subactivities.slug' , 'subactivities.name' ) -> selectRaw ( 'COUNT(members.id) AS count' ) -> join ( 'memberships' , 'memberships.member_id' , 'members.id' )
-> join ( 'activities' , 'memberships.activity_id' , 'activities.id' )
-> join ( 'subactivities' , 'memberships.subactivity_id' , 'subactivities.id' )
-> where ( 'subactivities.is_age_group' , true )
-> where ( 'activities.is_member' , true )
-> groupBy ( 'subactivities.name' , 'subactivities.slug' )
-> orderBy ( 'subactivities.id' )
2021-08-23 01:59:53 +02:00
-> get (),
'ending_tries' => MemberTriesResource :: collection ( Member :: endingTries () -> get ()),
2022-03-11 20:19:17 +01:00
],
2021-07-04 23:27:00 +02:00
];
}
}