mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 20:25:28 +00:00
Refactor basic methods to trait
This commit is contained in:
@@ -27,6 +27,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
@@ -36,6 +37,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
*/
|
||||
class IndexController extends Controller
|
||||
{
|
||||
use BasicDataSupport;
|
||||
/** @var AccountRepositoryInterface The account repository */
|
||||
private $repository;
|
||||
|
||||
@@ -119,23 +121,7 @@ class IndexController extends Controller
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the ID in a given array. Return '0' of not there (amount).
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $entryId
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
protected function isInArray(array $array, int $entryId) // helper for data (math, calculations)
|
||||
{
|
||||
$result = '0';
|
||||
if (isset($array[$entryId])) {
|
||||
$result = $array[$entryId];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@@ -36,6 +37,7 @@ use Log;
|
||||
*/
|
||||
class ReportController extends Controller
|
||||
{
|
||||
use BasicDataSupport;
|
||||
/** @var GeneratorInterface Chart generation methods. */
|
||||
protected $generator;
|
||||
|
||||
@@ -219,23 +221,6 @@ class ReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum up an array.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function arraySum(array $array): string // filter + group data
|
||||
{
|
||||
$sum = '0';
|
||||
foreach ($array as $entry) {
|
||||
$sum = bcadd($sum, $entry);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the incomes and expenses for the given periods, grouped per month. Will cache its results.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user