mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Working but fairly useless budget report
This commit is contained in:
parent
1b7546f3f9
commit
bc11c3fab2
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
10
public/js/ff/reports/budget/all.js
Normal file
10
public/js/ff/reports/budget/all.js
Normal file
@ -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.
|
||||
*/
|
||||
|
64
public/js/ff/reports/budget/month.js
Normal file
64
public/js/ff/reports/budget/month.js
Normal file
@ -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);
|
||||
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-defaultsign="az">{{ 'name'|_ }}</th>
|
||||
<th data-defaultsign="_19">{{ 'earned'|_ }}</th>
|
||||
<th data-defaultsign="_19">{{ 'spent'|_ }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -28,12 +27,7 @@
|
||||
<a href="{{ route('accounts.show', account.id) }}" title="{{ account.name }}">{{ account.name }}</a>
|
||||
</td>
|
||||
{% if accountSummary[account.id] %}
|
||||
<td data-value="{{ accountSummary[account.id].earned }}">{{ accountSummary[account.id].earned|formatAmount }}</td>
|
||||
{% else %}
|
||||
<td data-value="0">{{ 0|formatAmount }}</td>
|
||||
{% endif %}
|
||||
{% if accountSummary[account.id] %}
|
||||
<td data-value="{{ accountSummary[account.id].spent }}">{{ accountSummary[account.id].spent|formatAmount }}</td>
|
||||
<td data-value="{{ accountSummary[account.id] }}">{{ accountSummary[account.id]|formatAmount }}</td>
|
||||
{% else %}
|
||||
<td data-value="0">{{ 0|formatAmount }}</td>
|
||||
{% endif %}
|
||||
@ -63,12 +57,7 @@
|
||||
<a href="{{ route('budgets.show', budget.id) }}" title="{{ budget.name }}">{{ budget.name }}</a>
|
||||
</td>
|
||||
{% if budgetSummary[budget.id] %}
|
||||
<td data-value="{{ budgetSummary[budget.id].earned }}">{{ budgetSummary[budget.id].earned|formatAmount }}</td>
|
||||
{% else %}
|
||||
<td data-value="0">{{ 0|formatAmount }}</td>
|
||||
{% endif %}
|
||||
{% if budgetSummary[budget.id] %}
|
||||
<td data-value="{{ budgetSummary[budget.id].spent }}">{{ budgetSummary[budget.id].spent|formatAmount }}</td>
|
||||
<td data-value="{{ budgetSummary[budget.id] }}">{{ budgetSummary[budget.id]|formatAmount }}</td>
|
||||
{% else %}
|
||||
<td data-value="0">{{ 0|formatAmount }}</td>
|
||||
{% endif %}
|
||||
@ -120,6 +109,10 @@
|
||||
<h3 class="box-title">{{ 'income_and_expenses'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
Here be a chart with the budget limits as well if relevant.<br>
|
||||
amount spent vs budget limit reps<br>
|
||||
over the entire period the amount spent would rise and the budget limit rep would be like a heart beat jumping up and down<br>
|
||||
needs to be two axes to work<br>
|
||||
<canvas id="in-out-chart" style="margin:0 auto;" height="300"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
@ -244,11 +237,11 @@
|
||||
var budgetIds = '{{ budgetIds }}';
|
||||
|
||||
// chart uri's
|
||||
var categoryIncomeUri = '{{ route('chart.category.category-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var categoryExpenseUri = '{{ route('chart.category.category-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var accountIncomeUri = '{{ route('chart.category.account-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var accountExpenseUri = '{{ route('chart.category.account-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var mainUri = '{{ route('chart.category.main', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
||||
var budgetIncomeUri = '{{ route('chart.budget.budget-income', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var budgetExpenseUri = '{{ route('chart.budget.budget-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var accountIncomeUri = '{{ route('chart.budget.account-income', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var accountExpenseUri = '{{ route('chart.budget.account-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
|
||||
var mainUri = '{{ route('chart.budget.main', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
||||
</script>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user