Autoformat lol

This commit is contained in:
James Cole
2026-01-23 15:09:50 +01:00
parent ae1347c550
commit 8f15a32bd6
1071 changed files with 21111 additions and 21687 deletions
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -36,6 +35,7 @@ use FireflyIII\Support\Http\Controllers\BasicDataSupport;
use FireflyIII\Support\Report\Budget\BudgetReportGenerator;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
use Throwable;
@@ -54,13 +54,11 @@ class BudgetController extends Controller
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->middleware(function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class);
return $next($request);
}
);
return $next($request);
});
}
/**
@@ -82,9 +80,9 @@ class BudgetController extends Controller
$generator->setEnd($end);
$generator->accountPerBudget();
$report = $generator->getReport();
$report = $generator->getReport();
return view('reports.budget.partials.account-per-budget', ['report' => $report, 'budgets' => $budgets]);
return view('reports.budget.partials.account-per-budget', ['report' => $report, 'budgets' => $budgets]);
}
/**
@@ -99,12 +97,7 @@ class BudgetController extends Controller
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$report[$accountId] ??= [
'name' => $account->name,
'id' => $account->id,
'iban' => $account->iban,
'currencies' => [],
];
$report[$accountId] ??= ['name' => $account->name, 'id' => $account->id, 'iban' => $account->iban, 'currencies' => []];
}
// loop expenses.
@@ -115,28 +108,28 @@ class BudgetController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'sum' => '0',
'sum' => '0'
];
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'sum' => '0',
'sum' => '0'
];
$report[$sourceAccountId]['currencies'][$currencyId]['sum'] = bcadd(
$report[$sourceAccountId]['currencies'][$currencyId]['sum'],
(string) $journal['amount']
);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], (string) $journal['amount']);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], (string) $journal['amount']);
}
}
}
return view('reports.budget.partials.accounts', ['sums' => $sums, 'report' => $report]);
return view('reports.budget.partials.accounts', ['sums' => $sums, 'report' => $report]);
}
/**
@@ -146,13 +139,13 @@ class BudgetController extends Controller
*/
public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
@@ -163,11 +156,11 @@ class BudgetController extends Controller
'currency_id' => $currency['currency_id'],
'currency_name' => $currency['currency_name'],
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'currency_decimal_places' => $currency['currency_decimal_places']
];
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd((string) $journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
$result[$key]['sum'] = bcadd((string) $journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
$result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float
}
}
@@ -202,11 +195,7 @@ class BudgetController extends Controller
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budgetId = $budget->id;
$report[$budgetId] ??= [
'name' => $budget->name,
'id' => $budget->id,
'currencies' => [],
];
$report[$budgetId] ??= ['name' => $budget->name, 'id' => $budget->id, 'currencies' => []];
}
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
@@ -215,7 +204,7 @@ class BudgetController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'sum' => '0',
'sum' => '0'
];
/** @var array $budget */
@@ -230,10 +219,13 @@ class BudgetController extends Controller
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'currency_decimal_places' => $currency['currency_decimal_places']
];
$report[$budgetId]['currencies'][$currencyId]['sum'] = bcadd($report[$budgetId]['currencies'][$currencyId]['sum'], (string) $journal['amount']);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], (string) $journal['amount']);
$report[$budgetId]['currencies'][$currencyId]['sum'] = bcadd(
$report[$budgetId]['currencies'][$currencyId]['sum'],
(string) $journal['amount']
);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], (string) $journal['amount']);
}
}
}
@@ -241,9 +233,9 @@ class BudgetController extends Controller
// loop again to get percentages.
foreach ($report as $budgetId => $data) {
foreach ($data['currencies'] as $currencyId => $dataX) {
$sum = $dataX['sum'];
$total = $sums[$currencyId]['sum'] ?? '0';
$pct = '0';
$sum = $dataX['sum'];
$total = $sums[$currencyId]['sum'] ?? '0';
$pct = '0';
if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) {
$pct = round((float) bcmul(bcdiv($sum, $total), '100')); // intentional float
}
@@ -251,7 +243,7 @@ class BudgetController extends Controller
}
}
return view('reports.budget.partials.budgets', ['sums' => $sums, 'report' => $report]);
return view('reports.budget.partials.budgets', ['sums' => $sums, 'report' => $report]);
}
/**
@@ -272,7 +264,7 @@ class BudgetController extends Controller
$generator->setEnd($end);
$generator->general();
$report = $generator->getReport();
$report = $generator->getReport();
return view('reports.partials.budgets', ['report' => $report])->render();
}
@@ -286,7 +278,7 @@ class BudgetController extends Controller
*/
public function period(Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('budget-period-report');
@@ -299,9 +291,9 @@ class BudgetController extends Controller
$keyFormat = Navigation::preferredCarbonFormat($start, $end);
// list expenses for budgets in account(s)
$expenses = $this->opsRepository->listExpenses($start, $end, $accounts);
$expenses = $this->opsRepository->listExpenses($start, $end, $accounts);
$report = [];
$report = [];
foreach ($expenses as $currency) {
foreach ($currency['budgets'] as $budget) {
$count = 0;
@@ -315,12 +307,10 @@ class BudgetController extends Controller
continue;
}
++$count;
$key = sprintf('%d-%d', $budget['id'], $currency['currency_id']);
$dateKey = $journal['date']->format($keyFormat);
$report[$key] ??= [
$key = sprintf('%d-%d', $budget['id'], $currency['currency_id']);
$dateKey = $journal['date']->format($keyFormat);
$report[$key] ??= [
'id' => $budget['id'],
'name' => sprintf('%s (%s)', $budget['name'], $currency['currency_name']),
'sum' => '0',
@@ -329,18 +319,18 @@ class BudgetController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'entries' => [],
'entries' => []
];
$report[$key]['entries'][$dateKey] ??= '0';
$report[$key]['entries'][$dateKey] = bcadd((string) $journal['amount'], $report[$key]['entries'][$dateKey]);
$report[$key]['sum'] = bcadd($report[$key]['sum'], (string) $journal['amount']);
$report[$key]['avg'] = bcdiv($report[$key]['sum'], (string) count($periods));
$report[$key]['sum'] = bcadd($report[$key]['sum'], (string) $journal['amount']);
$report[$key]['avg'] = bcdiv($report[$key]['sum'], (string) count($periods));
}
}
}
try {
$result = view('reports.partials.budget-period', ['report' => $report, 'periods' => $periods])->render();
$result = view('reports.partials.budget-period', ['report' => $report, 'periods' => $periods])->render();
} catch (Throwable $e) {
Log::error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
Log::error($e->getTraceAsString());
@@ -361,15 +351,15 @@ class BudgetController extends Controller
*/
public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$result[] = [
'description' => $journal['description'],
'transaction_group_id' => $journal['transaction_group_id'],
'amount_float' => (float) $journal['amount'], // intentional float
'description' => $journal['description'],
'transaction_group_id' => $journal['transaction_group_id'],
'amount_float' => (float) $journal['amount'], // intentional float
'amount' => $journal['amount'],
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
'date_sort' => $journal['date']->format('Y-m-d'),
@@ -380,7 +370,7 @@ class BudgetController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'budget_id' => $budget['id'],
'budget_name' => $budget['name'],
'budget_name' => $budget['name']
];
}
}