mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 06:01:21 +00:00
Fixes #2464
This commit is contained in:
@@ -74,7 +74,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
@@ -92,7 +92,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
@@ -156,7 +156,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
@@ -206,6 +206,20 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $this->user->tags()->whereNotNull('date')->orderBy('date', 'ASC')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find one or more tags based on the query.
|
||||
*
|
||||
* @param string $query
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchTag(string $query): Collection
|
||||
{
|
||||
$search = sprintf('%%%s%%', $query);
|
||||
|
||||
return $this->user->tags()->where('tag', 'LIKE', $search)->get(['tags.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the users tags.
|
||||
*
|
||||
@@ -234,7 +248,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
@@ -266,7 +280,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
@@ -335,7 +349,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
foreach ($tags as $tag) {
|
||||
$amount = (string)$tag->amount_sum;
|
||||
$amount = '' === $amount ? '0' : $amount;
|
||||
$amountMin = bcsub($amount, $min);
|
||||
$amountMin = bcsub($amount, $min);
|
||||
$pointsForTag = bcmul($amountMin, $pointsPerCoin);
|
||||
$fontSize = bcadd($minimumFont, $pointsForTag);
|
||||
Log::debug(sprintf('Tag "%s": Amount is %s, so points is %s', $tag->tag, $amount, $fontSize));
|
||||
@@ -352,37 +366,39 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $year
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
private function getTagsInYear(?int $year): Collection
|
||||
public function transferredInPeriod(Tag $tag, Carbon $start, Carbon $end): array
|
||||
{
|
||||
// get all tags in the year (if present):
|
||||
$tagQuery = $this->user->tags()
|
||||
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where(
|
||||
function (Builder $query) {
|
||||
$query->where('transactions.amount', '>', 0);
|
||||
$query->orWhereNull('transactions.amount');
|
||||
}
|
||||
)
|
||||
->groupBy(['tags.id', 'tags.tag']);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::TRANSFER])->setTag($tag);
|
||||
|
||||
// add date range (or not):
|
||||
if (null === $year) {
|
||||
Log::debug('Get tags without a date.');
|
||||
$tagQuery->whereNull('tags.date');
|
||||
}
|
||||
if (null !== $year) {
|
||||
Log::debug(sprintf('Get tags with year %s.', $year));
|
||||
$tagQuery->where('tags.date', '>=', $year . '-01-01 00:00:00')->where('tags.date', '<=', $year . '-12-31 23:59:59');
|
||||
}
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
return $tagQuery->get(['tags.id', 'tags.tag', DB::raw('SUM(transactions.amount) as amount_sum')]);
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
public function update(Tag $tag, array $data): Tag
|
||||
{
|
||||
$tag->tag = $data['tag'];
|
||||
$tag->date = $data['date'];
|
||||
$tag->description = $data['description'];
|
||||
$tag->latitude = $data['latitude'];
|
||||
$tag->longitude = $data['longitude'];
|
||||
$tag->zoomLevel = $data['zoom_level'];
|
||||
$tag->save();
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,38 +452,36 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int|null $year
|
||||
*
|
||||
* @return array
|
||||
* @return Collection
|
||||
*/
|
||||
public function transferredInPeriod(Tag $tag, Carbon $start, Carbon $end): array
|
||||
private function getTagsInYear(?int $year): Collection
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::TRANSFER])->setTag($tag);
|
||||
// get all tags in the year (if present):
|
||||
$tagQuery = $this->user->tags()
|
||||
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where(
|
||||
function (Builder $query) {
|
||||
$query->where('transactions.amount', '>', 0);
|
||||
$query->orWhereNull('transactions.amount');
|
||||
}
|
||||
)
|
||||
->groupBy(['tags.id', 'tags.tag']);
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
// add date range (or not):
|
||||
if (null === $year) {
|
||||
Log::debug('Get tags without a date.');
|
||||
$tagQuery->whereNull('tags.date');
|
||||
}
|
||||
if (null !== $year) {
|
||||
Log::debug(sprintf('Get tags with year %s.', $year));
|
||||
$tagQuery->where('tags.date', '>=', $year . '-01-01 00:00:00')->where('tags.date', '<=', $year . '-12-31 23:59:59');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
public function update(Tag $tag, array $data): Tag
|
||||
{
|
||||
$tag->tag = $data['tag'];
|
||||
$tag->date = $data['date'];
|
||||
$tag->description = $data['description'];
|
||||
$tag->latitude = $data['latitude'];
|
||||
$tag->longitude = $data['longitude'];
|
||||
$tag->zoomLevel = $data['zoom_level'];
|
||||
$tag->save();
|
||||
return $tagQuery->get(['tags.id', 'tags.tag', DB::raw('SUM(transactions.amount) as amount_sum')]);
|
||||
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,14 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function findByTag(string $tag): ?Tag;
|
||||
|
||||
/**
|
||||
* Find one or more tags based on the query.
|
||||
* @param string $query
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchTag(string $query): Collection;
|
||||
|
||||
/**
|
||||
* @param int $tagId
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user