mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
A better tag overview as preparation for #525
This commit is contained in:
@@ -14,6 +14,8 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Repositories\Tag;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
@@ -121,6 +123,21 @@ class TagRepository implements TagRepositoryInterface
|
||||
return new Tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function firstUseDate(Tag $tag): Carbon
|
||||
{
|
||||
$journal = $tag->transactionJournals()->orderBy('date', 'ASC')->first();
|
||||
if (!is_null($journal)) {
|
||||
return $journal->date;
|
||||
}
|
||||
|
||||
return new Carbon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -137,6 +154,21 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function lastUseDate(Tag $tag): Carbon
|
||||
{
|
||||
$journal = $tag->transactionJournals()->orderBy('date', 'DESC')->first();
|
||||
if (!is_null($journal)) {
|
||||
return $journal->date;
|
||||
}
|
||||
|
||||
return new Carbon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
@@ -353,4 +385,40 @@ class TagRepository implements TagRepositoryInterface
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function earnedInPeriod(Tag $tag, Carbon $start, Carbon $end): string
|
||||
{
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class, [$this->user]);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag);
|
||||
$set = $collector->getJournals();
|
||||
$sum = strval($set->sum('transaction_amount'));
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function spentInPeriod(Tag $tag, Carbon $start, Carbon $end): string
|
||||
{
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class, [$this->user]);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag);
|
||||
$set = $collector->getJournals();
|
||||
$sum = strval($set->sum('transaction_amount'));
|
||||
|
||||
return $sum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Repositories\Tag;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -44,6 +45,15 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function destroy(Tag $tag): bool;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function earnedInPeriod(Tag $tag, Carbon $start, Carbon $end): string;
|
||||
|
||||
/**
|
||||
* @param int $tagId
|
||||
*
|
||||
@@ -58,6 +68,13 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function findByTag(string $tag): Tag;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function firstUseDate(Tag $tag): Carbon;
|
||||
|
||||
/**
|
||||
* This method returns all the user's tags.
|
||||
*
|
||||
@@ -65,6 +82,22 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function get(): Collection;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function lastUseDate(Tag $tag): Carbon;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function spentInPeriod(Tag $tag, Carbon $start, Carbon $end): string;
|
||||
|
||||
/**
|
||||
* This method stores a tag.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user