@extends('user.user_dashboard')
@section('home')
@php
use Carbon\Carbon;
// Authenticated user
$my_username = auth()->user()->username;
// All users referred by this user
$referredUsers = App\Models\User::where('referred_by', $my_username)->get();
// All users subscriptions referred by this user
$subscriptions = App\Models\Payment::with(['subscription', 'user'])
->where('purpose', 'subscription')
->whereNull('coupon')
->whereHas('user', function ($query) use ($my_username) {
$query->where('referred_by', $my_username);
})
->latest()
->get();
/*
//Monthly sum
$monthlySums = $subscriptions
->groupBy(function ($subscription) {
// Group by month and year: "July 2025", "August 2025", etc.
return Carbon::parse($subscription->created_at)->format('F Y');
})
->map(function ($groupedSubscriptions, $month) {
return [
'month' => $month,
'total' => $groupedSubscriptions->sum('total_amount'),
];
})
->values(); // Optional: to reset keys to 0, 1, 2...
*/
// Monthly sum (converted to Espees)
$monthlySums = $subscriptions
->groupBy(function ($subscription) {
// Group by month and year
return Carbon::parse($subscription->created_at)->format('F Y');
})
->map(function ($groupedSubscriptions, $month) {
// Conversion rates to Espees (per 1 unit of currency)
$conversionRates = [
'ESPEES' => 1,
'ESPEES-VOUCHER' => 1,
'USD' => 1 / 1.25, // 0.8 Espees
'GBP' => 1 / 1, // 1.0 Espee
'CAD' => 1 / 1.7, // 0.588 Espees
'EUR' => 1 / 1.15, // 0.869 Espees
'ZAR' => 1 / 23, // 0.043 Espees
'NGN' => 1 / 2050, // 0.000488 Espees
];
// Convert each payment to Espees before summing
$totalInEspees = $groupedSubscriptions->sum(function ($sub) use ($conversionRates) {
$currency = strtoupper($sub->currency ?? 'ESPEES');
$rate = $conversionRates[$currency] ?? 1;
return $sub->total_amount * $rate;
});
return [
'month' => $month,
'total' => $totalInEspees,
];
})
->values();
@endphp
My Registered Users
{{--
--}}
| s/n |
Name |
Dated Signed up |
Subscription Status |
@foreach ($referredUsers as $key => $user)
@php
$UserSubscription = $user
->subscriptions()
->where('status', 'active')
->where('end_date', '>', now())
->latest()
->first();
@endphp
| {{ $key + 1 }} |
{{ $user->title }} {{ $user->firstname }} {{ $user->surname }} |
{{ $user->created_at->format('F j, Y, g:i A') }} |
@if ($UserSubscription)
Subscribed
@else
Unsubscribed
@endif
|
@endforeach
Users Subscriptions
{{--
--}}
| s/n |
Fullname |
Subscription_Amount |
Subscription_Name |
Subscription_Duration |
Subscription_Date |
@foreach ($subscriptions as $key => $subscription)
| {{ $key + 1 }} |
{{ $subscription->user->title }} {{ $subscription->user->firstname }}
{{ $subscription->user->surname }} |
{{ $subscription->total_amount }} {{ $subscription->currency }} |
{{ $subscription->subscription->subscription_name }} |
{{ $subscription->subscription->subscription_duration }} |
{{ \Carbon\Carbon::parse($subscription->subscription->start_date)->format('Y F jS - h:ia') }}
|
@endforeach
Monthly Commissions
Commission is 30% of Total Users Subscription Amount
{{--
--}}
{{-- --}}
| s/n |
Month |
Total Subscription Amount |
Commission Amount ( 30% ) |
@php $i = 1; @endphp
@foreach ($monthlySums as $summary)
| {{ $i++ }} |
{{ $summary['month'] }} |
{{ number_format($summary['total'], 2) }} Espees |
{{ number_format($summary['total'] * 0.3, 2) }} Espees |
|
@endforeach
@endsection