@extends('admin.admin_dashboard') @section('admin') @php /* //old logic for subscription commission use Carbon\Carbon; $subscriptions = App\Models\Payment::with(['subscription', 'user']) ->where('purpose', 'subscription') ->where(function ($query) { $query ->where(function ($q) { $q->where('coupon', 'CCM')->where('created_at', '>', Carbon::parse('2025-06-30')->endOfDay()); }) ->orWhere(function ($q) { $q->whereNull('coupon') ->where('created_at', '>', Carbon::parse('2025-06-30')->endOfDay()) ->whereHas('user', function ($u) { $u->where('zone', 'CCM'); }); }); }) ->latest() ->get(); $monthlySums = $subscriptions ->groupBy(function ($item) { return Carbon::parse($item->created_at)->format('F Y'); }) ->map(function ($items, $month) { return [ 'month' => $month, 'total' => $items->sum('total_amount'), ]; }); */ @endphp @php use Carbon\Carbon; $subscriptions = App\Models\Payment::with(['subscription', 'user']) ->where('purpose', 'subscription') ->where(function ($query) { $query ->where(function ($q) { $q->where('coupon', 'CCM')->where('created_at', '>', Carbon::parse('2025-06-30')->endOfDay()); }) ->orWhere(function ($q) { $q->whereNull('coupon') ->where('created_at', '>', Carbon::parse('2025-06-30')->endOfDay()) ->whereHas('user', function ($u) { $u->where('zone', 'CCM'); }); }); }) ->latest() ->get(); // Conversion rates to Espees (per 1 unit of currency) <-- added this block $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 ]; $monthlySums = $subscriptions ->groupBy(function ($item) { return Carbon::parse($item->created_at)->format('F Y'); }) ->map(function ($items, $month) use ($conversionRates) { // <-- passed $conversionRates into closure return [ 'month' => $month, // Convert each payment’s total_amount to Espees before summing <-- updated this line 'total' => $items->sum(function ($payment) use ($conversionRates) { $currency = strtoupper($payment->currency ?? 'ESPEES'); // handle missing currency safely $rate = $conversionRates[$currency] ?? 1; // default to 1 if unknown return $payment->total_amount * $rate; // convert to Espees }), ]; }); @endphp @php /* // old purchase logic $purchases = App\Models\Payment::with(['user', 'purchase', 'orders']) ->whereIn('purpose', ['ebook purchase', 'print book purchase']) ->where(function ($query) { $query->where(function ($q) { $q->where('coupon', 'CCM') ->where('created_at', '>', Carbon::parse('2025-06-30')->endOfDay()); })->orWhere(function ($q) { $q->whereNull('coupon') ->where('created_at', '>', Carbon::parse('2025-06-30')->endOfDay()) ->whereHas('user', function ($u) { $u->where('zone', 'CCM'); }); }); }) ->latest() ->get(); $purchaseMonthlySums = $purchases->groupBy(function ($item) { return Carbon::parse($item->created_at)->format('F Y'); })->map(function ($items, $month) { return [ 'month' => $month, 'total' => $items->sum(function ($purchase) { return $purchase->purpose === 'print book purchase' ? $purchase->total_amount * 0.75 : $purchase->total_amount; }), ]; }); */ @endphp

Subscription Commissions

Total Commission [30%] = Net Commission [25%] + Coupon Code Discount [5%]

{{--
--}} @php $i = 1; @endphp @foreach ($monthlySums as $summary) @endforeach
s/n Month Total Subscription Amount Net Commission Amount ( 25% )
{{ $i++ }} {{ $summary['month'] }} {{ number_format($summary['total'], 2) }} Espees {{ number_format($summary['total'] * 0.25, 2) }} Espees
{{-- @if (Auth::user()->can('ccm.purchase'))

Purchase Commissions

Commission [5%]

@php $i = 1; @endphp @foreach ($purchaseMonthlySums as $summary) @endforeach
s/n Month Total Purchase Amount Net Commission Amount ( 5 % )
{{ $i++ }} {{ $summary['month'] }} {{ number_format($summary['total'], 2) }} Espees {{ number_format($summary['total'] * 0.05, 2) }} Espees
@endif --}}
@endsection