mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More code for the tag report.
This commit is contained in:
parent
f63c6875cd
commit
3d4feff7de
@ -47,7 +47,6 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
'budget' => ['transaction_journal_budget_id', 'transaction_budget_id'],
|
'budget' => ['transaction_journal_budget_id', 'transaction_budget_id'],
|
||||||
'category' => ['transaction_journal_category_id', 'transaction_category_id'],
|
'category' => ['transaction_journal_category_id', 'transaction_category_id'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $repositories
|
protected $repositories
|
||||||
= [
|
= [
|
||||||
@ -55,10 +54,10 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
'budget' => BudgetRepositoryInterface::class,
|
'budget' => BudgetRepositoryInterface::class,
|
||||||
'category' => CategoryRepositoryInterface::class,
|
'category' => CategoryRepositoryInterface::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/** @var Carbon */
|
/** @var Carbon */
|
||||||
protected $start;
|
protected $start;
|
||||||
|
/** @var Collection */
|
||||||
|
protected $tags;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $total = '0';
|
protected $total = '0';
|
||||||
/** @var User */
|
/** @var User */
|
||||||
@ -87,7 +86,6 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
if ($this->collectOtherObjects && $direction === 'expense') {
|
if ($this->collectOtherObjects && $direction === 'expense') {
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setUser($this->user);
|
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
$journals = $collector->getJournals();
|
$journals = $collector->getJournals();
|
||||||
$sum = strval($journals->sum('transaction_amount'));
|
$sum = strval($journals->sum('transaction_amount'));
|
||||||
@ -182,6 +180,18 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $tags
|
||||||
|
*
|
||||||
|
* @return MetaPieChartInterface
|
||||||
|
*/
|
||||||
|
public function setTags(Collection $tags): MetaPieChartInterface
|
||||||
|
{
|
||||||
|
$this->tags = $tags;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*
|
*
|
||||||
@ -219,6 +229,11 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
if ($this->categories->count() > 0) {
|
if ($this->categories->count() > 0) {
|
||||||
$collector->setCategories($this->categories);
|
$collector->setCategories($this->categories);
|
||||||
}
|
}
|
||||||
|
if ($this->tags->count() > 0) {
|
||||||
|
$collector->setTags($this->tags);
|
||||||
|
$collector->withCategoryInformation();
|
||||||
|
$collector->withBudgetInformation();
|
||||||
|
}
|
||||||
|
|
||||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
$accountIds = $this->accounts->pluck('id')->toArray();
|
||||||
$transactions = $collector->getJournals();
|
$transactions = $collector->getJournals();
|
||||||
|
@ -72,6 +72,13 @@ interface MetaPieChartInterface
|
|||||||
*/
|
*/
|
||||||
public function setStart(Carbon $start): MetaPieChartInterface;
|
public function setStart(Carbon $start): MetaPieChartInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $tags
|
||||||
|
*
|
||||||
|
* @return MetaPieChartInterface
|
||||||
|
*/
|
||||||
|
public function setTags(Collection $tags): MetaPieChartInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*
|
*
|
||||||
|
@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers\Chart;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Tag\MonthReportGenerator;
|
use FireflyIII\Generator\Report\Tag\MonthReportGenerator;
|
||||||
|
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
@ -40,6 +41,100 @@ class TagReportController extends Controller
|
|||||||
$this->generator = app(GeneratorInterface::class);
|
$this->generator = app(GeneratorInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Collection $tags
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param string $others
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function accountExpense(Collection $accounts, Collection $tags, Carbon $start, Carbon $end, string $others)
|
||||||
|
{
|
||||||
|
/** @var MetaPieChartInterface $helper */
|
||||||
|
$helper = app(MetaPieChartInterface::class);
|
||||||
|
$helper->setAccounts($accounts);
|
||||||
|
$helper->setTags($tags);
|
||||||
|
$helper->setStart($start);
|
||||||
|
$helper->setEnd($end);
|
||||||
|
$helper->setCollectOtherObjects(intval($others) === 1);
|
||||||
|
$chartData = $helper->generate('expense', 'account');
|
||||||
|
$data = $this->generator->pieChart($chartData);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Collection $tags
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param string $others
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function accountIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end, string $others)
|
||||||
|
{
|
||||||
|
/** @var MetaPieChartInterface $helper */
|
||||||
|
$helper = app(MetaPieChartInterface::class);
|
||||||
|
$helper->setAccounts($accounts);
|
||||||
|
$helper->setTags($tags);
|
||||||
|
$helper->setStart($start);
|
||||||
|
$helper->setEnd($end);
|
||||||
|
$helper->setCollectOtherObjects(intval($others) === 1);
|
||||||
|
$chartData = $helper->generate('income', 'account');
|
||||||
|
$data = $this->generator->pieChart($chartData);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Collection $tags
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function budgetExpense(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
||||||
|
{
|
||||||
|
/** @var MetaPieChartInterface $helper */
|
||||||
|
$helper = app(MetaPieChartInterface::class);
|
||||||
|
$helper->setAccounts($accounts);
|
||||||
|
$helper->setTags($tags);
|
||||||
|
$helper->setStart($start);
|
||||||
|
$helper->setEnd($end);
|
||||||
|
$helper->setCollectOtherObjects(false);
|
||||||
|
$chartData = $helper->generate('expense', 'budget');
|
||||||
|
$data = $this->generator->pieChart($chartData);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Collection $tags
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function categoryExpense(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
||||||
|
{
|
||||||
|
/** @var MetaPieChartInterface $helper */
|
||||||
|
$helper = app(MetaPieChartInterface::class);
|
||||||
|
$helper->setAccounts($accounts);
|
||||||
|
$helper->setTags($tags);
|
||||||
|
$helper->setStart($start);
|
||||||
|
$helper->setEnd($end);
|
||||||
|
$helper->setCollectOtherObjects(false);
|
||||||
|
$chartData = $helper->generate('expense', 'category');
|
||||||
|
$data = $this->generator->pieChart($chartData);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param Collection $tags
|
* @param Collection $tags
|
||||||
@ -146,7 +241,6 @@ class TagReportController extends Controller
|
|||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param Collection $tags
|
* @param Collection $tags
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
{% if journals.count == 0 %}
|
|
||||||
{% include 'partials.empty' with {what: what, type: 'transactions',route: route('transactions.create', [what])} %}
|
|
||||||
{% else %}
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-10 col-md-10 col-sm-12">
|
<div class="col-lg-10 col-md-10 col-sm-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
@ -44,7 +41,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script type="text/javascript" src="js/ff/transactions/list.js"></script>
|
<script type="text/javascript" src="js/ff/transactions/list.js"></script>
|
||||||
|
@ -333,13 +333,15 @@ Route::group(
|
|||||||
'account/expense/{accountList}/{tagList}/{start_date}/{end_date}/{others}',
|
'account/expense/{accountList}/{tagList}/{start_date}/{end_date}/{others}',
|
||||||
['uses' => 'TagReportController@accountExpense', 'as' => 'account-expense']
|
['uses' => 'TagReportController@accountExpense', 'as' => 'account-expense']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// new routes
|
||||||
Route::get(
|
Route::get(
|
||||||
'budget/expense/{accountList}/{tagList}/{start_date}/{end_date}',
|
'budget/expense/{accountList}/{tagList}/{start_date}/{end_date}',
|
||||||
['uses' => 'TagReportController@budgetExpense', 'as' => 'budget-expense']
|
['uses' => 'TagReportController@budgetExpense', 'as' => 'budget-expense']
|
||||||
);
|
);
|
||||||
Route::get(
|
Route::get('category/expense/{accountList}/{tagList}/{start_date}/{end_date}',
|
||||||
'category/expense/{accountList}/{tagList}/{start_date}/{end_date}',
|
|
||||||
['uses' => 'TagReportController@categoryExpense', 'as' => 'category-expense']
|
['uses' => 'TagReportController@categoryExpense', 'as' => 'category-expense']
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user