@php use Carbon\Carbon; // Fetch project from dp_project using request $project = null; $district = request('district'); $project_id = request('dp_project'); if($project_id) { $project = \App\Models\DpProject::find($project_id); } if (!$project && $district) { $project = \App\Models\DpProject::where('district', $district)->first(); } // Get the start year from the project $startYear = $project ? (Carbon::parse($project->start_date)->year ?? null) : null; // Prepare years for columns $years = []; if ($startYear) { $years = [$startYear, $startYear + 1, $startYear + 2]; } else { $years = [null, null, null]; } if($project){ $year_wise_results = \App\Helpers\ProjectHelper :: getDpConsolidatedResults($district, $project->start_date, $project->end_date); } // echo '
'; print_r($year_wise_results); echo '
'; die(); $project_types = ['al', 'asc', 'ict', 'overall']; // Prepare results $results = [ ['label' => 'Decisions', 'field' => 'decisions'], ['label' => 'New Life Members', 'field' => 'new_life_members'], ['label' => 'Hope Cells', 'field' => 'hope_cells'], ['label' => 'Villages Reached', 'field' => 'worship_groups'], ]; @endphp @php $table_colors = [ 'al' => '#ffe0b2', // Soft Orange 'asc' => '#b9f6ca', // Soft Green 'ict' => '#fff9b2', // Soft Yellow 'overall' => '#ef1f7276', // Soft Purple ]; $plannedFieldMap = [ 'al' => ['al_first_year_villages', 'al_second_year_villages', 'al_third_year_villages'], 'asc' => ['asc_first_year_villages', 'asc_second_year_villages', 'asc_third_year_villages'], 'ict' => ['ict_first_year_villages', 'ict_second_year_villages', 'ict_third_year_villages'], 'overall' => ['first_year_villages', 'second_year_villages', 'third_year_villages'], ]; $actualFieldMap = [ 'al' => ['actual_al_first_year_villages', 'actual_al_second_year_villages', 'actual_al_third_year_villages'], 'asc' => ['actual_asc_first_year_villages', 'actual_asc_second_year_villages', 'actual_asc_third_year_villages'], 'ict' => ['actual_ict_first_year_villages', 'actual_ict_second_year_villages', 'actual_ict_third_year_villages'], 'overall' => ['actual_first_year_villages', 'actual_second_year_villages', 'actual_third_year_villages'], ]; @endphp

Overall Impact of {{ AppHelper::dropdown($dp_project_proposal->district, 'districts_all') }} Program

@foreach($project_types as $type) @foreach($results as $i => $result) @php $y1 = $years[0] ? ($year_wise_results[$type][$years[0]][$result['field']] ?? 0) : 0; $y2 = $years[1] ? ($year_wise_results[$type][$years[1]][$result['field']] ?? 0) : 0; $y3 = $years[2] ? ($year_wise_results[$type][$years[2]][$result['field']] ?? 0) : 0; $total = $y1 + $y2 + $y3; @endphp @endforeach @php $pf = $plannedFieldMap[$type]; $af = $actualFieldMap[$type]; $plannedY1 = (int) (optional($project)->{$pf[0]} ?? 0); $plannedY2 = (int) (optional($project)->{$pf[1]} ?? 0); $plannedY3 = (int) (optional($project)->{$pf[2]} ?? 0); $plannedTotal = $plannedY1 + $plannedY2 + $plannedY3; $actualY1 = (int) (optional($project)->{$af[0]} ?? 0); $actualY2 = (int) (optional($project)->{$af[1]} ?? 0); $actualY3 = (int) (optional($project)->{$af[2]} ?? 0); $actualTotal = $actualY1 + $actualY2 + $actualY3; $actualDevY1 = $plannedY1 - $actualY1; $actualDevY2 = $plannedY2 - $actualY2; $actualDevY3 = $plannedY3 - $actualY3; $actualDevTotal = $plannedTotal - $actualTotal; @endphp
{{ strtoupper($type) }} Year Wise Results
S. No Results @if($years[0]) {{ $years[0] }} @else Year 1 @endif @if($years[1]) {{ $years[1] }} @else Year 2 @endif @if($years[2]) {{ $years[2] }} @else Year 3 @endif Total
{{ $i + 1 }} {{ $result['label'] }} {{ $y1 }} {{ $y2 }} {{ $y3 }} {{ $total }}
{{ count($results) + 1 }} Actual Villages Reached {{ $actualY1 }} {{ $actualY2 }} {{ $actualY3 }} {{ $actualTotal }}
{{ count($results) + 2 }} Actual Deviation {{ $actualDevY1 }} {{ $actualDevY2 }} {{ $actualDevY3 }} {{ $actualDevTotal }}
@endforeach