add new ststs feature
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 51s
Tests / PHPUnit (push) Successful in 1m25s

This commit is contained in:
root
2026-09-13 02:20:14 -04:00
parent 1787144f27
commit c3a30989b2
16 changed files with 1395 additions and 84 deletions
@@ -0,0 +1,41 @@
<?php
namespace App\Services;
final class FinancialCategorySummaryService
{
/**
* Classify grouped rows from the legacy expenses table by accounting meaning.
* Donation rows are incoming funds, not school expenses.
*/
public static function summarize(array $rows): array
{
$expenseCategories = [];
$totalExpenses = 0.0;
$donationIncome = 0.0;
foreach ($rows as $row) {
$category = trim((string) ($row['category'] ?? '')) ?: 'Uncategorized';
$amount = round((float) ($row['amount'] ?? $row['total_amount'] ?? 0), 2);
if ($amount <= 0) {
continue;
}
if (strcasecmp($category, 'Donation') === 0) {
$donationIncome += $amount;
continue;
}
$expenseCategories[$category] = round(($expenseCategories[$category] ?? 0) + $amount, 2);
$totalExpenses += $amount;
}
arsort($expenseCategories, SORT_NUMERIC);
return [
'totalExpenses' => round($totalExpenses, 2),
'donationIncome' => round($donationIncome, 2),
'expenseCategories' => $expenseCategories,
];
}
}