mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
Tag report.
This commit is contained in:
parent
701d7baca8
commit
01be5e3e23
@ -11,6 +11,7 @@ use FireflyIII\Helpers\Collection\Expense;
|
||||
use FireflyIII\Helpers\Collection\Income;
|
||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
@ -217,6 +218,63 @@ class ReportHelper implements ReportHelperInterface
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of tags and their comparitive size with amounts bla bla.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tagReport(Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
bcscale(2);
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$set = Tag::
|
||||
distinct()
|
||||
->leftJoin('tag_transaction_journal', 'tags.id', '=', 'tag_transaction_journal.tag_id')
|
||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
->whereIn('transactions.account_id', $ids)->get(['tags.id', 'tags.tag', 'transactions.amount']);
|
||||
$collection = [];
|
||||
if ($set->count() === 0) {
|
||||
return $collection;
|
||||
}
|
||||
foreach ($set as $entry) {
|
||||
// less than zero? multiply to be above zero.
|
||||
$amount = $entry->amount;
|
||||
if (bccomp($amount, '0', 2) === -1) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
$id = intval($entry->id);
|
||||
|
||||
if (!isset($collection[$id])) {
|
||||
$collection[$id] = [
|
||||
'id' => $id,
|
||||
'tag' => $entry->tag,
|
||||
'amount' => $amount,
|
||||
];
|
||||
} else {
|
||||
$collection[$id]['amount'] = bcadd($collection[$id]['amount'], $amount);
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup collection (match "fonts")
|
||||
$max = strval(max(array_column($collection, 'amount')));
|
||||
foreach ($collection as $id => $entry) {
|
||||
$size = bcdiv($entry['amount'], $max, 4);
|
||||
if (bccomp($size, '0.25') === -1) {
|
||||
$size = '0.5';
|
||||
}
|
||||
$collection[$id]['fontsize'] = $size;
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
|
@ -70,4 +70,15 @@ interface ReportHelperInterface
|
||||
*/
|
||||
public function listOfMonths(Carbon $date);
|
||||
|
||||
/**
|
||||
* Returns an array of tags and their comparitive size with amounts bla bla.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tagReport(Carbon $start, Carbon $end, Collection $accounts): array;
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
/** @var string */
|
||||
protected $dateTimeFormat;
|
||||
/** @var string */
|
||||
protected $monthAndDayFormat;
|
||||
/** @var string */
|
||||
@ -43,6 +45,7 @@ class Controller extends BaseController
|
||||
$lang = $pref->data;
|
||||
$this->monthFormat = (string)trans('config.month');
|
||||
$this->monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$this->dateTimeFormat = (string)trans('config.date_time');
|
||||
|
||||
App::setLocale($lang);
|
||||
Carbon::setLocale(substr($lang, 0, 2));
|
||||
@ -61,6 +64,7 @@ class Controller extends BaseController
|
||||
];
|
||||
View::share('monthFormat', $this->monthFormat);
|
||||
View::share('monthAndDayFormat', $this->monthAndDayFormat);
|
||||
View::share('dateTimeFormat', $this->dateTimeFormat);
|
||||
View::share('language', $lang);
|
||||
View::share('localeconv', $localeconv);
|
||||
}
|
||||
|
@ -161,6 +161,7 @@ class ReportController extends Controller
|
||||
$categories = $this->helper->getCategoryReport($start, $end, $accounts);
|
||||
$balance = $this->balanceHelper->getBalanceReport($start, $end, $accounts);
|
||||
$bills = $this->helper->getBillReport($start, $end, $accounts);
|
||||
$tags = $this->helper->tagReport($start, $end, $accounts);
|
||||
|
||||
// and some id's, joined:
|
||||
$accountIds = join(',', $accounts->pluck('id')->toArray());
|
||||
@ -170,7 +171,7 @@ class ReportController extends Controller
|
||||
'reports.default.month',
|
||||
compact(
|
||||
'start', 'end', 'reportType',
|
||||
'accountReport',
|
||||
'accountReport', 'tags',
|
||||
'incomes', 'incomeTopLength',
|
||||
'expenses', 'expenseTopLength',
|
||||
'budgets', 'balance',
|
||||
@ -234,6 +235,7 @@ class ReportController extends Controller
|
||||
$accountReport = $this->accountHelper->getAccountReport($start, $end, $accounts);
|
||||
$incomes = $this->helper->getIncomeReport($start, $end, $accounts);
|
||||
$expenses = $this->helper->getExpenseReport($start, $end, $accounts);
|
||||
$tags = $this->helper->tagReport($start, $end, $accounts);
|
||||
|
||||
Session::flash('gaEventCategory', 'report');
|
||||
Session::flash('gaEventAction', 'year');
|
||||
@ -251,7 +253,7 @@ class ReportController extends Controller
|
||||
'reports.default.year',
|
||||
compact(
|
||||
'start', 'accountReport', 'incomes', 'reportType', 'accountIds', 'end',
|
||||
'expenses', 'incomeTopLength', 'expenseTopLength'
|
||||
'expenses', 'incomeTopLength', 'expenseTopLength','tags'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ return [
|
||||
'locale' => 'en, English, en_US, en_US.utf8',
|
||||
'month' => '%B %Y',
|
||||
'month_and_day' => '%B %e, %Y',
|
||||
'date_time' => '%B %e, %Y, @ %T',
|
||||
'specific_day' => '%e %B %Y',
|
||||
'week_in_year' => 'Week %W, %Y',
|
||||
'quarter_of_year' => '%B %Y',
|
||||
|
@ -22,7 +22,6 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||
{% include 'reports/partials/accounts.twig' %}
|
||||
{% include 'reports/partials/income-vs-expenses.twig' %}
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3 col-sm-3">
|
||||
<!-- income -->
|
||||
@ -33,6 +32,14 @@
|
||||
{% include 'reports/partials/expenses.twig' %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||
{% include 'reports/partials/income-vs-expenses.twig' %}
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||
{% include 'reports/partials/tags.twig' %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-md-8 col-sm-12">
|
||||
<!-- budgets -->
|
||||
|
@ -42,6 +42,11 @@
|
||||
{% include 'reports/partials/expenses.twig' %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||
{% include 'reports/partials/tags.twig' %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
|
16
resources/views/reports/partials/tags.twig
Normal file
16
resources/views/reports/partials/tags.twig
Normal file
@ -0,0 +1,16 @@
|
||||
{% if tags|length > 0 %}
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'tags'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{% for tag in tags %}
|
||||
<span title="{{ tag.amount|formatAmountPlain }}"
|
||||
style="font-size: {{ tag.fontsize * 30 }}px"
|
||||
|
||||
> <a href="{{ route('tags.show', tag.id) }}">{{ tag.tag }}</a> </span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
Loading…
Reference in New Issue
Block a user