diff --git a/app/Services/FinancialCategorySummaryService.php b/app/Services/FinancialCategorySummaryService.php index 5834cdd..acadbae 100644 --- a/app/Services/FinancialCategorySummaryService.php +++ b/app/Services/FinancialCategorySummaryService.php @@ -26,6 +26,10 @@ final class FinancialCategorySummaryService continue; } + if (strcasecmp($category, 'Purchase') === 0) { + $category = 'Expense'; + } + $expenseCategories[$category] = round(($expenseCategories[$category] ?? 0) + $amount, 2); $totalExpenses += $amount; } diff --git a/app/Views/administrator/stats.php b/app/Views/administrator/stats.php index d21bdbb..19dffa4 100644 --- a/app/Views/administrator/stats.php +++ b/app/Views/administrator/stats.php @@ -404,7 +404,7 @@ $canViewFinancialStats = (bool) ($canViewFinancialStats ?? false); pie('studentGenderChart', data.gender, [palette.blue,palette.orange], data.totalStudents); pie('academicResultsChart', data.results, [palette.green,palette.red,palette.slate], data.totalStudents); - pie('topPerformersChart', data.topGender, [palette.blue,palette.orange], data.totalStudents, 'Other students'); + pie('topPerformersChart', data.topGender, [palette.blue,palette.orange], data.totalStudents, 'Not classified as top performers'); new Chart(document.getElementById('classSizeChart'), { type:'bar', diff --git a/tests/app/Services/FinancialCategorySummaryServiceTest.php b/tests/app/Services/FinancialCategorySummaryServiceTest.php index b74f38b..e29277a 100644 --- a/tests/app/Services/FinancialCategorySummaryServiceTest.php +++ b/tests/app/Services/FinancialCategorySummaryServiceTest.php @@ -21,4 +21,17 @@ class FinancialCategorySummaryServiceTest extends CIUnitTestCase $this->assertSame(['Books' => 125.50, 'Office Supplies' => 75.0], $summary['expenseCategories']); $this->assertArrayNotHasKey('Donation', $summary['expenseCategories']); } + + public function testPurchasesAreIncludedInExpenseCategory(): void + { + $summary = FinancialCategorySummaryService::summarize([ + ['category' => 'Expense', 'amount' => 350], + ['category' => 'Purchase', 'amount' => 25.50], + ['category' => 'purchase', 'amount' => 10], + ]); + + $this->assertSame(385.50, $summary['totalExpenses']); + $this->assertSame(['Expense' => 385.50], $summary['expenseCategories']); + $this->assertArrayNotHasKey('Purchase', $summary['expenseCategories']); + } }