@extends('organizations.layouts.default') @section('content')
@include('organizations.layouts.partials.breadcrumb')
@php $groupedEvaluation = $summary->groupBy('criteria_name'); $tender = $summary->pluck('applications.tenders.title')->unique()->first(); $uniqueApplicants = $summary ->pluck('applications.applicants.name', 'application_id') ->unique(); $uniqueEvaluators = $summary->pluck('evaluators.name', 'evaluator_id')->unique(); $totalFullMarks = $groupedEvaluation->sum(fn($results) => $results->first()->full_marks); $applicantEvaluatorTotals = []; // Calculate average scores for ranking $applicantAverages = []; foreach ($uniqueApplicants as $applicantId => $applicantName) { $applicantTotalMarks = $summary ->where('application_id', $applicantId) ->sum('obtained_marks'); $applicantAverages[$applicantId] = [ 'name' => $applicantName, 'average' => $applicantTotalMarks / $uniqueEvaluators->count(), ]; } $rankedApplicants = collect($applicantAverages)->sortByDesc('average')->values(); @endphp @if ($totalFullMarks > 0)

Evaluation summary of tender " {{ $tender }} " based on the applications

@foreach ($uniqueApplicants as $applicant) @endforeach @foreach ($groupedEvaluation as $criteria => $results) @foreach ($uniqueApplicants as $applicantId => $applicant) @foreach ($uniqueEvaluators as $evaluatorId => $evaluatorName) @php $marks = $results ->where('application_id', $applicantId) ->where('evaluator_id', $evaluatorId) ->first()->obtained_marks ?? 0; $applicantEvaluatorTotals[$applicantId][$evaluatorId] = ($applicantEvaluatorTotals[$applicantId][$evaluatorId] ?? 0) + $marks; @endphp @endforeach @endforeach @endforeach @foreach ($uniqueApplicants as $applicantId => $applicant) @foreach ($uniqueEvaluators as $evaluatorId => $evaluatorName) @endforeach @endforeach {{-- @foreach ($uniqueApplicants as $applicantId => $applicant) @php $avg = $summary ->where('application_id', $applicantId) ->sum('obtained_marks'); $average = $avg / count($uniqueEvaluators); @endphp @endforeach --}} @foreach ($applicantAverages as $index => $applicantData) {{-- --}} @endforeach
S.N Criteria Full Mark

Applicant: {{ $applicant }}

@foreach ($uniqueEvaluators as $evaluatorName)

{{ $evaluatorName }}

@endforeach
{{ nepali_number($loop->iteration) }}. {{ $criteria }} {{ $results->first()->full_marks }} {{ $marks }}
Total {{ $totalFullMarks }} {{ $applicantEvaluatorTotals[$applicantId][$evaluatorId] ?? 0 }}
Average {{ number_format($average, 2) }} {{ number_format($applicantData['average'], 2) }} {{ number_format($applicantData['average'], 2) }}

Rankings of Applicants based on their obtained marks

@php $previousAverage = null; // Variable to store the previous applicant's average @endphp @foreach ($rankedApplicants as $index => $applicantData) @php $previousAverage = $applicantData['average']; @endphp @endforeach
Rank Applicant Average Marks Recommended
{{ $index + 1 }} {{ $applicantData['name'] }} {{ number_format($applicantData['average'], 2) }} @if ($index + 1 == 1 || $applicantData['average'] == $previousAverage) @endif
@else

Evaluation Criteria not set, so all details included in summary !!!

@endif
@isset($uniqueApplicants) @foreach ($uniqueApplicants as $key => $applicantName)
Summary of applicant {{ $applicantName }}:
@foreach ($uniqueEvaluators as $evaluatorId => $evaluatorName)

{{ $loop->index + 1 }}. {{ $evaluatorName }}:

{!! $summary->where('application_id', $key)->where('evaluator_id', $evaluatorId)->unique('summary')->first()->summary ?? '' !!}
@endforeach
@endforeach @else

evaluation not done

@endisset
@endsection