From 9f23462c42206a50074b5eb05e2b26620f94269a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 27 Dec 2014 17:21:15 +0100 Subject: [PATCH] Expanded reports. --- app/controllers/ReportController.php | 1 + .../TransactionJournal/TransactionJournal.php | 5 + app/lib/FireflyIII/FF3ServiceProvider.php | 2 + app/lib/FireflyIII/Report/Report.php | 228 +++++++----------- app/lib/FireflyIII/Report/ReportHelper.php | 119 +++++++++ .../Report/ReportHelperInterface.php | 55 +++++ app/lib/FireflyIII/Report/ReportInterface.php | 14 +- app/lib/FireflyIII/Report/ReportQuery.php | 227 +++++++++++++++++ .../Report/ReportQueryInterface.php | 89 +++++++ app/views/reports/month.blade.php | 83 ++++--- 10 files changed, 650 insertions(+), 173 deletions(-) create mode 100644 app/lib/FireflyIII/Report/ReportHelper.php create mode 100644 app/lib/FireflyIII/Report/ReportHelperInterface.php create mode 100644 app/lib/FireflyIII/Report/ReportQuery.php create mode 100644 app/lib/FireflyIII/Report/ReportQueryInterface.php diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index a759ba17cc..86885e978a 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -71,6 +71,7 @@ class ReportController extends BaseController $budgets = $this->_repository->getBudgetsForMonth($date); $categories = $this->_repository->getCategoriesForMonth($date, 10); $accounts = $this->_repository->getAccountsForMonth($date); + $piggyBanks = $this->_repository->getPiggyBanksForMonth($date); return View::make( 'reports.month', diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php index f3c8084dae..04da13b06a 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php @@ -389,7 +389,12 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData if ($category) { $journal->categories()->sync([$category->id]); } + + return; } + $journal->categories()->sync([]); + + return; } /** diff --git a/app/lib/FireflyIII/FF3ServiceProvider.php b/app/lib/FireflyIII/FF3ServiceProvider.php index b79fcf3053..cf85ed6380 100644 --- a/app/lib/FireflyIII/FF3ServiceProvider.php +++ b/app/lib/FireflyIII/FF3ServiceProvider.php @@ -96,6 +96,8 @@ class FF3ServiceProvider extends ServiceProvider // reports $this->app->bind('FireflyIII\Report\ReportInterface', 'FireflyIII\Report\Report'); + $this->app->bind('FireflyIII\Report\ReportQueryInterface', 'FireflyIII\Report\ReportQuery'); + $this->app->bind('FireflyIII\Report\ReportHelperInterface', 'FireflyIII\Report\ReportHelper'); // chart $this->app->bind('FireflyIII\Chart\ChartInterface', 'FireflyIII\Chart\Chart'); diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php index eb3afeb88b..4dc0986102 100644 --- a/app/lib/FireflyIII/Report/Report.php +++ b/app/lib/FireflyIII/Report/Report.php @@ -6,11 +6,12 @@ use Carbon\Carbon; use FireflyIII\Database\Account\Account as AccountRepository; use FireflyIII\Database\SwitchUser; use FireflyIII\Database\TransactionJournal\TransactionJournal as JournalRepository; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; use stdClass; -// todo add methods to itnerface +// todo add methods to interface /** * Class Report @@ -25,9 +26,12 @@ class Report implements ReportInterface /** @var AccountRepository */ protected $_accounts; - + /** @var \FireflyIII\Report\ReportHelperInterface */ + protected $_helper; /** @var JournalRepository */ protected $_journals; + /** @var \FireflyIII\Report\ReportQueryInterface */ + protected $_queries; /** * @param AccountRepository $accounts @@ -36,10 +40,15 @@ class Report implements ReportInterface { $this->_accounts = $accounts; $this->_journals = $journals; + $this->_queries = \App::make('FireflyIII\Report\ReportQueryInterface'); + $this->_helper = \App::make('FireflyIII\Report\ReportHelperInterface'); + } /** + * TODO Used in yearly report, so not ready for cleanup. + * * @param Carbon $start * @param Carbon $end * @param int $limit @@ -76,7 +85,7 @@ class Report implements ReportInterface ->where('acm_from.data', '!=', '"sharedExpense"') ->before($end)->after($start) ->where('transaction_journals.user_id', \Auth::user()->id) - ->groupBy('account_id')->orderBy('sum', 'DESC')->limit(15) + ->groupBy('account_id')->orderBy('sum', 'DESC')->limit($limit) ->get(['t_to.account_id as account_id', 'ac_to.name as name', \DB::Raw('SUM(t_to.amount) as `sum`')]); @@ -85,7 +94,7 @@ class Report implements ReportInterface /** * @param Carbon $date * - * @return Collection + * @return array */ public function getAccountsForMonth(Carbon $date) { @@ -93,31 +102,21 @@ class Report implements ReportInterface $start->startOfMonth(); $end = clone $date; $end->endOfMonth(); - $list = \Auth::user()->accounts() - ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', "accountRole"); - } - ) - ->whereIn('account_types.type', ['Default account', 'Cash account', 'Asset account']) - ->where('active', 1) - ->where( - function ($query) { - $query->where('account_meta.data', '!=', '"sharedExpense"'); - $query->orWhereNull('account_meta.data'); - } - ) - ->get(['accounts.*']); - $list->each( - function (\Account $account) use ($start, $end) { - $account->startBalance = \Steam::balance($account, $start); - $account->endBalance = \Steam::balance($account, $end); - $account->difference = $account->endBalance - $account->startBalance; - } - ); + $list = $this->_queries->accountList(); + $accounts = []; + /** @var \Account $account */ + foreach ($list as $account) { + $id = intval($account->id); + $accounts[$id] = [ + 'name' => $account->name, + 'startBalance' => \Steam::balance($account, $start), + 'endBalance' => \Steam::balance($account, $end) + ]; - return $list; + $accounts[$id]['difference'] = $accounts[$id]['endBalance'] - $accounts[$id]['startBalance']; + } + + return $accounts; } /** @@ -132,74 +131,29 @@ class Report implements ReportInterface $end = clone $date; $end->endOfMonth(); // all budgets - /** @var Collection $budgets */ - $budgets = \Auth::user()->budgets() - ->leftJoin( - 'budget_limits', function (JoinClause $join) use ($date) { - $join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d')); - } - ) - ->get(['budgets.*', 'budget_limits.amount as budget_amount']); - $amounts = \Auth::user()->transactionjournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budgets', 'budget_transaction_journal.budget_id', '=', 'budgets.id') - ->leftJoin( - 'transactions', function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); - } - ) - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) - ->where('account_meta.data', '!=', '"sharedExpense"') - ->where('transaction_types.type', 'Withdrawal') - ->groupBy('budgets.id') - ->orderBy('name','ASC') - ->get(['budgets.id', 'budgets.name', \DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]); + $set = $this->_queries->getAllBudgets($date); + $budgets = $this->_helper->makeArray($set); + $amountSet = $this->_queries->journalsByBudget($start, $end); + $amounts = $this->_helper->makeArray($amountSet); + $combined = $this->_helper->mergeArrays($budgets, $amounts); + $combined[0]['spent'] = isset($combined[0]['spent']) ? $combined[0]['spent'] : 0.0; + $combined[0]['amount'] = isset($combined[0]['amount']) ? $combined[0]['amount'] : 0.0; + $combined[0]['name'] = 'No budget'; - - $spentNoBudget = 0; - foreach ($budgets as $budget) { - $budget->spent = 0; - foreach ($amounts as $amount) { - if (intval($budget->id) == intval($amount->id)) { - $budget->spent = floatval($amount->sum) * -1; - } - if (is_null($amount->id)) { - $spentNoBudget = floatval($amount->sum) * -1; - } - } + // find transactions to shared expense accounts, which are without a budget by default: + $transfers = $this->_queries->sharedExpenses($start, $end); + foreach ($transfers as $transfer) { + $combined[0]['spent'] += floatval($transfer->amount) * -1; } - $noBudget = new stdClass; - $noBudget->id = 0; - $noBudget->name = '(no budget)'; - $noBudget->budget_amount = 0; - $noBudget->spent = $spentNoBudget; - - // also get transfers to expense accounts (which are without a budget, and grouped). - $transfers = $this->getTransfersToSharedAccounts($date); - foreach($transfers as $transfer) { - $noBudget->spent += floatval($transfer->sum) * -1; - } - - - $budgets->push($noBudget); - - return $budgets; + return $combined; } /** * @param Carbon $date * @param int $limit * - * @return Collection + * @return array */ public function getCategoriesForMonth(Carbon $date, $limit = 15) { @@ -208,58 +162,21 @@ class Report implements ReportInterface $end = clone $date; $end->endOfMonth(); // all categories. - $amounts = \Auth::user()->transactionjournals() - ->leftJoin( - 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' - ) - ->leftJoin('categories', 'category_transaction_journal.category_id', '=', 'categories.id') - ->leftJoin( - 'transactions', function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); - } - ) - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) - ->where('account_meta.data', '!=', '"sharedExpense"') - ->where('transaction_types.type', 'Withdrawal') - ->groupBy('categories.id') - ->orderBy('sum') - ->get(['categories.id', 'categories.name', \DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]); - $spentNoCategory = 0; - foreach ($amounts as $amount) { - if (is_null($amount->id)) { - $spentNoCategory = floatval($amount->sum) * -1; - } - } - $noCategory = new stdClass; - $noCategory->id = 0; - $noCategory->name = '(no category)'; - $noCategory->sum = $spentNoCategory; - $amounts->push($noCategory); + $result = $this->_queries->journalsByCategory($start, $end); + $categories = $this->_helper->makeArray($result); - $return = new Collection; - $bottom = new stdClass(); - $bottom->name = 'Others'; - $bottom->id = 0; - $bottom->sum = 0; + // all transfers + $result = $this->_queries->sharedExpensesByCategory($start, $end); + $transfers = $this->_helper->makeArray($result); + $merged = $this->_helper->mergeArrays($categories, $transfers); - foreach ($amounts as $index => $entry) { - if ($index < $limit) { - $return->push($entry); - } else { - $bottom->sum += floatval($entry->sum); - } - } - $return->push($bottom); + // sort. + $sorted = $this->_helper->sortNegativeArray($merged); - return $return; + // limit to $limit: + $cut = $this->_helper->limitArray($sorted, $limit); + + return $cut; } /** @@ -314,7 +231,7 @@ class Report implements ReportInterface \DB::Raw('SUM(`transactions`.`amount`) * -1 AS `sum`') ] ); - $transfers = $this->getTransfersToSharedAccounts($date); + $transfers = $this->getTransfersToSharedGroupedByAccounts($date); // merge $transfers into $set foreach ($transfers as $transfer) { if (!is_null($transfer->account_id)) { @@ -409,7 +326,40 @@ class Report implements ReportInterface * * @return Collection */ - public function getTransfersToSharedAccounts(Carbon $date) + public function getPiggyBanksForMonth(Carbon $date) + { + $start = clone $date; + $start->startOfMonth(); + $end = clone $date; + $end->endOfMonth(); + + $set = \PiggyBank:: + leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') + ->where('accounts.user_id', \Auth::user()->id) + ->where('repeats', 0) + ->where( + function (Builder $query) use ($start, $end) { + $query->whereNull('piggy_banks.deleted_at'); + $query->orWhere( + function (Builder $query) use ($start, $end) { + $query->whereNotNull('piggy_banks.deleted_at'); + $query->where('piggy_banks.deleted_at', '>=', $start->format('Y-m-d 00:00:00')); + $query->where('piggy_banks.deleted_at', '<=', $end->format('Y-m-d 00:00:00')); + } + ); + } + ) + ->get(['piggy_banks.*']); + + + } + + /** + * @param Carbon $date + * + * @return Collection + */ + public function getTransfersToSharedGroupedByAccounts(Carbon $date) { $start = clone $date; $start->startOfMonth(); @@ -436,6 +386,7 @@ class Report implements ReportInterface ->where('date', '<=', $end->format('Y-m-d')) ->where('transaction_types.type', 'Transfer') ->where('transaction_journals.user_id', \Auth::user()->id) + ->groupBy('accounts.name') ->get( [ 'transactions.account_id', @@ -445,6 +396,7 @@ class Report implements ReportInterface ); } + /** * @param Carbon $start * diff --git a/app/lib/FireflyIII/Report/ReportHelper.php b/app/lib/FireflyIII/Report/ReportHelper.php new file mode 100644 index 0000000000..d6dd6e619f --- /dev/null +++ b/app/lib/FireflyIII/Report/ReportHelper.php @@ -0,0 +1,119 @@ + 'Others', + 'amount' => 0 + ]; + $return = []; + $count = 0; + foreach ($array as $id => $entry) { + if ($count < ($limit - 1)) { + $return[$id] = $entry; + } else { + $others['amount'] += $entry['amount']; + } + + $count++; + } + $return[0] = $others; + + return $return; + + } + + /** + * Turns a collection into an array. Needs the field 'id' for the key, + * and saves only 'name' and 'amount' as a subarray. + * + * @param Collection $collection + * + * @return array + */ + public function makeArray(Collection $collection) + { + $array = []; + foreach ($collection as $entry) { + $entry->spent = isset($entry->spent) ? floatval($entry->spent) : 0.0; + $id = intval($entry->id); + if (isset($array[$id])) { + $array[$id]['amount'] += floatval($entry->amount); + $array[$id]['spent'] += floatval($entry->spent); + } else { + $array[$id] = [ + 'amount' => floatval($entry->amount), + 'spent' => floatval($entry->spent), + 'name' => $entry->name + ]; + } + } + + return $array; + } + + /** + * Merges two of the arrays as defined above. Can't handle more (yet) + * + * @param array $one + * @param array $two + * + * @return array + */ + public function mergeArrays(array $one, array $two) + { + foreach ($two as $id => $value) { + // $otherId also exists in $one: + if (isset($one[$id])) { + $one[$id]['amount'] += $value['amount']; + $one[$id]['spent'] += $value['spent']; + } else { + $one[$id] = $value; + } + } + + return $one; + } + + /** + * Sort an array where all 'amount' keys are negative floats. + * + * @param array $array + * + * @return array + */ + public function sortNegativeArray(array $array) + { + uasort( + $array, function ($left, $right) { + if ($left['amount'] == $right['amount']) { + return 0; + } + + return ($left['amount'] < $right['amount']) ? -1 : 1; + } + ); + + return $array; + } +} \ No newline at end of file diff --git a/app/lib/FireflyIII/Report/ReportHelperInterface.php b/app/lib/FireflyIII/Report/ReportHelperInterface.php new file mode 100644 index 0000000000..1be77864c7 --- /dev/null +++ b/app/lib/FireflyIII/Report/ReportHelperInterface.php @@ -0,0 +1,55 @@ +accounts() + ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', "accountRole"); + } + ) + ->whereIn('account_types.type', ['Default account', 'Cash account', 'Asset account']) + ->where('active', 1) + ->where( + function ($query) { + $query->where('account_meta.data', '!=', '"sharedExpense"'); + $query->orWhereNull('account_meta.data'); + } + ) + ->get(['accounts.*']); + } + + /** + * Gets a list of all budgets and if present, the amount of the current BudgetLimit + * as well + * + * @param Carbon $date + * + * @return Collection + */ + public function getAllBudgets(Carbon $date) + { + return \Auth::user()->budgets() + ->leftJoin( + 'budget_limits', function (JoinClause $join) use ($date) { + $join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d')); + } + ) + ->get(['budgets.*', 'budget_limits.amount as amount']); + } + + /** + * Gets a list of expenses grouped by the budget they were filed under. + * + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function journalsByBudget(Carbon $start, Carbon $end) + { + return \Auth::user()->transactionjournals() + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budgets', 'budget_transaction_journal.budget_id', '=', 'budgets.id') + ->leftJoin( + 'transactions', function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); + } + ) + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') + ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) + ->where('account_meta.data', '!=', '"sharedExpense"') + ->where('transaction_types.type', 'Withdrawal') + ->groupBy('budgets.id') + ->orderBy('name', 'ASC') + ->get(['budgets.id', 'budgets.name', \DB::Raw('SUM(`transactions`.`amount`) AS `spent`')]); + } + + /** + * Gets a list of categories and the expenses therein, grouped by the relevant category. + * This result excludes transfers to shared accounts which are expenses, technically. + * + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function journalsByCategory(Carbon $start, Carbon $end) + { + return \Auth::user()->transactionjournals() + ->leftJoin( + 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' + ) + ->leftJoin('categories', 'category_transaction_journal.category_id', '=', 'categories.id') + ->leftJoin( + 'transactions', function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); + } + ) + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') + ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) + ->where('account_meta.data', '!=', '"sharedExpense"') + ->where('transaction_types.type', 'Withdrawal') + ->groupBy('categories.id') + ->orderBy('amount') + ->get(['categories.id', 'categories.name', \DB::Raw('SUM(`transactions`.`amount`) AS `amount`')]); + + } + + /** + * Gets a list of expense accounts and the expenses therein, grouped by that expense account. + * This result excludes transfers to shared accounts which are expenses, technically. + * + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function journalsByExpenseAccount(Carbon $start, Carbon $end) + { + } + + /** + * With an equally misleading name, this query returns are transfers to shared accounts. These are considered + * expenses. + * + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function sharedExpenses(Carbon $start, Carbon $end) + { + return \TransactionJournal:: + leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->leftJoin( + 'transactions', function (JoinClause $join) { + $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where( + 'transactions.amount', '>', 0 + ); + } + ) + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->where('account_meta.data', '"sharedExpense"') + ->after($start) + ->before($end) + ->where('transaction_types.type', 'Transfer') + ->where('transaction_journals.user_id', \Auth::user()->id) + ->get( + ['transaction_journals.id', 'transaction_journals.description', 'transactions.account_id', 'accounts.name', + 'transactions.amount'] + ); + + } + + /** + * With a slightly misleading name, this query returns all transfers to shared accounts + * which are technically expenses, since it won't be just your money that gets spend. + * + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function sharedExpensesByCategory(Carbon $start, Carbon $end) + { + return \TransactionJournal:: + leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->leftJoin( + 'transactions', function (JoinClause $join) { + $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where( + 'transactions.amount', '>', 0 + ); + } + ) + ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') + ->leftJoin( + 'account_meta', function (JoinClause $join) { + $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); + } + ) + ->leftJoin( + 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' + ) + ->leftJoin('categories', 'category_transaction_journal.category_id', '=', 'categories.id') + ->where('account_meta.data', '"sharedExpense"') + ->after($start) + ->before($end) + ->where('transaction_types.type', 'Transfer') + ->where('transaction_journals.user_id', \Auth::user()->id) + ->groupBy('categories.name') + ->get( + [ + 'categories.id', + 'categories.name as name', + \DB::Raw('SUM(`transactions`.`amount`) * -1 AS `amount`') + ] + ); + } +} \ No newline at end of file diff --git a/app/lib/FireflyIII/Report/ReportQueryInterface.php b/app/lib/FireflyIII/Report/ReportQueryInterface.php new file mode 100644 index 0000000000..fffdb133b4 --- /dev/null +++ b/app/lib/FireflyIII/Report/ReportQueryInterface.php @@ -0,0 +1,89 @@ +getName()) }}
-
+
Income
@include('list.journals-small',['journals' => $income])
-
+
Expenses (top 10)
@@ -31,6 +31,31 @@
+
+
+
Sums
+ transactions[1]->amount); + } + ?> + + + + + + + + + + + + + +
In{{mf($in)}}
Out{{mf($sum)}}
Difference{{mf($sum + $in)}}
+
+
@@ -48,23 +73,23 @@ $sumEnvelope = 0; $sumLeft = 0; ?> - @foreach($budgets as $budget) + @foreach($budgets as $id => $budget) spent); - $sumEnvelope += floatval($budget->budget_amount); - $sumLeft += floatval($budget->budget_amount) - floatval($budget->spent); + $sumSpent += $budget['spent']; + $sumEnvelope += $budget['amount']; + $sumLeft += $budget['amount'] + $budget['spent']; ?> - @if($budget->id > 0) - {{{$budget->name}}} + @if($id > 0) + {{{$budget['name']}}} @else - {{{$budget->name}}} + {{{$budget['name']}}} @endif - {{mf($budget->budget_amount)}} - {{mf($budget->spent,false)}} - {{mf(floatval($budget->budget_amount) - floatval($budget->spent))}} + {{mf($budget['amount'])}} + {{mf($budget['spent'],false)}} + {{mf($budget['amount'] + $budget['spent'])}} @endforeach @@ -74,9 +99,6 @@ {{mf($sumLeft)}} -
- This list does not take in account outgoing transfers to shared accounts. -
@@ -88,17 +110,17 @@ Spent - @foreach($categories as $category) - sum);?> + @foreach($categories as $id => $category) + - @if($category->id > 0) - {{{$category->name}}} + @if($id > 0) + {{{$category['name']}}} @else - {{{$category->name}}} + {{{$category['name']}}} @endif - {{mf($category->sum,false)}} + {{mf($category['amount'],false)}} @endforeach @@ -106,9 +128,6 @@ {{mf($sum)}} -
- This list does not take in account outgoing transfers to shared accounts. -
@@ -122,17 +141,17 @@ $sumEnd = 0; $sumDiff = 0; ?> - @foreach($accounts as $account) + @foreach($accounts as $id => $account) startBalance; - $sumEnd += $account->endBalance; - $sumDiff += $account->difference; + $sumStart += $account['startBalance']; + $sumEnd += $account['endBalance']; + $sumDiff += $account['difference']; ?> - {{{$account->name}}} - {{mf($account->startBalance)}} - {{mf($account->endBalance)}} - {{mf($account->difference)}} + {{{$account['name']}}} + {{mf($account['startBalance'])}} + {{mf($account['endBalance'])}} + {{mf($account['difference'])}} @endforeach