mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Refactor various methods away from controllers
This commit is contained in:
@@ -27,6 +27,7 @@ use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Throwable;
|
||||
@@ -36,6 +37,7 @@ use Throwable;
|
||||
*/
|
||||
class BudgetController extends Controller
|
||||
{
|
||||
use BasicDataSupport;
|
||||
|
||||
/**
|
||||
* Show partial overview of budgets.
|
||||
@@ -97,7 +99,7 @@ class BudgetController extends Controller
|
||||
$budgets = $repository->getBudgets();
|
||||
$data = $repository->getBudgetPeriodReport($budgets, $accounts, $start, $end);
|
||||
$data[0] = $repository->getNoBudgetPeriodReport($accounts, $start, $end); // append report data for "no budget"
|
||||
$report = $this->filterBudgetPeriodReport($data);
|
||||
$report = $this->filterPeriodReport($data);
|
||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||
try {
|
||||
$result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
|
||||
@@ -110,30 +112,4 @@ class BudgetController extends Controller
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters empty results from getBudgetPeriodReport.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function filterBudgetPeriodReport(array $data): array // helper function for period overview.
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @var array $set
|
||||
*/
|
||||
foreach ($data as $budgetId => $set) {
|
||||
$sum = '0';
|
||||
foreach ($set['entries'] as $amount) {
|
||||
$sum = bcadd($amount, $sum);
|
||||
}
|
||||
$data[$budgetId]['sum'] = $sum;
|
||||
if (0 === bccomp('0', $sum)) {
|
||||
unset($data[$budgetId]);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user