Skip to content

Firefly III: a personal finances manager

Some cleaning up in the reports. [skip ci]

James Cole3be1cdb24927
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index a032068318..56deca08ec 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -361,36 +361,8 @@ class Report implements ReportInterface
*/
public function revenueGroupedByAccount(Carbon $start, Carbon $end, $limit = 15)
{
- return \TransactionJournal::
- leftJoin(
- 'transactions as t_from', function (JoinClause $join) {
- $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
- }
- )
- ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
- ->leftJoin(
- 'account_meta as acm_from', function (JoinClause $join) {
- $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
- }
- )
- ->leftJoin(
- 'transactions as t_to', function (JoinClause $join) {
- $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
- }
- )
- ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
- ->leftJoin(
- 'account_meta as acm_to', function (JoinClause $join) {
- $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
- }
- )
- ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->where('transaction_types.type', 'Deposit')
- ->where('acm_to.data', '!=', '"sharedExpense"')
- ->before($end)->after($start)
- ->where('transaction_journals.user_id', \Auth::user()->id)
- ->groupBy('t_from.account_id')->orderBy('sum')->limit(15)
- ->get(['t_from.account_id as account_id', 'ac_from.name as name', \DB::Raw('SUM(t_from.amount) as `sum`')]);
+ return $this->_queries->journalsByRevenueAccount($start, $end);
+
}
diff --git a/app/lib/FireflyIII/Report/ReportQuery.php b/app/lib/FireflyIII/Report/ReportQuery.php
index 23d8113363..1a143cbb44 100644
--- a/app/lib/FireflyIII/Report/ReportQuery.php
+++ b/app/lib/FireflyIII/Report/ReportQuery.php
@@ -3,9 +3,9 @@
namespace FireflyIII\Report;
use Carbon\Carbon;
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
-use Illuminate\Database\Eloquent\Builder;
/**
* Class ReportQuery
@@ -319,6 +319,48 @@ class ReportQuery implements ReportQueryInterface
->get(['t_to.account_id as id', 'ac_to.name as name', \DB::Raw('SUM(t_to.amount) as `amount`')]);
}
+ /**
+ * This method returns all deposits into asset accounts, grouped by the revenue account,
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function journalsByRevenueAccount(Carbon $start, Carbon $end)
+ {
+ return \TransactionJournal::
+ leftJoin(
+ 'transactions as t_from', function (JoinClause $join) {
+ $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
+ }
+ )
+ ->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
+ ->leftJoin(
+ 'account_meta as acm_from', function (JoinClause $join) {
+ $join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
+ }
+ )
+ ->leftJoin(
+ 'transactions as t_to', function (JoinClause $join) {
+ $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
+ }
+ )
+ ->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
+ ->leftJoin(
+ 'account_meta as acm_to', function (JoinClause $join) {
+ $join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
+ }
+ )
+ ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
+ ->where('transaction_types.type', 'Deposit')
+ ->where('acm_to.data', '!=', '"sharedExpense"')
+ ->before($end)->after($start)
+ ->where('transaction_journals.user_id', \Auth::user()->id)
+ ->groupBy('t_from.account_id')->orderBy('amount')
+ ->get(['t_from.account_id as account_id', 'ac_from.name as name', \DB::Raw('SUM(t_from.amount) as `amount`')]);
+ }
+
/**
* With an equally misleading name, this query returns are transfers to shared accounts. These are considered
* expenses.
diff --git a/app/lib/FireflyIII/Report/ReportQueryInterface.php b/app/lib/FireflyIII/Report/ReportQueryInterface.php
index 6a729480f6..a2097c6635 100644
--- a/app/lib/FireflyIII/Report/ReportQueryInterface.php
+++ b/app/lib/FireflyIII/Report/ReportQueryInterface.php
@@ -108,6 +108,15 @@ interface ReportQueryInterface
*/
public function journalsByExpenseAccount(Carbon $start, Carbon $end);
+ /**
+ * This method returns all deposits into asset accounts, grouped by the revenue account,
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function journalsByRevenueAccount(Carbon $start, Carbon $end);
+
/**
* With an equally misleading name, this query returns are transfers to shared accounts. These are considered
* expenses.
diff --git a/app/views/reports/year.blade.php b/app/views/reports/year.blade.php
index 2911af39fa..130f29ec55 100644
--- a/app/views/reports/year.blade.php
+++ b/app/views/reports/year.blade.php
@@ -71,7 +71,7 @@
$incomeSum = 0;
$expenseSum = 0;
foreach($groupedIncomes as $income) {
- $incomeSum += floatval($income->sum);
+ $incomeSum += floatval($income->amount);
}
foreach($groupedExpenses as $exp) {
$expenseSum += floatval($exp['amount']);
@@ -104,10 +104,10 @@
<table class="table">
<?php $sum = 0;?>
@foreach($groupedIncomes as $income)
- <?php $sum += floatval($income->sum)*-1;?>
+ <?php $sum += floatval($income->amount)*-1;?>
<tr>
<td><a href="{{route('accounts.show',$income->account_id)}}">{{{$income->name}}}</a></td>
- <td>{{Amount::format(floatval($income->sum)*-1)}}</td>
+ <td>{{Amount::format(floatval($income->amount)*-1)}}</td>
</tr>
@endforeach
<tr>