diff --git a/app/Generator/Report/Budget/MonthReportGenerator.php b/app/Generator/Report/Budget/MonthReportGenerator.php
index 10b5c39afe..8a8e96d4b5 100644
--- a/app/Generator/Report/Budget/MonthReportGenerator.php
+++ b/app/Generator/Report/Budget/MonthReportGenerator.php
@@ -16,6 +16,7 @@ namespace FireflyIII\Generator\Report\Budget;
use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
+use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\JournalCollector;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
@@ -27,7 +28,7 @@ use Log;
*
* @package FireflyIII\Generator\Report\Budget
*/
-class MonthReportGenerator implements ReportGeneratorInterface
+class MonthReportGenerator extends Support implements ReportGeneratorInterface
{
/** @var Collection */
private $accounts;
@@ -56,26 +57,16 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
public function generate(): string
{
- $accountIds = join(',', $this->accounts->pluck('id')->toArray());
- $categoryIds = join(',', $this->budgets->pluck('id')->toArray());
- $reportType = 'budget';
- // $expenses = $this->getExpenses();
- // $income = $this->getIncome();
- // $accountSummary = $this->getObjectSummary($this->summarizeByAccount($expenses), $this->summarizeByAccount($income));
- // $categorySummary = $this->getObjectSummary($this->summarizeByCategory($expenses), $this->summarizeByCategory($income));
- // $averageExpenses = $this->getAverages($expenses, SORT_ASC);
- // $averageIncome = $this->getAverages($income, SORT_DESC);
- // $topExpenses = $this->getTopExpenses();
- // $topIncome = $this->getTopIncome();
-
+ $accountIds = join(',', $this->accounts->pluck('id')->toArray());
+ $categoryIds = join(',', $this->budgets->pluck('id')->toArray());
+ $expenses = $this->getExpenses();
+ $accountSummary = $this->summarizeByAccount($expenses);
+ $budgetSummary = $this->summarizeByBudget($expenses);
+ $averageExpenses = $this->getAverages($expenses, SORT_ASC);
+ $topExpenses = $this->getTopExpenses();
// render!
- return view(
- 'reports.budget.month',
- compact(
- 'accountIds', 'categoryIds', 'topIncome', 'reportType', 'accountSummary', 'categorySummary', 'averageExpenses', 'averageIncome', 'topExpenses'
- )
- )
+ return view('reports.budget.month', compact('accountIds', 'categoryIds', 'accountSummary', 'budgetSummary', 'averageExpenses', 'topExpenses'))
->with('start', $this->start)->with('end', $this->end)
->with('budgets', $this->budgets)
->with('accounts', $this->accounts)
@@ -113,8 +104,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
public function setCategories(Collection $categories): ReportGeneratorInterface
{
- $this->categories = $categories;
-
return $this;
}
@@ -197,8 +186,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
$collector = new JournalCollector(auth()->user());
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
- ->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
- ->setCategories($this->categories)->withOpposingAccount()->disableFilter();
+ ->setTypes([TransactionType::WITHDRAWAL])
+ ->setBudgets($this->budgets)->withOpposingAccount()->disableFilter();
$accountIds = $this->accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
@@ -208,67 +197,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
return $transactions;
}
- /**
- * @return Collection
- */
- private function getIncome(): Collection
- {
- if ($this->income->count() > 0) {
- return $this->income;
- }
-
- $collector = new JournalCollector(auth()->user());
- $collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
- ->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
- ->setCategories($this->categories)->withOpposingAccount();
- $accountIds = $this->accounts->pluck('id')->toArray();
- $transactions = $collector->getJournals();
- $transactions = self::filterIncome($transactions, $accountIds);
- $this->income = $transactions;
-
- return $transactions;
- }
-
- /**
- * @param array $spent
- * @param array $earned
- *
- * @return array
- */
- private function getObjectSummary(array $spent, array $earned): array
- {
- $return = [];
-
- /**
- * @var int $accountId
- * @var string $entry
- */
- foreach ($spent as $objectId => $entry) {
- if (!isset($return[$objectId])) {
- $return[$objectId] = ['spent' => 0, 'earned' => 0];
- }
-
- $return[$objectId]['spent'] = $entry;
- }
- unset($entry);
-
- /**
- * @var int $accountId
- * @var string $entry
- */
- foreach ($earned as $objectId => $entry) {
- if (!isset($return[$objectId])) {
- $return[$objectId] = ['spent' => 0, 'earned' => 0];
- }
-
- $return[$objectId]['earned'] = $entry;
- }
-
-
- return $return;
- }
-
-
/**
* @return Collection
*/
@@ -279,16 +207,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
return $transactions;
}
- /**
- * @return Collection
- */
- private function getTopIncome(): Collection
- {
- $transactions = $this->getIncome()->sortByDesc('transaction_amount');
-
- return $transactions;
- }
-
/**
* @param Collection $collection
*
@@ -312,16 +230,16 @@ class MonthReportGenerator implements ReportGeneratorInterface
*
* @return array
*/
- private function summarizeByCategory(Collection $collection): array
+ private function summarizeByBudget(Collection $collection): array
{
$result = [];
/** @var Transaction $transaction */
foreach ($collection as $transaction) {
- $jrnlCatId = intval($transaction->transaction_journal_category_id);
- $transCatId = intval($transaction->transaction_category_id);
- $categoryId = max($jrnlCatId, $transCatId);
- $result[$categoryId] = $result[$categoryId] ?? '0';
- $result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);
+ $jrnlBudId = intval($transaction->transaction_journal_budget_id);
+ $transBudId = intval($transaction->transaction_budget_id);
+ $budgetId = max($jrnlBudId, $transBudId);
+ $result[$budgetId] = $result[$budgetId] ?? '0';
+ $result[$budgetId] = bcadd($transaction->transaction_amount, $result[$budgetId]);
}
return $result;
diff --git a/app/Generator/Report/Category/MonthReportGenerator.php b/app/Generator/Report/Category/MonthReportGenerator.php
index cbac1ee2d9..410fd29346 100644
--- a/app/Generator/Report/Category/MonthReportGenerator.php
+++ b/app/Generator/Report/Category/MonthReportGenerator.php
@@ -16,6 +16,7 @@ namespace FireflyIII\Generator\Report\Category;
use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
+use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\JournalCollector;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
diff --git a/app/Generator/Report/Category/Support.php b/app/Generator/Report/Support.php
similarity index 98%
rename from app/Generator/Report/Category/Support.php
rename to app/Generator/Report/Support.php
index f568cd4282..56ee7e981c 100644
--- a/app/Generator/Report/Category/Support.php
+++ b/app/Generator/Report/Support.php
@@ -11,7 +11,7 @@
declare(strict_types = 1);
-namespace FireflyIII\Generator\Report\Category;
+namespace FireflyIII\Generator\Report;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
diff --git a/public/js/ff/reports/budget/all.js b/public/js/ff/reports/budget/all.js
new file mode 100644
index 0000000000..25a412d1c5
--- /dev/null
+++ b/public/js/ff/reports/budget/all.js
@@ -0,0 +1,10 @@
+/*
+ * all.js
+ * Copyright (C) 2016 thegrumpydictator@gmail.com
+ *
+ * This software may be modified and distributed under the terms of the
+ * Creative Commons Attribution-ShareAlike 4.0 International License.
+ *
+ * See the LICENSE file for details.
+ */
+
diff --git a/public/js/ff/reports/budget/month.js b/public/js/ff/reports/budget/month.js
new file mode 100644
index 0000000000..90a4f3a5a2
--- /dev/null
+++ b/public/js/ff/reports/budget/month.js
@@ -0,0 +1,64 @@
+/*
+ * month.js
+ * Copyright (C) 2016 thegrumpydictator@gmail.com
+ *
+ * This software may be modified and distributed under the terms of the
+ * Creative Commons Attribution-ShareAlike 4.0 International License.
+ *
+ * See the LICENSE file for details.
+ */
+
+
+$(function () {
+ "use strict";
+ drawChart();
+
+ $('#budgets-in-pie-chart-checked').on('change', function () {
+ redrawPieChart('budgets-in-pie-chart', categoryIncomeUri);
+ });
+
+ $('#budgets-out-pie-chart-checked').on('change', function () {
+ redrawPieChart('budgets-out-pie-chart', categoryExpenseUri);
+ });
+
+ $('#accounts-in-pie-chart-checked').on('change', function () {
+ redrawPieChart('accounts-in-pie-chart', accountIncomeUri);
+ });
+
+ $('#accounts-out-pie-chart-checked').on('change', function () {
+ redrawPieChart('accounts-out-pie-chart', accountExpenseUri);
+ });
+
+});
+
+
+function drawChart() {
+ "use strict";
+
+ // month view:
+ stackedColumnChart(mainUri, 'in-out-chart');
+
+ // draw pie chart of income, depending on "show other transactions too":
+ redrawPieChart('budgets-in-pie-chart', categoryIncomeUri);
+ redrawPieChart('budgets-out-pie-chart', categoryExpenseUri);
+ redrawPieChart('accounts-in-pie-chart', accountIncomeUri);
+ redrawPieChart('accounts-out-pie-chart', accountExpenseUri);
+
+
+}
+
+function redrawPieChart(container, uri) {
+ "use strict";
+ var checkbox = $('#' + container + '-checked');
+
+ var others = '0';
+ // check if box is checked:
+ if (checkbox.prop('checked')) {
+ others = '1';
+ }
+ uri = uri.replace('OTHERS', others);
+ console.log('URI for ' + container + ' is ' + uri);
+
+ pieChart(uri, container);
+
+}
diff --git a/resources/views/reports/budget/month.twig b/resources/views/reports/budget/month.twig
index 29fe364188..aeccc2dbde 100644
--- a/resources/views/reports/budget/month.twig
+++ b/resources/views/reports/budget/month.twig
@@ -17,7 +17,6 @@
@@ -28,12 +27,7 @@
{{ account.name }}
{% if accountSummary[account.id] %}
- {{ 'name'|_ }}
- {{ 'earned'|_ }}
{{ 'spent'|_ }}