Expand tag view.

This commit is contained in:
James Cole 2017-08-26 14:50:08 +02:00
parent 989e931edf
commit 50837af607
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 45 additions and 2 deletions

View File

@ -171,7 +171,6 @@ class TagController extends Controller
}
$count = $repository->count();
return view('tags.index', compact('clouds', 'count'));
}
@ -205,6 +204,7 @@ class TagController extends Controller
$start = $repository->firstUseDate($tag);
$end = new Carbon;
$sum = $repository->sumOfTag($tag, null, null);
$result = $repository->resultOfTag($tag, null, null);
$path = route('tags.show', [$tag->id, 'all']);
}
@ -219,6 +219,7 @@ class TagController extends Controller
);
$periods = $this->getPeriodOverview($tag);
$sum = $repository->sumOfTag($tag, $start, $end);
$result = $repository->resultOfTag($tag, $start, $end);
$path = route('tags.show', [$tag->id, $moment]);
}
@ -227,6 +228,8 @@ class TagController extends Controller
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
$periods = $this->getPeriodOverview($tag);
$sum = $repository->sumOfTag($tag, $start, $end);
$result = $repository->resultOfTag($tag, $start, $end);
$subTitle = trans(
'firefly.journals_in_period_for_tag',
['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@ -241,7 +244,7 @@ class TagController extends Controller
$journals->setPath($path);
return view('tags.show', compact('apiKey', 'tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end', 'moment'));
return view('tags.show', compact('apiKey', 'tag', 'result', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end', 'moment'));
}
/**

View File

@ -262,6 +262,34 @@ class TagRepository implements TagRepositoryInterface
return strval($sum);
}
/**
* Same as sum of tag but substracts income instead of adding it as well.
*
* @param Tag $tag
* @param Carbon|null $start
* @param Carbon|null $end
*
* @return string
*/
public function resultOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): string
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
if (!is_null($start) && !is_null($end)) {
$collector->setRange($start, $end);
}
$collector->setAllAssetAccounts()->setTag($tag);
$journals = $collector->getJournals();
$sum = '0';
foreach ($journals as $journal) {
$sum = bcadd($sum, strval($journal->transaction_amount));
}
return strval($sum);
}
/**
* Generates a tag cloud.
*

View File

@ -108,6 +108,15 @@ interface TagRepositoryInterface
*/
public function setUser(User $user);
/**
* @param Tag $tag
* @param Carbon|null $start
* @param Carbon|null $end
*
* @return string
*/
public function resultOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): string;
/**
* @param Tag $tag
* @param Carbon $start

View File

@ -311,6 +311,7 @@ return [
'meta_data' => 'Meta data',
'location' => 'Location',
'without_date' => 'Without date',
'result' => 'Result',
// preferences
'pref_home_screen_accounts' => 'Home screen accounts',

View File

@ -40,10 +40,12 @@
{% if moment == 'all' %}
<p>
{{ 'total_sum'|_ }}: {{ sum|formatAmount }}<br/>
{{ 'total_result'|_ }}: {{ result|formatAmount }}<br/>
</p>
{% else %}
<p>
{{ 'sum'|_ }}: {{ sum|formatAmount }}<br/>
{{ 'result'|_ }}: {{ result|formatAmount }}<br/>
</p>
{% endif %}