mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 06:51:08 +00:00
Code cleanup.
This commit is contained in:
@@ -33,7 +33,6 @@ use FireflyIII\Support\Http\Controllers\AugumentData;
|
||||
use FireflyIII\Support\Http\Controllers\TransactionCalculation;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
|
||||
/**
|
||||
* Separate controller because many helper functions are shared.
|
||||
@@ -47,13 +46,12 @@ class ExpenseReportController extends Controller
|
||||
|
||||
/** @var AccountRepositoryInterface The account repository */
|
||||
protected $accountRepository;
|
||||
|
||||
/** @var GeneratorInterface Chart generation methods. */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
* ExpenseReportController constructor.
|
||||
*
|
||||
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -73,13 +71,7 @@ class ExpenseReportController extends Controller
|
||||
*
|
||||
* TODO this chart is not multi currency aware.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $expense
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function mainChart(Collection $accounts, Collection $expense, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
@@ -113,27 +105,27 @@ class ExpenseReportController extends Controller
|
||||
// first is always expense account:
|
||||
/** @var Account $exp */
|
||||
$exp = $combination->first();
|
||||
$chartData[$exp->id . '-in'] = [
|
||||
$chartData[$exp->id.'-in'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.income')),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$exp->id . '-out'] = [
|
||||
$chartData[$exp->id.'-out'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.expenses')),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
// total in, total out:
|
||||
$chartData[$exp->id . '-total-in'] = [
|
||||
$chartData[$exp->id.'-total-in'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.sum_of_income')),
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$exp->id . '-total-out'] = [
|
||||
$chartData[$exp->id.'-total-out'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.sum_of_expenses')),
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
@@ -147,7 +139,7 @@ class ExpenseReportController extends Controller
|
||||
|
||||
while ($currentStart < $end) {
|
||||
$currentEnd = clone $currentStart;
|
||||
$currentEnd = $currentEnd->$function(); // @phpstan-ignore-line
|
||||
$currentEnd = $currentEnd->{$function}(); // @phpstan-ignore-line
|
||||
|
||||
// get expenses grouped by opposing name:
|
||||
$expenses = $this->groupByName($this->getExpensesForOpposing($accounts, $all, $currentStart, $currentEnd));
|
||||
@@ -158,10 +150,10 @@ class ExpenseReportController extends Controller
|
||||
// first is always expense account:
|
||||
/** @var Account $exp */
|
||||
$exp = $combination->first();
|
||||
$labelIn = $exp->id . '-in';
|
||||
$labelOut = $exp->id . '-out';
|
||||
$labelSumIn = $exp->id . '-total-in';
|
||||
$labelSumOut = $exp->id . '-total-out';
|
||||
$labelIn = $exp->id.'-in';
|
||||
$labelOut = $exp->id.'-out';
|
||||
$labelSumIn = $exp->id.'-total-in';
|
||||
$labelSumOut = $exp->id.'-total-out';
|
||||
$currentIncome = bcmul($income[$name] ?? '0', '-1');
|
||||
$currentExpense = $expenses[$name] ?? '0';
|
||||
|
||||
@@ -177,6 +169,7 @@ class ExpenseReportController extends Controller
|
||||
$chartData[$labelSumIn]['entries'][$label] = $sumOfIncome[$exp->id];
|
||||
$chartData[$labelSumOut]['entries'][$label] = $sumOfExpense[$exp->id];
|
||||
}
|
||||
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
|
Reference in New Issue
Block a user