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\Member\MemberResource ;
use App\Payment\Payment ;
use App\Payment\PaymentResource ;
2021-07-04 23:27:00 +02:00
use App\Payment\Status ;
use App\Payment\Subscription ;
2021-08-23 01:26:46 +02:00
use Illuminate\Http\Request ;
2021-07-04 23:27:00 +02:00
class HomeView {
public function index ( Request $request ) {
$amount = Payment :: whereNeedsPayment () -> selectRaw ( 'sum(subscriptions.amount) AS a' ) -> join ( 'subscriptions' , 'subscriptions.id' , 'payments.subscription_id' ) -> first () -> a ;
$members = Member :: whereHasPendingPayment () -> count ();
return [
'data' => [
'payments' => [
'users' => $members ,
'all_users' => Member :: count (),
'amount' => number_format ( $amount / 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 ()),
2021-07-04 23:27:00 +02:00
]
];
}
}