diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 10953f2cfa..8a5990da55 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -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. diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php index 3d1f71e4e7..e45fd3b56f 100644 --- a/app/Helpers/Report/ReportHelperInterface.php +++ b/app/Helpers/Report/ReportHelperInterface.php @@ -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; + } diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 022193a759..373bf1968b 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -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); } diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 8f48f151f5..e11b562b3f 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -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' ) ); } diff --git a/resources/lang/en_US/config.php b/resources/lang/en_US/config.php index 18a904a149..1f29d0fee1 100644 --- a/resources/lang/en_US/config.php +++ b/resources/lang/en_US/config.php @@ -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', diff --git a/resources/views/reports/default/month.twig b/resources/views/reports/default/month.twig index 4b7a9401a5..4fd27d79e5 100644 --- a/resources/views/reports/default/month.twig +++ b/resources/views/reports/default/month.twig @@ -22,7 +22,6 @@
{% include 'reports/partials/accounts.twig' %} - {% include 'reports/partials/income-vs-expenses.twig' %}
@@ -33,6 +32,14 @@ {% include 'reports/partials/expenses.twig' %}
+
+
+ {% include 'reports/partials/income-vs-expenses.twig' %} +
+
+ {% include 'reports/partials/tags.twig' %} +
+
diff --git a/resources/views/reports/default/year.twig b/resources/views/reports/default/year.twig index c7551a3c56..09f85cc8e3 100644 --- a/resources/views/reports/default/year.twig +++ b/resources/views/reports/default/year.twig @@ -42,6 +42,11 @@ {% include 'reports/partials/expenses.twig' %}
+
+
+ {% include 'reports/partials/tags.twig' %} +
+
diff --git a/resources/views/reports/partials/tags.twig b/resources/views/reports/partials/tags.twig new file mode 100644 index 0000000000..8c6d2c7e60 --- /dev/null +++ b/resources/views/reports/partials/tags.twig @@ -0,0 +1,16 @@ +{% if tags|length > 0 %} +
+
+

{{ 'tags'|_ }}

+
+
+ {% for tag in tags %} +  {{ tag.tag }}  + {% endfor %} +
+
+ +{% endif %} \ No newline at end of file