@extends('layouts.vertical', ['page_title' => 'SBM Goal & Proficiency Tracking']) @section('css') @endsection @section('content') @php $submissionsArr = $response->data->submissions ?? []; // Flatten array of month-objects into [ 'YYYY-MM' => (object goals=>arrays) ] $byMonth = []; foreach ($submissionsArr as $item) { foreach ((array) $item as $month => $payload) { $byMonth[$month] = (object) $payload; } } // Months sorted ascending (YYYY-MM) $months = array_keys($byMonth); sort($months, SORT_STRING); // Fixed proficiency order $ratings = ['Proficient', 'Competent', 'Intermediate', 'Beginner']; // Helper: safe fetch count for a given goal/month/label function goalCount($byMonth, $month, $goalName, $label) { if (!isset($byMonth[$month]) || !isset($byMonth[$month]->{$goalName})) return 0; $rows = $byMonth[$month]->{$goalName}; $sum = 0; foreach ($rows as $row) { if (($row->goal_value ?? null) === $label) { $sum += (int) ($row->user_count ?? 0); } } return $sum; } @endphp
| SBM/ME Goals | @foreach ($months as $month){{ preg_match('/^\d{4}-\d{2}$/', $month) ? \Carbon\Carbon::createFromFormat('Y-m', $month)->format('M-y') : $month }} | @endforeach|||
|---|---|---|---|---|
| {{ $r }} | @endforeach @endforeach||||
| Goal {{ $loop->iteration }}: {{ $goalName }}* | @foreach ($months as $month) @foreach ($ratings as $r){{ goalCount($byMonth, $month, $goalName, $r) }} | @endforeach @endforeach|||