Code cleanup that (hopefully) matches style CI

This commit is contained in:
James Cole
2020-03-17 15:01:00 +01:00
parent bd2f064eeb
commit 2b6c3fd743
110 changed files with 2060 additions and 1660 deletions

View File

@@ -59,6 +59,7 @@ class AccountController extends Controller
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
@@ -116,10 +117,10 @@ class AccountController extends Controller
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int)$accountId;
$accountId = (int) $accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int)$currencyId;
$currencyId = (int) $currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
@@ -131,7 +132,7 @@ class AccountController extends Controller
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => $diff,
'diff_float' => (float)$diff,
'diff_float' => (float) $diff,
'currency_id' => $currencyId,
];
}
@@ -144,13 +145,13 @@ class AccountController extends Controller
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
$dataSet
= [
'label' => (string)trans('firefly.spent'),
'label' => (string) trans('firefly.spent'),
'type' => 'bar',
'currency_symbol' => $currency->symbol,
'entries' => $this->expandNames($tempData),
@@ -171,28 +172,12 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* Expenses per budget for all time, as shown on account overview.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseBudget($account, $start, $end);
}
/**
* Expenses per budget, as shown on account overview.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@@ -215,7 +200,7 @@ class AccountController extends Controller
$budgetIds = [];
/** @var array $journal */
foreach ($journals as $journal) {
$budgetId = (int)$journal['budget_id'];
$budgetId = (int) $journal['budget_id'];
$key = sprintf('%d-%d', $budgetId, $journal['currency_id']);
$budgetIds[] = $budgetId;
if (!isset($result[$key])) {
@@ -234,7 +219,7 @@ class AccountController extends Controller
foreach ($result as $row) {
$budgetId = $row['budget_id'];
$name = $names[$budgetId];
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
}
@@ -245,27 +230,27 @@ class AccountController extends Controller
}
/**
* Expenses grouped by category for account.
* Expenses per budget for all time, as shown on account overview.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
* @param Account $account
*
* @return JsonResponse
*/
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseCategory($account, $start, $end);
return $this->expenseBudget($account, $start, $end);
}
/**
* Expenses per category for one single account.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@@ -283,9 +268,9 @@ class AccountController extends Controller
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::WITHDRAWAL]);
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
/** @var array $journal */
foreach ($journals as $journal) {
@@ -293,7 +278,7 @@ class AccountController extends Controller
if (!isset($result[$key])) {
$result[$key] = [
'total' => '0',
'category_id' => (int)$journal['category_id'],
'category_id' => (int) $journal['category_id'],
'currency_name' => $journal['currency_name'],
'currency_symbol' => $journal['currency_symbol'],
];
@@ -305,7 +290,7 @@ class AccountController extends Controller
foreach ($result as $row) {
$categoryId = $row['category_id'];
$name = $names[$categoryId] ?? '(unknown)';
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
}
@@ -315,6 +300,22 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* Expenses grouped by category for account.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseCategory($account, $start, $end);
}
/**
* Shows the balances for all the user's frontpage accounts.
*
@@ -341,28 +342,12 @@ class AccountController extends Controller
return response()->json($this->accountBalanceChart($accounts, $start, $end));
}
/**
* Shows the income grouped by category for an account, in all time.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->incomeCategory($account, $start, $end);
}
/**
* Shows all income per account for each category.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@@ -382,9 +367,9 @@ class AccountController extends Controller
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::DEPOSIT]);
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
/** @var array $journal */
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
@@ -403,7 +388,7 @@ class AccountController extends Controller
foreach ($result as $row) {
$categoryId = $row['category_id'];
$name = $names[$categoryId] ?? '(unknown)';
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
@@ -412,15 +397,31 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* Shows the income grouped by category for an account, in all time.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->incomeCategory($account, $start, $end);
}
/**
* Shows overview of account during a single period.
*
* TODO this chart is not multi-currency aware.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $start
*
* @param Carbon $end
* @param Carbon $end
*
* @return JsonResponse
*/
@@ -440,14 +441,14 @@ class AccountController extends Controller
$current = clone $start;
switch ($step) {
case '1D':
$format = (string)trans('config.month_and_day');
$format = (string) trans('config.month_and_day');
$range = app('steam')->balanceInRange($account, $start, $end);
$previous = array_values($range)[0];
while ($end >= $current) {
$theDate = $current->format('Y-m-d');
$balance = $range[$theDate] ?? $previous;
$label = $current->formatLocalized($format);
$chartData[$label] = (float)$balance;
$chartData[$label] = (float) $balance;
$previous = $balance;
$current->addDay();
}
@@ -457,7 +458,7 @@ class AccountController extends Controller
case '1M':
case '1Y':
while ($end >= $current) {
$balance = (float)app('steam')->balance($account, $current);
$balance = (float) app('steam')->balance($account, $current);
$label = app('navigation')->periodShow($current, $step);
$chartData[$label] = $balance;
$current = app('navigation')->addPeriod($current, $step, 0);
@@ -476,8 +477,8 @@ class AccountController extends Controller
*
* TODO this chart is not multi-currency aware.
*
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return JsonResponse
@@ -525,10 +526,10 @@ class AccountController extends Controller
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int)$accountId;
$accountId = (int) $accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int)$currencyId;
$currencyId = (int) $currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
@@ -540,7 +541,7 @@ class AccountController extends Controller
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => $diff,
'diff_float' => (float)$diff,
'diff_float' => (float) $diff,
'currency_id' => $currencyId,
];
}
@@ -553,13 +554,13 @@ class AccountController extends Controller
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
$dataSet
= [
'label' => (string)trans('firefly.earned'),
'label' => (string) trans('firefly.earned'),
'type' => 'bar',
'currency_symbol' => $currency->symbol,
'entries' => $this->expandNames($tempData),

View File

@@ -42,6 +42,7 @@ class BillController extends Controller
/**
* BillController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
@@ -79,12 +80,12 @@ class BillController extends Controller
foreach ($paid as $currencyId => $amount) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);
$label = (string)trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$label = (string) trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol];
}
foreach ($unpaid as $currencyId => $amount) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);
$label = (string)trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$label = (string) trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol];
}
@@ -116,18 +117,21 @@ class BillController extends Controller
$journals = $collector->setBill($bill)->getExtractedJournals();
// sort the other way around:
usort($journals, static function (array $left, array $right) {
return $left['date']->gte($right['date'])? 1 : 0;
});
usort(
$journals,
static function (array $left, array $right) {
return $left['date']->gte($right['date']) ? 1 : 0;
}
);
$chartData = [
['type' => 'line', 'label' => (string)trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
['type' => 'line', 'label' => (string)trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
['type' => 'bar', 'label' => (string)trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
['type' => 'line', 'label' => (string) trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
['type' => 'line', 'label' => (string) trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
['type' => 'bar', 'label' => (string) trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
];
foreach ($journals as $journal) {
$date = $journal['date']->formatLocalized((string)trans('config.month_and_day'));
$date = $journal['date']->formatLocalized((string) trans('config.month_and_day'));
$chartData[0]['entries'][$date] = $bill->amount_min; // minimum amount of bill
$chartData[1]['entries'][$date] = $bill->amount_max; // maximum amount of bill

View File

@@ -27,9 +27,9 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@@ -104,11 +104,11 @@ class BudgetController extends Controller
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
}
$step = $this->calculateStep($start, $end); // depending on diff, do something with range of chart.
$collection = new Collection([$budget]);
$chartData = [];
$loopStart = clone $start;
$loopStart = app('navigation')->startOfPeriod($loopStart, $step);
$step = $this->calculateStep($start, $end); // depending on diff, do something with range of chart.
$collection = new Collection([$budget]);
$chartData = [];
$loopStart = clone $start;
$loopStart = app('navigation')->startOfPeriod($loopStart, $step);
$currencies = [];
$defaultEntries = [];
// echo '<hr>';
@@ -135,10 +135,10 @@ class BudgetController extends Controller
// loop all currencies:
foreach ($currencies as $currencyId => $currency) {
$chartData[$currencyId] = [
'label' => count($currencies) > 1 ? sprintf('%s (%s)', $budget->name, $currency['currency_name']) : $budget->name,
'type' => 'bar',
'label' => count($currencies) > 1 ? sprintf('%s (%s)', $budget->name, $currency['currency_name']) : $budget->name,
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
'entries' => $defaultEntries,
'entries' => $defaultEntries,
];
foreach ($currency['spent'] as $label => $spent) {
$chartData[$currencyId]['entries'][$label] = round(bcmul($spent, '-1'), $currency['currency_decimal_places']);
@@ -157,9 +157,9 @@ class BudgetController extends Controller
* @param Budget $budget
* @param BudgetLimit $budgetLimit
*
* @throws FireflyException
* @return JsonResponse
*
* @throws FireflyException
*/
public function budgetLimit(Budget $budget, BudgetLimit $budgetLimit): JsonResponse
{
@@ -186,12 +186,12 @@ class BudgetController extends Controller
while ($start <= $end) {
$spent = $this->opsRepository->spentInPeriod($budgetCollection, new Collection, $start, $start);
$amount = bcadd($amount, $spent);
$format = $start->formatLocalized((string)trans('config.month_and_day'));
$format = $start->formatLocalized((string) trans('config.month_and_day'));
$entries[$format] = $amount;
$start->addDay();
}
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
$data = $this->generator->singleSet((string) trans('firefly.left'), $entries);
// add currency symbol from budget limit:
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
$cache->store($data);
@@ -211,7 +211,7 @@ class BudgetController extends Controller
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
$cache = new CacheProperties;
$cache->addProperty($budget->id);
@@ -238,7 +238,7 @@ class BudgetController extends Controller
// group by asset account ID:
foreach ($journals as $journal) {
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
$key = sprintf('%d-%d', (int) $journal['source_account_id'], $journal['currency_id']);
$result[$key] = $result[$key] ?? [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
@@ -250,7 +250,7 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$assetId = (int)$parts[0];
$assetId = (int) $parts[0];
$title = sprintf('%s (%s)', $names[$assetId] ?? '(empty)', $info['currency_name']);
$chartData[$title]
= [
@@ -277,7 +277,7 @@ class BudgetController extends Controller
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
$cache = new CacheProperties;
$cache->addProperty($budget->id);
@@ -314,7 +314,7 @@ class BudgetController extends Controller
$names = $this->getCategoryNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$categoryId = (int)$parts[0];
$categoryId = (int) $parts[0];
$title = sprintf('%s (%s)', $names[$categoryId] ?? '(empty)', $info['currency_name']);
$chartData[$title] = [
'amount' => $info['amount'],
@@ -340,7 +340,7 @@ class BudgetController extends Controller
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
$cache = new CacheProperties;
$cache->addProperty($budget->id);
@@ -379,7 +379,7 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$opposingId = (int)$parts[0];
$opposingId = (int) $parts[0];
$name = $names[$opposingId] ?? 'no name';
$title = sprintf('%s (%s)', $name, $info['currency_name']);
$chartData[$title] = [
@@ -418,9 +418,9 @@ class BudgetController extends Controller
}
$budgets = $this->repository->getActiveBudgets();
$chartData = [
['label' => (string)trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'],
['label' => (string)trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'],
['label' => (string)trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'],
['label' => (string) trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'],
['label' => (string) trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'],
['label' => (string) trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'],
];
/** @var Budget $budget */
@@ -440,14 +440,20 @@ class BudgetController extends Controller
/** @var BudgetLimit $limit */
foreach ($limits as $limit) {
$spent = $this->opsRepository->sumExpenses(
$limit->start_date, $limit->end_date, null, new Collection([$budget]), $limit->transactionCurrency
$limit->start_date,
$limit->end_date,
null,
new Collection([$budget]),
$limit->transactionCurrency
);
/** @var array $entry */
foreach ($spent as $entry) {
$title = sprintf('%s (%s)', $budget->name, $entry['currency_name']);
if ($limit->start_date->startOfDay()->ne($start->startOfDay()) || $limit->end_date->startOfDay()->ne($end->startOfDay())) {
$title = sprintf(
'%s (%s) (%s - %s)', $budget->name, $entry['currency_name'],
'%s (%s) (%s - %s)',
$budget->name,
$entry['currency_name'],
$limit->start_date->formatLocalized($this->monthAndDayFormat),
$limit->end_date->formatLocalized($this->monthAndDayFormat)
);
@@ -498,13 +504,13 @@ class BudgetController extends Controller
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$chartData = [
[
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
'type' => 'bar',
'entries' => [],
'currency_symbol' => $currency->symbol,
],
[
'label' => (string)trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
'label' => (string) trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
'type' => 'bar',
'currency_symbol' => $currency->symbol,
'entries' => [],
@@ -513,9 +519,9 @@ class BudgetController extends Controller
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentStart= app('navigation')->startOfPeriod($currentStart, $preferredRange);
$title = $currentStart->formatLocalized($titleFormat);
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange);
$title = $currentStart->formatLocalized($titleFormat);
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
// default limit is no limit:
$chartData[0]['entries'][$title] = 0;
@@ -582,11 +588,9 @@ class BudgetController extends Controller
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
$data = $this->generator->singleSet((string) trans('firefly.spent'), $chartData);
$cache->store($data);
return response()->json($data);
}
}

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @noinspection MoreThanThreeArgumentsInspection */
/** @noinspection MoreThanThreeArgumentsInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;
@@ -118,8 +118,6 @@ class BudgetReportController extends Controller
// loop expenses.
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
@@ -157,8 +155,6 @@ class BudgetReportController extends Controller
// loop expenses.
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$title = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
$result[$title] = $result[$title] ?? [
@@ -199,7 +195,9 @@ class BudgetReportController extends Controller
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.spent_in_specific_budget', ['budget' => $budget->name]), $currency['currency_name']
'%s (%s)',
(string) trans('firefly.spent_in_specific_budget', ['budget' => $budget->name]),
$currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
@@ -240,8 +238,6 @@ class BudgetReportController extends Controller
// loop expenses.
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$title = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
$result[$title] = $result[$title] ?? [
@@ -282,5 +278,4 @@ class BudgetReportController extends Controller
return $return;
}
}

View File

@@ -191,7 +191,7 @@ class CategoryController extends Controller
/** @var array $currency */
foreach ($currencies as $currency) {
$dataSet = [
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currency['currency_name']),
'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currency['currency_name']),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
'entries' => $this->expandNames($tempData),
@@ -353,7 +353,7 @@ class CategoryController extends Controller
if (null !== $category) {
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
$categoryId = (int)$category->id;
$categoryId = (int) $category->id;
// this gives us all currencies
$collection = new Collection([$category]);
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
@@ -372,7 +372,7 @@ class CategoryController extends Controller
$inKey = sprintf('%d-in', $currencyId);
$chartData[$outKey]
= [
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currencyInfo['currency_name']),
'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currencyInfo['currency_name']),
'entries' => [],
'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
@@ -380,7 +380,7 @@ class CategoryController extends Controller
$chartData[$inKey]
= [
'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']),
'label' => sprintf('%s (%s)', (string) trans('firefly.earned'), $currencyInfo['currency_name']),
'entries' => [],
'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green

View File

@@ -316,7 +316,9 @@ class CategoryReportController extends Controller
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.spent_in_specific_category', ['category' => $category->name]), $currency['currency_name']
'%s (%s)',
(string) trans('firefly.spent_in_specific_category', ['category' => $category->name]),
$currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
@@ -340,7 +342,9 @@ class CategoryReportController extends Controller
$spentKey = sprintf('%d-earned', $currency['currency_id']);
$chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.earned_in_specific_category', ['category' => $category->name]), $currency['currency_name']
'%s (%s)',
(string) trans('firefly.earned_in_specific_category', ['category' => $category->name]),
$currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
@@ -457,5 +461,4 @@ class CategoryReportController extends Controller
return $return;
}
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Http\Controllers\Controller;
@@ -196,7 +195,9 @@ class DoubleReportController extends Controller
$chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.spent_in_specific_double', ['account' => $name]), $currency['currency_name']
'%s (%s)',
(string) trans('firefly.spent_in_specific_double', ['account' => $name]),
$currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
@@ -210,7 +211,6 @@ class DoubleReportController extends Controller
$chartData[$spentKey]['entries'][$key] = $chartData[$spentKey]['entries'][$key] ?? '0';
$chartData[$spentKey]['entries'][$key] = bcadd($chartData[$spentKey]['entries'][$key], $amount);
}
}
// loop income.
foreach ($earned as $currency) {
@@ -220,7 +220,9 @@ class DoubleReportController extends Controller
$chartData[$earnedKey] = $chartData[$earnedKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.earned_in_specific_double', ['account' => $name]), $currency['currency_name']
'%s (%s)',
(string) trans('firefly.earned_in_specific_double', ['account' => $name]),
$currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
@@ -242,7 +244,6 @@ class DoubleReportController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $others
@@ -275,7 +276,6 @@ class DoubleReportController extends Controller
];
$amount = app('steam')->positive($journal['amount']);
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
}
// loop each tag:
/** @var array $tag */
@@ -334,7 +334,6 @@ class DoubleReportController extends Controller
];
$amount = app('steam')->positive($journal['amount']);
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
}
// loop each tag:
/** @var array $tag */
@@ -364,10 +363,10 @@ class DoubleReportController extends Controller
/**
* TODO this method is double.
*
* @param Collection $accounts
* @param int $id
* @param string $name
* @param null|string $iban
* @param Collection $accounts
* @param int $id
* @param string $name
* @param null|string $iban
*
* @return string
*/
@@ -410,6 +409,4 @@ class DoubleReportController extends Controller
return $return;
}
}
}

View File

@@ -49,6 +49,7 @@ class ExpenseReportController extends Controller
/**
* ExpenseReportController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
@@ -72,8 +73,8 @@ class ExpenseReportController extends Controller
*
* @param Collection $accounts
* @param Collection $expense
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*
@@ -87,7 +88,7 @@ class ExpenseReportController extends Controller
$cache->addProperty($start);
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get()); // @codeCoverageIgnore
}
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
@@ -103,7 +104,7 @@ class ExpenseReportController extends Controller
// prep chart data:
/**
* @var string $name
* @var string $name
* @var Collection $combination
*/
foreach ($combined as $name => $combination) {
@@ -111,27 +112,27 @@ class ExpenseReportController extends Controller
/** @var Account $exp */
$exp = $combination->first();
$chartData[$exp->id . '-in'] = [
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.income'))),
'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.income'))),
'type' => 'bar',
'yAxisID' => 'y-axis-0',
'entries' => [],
];
$chartData[$exp->id . '-out'] = [
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.expenses'))),
'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.expenses'))),
'type' => 'bar',
'yAxisID' => 'y-axis-0',
'entries' => [],
];
// total in, total out:
$chartData[$exp->id . '-total-in'] = [
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_income'))),
'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.sum_of_income'))),
'type' => 'line',
'fill' => false,
'yAxisID' => 'y-axis-1',
'entries' => [],
];
$chartData[$exp->id . '-total-out'] = [
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_expenses'))),
'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.sum_of_expenses'))),
'type' => 'line',
'fill' => false,
'yAxisID' => 'y-axis-1',

View File

@@ -44,6 +44,7 @@ class PiggyBankController extends Controller
/**
* PiggyBankController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
@@ -98,7 +99,7 @@ class PiggyBankController extends Controller
}
);
$currentSum = $filtered->sum('amount');
$label = $oldest->formatLocalized((string)trans('config.month_and_day'));
$label = $oldest->formatLocalized((string) trans('config.month_and_day'));
$chartData[$label] = $currentSum;
$oldest = app('navigation')->addPeriod($oldest, $step, 0);
}
@@ -109,7 +110,7 @@ class PiggyBankController extends Controller
}
);
$finalSum = $finalFiltered->sum('amount');
$finalLabel = $today->formatLocalized((string)trans('config.month_and_day'));
$finalLabel = $today->formatLocalized((string) trans('config.month_and_day'));
$chartData[$finalLabel] = $finalSum;
$data = $this->generator->singleSet($piggyBank->name, $chartData);

View File

@@ -110,7 +110,7 @@ class ReportController extends Controller
/** @var array $netWorthItem */
foreach ($result as $netWorthItem) {
$currencyId = $netWorthItem['currency']->id;
$label = $current->formatLocalized((string)trans('config.month_and_day'));
$label = $current->formatLocalized((string) trans('config.month_and_day'));
if (!isset($chartData[$currencyId])) {
$chartData[$currencyId] = [
'label' => 'Net worth in ' . $netWorthItem['currency']->name,
@@ -138,7 +138,7 @@ class ReportController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function operations(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
@@ -152,10 +152,10 @@ class ReportController extends Controller
return response()->json($cache->get()); // @codeCoverageIgnore
}
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray());
$format = app('navigation')->preferredCarbonFormat($start, $end);
$titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$format = app('navigation')->preferredCarbonFormat($start, $end);
$titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$ids = $accounts->pluck('id')->toArray();
$ids = $accounts->pluck('id')->toArray();
// get journals for entire period:
$data = [];
@@ -173,13 +173,13 @@ class ReportController extends Controller
/** @var array $journal */
foreach ($journals as $journal) {
$period = $journal['date']->format($format);
$currencyId = (int)$journal['currency_id'];
$currencyId = (int) $journal['currency_id'];
$data[$currencyId] = $data[$currencyId] ?? [
'currency_id' => $currencyId,
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
'currency_name' => $journal['currency_name'],
'currency_decimal_places' => (int)$journal['currency_decimal_places'],
'currency_decimal_places' => (int) $journal['currency_decimal_places'],
];
$data[$currencyId][$period] = $data[$currencyId][$period] ?? [
'period' => $period,
@@ -211,7 +211,7 @@ class ReportController extends Controller
/** @var array $currency */
foreach ($data as $currency) {
$income = [
'label' => (string)trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]),
'label' => (string) trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
'currency_id' => $currency['currency_id'],
@@ -219,7 +219,7 @@ class ReportController extends Controller
'entries' => [],
];
$expense = [
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
'currency_id' => $currency['currency_id'],
@@ -234,7 +234,7 @@ class ReportController extends Controller
$title = $currentStart->formatLocalized($titleFormat);
$income['entries'][$title] = round($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
$expense['entries'][$title] = round($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}
$chartData[] = $income;

View File

@@ -264,7 +264,9 @@ class TagReportController extends Controller
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.spent_in_specific_tag', ['tag' => $tag->tag]), $currency['currency_name']
'%s (%s)',
(string) trans('firefly.spent_in_specific_tag', ['tag' => $tag->tag]),
$currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
@@ -288,7 +290,9 @@ class TagReportController extends Controller
$spentKey = sprintf('%d-earned', $currency['currency_id']);
$chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.earned_in_specific_tag', ['tag' => $tag->tag]), $currency['currency_name']
'%s (%s)',
(string) trans('firefly.earned_in_specific_tag', ['tag' => $tag->tag]),
$currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
@@ -475,5 +479,4 @@ class TagReportController extends Controller
return $return;
}
}

View File

@@ -21,7 +21,6 @@
namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
@@ -29,6 +28,7 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties;
use Illuminate\Http\JsonResponse;
/**
* Class TransactionController
@@ -53,8 +53,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
* @return JsonResponse
*/
public function budgets(Carbon $start, Carbon $end)
{
@@ -79,7 +79,7 @@ class TransactionController extends Controller
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$budget = $journal['budget_name'] ?? (string)trans('firefly.no_budget');
$budget = $journal['budget_name'] ?? (string) trans('firefly.no_budget');
$title = sprintf('%s (%s)', $budget, $journal['currency_symbol']);
// key => [value => x, 'currency_symbol' => 'x']
$data[$title] = $data[$title] ?? [
@@ -108,8 +108,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
* @return JsonResponse
*/
public function categories(string $objectType, Carbon $start, Carbon $end)
{
@@ -146,7 +146,7 @@ class TransactionController extends Controller
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$category = $journal['category_name'] ?? (string)trans('firefly.no_category');
$category = $journal['category_name'] ?? (string) trans('firefly.no_category');
$title = sprintf('%s (%s)', $category, $journal['currency_symbol']);
// key => [value => x, 'currency_symbol' => 'x']
$data[$title] = $data[$title] ?? [
@@ -175,8 +175,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
* @return JsonResponse
*/
public function destinationAccounts(string $objectType, Carbon $start, Carbon $end)
{
@@ -213,8 +213,8 @@ class TransactionController extends Controller
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$name = $journal['destination_account_name'];
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
$name = $journal['destination_account_name'];
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
$data[$title] = $data[$title] ?? [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
@@ -241,8 +241,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
* @return JsonResponse
*/
public function sourceAccounts(string $objectType, Carbon $start, Carbon $end)
{
@@ -279,8 +279,8 @@ class TransactionController extends Controller
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$name = $journal['source_account_name'];
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
$name = $journal['source_account_name'];
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
$data[$title] = $data[$title] ?? [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
@@ -301,5 +301,4 @@ class TransactionController extends Controller
return response()->json($chart);
}
}
}