@php $headerOption = [ 'title' => 'Sponsorship Details', 'header_buttons' => [], 'filters' => [], 'data' => [] ]; $sponsorship = $sponsorship ?? null; $beneficiary = $sponsorship->beneficiary ?? null; $sponsor = $sponsorship->sponsor ?? null; $installments = $sponsorship->installments ?? collect(); // Calculate statistics $totalMilestones = $installments->count(); $completedMilestones = $installments->whereIn('payment_status', [ \App\Models\Users\SponsorshipInstallment::STATUS_PAID, \App\Models\Users\SponsorshipInstallment::STATUS_APPROVED_AND_RELEASED ])->count(); $totalPaid = $installments->whereIn('payment_status', [ \App\Models\Users\SponsorshipInstallment::STATUS_PAID, \App\Models\Users\SponsorshipInstallment::STATUS_APPROVED_AND_RELEASED ])->sum('installment_amount'); $disputedMilestones = $installments->where('payment_status', \App\Models\Users\SponsorshipInstallment::STATUS_DISPUTE); $disputedCount = $disputedMilestones->count(); // Format offer type $offerTypeMap = [ 1 => 'Endorsement Deal', 2 => 'Brand Ambassador', 3 => 'Team Partnership', 4 => 'Product Sponsorship', 5 => 'Event Sponsor', 6 => 'Media Partnership', ]; $offerTypeName = $sponsorship->offer_type && isset($offerTypeMap[$sponsorship->offer_type]) ? $offerTypeMap[$sponsorship->offer_type] : 'N/A'; // Beneficiary info $beneficiaryName = $beneficiary ? ($beneficiary->full_name ?? $beneficiary->name ?? 'N/A') : 'N/A'; $beneficiaryType = ucfirst($sponsorship->beneficiary_type ?? 'N/A'); $beneficiaryInitials = strtoupper(substr($beneficiaryName, 0, 1) . substr($beneficiaryName, strpos($beneficiaryName, ' ') + 1, 1)); if (strpos($beneficiaryName, ' ') === false) { $beneficiaryInitials = strtoupper(substr($beneficiaryName, 0, 2)); } // Get beneficiary location/organization $beneficiaryLocation = ''; if ($sponsorship->beneficiary_type === 'athlete' && $beneficiary) { $athleteProfile = $beneficiary->athleteProfile; if ($athleteProfile && isset($athleteProfile->organization_name)) { $beneficiaryLocation = $athleteProfile->organization_name; } } elseif ($sponsorship->beneficiary_type === 'team') { $beneficiaryLocation = $sponsorship->team_organization ?? ''; } // Get sport info $sportName = ''; if ($beneficiary && $beneficiary->sports && $beneficiary->sports->count() > 0) { $sport = $beneficiary->sports->first(); $sportName = $sport->sport->title ?? ''; } // Sponsor info $sponsorName = $sponsor ? ($sponsor->full_name ?? $sponsor->name ?? 'N/A') : 'N/A'; // Status $statusClass = 'badge-secondary'; $statusText = ($sponsorship->is_withdrawal == 1) ? 'Withdrawn' : (ucfirst($sponsorship->status ?? 'pending')); if ($sponsorship->status === 'active') { $statusClass = 'badge-success'; } elseif ($sponsorship->status === 'pending') { $statusClass = 'badge-warning'; } elseif (in_array($sponsorship->status, ['declined', 'cancelled', 'withdrawn'])) { $statusClass = 'badge-danger'; } // Calculate percentage for each milestone $totalAmount = $sponsorship->funding_amount ?? 1; @endphp @extends('admin.layouts.layout', $headerOption) @push('page_css') @endpush @section('content')