@extends('super_admin.layouts.master') @section('title', 'Reports & Billing') @section('page_title', 'Financial Reports & Invoicing') @section('content')

Total Schools

{{ $schools->count() }}

Total Revenue

₹{{ number_format($summary['total_revenue'] ?? 0) }}

₹

Total GST Collected

₹{{ number_format($summary['total_gst'] ?? 0) }}

Total Invoices

{{ $summary['total_transactions'] ?? 0 }}

@if(request('school_id') && $selectedSchool)
{{ substr($selectedSchool->name, 0, 1) }}

{{ $selectedSchool->name }}

{{ $selectedSchool->email }} | {{ $selectedSchool->phone }}

{{ ucfirst($selectedSchool->plan) }} Plan Expires: {{ $selectedSchool->subscription_end->format('M d, Y') }}

Total Spent

₹{{ number_format($schoolTotalSpent) }}

@endif @if(!request('school_id'))

Schools by Plan

@php $hasData = !empty($planRevenue) && array_sum($planRevenue) > 0; $maxCount = !empty($planRevenue) ? max($planRevenue) : 0; $totalSchools = array_sum($planRevenue); @endphp @if($hasData)
@foreach($planRevenue as $plan => $count) @php $percentage = $totalSchools > 0 ? ($count / $totalSchools * 100) : 0; // Scale bar height relative to max count (max 180px) $barHeight = $maxCount > 0 ? ($count / $maxCount * 180) : 0; $barHeight = max($barHeight, 4); // Minimum 4px visibility // Different color for each plan $colors = [ 'basic' => 'from-gray-400 to-gray-500', 'standard' => 'from-blue-400 to-blue-600', 'premium' => 'from-purple-400 to-purple-600' ]; $colorClass = $colors[$plan] ?? 'from-blue-400 to-blue-600'; @endphp
{{ $count }} Schools
{{ number_format($percentage, 1) }}% of total

{{ ucfirst($plan) }}

{{ $count }} Schools

@endforeach
@else

No school data available

Schools will appear here when subscriptions are created

@endif
@endif
This Month Last Month This Year All Time

@if(request('school_id')) Subscription History: {{ $selectedSchool->name }} @else All Subscription History @endif

@if(request('school_id')) View School @endif
@forelse($histories as $history) @empty @endforelse
Sr. Invoice # School Plan Period Duration Amount Status Actions
{{ $loop->iteration }} @if($history->invoice) {{ $history->invoice->invoice_number }} @else Draft @endif
{{ $history->school ? substr($history->school->name, 0, 1) : '?' }}

{{ $history->school ? $history->school->name : 'Unknown School' }}

{{ $history->school ? $history->school->email : 'ID: ' . $history->school_id }}

{{ ucfirst($history->plan) }} @if($history->action !== 'created' && $history->action !== 'renewed') {{ ucfirst($history->action) }} @endif

{{ $history->start_date->format('M d, Y') }}

to {{ $history->end_date->format('M d, Y') }}

{{ $history->duration_months }} month(s) @php // 🆕 Get actual invoice amount if invoice exists, else fall back to plan amount $invoice = \App\Models\Invoice::where('subscription_history_id', $history->id)->first(); $displayAmount = $invoice ? $invoice->total_amount : $history->amount; $displayGst = $invoice ? $invoice->gst_amount : ($history->amount * 0.18); @endphp

₹{{ number_format($displayAmount, 2) }}

@if($displayAmount > 0)

GST: ₹{{ number_format($displayGst, 2) }}

@endif
{{ $history->school ? ucfirst($history->school->status) : 'Unknown' }}
@if($history->school) @php $invoice = \App\Models\Invoice::where('subscription_history_id', $history->id)->first(); $paymentCount = \App\Models\Payment::where('subscription_history_id', $history->id)->count(); $hasInvoice = !is_null($invoice); $hasPayments = $paymentCount > 0; $isFullyPaid = $invoice && $invoice->is_locked; $hasPartialPayment = $invoice && !$invoice->is_locked && $paymentCount > 0; $isCreditNote = $invoice && $invoice->is_credit_note; $isLatest = \App\Models\SubscriptionHistory::where('school_id', $history->school_id) ->orderBy('id', 'desc') ->first()?->id === $history->id; $isFirstEntry = \App\Models\SubscriptionHistory::where('school_id', $history->school_id) ->orderBy('id', 'asc') ->first()?->id === $history->id; @endphp @if(!$hasInvoice) @if($isLatest && !$isFirstEntry) @endif @else @if($isCreditNote) CreditNote ₹{{ number_format(abs($invoice->total_amount), 2) }} @php $isConsumed = false; if ($invoice->credit_consumed) { if ($invoice->consumed_by_invoice_id) { $consumingInvoice = \App\Models\Invoice::find($invoice->consumed_by_invoice_id); $isConsumed = !is_null($consumingInvoice); } else { $isConsumed = true; } } $canDeleteCreditNote = !$isConsumed; @endphp @if($canDeleteCreditNote) @else Adjusted @endif @else @if($isFullyPaid) Paid @elseif($hasPartialPayment) @else @endif @if(!$hasPayments) @endif @endif @endif @else N/A @endif

No records found for the selected filters

{{ $histories->links() }}
@endsection @push('scripts') @endpush